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 <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-11-08 14:42:58 +01:00
1 parent fc84ce6555
commit 60d531f9ef
2 files changed
+27 -4

No files matched your search

+26 -3
View File
@@ -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[] = {