Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.c

    r851fd92 r73530d9  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr 14 12:01:00 2020
    13 // Update Count     : 18
     12// Last Modified On : Fri Apr 03 11:57:00 2020
     13// Update Count     : 14
    1414//
    1515
     
    2828#include <unwind.h>
    2929#include <bits/debug.hfa>
    30 #include "stdhdr/assert.h"
    3130
    3231// FIX ME: temporary hack to keep ARM build working
     
    7675// RESUMPTION ================================================================
    7776
    78 static void reset_top_resume(struct __cfaehm_try_resume_node ** store) {
    79         this_exception_context()->top_resume = *store;
    80 }
    81 
    8277void __cfaehm_throw_resume(exception_t * except) {
    8378        struct exception_context_t * context = this_exception_context();
    8479
    85         __cfadbg_print_safe(exception, "Throwing resumption exception\n");
    86 
    87         __attribute__((cleanup(reset_top_resume)))
     80        __cfaabi_dbg_print_safe("Throwing resumption exception\n");
     81
    8882        struct __cfaehm_try_resume_node * original_head = context->top_resume;
    8983        struct __cfaehm_try_resume_node * current = context->top_resume;
     
    9286                context->top_resume = current->next;
    9387                if (current->handler(except)) {
     88                        context->top_resume = original_head;
    9489                        return;
    9590                }
    9691        }
    9792
    98         __cfadbg_print_safe(exception, "Unhandled exception\n");
     93        __cfaabi_dbg_print_safe("Unhandled exception\n");
     94        context->top_resume = original_head;
    9995
    10096        // Fall back to termination:
     
    180176        struct exception_context_t * context = this_exception_context();
    181177
    182         __cfadbg_print_safe(exception, "Deleting Exception\n");
     178        __cfaabi_dbg_print_safe("Deleting Exception\n");
    183179
    184180        // Remove the exception from the list.
     
    217213                struct _Unwind_Context * unwind_context,
    218214                void * stop_param) {
    219         // Verify actions follow the rules we expect.
    220         verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
    221         verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDER_FRAME)));
    222 
    223         if ( actions & _UA_END_OF_STACK ) {
    224                 exit(1);
    225         } else {
    226                 return _URC_NO_REASON;
    227         }
     215        if ( actions & _UA_END_OF_STACK  ) exit(1);
     216        if ( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
     217
     218        return _URC_FATAL_PHASE2_ERROR;
    228219}
    229220
     
    261252
    262253void __cfaehm_throw_terminate( exception_t * val ) {
    263         __cfadbg_print_safe(exception, "Throwing termination exception\n");
     254        __cfaabi_dbg_print_safe("Throwing termination exception\n");
    264255
    265256        __cfaehm_allocate_exception( val );
     
    268259
    269260void __cfaehm_rethrow_terminate(void) {
    270         __cfadbg_print_safe(exception, "Rethrowing termination exception\n");
     261        __cfaabi_dbg_print_safe("Rethrowing termination exception\n");
    271262
    272263        __cfaehm_begin_unwind();
     
    284275{
    285276
    286         //__cfadbg_print_safe(exception, "CFA: 0x%lx\n", _Unwind_GetCFA(context));
    287         __cfadbg_print_safe(exception, "Personality function (%d, %x, %llu, %p, %p):",
     277        //__cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context));
     278        __cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):",
    288279                        version, actions, exception_class, unwind_exception, unwind_context);
    289280
    290         // Verify that actions follow the rules we expect.
    291         // This function should never be called at the end of the stack.
    292         verify(!(actions & _UA_END_OF_STACK));
    293         // Either only the search phase flag is set or...
     281        // If we've reached the end of the stack then there is nothing much we can do...
     282        if (actions & _UA_END_OF_STACK) return _URC_END_OF_STACK;
     283
    294284        if (actions & _UA_SEARCH_PHASE) {
    295                 verify(actions == _UA_SEARCH_PHASE);
    296                 __cfadbg_print_safe(exception, " lookup phase");
    297         // ... we are in clean-up phase.
    298         } else {
    299                 verify(actions & _UA_CLEANUP_PHASE);
    300                 __cfadbg_print_safe(exception, " cleanup phase");
    301                 // We shouldn't be the handler frame during forced unwind.
    302                 if (actions & _UA_HANDLER_FRAME) {
    303                         verify(!(actions & _UA_FORCE_UNWIND));
    304                         __cfadbg_print_safe(exception, " (handler frame)");
    305                 } else if (actions & _UA_FORCE_UNWIND) {
    306                         __cfadbg_print_safe(exception, " (force unwind)");
    307                 }
     285                __cfaabi_dbg_print_safe(" lookup phase");
     286        }
     287        else if (actions & _UA_CLEANUP_PHASE) {
     288                __cfaabi_dbg_print_safe(" cleanup phase");
     289        }
     290        // Just in case, probably can't actually happen
     291        else {
     292                printf(" error\n");
     293                return _URC_FATAL_PHASE1_ERROR;
    308294        }
    309295
     
    345331                        void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
    346332                        void * ip = (void*)instruction_ptr;
    347                         __cfadbg_print_safe(exception, "\nfound %p - %p (%p, %p, %p), looking for %p\n",
     333                        __cfaabi_dbg_print_safe("\nfound %p - %p (%p, %p, %p), looking for %p\n",
    348334                                        bp, ep, ls, cs, cl, ip);
    349335#endif // __CFA_DEBUG_PRINT__
     
    360346                if ( 0 == callsite_landing_pad ) {
    361347                        // Nothing to do, move along
    362                         __cfadbg_print_safe(exception, " no landing pad");
     348                        __cfaabi_dbg_print_safe(" no landing pad");
    363349                } else if (actions & _UA_SEARCH_PHASE) {
    364350                        // In search phase, these means we found a potential handler we must check.
     
    398384                                // Based on the return value, check if we matched the exception
    399385                                if (ret == _URC_HANDLER_FOUND) {
    400                                         __cfadbg_print_safe(exception, " handler found\n");
     386                                        __cfaabi_dbg_print_safe(" handler found\n");
    401387                                } else {
    402                                         __cfadbg_print_safe(exception, " no handler\n");
     388                                        __cfaabi_dbg_print_safe(" no handler\n");
    403389                                }
    404390                                return ret;
     
    406392
    407393                        // This is only a cleanup handler, ignore it
    408                         __cfadbg_print_safe(exception, " no action");
    409                 } else {
     394                        __cfaabi_dbg_print_safe(" no action");
     395                } else if (actions & _UA_CLEANUP_PHASE) {
    410396                        // In clean-up phase, no destructors here but this could be the handler.
    411397
     
    428414                        _Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
    429415
    430                         __cfadbg_print_safe(exception, " action\n");
     416                        __cfaabi_dbg_print_safe(" action\n");
    431417
    432418                        // Return have some action to run
     
    435421        }
    436422        // No handling found
    437         __cfadbg_print_safe(exception, " table end reached");
     423        __cfaabi_dbg_print_safe(" table end reached\n");
    438424
    439425        UNWIND:
    440         __cfadbg_print_safe(exception, " unwind\n");
     426        __cfaabi_dbg_print_safe(" unwind\n");
    441427
    442428        // Keep unwinding the stack
     
    445431
    446432#pragma GCC push_options
    447 #pragma GCC optimize(0)
     433#pragma GCC optimize("O0")
    448434
    449435// Try statements are hoisted out see comments for details. While this could probably be unique
     
    542528        "       .quad __gcfa_personality_v0\n"
    543529#else // then __i386
    544         "       .long __gcfa_personality_v0\n"
     530        "   .long __gcfa_personality_v0\n"
    545531#endif
    546532);
Note: See TracChangeset for help on using the changeset viewer.