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

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 30 03:49:51 PDT 2025


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/137951

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.

>From 27b7d0e7946fd030b7a8f0026a6732b51017ce62 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Tue, 18 Apr 2023 15:47:13 +0300
Subject: [PATCH] [libunwind] [SEH] Set NonVolatileRegisters before calling a
 personality 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.
---
 libunwind/src/Unwind-seh.cpp | 5 +++++
 1 file changed, 5 insertions(+)

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,



More information about the cfe-commits mailing list