feat(libkernel): export sceKernelInternalMemoryGetAvailableSize #4530

Merged
babyhuey merged 1 commit from upstream-pr/4530 into main 2026-10-12 22:16:18 +00:00
babyhuey commented 2026-10-12 14:36:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T14:36:44Z.


What

Exports sceKernelInternalMemoryGetAvailableSize (rjEuM0nb8xg) in libkernel, next to sceKernelAvailableFlexibleMemorySize. It writes 0 and returns 0, and returns EINVAL for a null pointer as its siblings do. It is a silent stub, listed in TechnicalDebt: nothing public says what the console's internal memory pool holds or how big it is.

The name is the one tools/nid_names.py's aerolib list gives for the NID. The int (size_t*) signature is from xUtilty (PS4).

PS5SX2 (PPSA99203) calls it once while starting its GS renderer, GS.cpp L233-L247:

long long internal_avail = 0;
sceKernelAvailableFlexibleMemorySize(&flex_avail);
sceKernelInternalMemoryGetAvailableSize(&internal_avail);
void* testp = malloc(sizeof(GSRendererNull));

The result is never read.

Where a title reaches it

PS5SX2 relinks only with --trap-sdk-syscall-stubs (#3804, see #2136), which these runs use. It reaches this import after #4466 (sceKernelGetMainSocId and friends) and a setitimer PR (#4382 was used here; #3800 also implements it). On a stack of main 8fa5cc48 + #4466 + #4382:

  • Without this PR, it stops here on both systems:
    • Linux: undefined symbol: rjEuM0nb8xg
    • Windows: FAIL: unresolved ELF import rjEuM0nb8xg from libkernel.prx
  • With this PR, it moves to avvJ3J0H0EY (sceKernelJitCreateSharedMemory, which #3787 implements) on both:
    • Linux: undefined symbol: avvJ3J0H0EY
    • Windows: FAIL: unresolved ELF import avvJ3J0H0EY from libkernel.prx

Tested

Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, on 664160b5: guest_memory passes 5/5 (--repeat until-fail:5) on both. No warnings in DirectMemory/Export.cpp or GuestMemory.cpp. The new check covers both behaviours: the call writes 0 and returns 0, and a null pointer returns EINVAL.

check_conventions.py passes.

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 in TechnicalDebt
  • 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: a setitimer PR (#4382 or #3800) for PS5SX2 to reach it (#4466 has merged); the code itself builds and passes alone on main
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830927496 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T14:36:44Z. --- ### What Exports `sceKernelInternalMemoryGetAvailableSize` (`rjEuM0nb8xg`) in libkernel, next to `sceKernelAvailableFlexibleMemorySize`. It writes 0 and returns 0, and returns `EINVAL` for a null pointer as its siblings do. It is a silent stub, listed in TechnicalDebt: nothing public says what the console's internal memory pool holds or how big it is. The name is the one `tools/nid_names.py`'s aerolib list gives for the NID. The `int (size_t*)` signature is from xUtilty (PS4). PS5SX2 (PPSA99203) calls it once while starting its GS renderer, [GS.cpp L233-L247](https://github.com/Swordpdf/PS5SX2/blob/b4cf55e87c34/pcsx2/GS/GS.cpp#L233-L247): ```cpp long long internal_avail = 0; sceKernelAvailableFlexibleMemorySize(&flex_avail); sceKernelInternalMemoryGetAvailableSize(&internal_avail); void* testp = malloc(sizeof(GSRendererNull)); ``` The result is never read. ### Where a title reaches it PS5SX2 relinks only with `--trap-sdk-syscall-stubs` (#3804, see #2136), which these runs use. It reaches this import after #4466 (`sceKernelGetMainSocId` and friends) and a `setitimer` PR (#4382 was used here; #3800 also implements it). On a stack of `main` 8fa5cc48 + #4466 + #4382: - Without this PR, it stops here on both systems: - Linux: `undefined symbol: rjEuM0nb8xg` - Windows: `FAIL: unresolved ELF import rjEuM0nb8xg from libkernel.prx` - With this PR, it moves to `avvJ3J0H0EY` (`sceKernelJitCreateSharedMemory`, which #3787 implements) on both: - Linux: `undefined symbol: avvJ3J0H0EY` - Windows: `FAIL: unresolved ELF import avvJ3J0H0EY from libkernel.prx` ### Tested Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, on 664160b5: `guest_memory` passes 5/5 (`--repeat until-fail:5`) on both. No warnings in `DirectMemory/Export.cpp` or `GuestMemory.cpp`. The new check covers both behaviours: the call writes 0 and returns 0, and a null pointer returns `EINVAL`. `check_conventions.py` passes. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: a `setitimer` PR (#4382 or #3800) for PS5SX2 to reach it (#4466 has merged); the code itself builds and passes alone on `main` - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 14:37:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T14:37:07Z.


Progress report (682ef0c → e95bd66)

📈 System libraries: 86.37% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelInternalMemoryGetAvailableSize
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126444930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#issuecomment-6126444930). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:37:07Z. --- <!-- progress-report --> ### Progress report (682ef0c → e95bd66) 📈 **System libraries**: 86.37% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelInternalMemoryGetAvailableSize` | </details>
Dextroid17 commented 2026-10-12 15:42:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T15:42:10Z.

Review: COMMENTED


The unit-test control is the part a reader can reproduce — with the parent's Export.cpp and this PR's test file, the test binary will not even link. At the head in a worktree guest_memory passes (100% tests passed out of 1 under ctest -R '^guest_memory$'; a loose -R guest_memory also selects guest_memory_pool_stats, which this target does not build). Then, reverting only core/libs/prx/libkernel/DirectMemory/Export.cpp to 8fa5cc486:

ninja: build stopped: subcommand failed.       (build exit 1)
/usr/bin/ld: GuestMemory.cpp:(.text.startup+0x2f0): undefined reference to `sceKernelInternalMemoryGetAvailableSize'
/usr/bin/ld: GuestMemory.cpp:(.text.startup+0x318): undefined reference to `sceKernelInternalMemoryGetAvailableSize'

libkernel.prx itself still links in that state — nothing inside it references the symbol — so the stop is the test link, and what it shows is that the pre-PR tree has no such export. It is the same shape of stop as your title rows but at a different stage: yours is the relinker resolving a guest import at title load, mine is the host linker on a test binary, and I did not reproduce the title stack (main + #4466 + #4382).

  • On the NID: it is in the list the project's own tooling uses — rjEuM0nb8xg sceKernelInternalMemoryGetAvailableSize, line 84887 of 159,042 in the aerolib.csv that tools/nid_names.py downloads (zecoxao/sce_symbols@2883963) — so the name-hashing detour was not needed, unless the list you searched predates that entry. The two derivations agree, and so does the repo's own: tools/nid_names.py's compute_nid returns rjEuM0nb8xg for this name, and the same function returns avvJ3J0H0EY for sceKernelJitCreateSharedMemory, the next stop your body reports.
  • The title evidence holds as far as the source goes: GS.cpp declares int sceKernelInternalMemoryGetAvailableSize(long long*) — the definition here takes size_t*, the same width on both targets — and internal_avail occurs only at lines 245 and 247 of that 1533-line file, so the value really is unused. Nothing in the tree allocates or accounts for an internal pool either: against the parent, grep -i InternalMemory returns only the segment-info stub.
  • Optional, body only: 0 is the opposite convention to its neighbours in the same file — sceKernelAvailableFlexibleMemorySize returns 448 MiB − (images + used) and sceKernelConfiguredFlexibleMemorySize returns 448 MiB — so a title that reads both and sizes something from the sum sees one real number and one zero. Nothing has been shown to do that, and the one caller we have never reads the value; the note is only so the choice reads as deliberate.

Written with AI assistance.

Hermes Agent 🤖 at your service

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5493001452 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#pullrequestreview-5493001452). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T15:42:10Z. **Review:** COMMENTED --- **The unit-test control is the part a reader can reproduce — with the parent's `Export.cpp` and this PR's test file, the test binary will not even link.** At the head in a worktree `guest_memory` passes (`100% tests passed out of 1` under `ctest -R '^guest_memory$'`; a loose `-R guest_memory` also selects `guest_memory_pool_stats`, which this target does not build). Then, reverting only `core/libs/prx/libkernel/DirectMemory/Export.cpp` to `8fa5cc486`: ``` ninja: build stopped: subcommand failed. (build exit 1) /usr/bin/ld: GuestMemory.cpp:(.text.startup+0x2f0): undefined reference to `sceKernelInternalMemoryGetAvailableSize' /usr/bin/ld: GuestMemory.cpp:(.text.startup+0x318): undefined reference to `sceKernelInternalMemoryGetAvailableSize' ``` `libkernel.prx` itself still links in that state — nothing inside it references the symbol — so the stop is the test link, and what it shows is that the pre-PR tree has no such export. It is the same *shape* of stop as your title rows but at a different stage: yours is the relinker resolving a guest import at title load, mine is the host linker on a test binary, and I did not reproduce the title stack (main + #4466 + #4382). - On the NID: it **is** in the list the project's own tooling uses — `rjEuM0nb8xg sceKernelInternalMemoryGetAvailableSize`, line 84887 of 159,042 in the `aerolib.csv` that `tools/nid_names.py` downloads (`zecoxao/sce_symbols@2883963`) — so the name-hashing detour was not needed, unless the list you searched predates that entry. The two derivations agree, and so does the repo's own: `tools/nid_names.py`'s `compute_nid` returns `rjEuM0nb8xg` for this name, and the same function returns `avvJ3J0H0EY` for `sceKernelJitCreateSharedMemory`, the next stop your body reports. - The title evidence holds as far as the source goes: `GS.cpp` declares `int sceKernelInternalMemoryGetAvailableSize(long long*)` — the definition here takes `size_t*`, the same width on both targets — and `internal_avail` occurs only at lines 245 and 247 of that 1533-line file, so the value really is unused. Nothing in the tree allocates or accounts for an internal pool either: against the parent, `grep -i InternalMemory` returns only the segment-info stub. - Optional, body only: 0 is the opposite convention to its neighbours in the same file — `sceKernelAvailableFlexibleMemorySize` returns `448 MiB − (images + used)` and `sceKernelConfiguredFlexibleMemorySize` returns `448 MiB` — so a title that reads both and sizes something from the sum sees one real number and one zero. Nothing has been shown to do that, and the one caller we have never reads the value; the note is only so the choice reads as deliberate. Written with AI assistance. Hermes Agent 🤖 at your service
babyhuey commented 2026-10-12 16:20:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T16:20:33Z.


Thanks for checking. You're right about the NID: rjEuM0nb8xg is in the pinned aerolib list. I was looking it up in a smaller name table of my own, not the list tools/nid_names.py downloads. I've corrected the sentence here and the same one in #4466, whose three NIDs are in that list too.

On the 0: it's deliberate. AnyPS5 has no internal pool, so any other number would be made up, and taking the flexible-memory figure would suggest the two pools are the same. Writing 0 keeps it visibly a stub, and it's listed under silent stubs in TechnicalDebt. If a title ever sizes something from it, that entry is where it would show up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128220528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#issuecomment-6128220528). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T16:20:33Z. --- Thanks for checking. You're right about the NID: `rjEuM0nb8xg` is in the pinned aerolib list. I was looking it up in a smaller name table of my own, not the list `tools/nid_names.py` downloads. I've corrected the sentence here and the same one in #4466, whose three NIDs are in that list too. On the 0: it's deliberate. AnyPS5 has no internal pool, so any other number would be made up, and taking the flexible-memory figure would suggest the two pools are the same. Writing 0 keeps it visibly a stub, and it's listed under silent stubs in TechnicalDebt. If a title ever sizes something from it, that entry is where it would show up.
Dextroid17 commented 2026-10-12 17:46:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:46:11Z.


Both readings hold, and the stub's placement checks out. Read at 664160b5f.

  • The NID. Agreed, and nothing about the export changes: the name is in the pinned aerolib.csv the project's own tooling downloads, and the two derivations agreeing is the line worth keeping in the body.
  • The 0. Verified where it sits rather than accepting it: docs/dev/TechnicalDebt.md has ### Silent stubs at line 16 and the next header at line 60, and the sceKernelInternalMemoryGetAvailableSize entry is line 58 — inside that section, not above it. A deliberate 0 with the entry pointing at the file is exactly the state a title's log line should land on, and it is the opposite of the silent-stub problem the rule exists for.
  • On the neighbour point I raised: the note was only that the choice should read as deliberate, and it now does.

The link-level control is still the reproducible half for a reader: reverting DirectMemory/Export.cpp alone stops the test link, not libkernel.prx.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129536933 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#issuecomment-6129536933). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T17:46:11Z. --- **Both readings hold, and the stub's placement checks out.** Read at `664160b5f`. - **The NID.** Agreed, and nothing about the export changes: the name is in the pinned `aerolib.csv` the project's own tooling downloads, and the two derivations agreeing is the line worth keeping in the body. - **The 0.** Verified where it sits rather than accepting it: `docs/dev/TechnicalDebt.md` has `### Silent stubs` at line 16 and the next header at line 60, and the `sceKernelInternalMemoryGetAvailableSize` entry is line 58 — inside that section, not above it. A deliberate 0 with the entry pointing at the file is exactly the state a title's log line should land on, and it is the opposite of the silent-stub problem the rule exists for. - On the neighbour point I raised: the note was only that the choice should read as deliberate, and it now does. The link-level control is still the reproducible half for a reader: reverting `DirectMemory/Export.cpp` alone stops the *test* link, not `libkernel.prx`. Written with AI assistance.
oneandonlydean commented 2026-10-12 21:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T21:12:35Z.


#4466 and #3800 are merged, so PPSA99203 reaches rjEuM0nb8xg on main now. It conflicts with main again; please rebase, and I'll build and merge it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132695410 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#issuecomment-6132695410). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T21:12:35Z. --- #4466 and #3800 are merged, so PPSA99203 reaches `rjEuM0nb8xg` on `main` now. It conflicts with `main` again; please rebase, and I'll build and merge it.
babyhuey commented 2026-10-12 21:23:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T21:23:35Z.


Rebased onto main 559979dc (ff56dadc). The only conflict was GuestMemory.cpp, where CheckPageTableStats landed beside this test; both are kept.

Checked on that head, Linux (GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: guest_memory 5/5 on both, no warnings in the PR's files. PS5SX2 (PPSA99203, catalog vk-285-163, --trap-sdk-syscall-stubs):

  • main 559979dc: FAIL: unresolved ELF import rjEuM0nb8xg from libkernel.prx
  • with this PR: every import resolves (the JIT calls and setitimer are on main now) and it starts running. It then stops at sysctlbyname("machdep.tsc_freq"), which I'll open separately.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132866252 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4530#issuecomment-6132866252). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T21:23:35Z. --- Rebased onto `main` 559979dc (ff56dadc). The only conflict was `GuestMemory.cpp`, where `CheckPageTableStats` landed beside this test; both are kept. Checked on that head, Linux (GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: `guest_memory` 5/5 on both, no warnings in the PR's files. PS5SX2 (PPSA99203, catalog vk-285-163, `--trap-sdk-syscall-stubs`): - `main` 559979dc: `FAIL: unresolved ELF import rjEuM0nb8xg from libkernel.prx` - with this PR: every import resolves (the JIT calls and `setitimer` are on `main` now) and it starts running. It then stops at `sysctlbyname("machdep.tsc_freq")`, which I'll open separately.
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!4530
No description provided.