INLINE static bool process_cleanup(_Unwind_Exception *uexcep, _Unwind_Phase phase, _Unwind_Context *context, _UINT32 **descr_ptr, _UINT32 length, _UINT32 offset) { _UINT32 *p_lp = *descr_ptr; _UINT32 range_start = uexcep->pr_data.func_start + offset; _UINT32 curr_pc = __TI_targ_regbuf_get_pc(context); #ifdef DEBUG_PR printf("PR: (@ %p) Clean, Phase %d, " "Len %"PRId32", Off %"PRIx32", lp %"PRIx32"\n", *descr_ptr, phase, length, offset, **descr_ptr); #endif /* DEBUG_PR */ /*-----------------------------------------------------------------------*/ /* Increment desc ptr beyond landing pad */ /*-----------------------------------------------------------------------*/ (*descr_ptr)++; /*-----------------------------------------------------------------------*/ /* Phase 2, and PC is within the range, set up reg buff to call handler */ /*-----------------------------------------------------------------------*/ if (phase != _UP_Phase1 && curr_pc >= range_start && curr_pc < range_start+length) { /*-------------------------------------------------------------------*/ /* Save address of next EHT descriptor, to resume processing later */ /*-------------------------------------------------------------------*/ uexcep->cleanup_data.cleanup_ehtp = (_UINT32)(*descr_ptr); /*-------------------------------------------------------------------*/ /* __cxa_begin_cleanup must be called before starting any cleanups */ /*-------------------------------------------------------------------*/ __cxa_begin_cleanup(uexcep); /*-------------------------------------------------------------------*/ /* Set up registers to call cleanup landing pad */ /*-------------------------------------------------------------------*/ __TI_targ_regbuf_set_pc(context, __TI_prel2abs(p_lp)); return true; } return false; }
void __TI_Unwind_Resume(_Unwind_Exception *uexcep, _Unwind_Context *context) { #ifdef DEBUG_UNWINDER printf("UW: __TI_Unwind_Resume\n"); #endif /*-----------------------------------------------------------------------*/ /* Resuming after running a cleanup, restore PC from saved area in UE */ /*-----------------------------------------------------------------------*/ __TI_targ_regbuf_set_pc(context, uexcep->unwinder_data.saved_callsite_addr); #ifdef DEBUG_UNWINDER printf("UW: restored PC: %"PRIx32"\n", uexcep->unwinder_data.saved_callsite_addr); #endif /*-----------------------------------------------------------------------*/ /* Call PR with phase set to Phase2 Resume (PR set up by Phase 2 Start) */ /*-----------------------------------------------------------------------*/ #pragma diag_suppress 1107 _Unwind_Reason_Code reason_code = ((_PR_TYPE)(uexcep->unwinder_data.pr_addr))(_UP_Phase2_Resume, uexcep, context); #pragma diag_default 1107 #ifdef DEBUG_UNWINDER printf("UW: PR returned to __TI_Unwind_Resume\n"); #endif /*-----------------------------------------------------------------------*/ /* If PR returns CONTINUE, call __TI_unwind_frame to unwind next frame */ /* If PR returns INSTALL, copy register buffer regs to machine regs */ /*-----------------------------------------------------------------------*/ if (reason_code == _URC_CONTINUE_UNWIND) __TI_unwind_frame(uexcep, context); /* Process next frame */ else if (reason_code == _URC_INSTALL_CONTEXT) __TI_targ_regbuf_install(context); else abort(); }
INLINE static bool process_fespec (_Unwind_Exception *uexcep, _Unwind_Phase phase, _Unwind_Context *context, _UINT32 **descr_ptr, _UINT32 length, _UINT32 offset, _Unwind_Reason_Code *reason, bool *ph2_call_unexpected) { bool reason_valid = false; _UINT32 rtti_count = **descr_ptr; _UINT32 range_start = uexcep->pr_data.func_start + offset; bool call_unexpected; _UINT32 curr_pc = __TI_targ_regbuf_get_pc(context); _UINT32 sp = __TI_targ_regbuf_get_sp(context); _UINT32 sb = __TI_targ_regbuf_get_sb(context); /*-----------------------------------------------------------------------*/ /* The MSB in rtti_count is used to indicate a call to call_unexpected */ /* MSB ==0, use call_unexpected, MSB ==1, use handler supplied in descr */ /*-----------------------------------------------------------------------*/ call_unexpected = (rtti_count & 0x80000000) ? false : true; rtti_count &= 0x7fffffff; #ifdef DEBUG_PR printf("PR: (@ %p) Fspec, Len %"PRId32", " "Off %"PRIx32", Count %"PRIx32"\n", *descr_ptr, length, offset, rtti_count); #endif /* DEBUG_PR */ /*-----------------------------------------------------------------------*/ /* Phase 1, check if fespec forms a propagation barrier */ /*-----------------------------------------------------------------------*/ if (phase == _UP_Phase1) { if (curr_pc >= range_start && curr_pc < range_start+length) { /*---------------------------------------------------------------*/ /* Check list of rtti types for match */ /*---------------------------------------------------------------*/ void *matched; _UINT32 idx; for (idx=0; idx < rtti_count; idx++) { _UINT32 rtti_offset = (_UINT32)*((*descr_ptr) + idx + 1); _UINT32 rtti_address = __TI_targ_rtti_address(rtti_offset, context); #pragma diag_suppress 1107 if (__cxa_type_match(uexcep, (std::type_info *)(uintptr_t)rtti_address, &matched)) break; #pragma diag_default 1107 } /*---------------------------------------------------------------*/ /* If no match, exception should not propagate beyond this func */ /* save propagation barrier */ /*---------------------------------------------------------------*/ if (idx == rtti_count) { #ifdef DEBUG_PR printf("PR: Found fespec propagation barrier\n"); #endif /* DEBUG_PR */ /*-----------------------------------------------------------*/ /* Save propagation barrier: SP and ptr to descr (Sec 7.3/5) */ /*-----------------------------------------------------------*/ uexcep->barrier_data.sp = sp; uexcep->barrier_data.data[1] = (_UINT32)*descr_ptr; /*-----------------------------------------------------------*/ /* cxa_begin_catch requires matched type in 0, Sec 8.2 - it */ /* is called from cxa_call_unexpected. */ /*-----------------------------------------------------------*/ uexcep->barrier_data.data[0] = (_UINT32)matched; *reason = _URC_HANDLER_FOUND; reason_valid = true; } } } /*-----------------------------------------------------------------------*/ /* Phase 2, check for a previously saved propagation barrier */ /*-----------------------------------------------------------------------*/ else { if (sp == uexcep->barrier_data.sp && (_UINT32)*descr_ptr == uexcep->barrier_data.data[1]) { /*---------------------------------------------------------------*/ /* Set up barrier cache with required data - Sec 8.2 */ /*---------------------------------------------------------------*/ uexcep->barrier_data.data[1] = rtti_count; uexcep->barrier_data.data[2] = sb; uexcep->barrier_data.data[3] = 4; uexcep->barrier_data.data[4] = (_UINT32)((*descr_ptr)+1); /*---------------------------------------------------------------*/ /* If descriptor specifies a landing pad, call landing pad else */ /* call cxa_call_unexpected _after_ unwinding */ /* Sec 8.5.3 - any permitted throw out of unexpected() must */ /* behave as if unwinding resumes at the call site to the func */ /* whose exception specification was violated. */ /*---------------------------------------------------------------*/ if (!call_unexpected) { _UINT32 *p_lp_offset = ((*descr_ptr) + 1 + rtti_count); __TI_targ_regbuf_set_pc(context, __TI_prel2abs(p_lp_offset)); __TI_targ_setup_call_parm0(context, (_UINT32)uexcep); *reason = _URC_INSTALL_CONTEXT; reason_valid = true; } else *ph2_call_unexpected = true; } } /*-----------------------------------------------------------------------*/ /* Skip over rtti count field, list of types & lp offset if any */ /*-----------------------------------------------------------------------*/ (*descr_ptr) += (rtti_count + 1 + (call_unexpected ? 0 : 1)); return reason_valid; }
INLINE static bool process_catch(_Unwind_Exception *uexcep, _Unwind_Phase phase, _Unwind_Context *context, _UINT32 **descr_ptr, _UINT32 length, _UINT32 offset, _Unwind_Reason_Code *reason) { bool reason_valid = false; _UINT32 *p_lp_offset = *descr_ptr; _UINT32 rtti_offset = *(*descr_ptr+1); _UINT32 range_start = uexcep->pr_data.func_start + offset; _UINT32 curr_pc = __TI_targ_regbuf_get_pc(context); _UINT32 sp = __TI_targ_regbuf_get_sp(context); _UINT32 rtti_address = __TI_targ_rtti_address(rtti_offset, context); #ifdef DEBUG_PR printf("PR: (@ %p) Catch, Phase %d, " "Len %"PRId32", Off %#"PRIx32", (%"PRIx32" - %"PRIx32") " "lp %"PRIx32", type %"PRIx32" (offset = %"PRIx32")\n", *descr_ptr, phase, length, offset, range_start, range_start+length, *p_lp_offset, rtti_address, rtti_offset); #endif /* DEBUG_PR */ /*-----------------------------------------------------------------------*/ /* Phase 1, Check if catch forms propagation barrier */ /*-----------------------------------------------------------------------*/ if (phase == _UP_Phase1) { /*-------------------------------------------------------------------*/ /* Check if PC is in range */ /*-------------------------------------------------------------------*/ if (curr_pc >= range_start && curr_pc < range_start+length) { /*---------------------------------------------------------------*/ /* Check for a type match, also check for catch all/terminate */ /*---------------------------------------------------------------*/ void *matched; if (rtti_offset == CATCH_ANY_TERMINATE) { *reason = _URC_FAILURE; reason_valid = true; } #pragma diag_suppress 1107 else if (rtti_offset == CATCH_ANY || __cxa_type_match(uexcep, (std::type_info *)(uintptr_t)rtti_address, &matched)) #pragma diag_default 1107 { #ifdef DEBUG_PR printf("PR: Found catch propagation barrier\n"); #endif /* DEBUG_PR */ /*-----------------------------------------------------------*/ /* Save propagation barrier: SP and ptr to descr (Sec 7.3/5) */ /*-----------------------------------------------------------*/ uexcep->barrier_data.sp = sp; uexcep->barrier_data.data[1] = (_UINT32)*descr_ptr; /*-----------------------------------------------------------*/ /* cxa_begin_catch requires matched type in 0, Sec 8.2 */ /*-----------------------------------------------------------*/ uexcep->barrier_data.data[0] = (_UINT32)matched; *reason = _URC_HANDLER_FOUND; reason_valid = true; } } } /*-----------------------------------------------------------------------*/ /* Phase 2 Start or Resume, check for barrier, set up catch handler */ /*-----------------------------------------------------------------------*/ else { /*-------------------------------------------------------------------*/ /* Check for a previously saved propagation barrier */ /*-------------------------------------------------------------------*/ if (sp == uexcep->barrier_data.sp && (_UINT32)*descr_ptr == uexcep->barrier_data.data[1]) { /*---------------------------------------------------------------*/ /* Set up PC to call catch handler, set up UE ptr in R0 */ /*---------------------------------------------------------------*/ __TI_targ_regbuf_set_pc(context, __TI_prel2abs(p_lp_offset)); __TI_targ_setup_call_parm0(context, (_UINT32)uexcep); *reason = _URC_INSTALL_CONTEXT; reason_valid = true; } } /*-----------------------------------------------------------------------*/ /* Increment desc ptr beyond landing pad & rtti offset */ /*-----------------------------------------------------------------------*/ (*descr_ptr) += 2; return reason_valid; }