Ignore:
Timestamp:
Jul 5, 2017, 5:00:46 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/exception.c

    rf7cb0bc ra5de33e  
    3737// This macro should be the only thing that needs to change across machines.
    3838// Used in the personality function, way down in termination.
    39 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)()
     39// struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception *)
    4040#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))
    4242
    4343
    4444// RESUMPTION ================================================================
    4545
    46 void __cfaehm__throw_resume(exception except) {
    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 =
     46void __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 =
    5353                (original_head) ? original_head->next : shared_stack.top_resume;
    5454
    5555        for ( ; current ; current = current->next) {
    5656                shared_stack.current_resume = current;
    57                 if (current->try_to_handle(except)) {
     57                if (current->handler(except)) {
    5858                        shared_stack.current_resume = original_head;
    5959                        return;
     
    6161        }
    6262
    63         printf("Unhandled exception %d\n", except);
     63        printf("Unhandled exception %d\n", *except);
    6464        shared_stack.current_resume = original_head;
    6565
    6666        // Fall back to termination:
    67         __cfaehm__throw_terminate(except);
     67        __cfaehm__throw_termination(except);
    6868        // TODO: Default handler for resumption.
    6969}
     
    7373 * after the node is built but before it is made the top node.
    7474 */
    75 void __try_resume_setup(struct __try_resume_node * node,
    76                         bool (*handler)(exception except)) {
     75void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node,
     76                        int (*handler)(exception * except)) {
    7777        node->next = shared_stack.top_resume;
    78         node->try_to_handle = handler;
     78        node->handler = handler;
    7979        shared_stack.top_resume = node;
    8080}
    8181
    82 void __try_resume_cleanup(struct __try_resume_node * node) {
     82void __cfaehm__try_resume_cleanup(struct __cfaehm__try_resume_node * node) {
    8383        shared_stack.top_resume = node->next;
    8484}
     
    111111}
    112112
    113 void __cfaehm__throw_terminate( int val ) {
     113void __cfaehm__throw_termination( exception * val ) {
    114114        // 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);
    119119
    120120        // Call stdlibc to raise the exception
     
    147147
    148148// Nesting this the other way would probably be faster.
    149 void __cfaehm__rethrow_terminate(void) {
     149void __cfaehm__rethrow_termination(void) {
    150150        // DEBUG
    151151        printf("Rethrowing termination exception\n");
    152152
    153         __cfaehm__throw_terminate(shared_stack.current_exception);
     153        __cfaehm__throw_termination(&shared_stack.current_exception);
    154154}
    155155
     
    261261                                        // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;                                   
    262262
    263                                         _Unwind_Reason_Code (*matcher)() =
     263                                        _Unwind_Reason_Code (*matcher)(exception *) =
    264264                                                MATCHER_FROM_CONTEXT(context);
    265                                         int index = matcher(shared_stack.current_exception);
     265                                        int index = matcher(&shared_stack.current_exception);
    266266                                        _Unwind_Reason_Code ret = (0 == index)
    267267                                                ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
     
    322322// for details
    323323__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)) {
     324void __cfaehm__try_terminate(void (*try_block)(),
     325                void (*catch_block)(int index, exception * except),
     326                __attribute__((unused)) int (*match_block)(exception * except)) {
    327327        //! volatile int xy = 0;
    328328        //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     
    364364        // Exception handler
    365365        catch_block(shared_stack.current_handler_index,
    366                     shared_stack.current_exception);
     366                    &shared_stack.current_exception);
    367367}
    368368
     
    384384        // Body uses language specific data and therefore could be modified arbitrarily
    385385        ".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)
    387387        "       .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)
    389389        "       .uleb128 1\n"                                           // Action code, gcc seems to use always 0
    390390        ".LLSDACSECFA2:\n"                                              // BODY end
    391391        "       .text\n"                                                        // TABLE footer
    392         "       .size   __try_terminate, .-__try_terminate\n"
     392        "       .size   __cfaehm__try_terminate, .-__cfaehm__try_terminate\n"
    393393        "       .ident  \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
    394394//      "       .section        .note.GNU-stack,\"x\",@progbits\n"
Note: See TracChangeset for help on using the changeset viewer.