cxx_exception_stubs.cpp 3.9 KB

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