Skip to content

[libunwind] [SEH] Set NonVolatileRegisters before calling a personality function #137951

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mstorsjo
Copy link
Member

The CRT __C_specific_handler function uses this for restoring registers before calling the filter function.

This fixes the libunwind/libcxxabi forced unwind testcases on ARM and AArch64.

@mstorsjo mstorsjo requested a review from a team as a code owner April 30, 2025 10:49
@mstorsjo
Copy link
Member Author

Together with #137949 and #137950, this makes check-cxxabi and check-unwind pass on aarch64 and arm.

@llvmbot
Copy link
Member

llvmbot commented Apr 30, 2025

@llvm/pr-subscribers-libunwind

Author: Martin Storsjö (mstorsjo)

Changes

The CRT __C_specific_handler function uses this for restoring registers before calling the filter function.

This fixes the libunwind/libcxxabi forced unwind testcases on ARM and AArch64.


Full diff: https://github.com/llvm/llvm-project/pull/137951.diff

1 Files Affected:

  • (modified) libunwind/src/Unwind-seh.cpp (+5)
diff --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index b2bb119ed6d29..f6525af07e25f 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -212,6 +212,11 @@ __libunwind_seh_personality(int version, _Unwind_Action state,
   ms_exc.ExceptionInformation[2] = state;
   DISPATCHER_CONTEXT *disp_ctx =
       __unw_seh_get_disp_ctx((unw_cursor_t *)context);
+#if defined(__aarch64__)
+  disp_ctx->NonVolatileRegisters = (PBYTE)&disp_ctx->ContextRecord->X19;
+#elif defined(__arm__)
+  disp_ctx->NonVolatileRegisters = (PBYTE)&disp_ctx->ContextRecord->R4;
+#endif
   _LIBUNWIND_TRACE_UNWINDING("__libunwind_seh_personality() calling "
                              "LanguageHandler %p(%p, %p, %p, %p)",
                              (void *)disp_ctx->LanguageHandler, (void *)&ms_exc,

@mstorsjo mstorsjo force-pushed the libunwind-seh-nonvolatile branch from 27b7d0e to 31a2490 Compare May 2, 2025 12:18
Copy link
Contributor

@cjacek cjacek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me overall.

…ty function

The CRT __C_specific_handler function uses this for restoring
registers before calling the filter function.

This fixes the libunwind/libcxxabi forced unwind testcases on
ARM and AArch64.
@mstorsjo mstorsjo force-pushed the libunwind-seh-nonvolatile branch from 31a2490 to 6072d4b Compare May 5, 2025 10:57
@mstorsjo
Copy link
Member Author

mstorsjo commented May 5, 2025

@MaskRay Can you give the necessary @reviewers-libunwind approval here, given @cjacek's review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants