Changeset 2a3b019
- Timestamp:
- Mar 25, 2020, 4:36:25 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 9cb89b87
- Parents:
- 44a88528
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
r44a88528 r2a3b019 63 63 // There can be a single global until multithreading occurs, then each stack 64 64 // needs its own. It will have to be updated to handle that. 65 struct exception_context_t * this_exception_context() {65 inline static struct exception_context_t * this_exception_context() { 66 66 return &shared_stack; 67 67 } 68 //#define SAVE_EXCEPTION_CONTEXT(to_name)69 //struct exception_context_t * to_name = this_exception_context();70 //exception * this_exception() {71 // return this_exception_context()->current_exception;72 //}73 68 74 69 … … 76 71 77 72 void __cfaabi_ehm__throw_resume(exception_t * except) { 73 struct exception_context_t * context = this_exception_context(); 78 74 79 75 __cfaabi_dbg_print_safe("Throwing resumption exception\n"); 80 76 81 struct __cfaabi_ehm__try_resume_node * original_head = shared_stack.current_resume;77 struct __cfaabi_ehm__try_resume_node * original_head = context->current_resume; 82 78 struct __cfaabi_ehm__try_resume_node * current = 83 (original_head) ? original_head->next : shared_stack.top_resume;79 (original_head) ? original_head->next : context->top_resume; 84 80 85 81 for ( ; current ; current = current->next) { 86 shared_stack.current_resume = current;82 context->current_resume = current; 87 83 if (current->handler(except)) { 88 shared_stack.current_resume = original_head;84 context->current_resume = original_head; 89 85 return; 90 86 } … … 92 88 93 89 __cfaabi_dbg_print_safe("Unhandled exception\n"); 94 shared_stack.current_resume = original_head;90 context->current_resume = original_head; 95 91 96 92 // Fall back to termination: … … 105 101 void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node, 106 102 _Bool (*handler)(exception_t * except)) { 107 node->next = shared_stack.top_resume; 103 struct exception_context_t * context = this_exception_context(); 104 node->next = context->top_resume; 108 105 node->handler = handler; 109 shared_stack.top_resume = node;106 context->top_resume = node; 110 107 } 111 108 112 109 void __cfaabi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) { 113 shared_stack.top_resume = node->next; 110 struct exception_context_t * context = this_exception_context(); 111 context->top_resume = node->next; 114 112 } 115 113 … … 191 189 _Unwind_Exception_Class exceptionClass, 192 190 struct _Unwind_Exception * unwind_exception, 193 struct _Unwind_Context * context,194 void * s ome_param) {191 struct _Unwind_Context * unwind_context, 192 void * stop_param) { 195 193 if( actions & _UA_END_OF_STACK ) exit(1); 196 194 if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON; … … 251 249 int version, _Unwind_Action actions, unsigned long long exceptionClass, 252 250 struct _Unwind_Exception* unwind_exception, 253 struct _Unwind_Context* context)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, exceptionClass, unwind_exception, 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... … … 274 272 275 273 // Get a pointer to the language specific data from which we will read what we need 276 const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( context );274 const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( unwind_context ); 277 275 278 276 if( !lsd ) { //Nothing to do, keep unwinding … … 283 281 // Get the instuction pointer and a reading pointer into the exception table 284 282 lsda_header_info lsd_info; 285 const unsigned char * cur_ptr = parse_lsda_header(context, lsd, &lsd_info); 286 _Unwind_Ptr instruction_ptr = _Unwind_GetIP( context ); 283 const unsigned char * cur_ptr = parse_lsda_header(unwind_context, lsd, &lsd_info); 284 _Unwind_Ptr instruction_ptr = _Unwind_GetIP(unwind_context); 285 286 struct exception_context_t * context = this_exception_context(); 287 287 288 288 // Linearly search the table for stuff to do … … 321 321 322 322 // Something to do? 323 if( callsite_landing_pad ) { 323 if ( 0 == callsite_landing_pad ) { 324 // Nothing to do, move along 325 __cfaabi_dbg_print_safe(" no landing pad"); 326 } else { 324 327 // Which phase are we in 325 328 if (actions & _UA_SEARCH_PHASE) { … … 348 351 349 352 # if defined( __x86_64 ) 350 _Unwind_Word match_pos = _Unwind_GetCFA( context) + 8;353 _Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 8; 351 354 # elif defined( __i386 ) 352 _Unwind_Word match_pos = _Unwind_GetCFA( context) + 24;355 _Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 24; 353 356 # endif 354 357 int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos; 355 358 356 int index = matcher( shared_stack.current_exception);359 int index = matcher(context->current_exception); 357 360 _Unwind_Reason_Code ret = (0 == index) 358 361 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND; 359 shared_stack.current_handler_index = index;362 context->current_handler_index = index; 360 363 361 364 // Based on the return value, check if we matched the exception … … 382 385 // We need to run some clean-up or a handler 383 386 // These statment do the right thing but I don't know any specifics at all 384 _Unwind_SetGR( context, __builtin_eh_return_data_regno(0), (_Unwind_Ptr) unwind_exception ); 385 _Unwind_SetGR( context, __builtin_eh_return_data_regno(1), 0 ); 387 _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0), 388 (_Unwind_Ptr)unwind_exception ); 389 _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 ); 386 390 387 391 // I assume this sets the instruction pointer to the adress of the landing pad 388 392 // It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT 389 _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) );393 _Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) ); 390 394 391 395 __cfaabi_dbg_print_safe(" action\n"); … … 395 399 } 396 400 } 397 398 // Nothing to do, move along399 __cfaabi_dbg_print_safe(" no landing pad");400 401 } 401 402 // No handling found … … 457 458 458 459 // Exception handler 459 catch_block( shared_stack.current_handler_index, 460 shared_stack.current_exception ); 460 // Note: Saving the exception context on the stack breaks termination exceptions. 461 catch_block( this_exception_context()->current_handler_index, 462 this_exception_context()->current_exception ); 461 463 } 462 464
Note: See TracChangeset
for help on using the changeset viewer.