fix(libc): start sceLibcBacktraceSelf's frames at its caller #9240
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9240"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T16:17:35Z.
What
sceLibcBacktraceSelfandsceLibcBacktraceGetBufferSizebuild their records inCaptureFrames, which drops the first two captured return addresses: they are taken to beCaptureFrames' own frame and the export's. If the unwinder adds a frame between them, the records start one frame early, insidelibc.prx.An
ANYPS5_ENABLE_ASANbuild does this. The sanitizer interceptsbacktrace(), so the captured list has one more frame at its start, and the first record is the export itself:Both exports now pass
__builtin_return_address(0), their caller's return address, toCaptureFrames. The records start at the captured address equal to it, so a guest's first record is its own call site however many frames the unwinder adds. If no captured address matches, the first two are dropped as before.Tested
Ubuntu 24.04, GCC 13.3, on
maincecb540a63.ANYPS5_ENABLE_ASANbuild,ctest -R '^guest_backtrace$':main: fails 3 of 3 with "first frame is not in the calling module". The frames above are frommainwith a print added to the test._Unwind_Backtracepath:guest_backtracepasses 3 of 3 onmainand 3 of 3 with this change.It came up in an ASan sweep of the CPU-side tests on
main, with #9236 and #9238. With all three, the sweep's only failures are the threenet_dontwait_blocking_*tests (#8917, #8918) andguest_kernel_stack_protect, which fails intermittently under ASan onmaintoo ("Shadow memory range interleaves with an existing memory mapping", 2 of 3 runs).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)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:56:55Z.
Review: APPROVED
Checked against main
99feaf0eb8and core/libs/prx/libc/src/exception/Unwind.cpp on main:CaptureFramesstill drops a fixed two frames._Unwind_Backtrace_nid_postfixsteps once before the first callback and_Unwind_GetIP_nid_postfixreturnsregisters[16](Unwind.cpp:619, 638-649), so each frame's entry is a return address and__builtin_return_address(0)is a valid key. The index-2 fallback keeps today's behaviour if nothing matches.#if defined(__linux__)lines; whichever lands second needs a trivial rebase.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.