ams: move around abort handler to avoid linker errors

This commit is contained in:
Michael Scire 2021-05-07 17:48:52 -07:00
parent 6bb4253df5
commit bf8de39e69
2 changed files with 26 additions and 24 deletions

View File

@ -153,29 +153,14 @@ namespace ams {
::ams::ExceptionHandler(&ams_ctx);
}
inline NORETURN void AbortImpl() {
/* Just perform a data abort. */
register u64 addr __asm__("x27") = FatalErrorContext::StdAbortMagicAddress;
register u64 val __asm__("x28") = FatalErrorContext::StdAbortMagicValue;
while (true) {
__asm__ __volatile__ (
"str %[val], [%[addr]]"
:
: [val]"r"(val), [addr]"r"(addr)
);
}
__builtin_unreachable();
}
NORETURN void AbortImpl();
}
extern "C" {
/* Redefine abort to trigger these handlers. */
void abort();
/* Redefine C++ exception handlers. Requires wrap linker flag. */
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { abort(); __builtin_unreachable(); }
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { ::ams::AbortImpl(); __builtin_unreachable(); }
WRAP_ABORT_FUNC(__cxa_throw)
WRAP_ABORT_FUNC(__cxa_rethrow)
WRAP_ABORT_FUNC(__cxa_allocate_exception)
@ -195,9 +180,3 @@ extern "C" {
#undef WRAP_ABORT_FUNC
}
/* Custom abort handler, so that std::abort will trigger these. */
void abort() {
ams::AbortImpl();
__builtin_unreachable();
}

View File

@ -44,15 +44,38 @@ namespace ams {
__builtin_unreachable();
}
NOINLINE NORETURN void AbortImpl() {
/* Just perform a data abort. */
register u64 addr __asm__("x27") = FatalErrorContext::StdAbortMagicAddress;
register u64 val __asm__("x28") = FatalErrorContext::StdAbortMagicValue;
while (true) {
__asm__ __volatile__ (
"str %[val], [%[addr]]"
:
: [val]"r"(val), [addr]"r"(addr)
);
}
__builtin_unreachable();
}
}
extern "C" {
/* Redefine abort to trigger these handlers. */
void abort();
/* Redefine C++ exception handlers. Requires wrap linker flag. */
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { abort(); __builtin_unreachable(); }
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { ::ams::AbortImpl(); __builtin_unreachable(); }
WRAP_ABORT_FUNC(__cxa_pure_virtual)
#undef WRAP_ABORT_FUNC
void NORETURN __wrap_exit(int rc) { ::ams::Exit(rc); __builtin_unreachable(); }
}
/* Custom abort handler, so that std::abort will trigger these. */
void abort() {
ams::AbortImpl();
__builtin_unreachable();
}