コード例 #1
0
int __TI_ut_entry_cmp(const void *key, const void *entry)
{ 
    #pragma diag_suppress 1107
    const _Unwind_Table_Entry *ut_limit = 
        (_Unwind_Table_Entry *)(uintptr_t)__TI_UT_BaseLimit.UT_limit;
    #pragma diag_default 1107

    const _Unwind_Table_Entry *ut_entry      = (_Unwind_Table_Entry *)entry; 
    const _Unwind_Table_Entry *ut_next_entry = ut_entry + 1; 

    _UINT32 pc_abs = *(_UINT32 *)key; 

    /*-----------------------------------------------------------------------*/
    /* Only function start offsets are stored in the entries. For the last   */
    /* entry in the table, there is no "end" address for the function. Any   */
    /* PC value greater that the func start address will match the entry for */
    /* that function                                                         */
    /*-----------------------------------------------------------------------*/
    _UINT32 next_func_abs = 
	(ut_next_entry != ut_limit) ? 
        __TI_prel2abs(&ut_next_entry->fn_offset) : 0xffffffff;

    _UINT32 this_addr = __TI_prel2abs(&ut_entry->fn_offset);

    #ifdef DEBUG_BSEARCH
    printf("UW/BS: PC=%"PRIx32" entry=%p, "
           "this_addr=%"PRIx32" next_addr=%"PRIx32"\n", 
           pc_abs, entry, this_addr, next_func_abs);
    #endif /* DEBUG_BSEARCH */

    if      (pc_abs < this_addr) return -1; 
    else if (pc_abs >= next_func_abs)                     return  1; 
    else                                                  return  0;
}
コード例 #2
0
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;
}
コード例 #3
0
static _Unwind_Reason_Code find_et_setup_pr(_Unwind_Exception *uexcep, 
					    _UINT32 pc)
{

    #pragma diag_suppress 1107
    const _Unwind_Table_Entry *ut_base  = 
        (_Unwind_Table_Entry *)(uintptr_t)__TI_UT_BaseLimit.UT_base;
    const _Unwind_Table_Entry *ut_limit = 
        (_Unwind_Table_Entry *)(uintptr_t)__TI_UT_BaseLimit.UT_limit;
    #pragma diag_default 1107

    size_t num_entries = ut_limit - ut_base;

    uexcep->unwinder_data.pr_addr = NULL;
    
    /*-----------------------------------------------------------------------*/
    /* Search for matching Unwind Table entry using pc                       */
    /*-----------------------------------------------------------------------*/
    _Unwind_Table_Entry *match_entry =
	(_Unwind_Table_Entry *)bsearch((void *)&pc, (void *)ut_base, 
				       num_entries, sizeof(_Unwind_Table_Entry),
				       __TI_ut_entry_cmp);

    if (match_entry == NULL)
    {
        #ifdef DEBUG_UNWINDER
        printf("UW: bsearch did not find PC %"PRIx32" in EXIDX\n", pc);
        #endif /* DEBUG_UNWINDER */

        return _URC_FAILURE; 
    }

    #ifdef DEBUG_UNWINDER
    printf("UW: PC=%"PRIx32" -> UTEntry @ %p, "
           "Func %"PRIxMAX", Off %"PRIx32"\n",
           pc, match_entry, (uintmax_t)__TI_prel2abs(&match_entry->fn_offset), 
           match_entry->et_offset);
    #endif /* DEBUG_UNWINDER */

    /*-----------------------------------------------------------------------*/
    /* If entry indicates cant unwind, return failure                        */
    /*-----------------------------------------------------------------------*/
    if (match_entry->et_offset == UT_CANT_UNWIND) return _URC_FAILURE;

    /*-----------------------------------------------------------------------*/
    /* Store function start address (absolute)                               */
    /*-----------------------------------------------------------------------*/
    uexcep->pr_data.func_start = __TI_prel2abs(&match_entry->fn_offset);

    /*-----------------------------------------------------------------------*/
    /* Set up EHT related info in the UE. If et_offset MSB==1, EHT inlined   */
    /*-----------------------------------------------------------------------*/
    if ((match_entry->et_offset & 0x80000000) != 0)
    {
        #ifdef DEBUG_UNWINDER
        printf("UW: Inlined EHT\n");
        #endif /* DEBUG_UNWINDER */

	uexcep->pr_data.eht_start = (_UINT32 *)&match_entry->et_offset;
	uexcep->pr_data.additional = 1;
    }
    else
    {
        #pragma diag_suppress 1107
	uexcep->pr_data.eht_start = 
            (_UINT32 *)(uintptr_t)__TI_prel2abs(&match_entry->et_offset);
	uexcep->pr_data.additional = 0;
        #pragma diag_default 1107

        #ifdef DEBUG_UNWINDER
        printf("UW: Non-inlined EHT at %p\n", uexcep->pr_data.eht_start);
        #endif /* DEBUG_UNWINDER */
    }

    /*-----------------------------------------------------------------------*/
    /* Compute PR to call from the EHT entry, update UE with this PR         */
    /*-----------------------------------------------------------------------*/
    if (!__TI_targ_set_pr(uexcep)) return _URC_FAILURE;

    #ifdef DEBUG_UNWINDER
    printf("UW: FAddr %"PRIx32", EAddr %p, I? %d, PAddr %"PRIx32"\n",
           uexcep->pr_data.func_start, uexcep->pr_data.eht_start,
           (int)uexcep->pr_data.additional, uexcep->unwinder_data.pr_addr);
    #endif /* DEBUG_UNWINDER */

    return _URC_SUCCESS;
}
コード例 #4
0
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;
}
コード例 #5
0
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;
}