Skip to content

Commit a17afee

Browse files
mstorsjocorsixssbssa
authored
[libunwind] Fix aarch64 SEH unwinding with a debugger attached (#162867)
See LuaJIT/LuaJIT#593 (comment) for the original explanation of the problem. In short; when a debugger is attached, there's a function KiUserExceptionDispatcher in the stack that is being unwound. The function KiUserExceptionDispatcher contains a CONTEXT, with a copy of the context from where the exception was raised. When unwinding through this function, this whole CONTEXT gets restored. This CONTEXT is what we receive a pointer to in the callbacks, as the ms_ctx pointer. When we unwind manually using RtlUnwindEx, the unwinding overwrites the CONTEXT that is passed to it. Thus, to avoid clobbering the CONTEXT that needs to be restored by KiUserExceptionDispatcher, we could either declare a new temporary CONTEXT on the stack before calling RtlUnwindEx, or just use disp->ContextRecord as we already have available. Fixes: llvm/llvm-project#161851 Co-authored-by: Peter Cawley <[email protected]> Co-authored-by: Hannes Domani <[email protected]>
1 parent 2a7e7e2 commit a17afee

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libunwind/src/Unwind-seh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
174174
}
175175
// FIXME: Indicate target frame in foreign case!
176176
// phase 2: the clean up phase
177-
RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, ms_ctx, disp->HistoryTable);
177+
RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, disp->ContextRecord,
178+
disp->HistoryTable);
178179
_LIBUNWIND_ABORT("RtlUnwindEx() failed");
179180
case _URC_INSTALL_CONTEXT: {
180181
// If we were called by __libunwind_seh_personality(), indicate that

0 commit comments

Comments
 (0)