aboutsummaryrefslogtreecommitdiffstats
path: root/src/Unwind-seh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Unwind-seh.cpp')
-rw-r--r--src/Unwind-seh.cpp100
1 files changed, 55 insertions, 45 deletions
diff --git a/src/Unwind-seh.cpp b/src/Unwind-seh.cpp
index c5cf7c47d40d..7647f2e0db0b 100644
--- a/src/Unwind-seh.cpp
+++ b/src/Unwind-seh.cpp
@@ -1,9 +1,8 @@
//===--------------------------- Unwind-seh.cpp ---------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -53,14 +52,16 @@ static const uint64_t kSEHExceptionClass = 0x434C4E4753454800; // CLNGSEH\0
/// Exception cleanup routine used by \c _GCC_specific_handler to
/// free foreign exceptions.
static void seh_exc_cleanup(_Unwind_Reason_Code urc, _Unwind_Exception *exc) {
+ (void)urc;
if (exc->exception_class != kSEHExceptionClass)
_LIBUNWIND_ABORT("SEH cleanup called on non-SEH exception");
free(exc);
}
-static int _unw_init_seh(unw_cursor_t *cursor, CONTEXT *ctx);
-static DISPATCHER_CONTEXT *_unw_seh_get_disp_ctx(unw_cursor_t *cursor);
-static void _unw_seh_set_disp_ctx(unw_cursor_t *cursor, DISPATCHER_CONTEXT *disp);
+static int __unw_init_seh(unw_cursor_t *cursor, CONTEXT *ctx);
+static DISPATCHER_CONTEXT *__unw_seh_get_disp_ctx(unw_cursor_t *cursor);
+static void __unw_seh_set_disp_ctx(unw_cursor_t *cursor,
+ DISPATCHER_CONTEXT *disp);
/// Common implementation of SEH-style handler functions used by Itanium-
/// style frames. Depending on how and why it was called, it may do one of:
@@ -69,7 +70,6 @@ static void _unw_seh_set_disp_ctx(unw_cursor_t *cursor, DISPATCHER_CONTEXT *disp
_LIBUNWIND_EXPORT EXCEPTION_DISPOSITION
_GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
DISPATCHER_CONTEXT *disp, __personality_routine pers) {
- unw_context_t uc;
unw_cursor_t cursor;
_Unwind_Exception *exc;
_Unwind_Action action;
@@ -78,7 +78,9 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
uintptr_t retval, target;
bool ours = false;
- _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler(%#010x(%x), %p)", ms_exc->ExceptionCode, ms_exc->ExceptionFlags, frame);
+ _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler(%#010lx(%lx), %p)",
+ ms_exc->ExceptionCode, ms_exc->ExceptionFlags,
+ (void *)frame);
if (ms_exc->ExceptionCode == STATUS_GCC_UNWIND) {
if (IS_TARGET_UNWIND(ms_exc->ExceptionFlags)) {
// Set up the upper return value (the lower one and the target PC
@@ -112,9 +114,9 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
memset(exc->private_, 0, sizeof(exc->private_));
}
if (!ctx) {
- _unw_init_seh(&cursor, disp->ContextRecord);
- _unw_seh_set_disp_ctx(&cursor, disp);
- unw_set_reg(&cursor, UNW_REG_IP, disp->ControlPc-1);
+ __unw_init_seh(&cursor, disp->ContextRecord);
+ __unw_seh_set_disp_ctx(&cursor, disp);
+ __unw_set_reg(&cursor, UNW_REG_IP, disp->ControlPc - 1);
ctx = (struct _Unwind_Context *)&cursor;
if (!IS_UNWINDING(ms_exc->ExceptionFlags)) {
@@ -130,7 +132,10 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
}
}
- _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler() calling personality function %p(1, %d, %llx, %p, %p)", pers, action, exc->exception_class, exc, ctx);
+ _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler() calling personality "
+ "function %p(1, %d, %llx, %p, %p)",
+ (void *)pers, action, exc->exception_class,
+ (void *)exc, (void *)ctx);
urc = pers(1, action, exc->exception_class, exc, ctx);
_LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler() personality returned %d", urc);
switch (urc) {
@@ -168,18 +173,18 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
_LIBUNWIND_ABORT("Personality installed context during phase 1!");
#ifdef __x86_64__
exc->private_[2] = disp->TargetIp;
- unw_get_reg(&cursor, UNW_X86_64_RAX, &retval);
- unw_get_reg(&cursor, UNW_X86_64_RDX, &exc->private_[3]);
+ __unw_get_reg(&cursor, UNW_X86_64_RAX, &retval);
+ __unw_get_reg(&cursor, UNW_X86_64_RDX, &exc->private_[3]);
#elif defined(__arm__)
exc->private_[2] = disp->TargetPc;
- unw_get_reg(&cursor, UNW_ARM_R0, &retval);
- unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]);
+ __unw_get_reg(&cursor, UNW_ARM_R0, &retval);
+ __unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]);
#elif defined(__aarch64__)
exc->private_[2] = disp->TargetPc;
- unw_get_reg(&cursor, UNW_ARM64_X0, &retval);
- unw_get_reg(&cursor, UNW_ARM64_X1, &exc->private_[3]);
+ __unw_get_reg(&cursor, UNW_ARM64_X0, &retval);
+ __unw_get_reg(&cursor, UNW_ARM64_X1, &exc->private_[3]);
#endif
- unw_get_reg(&cursor, UNW_REG_IP, &target);
+ __unw_get_reg(&cursor, UNW_REG_IP, &target);
ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
#ifdef __x86_64__
ms_exc->ExceptionInformation[2] = disp->TargetIp;
@@ -199,7 +204,7 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
}
}
-/// Personality function returned by \c unw_get_proc_info() in SEH contexts.
+/// Personality function returned by \c __unw_get_proc_info() in SEH contexts.
/// This is a wrapper that calls the real SEH handler function, which in
/// turn (at least, for Itanium-style frames) calls the real Itanium
/// personality function (see \c _GCC_specific_handler()).
@@ -207,6 +212,8 @@ extern "C" _Unwind_Reason_Code
__libunwind_seh_personality(int version, _Unwind_Action state,
uint64_t klass, _Unwind_Exception *exc,
struct _Unwind_Context *context) {
+ (void)version;
+ (void)klass;
EXCEPTION_RECORD ms_exc;
bool phase2 = (state & (_UA_SEARCH_PHASE|_UA_CLEANUP_PHASE)) == _UA_CLEANUP_PHASE;
ms_exc.ExceptionCode = STATUS_GCC_THROW;
@@ -215,7 +222,8 @@ __libunwind_seh_personality(int version, _Unwind_Action state,
ms_exc.ExceptionInformation[0] = (ULONG_PTR)exc;
ms_exc.ExceptionInformation[1] = (ULONG_PTR)context;
ms_exc.ExceptionInformation[2] = state;
- DISPATCHER_CONTEXT *disp_ctx = _unw_seh_get_disp_ctx((unw_cursor_t *)context);
+ DISPATCHER_CONTEXT *disp_ctx =
+ __unw_seh_get_disp_ctx((unw_cursor_t *)context);
EXCEPTION_DISPOSITION ms_act = disp_ctx->LanguageHandler(&ms_exc,
(PVOID)disp_ctx->EstablisherFrame,
disp_ctx->ContextRecord,
@@ -234,15 +242,15 @@ unwind_phase2_forced(unw_context_t *uc,
_Unwind_Exception *exception_object,
_Unwind_Stop_Fn stop, void *stop_parameter) {
unw_cursor_t cursor2;
- unw_init_local(&cursor2, uc);
+ __unw_init_local(&cursor2, uc);
// Walk each frame until we reach where search phase said to stop
- while (unw_step(&cursor2) > 0) {
+ while (__unw_step(&cursor2) > 0) {
// Update info about this frame.
unw_proc_info_t frameInfo;
- if (unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {
- _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): unw_step "
+ if (__unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {
+ _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step "
"failed => _URC_END_OF_STACK",
(void *)exception_object);
return _URC_FATAL_PHASE2_ERROR;
@@ -253,8 +261,8 @@ unwind_phase2_forced(unw_context_t *uc,
char functionBuf[512];
const char *functionName = functionBuf;
unw_word_t offset;
- if ((unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),
- &offset) != UNW_ESUCCESS) ||
+ if ((__unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),
+ &offset) != UNW_ESUCCESS) ||
(frameInfo.start_ip + offset > frameInfo.end_ip))
functionName = ".anonymous.";
_LIBUNWIND_TRACE_UNWINDING(
@@ -304,7 +312,7 @@ unwind_phase2_forced(unw_context_t *uc,
"_URC_INSTALL_CONTEXT",
(void *)exception_object);
// We may get control back if landing pad calls _Unwind_Resume().
- unw_resume(&cursor2);
+ __unw_resume(&cursor2);
break;
default:
// Personality routine returned an unknown result code.
@@ -369,7 +377,7 @@ _Unwind_Resume(_Unwind_Exception *exception_object) {
if (exception_object->private_[0] != 0) {
unw_context_t uc;
- unw_getcontext(&uc);
+ __unw_getcontext(&uc);
unwind_phase2_forced(&uc, exception_object,
(_Unwind_Stop_Fn) exception_object->private_[0],
(void *)exception_object->private_[4]);
@@ -407,7 +415,7 @@ _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
_LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)",
(void *)exception_object, (void *)(uintptr_t)stop);
unw_context_t uc;
- unw_getcontext(&uc);
+ __unw_getcontext(&uc);
// Mark that this is a forced unwind, so _Unwind_Resume() can do
// the right thing.
@@ -421,7 +429,8 @@ _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
/// Called by personality handler during phase 2 to get LSDA for current frame.
_LIBUNWIND_EXPORT uintptr_t
_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
- uintptr_t result = (uintptr_t)_unw_seh_get_disp_ctx((unw_cursor_t *)context)->HandlerData;
+ uintptr_t result =
+ (uintptr_t)__unw_seh_get_disp_ctx((unw_cursor_t *)context)->HandlerData;
_LIBUNWIND_TRACE_API(
"_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIxPTR,
(void *)context, result);
@@ -432,30 +441,32 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
/// function.
_LIBUNWIND_EXPORT uintptr_t
_Unwind_GetRegionStart(struct _Unwind_Context *context) {
- DISPATCHER_CONTEXT *disp = _unw_seh_get_disp_ctx((unw_cursor_t *)context);
+ DISPATCHER_CONTEXT *disp = __unw_seh_get_disp_ctx((unw_cursor_t *)context);
uintptr_t result = (uintptr_t)disp->FunctionEntry->BeginAddress + disp->ImageBase;
_LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%" PRIxPTR,
(void *)context, result);
return result;
}
-static int
-_unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) {
+static int __unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) {
#ifdef _LIBUNWIND_TARGET_X86_64
- new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_x86_64>(
- context, LocalAddressSpace::sThisAddressSpace);
+ new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_x86_64> *>(cursor))
+ UnwindCursor<LocalAddressSpace, Registers_x86_64>(
+ context, LocalAddressSpace::sThisAddressSpace);
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
co->setInfoBasedOnIPRegister();
return UNW_ESUCCESS;
#elif defined(_LIBUNWIND_TARGET_ARM)
- new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm>(
- context, LocalAddressSpace::sThisAddressSpace);
+ new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm> *>(cursor))
+ UnwindCursor<LocalAddressSpace, Registers_arm>(
+ context, LocalAddressSpace::sThisAddressSpace);
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
co->setInfoBasedOnIPRegister();
return UNW_ESUCCESS;
#elif defined(_LIBUNWIND_TARGET_AARCH64)
- new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm64>(
- context, LocalAddressSpace::sThisAddressSpace);
+ new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm64> *>(cursor))
+ UnwindCursor<LocalAddressSpace, Registers_arm64>(
+ context, LocalAddressSpace::sThisAddressSpace);
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
co->setInfoBasedOnIPRegister();
return UNW_ESUCCESS;
@@ -464,8 +475,7 @@ _unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) {
#endif
}
-static DISPATCHER_CONTEXT *
-_unw_seh_get_disp_ctx(unw_cursor_t *cursor) {
+static DISPATCHER_CONTEXT *__unw_seh_get_disp_ctx(unw_cursor_t *cursor) {
#ifdef _LIBUNWIND_TARGET_X86_64
return reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_x86_64> *>(cursor)->getDispatcherContext();
#elif defined(_LIBUNWIND_TARGET_ARM)
@@ -477,8 +487,8 @@ _unw_seh_get_disp_ctx(unw_cursor_t *cursor) {
#endif
}
-static void
-_unw_seh_set_disp_ctx(unw_cursor_t *cursor, DISPATCHER_CONTEXT *disp) {
+static void __unw_seh_set_disp_ctx(unw_cursor_t *cursor,
+ DISPATCHER_CONTEXT *disp) {
#ifdef _LIBUNWIND_TARGET_X86_64
reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_x86_64> *>(cursor)->setDispatcherContext(disp);
#elif defined(_LIBUNWIND_TARGET_ARM)