Changeset a5de33e for src/libcfa/exception.c
- Timestamp:
- Jul 5, 2017, 5:00:46 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 55a68c3, 5805d15
- Parents:
- f7cb0bc (diff), 1ce2189 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/exception.c
rf7cb0bc ra5de33e 37 37 // This macro should be the only thing that needs to change across machines. 38 38 // Used in the personality function, way down in termination. 39 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)( )39 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception *) 40 40 #define MATCHER_FROM_CONTEXT(ptr_to_context) \ 41 (*(_Unwind_Reason_Code(**)( ))(_Unwind_GetCFA(ptr_to_context) + 8))41 (*(_Unwind_Reason_Code(**)(exception*))(_Unwind_GetCFA(ptr_to_context) + 8)) 42 42 43 43 44 44 // RESUMPTION ================================================================ 45 45 46 void __cfaehm__throw_resum e(exceptionexcept) {47 48 // DEBUG 49 printf("Throwing resumption exception %d\n", except);50 51 struct __ try_resume_node * original_head = shared_stack.current_resume;52 struct __ try_resume_node * current =46 void __cfaehm__throw_resumption(exception * except) { 47 48 // DEBUG 49 printf("Throwing resumption exception %d\n", *except); 50 51 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; 52 struct __cfaehm__try_resume_node * current = 53 53 (original_head) ? original_head->next : shared_stack.top_resume; 54 54 55 55 for ( ; current ; current = current->next) { 56 56 shared_stack.current_resume = current; 57 if (current-> try_to_handle(except)) {57 if (current->handler(except)) { 58 58 shared_stack.current_resume = original_head; 59 59 return; … … 61 61 } 62 62 63 printf("Unhandled exception %d\n", except);63 printf("Unhandled exception %d\n", *except); 64 64 shared_stack.current_resume = original_head; 65 65 66 66 // Fall back to termination: 67 __cfaehm__throw_terminat e(except);67 __cfaehm__throw_termination(except); 68 68 // TODO: Default handler for resumption. 69 69 } … … 73 73 * after the node is built but before it is made the top node. 74 74 */ 75 void __ try_resume_setup(struct__try_resume_node * node,76 bool (*handler)(exceptionexcept)) {75 void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node, 76 int (*handler)(exception * except)) { 77 77 node->next = shared_stack.top_resume; 78 node-> try_to_handle= handler;78 node->handler = handler; 79 79 shared_stack.top_resume = node; 80 80 } 81 81 82 void __ try_resume_cleanup(struct__try_resume_node * node) {82 void __cfaehm__try_resume_cleanup(struct __cfaehm__try_resume_node * node) { 83 83 shared_stack.top_resume = node->next; 84 84 } … … 111 111 } 112 112 113 void __cfaehm__throw_terminat e( intval ) {113 void __cfaehm__throw_termination( exception * val ) { 114 114 // Store the current exception 115 shared_stack.current_exception = val;116 117 // DEBUG 118 printf("Throwing termination exception %d\n", val);115 shared_stack.current_exception = *val; 116 117 // DEBUG 118 printf("Throwing termination exception %d\n", *val); 119 119 120 120 // Call stdlibc to raise the exception … … 147 147 148 148 // Nesting this the other way would probably be faster. 149 void __cfaehm__rethrow_terminat e(void) {149 void __cfaehm__rethrow_termination(void) { 150 150 // DEBUG 151 151 printf("Rethrowing termination exception\n"); 152 152 153 __cfaehm__throw_terminat e(shared_stack.current_exception);153 __cfaehm__throw_termination(&shared_stack.current_exception); 154 154 } 155 155 … … 261 261 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 262 262 263 _Unwind_Reason_Code (*matcher)( ) =263 _Unwind_Reason_Code (*matcher)(exception *) = 264 264 MATCHER_FROM_CONTEXT(context); 265 int index = matcher( shared_stack.current_exception);265 int index = matcher(&shared_stack.current_exception); 266 266 _Unwind_Reason_Code ret = (0 == index) 267 267 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND; … … 322 322 // for details 323 323 __attribute__((noinline)) 324 void __ try_terminate(void (*try_block)(),325 void (*catch_block)(int index, exception except),326 __attribute__((unused)) int (*match_block)(exception except)) {324 void __cfaehm__try_terminate(void (*try_block)(), 325 void (*catch_block)(int index, exception * except), 326 __attribute__((unused)) int (*match_block)(exception * except)) { 327 327 //! volatile int xy = 0; 328 328 //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); … … 364 364 // Exception handler 365 365 catch_block(shared_stack.current_handler_index, 366 shared_stack.current_exception);366 &shared_stack.current_exception); 367 367 } 368 368 … … 384 384 // Body uses language specific data and therefore could be modified arbitrarily 385 385 ".LLSDACSBCFA2:\n" // BODY start 386 " .uleb128 .TRYSTART-__ try_terminate\n" // Handled area start (relative to start of function)386 " .uleb128 .TRYSTART-__cfaehm__try_terminate\n" // Handled area start (relative to start of function) 387 387 " .uleb128 .TRYEND-.TRYSTART\n" // Handled area length 388 " .uleb128 .CATCH-__ try_terminate\n" // Hanlder landing pad adress (relative to start of function)388 " .uleb128 .CATCH-__cfaehm__try_terminate\n" // Hanlder landing pad adress (relative to start of function) 389 389 " .uleb128 1\n" // Action code, gcc seems to use always 0 390 390 ".LLSDACSECFA2:\n" // BODY end 391 391 " .text\n" // TABLE footer 392 " .size __ try_terminate, .-__try_terminate\n"392 " .size __cfaehm__try_terminate, .-__cfaehm__try_terminate\n" 393 393 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 394 394 // " .section .note.GNU-stack,\"x\",@progbits\n"
Note:
See TracChangeset
for help on using the changeset viewer.