From 7472bc1c7f3b73c2a17dd6c3d5c45e2811252008 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 8 Dec 2019 03:29:47 -0800 Subject: [PATCH] Improve exception wrapping --- stratosphere/ams_mitm/Makefile | 7 ++++- stratosphere/boot/Makefile | 7 ++++- stratosphere/boot2/Makefile | 7 ++++- stratosphere/creport/Makefile | 7 ++++- stratosphere/dmnt/Makefile | 7 ++++- stratosphere/eclct.stub/Makefile | 7 ++++- stratosphere/fatal/Makefile | 7 ++++- .../source/ams/ams_environment.cpp | 30 +++++++++++++------ stratosphere/loader/Makefile | 7 ++++- stratosphere/pm/Makefile | 7 ++++- stratosphere/ro/Makefile | 7 ++++- stratosphere/sm/Makefile | 7 ++++- stratosphere/spl/Makefile | 7 ++++- 13 files changed, 93 insertions(+), 21 deletions(-) diff --git a/stratosphere/ams_mitm/Makefile b/stratosphere/ams_mitm/Makefile index 80cdb7332..4bd985667 100644 --- a/stratosphere/ams_mitm/Makefile +++ b/stratosphere/ams_mitm/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/boot/Makefile b/stratosphere/boot/Makefile index cd7f519cd..f70d9049b 100644 --- a/stratosphere/boot/Makefile +++ b/stratosphere/boot/Makefile @@ -56,11 +56,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/boot2/Makefile b/stratosphere/boot2/Makefile index 52911803e..cedb94b15 100644 --- a/stratosphere/boot2/Makefile +++ b/stratosphere/boot2/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/creport/Makefile b/stratosphere/creport/Makefile index 4b06622de..ab283ad98 100644 --- a/stratosphere/creport/Makefile +++ b/stratosphere/creport/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/dmnt/Makefile b/stratosphere/dmnt/Makefile index 5e65198ed..9c3e0a2fc 100644 --- a/stratosphere/dmnt/Makefile +++ b/stratosphere/dmnt/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/eclct.stub/Makefile b/stratosphere/eclct.stub/Makefile index 52911803e..cedb94b15 100644 --- a/stratosphere/eclct.stub/Makefile +++ b/stratosphere/eclct.stub/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/fatal/Makefile b/stratosphere/fatal/Makefile index 8d7dca879..ec1821d26 100644 --- a/stratosphere/fatal/Makefile +++ b/stratosphere/fatal/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/libstratosphere/source/ams/ams_environment.cpp b/stratosphere/libstratosphere/source/ams/ams_environment.cpp index 9025615ae..16d1cf30c 100644 --- a/stratosphere/libstratosphere/source/ams/ams_environment.cpp +++ b/stratosphere/libstratosphere/source/ams/ams_environment.cpp @@ -136,6 +136,7 @@ namespace ams { : [val]"r"(val), [addr]"r"(addr) ); } + __builtin_unreachable(); } } @@ -146,19 +147,30 @@ extern "C" { void abort(); /* Redefine C++ exception handlers. Requires wrap linker flag. */ - void __wrap___cxa_pure_virtual(void) { abort(); } - void __wrap___cxa_throw(void) { abort(); } - void __wrap___cxa_rethrow(void) { abort(); } - void __wrap___cxa_allocate_exception(void) { abort(); } - void __wrap___cxa_begin_catch(void) { abort(); } - void __wrap___cxa_end_catch(void) { abort(); } - void __wrap___cxa_call_unexpected(void) { abort(); } - void __wrap___cxa_call_terminate(void) { abort(); } - void __wrap___gxx_personality_v0(void) { abort(); } + #define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { abort(); __builtin_unreachable(); } + WRAP_ABORT_FUNC(__cxa_pure_virtual) + WRAP_ABORT_FUNC(__cxa_throw) + WRAP_ABORT_FUNC(__cxa_rethrow) + WRAP_ABORT_FUNC(__cxa_allocate_exception) + WRAP_ABORT_FUNC(__cxa_free_exception) + WRAP_ABORT_FUNC(__cxa_begin_catch) + WRAP_ABORT_FUNC(__cxa_end_catch) + WRAP_ABORT_FUNC(__cxa_call_unexpected) + WRAP_ABORT_FUNC(__cxa_call_terminate) + WRAP_ABORT_FUNC(__gxx_personality_v0) + WRAP_ABORT_FUNC(_ZSt19__throw_logic_errorPKc) + WRAP_ABORT_FUNC(_ZSt20__throw_length_errorPKc) + WRAP_ABORT_FUNC(_ZNSt11logic_errorC2EPKc) + + /* TODO: We may wish to consider intentionally not defining an _Unwind_Resume wrapper. */ + /* This would mean that a failure to wrap all exception functions is a linker error. */ + WRAP_ABORT_FUNC(_Unwind_Resume) + #undef WRAP_ABORT_FUNC } /* Custom abort handler, so that std::abort will trigger these. */ void abort() { ams::AbortImpl(); + __builtin_unreachable(); } diff --git a/stratosphere/loader/Makefile b/stratosphere/loader/Makefile index a33159bd1..47457ed33 100644 --- a/stratosphere/loader/Makefile +++ b/stratosphere/loader/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/pm/Makefile b/stratosphere/pm/Makefile index 1fcad970c..dc2d72a8c 100644 --- a/stratosphere/pm/Makefile +++ b/stratosphere/pm/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/ro/Makefile b/stratosphere/ro/Makefile index 8d4e634b2..a0a911f58 100644 --- a/stratosphere/ro/Makefile +++ b/stratosphere/ro/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/stratosphere/sm/Makefile b/stratosphere/sm/Makefile index f4ff49057..eee88a1cc 100644 --- a/stratosphere/sm/Makefile +++ b/stratosphere/sm/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) diff --git a/stratosphere/spl/Makefile b/stratosphere/spl/Makefile index a33159bd1..47457ed33 100644 --- a/stratosphere/spl/Makefile +++ b/stratosphere/spl/Makefile @@ -49,11 +49,16 @@ CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,__cxa_throw \ -Wl,--wrap,__cxa_rethrow \ -Wl,--wrap,__cxa_allocate_exception \ + -Wl,--wrap,__cxa_free_exception \ -Wl,--wrap,__cxa_begin_catch \ -Wl,--wrap,__cxa_end_catch \ -Wl,--wrap,__cxa_call_unexpected \ -Wl,--wrap,__cxa_call_terminate \ - -Wl,--wrap,__gxx_personality_v0 + -Wl,--wrap,__gxx_personality_v0 \ + -Wl,--wrap,_Unwind_Resume \ + -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ + -Wl,--wrap,_ZSt20__throw_length_errorPKc \ + -Wl,--wrap,_ZNSt11logic_errorC2EPKc ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map)