fix(libSceNet): accept every sceNetMemoryAllocate flag as measured on a PS5 #9076

Merged
orezraey merged 2 commits from upstream-pr/9076 into main 2026-10-22 20:22:22 +00:00
orezraey commented 2026-10-21 11:51:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-21T11:51:22Z.


What

On main, sceNetMemoryAllocate takes an int32_t size and throws for flag 4 (the pool reserve bypass), since AnyPS5 has no network pool. In a payload process on a PS5 (firmware 13.60):

sceNetMemoryAllocate case Payload process, firmware 13.60 main before this PR here now
flag 4 a block, no zero fill std::runtime_error a block, no zero fill
flags 1, 8, 0x10, 0x100, 0x80000000 (and 1<<32 in the register) a block, no zero fill a block a block
flag 3 a zero-filled block a zero-filled block a zero-filled block
alignment, sizes 1 to 65536 always 64-byte aligned the heap's minimum (32) 64
size 0, -1, INT64_MIN (flags 0 or 2) null, sceNetErrnoLoc unchanged null null, errno unchanged (now tested)

Flag 4 only lets an allocation dip into the pool's reserve. AnyPS5 allocates from the guest heap and enforces no pool or reserve, so a flag 4 allocation succeeds exactly as one without it does, which is what the console shows away from the reserve. The probe's sizes do not tell an int32_t size from an int64_t one (INT64_MIN has a zero low half), so this PR keeps main's int32_t.

The same probe measured the other small utilities whose debt entries said "unverified on hardware". They already matched:

  • sceNetGetIfName gives the 10 names for indexes 0 to 9 and an empty string with errno 22 past them, with a 32-bit index.
  • sceNetGetRandom writes exactly 4 bytes and fails with 22 for a null output.
  • sceNetGetSystemTime gives microseconds equal to sceKernelGetProcessTime and ignores a null output.
  • sceNetMemoryFree(NULL) does nothing.
  • sceNetUsleep takes a signed 32-bit count and fails with 22 when it is negative.
  • sceNetEtherNtostr's results and errors.

On every failure the console returns 0x80410100 | errno and sets sceNetErrnoLoc, and a successful call leaves it unchanged; AnyPS5's fail() already does this. Results were the same before and after sceNetInit (which returned 0).

Debt: main already removed the sceNetGetIfName and sceNetGetSystemTime entries and rewrote sceNetGetRandom's. This PR:

  • extends main's sceNetMemoryAllocate and sceNetMemoryFree entry with the measured cases, the 0xdd bytes a non-zero-filled block holds on the console, what happens when the pool runs out, and why flag 4 no longer throws;
  • adds a Functional entry for sceNetUsleep: the [LIBNET] usleep <n> line the console prints for a negative count, and what an interrupted sleep returns.

Tests: guest_sce_net checks:

  • every measured flag, including flag 4 and the zero fill for flags 2, 3 and 6;
  • the 64-byte alignment;
  • errno left unchanged by a null result and by a successful sceNetGetRandom;
  • the 4-byte write of sceNetGetRandom;
  • sceNetUsleep(INT32_MIN).

Related: open PR #8204 implements sceNetEtherStrton, which this PR does not touch. The same probe measured it, and the console does not validate its input; see the log.

How the console was measured

  • Setup:
    • The console runs firmware 13.60 and is jailbroken.
    • The probe is an ELF payload built with ps5-payload-dev/sdk v0.44 and clang 18.1.8 and started through elfldr, so it ran in a payload process, not in a title.
  • Provenance: libSceNet.sprx was loaded with dlopen, and every function was taken from it with dlsym.
  • Method:
    • Outputs are pre-filled with ~ or 0x5a, and sceNetErrnoLoc is preset to 90 before each call.
    • Each allocation logs whether the block is 16- and 64-byte aligned, whether it is all zero and its first byte.
    • Sleeps are short (at most 20 ms) and timed with sceKernelGetProcessTime.
  • Files: the probe source and full log are in this gist.
Console output (excerpt, copied unchanged)
netutil: meta fw=0x13600007 pid=154 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 21 2026 08:21:24 log=/data/anyps5-probes/netutil.log
netutil: case alloc zero size=0 flags=0x0 ret=null errno=90 align16=0 align64=0
netutil: case alloc minus1 size=-1 flags=0x0 ret=null errno=90 align16=0 align64=0
netutil: case alloc min size=-9223372036854775808 flags=0x0 ret=null errno=90 align16=0 align64=0
netutil: case alloc small size=16 flags=0x0 ret=block errno=90 align16=1 align64=1
netutil: case alloc small size=16 flags=0x0 all_zero=0 first=dd
netutil: case alloc flag1 size=16 flags=0x1 ret=block errno=90 align16=1 align64=1
netutil: case alloc flag3 size=16 flags=0x3 all_zero=1 first=00
netutil: case alloc flag4 size=16 flags=0x4 ret=block errno=90 align16=1 align64=1
netutil: case alloc flag_high size=16 flags=0x80000000 all_zero=0 first=dd
netutil: case alloc page size=4096 flags=0x2 all_zero=1 first=00
netutil: case ifname index=0x0 string="lo0" len=3 module=libSceNet.sprx

Tested

Windows 11, WinLibs GCC 15.2.0, Release: guest_sce_net passes, also after the merge of main in da0ed3b5c3. Not tested on Linux or with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951076215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9076). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-21T11:51:22Z. --- ### What On `main`, `sceNetMemoryAllocate` takes an `int32_t` size and throws for flag 4 (the pool reserve bypass), since AnyPS5 has no network pool. In a payload process on a PS5 (firmware 13.60): | `sceNetMemoryAllocate` case | Payload process, firmware 13.60 | `main` before this PR | here now | |---|---|---|---| | flag 4 | a block, no zero fill | `std::runtime_error` | a block, no zero fill | | flags 1, 8, 0x10, 0x100, 0x80000000 (and 1<<32 in the register) | a block, no zero fill | a block | a block | | flag 3 | a zero-filled block | a zero-filled block | a zero-filled block | | alignment, sizes 1 to 65536 | always 64-byte aligned | the heap's minimum (32) | 64 | | size 0, -1, `INT64_MIN` (flags 0 or 2) | null, `sceNetErrnoLoc` unchanged | null | null, errno unchanged (now tested) | Flag 4 only lets an allocation dip into the pool's reserve. AnyPS5 allocates from the guest heap and enforces no pool or reserve, so a flag 4 allocation succeeds exactly as one without it does, which is what the console shows away from the reserve. The probe's sizes do not tell an `int32_t` size from an `int64_t` one (`INT64_MIN` has a zero low half), so this PR keeps `main`'s `int32_t`. The same probe measured the other small utilities whose debt entries said "unverified on hardware". They already matched: - `sceNetGetIfName` gives the 10 names for indexes 0 to 9 and an empty string with errno 22 past them, with a 32-bit index. - `sceNetGetRandom` writes exactly 4 bytes and fails with 22 for a null output. - `sceNetGetSystemTime` gives microseconds equal to `sceKernelGetProcessTime` and ignores a null output. - `sceNetMemoryFree(NULL)` does nothing. - `sceNetUsleep` takes a signed 32-bit count and fails with 22 when it is negative. - `sceNetEtherNtostr`'s results and errors. On every failure the console returns `0x80410100 | errno` and sets `sceNetErrnoLoc`, and a successful call leaves it unchanged; AnyPS5's `fail()` already does this. Results were the same before and after `sceNetInit` (which returned 0). **Debt:** `main` already removed the `sceNetGetIfName` and `sceNetGetSystemTime` entries and rewrote `sceNetGetRandom`'s. This PR: - extends `main`'s `sceNetMemoryAllocate and sceNetMemoryFree` entry with the measured cases, the `0xdd` bytes a non-zero-filled block holds on the console, what happens when the pool runs out, and why flag 4 no longer throws; - adds a Functional entry for `sceNetUsleep`: the `[LIBNET] usleep <n>` line the console prints for a negative count, and what an interrupted sleep returns. **Tests:** `guest_sce_net` checks: - every measured flag, including flag 4 and the zero fill for flags 2, 3 and 6; - the 64-byte alignment; - errno left unchanged by a null result and by a successful `sceNetGetRandom`; - the 4-byte write of `sceNetGetRandom`; - `sceNetUsleep(INT32_MIN)`. **Related:** open PR #8204 implements `sceNetEtherStrton`, which this PR does not touch. The same probe measured it, and the console does not validate its input; see the log. #### How the console was measured - **Setup:** - The console runs firmware 13.60 and is jailbroken. - The probe is an ELF payload built with [ps5-payload-dev/sdk](https://github.com/ps5-payload-dev/sdk) v0.44 and clang 18.1.8 and started through elfldr, so it ran in a payload process, not in a title. - **Provenance:** `libSceNet.sprx` was loaded with `dlopen`, and every function was taken from it with `dlsym`. - **Method:** - Outputs are pre-filled with `~` or 0x5a, and `sceNetErrnoLoc` is preset to 90 before each call. - Each allocation logs whether the block is 16- and 64-byte aligned, whether it is all zero and its first byte. - Sleeps are short (at most 20 ms) and timed with `sceKernelGetProcessTime`. - **Files:** the probe source and full log are in [this gist](https://gist.github.com/orezraey/789290577123af3c45b340d6db6f395c). <details><summary>Console output (excerpt, copied unchanged)</summary> ``` netutil: meta fw=0x13600007 pid=154 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 21 2026 08:21:24 log=/data/anyps5-probes/netutil.log netutil: case alloc zero size=0 flags=0x0 ret=null errno=90 align16=0 align64=0 netutil: case alloc minus1 size=-1 flags=0x0 ret=null errno=90 align16=0 align64=0 netutil: case alloc min size=-9223372036854775808 flags=0x0 ret=null errno=90 align16=0 align64=0 netutil: case alloc small size=16 flags=0x0 ret=block errno=90 align16=1 align64=1 netutil: case alloc small size=16 flags=0x0 all_zero=0 first=dd netutil: case alloc flag1 size=16 flags=0x1 ret=block errno=90 align16=1 align64=1 netutil: case alloc flag3 size=16 flags=0x3 all_zero=1 first=00 netutil: case alloc flag4 size=16 flags=0x4 ret=block errno=90 align16=1 align64=1 netutil: case alloc flag_high size=16 flags=0x80000000 all_zero=0 first=dd netutil: case alloc page size=4096 flags=0x2 all_zero=1 first=00 netutil: case ifname index=0x0 string="lo0" len=3 module=libSceNet.sprx ``` </details> ### Tested Windows 11, WinLibs GCC 15.2.0, Release: `guest_sce_net` passes, also after the merge of `main` in `da0ed3b5c3`. Not tested on Linux or with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
xXPBSXx commented 2026-10-21 13:43:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T13:43:56Z.


Linux data point for c5df2f4ce0: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main) (its merge-base is 47fa6eecf).

  • With the PR: ctest -R '^guest_sce_net$' passes 3 of 3.
  • With the production files of the PR restored to the merge-base (core/libs/prx/libSceNet/Export.cpp; the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6317608495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9076#issuecomment-6317608495). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T13:43:56Z. --- Linux data point for `c5df2f4ce0`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`) (its merge-base is `47fa6eecf`). - With the PR: `ctest -R '^guest_sce_net$'` passes 3 of 3. - With the production files of the PR restored to the merge-base (`core/libs/prx/libSceNet/Export.cpp`; the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9076
No description provided.