Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions core/libs/prx/libSceNet/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ struct NetMsghdr {
static_assert(sizeof(NetMsghdr) == 48 && offsetof(NetMsghdr, iov) == 16 && offsetof(NetMsghdr, control) == 32 &&
offsetof(NetMsghdr, flags) == 44);

struct NetResolverAddress {
std::uint32_t address;
std::uint8_t address6[12];
std::uint32_t af;
std::uint32_t reserved[3];
};

struct NetResolverRecords {
NetResolverAddress addrs[10];
std::uint32_t records;
std::uint32_t recordsv4;
std::uint32_t reserved[14];
};
static_assert(sizeof(NetResolverAddress) == 32 && sizeof(NetResolverRecords) == 384 &&
offsetof(NetResolverRecords, records) == 320 && offsetof(NetResolverRecords, recordsv4) == 324);

std::int64_t message_length(const NetMsghdr* message) {
if (!message) return fail(NET_EFAULT);
if (message->iov_length < 0 || message->iov_length > NET_UIO_MAXIOV) return fail(NET_EMSGSIZE);
Expand Down Expand Up @@ -1140,8 +1156,47 @@ int APS5_VABI sceNetResolverAbort(void) {
return 0;
}

int APS5_VABI sceNetResolverStartNtoaMultipleRecords() {
NotImplemented_nid_no_patch(__func__);
int APS5_VABI sceNetResolverStartNtoaMultipleRecords(int rid, const char* hostname, NetResolverRecords* records,
int timeout, int retry, int flags) {
(void)timeout;
(void)retry;
(void)flags;
if (!hostname || !records) return fail(NET_EINVAL);
std::size_t length = 0;
while (length <= 255 && hostname[length] != '\0') ++length;
if (length == 0 || length > 255) return fail(NET_EINVAL);
{
std::lock_guard<std::mutex> lk(g_mutex);
if (g_resolvers.count(rid) == 0) return fail(NET_EBADF);
}
if (!initialize_sockets()) return fail(5);
addrinfo hints{};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
addrinfo* results = nullptr;
const int result = ::getaddrinfo(hostname, nullptr, &hints, &results);
if (result != 0) {
*errno_slot() = result == EAI_AGAIN ? NET_ETIMEDOUT : NET_ENOENT;
log_soft(__func__, "host DNS lookup failed");
set_resolver_error(rid, NET_ERROR_RESOLVER_ENODNS);
return NET_ERROR_RESOLVER_ENODNS;
}
std::memset(records, 0, sizeof(*records));
std::uint32_t count = 0;
for (const addrinfo* entry = results; entry != nullptr && count < 10; entry = entry->ai_next) {
if (entry->ai_family != AF_INET || entry->ai_addr == nullptr) continue;
const auto address = reinterpret_cast<const sockaddr_in*>(entry->ai_addr)->sin_addr.s_addr;
bool seen = false;
for (std::uint32_t i = 0; i < count; ++i) seen = seen || records->addrs[i].address == address;
if (seen) continue;
records->addrs[count].address = static_cast<std::uint32_t>(address);
records->addrs[count].af = NET_AF_INET;
++count;
}
::freeaddrinfo(results);
records->records = count;
records->recordsv4 = count;
set_resolver_error(rid, 0);
return 0;
}

Expand Down
35 changes: 35 additions & 0 deletions core/libs/tests/GuestSceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,24 @@ struct NetMsghdr {
int flags;
};

struct GuestResolverAddress {
std::uint32_t address;
std::uint8_t address6[12];
std::uint32_t af;
std::uint32_t reserved[3];
};

struct GuestResolverRecords {
GuestResolverAddress addrs[10];
std::uint32_t records;
std::uint32_t recordsv4;
std::uint32_t reserved[14];
};

extern "C" {
std::int64_t APS5_VABI sceNetSendmsg(int, const NetMsghdr*, int);
std::int64_t APS5_VABI sceNetRecvmsg(int, NetMsghdr*, int);
int APS5_VABI sceNetResolverStartNtoaMultipleRecords(int, const char*, GuestResolverRecords*, int, int, int);
}

static void Require(bool condition) {
Expand Down Expand Up @@ -306,8 +321,28 @@ int main() {
Require(sceNetResolverStartNtoa(resolver, "localhost", ipv4.data(), 5000000, 1, 0) == 0);
Require(ipv4[0] == 127);
Require(sceNetResolverGetError(resolver, &resolver_error) == 0 && resolver_error == 0);
GuestResolverRecords multiple{};
Require(sceNetResolverStartNtoaMultipleRecords(resolver, "localhost", &multiple, 5000000, 1, 0) == 0);
Require(multiple.records >= 1 && multiple.records <= 10 && multiple.recordsv4 == multiple.records);
Require(multiple.addrs[0].af == 2 && (multiple.addrs[0].address & 0xffu) == 127);
for (std::uint32_t i = 1; i < multiple.records; ++i) {
Require(multiple.addrs[i].af == 2 && multiple.addrs[i].address != 0);
}
Require(sceNetResolverGetError(resolver, &resolver_error) == 0 && resolver_error == 0);
Require(sceNetResolverStartNtoaMultipleRecords(resolver, nullptr, &multiple, 5000000, 1, 0) ==
static_cast<int>(0x80410116) && *sceNetErrnoLoc() == 22);
Require(sceNetResolverStartNtoaMultipleRecords(resolver, "localhost", nullptr, 5000000, 1, 0) ==
static_cast<int>(0x80410116) && *sceNetErrnoLoc() == 22);
Require(sceNetResolverStartNtoaMultipleRecords(resolver, "", &multiple, 5000000, 1, 0) ==
static_cast<int>(0x80410116) && *sceNetErrnoLoc() == 22);
Require(sceNetResolverStartNtoaMultipleRecords(resolver, "guest-sce-net.invalid", &multiple, 5000000, 1, 0) ==
static_cast<int>(0x804101E1));
Require(sceNetResolverGetError(resolver, &resolver_error) == 0 &&
resolver_error == static_cast<int>(0x804101E1));
Require(sceNetResolverGetError(resolver, nullptr) == static_cast<int>(0x80410116) && *sceNetErrnoLoc() == 22);
Require(sceNetResolverDestroy(resolver) == 0);
Require(sceNetResolverStartNtoaMultipleRecords(resolver, "localhost", &multiple, 5000000, 1, 0) ==
static_cast<int>(0x80410109) && *sceNetErrnoLoc() == 9);
resolver_error = -1;
Require(sceNetResolverGetError(resolver, &resolver_error) == static_cast<int>(0x80410109) &&
*sceNetErrnoLoc() == 9 && resolver_error == -1);
Expand Down
2 changes: 2 additions & 0 deletions docs/dev/TechnicalDebt.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Throughout the project, every function at every stage either **does exactly what
- [sceAgcWaitRegMemPatchMask](../../core/libs/prx/libSceAgc/Patch/src/WaitRegMem.cpp) (libSceAgc) - follows `sceAgcWaitRegMemPatchReference`: the mask is taken as a 32-bit value and written to the low mask word of a 32- or 64-bit wait, as [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c) does; [sharpemu](https://github.com/sharpemu/sharpemu/blob/main/src/SharpEmu.Libs/Agc/AgcExports.PacketPatching.cs) writes both words of a 64-bit wait's mask. A mask above 32 bits throws
- [scePsmlMfsr2CreateContext, scePsmlMfsr2CreateSharedResources, scePsmlMfsr2GetContextInitRequirement, scePsmlMfsr2GetDispatchPackets, scePsmlMfsr2GetDispatchPacketsSizeInDwords, scePsmlMfsr2GetSharedResourcesInitRequirement, scePsmlMfsr2Init, scePsmlMfsr2ReleaseContext, scePsmlMfsr2ReleaseSharedResources](../../core/libs/prx/libScePsml_debug/Export.cpp) (libScePsml_mfsr2) - unknown signatures, imported by PPSA23566; declared without parameters
- [sceAgcDcbSetCfRegisterDirect, sceAgcDcbSetCfRegisterRangeDirect](../../core/libs/prx/libSceAgc/DcbState/src/Registers.cpp) (libSceAgc) - signatures follow [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c) and [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Agc/SceAgc.cs), which agree; the SET_CONFIG_REG (0x68) packet is OpenAGC's. The driver does not execute SET_CONFIG_REG, so a submitted packet throws
- PPSA23566 imports declared without parameters, signatures unknown: [sceAudioOut2UserGetSupportedAttributes](../../core/libs/prx/libSceAudioOut/src/AudioOut2System.cpp), [sceConvertKeycodeGetCharacterFromKeyboardData](../../core/libs/prx/libSceConvertKeycode/Export.cpp), [sceHttpSetCookieRecvCallback, sceHttpSetRedirectCallback, sceHttpsGetSslError, sceHttpsSetSslVersion](../../core/libs/prx/libSceHttp/Export.cpp), [sce::Json::MemAllocator::notifyError, sce::Json::Value::clear](../../core/libs/prx/libSceJson2/Export.cpp), [sceNetResolverAbort](../../core/libs/prx/libSceNet/Export.cpp), [sceNpCommerceDialogOpen2](../../core/libs/prx/libSceNpCommerce/Export.cpp), [sceNpEntitlementAccessGetPftFlag](../../core/libs/prx/libSceNpEntitlementAccess/Export.cpp), [sceProprietaryVoiceChatHelper{Initialize,Terminate,SetVoiceChatState,GetVoiceChatUsageState}](../../core/libs/prx/libSceProprietaryVoiceChatHelperPrx/Export.cpp), [sceVoice{GetResourceInfo,ResetPort,EnableChat,DisableChat}](../../core/libs/prx/libSceVoice/Export.cpp). Names from the shadPS4 aerolib NID list
- [sceNetResolverStartNtoaMultipleRecords](../../core/libs/prx/libSceNet/Export.cpp) (libSceNet) - the `(rid, hostname, records, timeout, retry, flags)` signature, the 384-byte records layout (10 records of a 16-byte address union, `af`, 12 bytes of padding, then `records`, `recordsv4` and 56 bytes of padding) and the cleared output follow the [shadPS4](https://github.com/shadps4-emu/shadPS4) reimplementation of the PS4 library, not confirmed on a PS5 title. As for `sceNetResolverStartNtoa`, timeout, retry and flags are ignored: shadPS4 runs the ASYNC flag on a worker thread and skips numeric hostnames for the 0x10000 flag, and a lookup failure returns `RESOLVER_ENODNS`, where shadPS4 separates `RESOLVER_ENOHOST`, `ETIMEDOUT`, `ESERVERFAILURE` and `EINTERNAL`; the lookup is IPv4-only over host DNS, deduplicates addresses and stops at 10 records
- [scePadOpenExt](../../core/libs/prx/libScePad/Export.cpp) (libScePad) - only special ports (type 2) are handled, and they return `DEVICE_NOT_CONNECTED` (0x80920007) because the host has no special controller; whether the console opens a handle and reports the device as disconnected later is unknown. PPSA01317 passes a 16-byte param that names the device by vendor and product id (`b7 0e 04 0e ...` for 0x0eb7:0x0e04) and skips the user on any negative result. Other port types throw
- PPSA23566 imports declared without parameters, signatures unknown: [sceAudioOut2UserGetSupportedAttributes](../../core/libs/prx/libSceAudioOut/src/AudioOut2System.cpp), [sceConvertKeycodeGetCharacterFromKeyboardData](../../core/libs/prx/libSceConvertKeycode/Export.cpp), [sce::Json::MemAllocator::notifyError, sce::Json::Value::clear](../../core/libs/prx/libSceJson2/Export.cpp), [sceNetResolverAbort](../../core/libs/prx/libSceNet/Export.cpp), [sceNpCommerceDialogOpen2](../../core/libs/prx/libSceNpCommerce/Export.cpp), [sceNpEntitlementAccessGetPftFlag](../../core/libs/prx/libSceNpEntitlementAccess/Export.cpp), [sceProprietaryVoiceChatHelper{Initialize,Terminate,SetVoiceChatState,GetVoiceChatUsageState}](../../core/libs/prx/libSceProprietaryVoiceChatHelperPrx/Export.cpp), [sceVoice{GetResourceInfo,ResetPort,EnableChat,DisableChat}](../../core/libs/prx/libSceVoice/Export.cpp). Names from the shadPS4 aerolib NID list
- PPSA01325 imports declared without parameters, signature unknown: [sceRudpActivate](../../core/libs/prx/libSceRudp/Export.cpp). Name from the shadPS4 aerolib NID list
Expand Down
Loading