Repository navigation
fix(libc): use the default heap for an executable without process parameters - #11979
oneandonlydean merged 5 commits into
Conversation
…ameters An ELF without a PT_SCE_PROCPARAM segment, such as a ps5-payload-dev SDK program, had no .procpar section after relinking, so the first allocation stopped with "process metadata is missing; relink the executable". The Windows relinker now writes a .procpar section that records no parameters for such an ELF, and the application heap registers its default allocator when it finds that record. An executable without any .procpar section still gets the relink message.
|
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.
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.
|
|
@xXPBSXx ApplicationProcessParameters_nid_no_patch() now returns null on Windows for the no-procparam record, but libSceRtc/Export.cpp:123, libSceHttp/src/Uri.cpp:254, libSceSsl/Export.cpp:726, libSceAppContent/Export.cpp:36, libkernel_sys/Export.cpp:315 and libkernel/System/src/Coredump.cpp:30 (and the other callers in core/libs/prx) memcpy from process+16 without a null check, which would crash where main threw a message. Could the no-parameter case return a static zeroed block (or could those callers handle null), with a test that sceKernelGetProcParam's result is safe to read at offset 16? |
…process parameters Callers of ApplicationProcessParameters_nid_no_patch read the compiled SDK version at offset 16 without a null check, so the null result for the no-parameters record would crash them. The lookup now returns a static zeroed 0x40-byte block for that record, and the heap recognises it by address and keeps registering its default allocator. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks, confirmed: the callers you list, and the others in
AI-assisted (Claude Code). |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
AI-assisted (Claude Code). |
rooklz
left a comment
There was a problem hiding this comment.
Reviewed the relinker half on the head 944b4d753e, merged onto main 895ead67f7. I could not build the libc half or its application_heap_without_parameters test: they are Windows-only, and I only have macOS here.
Ran
- Relinker-only build of the merge,
ctest371 of 371 passed. The newwindows_process_parameterstest passes. - The
windows-latestfailure on this run isshader_cache_native_pathstiming out after 20.36 s. This PR changes no shader files. - Section headers the relinker writes for
main_fixture():.procparhas RVA0x11000, VirtualSize 8, SizeOfRawData 0, PointerToRawData 0, flags0x40000040. The loader zero-fills it, so the reader gets address 0 and size 0, which is what the new branch inApplicationProcessParameters_nid_no_patchexpects.
Mutants of the WindowsPePatcher.cpp hunk, run against the new test
| mutant | result |
|---|---|
| hunk removed | killed |
std::vector<std::uint8_t>(8, 1) |
killed |
| empty data | killed |
std::vector<std::uint8_t>(4) |
survives |
std::vector<std::uint8_t>(16) |
survives |
flag 0x40u changed to 0x80u |
survives |
Raw size and raw offset are both 0 here, so stored is b"" and the zero check passes whatever the section holds. The test only checks that the section exists. The reader rejects any VirtualSize other than 8 (invalid process metadata section), so mutants 4 and 16 would fail at runtime on Windows while this test still passes. This is not blocking, but one more assertion catches both of them. The head still passes with it:
import struct
...
header, = struct.unpack_from("<I", data, 0x3C)
optional_size, = struct.unpack_from("<H", data, header + 20)
index = [section[0] for section in pe_sections(data)].index(b".procpar")
virtual_size, = struct.unpack_from("<I", data, header + 24 + optional_size + index * 40 + 8)
assert virtual_size == 8, virtual_sizeI only read the libc side. Using found instead of result != nullptr keeps the duplicate check working when the empty record comes first. The new debt line says that returning a zeroed block, not null, from sceKernelGetProcParam has not been measured, which is right.
AI-assisted: yes
|
Thanks for the mutant run and for reading the relinker half. You are right that AI-assisted (Claude Code). |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
The follow-up commit AI-assisted (Claude Code). |
What
Carries #6713 (karimibrahim07, head
668d51adbd; both commits keep their authorship), rebased onto currentmainafter a conflict indocs/dev/debt/libc.md, as offered in the hand-off comment on that PR. The rebase adds only the new "Application heap without process parameters" line todocs/dev/debt/libc.md. The review asked to reconcile this PR's debt notes with #10947 (merged on 27 October); after the rebase this PR adds only that one line to the debt file, and its ownnearbyintfand_Thrd_sleepnotes are no longer part of the diff. Whether the entries onmainagree with each other is not checked here.An ELF without a
PT_SCE_PROCPARAMsegment, such as a ps5-payload-dev SDK program, got no.procparsection when relinked for Windows. Its first allocation then stopped withapplication heap: process metadata is missing; relink the executable(read in the code, not run on the unchangedmain). That message, added together with the.procparwriter in9f2b41b9a1, asks for a relink, but relinking such an ELF cannot add process parameters it does not have.WindowsPePatchernow writes a.procparsection with address 0 and size 0 when the ELF has noPT_SCE_PROCPARAMsegment.ApplicationProcessParameters_nid_no_patchreturns a static zeroed 0x40-byte block for that record, so callers that read the compiled SDK version at offset 16 see 0.ApplicationHeapInitialize_nid_no_patchrecognises that block by its address and registers the heap's existing default allocator, as it already does for an all-null replacement table.sceKernelGetProcParamreturns the result of that lookup, so it returns the same block (read in the code).An executable without any
.procparsection still gets the relink message (application_heap_stats_missingstill passes). The new entry indocs/dev/debt/libc.mdrecords that, on the console, such a program runs inside its launcher's process, whose parameters aren't modelled (this is the entry's wording, not something measured here). On Linux the process-parameter lookup is unchanged and still throwsapplication heap: invalid or missing process parameterswhen it finds none (read inApplicationProcessParameters.cpp, not run here).Overlap: 170 of the 1295 open pull requests change at least one of the files this PR touches;
git merge-treeof this branch with each of their heads, each on the merge base git finds, reports a conflict for 22 of them. 20 of those already conflict withmainon their own (almost all indocs/dev/debt/libc.md), so this change adds no landing order for them. #11302 (indocs/dev/debt/libc.md) and #11463 (incore/relinker/CMakeLists.txt) conflict only with this branch; whichever lands second rebases and keeps both changes. The authors of #11302 and #11463 are asked here which of the pull requests should land first, and this PR waits for their answer before the landing order is fixed. No pull request of mine is a dependency (Depends on: none).Tested
Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Ninja Release,
BUILD_TESTING=ON, and Ubuntu 24.04 under WSL2 (a virtualised kernel, not bare-metal; GCC 13.3, Release), both onmain8ff4baf534with this branch on top; each arm built fresh (ninja exit code 0 read), 5 runs each:application_heap*(10 tests, including the newapplication_heap_without_parameters) and the new relinker testwindows_process_parameterspass, 11 of 11, in all five runs.mainwithApplicationHeap.cpp,ApplicationProcessParameters.cppandWindowsPePatcher.cppreverted and the tests kept: 2 of 11 fail in all five runs.application_heap_without_parametersstops with exit code0xc0000409, andwindows_process_parametersfails.application_heap*tests that exist on Linux andwindows_process_parameterspass, 13 of 13, in all five runs. With the three files reverted, 1 of 13 fails in all five runs:windows_process_parameters.maineece5da035(before the final rebase onto1089f2bbfd, which changes none of the PR's files or test targets): 3 runs each, Windows 11 of 11 and Linux (WSL2) 13 of 13.0cb4dde2ee, which returns null) and the new test,application_heap_without_parametersfails in all three runs (1 of 11); Linux (WSL2), 3 runs, 13 of 13 pass. The callers that read offset 16 were not run.python tools/check_conventions.py --base upstream/mainpasses with this title and description;git merge-treeagainstmain1089f2bbfdis clean.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Co-authored by the original author of #6713.
AI-assisted (Claude Code).
🤖 Generated with Claude Code