feat(libc): export the CRT data markers #17062

Merged
Opensource55 merged 6 commits from upstream-pr/17062 into main 2026-11-12 00:44:47 +00:00
Opensource55 commented 2026-11-08 08:52:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Opensource55 on 2026-11-08T08:52:45Z.


What

libc.prx exports data as well as functions: for a data slot the export is the object's address, and the NID comes from its name. __isthreaded (q1OvUam0BJU) has been exported that way in StandardStreams.cpp for a while; three more slots the console exports were missing here:

NID symbol value here
P330P3dFF68 Need_sceLibc 1
kQelMBYgkK0 _thread_autoinit_dummy_decl 0
dmUgzUX3nXU _thread_autoinit_dummy_decl_stub 0

Need_sceLibc already existed in Export.cpp as a plain uint32_t that nothing exported, so it needed only the suffix; the two _thread_autoinit_dummy_decl objects did not exist at all.

The libc.prx of PPSA01341 v01.007.000 exports them at 0x15d780 and 0x1a60a8. The two dummy declarations share one address in that module, so here the stub is an assembler alias of the declaration — the same .set that APS5_EXPORT uses for function NIDs — and a caller comparing their addresses sees one address too. Emscripten and MSVC keep a second object, which the debt entry records.

The same entry records the twelve data slots this change deliberately does not export, and why: _Files has no measured length, and a table shorter than the console's would let a guest that indexes it read past the end, which is worse than an import that fails to resolve; fcloseall closes that table's streams and needs the registry fopen/fdopen do not keep; _Ctype, _Locale, _Tolotab and _Touptab are console-private TLS tables; the four _Tls_setup__* flags record setup internal to that module; the two _PJP_*_Copyright texts have unknown bytes; and __cleanup shares its eight-byte slot with __isthreaded there, so the console holds one slot that is both a thread flag and a cleanup pointer.

Tested

Windows 10 19045.6456, MinGW GCC 15.2.0, Ninja, Release.

  • ctest -R standard_stream: 6/6 pass, including the three new assertions (Need_sceLibc_nid_postfix == 1, both dummies == 0).
  • objdump -p libc.prx lists Need_sceLibc_nid_postfix, _thread_autoinit_dummy_decl_nid_postfix and _thread_autoinit_dummy_decl_stub_nid_postfix, and recomputing their NIDs gives the three console values above.
  • Full ctest -j6: 4638 tests, 25 failures; rerunning them serially leaves 10, all of kinds this machine produces with or without this change: creating symbolic links without SeCreateSymbolicLinkPrivilege fails with WinError 1314, and guest_directory, guest_filesystem, guest_kernel_sys and guest_kqueue abort with 0xc0000409 on stacks that carry tsbx.dll, the hook the agent sandbox uses to redirect deletions — the tests that abort are exactly the filesystem ones. agc_shader_cache_housekeeping_plain fails under parallel load and passes when run alone.
  • The hosted Windows job does not run these tests; this is the only Windows evidence.
  • Linux and macOS are not built on this machine. No console.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5210005441 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17062). Originally posted by [Opensource55](https://github.com/Opensource55) on 2026-11-08T08:52:45Z. --- ### What `libc.prx` exports data as well as functions: for a data slot the export is the object's address, and the NID comes from its name. `__isthreaded` (`q1OvUam0BJU`) has been exported that way in `StandardStreams.cpp` for a while; three more slots the console exports were missing here: | NID | symbol | value here | |---|---|---| | `P330P3dFF68` | `Need_sceLibc` | 1 | | `kQelMBYgkK0` | `_thread_autoinit_dummy_decl` | 0 | | `dmUgzUX3nXU` | `_thread_autoinit_dummy_decl_stub` | 0 | `Need_sceLibc` already existed in `Export.cpp` as a plain `uint32_t` that nothing exported, so it needed only the suffix; the two `_thread_autoinit_dummy_decl` objects did not exist at all. The `libc.prx` of PPSA01341 v01.007.000 exports them at `0x15d780` and `0x1a60a8`. The two dummy declarations share one address in that module, so here the stub is an assembler alias of the declaration — the same `.set` that `APS5_EXPORT` uses for function NIDs — and a caller comparing their addresses sees one address too. Emscripten and MSVC keep a second object, which the debt entry records. The same entry records the twelve data slots this change deliberately does not export, and why: `_Files` has no measured length, and a table shorter than the console's would let a guest that indexes it read past the end, which is worse than an import that fails to resolve; `fcloseall` closes that table's streams and needs the registry `fopen`/`fdopen` do not keep; `_Ctype`, `_Locale`, `_Tolotab` and `_Touptab` are console-private TLS tables; the four `_Tls_setup__*` flags record setup internal to that module; the two `_PJP_*_Copyright` texts have unknown bytes; and `__cleanup` shares its eight-byte slot with `__isthreaded` there, so the console holds one slot that is both a thread flag and a cleanup pointer. ### Tested Windows 10 19045.6456, MinGW GCC 15.2.0, Ninja, Release. - `ctest -R standard_stream`: 6/6 pass, including the three new assertions (`Need_sceLibc_nid_postfix == 1`, both dummies `== 0`). - `objdump -p libc.prx` lists `Need_sceLibc_nid_postfix`, `_thread_autoinit_dummy_decl_nid_postfix` and `_thread_autoinit_dummy_decl_stub_nid_postfix`, and recomputing their NIDs gives the three console values above. - Full `ctest -j6`: 4638 tests, 25 failures; rerunning them serially leaves 10, all of kinds this machine produces with or without this change: creating symbolic links without `SeCreateSymbolicLinkPrivilege` fails with `WinError 1314`, and `guest_directory`, `guest_filesystem`, `guest_kernel_sys` and `guest_kqueue` abort with `0xc0000409` on stacks that carry `tsbx.dll`, the hook the agent sandbox uses to redirect deletions — the tests that abort are exactly the filesystem ones. `agc_shader_cache_housekeeping_plain` fails under parallel load and passes when run alone. - The hosted Windows job does not run these tests; this is the only Windows evidence. - Linux and macOS are not built on this machine. No console. ### 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 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
gabichuuuuu commented 2026-11-08 16:03:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T16:03:14Z.

Review: COMMENTED


Windows run of head b58f62ed1e, merged onto main 828e44310e (clean merge). Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, BUILD_TESTING=ON.

  • guest_standard_streams* with --repeat until-fail:20: 100 / 100 pass (5 tests).
  • The exports are really in the PE. objdump -p on the patched build/core/libs/libs/libc.prx lists each of P330P3dFF68 (Need_sceLibc), kQelMBYgkK0 and dmUgzUX3nXU once, next to the existing q1OvUam0BJU (__isthreaded). So the _nid_postfix data objects become NID data exports on Windows too, not only in-process symbols the test links against.

The aliasing the debt entry records, two separate objects where the console has one address, could be matched in-tree. You could define one object and give the second NID an APS5_EXPORT alias to it, as other modules alias function NIDs. Then a caller comparing the two addresses would see what it sees on the console. I haven't checked whether APS5_EXPORT accepts data symbols.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818574742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17062#pullrequestreview-5818574742). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T16:03:14Z. **Review:** COMMENTED --- Windows run of head `b58f62ed1e`, merged onto `main` `828e44310e` (clean merge). Setup: Windows 11, WinLibs GCC 15.2 (`x86_64-ucrt-posix-seh`), Release, `BUILD_TESTING=ON`. - `guest_standard_streams*` with `--repeat until-fail:20`: 100 / 100 pass (5 tests). - **The exports are really in the PE.** `objdump -p` on the patched `build/core/libs/libs/libc.prx` lists each of `P330P3dFF68` (`Need_sceLibc`), `kQelMBYgkK0` and `dmUgzUX3nXU` once, next to the existing `q1OvUam0BJU` (`__isthreaded`). So the `_nid_postfix` data objects become NID data exports on Windows too, not only in-process symbols the test links against. The aliasing the debt entry records, two separate objects where the console has one address, could be matched in-tree. You could define one object and give the second NID an `APS5_EXPORT` alias to it, as other modules alias function NIDs. Then a caller comparing the two addresses would see what it sees on the console. I haven't checked whether `APS5_EXPORT` accepts data symbols.
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!17062
No description provided.