9 #include "exception_handling.h"
12 int uncaught_exception_count;
13 __cxa_exception *uncaught_exception_top;
18 } emergency_exception;
19 /*__thread*/ bool emergency_exception_used;
21 static bool TEST_AND_SET(bool& flag) {
28 extern "C" void __cxa_call_unexpected(void *)
30 // An unexpected exception was thrown from a function that lists its possible exceptions
34 extern "C" void *__cxa_allocate_exception(size_t thrown_size)
36 __cxa_exception *ret = static_cast<__cxa_exception*>( malloc( sizeof(__cxa_exception) + thrown_size ) );
38 if( thrown_size <= sizeof(emergency_exception.buf) && TEST_AND_SET(emergency_exception_used) )
40 ret = &emergency_exception.info;
49 extern "C" void __cxa_free_exception(void *thrown_exception)
51 if(thrown_exception == &emergency_exception.buf) {
52 //assert(emergency_exception_used);
53 emergency_exception_used = false;
56 __cxa_exception *except = static_cast<__cxa_exception*>( thrown_exception ) - 1;
61 extern "C" void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void (*dest)(void*))
63 __cxa_exception *except = static_cast<__cxa_exception*>( thrown_exception ) - 1;
65 except->exceptionType = tinfo;
66 except->exceptionDestructor = dest;
67 memcpy(&except->unwindHeader.exception_class, "Ac20C++\0", 8);
68 uncaught_exception_top ++;
70 _Unwind_RaiseException(thrown_exception);
75 extern "C" void *__cxa_begin_catch(void *exceptionObject)
77 __cxa_exception *except = static_cast<__cxa_exception*>( exceptionObject ) - 1;
79 except->handlerCount ++;
81 except->nextException = uncaught_exception_top;
82 uncaught_exception_top = except;
84 uncaught_exception_count --;
89 extern "C" void __cxa_end_catch()
91 struct __cxa_exception *except = uncaught_exception_top;
92 except->handlerCount --;
93 uncaught_exception_top = except->nextException;
95 if( except->handlerCount == 0 ) {
96 __cxa_free_exception(except+1);