19
19
#include < pthread.h>
20
20
21
21
#include " cxa_exception.hpp"
22
+ #include " cxa_handlers.hpp"
22
23
23
24
namespace __cxxabiv1 {
24
25
static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00 ; // CLNGC++\0
25
26
static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01 ; // CLNGC++\1
26
27
27
28
// Utility routines
28
- static __cxa_exception *exception_from_thrown_object (void *p) throw() {
29
+ static inline __cxa_exception *exception_from_thrown_object (void *p) throw() {
29
30
return ((__cxa_exception *) p) - 1 ;
30
31
}
31
32
32
- static void * thrown_object_from_exception (void *p) throw() {
33
+ static inline void * thrown_object_from_exception (void *p) throw() {
33
34
return (void *) (((__cxa_exception *) p) + 1 );
34
35
}
35
36
36
- static size_t object_size_from_exception_size (size_t size) throw() {
37
+ static inline size_t object_size_from_exception_size (size_t size) throw() {
37
38
return size + sizeof (__cxa_exception);
38
39
}
39
40
@@ -90,15 +91,15 @@ static void do_free(void *ptr) throw() {
90
91
return is_fallback_ptr (ptr) ? fallback_free (ptr) : std::free (ptr);
91
92
}
92
93
93
- /* Howard says:
94
+ /*
94
95
If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
95
96
stored in exc is called. Otherwise the exceptionDestructor stored in
96
97
exc is called, and then the memory for the exception is deallocated.
97
98
*/
98
99
static void exception_cleanup_func (_Unwind_Reason_Code reason, struct _Unwind_Exception * exc) {
99
100
__cxa_exception *exception = exception_from_exception_object (exc);
100
101
if (_URC_FOREIGN_EXCEPTION_CAUGHT != reason)
101
- exception->terminateHandler ( );
102
+ std::__terminate ( exception->terminateHandler );
102
103
103
104
void * thrown_object = thrown_object_from_exception (exception);
104
105
if (NULL != exception->exceptionDestructor )
@@ -115,7 +116,7 @@ static LIBCXXABI_NORETURN void failed_throw(__cxa_exception *exception) throw()
115
116
// a handler must call:
116
117
// * void *__cxa_begin_catch(void *exceptionObject );
117
118
(void ) __cxa_begin_catch (&exception->unwindHeader );
118
- std::terminate ( );
119
+ std::__terminate (exception-> terminateHandler );
119
120
}
120
121
121
122
extern " C" {
@@ -150,15 +151,13 @@ void * __cxa_allocate_dependent_exception () throw() {
150
151
if (NULL == ptr)
151
152
std::terminate ();
152
153
std::memset (ptr, 0 , actual_size);
153
- // bookkeeping here ?
154
154
return ptr;
155
155
}
156
156
157
157
158
158
// This function shall free a dependent_exception.
159
159
// It does not affect the reference count of the primary exception.
160
160
void __cxa_free_dependent_exception (void * dependent_exception) throw() {
161
- // I'm pretty sure there's no bookkeeping here
162
161
do_free (dependent_exception);
163
162
}
164
163
@@ -228,11 +227,7 @@ void * __cxa_begin_catch(void * exceptionObject) throw() {
228
227
__cxa_eh_globals *globals = __cxa_get_globals ();
229
228
__cxa_exception *exception = exception_from_exception_object (exceptionObject);
230
229
231
- // TODO add stuff for dependent exceptions.
232
-
233
- // TODO - should this be atomic?
234
230
// Increment the handler count, removing the flag about being rethrown
235
- // assert(exception->handlerCount != 0);
236
231
exception->handlerCount = exception->handlerCount < 0 ?
237
232
-exception->handlerCount + 1 : exception->handlerCount + 1 ;
238
233
0 commit comments