|
| 1 | +#include <cstdlib> |
| 2 | +#include <cstdio> |
| 3 | +#include <exception> |
| 4 | +#include <bits/functexcept.h> |
| 5 | +#include <sdkconfig.h> |
| 6 | + |
| 7 | +#ifndef CONFIG_CXX_EXCEPTIONS |
| 8 | + |
| 9 | +const char *FATAL_EXCEPTION = "Fatal C++ exception: "; |
| 10 | + |
| 11 | +extern "C" void __cxx_fatal_exception(void) |
| 12 | +{ |
| 13 | + abort(); |
| 14 | +} |
| 15 | + |
| 16 | +extern "C" void __cxx_fatal_exception_message(const char *msg) |
| 17 | +{ |
| 18 | + printf("%s%s\n", FATAL_EXCEPTION, msg); |
| 19 | + abort(); |
| 20 | +} |
| 21 | + |
| 22 | +extern "C" void __cxx_fatal_exception_int(int i) |
| 23 | +{ |
| 24 | + printf("%s (%d)\n", FATAL_EXCEPTION, i); |
| 25 | + abort(); |
| 26 | +} |
| 27 | + |
| 28 | +void std::__throw_bad_exception(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 29 | + |
| 30 | +void std::__throw_bad_alloc(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 31 | + |
| 32 | +void std::__throw_bad_cast(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 33 | + |
| 34 | +void std::__throw_bad_typeid(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 35 | + |
| 36 | +void std::__throw_logic_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 37 | + |
| 38 | +void std::__throw_domain_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 39 | + |
| 40 | +void std::__throw_invalid_argument(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 41 | + |
| 42 | +void std::__throw_length_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 43 | + |
| 44 | +void std::__throw_out_of_range(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 45 | + |
| 46 | +void std::__throw_out_of_range_fmt(const char*, ...) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 47 | + |
| 48 | +void std::__throw_runtime_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 49 | + |
| 50 | +void std::__throw_range_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 51 | + |
| 52 | +void std::__throw_overflow_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 53 | + |
| 54 | +void std::__throw_underflow_error(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 55 | + |
| 56 | +void std::__throw_ios_failure(const char*) __attribute__((alias("__cxx_fatal_exception_message"))); |
| 57 | + |
| 58 | +void std::__throw_system_error(int) __attribute__((alias("__cxx_fatal_exception_int"))); |
| 59 | + |
| 60 | +void std::__throw_bad_function_call(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 61 | + |
| 62 | +void std::__throw_future_error(int) __attribute__((alias("__cxx_fatal_exception_int"))); |
| 63 | + |
| 64 | + |
| 65 | +/* The following definitions are needed because libstdc++ is also compiled with |
| 66 | + __throw_exception_again defined to throw, and some other exception code in a few places. |
| 67 | +
|
| 68 | + This cause exception handler code to be emitted in the library even though it's mostly |
| 69 | + unreachable (as any libstdc++ "throw" will first call one of the above stubs, which will abort). |
| 70 | +
|
| 71 | + If these are left out, a bunch of unwanted exception handler code is linked. |
| 72 | +
|
| 73 | + Note: these function prototypes are not correct. |
| 74 | +*/ |
| 75 | + |
| 76 | +extern "C" void __cxa_allocate_exception(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 77 | +extern "C" void __cxa_begin_catch(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 78 | +extern "C" void __cxa_end_catch(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 79 | +extern "C" void __cxa_get_exception_ptr(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 80 | +extern "C" void __cxa_free_exception(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 81 | +extern "C" void __cxa_rethrow(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 82 | +extern "C" void __cxa_throw(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 83 | +extern "C" void __cxa_call_terminate(void) __attribute__((alias("__cxx_fatal_exception"))); |
| 84 | + |
| 85 | +bool std::uncaught_exception() __attribute__((alias("__cxx_fatal_exception"))); |
| 86 | + |
| 87 | +#endif // CONFIG_CXX_EXCEPTIONS |
0 commit comments