Changes in libcfa/src/exception.c [3090127:9cb89b87]
- File:
-
- 1 edited
-
libcfa/src/exception.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
r3090127 r9cb89b87 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Mar 27 10:19:00 202013 // Update Count : 1 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 18:17:34 2018 13 // Update Count : 11 14 14 // 15 15 … … 41 41 42 42 // Base exception vtable is abstract, you should not have base exceptions. 43 struct __cfa ehm_base_exception_t_vtable44 ___cfa ehm_base_exception_t_vtable_instance = {43 struct __cfaabi_ehm__base_exception_t_vtable 44 ___cfaabi_ehm__base_exception_t_vtable_instance = { 45 45 .parent = NULL, 46 46 .size = 0, … … 53 53 // Temperary global exception context. Does not work with concurency. 54 54 struct exception_context_t { 55 struct __cfa ehm_try_resume_node * top_resume;56 struct __cfa ehm_try_resume_node * current_resume;55 struct __cfaabi_ehm__try_resume_node * top_resume; 56 struct __cfaabi_ehm__try_resume_node * current_resume; 57 57 58 58 exception_t * current_exception; … … 70 70 // RESUMPTION ================================================================ 71 71 72 void __cfa ehm_throw_resume(exception_t * except) {72 void __cfaabi_ehm__throw_resume(exception_t * except) { 73 73 struct exception_context_t * context = this_exception_context(); 74 74 75 75 __cfaabi_dbg_print_safe("Throwing resumption exception\n"); 76 76 77 struct __cfa ehm_try_resume_node * original_head = context->current_resume;78 struct __cfa ehm_try_resume_node * current =77 struct __cfaabi_ehm__try_resume_node * original_head = context->current_resume; 78 struct __cfaabi_ehm__try_resume_node * current = 79 79 (original_head) ? original_head->next : context->top_resume; 80 80 … … 91 91 92 92 // Fall back to termination: 93 __cfa ehm_throw_terminate(except);93 __cfaabi_ehm__throw_terminate(except); 94 94 // TODO: Default handler for resumption. 95 95 } … … 99 99 // be added after the node is built but before it is made the top node. 100 100 101 void __cfa ehm_try_resume_setup(struct __cfaehm_try_resume_node * node,101 void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node, 102 102 _Bool (*handler)(exception_t * except)) { 103 103 struct exception_context_t * context = this_exception_context(); … … 107 107 } 108 108 109 void __cfa ehm_try_resume_cleanup(struct __cfaehm_try_resume_node * node) {109 void __cfaabi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) { 110 110 struct exception_context_t * context = this_exception_context(); 111 111 context->top_resume = node->next; … … 118 118 // May have to move to cfa for constructors and destructors (references). 119 119 120 struct __cfa ehm_node {121 struct __cfa ehm_node * next;120 struct __cfaabi_ehm__node { 121 struct __cfaabi_ehm__node * next; 122 122 }; 123 123 124 124 #define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node))) 125 #define EXCEPT_TO_NODE(except) ((struct __cfa ehm_node *)(except) - 1)125 #define EXCEPT_TO_NODE(except) ((struct __cfaabi_ehm__node *)(except) - 1) 126 126 127 127 // Creates a copy of the indicated exception and sets current_exception to it. 128 static void __cfa ehm_allocate_exception( exception_t * except ) {128 static void __cfaabi_ehm__allocate_exception( exception_t * except ) { 129 129 struct exception_context_t * context = this_exception_context(); 130 130 131 131 // Allocate memory for the exception. 132 struct __cfa ehm_node * store = malloc(133 sizeof( struct __cfa ehm_node ) + except->virtual_table->size );132 struct __cfaabi_ehm__node * store = malloc( 133 sizeof( struct __cfaabi_ehm__node ) + except->virtual_table->size ); 134 134 135 135 if ( ! store ) { … … 147 147 148 148 // Delete the provided exception, unsetting current_exception if relivant. 149 static void __cfa ehm_delete_exception( exception_t * except ) {149 static void __cfaabi_ehm__delete_exception( exception_t * except ) { 150 150 struct exception_context_t * context = this_exception_context(); 151 151 … … 153 153 154 154 // Remove the exception from the list. 155 struct __cfa ehm_node * to_free = EXCEPT_TO_NODE(except);156 struct __cfa ehm_node * node;155 struct __cfaabi_ehm__node * to_free = EXCEPT_TO_NODE(except); 156 struct __cfaabi_ehm__node * node; 157 157 158 158 if ( context->current_exception == except ) { … … 174 174 175 175 // If this isn't a rethrow (*except==0), delete the provided exception. 176 void __cfa ehm_cleanup_terminate( void * except ) {177 if ( *(void**)except ) __cfa ehm_delete_exception( *(exception_t **)except );176 void __cfaabi_ehm__cleanup_terminate( void * except ) { 177 if ( *(void**)except ) __cfaabi_ehm__delete_exception( *(exception_t **)except ); 178 178 } 179 179 … … 187 187 int version, 188 188 _Unwind_Action actions, 189 _Unwind_Exception_Class exception _class,189 _Unwind_Exception_Class exceptionClass, 190 190 struct _Unwind_Exception * unwind_exception, 191 191 struct _Unwind_Context * unwind_context, … … 198 198 199 199 // The exception that is being thrown must already be stored. 200 static __attribute__((noreturn)) void __cfaehm_begin_unwind(void) {200 __attribute__((noreturn)) void __cfaabi_ehm__begin_unwind(void) { 201 201 if ( ! this_exception_context()->current_exception ) { 202 202 printf("UNWIND ERROR missing exception in begin unwind\n"); … … 230 230 } 231 231 232 void __cfa ehm_throw_terminate( exception_t * val ) {232 void __cfaabi_ehm__throw_terminate( exception_t * val ) { 233 233 __cfaabi_dbg_print_safe("Throwing termination exception\n"); 234 234 235 __cfa ehm_allocate_exception( val );236 __cfa ehm_begin_unwind();237 } 238 239 void __cfa ehm_rethrow_terminate(void) {235 __cfaabi_ehm__allocate_exception( val ); 236 __cfaabi_ehm__begin_unwind(); 237 } 238 239 void __cfaabi_ehm__rethrow_terminate(void) { 240 240 __cfaabi_dbg_print_safe("Rethrowing termination exception\n"); 241 241 242 __cfa ehm_begin_unwind();242 __cfaabi_ehm__begin_unwind(); 243 243 } 244 244 … … 246 246 // ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding. 247 247 // Once in the search phase and once in the cleanup phase. 248 _Unwind_Reason_Code __gcfa_personality_v0( 249 int version, 250 _Unwind_Action actions, 251 unsigned long long exception_class, 252 struct _Unwind_Exception * unwind_exception, 253 struct _Unwind_Context * unwind_context) 248 _Unwind_Reason_Code __gcfa_personality_v0 ( 249 int version, _Unwind_Action actions, unsigned long long exceptionClass, 250 struct _Unwind_Exception* unwind_exception, 251 struct _Unwind_Context* unwind_context) 254 252 { 255 253 256 254 //__cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 257 255 __cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):", 258 version, actions, exception _class, unwind_exception, unwind_context);256 version, actions, exceptionClass, unwind_exception, unwind_context); 259 257 260 258 // If we've reached the end of the stack then there is nothing much we can do... … … 344 342 // - The BSP (Probably the base stack pointer) 345 343 344 346 345 // The current apprach uses one exception table entry per try block 347 346 _uleb128_t imatcher; … … 415 414 // and simply linked from libcfa but there is one problem left, see the exception table for details 416 415 __attribute__((noinline)) 417 void __cfa ehm_try_terminate(void (*try_block)(),416 void __cfaabi_ehm__try_terminate(void (*try_block)(), 418 417 void (*catch_block)(int index, exception_t * except), 419 418 __attribute__((unused)) int (*match_block)(exception_t * except)) { … … 481 480 // handler landing pad offset and 1 (action code, gcc seems to use 0). 482 481 ".LLSDACSBCFA2:\n" 483 " .uleb128 .TRYSTART-__cfa ehm_try_terminate\n"482 " .uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n" 484 483 " .uleb128 .TRYEND-.TRYSTART\n" 485 " .uleb128 .CATCH-__cfa ehm_try_terminate\n"484 " .uleb128 .CATCH-__cfaabi_ehm__try_terminate\n" 486 485 " .uleb128 1\n" 487 486 ".LLSDACSECFA2:\n" 488 487 // TABLE FOOTER 489 488 " .text\n" 490 " .size __cfa ehm_try_terminate, .-__cfaehm_try_terminate\n"489 " .size __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n" 491 490 ); 492 491 … … 525 524 ".LLSDACSBCFA2:\n" 526 525 // Handled area start (relative to start of function) 527 " .uleb128 .TRYSTART-__cfa ehm_try_terminate\n"526 " .uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n" 528 527 // Handled area length 529 528 " .uleb128 .TRYEND-.TRYSTART\n" 530 529 // Handler landing pad address (relative to start of function) 531 " .uleb128 .CATCH-__cfa ehm_try_terminate\n"530 " .uleb128 .CATCH-__cfaabi_ehm__try_terminate\n" 532 531 // Action code, gcc seems to always use 0. 533 532 " .uleb128 1\n" … … 535 534 ".LLSDACSECFA2:\n" 536 535 " .text\n" 537 " .size __cfa ehm_try_terminate, .-__cfaehm_try_terminate\n"536 " .size __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n" 538 537 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 539 538 " .section .note.GNU-stack,\"x\",@progbits\n"
Note:
See TracChangeset
for help on using the changeset viewer.