From fa332e13deca32ef5bb636127b8b5aee538419fb Mon Sep 17 00:00:00 2001 From: Gliniak Date: Wed, 17 Nov 2021 22:00:34 +0100 Subject: [PATCH] [XAM/Net] Removed hardcoded WSA error codes --- src/xenia/kernel/xam/xam_net.cc | 51 ++++++++++++--------------------- src/xenia/kernel/xsocket.h | 8 ++++++ 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/xenia/kernel/xam/xam_net.cc b/src/xenia/kernel/xam/xam_net.cc index 014c61533..6fc3db0cc 100644 --- a/src/xenia/kernel/xam/xam_net.cc +++ b/src/xenia/kernel/xam/xam_net.cc @@ -211,13 +211,13 @@ dword_result_t NetDll_XNetGetOpt_entry(dword_t one, dword_t option_id, case 1: if (*buffer_size < sizeof(XNetStartupParams)) { *buffer_size = sizeof(XNetStartupParams); - return 0x2738; // WSAEMSGSIZE + return uint32_t(X_WSAError::X_WSAEMSGSIZE); } std::memcpy(buffer_ptr, &xnet_startup_params, sizeof(XNetStartupParams)); return 0; default: XELOGE("NetDll_XNetGetOpt: option {} unimplemented", option_id); - return 0x2726; // WSAEINVAL + return uint32_t(X_WSAError::X_WSAEINVAL); } } DECLARE_XAM_EXPORT1(NetDll_XNetGetOpt, kNetworking, kSketchy); @@ -326,8 +326,7 @@ dword_result_t NetDll_WSASendTo_entry( auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -363,7 +362,7 @@ dword_result_t NetDll_WSAWaitForMultipleEvents_entry(dword_t num_events, dword_t timeout, dword_t alertable) { if (num_events > 64) { - XThread::SetLastError(87); // ERROR_INVALID_PARAMETER + XThread::SetLastError(uint32_t(X_WSAError::X_WSA_INVALID_PARAMETER)); return ~0u; } @@ -645,8 +644,7 @@ dword_result_t NetDll_closesocket_entry(dword_t caller, dword_t socket_handle) { auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -663,8 +661,7 @@ int_result_t NetDll_shutdown_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -682,8 +679,7 @@ dword_result_t NetDll_setsockopt_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -697,8 +693,7 @@ dword_result_t NetDll_ioctlsocket_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -719,8 +714,7 @@ dword_result_t NetDll_bind_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -741,8 +735,7 @@ dword_result_t NetDll_connect_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -762,8 +755,7 @@ dword_result_t NetDll_listen_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -781,16 +773,14 @@ dword_result_t NetDll_accept_entry(dword_t caller, dword_t socket_handle, pointer_t addr_ptr, lpdword_t addrlen_ptr) { if (!addr_ptr) { - // WSAEFAULT - XThread::SetLastError(0x271E); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAEFAULT)); return -1; } auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -922,8 +912,7 @@ dword_result_t NetDll_recv_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -939,8 +928,7 @@ dword_result_t NetDll_recvfrom_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -976,8 +964,7 @@ dword_result_t NetDll_send_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -993,8 +980,7 @@ dword_result_t NetDll_sendto_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } @@ -1024,8 +1010,7 @@ dword_result_t NetDll_getsockname_entry(dword_t caller, dword_t socket_handle, auto socket = kernel_state()->object_table()->LookupObject(socket_handle); if (!socket) { - // WSAENOTSOCK - XThread::SetLastError(0x2736); + XThread::SetLastError(uint32_t(X_WSAError::X_WSAENOTSOCK)); return -1; } diff --git a/src/xenia/kernel/xsocket.h b/src/xenia/kernel/xsocket.h index 6185e3338..b0b528847 100644 --- a/src/xenia/kernel/xsocket.h +++ b/src/xenia/kernel/xsocket.h @@ -19,6 +19,14 @@ namespace xe { namespace kernel { +enum class X_WSAError : uint32_t { + X_WSA_INVALID_PARAMETER = 0x0057, + X_WSAEFAULT = 0x271E, + X_WSAEINVAL = 0x2726, + X_WSAENOTSOCK = 0x2736, + X_WSAEMSGSIZE = 0x2738, +}; + struct XSOCKADDR { xe::be address_family; char sa_data[14];