diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 724c7724e6..153b345f85 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -252,7 +252,7 @@ namespace fmt { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" - const std::size_t len = snprintf(buf_addr, buf_size, fmt, do_unveil(args)...); + const std::size_t len = std::snprintf(buf_addr, buf_size, fmt, do_unveil(args)...); #pragma GCC diagnostic pop diff --git a/rpcs3/Emu/SysCalls/ModuleManager.cpp b/rpcs3/Emu/SysCalls/ModuleManager.cpp index 1cc7ce90a5..a6a2d4b487 100644 --- a/rpcs3/Emu/SysCalls/ModuleManager.cpp +++ b/rpcs3/Emu/SysCalls/ModuleManager.cpp @@ -90,7 +90,7 @@ extern Module sceNpTrophy; extern Module sceNpTus; extern Module sceNpUtil; extern Module sys_io; -extern Module sys_net; +extern Module libnet; extern Module sysPrxForUser; extern Module sys_libc; extern Module sys_lv2dbg; @@ -118,7 +118,7 @@ struct ModuleInfo } const g_module_list[] = { - { 0x0000, "sys_net", &sys_net }, + { 0x0000, "sys_net", &libnet }, { 0x0001, "cellHttp", &cellHttp }, { 0x0002, "cellHttpUtil", &cellHttpUtil }, { 0x0003, "cellSsl", &cellSsl }, diff --git a/rpcs3/Emu/SysCalls/Modules/cellRudp.cpp b/rpcs3/Emu/SysCalls/Modules/cellRudp.cpp index affb101541..f5c4301965 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellRudp.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellRudp.cpp @@ -4,7 +4,6 @@ #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" -#include "sys_net.h" #include "cellRudp.h" extern Module cellRudp; diff --git a/rpcs3/Emu/SysCalls/Modules/cellRudp.h b/rpcs3/Emu/SysCalls/Modules/cellRudp.h index 8eddf2eb27..5a314100a7 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellRudp.h +++ b/rpcs3/Emu/SysCalls/Modules/cellRudp.h @@ -1,5 +1,7 @@ #pragma once +#include "sys_net.h" + namespace vm { using namespace ps3; } // Return Codes @@ -77,7 +79,7 @@ enum CELL_RUDP_POLL_EV_ERROR = 0x0008, }; -using CellRudpEventHandler = s32(s32 event_id, s32 soc, vm::cptr data, u32 datalen, vm::cptr addr, u32 addrlen, vm::ptr arg); +using CellRudpEventHandler = s32(s32 event_id, s32 soc, vm::cptr data, u32 datalen, vm::cptr addr, u32 addrlen, vm::ptr arg); using CellRudpAllocatorFuncAlloc = vm::ptr(u32 size); using CellRudpAllocatorFuncFree = void(vm::ptr ptr); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_net.cpp b/rpcs3/Emu/SysCalls/Modules/sys_net.cpp index 0d039d8b73..7b368a4ec6 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_net.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_net.cpp @@ -2,25 +2,20 @@ #include "Emu/Memory/Memory.h" #include "Emu/SysCalls/Modules.h" +#include "sys_net.h" + #ifdef _WIN32 #include #include #else -extern "C" -{ #include #include #include #include #include -} #endif -#include "sys_net.h" - -extern Module sys_net; - -vm::ptr g_lastError = vm::null; +extern Module libnet; // We map host sockets to sequential IDs to return as FDs because syscalls using // socketselect(), etc. expect socket FDs to be under 1024. @@ -91,252 +86,282 @@ s32 getLastError() #endif } -using pck_len_t = u32; - -namespace sys_net_func +void copy_fdset(fd_set* set, vm::ptr src) { - // Functions - s32 accept(s32 s, vm::ptr addr, vm::ptr paddrlen) + FD_ZERO(set); + + if (src) { - sys_net.Warning("accept(s=%d, family=*0x%x, paddrlen=*0x%x)", s, addr, paddrlen); + // Go through the bit set fds_bits and calculate the + // socket FDs from it, setting it in the native fd-set. + + for (int i = 0; i < 32; i++) + { + for (int bit = 0; bit < 32; bit++) + { + if (src->fds_bits[i] & (1 << bit)) + { + u32 sock = (i << 5) | bit; + //libnet.Error("setting: fd %d", sock); + FD_SET(g_socketMap[sock], set); + } + } + } + } +} + +namespace sys_net +{ + struct tls_data_t + { + be_t _errno; + be_t _h_errno; + }; + + thread_local vm::var g_tls_data; + + // Functions + s32 accept(s32 s, vm::ptr addr, vm::ptr paddrlen) + { + libnet.Warning("accept(s=%d, family=*0x%x, paddrlen=*0x%x)", s, addr, paddrlen); s = g_socketMap[s]; if (!addr) { int ret = ::accept(s, nullptr, nullptr); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } else { - sockaddr _addr; - memcpy(&_addr, addr.get_ptr(), sizeof(sockaddr)); + ::sockaddr _addr; + memcpy(&_addr, addr.get_ptr(), sizeof(::sockaddr)); _addr.sa_family = addr->sa_family; ::socklen_t _paddrlen; s32 ret = ::accept(s, &_addr, &_paddrlen); *paddrlen = _paddrlen; - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } } - s32 bind(s32 s, vm::ptr addr, u32 addrlen) + s32 bind(s32 s, vm::cptr addr, u32 addrlen) { - sys_net.Warning("bind(s=%d, family=*0x%x, addrlen=%d)", s, addr, addrlen); + libnet.Warning("bind(s=%d, family=*0x%x, addrlen=%d)", s, addr, addrlen); s = g_socketMap[s]; - sockaddr_in saddr; - memcpy(&saddr, addr.get_ptr(), sizeof(sockaddr_in)); - saddr.sin_family = addr->sin_family; - const char *ipaddr = inet_ntoa(saddr.sin_addr); - sys_net.Warning("binding on %s to port %d", ipaddr, ntohs(saddr.sin_port)); - s32 ret = ::bind(s, (const sockaddr *)&saddr, addrlen); - *g_lastError = getLastError(); + ::sockaddr_in saddr; + memcpy(&saddr, addr.get_ptr(), sizeof(::sockaddr_in)); + saddr.sin_family = addr->sa_family; + const char *ipaddr = ::inet_ntoa(saddr.sin_addr); + libnet.Warning("binding on %s to port %d", ipaddr, ntohs(saddr.sin_port)); + s32 ret = ::bind(s, (const ::sockaddr*)&saddr, addrlen); + g_tls_data->_errno = getLastError(); return ret; } - s32 connect(s32 s, vm::ptr addr, u32 addrlen) + s32 connect(s32 s, vm::ptr addr, u32 addrlen) { - sys_net.Warning("connect(s=%d, family=*0x%x, addrlen=%d)", s, addr, addrlen); + libnet.Warning("connect(s=%d, family=*0x%x, addrlen=%d)", s, addr, addrlen); s = g_socketMap[s]; - sockaddr_in saddr; - memcpy(&saddr, addr.get_ptr(), sizeof(sockaddr_in)); - saddr.sin_family = addr->sin_family; - const char *ipaddr = inet_ntoa(saddr.sin_addr); - sys_net.Warning("connecting on %s to port %d", ipaddr, ntohs(saddr.sin_port)); - s32 ret = ::connect(s, (const sockaddr *)&saddr, addrlen); - *g_lastError = getLastError(); + ::sockaddr_in saddr; + memcpy(&saddr, addr.get_ptr(), sizeof(::sockaddr_in)); + saddr.sin_family = addr->sa_family; + const char *ipaddr = ::inet_ntoa(saddr.sin_addr); + libnet.Warning("connecting on %s to port %d", ipaddr, ntohs(saddr.sin_port)); + s32 ret = ::connect(s, (const ::sockaddr*)&saddr, addrlen); + g_tls_data->_errno = getLastError(); return ret; } s32 gethostbyaddr() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 gethostbyname() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 getpeername() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 getsockname() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 getsockopt() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } - s32 inet_addr(vm::cptr cp) + u32 inet_addr(vm::cptr cp) { - sys_net.Warning("inet_addr(cp=*0x%x)", cp.addr()); + libnet.Warning("inet_addr(cp=*0x%x)", cp); return htonl(::inet_addr(cp.get_ptr())); // return a big-endian IP address (WTF? function should return LITTLE-ENDIAN value) } s32 inet_aton() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_lnaof() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_makeaddr() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_netof() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_network() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_ntoa() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_ntop() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 inet_pton(s32 af, vm::cptr src, vm::ptr dst) { - sys_net.Warning("inet_pton(af=%d, src=*0x%x, dst=*0x%x)", af, src, dst); + libnet.Warning("inet_pton(af=%d, src=*0x%x, dst=*0x%x)", af, src, dst); return ::inet_pton(af, src.get_ptr(), dst.get_ptr()); } s32 listen(s32 s, s32 backlog) { - sys_net.Warning("listen(s=%d, backlog=%d)", s, backlog); + libnet.Warning("listen(s=%d, backlog=%d)", s, backlog); s = g_socketMap[s]; s32 ret = ::listen(s, backlog); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 recv(s32 s, vm::ptr buf, u32 len, s32 flags) { - sys_net.Warning("recv(s=%d, buf=*0x%x, len=%d, flags=0x%x)", s, buf, len, flags); + libnet.Warning("recv(s=%d, buf=*0x%x, len=%d, flags=0x%x)", s, buf, len, flags); s = g_socketMap[s]; s32 ret = ::recv(s, buf.get_ptr(), len, flags); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } - s32 recvfrom(s32 s, vm::ptr buf, u32 len, s32 flags, vm::ptr addr, vm::ptr paddrlen) + s32 recvfrom(s32 s, vm::ptr buf, u32 len, s32 flags, vm::ptr addr, vm::ptr paddrlen) { - sys_net.Warning("recvfrom(s=%d, buf=*0x%x, len=%d, flags=0x%x, addr=*0x%x, paddrlen=*0x%x)", s, buf, len, flags, addr, paddrlen); + libnet.Warning("recvfrom(s=%d, buf=*0x%x, len=%d, flags=0x%x, addr=*0x%x, paddrlen=*0x%x)", s, buf, len, flags, addr, paddrlen); s = g_socketMap[s]; - sockaddr _addr; - memcpy(&_addr, addr.get_ptr(), sizeof(sockaddr)); + ::sockaddr _addr; + memcpy(&_addr, addr.get_ptr(), sizeof(::sockaddr)); _addr.sa_family = addr->sa_family; ::socklen_t _paddrlen; s32 ret = ::recvfrom(s, buf.get_ptr(), len, flags, &_addr, &_paddrlen); *paddrlen = _paddrlen; - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 recvmsg() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } s32 send(s32 s, vm::cptr buf, u32 len, s32 flags) { - sys_net.Warning("send(s=%d, buf=*0x%x, len=%d, flags=0x%x)", s, buf, len, flags); + libnet.Warning("send(s=%d, buf=*0x%x, len=%d, flags=0x%x)", s, buf, len, flags); s = g_socketMap[s]; s32 ret = ::send(s, buf.get_ptr(), len, flags); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 sendmsg() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } - s32 sendto(s32 s, vm::cptr buf, u32 len, s32 flags, vm::ptr addr, u32 addrlen) + s32 sendto(s32 s, vm::cptr buf, u32 len, s32 flags, vm::ptr addr, u32 addrlen) { - sys_net.Warning("sendto(s=%d, buf=*0x%x, len=%d, flags=0x%x, addr=*0x%x, addrlen=%d)", s, buf, len, flags, addr, addrlen); + libnet.Warning("sendto(s=%d, buf=*0x%x, len=%d, flags=0x%x, addr=*0x%x, addrlen=%d)", s, buf, len, flags, addr, addrlen); s = g_socketMap[s]; - sockaddr _addr; - memcpy(&_addr, addr.get_ptr(), sizeof(sockaddr)); + ::sockaddr _addr; + memcpy(&_addr, addr.get_ptr(), sizeof(::sockaddr)); _addr.sa_family = addr->sa_family; s32 ret = ::sendto(s, buf.get_ptr(), len, flags, &_addr, addrlen); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 setsockopt(s32 s, s32 level, s32 optname, vm::cptr optval, u32 optlen) { - sys_net.Warning("socket(s=%d, level=%d, optname=%d, optval=*0x%x, optlen=%d)", s, level, optname, optval, optlen); + libnet.Warning("socket(s=%d, level=%d, optname=%d, optval=*0x%x, optlen=%d)", s, level, optname, optval, optlen); s = g_socketMap[s]; s32 ret = ::setsockopt(s, level, optname, optval.get_ptr(), optlen); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 shutdown(s32 s, s32 how) { - sys_net.Warning("shutdown(s=%d, how=%d)", s, how); + libnet.Warning("shutdown(s=%d, how=%d)", s, how); s = g_socketMap[s]; s32 ret = ::shutdown(s, how); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 socket(s32 family, s32 type, s32 protocol) { - sys_net.Warning("socket(family=%d, type=%d, protocol=%d)", family, type, protocol); + libnet.Warning("socket(family=%d, type=%d, protocol=%d)", family, type, protocol); s32 sock = ::socket(family, type, protocol); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); g_socketMap.push_back(sock); return g_socketMap.size() - 1; @@ -344,7 +369,7 @@ namespace sys_net_func s32 socketclose(s32 s) { - sys_net.Warning("socket(s=%d)", s); + libnet.Warning("socket(s=%d)", s); s = g_socketMap[s]; #ifdef _WIN32 @@ -352,21 +377,21 @@ namespace sys_net_func #else int ret = ::close(s); #endif - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); return ret; } s32 socketpoll() { - UNIMPLEMENTED_FUNC(sys_net); + UNIMPLEMENTED_FUNC(libnet); return CELL_OK; } - s32 socketselect(s32 nfds, vm::ptr readfds, vm::ptr writefds, vm::ptr exceptfds, vm::ptr timeout) + s32 socketselect(s32 nfds, vm::ptr readfds, vm::ptr writefds, vm::ptr exceptfds, vm::ptr timeout) { - sys_net.Warning("socketselect(nfds=%d, readfds=*0x%x, writefds=*0x%x, exceptfds=*0x%x, timeout=*0x%x)", nfds, readfds, writefds, exceptfds, timeout); + libnet.Warning("socketselect(nfds=%d, readfds=*0x%x, writefds=*0x%x, exceptfds=*0x%x, timeout=*0x%x)", nfds, readfds, writefds, exceptfds, timeout); - timeval _timeout; + ::timeval _timeout; if (timeout) { @@ -374,222 +399,197 @@ namespace sys_net_func _timeout.tv_usec = timeout->tv_usec; } - //sys_net.Error("timeval: %d . %d", _timeout.tv_sec, _timeout.tv_usec); + //libnet.Error("timeval: %d . %d", _timeout.tv_sec, _timeout.tv_usec); - fd_set _readfds; - fd_set _writefds; - fd_set _exceptfds; + ::fd_set _readfds; + ::fd_set _writefds; + ::fd_set _exceptfds; // Copy the fd_sets to native ones - - FD_ZERO(&_readfds); - FD_ZERO(&_writefds); - FD_ZERO(&_exceptfds); - - auto copy_fdset = [](fd_set *set, vm::ptr src) - { - if (src) - { - // Go through the bit set fds_bits and calculate the - // socket FDs from it, setting it in the native fd-set. - - for (int i = 0; i < 32; i++) - { - for (int bit = 0; bit < 32; bit++) - { - if (src->fds_bits[i] & (1 << bit)) - { - u32 sock = (i << 5) | bit; - //sys_net.Error("setting: fd %d", sock); - FD_SET(g_socketMap[sock], set); - } - } - } - } - }; - copy_fdset(&_readfds, readfds); copy_fdset(&_writefds, writefds); copy_fdset(&_exceptfds, exceptfds); s32 ret = ::select(nfds, &_readfds, &_writefds, &_exceptfds, timeout ? &_timeout : NULL); - *g_lastError = getLastError(); + g_tls_data->_errno = getLastError(); if (getLastError() >= 0) { - sys_net.Error("socketselect(): error %d", getLastError()); + libnet.Error("socketselect(): error %d", getLastError()); } //return ret; return CELL_OK; } -} -s32 sys_net_initialize_network_ex(vm::ptr param) -{ - sys_net.Warning("sys_net_initialize_network_ex(param=*0x%x)", param); - g_lastError = vm::ptr::make(vm::alloc(4, vm::main)); + s32 sys_net_initialize_network_ex(vm::ptr param) + { + libnet.Warning("sys_net_initialize_network_ex(param=*0x%x)", param); + #ifdef _WIN32 - WSADATA wsaData; - WORD wVersionRequested = MAKEWORD(2, 2); - WSAStartup(wVersionRequested, &wsaData); + WSADATA wsaData; + WORD wVersionRequested = MAKEWORD(2, 2); + WSAStartup(wVersionRequested, &wsaData); #endif - return CELL_OK; -} + return CELL_OK; + } -s32 sys_net_get_udpp2p_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_udpp2p_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_set_udpp2p_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_set_udpp2p_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_get_lib_name_server() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_lib_name_server() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_if_ctl() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_if_ctl() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_get_netemu_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_netemu_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_get_sockinfo() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_sockinfo() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_close_dump() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_close_dump() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_set_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_set_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_show_nameserver() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_show_nameserver() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -u32 _sys_net_errno_loc() -{ - sys_net.Warning("_sys_net_errno_loc()"); - return g_lastError.addr(); -} + vm::ptr _sys_net_errno_loc() + { + libnet.Warning("_sys_net_errno_loc()"); -s32 sys_net_set_resolver_configurations() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + const vm::ptr tls = g_tls_data; -s32 sys_net_show_route() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + return tls.of(&tls_data_t::_errno); + } -s32 sys_net_read_dump() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_set_resolver_configurations() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_abort_resolver() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_show_route() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_abort_socket() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_read_dump() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_set_lib_name_server() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_abort_resolver() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_get_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_abort_socket() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_get_sockinfo_ex() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_set_lib_name_server() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_open_dump() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_show_ifconfig() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_get_sockinfo_ex() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } + + s32 sys_net_open_dump() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } + + s32 sys_net_show_ifconfig() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } + + s32 sys_net_finalize_network() + { + libnet.Warning("sys_net_initialize_network_ex()"); -s32 sys_net_finalize_network() -{ - sys_net.Warning("sys_net_initialize_network_ex()"); - vm::dealloc(g_lastError.addr(), vm::main); - g_lastError = vm::null; #ifdef _WIN32 - WSACleanup(); + WSACleanup(); #endif - return CELL_OK; -} + return CELL_OK; + } -s32 _sys_net_h_errno_loc() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 _sys_net_h_errno_loc() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_set_netemu_test_param() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; -} + s32 sys_net_set_netemu_test_param() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } -s32 sys_net_free_thread_context() -{ - UNIMPLEMENTED_FUNC(sys_net); - return CELL_OK; + s32 sys_net_free_thread_context() + { + UNIMPLEMENTED_FUNC(libnet); + return CELL_OK; + } } // define additional macro for specific namespace -#define REG_FUNC_(name) add_ppu_func(ModuleFunc(get_function_id(#name), 0, &sys_net, #name, bind_func(sys_net_func::name))) +#define REG_FUNC_(name) add_ppu_func(ModuleFunc(get_function_id(#name), 0, &libnet, #name, bind_func(sys_net::name))) -Module sys_net("sys_net", []() +Module libnet("sys_net", []() { REG_FUNC_(accept); REG_FUNC_(bind); @@ -622,29 +622,29 @@ Module sys_net("sys_net", []() REG_FUNC_(socketpoll); REG_FUNC_(socketselect); - REG_FUNC(sys_net, sys_net_initialize_network_ex); - REG_FUNC(sys_net, sys_net_get_udpp2p_test_param); - REG_FUNC(sys_net, sys_net_set_udpp2p_test_param); - REG_FUNC(sys_net, sys_net_get_lib_name_server); - REG_FUNC(sys_net, sys_net_if_ctl); - REG_FUNC(sys_net, sys_net_get_netemu_test_param); - REG_FUNC(sys_net, sys_net_get_sockinfo); - REG_FUNC(sys_net, sys_net_close_dump); - REG_FUNC(sys_net, sys_net_set_test_param); - REG_FUNC(sys_net, sys_net_show_nameserver); - REG_FUNC(sys_net, _sys_net_errno_loc); - REG_FUNC(sys_net, sys_net_set_resolver_configurations); - REG_FUNC(sys_net, sys_net_show_route); - REG_FUNC(sys_net, sys_net_read_dump); - REG_FUNC(sys_net, sys_net_abort_resolver); - REG_FUNC(sys_net, sys_net_abort_socket); - REG_FUNC(sys_net, sys_net_set_lib_name_server); - REG_FUNC(sys_net, sys_net_get_test_param); - REG_FUNC(sys_net, sys_net_get_sockinfo_ex); - REG_FUNC(sys_net, sys_net_open_dump); - REG_FUNC(sys_net, sys_net_show_ifconfig); - REG_FUNC(sys_net, sys_net_finalize_network); - REG_FUNC(sys_net, _sys_net_h_errno_loc); - REG_FUNC(sys_net, sys_net_set_netemu_test_param); - REG_FUNC(sys_net, sys_net_free_thread_context); + REG_FUNC_(sys_net_initialize_network_ex); + REG_FUNC_(sys_net_get_udpp2p_test_param); + REG_FUNC_(sys_net_set_udpp2p_test_param); + REG_FUNC_(sys_net_get_lib_name_server); + REG_FUNC_(sys_net_if_ctl); + REG_FUNC_(sys_net_get_netemu_test_param); + REG_FUNC_(sys_net_get_sockinfo); + REG_FUNC_(sys_net_close_dump); + REG_FUNC_(sys_net_set_test_param); + REG_FUNC_(sys_net_show_nameserver); + REG_FUNC_(_sys_net_errno_loc); + REG_FUNC_(sys_net_set_resolver_configurations); + REG_FUNC_(sys_net_show_route); + REG_FUNC_(sys_net_read_dump); + REG_FUNC_(sys_net_abort_resolver); + REG_FUNC_(sys_net_abort_socket); + REG_FUNC_(sys_net_set_lib_name_server); + REG_FUNC_(sys_net_get_test_param); + REG_FUNC_(sys_net_get_sockinfo_ex); + REG_FUNC_(sys_net_open_dump); + REG_FUNC_(sys_net_show_ifconfig); + REG_FUNC_(sys_net_finalize_network); + REG_FUNC_(_sys_net_h_errno_loc); + REG_FUNC_(sys_net_set_netemu_test_param); + REG_FUNC_(sys_net_free_thread_context); }); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_net.h b/rpcs3/Emu/SysCalls/Modules/sys_net.h index 070f161d1b..f704539f09 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_net.h +++ b/rpcs3/Emu/SysCalls/Modules/sys_net.h @@ -2,42 +2,127 @@ namespace vm { using namespace ps3; } -struct sys_net_initialize_parameter +// must die +#undef s_addr + +namespace sys_net { - be_t memory_addr; + // only for reference, no need to use it + using in_addr_t = u32; + using in_port_t = u16; + using sa_family_t = u8; + using socklen_t = u32; + + struct fd_set + { + be_t fds_bits[32]; + }; + + struct hostent + { + vm::bptr h_name; + vm::bpptr h_aliases; + be_t h_addrtype; + be_t h_length; + vm::bpptr h_addr_list; + }; + + struct in_addr + { + be_t s_addr; + }; + + struct iovec + { + be_t zero1; + vm::bptr iov_base; + be_t zero2; + be_t iov_len; + }; + + struct ip_mreq + { + be_t imr_multiaddr; + be_t imr_interface; + }; + + struct msghdr + { + be_t zero1; + vm::bptr msg_name; + be_t msg_namelen; + be_t pad1; + be_t zero2; + vm::bptr msg_iov; + be_t msg_iovlen; + be_t pad2; + be_t zero3; + vm::bptr msg_control; + be_t msg_controllen; + be_t msg_flags; + }; + + struct pollfd + { + be_t fd; + be_t events; + be_t revents; + }; + + struct sockaddr + { + u8 sa_len; + u8 sa_family; + char sa_data[14]; + }; + + struct sockaddr_dl + { + u8 sdl_len; + u8 sdl_family; + be_t sdl_index; + u8 sdl_type; + u8 sdl_nlen; + u8 sdl_alen; + u8 sdl_slen; + char sdl_data[12]; + }; + + struct sockaddr_in + { + u8 sin_len; + u8 sin_family; + be_t sin_port; + be_t sin_addr; + char sin_zero[8]; + }; + + struct sockaddr_in_p2p + { + u8 sin_len; + u8 sin_family; + be_t sin_port; + be_t sin_addr; + be_t sin_vport; + char sin_zero[6]; + }; + + struct timeval + { + be_t tv_sec; + be_t tv_usec; + }; +} + +struct sys_net_initialize_parameter_t +{ + vm::bptr memory; be_t memory_size; be_t flags; }; -// The names of the following structs are modified to avoid overloading problems -struct sys_net_sockaddr +// PS3 libnet socket struct +struct net_socket_t { - u8 sa_len; - u8 sa_family; // sa_family_t - u8 sa_data[14]; -}; - -struct sys_net_sockaddr_in -{ - u8 sin_len; - u8 sin_family; - be_t sin_port; - be_t sa_addr; // struct in_addr - u8 unused[8]; -}; - -struct sys_net_in_addr -{ - be_t sa_addr; -}; - -struct sys_net_fd_set -{ - be_t fds_bits[32]; -}; - -struct sys_net_timeval -{ - be_t tv_sec; - be_t tv_usec; + std::intptr_t native_handle; }; diff --git a/rpcs3/Emu/SysCalls/SC_FUNC.h b/rpcs3/Emu/SysCalls/SC_FUNC.h index b23398e56f..50bd1d1d7b 100644 --- a/rpcs3/Emu/SysCalls/SC_FUNC.h +++ b/rpcs3/Emu/SysCalls/SC_FUNC.h @@ -33,9 +33,9 @@ namespace ppu_func_detail static_assert(!std::is_reference::value, "Invalid function argument type (reference)"); static_assert(sizeof(T) <= 8, "Invalid function argument type for ARG_GENERAL"); - static force_inline T get_arg(PPUThread& CPU) + static force_inline T get_arg(PPUThread& ppu) { - return cast_from_ppu_gpr(CPU.GPR[g_count + 2]); + return cast_from_ppu_gpr(ppu.GPR[g_count + 2]); } }; @@ -44,9 +44,9 @@ namespace ppu_func_detail { static_assert(sizeof(T) <= 8, "Invalid function argument type for ARG_FLOAT"); - static force_inline T get_arg(PPUThread& CPU) + static force_inline T get_arg(PPUThread& ppu) { - return static_cast(CPU.FPR[f_count]); + return static_cast(ppu.FPR[f_count]); } }; @@ -55,9 +55,9 @@ namespace ppu_func_detail { static_assert(std::is_same, v128>::value, "Invalid function argument type for ARG_VECTOR"); - static force_inline T get_arg(PPUThread& CPU) + static force_inline T get_arg(PPUThread& ppu) { - return CPU.VPR[v_count + 1]; + return ppu.VPR[v_count + 1]; } }; @@ -68,10 +68,10 @@ namespace ppu_func_detail static_assert(v_count <= 12, "TODO: Unsupported stack argument type (vector)"); static_assert(sizeof(T) <= 8, "Invalid function argument type for ARG_STACK"); - static force_inline T get_arg(PPUThread& CPU) + static force_inline T get_arg(PPUThread& ppu) { // TODO: check stack argument displacement - const u64 res = CPU.get_stack_arg(8 + std::max(g_count - 8, 0) + std::max(f_count - 13, 0) + std::max(v_count - 12, 0)); + const u64 res = ppu.get_stack_arg(8 + std::max(g_count - 8, 0) + std::max(f_count - 13, 0) + std::max(v_count - 12, 0)); return cast_from_ppu_gpr(res); } }; @@ -81,9 +81,9 @@ namespace ppu_func_detail { static_assert(std::is_same::value, "Invalid function argument type for ARG_CONTEXT"); - static force_inline PPUThread& get_arg(PPUThread& CPU) + static force_inline PPUThread& get_arg(PPUThread& ppu) { - return CPU; + return ppu; } }; @@ -92,7 +92,7 @@ namespace ppu_func_detail { static_assert(std::is_same::value, "Invalid function argument type for ARG_VARIADIC"); - static force_inline ppu_va_args_t get_arg(PPUThread& CPU) + static force_inline ppu_va_args_t get_arg(PPUThread& ppu) { return{ g_count, f_count, v_count }; } @@ -104,9 +104,9 @@ namespace ppu_func_detail static_assert(type == ARG_GENERAL, "Unknown function result type"); static_assert(sizeof(T) <= 8, "Invalid function result type for ARG_GENERAL"); - static force_inline void put_result(PPUThread& CPU, const T& result) + static force_inline void put_result(PPUThread& ppu, const T& result) { - CPU.GPR[3] = cast_to_ppu_gpr(result); + ppu.GPR[3] = cast_to_ppu_gpr(result); } }; @@ -115,9 +115,9 @@ namespace ppu_func_detail { static_assert(sizeof(T) <= 8, "Invalid function result type for ARG_FLOAT"); - static force_inline void put_result(PPUThread& CPU, const T& result) + static force_inline void put_result(PPUThread& ppu, const T& result) { - CPU.FPR[1] = static_cast(result); + ppu.FPR[1] = static_cast(result); } }; @@ -126,9 +126,9 @@ namespace ppu_func_detail { static_assert(std::is_same, v128>::value, "Invalid function result type for ARG_VECTOR"); - static force_inline void put_result(PPUThread& CPU, const T& result) + static force_inline void put_result(PPUThread& ppu, const T& result) { - CPU.VPR[2] = result; + ppu.VPR[2] = result; } }; @@ -153,21 +153,21 @@ namespace ppu_func_detail // argument type + g/f/v_count unpacker template struct bind_arg_packed { - static force_inline T get_arg(PPUThread& CPU) + static force_inline T get_arg(PPUThread& ppu) { - return bind_arg(type_pack & 0xff), (type_pack >> 8) & 0xff, (type_pack >> 16) & 0xff, (type_pack >> 24)>::get_arg(CPU); + return bind_arg(type_pack & 0xff), (type_pack >> 8) & 0xff, (type_pack >> 16) & 0xff, (type_pack >> 24)>::get_arg(ppu); } }; template - force_inline RT call(PPUThread& CPU, RT(*func)(Args...), arg_info_pack_t) + force_inline RT call(PPUThread& ppu, RT(*func)(Args...), arg_info_pack_t) { // do the actual function call when all arguments are prepared (simultaneous unpacking of Args... and Info...) - return func(bind_arg_packed::get_arg(CPU)...); + return func(bind_arg_packed::get_arg(ppu)...); } template - force_inline RT call(PPUThread& CPU, RT(*func)(Args...), arg_info_pack_t info) + force_inline RT call(PPUThread& ppu, RT(*func)(Args...), arg_info_pack_t info) { // unpack previous type counts (0/0/0 for the first time) const u32 g_count = (info.last_value >> 8) & 0xff; @@ -193,7 +193,7 @@ namespace ppu_func_detail const u32 f = f_count + is_float; const u32 v = v_count + is_vector; - return call(CPU, func, arg_info_pack_t{}); + return call(ppu, func, arg_info_pack_t{}); } template struct result_type @@ -212,9 +212,9 @@ namespace ppu_func_detail { using func_t = void(*)(T...); - static force_inline void do_call(PPUThread& CPU, func_t func) + static force_inline void do_call(PPUThread& ppu, func_t func) { - call(CPU, func, arg_info_pack_t<>{}); + call(ppu, func, arg_info_pack_t<>{}); } }; @@ -223,16 +223,16 @@ namespace ppu_func_detail { using func_t = RT(*)(T...); - static force_inline void do_call(PPUThread& CPU, func_t func) + static force_inline void do_call(PPUThread& ppu, func_t func) { - bind_result::value>::put_result(CPU, call(CPU, func, arg_info_pack_t<>{})); + bind_result::value>::put_result(ppu, call(ppu, func, arg_info_pack_t<>{})); } }; } -template force_inline void call_ppu_func(PPUThread& CPU, RT(*func)(T...)) +template force_inline void call_ppu_func(PPUThread& ppu, RT(*func)(T...)) { - ppu_func_detail::func_binder::do_call(CPU, func); + ppu_func_detail::func_binder::do_call(ppu, func); } -#define bind_func(func) [](PPUThread& CPU){ call_ppu_func(CPU, func); } +#define bind_func(func) [](PPUThread& ppu){ call_ppu_func(ppu, func); }