Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
orezraey:fix/net-utilities-measured-ps5
Oct 22, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
orezraey:fix/net-utilities-measured-ps5

Conversation

@orezraey

@orezraey orezraey commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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)

… a PS5

A PS5 (firmware 13.60) allocates with any flag value, zero-fills only for
flag 2 and returns 64-byte aligned blocks. Record the measured behaviour of
sceNetGetIfName, sceNetGetRandom, sceNetGetSystemTime, sceNetMemoryFree and
sceNetUsleep, which already match the console, and keep only their open gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9060 docs/dev/debt/libSceNet.md L28

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5836 core/libs/prx/libSceNet/Export.cpp
core/libs/tests/GuestSceNet.cpp
docs/dev/debt/libSceNet.md
PR 6044 core/libs/tests/GuestSceNet.cpp
PR 6879 core/libs/prx/libSceNet/Export.cpp
PR 7201 core/libs/prx/libSceNet/Export.cpp
PR 8254 core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md

@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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).

@github-actions github-actions Bot added docs prx needs rebase Conflicts with main, rebase needed labels Oct 21, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@Queuse Queuse mentioned this pull request Oct 22, 2026
12 tasks done
@oneandonlydean oneandonlydean self-assigned this Oct 22, 2026
@oneandonlydean
oneandonlydean merged commit 1da03c6 into boykopovar:main Oct 22, 2026
12 checks passed
oneandonlydean pushed a commit that referenced this pull request Oct 25, 2026
After sceNetInit, the console's sceNetUsleep prints
"[LIBNET] usleep <count>" to standard output for a negative count
before failing with EINVAL, as a payload measured on firmware 13.60
(#9076). AnyPS5 failed without printing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants