-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[libunwind] Fix aarch64 unwinding with a debugger attached #162867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-libunwind Author: Martin Storsjö (mstorsjo) ChangesSee LuaJIT/LuaJIT#593 (comment) for the original explanation of the problem. In short; when a debugger is attached, there's a 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: #161851 Full diff: https://github.com/llvm/llvm-project/pull/162867.diff 1 Files Affected:
diff --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index 8b83f10615f22..058369acf3360 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -174,7 +174,7 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
}
// FIXME: Indicate target frame in foreign case!
// phase 2: the clean up phase
- RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, ms_ctx, disp->HistoryTable);
+ RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, disp->ContextRecord, disp->HistoryTable);
_LIBUNWIND_ABORT("RtlUnwindEx() failed");
case _URC_INSTALL_CONTEXT: {
// If we were called by __libunwind_seh_personality(), indicate that
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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#161851 Co-authored-by: Peter Cawley <corsix@corsix.org> Co-authored-by: Hannes Domani <ssbssa@yahoo.de>
3325101
to
7416b04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.
@llvm/reviewers-libunwind - Can I have a code owner approval here, or is it ok to merge this without one? |
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: #161851