fix(libkernel): report guest unwind tables in sceKernelGetModuleInfoForUnwind #904
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/904"
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 merwie on 2026-10-06T15:10:03Z.
What
On Windows,
sceKernelGetModuleInfoForUnwindreported no unwind tables for any address (eh_frame_hdr_addr,eh_frame_addrandeh_frame_sizeall 0). A title that ships its ownlibc.prxunwinds C++ exceptions with that libc's libunwind, which asks this call where a frame's FDEs are. With the empty answer it finds nothing, and the first C++ exception thrown in guest code ends interminate.PPSA12544 (Hollow Knight: Silksong, Unity/IL2CPP) died that way right after its intro cinematic:
The exception is a
System.Reflection.AmbiguousMatchExceptionthat Unity's invoke wrapper in the executable normally catches and logs; the search phase just never reached it.For an address in a relinked guest image, the call now returns:
eh_frame_hdr_addr: thePT_GNU_EH_FRAMEsegment the relinker names in.ehmeta(the same section the emulator's own libc unwinder reads);eh_frame_addr: decoded from the header'seh_frame_ptr;eh_frame_size: found by walking the records to the zero terminator, not counting the terminator;seg0: the whole image.Once an image has
.ehmeta, every other outcome throws instead of giving the empty answer:eh_frame_hdrversion other than 1;eh_frame_ptrencoding other than absptr or pcrel (datarel, funcrel, aligned and indirect throw, as do the omit encoding and unknown value formats);0xffffffff);eh_frame_ptroutside the image, or no terminator inside it.A
MEM_IMAGEwithout DOS/NT signatures also throws. Host images, which have no.ehmeta, keep the empty answer. Linux is unchanged.eh_frame_sizeand the terminator: I followed LLVM libunwind, which Sony's libunwind derives from.CFI_Parser::findFDEscans from the start of.eh_frameuntil either the given length runs out or it reads a zero length. So a size with or without the terminator finds the same FDEs. For aPT_GNU_EH_FRAMEfound throughdl_iterate_phdr, LLVM passesSIZE_MAXand relies on the terminator alone. What the console's kernel reports is not public, so TechnicalDebt records the choice.The
guest_unwind_module_infotest (Windows) uses a small fixture DLL whose.ehmetapoints at aneh_frame_hdrwith one CIE. It checks:eh_frame_ptrencodings 0x3b (datarel), 0x9b (indirect), 0x0f (unknown format) and 0xff (omit), and for a 64-bit length record;kernel32.The fixture is a separate DLL because the emulator's unwinder reads the same
.ehmeta: with a broken table in the test executable itself, the thrown exception could not be caught there. The test fails without the change.Tested
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T22:02:54Z.
Thanks, the Silksong trace makes the cause clear, and the happy path looks right to me: the header comes from
.ehmeta,eh_frame_ptris decoded, the walk goes to the terminator, and seg0 is the whole image.One point on exactness. Once an image has
.ehmeta, every other outcome should throw rather than fall back to the empty answer, since an empty answer just moves the failure to aterminatelater on:FillGuestUnwindInforeturns silently when the header version isn't 1, whenReadEncodeddoesn't know theeh_frame_ptrencoding (it returns 0), and when the DOS/NT signatures don't match for aMEM_IMAGE.ReadEncodedapplies only the pcrel bit (0x10). Any other application bits (datarel, funcrel, aligned, indirect) are ignored, so the value it returns would be wrong without any error. It should throw for anything other than absptr or pcrel.0xffffffff) and reports the size up to that point, which is a shorteh_frame_size. Throwing there would be better too.Images without
.ehmeta(host DLLs) keeping the empty answer is fine.Also, after the last batch this branch conflicts with main in
core/libs/prx/libkernel/CMakeLists.txt, so please rebase onto main when you push the change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T20:08:21Z.
Review: CHANGES_REQUESTED
Agree with Dean's points above (throw instead of the empty answer once
.ehmetaexists, only absptr/pcrel inReadEncoded, throw on the 64-bit length, rebase on main forlibkernel/CMakeLists.txt). Two additions:core/libs/tests/GuestUnwindModuleInfo.cpp: once those paths throw, each needs a case (version != 1, unsupportedeh_frame_ptrencoding, 64-bit length record); today only the happy path and the host image are covered.Module.cpp:58:eh_frame_sizestops before the zero terminator (16 in the test). Please say which reference the libunwind consumer follows for this (with or without the terminator), in the PR description.Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-07T21:48:48Z.
Test report from a second machine, in case it helps review.
Setup: Windows 11, Intel i9-10850K, NVIDIA RTX 3080, WinLibs GCC 15.2.0. PPSA12544 v1.0.30021, relinked with
--windows --to-intel --module-dir Media/Plugins.Stack:
0d3c1eecplus #759, #760, #846, #842, #844, #839, #904 (f5cebd30), #788 (8710433f), #903, #518, #301, #1101, #864, #1120, and the POSIXrenamefrom #1192 (this title imports it).Result: the title boots past the Team Cherry logos to the main menu (Start Game / Options / Extras) and holds 60 FPS (vsync) there for several minutes, from a warm or a cold shader cache (cold: one dip while pipelines compile around 30 s).
APS5_PROFILE_DRAW=1at the menu shows about 1,790 draws/s, about 90-100 us of CPU per draw, and the GPU worker about 23% busy. I have not gone past the menu yet, so I can't confirm the post-cinematic path this PR fixes on my side; I'll report back when I do.Small visual artifact at the menu: a white block covers the first letter of "Options". I have not looked into which draw produces it.
AI-assisted (Claude Code) testing and write-up.
Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-07T22:47:38Z.
Thanks both. Addressed in 732a8b50 and 6eed05c0:
.ehmetaexists: version other than 1, aneh_frame_ptroutside the image, no terminator inside the image, and aMEM_IMAGEwithout DOS/NT signatures. Images without.ehmetakeep the empty answer.ReadEncoded: only absptr and pcrel are accepted. Any other application bits, the indirect bit, the omit encoding and unknown value formats throw (NotImplemented_nid_no_patch).NotImplemented_nid_no_patch)..ehmetamoved into a small fixture DLL. The emulator's unwinder reads the same section, so with a broken table in the test executable the exception could not be caught there. The fixture defines the section with a top-levelasmdeclaration, since the new conventions check rejects__attribute__. Without the change the test fails.eh_frame_size: it stops before the terminator. The reference is in the description: LLVM libunwind'sCFI_Parser::findFDEstops at either the length or a zero length, whichever comes first, so both values find the same FDEs, and LLVM's own ELF path passesSIZE_MAXand relies on the terminator. The console's value is unknown, so TechnicalDebt has a line for it.main: merged, which resolves thelibkernel/CMakeLists.txtconflict. I haven't rebased yet; I'll follow up on that separately.Non-GPU tests pass (239).
tools/check_conventions.pyreports one doc-link error for the new TechnicalDebt line when run on Windows only.os.path.normpathturns the link into a backslash path there, and the target exists, so it does not happen on Linux CI.Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-07T23:10:54Z.
Rebased onto current
main(df16c4c2) as requested; the merge commits are gone. The branch is three commits: the original fix, the throw paths with their tests, and the fixture without compiler extensions. Same changes as before the rebase. Non-GPU tests pass (239).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T05:21:19Z.
Review: APPROVED
Checked the diff against Dean's and my earlier requests: throws once
.ehmetaexists, only absptr/pcrel inReadEncoded, 64-bit length throws, fixture tests for each, rebased, terminator choice recorded in TechnicalDebt. CI is green on this head and the Windows job runsguest_unwind_module_info(Passed). Windows-only code, Linux unchanged; merging.Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-10T09:17:36Z.
Follow-up as promised: PPSA12544 now gets past the intro cinematic into gameplay with this change on
main.Setup: Windows 11, Intel i9-10850K, NVIDIA RTX 3080, DualSense over SDL.
main6cc33583plus a local integration branch (#846 for the runtime-loaded plugins, and a few open AGC PRs). Relinked with--windows --to-intel --module-dir Media/Plugins.Result: the game was played from the menu through the cinematic into gameplay. The window-title counter read 59.92 FPS during gameplay (5847 frames at 135 s, including boot and loading), and it played smoothly. The log has no exceptions and no skipped draws. The gameplay was played by hand and only the counter was measured, with no profiling.
Written with AI assistance.