Changeset 2554f24


Ignore:
Timestamp:
Dec 11, 2023, 1:05:50 PM (7 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
dab9fb93
Parents:
81da3da4
Message:

Try terminate now does not call the catch function, now they have the same caller. This involved updating some platform dependent code which should be correct in all cases.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.c

    r81da3da4 r2554f24  
    5555}
    5656
     57struct __cfaehm_base_exception_t * __cfaehm_get_current_exception(void) {
     58        return this_exception_context()->current_exception;
     59}
    5760
    5861// RESUMPTION ================================================================
     
    309312                struct _Unwind_Context * unwind_context)
    310313{
    311 
    312314        //__cfadbg_print_safe(exception, "CFA: 0x%lx\n", _Unwind_GetCFA(context));
    313315        __cfadbg_print_safe(exception, "Personality function (%d, %x, %llu, %p, %p):",
     
    412414                                _Unwind_Word match_pos =
    413415#                               if defined( __x86_64 )
     416                                    _Unwind_GetCFA(unwind_context);
     417#                               elif defined( __i386 )
    414418                                    _Unwind_GetCFA(unwind_context) + 8;
    415 #                               elif defined( __i386 )
    416                                     _Unwind_GetCFA(unwind_context) + 24;
    417419#                               elif defined( __ARM_ARCH )
    418                                     _Unwind_GetCFA(unwind_context) + 40;
     420                                    _Unwind_GetCFA(unwind_context) + 16;
    419421#                               endif
    420422                                int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
     
    480482// and simply linked from libcfa but there is one problem left, see the exception table for details
    481483__attribute__((noinline))
    482 void __cfaehm_try_terminate(void (*try_block)(),
    483                 void (*catch_block)(int index, exception_t * except),
     484int __cfaehm_try_terminate(void (*try_block)(),
    484485                __attribute__((unused)) int (*match_block)(exception_t * except)) {
    485486        //! volatile int xy = 0;
    486         //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     487        //! printf("%p %p %p\n", &try_block, &match_block, &xy);
    487488
    488489        // Setup the personality routine and exception table.
     
    508509
    509510        // Normal return for when there is no throw.
    510         return;
     511        return 0;
    511512
    512513        // Exceptionnal path
     
    519520        asm volatile (".CATCH:");
    520521
    521         // Exception handler
    522         // Note: Saving the exception context on the stack breaks termination exceptions.
    523         catch_block( EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index,
    524                      this_exception_context()->current_exception );
     522        return EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index;
    525523}
    526524
  • libcfa/src/exception.h

    r81da3da4 r2554f24  
    4343extern struct __cfavir_type_info __cfatid_exception_t;
    4444
     45struct __cfaehm_base_exception_t * __cfaehm_get_current_exception(void);
    4546
    4647void __cfaehm_cancel_stack(exception_t * except) __attribute__((noreturn));
     
    5758
    5859// Function catches termination exceptions.
    59 void __cfaehm_try_terminate(
     60int __cfaehm_try_terminate(
    6061        void (*try_block)(),
    61         void (*catch_block)(int index, exception_t * except),
    6262        int (*match_block)(exception_t * except));
    6363
  • src/ControlStruct/ExceptTranslate.cpp

    r81da3da4 r2554f24  
    482482                ast::FunctionDecl * terminate_catch,
    483483                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_exception() );
     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_exception" )
     515                                                ),
     516                                        }
     517                                )
     518                        )
     519                ),
     520        } );
    495521}
    496522
Note: See TracChangeset for help on using the changeset viewer.