feat(libc): answer every libunwind cursor slot of an unwind context #6819
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6819"
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 GitamarT045T3R on 2026-10-16T13:13:27Z.
What
The
_Unwind_Contextthat_Unwind_Backtracepasses to its callback starts with a table laid out like LLVM libunwind'sAbstractUnwindCursorvirtual table (db3ec02c5), because homebrew built with the ps5-payload-dev SDK links libunwind statically and calls through that table from its own_Unwind_GetIP. Only the register slots andisSignalFramewere answered; the other nine slots threw. A title that asks its own libunwind for a frame's procedure info or name (_Unwind_GetRegionStart,_Unwind_GetLanguageSpecificDataandunw_get_proc_infocallgetInfo;_Unwind_SetIPcallsgetInfoandsetInfoBasedOnIPRegister;unw_get_proc_namecallsgetFunctionName), steps a frame (unw_step) or resumes one (unw_resume) stopped there.Every slot now answers as
UnwindCursor<LocalAddressSpace, Registers_x86_64>of LLVM 18.1.8 does with DWARF unwind information:~AbstractUnwindCursor(complete and deleting)operator deleteis emptygetReg,setRegUNW_REG_SP) to 16 (rip); any other number printslibunwind: getRegister - unsupported x86_64 register(orsetRegister) and aborts, asRegisters_x86_64does through_LIBUNWIND_ABORTgetFloatReg,setFloatReglibunwind: getFloatRegister - no x86_64 float registers(orsetFloatRegister) and abortstepUNW_STEP_ENDwithout unwind info,UNW_EBADFRAMEwhen the rules cannot be applied, otherwise moves to the caller with the same rules as_Unwind_Backtraceand looks the new IP up, returningUNW_STEP_ENDwhen nothing covers it (IP 0 included)getInfoDW_CFA_GNU_args_sizeasgp,UNWIND_X86_64_MODE_DWARFasformat, the FDE and its size asunwind_info, the start of the ELF segment or PE section holding the IP asextra; all zero without unwind infojumpto_Unwind_RaiseExceptioninstalls a landing padgetFunctionNamedladdrof the IP (Linux, macOS); on Windows the nearest export at or below the IP in the image holding itsetInfoBasedOnIPRegistergetRegisterNameRegisters_x86_64::getRegisterName's names,unknown registerotherwiseTo share the walk with
_Unwind_Backtrace,Stepis split intoCaller(the registers of the caller) and the end-of-stack checks, andGetRulesrecords the FDE, the function's end, the arguments size and the segment in the context, and clears them when no FDE covers the IP.DW_CFA_GNU_args_sizewas parsed and dropped before.Differences from libunwind are listed in the libc technical debt entry: Windows host frames without an FDE are stepped with
RtlVirtualUnwindand report no range; a frame whose rules leaverspandripunchanged ends the walk instead of being returned again; a signal frame is looked up at its IP;jumptodoes not restorer10andr11.Tested
Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release,
BUILD_TESTING=ON, onmaineb901bcf4:unwind_cursor(registered on every platform): captures a context in an exported probe and calls every slot through the table:setInfoBasedOnIPRegisterandgetInfoagainst the probe's own address, its FDE and_Unwind_GetRegionStart/_Unwind_GetLanguageSpecificData,getFunctionName(full and truncated), IP 0,stepto the exported caller and on to the end of the stack, register names, the destructors,jumptoback to a captured point, and the context_Unwind_Backtracepasses to its callback. Passes, 25 of 25 repeated runs.unwind_cursor_get_register,_set_register,_get_float_registerand_set_float_registermatch libunwind'slibunwind: getRegister - unsupported x86_64 registerandlibunwind: getFloatRegister - no x86_64 float registerslines: pass.libc.prxofmainstops at the firstsetInfoBasedOnIPRegisterwithlibunwind cursor: operation other than register access or isSignalFrame not implemented.windows_exceptions,windows_backtrace_*,guest_exception_*,guest_raise_exception,guest_unwind_module_info,agc_stack_walk,linux_eh_frame_header, ...) pass.ctest -j 12: 1324 of 1325 pass.agc_shader_disk_cachefails withAccess is deniedas it does onmainon Windows 10 (#6415).agc_driver_gpu_indirect_arguments_misaligned_writer_ahead_testsdoes not build with MinGW onmain(alignment 65536 above the object file maximum of 8192, #6452), so it was excluded.python tools/check_conventions.py --base origin/mainpasses.getFunctionNameusesdladdrandextrathePT_LOADsegment fromdl_iterate_phdr; the test exports its probe withENABLE_EXPORTS.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 jotitadev on 2026-10-16T13:45:41Z.
Review: COMMENTED
Native Linux run on exact head
3bf85ad5c71a2feb54df83cbd5eb5673ed539bff, merged onmain82ddae75b.Machine: Intel i7-8700 (6C/12T), Ubuntu 26.04, GCC 15.2, CMake 4.2.3, Ninja, Release,
BUILD_TESTING=ON, full build.The four abort tests fail on Linux.
unwind_cursor_get_register,_set_register,_get_float_registerand_set_float_registerprint the expected line (libunwind: getRegister - unsupported x86_64 register, ...), butstd::abort()ends the process withSIGABRThere, and CTest reports a signal asSubprocess aborted***Exceptionand fails the test even thoughPASS_REGULAR_EXPRESSIONmatches. On Windows_set_abort_behaviorturnsabort()into exit code 3, which is why they pass there. The other abort-plus-regex tests in the tree (guest_call_trace_abort,windows_backtrace_*) are registered only underif(WIN32); these four are registered on every platform.With a SIGABRT handler that exits normally on non-Windows, all four pass. I tested only this change:
(plus
#include <csignal>). Registering the four tests underif(WIN32)would also work, but then the abort paths would go untested on Linux.Other results:
unwind_cursorpasses, 25 of 25 repeated runs. This covers the Linux paths you could not run:getFunctionNamethroughdladdr,extrafrom thePT_LOADsegment,stepto the end of the stack, andjumpto.unwind_cursor_testsbinary run againstmain'slibc.prxaborts withlibunwind cursor: operation other than register access or isSignalFrame not implemented, so the test does cover the change.ctest -E "^agc|gpu|vulkan|video_out"): 649/655. The six failures are the four above plusfile_writer_binary/file_writer_text, which also fail onmainon this machine (648/650). All the other exception, unwind and backtrace tests pass.Not checked: macOS.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-16T14:11:56Z.
@jotitadev thank you for the Linux run, and for pinning down why the four abort tests failed there.
5514a8579 adds the SIGABRT handler you tested (
std::_Exit(3)outside Windows,<csignal>), so the abort paths stay covered on Linux instead of moving the tests underif(WIN32). On Windowsunwind_cursorand the four abort tests still pass. The same commit moves the test registration beforeguest_strings, which removes the overlap with #6079; the remaining overlap with #6541 is the adjacent debt entry indocs/dev/debt/libc.mdand resolves either way.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T14:44:59Z.
Review: COMMENTED
Re-ran on exact head
5514a8579ed9a27b2d903d9e9c4d34f5d6548b3a, merged onmain82ddae75b. Same machine as before: Intel i7-8700, Ubuntu 26.04, GCC 15.2, CMake 4.2.3, Ninja, Release,BUILD_TESTING=ON, full build.unwind_cursorand the four abort tests (unwind_cursor_get_register,_set_register,_get_float_register,_set_float_register) now pass on Linux, 25 of 25 repeated runs each (ctest -R unwind_cursor --repeat until-fail:25). The abort tests print the expectedlibunwind: ... unsupported x86_64 registerline and exit normally through the new handler.ctest -E "^agc|gpu|vulkan|video_out" -j6): 653/655 with this PR;main647/650 on the same machine. The two failures arefile_writer_binary/file_writer_text, which also fail onmainhere. The thirdmainfailure was aguest_pthread_starttimeout under load; it passes 5 of 5 when run alone.Not checked: macOS, Windows.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T11:10:03Z.
Review: COMMENTED
Re-ran on the new head, since b178ec5de changes the Linux-only path and the PR says it wasn't run on Linux.
Exact head
b178ec5dedd774153631e0504684b8e1e1a58505, merged onmain674c25388. Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, CMake 4.2.3, Ninja, Release,BUILD_TESTING=ON, full build.unwind_cursorand the four abort tests pass, 10 of 10 repeated runs. The 15unwind|exception|backtracetests pass.unwind_cursorfails withunwind cursor check failed: getInfo gives the start of the segment holding the function. So the commit is needed on glibc now thatmaintakes the_dl_find_objectpath (2a12dbd40, which landed after my run on 5514a8579), and the test covers it.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:04:12Z.
docs/dev/debt/libc.mdline 87: this PR closes the gap "the other slots throw", but the entry is rewritten to describe the new slots: the aborts ingetReg/setReg/getFloatReg/setFloatReg, the destructors and everygetInfofield, all of which match libunwind. What is still open comes only after that: the differences, and that the console'slibSceLibcInternalis not checked. CONTRIBUTING.md line 73 asks for the gap first and says a pull request that closes a gap "removes its entry, or cuts it to what is still open, instead of rewriting it to describe the corrected behaviour".The branch needs a rebase for the conflict in this file anyway (main added the
RemoveTreeentry just above it). After the rebase, thedebt-lengthcheck that main gained in #6757 flags the entry. I merged this head into maind97361bd0, kept both entries and ranpython3 tools/check_conventions.py --base d97361bd0:Cutting the current text down to its open parts gives 875 characters, and the check passes with it:
Why the table exists is already recorded in
db3ec02c5and in the PR description, so the entry does not need to repeat it.Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T16:00:57Z.
Rebased onto
maincecb540a6on top of @adriadam10's b178ec5de, which is kept as 13232cbe7. Two commits are added:check_conventionspasses with nodebt-lengthfinding).TraceFirstFrameAPS5_VABI: since #6851_Unwind_Trace_Fnhas the guest calling convention, and without itunwind_cursor_testsno longer compiles on Windows.On Windows
unwind_cursor, the four abort tests, the fiveunwind_callback_abitests and the Windows exception and backtrace tests pass, 3 of 3. Thank you @jotitadev for the glibc run that shows b178ec5de is needed.Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-22T08:03:31Z.
Rebased onto
maind6eafa54d(3551ba114). The conflict was with726edc503(MSYS2 GCC runtime builds), which changedVirtualUnwindto take theFrameand record the start, language data and personality of a Windows host frame. This PR keeps that version:NearestExportstays in front of it, andFrameRulesno longer setscontext.cfaitself, sinceVirtualUnwindnow does. The debt entry keepsmain's new Windows unwinder line. One added commit, 3551ba114, saysgetInfogives host frames no end address instead of "no range", because they now have a start.On Windows, the 16
unwind_*,windows_backtrace_*andwindows_exceptionstests pass andcheck_conventionspasses.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T01:20:37Z.
Review: APPROVED
Reviewed current head 3551ba114cf3000200e39d574fc2f774f5e4f99f against LLVM libunwind 18.1.8 and the changed call paths. The 15-entry cursor slot order and x86_64 register mapping align with the reference; carries the FDE range, LSDA/personality, DWARF format, FDE pointer/size, segment base and parsed ; , end-of-stack handling, IP re-lookup, and the Windows host-frame fallback are consistent with the documented scope. The added cursor test exercises slot behavior, frame traversal, info/name queries, , and abort cases. Current hosted checks pass for conventions, eligibility, labels, macOS and Linux register-context/relinker matrices, ASan, and write-watch. The repository's full Linux and Windows product jobs are skipped by policy. The PR also documents remaining Windows/IP/jumpto gaps and lack of console-side verification.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T05:32:08Z.
Review: COMMENTED
Merge-skew check: head
3551ba114merged onto currentmainabed03546(clean merge,git merge --no-commit). This head's CI ran on the October 22 base, before #10706 landed. Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,BUILD_TESTING=ON, full build, then the full non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out" -j6).mainalone: 1363/1363 pass.unwind_cursorand the fourunwind_cursor_*tests pass, butpublic_headersfails 3/3, and its 64public_headers_compile_*dependents don't run:35cf8d56c/f38d29fd0, merged 2026-10-24) added thepublic_headersaudit and canonical declarations of these three exports inlibc/include/Api.hpp. The newUnwindCursor.cppdeclares them a second time.Minimal fix I checked: include the canonical header and drop the three local declarations:
The rest of the test compiles unchanged. With it, the full non-GPU suite passes 1368/1368, including
public_headers, allpublic_headers_compile_*and the fiveunwind_cursor*tests.The head still merges cleanly onto the newer
main92bfca720. Sinceabed03546, nothing there has touched the audit script,libc/include/Api.hppor the tab bit.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.