fix(libc): let a title's own libunwind read _Unwind_Backtrace frames #4945
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4945"
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 nicolasfalesy on 2026-10-13T05:55:58Z.
What
Homebrew built with the ps5-payload-dev SDK links LLVM libunwind statically, but imports
_Unwind_Backtrace(s62MgBhosjU) fromlibSceLibcInternal. Its trace callback then reads each frame with its own_Unwind_GetIP, i.e.__unw_get_reg(cursor, UNW_REG_IP, &ip), which treats the context as a libunwind cursor:co->validReg(regNum)thenco->getReg(regNum), through the virtual table in the cursor's first word (slots+0x10and+0x18).AnyPS5's
_Unwind_Contextstarts with the saved RAX, so that call jumps to a register value. vkQuake (PPSA99010) without its game data crashes this way on Linux instead of showing its error:(at
app.elf+0x367e, inside the title's own libunwind; the format string next to it islibunwind: __unw_get_reg(cursor=%p, regNum=%d, &value=%p).)The context now starts with a table in LLVM libunwind's
AbstractUnwindCursorslot order (UnwindCursor.hpp: two destructors,validReg,getReg,setReg,validFloatReg,getFloatReg,setFloatReg,step,getInfo,jumpto,isSignalFrame,getFunctionName,setInfoBasedOnIPRegister,getRegisterName). It answers register reads and writes (DWARF numbers 0 to 16,UNW_REG_IP= -1,UNW_REG_SP= -2),validFloatReg(false, as libunwind'sRegisters_x86_64) andisSignalFrame. The other slots throwNotImplemented. AnyPS5's own_Unwind_*functions are unchanged; the register capture and restore code addresses the context throughregisters, so moving it by one word does not affect it.13 of the catalog's titles have both the static libunwind and the
_Unwind_Backtraceimport: PPSA59322, PPSA76677, PPSA85300, PPSA97358, PPSA97510, PPSA98510, PPSA99002, PPSA99010, PPSA99141, PPSA99303, PPSA99309, PPSA99310, PPSA99810.Tested
Linux (Arch, GCC 16.2.1, Release), on
main7e181fcc3:exception_runtime: a second_Unwind_Backtracecheck reads every frame through the table the way a title's libunwind does (validReg,getRegof IP, SP and RBX,setReg,validFloatReg,isSignalFrame) and compares with_Unwind_GetIPand_Unwind_GetGR. TheRegisterContextlayout assertion now checkscfarelative toregisters.ctest: 1011 of 1011 pass (the display-only VideoOut and AGC tests skip).--to-intel) withoutid1: onmainit dies with SIGSEGV (exit 139). With this change it exits 0 after its own error, as on a console:Quake Error: W_LoadWadFile: couldn't load gfx.wad ... Check that this has an id1 subdirectory containing pak0.pak and pak1.pak.tools/check_conventions.py --base upstream/mainpasses.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 github-actions[bot] on 2026-10-13T05:56:22Z.
Progress report (
ea2bbef→db3ec02)📉 System libraries: 87.92% (-0.06%, +3 implemented, +3 declared functions)
✅ 3 implemented
CursorIsSignalFrameCursorValidFloatRegisterCursorValidRegister⚪ 1 behaviourally empty (constant return or throw)
CursorValidFloatRegister🆕 3 declared as stubs
CursorGetRegisterCursorSetRegisterCursorUnsupportedImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T06:50:41Z.
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.
main)docs/dev/debt/libc.mdL43Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T07:36:43Z.
Checked on the PR merged onto main:
exception_runtimeandregister_contextpass, andexception_runtimefails without the change (the new_Unwind_Backtracecallback reads every frame through the cursor table). The register layout and slot order match LLVM libunwind'sAbstractUnwindCursor, and unsupported slots throw. Merging.