Merge pull request #2622 from jfmherokiller/socufix

error conversion fixes for soc_u
This commit is contained in:
bunnei 2017-04-03 21:06:53 -04:00 committed by GitHub
commit 30c130546e

View File

@ -362,18 +362,18 @@ static void Socket(Interface* self) {
return; return;
} }
u32 socket_handle = static_cast<u32>(::socket(domain, type, protocol)); u32 ret = static_cast<u32>(::socket(domain, type, protocol));
if ((s32)socket_handle != SOCKET_ERROR_VALUE) if ((s32)ret != SOCKET_ERROR_VALUE)
open_sockets[socket_handle] = {socket_handle, true}; open_sockets[ret] = {ret, true};
int result = 0; int result = 0;
if ((s32)socket_handle == SOCKET_ERROR_VALUE) if ((s32)ret == SOCKET_ERROR_VALUE)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(2, 2, 0); cmd_buffer[0] = IPC::MakeHeader(2, 2, 0);
cmd_buffer[1] = result; cmd_buffer[1] = result;
cmd_buffer[2] = socket_handle; cmd_buffer[2] = ret;
} }
static void Bind(Interface* self) { static void Bind(Interface* self) {
@ -393,15 +393,15 @@ static void Bind(Interface* self) {
sockaddr sock_addr = CTRSockAddr::ToPlatform(ctr_sock_addr); sockaddr sock_addr = CTRSockAddr::ToPlatform(ctr_sock_addr);
int res = ::bind(socket_handle, &sock_addr, std::max<u32>(sizeof(sock_addr), len)); int ret = ::bind(socket_handle, &sock_addr, std::max<u32>(sizeof(sock_addr), len));
int result = 0; int result = 0;
if (res != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(5, 2, 0); cmd_buffer[0] = IPC::MakeHeader(5, 2, 0);
cmd_buffer[1] = result; cmd_buffer[1] = result;
cmd_buffer[2] = res; cmd_buffer[2] = ret;
} }
static void Fcntl(Interface* self) { static void Fcntl(Interface* self) {
@ -426,8 +426,7 @@ static void Fcntl(Interface* self) {
#else #else
int ret = ::fcntl(socket_handle, F_GETFL, 0); int ret = ::fcntl(socket_handle, F_GETFL, 0);
if (ret == SOCKET_ERROR_VALUE) { if (ret == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); posix_ret = TranslateError(GET_ERRNO);
posix_ret = -1;
return; return;
} }
posix_ret = 0; posix_ret = 0;
@ -439,8 +438,7 @@ static void Fcntl(Interface* self) {
unsigned long tmp = (ctr_arg & 4 /* O_NONBLOCK */) ? 1 : 0; unsigned long tmp = (ctr_arg & 4 /* O_NONBLOCK */) ? 1 : 0;
int ret = ioctlsocket(socket_handle, FIONBIO, &tmp); int ret = ioctlsocket(socket_handle, FIONBIO, &tmp);
if (ret == SOCKET_ERROR_VALUE) { if (ret == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); posix_ret = TranslateError(GET_ERRNO);
posix_ret = -1;
return; return;
} }
auto iter = open_sockets.find(socket_handle); auto iter = open_sockets.find(socket_handle);
@ -449,8 +447,7 @@ static void Fcntl(Interface* self) {
#else #else
int flags = ::fcntl(socket_handle, F_GETFL, 0); int flags = ::fcntl(socket_handle, F_GETFL, 0);
if (flags == SOCKET_ERROR_VALUE) { if (flags == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); posix_ret = TranslateError(GET_ERRNO);
posix_ret = -1;
return; return;
} }
@ -460,15 +457,13 @@ static void Fcntl(Interface* self) {
int ret = ::fcntl(socket_handle, F_SETFL, flags); int ret = ::fcntl(socket_handle, F_SETFL, flags);
if (ret == SOCKET_ERROR_VALUE) { if (ret == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); posix_ret = TranslateError(GET_ERRNO);
posix_ret = -1;
return; return;
} }
#endif #endif
} else { } else {
LOG_ERROR(Service_SOC, "Unsupported command (%d) in fcntl call", ctr_cmd); LOG_ERROR(Service_SOC, "Unsupported command (%d) in fcntl call", ctr_cmd);
result = TranslateError(EINVAL); // TODO: Find the correct error posix_ret = TranslateError(EINVAL); // TODO: Find the correct error
posix_ret = -1;
return; return;
} }
} }
@ -481,7 +476,7 @@ static void Listen(Interface* self) {
int ret = ::listen(socket_handle, backlog); int ret = ::listen(socket_handle, backlog);
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(3, 2, 0); cmd_buffer[0] = IPC::MakeHeader(3, 2, 0);
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -504,7 +499,7 @@ static void Accept(Interface* self) {
int result = 0; int result = 0;
if ((s32)ret == SOCKET_ERROR_VALUE) { if ((s32)ret == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
} else { } else {
CTRSockAddr ctr_addr = CTRSockAddr::FromPlatform(addr); CTRSockAddr ctr_addr = CTRSockAddr::FromPlatform(addr);
Memory::WriteBlock(cmd_buffer[0x104 >> 2], &ctr_addr, sizeof(ctr_addr)); Memory::WriteBlock(cmd_buffer[0x104 >> 2], &ctr_addr, sizeof(ctr_addr));
@ -545,7 +540,7 @@ static void Close(Interface* self) {
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -589,7 +584,7 @@ static void SendTo(Interface* self) {
int result = 0; int result = 0;
if (ret == SOCKET_ERROR_VALUE) if (ret == SOCKET_ERROR_VALUE)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -638,7 +633,7 @@ static void RecvFrom(Interface* self) {
int result = 0; int result = 0;
int total_received = ret; int total_received = ret;
if (ret == SOCKET_ERROR_VALUE) { if (ret == SOCKET_ERROR_VALUE) {
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
total_received = 0; total_received = 0;
} else { } else {
// Write only the data we received to avoid overwriting parts of the buffer with zeros // Write only the data we received to avoid overwriting parts of the buffer with zeros
@ -673,7 +668,7 @@ static void Poll(Interface* self) {
std::vector<pollfd> platform_pollfd(nfds); std::vector<pollfd> platform_pollfd(nfds);
std::transform(ctr_fds.begin(), ctr_fds.end(), platform_pollfd.begin(), CTRPollFD::ToPlatform); std::transform(ctr_fds.begin(), ctr_fds.end(), platform_pollfd.begin(), CTRPollFD::ToPlatform);
const int ret = ::poll(platform_pollfd.data(), nfds, timeout); int ret = ::poll(platform_pollfd.data(), nfds, timeout);
// Now update the output pollfd structure // Now update the output pollfd structure
std::transform(platform_pollfd.begin(), platform_pollfd.end(), ctr_fds.begin(), std::transform(platform_pollfd.begin(), platform_pollfd.end(), ctr_fds.begin(),
@ -683,7 +678,7 @@ static void Poll(Interface* self) {
int result = 0; int result = 0;
if (ret == SOCKET_ERROR_VALUE) if (ret == SOCKET_ERROR_VALUE)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[1] = result; cmd_buffer[1] = result;
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
@ -710,7 +705,7 @@ static void GetSockName(Interface* self) {
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -724,7 +719,7 @@ static void Shutdown(Interface* self) {
int ret = ::shutdown(socket_handle, how); int ret = ::shutdown(socket_handle, how);
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
cmd_buffer[1] = result; cmd_buffer[1] = result;
} }
@ -750,7 +745,7 @@ static void GetPeerName(Interface* self) {
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret; cmd_buffer[2] = ret;
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -777,7 +772,7 @@ static void Connect(Interface* self) {
int ret = ::connect(socket_handle, &input_addr, sizeof(input_addr)); int ret = ::connect(socket_handle, &input_addr, sizeof(input_addr));
int result = 0; int result = 0;
if (ret != 0) if (ret != 0)
result = TranslateError(GET_ERRNO); ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(6, 2, 0); cmd_buffer[0] = IPC::MakeHeader(6, 2, 0);
cmd_buffer[1] = result; cmd_buffer[1] = result;
@ -815,7 +810,7 @@ static void GetSockOpt(Interface* self) {
int optname = TranslateSockOpt(cmd_buffer[3]); int optname = TranslateSockOpt(cmd_buffer[3]);
socklen_t optlen = (socklen_t)cmd_buffer[4]; socklen_t optlen = (socklen_t)cmd_buffer[4];
int ret = -1; int ret = 0;
int err = 0; int err = 0;
if (optname < 0) { if (optname < 0) {
@ -830,9 +825,8 @@ static void GetSockOpt(Interface* self) {
// >> 2 = convert to u32 offset instead of byte offset (cmd_buffer = u32*) // >> 2 = convert to u32 offset instead of byte offset (cmd_buffer = u32*)
char* optval = reinterpret_cast<char*>(Memory::GetPointer(cmd_buffer[0x104 >> 2])); char* optval = reinterpret_cast<char*>(Memory::GetPointer(cmd_buffer[0x104 >> 2]));
ret = ::getsockopt(socket_handle, level, optname, optval, &optlen); err = ::getsockopt(socket_handle, level, optname, optval, &optlen);
err = 0; if (err == SOCKET_ERROR_VALUE) {
if (ret == SOCKET_ERROR_VALUE) {
err = TranslateError(GET_ERRNO); err = TranslateError(GET_ERRNO);
} }
} }
@ -849,7 +843,7 @@ static void SetSockOpt(Interface* self) {
u32 level = cmd_buffer[2]; u32 level = cmd_buffer[2];
int optname = TranslateSockOpt(cmd_buffer[3]); int optname = TranslateSockOpt(cmd_buffer[3]);
int ret = -1; int ret = 0;
int err = 0; int err = 0;
if (optname < 0) { if (optname < 0) {
@ -862,9 +856,8 @@ static void SetSockOpt(Interface* self) {
socklen_t optlen = static_cast<socklen_t>(cmd_buffer[4]); socklen_t optlen = static_cast<socklen_t>(cmd_buffer[4]);
const char* optval = reinterpret_cast<const char*>(Memory::GetPointer(cmd_buffer[8])); const char* optval = reinterpret_cast<const char*>(Memory::GetPointer(cmd_buffer[8]));
ret = static_cast<u32>(::setsockopt(socket_handle, level, optname, optval, optlen)); err = static_cast<u32>(::setsockopt(socket_handle, level, optname, optval, optlen));
err = 0; if (err == SOCKET_ERROR_VALUE) {
if (ret == SOCKET_ERROR_VALUE) {
err = TranslateError(GET_ERRNO); err = TranslateError(GET_ERRNO);
} }
} }