cxx_exception_stubs.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <exception>
  4. #include <bits/functexcept.h>
  5. #include <sdkconfig.h>
  6. #ifndef CONFIG_COMPILER_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. /* The following definitions are needed because libstdc++ is also compiled with
  32. __throw_exception_again defined to throw, and some other exception code in a few places.
  33. This cause exception handler code to be emitted in the library even though it's mostly
  34. unreachable (as any libstdc++ "throw" will first call one of the above stubs, which will abort).
  35. If these are left out, a bunch of unwanted exception handler code is linked.
  36. Note: these function prototypes are not correct.
  37. */
  38. extern "C" void __cxa_allocate_exception(void) __attribute__((alias("__cxx_fatal_exception")));
  39. extern "C" void __cxa_allocate_dependent_exception(void) __attribute__((alias("__cxx_fatal_exception")));
  40. extern "C" void __cxa_begin_catch(void) __attribute__((alias("__cxx_fatal_exception")));
  41. extern "C" void __cxa_end_catch(void) __attribute__((alias("__cxx_fatal_exception")));
  42. extern "C" void __cxa_get_exception_ptr(void) __attribute__((alias("__cxx_fatal_exception")));
  43. extern "C" void __cxa_free_exception(void) __attribute__((alias("__cxx_fatal_exception")));
  44. extern "C" void __cxa_free_dependent_exception(void) __attribute__((alias("__cxx_fatal_exception")));
  45. extern "C" void __cxa_rethrow(void) __attribute__((alias("__cxx_fatal_exception")));
  46. extern "C" void __cxa_throw(void) __attribute__((alias("__cxx_fatal_exception")));
  47. extern "C" void __cxa_call_terminate(void) __attribute__((alias("__cxx_fatal_exception")));
  48. bool std::uncaught_exception() __attribute__((alias("__cxx_fatal_exception_bool")));
  49. #endif // CONFIG_COMPILER_CXX_EXCEPTIONS