Repository navigation
Implement x86 structured exception handling - #166
malvarezcastillo wants to merge 1 commit into
Conversation
|
I don't think we should take this hack upstream. Surely it's not that hard to work out signal handlers and basic SEH. Worst case, I could see accepting it behind a flag, that prints an error on non-32-bit-Linux. |
I'll look for a way to implement this (I need it for my environment) that isn't considered a hack then. Marking PR as draft in the meantiem |
Guest faults and RaiseException now go through the guest's fs:[0] handlers instead of killing the process, on i686 and x86_64 Linux and on macOS. The dispatch and unwind loops run in guest mode, so a handler that never returns leaves no host frames behind. This replaces the commit-on-fault hack: c1xx commits its reserved pages from its own filter.
30f8414 to
5650084
Compare
|
Reworked this into actual SEH: guest faults and |
Summary
Replaces the commit-on-fault hack with x86 structured exception handling, as suggested in review. Guest faults and
RaiseExceptionnow reach the guest'sfs:[0]handlers, soc1xxcommits its reserved pages with its own filter. It works on i686 and x86_64 Linux and on macOS.The loops run in guest mode and call handlers directly. A handler that never returns (
__except, a C++ catch,longjmp) therefore leaves no host frames behind. Host→guest thunks now keep the outerTEB_SP, and on x86_64r12–r15, so unwinding out of a guest callback leaves the host consistent.Evidence
SIGSEGV.cl.exe14.00.50727.762 dies with exit 139 on large translation units.test_seh.exefails at its first check.test_seh.exepasses under Wine and under wibo on the debug and release presets for i686 and x86_64 Linux, and on macOS arm64 (Rosetta). It covers commit-on-write, register and FPU state across a fault, context edits,RaiseException, nested exceptions, unwinding, noncontinuable exceptions, stack overflow, unwinding out of a callback and the top-level filter. All 61 fixtures pass on those builds.cl.exe: I applied this patch to a 1.2.0-based branch that adds the imports that toolchain needs, then compiled 58 translation units from a/GLproject. Six of them hit the reserved-page fault. All 58 objects are byte-identical to the ones the commit-on-fault build produced, which meansc1xx's own filter now does the commit. I can't share the sources.Merge Danger
Door: two-way
Blast Radius: wide
Every guest fault now runs guest handlers before anything else happens. Every host→guest callback goes through the changed thunks, and guest stacks reserve one more guard page.
Known limits:
CONTEXTare not restored.RaiseExceptionreports its caller's address rather than one inside it.DllMainraises)._resetstkoflwcan't re-arm the guard page, becauseVirtualProtectdoesn't handle guest stacks orPAGE_GUARD.intoreports an illegal instruction.