From 60d531f9ef01beb912e65dd6b9fe7a9f25d41e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 8 Nov 2026 12:37:19 +0100 Subject: [PATCH] sceNetAdhoc: Take a PdpRecv buffer that runs past the end of memory Since 74178a8106 the PdpRecv syscall wants the game's whole buffer length to be valid memory. Gods Eater Burst receives into the end of the scratchpad (0x00013800) with a length of 2049, one byte past it, so every receive failed with INVALID_ARG and its multiplayer session never got the other side's datagrams. A PSP takes such a buffer, and with nothing waiting leaves the length alone (pspautotests net/adhoc/pdp). Handle it the way 185bbd5b5d does for PtpRecv: receive no more than fits in memory, and give the game its length back if the call fails without waiting. Co-Authored-By: Claude Opus 5.5 --- Core/HLE/sceNetAdhoc.cpp | 29 ++++++++++++++++++++++++++--- pspautotests | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 299408c467..df6f408b31 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -4995,10 +4995,33 @@ static int sceNetAdhocPdpSendSyscall(MIPSState *mips, int id, u32 macAddr, u32 p } static int sceNetAdhocPdpRecvSyscall(MIPSState *mips, int id, u32 macAddr, u32 portAddr, u32 bufAddr, u32 lenAddr, u32 timeout, u32 flag) { - void *len = GuestBuffer(lenAddr, 4); - void *buf = GuestBuffer(bufAddr, len ? *(s32_le *)len : 0); + s32_le *len = (s32_le *)GuestBuffer(lenAddr, 4); // NULL for the sender's MAC and port is fine. - return sceNetAdhocPdpRecv(mips, id, macAddr ? GuestBuffer(macAddr, ETHER_ADDR_LEN) : nullptr, portAddr ? GuestBuffer(portAddr, 2) : nullptr, buf, len, timeout, (int)flag); + void *mac = macAddr ? GuestBuffer(macAddr, ETHER_ADDR_LEN) : nullptr; + void *port = portAddr ? GuestBuffer(portAddr, 2) : nullptr; + if (!len || *len <= 0 || !Memory::IsValidAddress(bufAddr)) { + void *buf = len ? GuestBuffer(bufAddr, *len) : nullptr; + return sceNetAdhocPdpRecv(mips, id, mac, port, buf, len, timeout, (int)flag); + } + // The buffer may run past the end of memory: Gods Eater Burst receives into the scratchpad's last + // 2048 bytes with a length of 2049, and a PSP takes it (pspautotests net/adhoc/pdp). Receive no more + // than fits, as PtpRecv does. A blocking recv keeps the pointer, so the clamp goes into the game's + // length, and a call that fails without waiting or touching the length gets the game's back. + void *buf = Memory::GetPointerWriteUnchecked(bufAddr); + const s32 requested = *len; + const s32 valid = (s32)Memory::ClampValidSizeAt(bufAddr, (u32)requested); + if (valid == requested) { + return sceNetAdhocPdpRecv(mips, id, mac, port, buf, len, timeout, (int)flag); + } + *len = valid; + int result = sceNetAdhocPdpRecv(mips, id, mac, port, buf, len, timeout, (int)flag); + const bool waiting = std::any_of(adhocSocketRequests.begin(), adhocSocketRequests.end(), [&](const auto &it) { + return it.second.length == len; + }); + if (result != 0 && !waiting && *len == valid) { + *len = requested; + } + return result; } const HLEFunction sceNetAdhoc[] = { diff --git a/pspautotests b/pspautotests index 7442ae4d2c..ecf1ea59b7 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 7442ae4d2c38a201f03e3a6b68d22a9b242f21c7 +Subproject commit ecf1ea59b7d2f125d4d20980602d49dd9aae0d16