Changeset b7898ac
- Timestamp:
- Dec 18, 2023, 12:24:06 PM (15 months ago)
- Branches:
- master
- Children:
- 9fba8e6
- Parents:
- 5546eee4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/exception.c ¶
r5546eee4 rb7898ac 55 55 } 56 56 57 struct __cfaehm_base_exception_t * __cfaehm_get_current_termination(void) { 58 return this_exception_context()->current_exception; 59 } 60 57 61 58 62 // RESUMPTION ================================================================ … … 309 313 struct _Unwind_Context * unwind_context) 310 314 { 311 //! __cfadbg_print_safe(exception, "CFA: 0x%lx\n",_Unwind_GetCFA(unwind_context));315 __cfadbg_print_safe(exception, "CFA: 0x%p\n", (void*)_Unwind_GetCFA(unwind_context)); 312 316 __cfadbg_print_safe(exception, "Personality function (%d, %x, %llu, %p, %p):", 313 317 version, actions, exception_class, unwind_exception, unwind_context); … … 411 415 _Unwind_Word match_pos = 412 416 # if defined( __x86_64 ) 413 _Unwind_GetCFA(unwind_context) + 8;417 _Unwind_GetCFA(unwind_context); 414 418 # elif defined( __i386 ) 415 _Unwind_GetCFA(unwind_context) + 24;419 _Unwind_GetCFA(unwind_context) + 20; 416 420 # elif defined( __ARM_ARCH ) 417 _Unwind_GetCFA(unwind_context) + 40;421 _Unwind_GetCFA(unwind_context) + 16; 418 422 # endif 423 //! printf("match_pos: %p\n", (void*)match_pos); 424 //! fflush(stdout); 419 425 int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos; 420 426 … … 479 485 // and simply linked from libcfa but there is one problem left, see the exception table for details 480 486 __attribute__((noinline)) 481 void __cfaehm_try_terminate(void (*try_block)(), 482 void (*catch_block)(int index, exception_t * except), 487 int __cfaehm_try_terminate(void (*try_block)(), 483 488 __attribute__((unused)) int (*match_block)(exception_t * except)) { 484 489 //! volatile int xy = 0; 485 //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); 490 //! printf("%p %p %p\n", &try_block, &match_block, &xy); 491 //! fflush(stdout); 486 492 487 493 // Setup the personality routine and exception table. … … 507 513 508 514 // Normal return for when there is no throw. 509 return ;515 return 0; 510 516 511 517 // Exceptionnal path … … 518 524 asm volatile (".CATCH:"); 519 525 520 // Exception handler 521 // Note: Saving the exception context on the stack breaks termination exceptions. 522 catch_block( EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index, 523 this_exception_context()->current_exception ); 526 return EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index; 524 527 } 525 528 -
TabularUnified libcfa/src/exception.h ¶
r5546eee4 rb7898ac 44 44 45 45 46 struct __cfaehm_base_exception_t * __cfaehm_get_current_termination(void); 47 48 46 49 void __cfaehm_cancel_stack(exception_t * except) __attribute__((noreturn)); 47 50 … … 57 60 58 61 // Function catches termination exceptions. 59 void__cfaehm_try_terminate(62 int __cfaehm_try_terminate( 60 63 void (*try_block)(), 61 void (*catch_block)(int index, exception_t * except),62 64 int (*match_block)(exception_t * except)); 63 65 -
TabularUnified src/ControlStruct/ExceptTranslate.cpp ¶
r5546eee4 rb7898ac 482 482 ast::FunctionDecl * terminate_catch, 483 483 ast::FunctionDecl * terminate_match ) { 484 // { __cfaehm_try_terminate(`try`, `catch`, `match`); } 485 486 ast::UntypedExpr * caller = new ast::UntypedExpr(loc, new ast::NameExpr(loc, 487 "__cfaehm_try_terminate" ) ); 488 caller->args.push_back( new ast::VariableExpr(loc, try_wrapper ) ); 489 caller->args.push_back( new ast::VariableExpr(loc, terminate_catch ) ); 490 caller->args.push_back( new ast::VariableExpr(loc, terminate_match ) ); 491 492 ast::CompoundStmt * callStmt = new ast::CompoundStmt(loc); 493 callStmt->push_back( new ast::ExprStmt( loc, caller ) ); 494 return callStmt; 484 // { 485 // int __handler_index = __cfaehm_try_terminate(`try`, `match`); 486 // if ( __handler_index ) { 487 // `catch`( __handler_index, __cfaehm_get_current_termination() ); 488 // } 489 // } 490 491 ast::ObjectDecl * index = new ast::ObjectDecl( loc, "__handler_index", 492 new ast::BasicType( ast::BasicType::SignedInt ), 493 new ast::SingleInit( loc, 494 new ast::UntypedExpr( loc, 495 new ast::NameExpr( loc, "__cfaehm_try_terminate" ), 496 { 497 new ast::VariableExpr( loc, try_wrapper ), 498 new ast::VariableExpr( loc, terminate_match ), 499 } 500 ) 501 ) 502 ); 503 504 return new ast::CompoundStmt( loc, { 505 new ast::DeclStmt( loc, index ), 506 new ast::IfStmt( loc, 507 new ast::VariableExpr( loc, index ), 508 new ast::ExprStmt( loc, 509 new ast::UntypedExpr( loc, 510 new ast::VariableExpr( loc, terminate_catch ), 511 { 512 new ast::VariableExpr( loc, index ), 513 new ast::UntypedExpr( loc, 514 new ast::NameExpr( loc, "__cfaehm_get_current_termination" ) 515 ), 516 } 517 ) 518 ) 519 ), 520 } ); 495 521 } 496 522
Note: See TracChangeset
for help on using the changeset viewer.