Skip to content

feat(libkernel): export sceKernelInternalMemoryGetAvailableSize - #4530

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-internal-memory-available-size
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-internal-memory-available-size

Conversation

@babyhuey

@babyhuey babyhuey commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 8fa5cc4 + #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 feat(libkernel): implement the JIT shared memory calls #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 664160b: 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

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Progress report (682ef0c → e95bd66)

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

✅ 1 implemented
Library Name
libkernel sceKernelInternalMemoryGetAvailableSize

@Dextroid17 Dextroid17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@babyhuey
babyhuey force-pushed the feat/libkernel-internal-memory-available-size branch from 664160b to e95bd66 Compare October 12, 2026 19:23
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 12, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

#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

Copy link
Copy Markdown
Contributor Author

Rebased onto main 559979d (ff56dad). 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 559979d: 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.

@babyhuey
babyhuey force-pushed the feat/libkernel-internal-memory-available-size branch from e95bd66 to ff56dad Compare October 12, 2026 21:23
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit df5108f into boykopovar:main Oct 12, 2026
6 of 8 checks passed
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