fix(libkernel): end guest thread, fiber and context frame chains at a zero record #7123
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7123"
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 thuanquang on 2026-10-17T12:28:37Z.
What
Unreal Engine walks the frame-pointer chain to capture call stacks (for
ensure(), hitch reports and fatal errors): it reads the return address at[rbp + 8], followsrbp = [rbp], and stops when the return address is 0. It never checks the frame pointer itself, so the walk only ends cleanly at a frame record whose return address is 0. The relinker's entry stub gives the main thread such a record (#2339), but guest threads did not get one:RunThreadcalled the guest thread entry directly, so the entry's savedrbpwas whatever the host code left in it. On Linux, Tamalero's LEGO Batman core dump on #4239 shows the chain running from the guest entry intoStartNativeThreadand then to glibc's frame with savedrbp0x21; on Windows, Returnal's walk on itsUE4 Main Threadreads address0x8(#4239). Both titles fault inside the walker.Aps5FiberMain's frame has a savedrbpof 0 but a non-zero return address, so the same walker reads[0 + 8]from inside a fiber.makecontextstarts its function withrbp0 throughAps5MakecontextStart_nid_no_patch, which is built without frame pointers, so a walk from a made context reads[0 + 8]as well.Guest threads now start through
Aps5CallGuestEntry_nid_no_patch, a small thunk next toRunThreadthat pushes a{saved rbp 0, return address 0}record, pointsrbpat it and calls the entry; the fiber trampolines push the same record before callingAps5FiberMain; andUserContext.cppis built with frame pointers, soAps5MakecontextStart_nid_no_patch's own frame, over the zero return addressmakecontextalready stores, is that record. The walk then ends at the record, as it does on the main thread. The thunk issysv_abi, so on Windows the compiler saves the registers the guest may clobber around the call, as it did for the direct call; it keepsrsp16-byte aligned at the call and has CFI for unwinders. Neither thread exit path runs through it: Windows exits with_endthreadex, POSIXlongjmps back toStartNativeThread.Not covered here: module initializers that the Windows entry stub runs before it writes its record, guest
signal()handlers that run on threads the OS creates, and guest callbacks reached through host code that does not keep a frame pointer (for examplelibSceJobManager's worker loop) can still see host frames in their chain.Tested
Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON:guest_pthread_frame_chain: a guest thread walks its chain the way Unreal does (bounded to its own stack, required to climb) and must end at a{0, 0}record after the walker's and the entry's frames; it also checks that the entry gets its argument and its return value reachesscePthreadJointhrough the thunk. Onmainit fails:the frame chain of a guest thread stays on its stack and climbs it.fiber's frame-chain check now walks the same way and requires the{0, 0}record instead of a null frame. Onmainit fails:frame chain climbs the stack to a frame whose return address is 0.guest_user_contextnow walks the chain from the made context's function, bounded to the context's stack, and requires the record. WithUserContext.cppbuilt as onmainit fails:the frame chain of a made context ends on its stack at a frame whose saved frame pointer and return address are 0.thread,guest_pthread, user context and fiber tests (44 in all).ctest --parallel 4 --timeout 120onmaine09dbc2b4with this change (mainhas since moved toc9e6c45dewithout touching these files): 1384 tests;agc_driver_lds_mixed_width_atomics(#5271, fixed by #6976) andagc_driver_layered_volume_vertex_no_gpl(#4768) fail as onmainhere. Six Python-driven tests hit their 30 s timeout, which happens on this PC only (slow Python start-up); theconventions_function_bodiesshards pass when rerun on their own.python tools/check_conventions.py --base origin/mainwith this title and body passes.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T12:42:55Z.
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.
core/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/tests/Fiber.cppcore/libs/tests/GuestUserContext.cppcore/libs/prx/libSceFiber/Export.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libSceFiber/Export.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T15:16:36Z.
Review: COMMENTED
Linux run, since the description notes the change was tested on Windows only.
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
ff9bf2228merged ontomain40315fcf8(clean merge).guest_pthread_frame_chain,fiberandguest_user_contextpass with the PR. The thread, fiber and context tests (ctest -R "frame_chain|fiber|user_context|pthread|thread", 45 tests) all pass.libkernel/CMakeLists.txtonly, onmain(no thunk, no fiber change,UserContext.cppbuilt as onmain): all three abort, with the same messages as on Windows:guest_pthread_frame_chain:the frame chain of a guest thread stays on its stack and climbs itfiber:frame chain climbs the stack to a frame whose return address is 0guest_user_context:the frame chain of a made context ends on its stack at a frame whose saved frame pointer and return address are 0ctest -E "^agc|gpu|vulkan|video_out"): 683/683, the 682 tests ofmainplusguest_pthread_frame_chain.Not checked: the titles from #4239.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-17T23:18:27Z.
Title check on LEGO Batman: Legacy of the Dark Knight (PPSA16833), Linux, RTX 4090,
main5d9dcc42d+ the title's start-up changes (#6694, #6699, the ToS hunk of #6447), the same route in every run.StartNativeThread's savedrbp0x21)With this PR the run reached an Unreal
LowLevelFatalError(GameThread timed out waiting for RenderThread after 120.00 secs, a separate problem I'm still looking at), and Unreal printed the call stack: four title frames and the return intoAps5CallGuestEntry_nid_no_patch, then the walk stopped at the zero record. The run with the local change did the same on a different fatal error (Could not decompress shader group with Oodle, 62 frames). In the four runs without it, no fatal-error text was logged at all, because the walk that precedes it faulted first. After the call stack, both runs end in the title's own crash path, the same in both.Tested and written by Claude (AI assistant) on a contributor's machine.