fix(libc): return the fatal unwind error for an unknown personality on Windows #9585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9585"
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 DavidSamir on 2026-10-22T03:20:53Z.
What
On Windows,
LibcUnwind::CallPersonalitychecks whether the personality address is ajmp [rip+disp]import thunk, and follows it, before comparing it to the known personalities. It does that by reading the bytes at the address. An unknown personality that isn't mapped therefore crashed the process with an access violation. On Linux the same input returns_URC_FATAL_PHASE1_ERROR/_URC_FATAL_PHASE2_ERROR.exception_personalitycovers exactly this case (CallPersonality(0x1000, ...), ExceptionPersonality.cpp:87-88), but it was registered only underif(UNIX). Built on Windows, it segfaulted at that line, and every earlier check passed.How:
Unwind.cpp(Windows only):ResolveImportuses aReadable(address, size)helper that walks theVirtualQueryregions and requires them to be committed, notPAGE_NOACCESS/PAGE_GUARD, and not execute-only. The 6 thunk bytes are read only if readable, and the slot they point to only if readable. Otherwise the address is compared as it is and falls through to the fatal result.libc/CMakeLists.txt: anif(WIN32)block registersexception_personality(libc link,configure_windows_unwind,PATHprepend), and theif(UNIX)registration is untouched. Moving the lines out ofif(UNIX)instead would have conflicted with #4627, #5021 and #8658, which edit the adjacentexception_runtimelines.Tested
exception_personalitypasses.Unwind.cppchange reverted, it segfaults.tools/check_conventions.pypasses.Overlap (
tools/pr_overlap.py --branchplusgit merge-tree):static Word ResolveImport(Word), whichVirtualUnwindalso calls for.sehgcchandlers. Since the merge, the twoReadablechecks live inResolveImport, which returns the address unchanged when it is not readable, so they cover both callers.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 MarcZX10 on 2026-10-22T03:44:54Z.
Review: CHANGES_REQUESTED
The Windows guard addresses the reported invalid-address crash, and the Windows-only test registration is appropriately separate from the existing UNIX registration. The rerun conventions check on the current head passes, so the initial failing run is superseded.
The remaining required coordination is with #8087. It is open and changes
Unwind.cpp, the same file this PR modifies. The description already gives a concrete composition plan if #8087 lands first, but the checklist still saysDepends on: none, which does not record the required order. Please agree the order with #8087's author and updateDepends on(or document the agreed reverse order and corresponding rebase). The repository rule requires overlap order to be agreed and listed in the checklist.Hosted relinker, ASan, register-context and write-watch checks pass; the Linux and Windows product build jobs are skipped. The Windows test results in the description are author-reported; I did not run tests locally.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T04:28:51Z.
Merged
mainafter #8087 landed, in a new merge commit with no force-push. As this PR's description said it would, the twoReadablechecks now live in #8087'sResolveImport(Word): the thunk bytes and the slot are read only whenVirtualQueryreports them readable, and otherwise the address comes back unchanged. That covers bothCallPersonalityandVirtualUnwind's.sehgcchandler lookups. The diff againstmainis now justReadable, the guardedResolveImport, and theexception_personalityregistration.Re-run on the merge (Windows 11, WinLibs GCC 15.2):
exception_personalitypasses, and the 31 exception, unwind, backtrace, overflow_error and bad_optional_access tests pass.ResolveImport,exception_personalitysegfaults again.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:37:54Z.
Reviewed; verified the guard and the test wiring. On main,
ResolveImportunconditionally readcode[0]/code[1]and then the IAT slot ataddress + 6 + displacement, so a personality pointer into anything unmapped faulted inside the unwinder itself. The branch now gates both reads with aVirtualQuery-basedReadablecheck; when the reads fail the address is returned untouched, the two known-personality comparisons (dllimport/bound personalities) fall through, and the search/phase-2 callers return_URC_FATAL_PHASE1_ERROR/_URC_FATAL_PHASE2_ERROR— the Linux behavior, and both callers propagate non-CONTINUE_UNWINDresults so nothing swallows it. The diff leaves every mappedff 25thunk byte-identical to main (only unmapped inputs change behavior), and the secondResolveImportcaller (.sehgcchandler resolution) is covered by the same guard. The test'sCallPersonality(0x1000, …)cases pin exactly the previously faulting invocation for both phases, and theif(WIN32)registration block mirrors the existingguest_bad_optional_accesspattern.One nit:
Readable's loop advances byRegionSizeand only terminates via bounds or a failedVirtualQuery; a committed region reportingRegionSize == 0would in principle loop forever. Not reachable in practice, but amemory.RegionSize == 0bail-out alongside the other checks would make the guard airtight.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:24:28Z.
Thanks @fogydes, good catch.
1fdd345499makesReadabletreat a region reported withRegionSize == 0as unreadable, so the walk always ends. I also merged currentmain. The 31 exception, unwind, backtrace, overflow_error and bad_optional_access tests pass on Windows, andcheck_conventions.pypasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T10:20:32Z.
Review: DISMISSED
The fix now composes correctly with merged #8087: the
Readablechecks protect the sharedResolveImportpath used by both personality and.sehgcchandler lookup. The zero-sizeVirtualQueryregion case raised by the independent reviewer is also handled. I found no remaining behavior defect in the Windows guard, and the Windows red/green results are clearly reported by the author. One repository gate remains: 1. Test registration overlap: #6044 remains open and reorganizes the samelibc/CMakeLists.txtexception-test block. Its patch moves the existingexception_personalityregistration while this PR adds a Windows registration for that test. The overlap workflow could not compare #6044 because it conflicts withmain; the description notes the hunk count but does not record an agreed merge order with that PR's author or aDepends onedge. Please agree which change lands first and record the order in the checklist, then rebase accordingly. #8087 is already merged, so it no longer needs to be listed as a dependency. This head is also four commits behind currentupstream/main; please update it after the overlap order is agreed. Checks on exact heada3fa95b4d75b7c3ed5299216d98e102dd6d3ef91: -git diff --check upstream/main...HEAD: passed. -python tools/check_conventions.py --base upstream/main --head HEAD: passed. - The latest hosted relinker matrix, ASan, register-context and write-watch checks pass. Hosted Linux/Windows product jobs are skipped. - The Windows-onlyexception_personalitytarget is not available to run in this Linux workspace. The Windows test results and negative control in the PR description are author-reported; the independent review confirms the guard behavior and regression case. I am requesting changes for required overlap coordination and base freshness only, not a queue-based intake hold or a defect in the guarded read itself. It is fine to keep submitting PRs; maintainers will handle them in due course.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T10:21:28Z.
Thanks @MarcZX10 for the careful passes, and for confirming no remaining behaviour defect.
On intake: we're keeping this open under the same reasoning as on #9379. It's a small fix/test with negative controls and no inferred title. If a maintainer asks on this PR to hold it, I'll convert it to a draft right away. I'll merge
mainagain just before it's picked up, so the final matrix runs on the current base without a merge commit every few hours. For #6044 (theexception_personalityregistration it moves), I proposed the order on #6044: neither waits, and if #6044 lands first the Windows registration follows the moved file. I'll record the reply in the checklist. #8087 is merged and no longer listed.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:14:53Z.
Independent Windows run, as data only. Machine: Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Release. Head a3fa95b4d7 was merged onto
main8b3a6ba88d.exception_personalitypasses in 10 of 10 runs.core/libs/prx/libc/src/exception/Unwind.cppreverted tomain, it fails withException: SegFaultin 3 of 3 runs, as you reported.overflow_errorandbad_optional_accesstests: 30 always pass. The other,guest_raise_exception, times out in about half of runs here (5 of 10 serial runs at 60 s, 4 of 5 parallel runs at 30 s). That is the known Windows budget issue #9610 onmainand is not touched by this change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:29:40Z.
Correction to my earlier review: please disregard its intake objection and request to defer. Given your contribution-count eligibility, a queue-based hold does not apply, and I am not asking you to infer a title need.
The actionable review items are base freshness and the test-registration overlap. This head is 52 commits behind current
upstream/main8b3e39832af85f404c6195418d11b3e1ebd1924d;git diff --checkand current-main conventions pass. The author and independent reviewer report the Windows regression and negative control passing; I cannot run that Windows-only test in this Linux workspace, and hosted product jobs are skipped. #6044 is still open and its author has not replied to the proposed ordering posted there, so please record the agreed handling of theexception_personalityregistration before updating/retesting against current main. I found no new defect in the guarded read.