Skip to content

Commit

Permalink
Support longjmp in exception handler (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
guzongmin authored Oct 23, 2020
1 parent 74b24b6 commit 9671c99
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions sdk/trts/trts_veh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
continue_execution(info);
}

if ((nhead = (uintptr_t *)malloc(size)) == NULL)
// The customer handler may never return, use alloca instead of malloc
if ((nhead = (uintptr_t *)alloca(size)) == NULL)
{
sgx_spin_unlock(&g_handler_lock);
goto failed_end;
Expand All @@ -241,6 +242,10 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
// read unlock
sgx_spin_unlock(&g_handler_lock);

// decrease the nested exception count before the customer
// handler execution, becasue the handler may never return
thread_data->exception_flag--;

// call exception handler until EXCEPTION_CONTINUE_EXECUTION is returned
ntmp = nhead;
while(size > 0)
Expand All @@ -254,7 +259,6 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
ntmp++;
size -= sizeof(sgx_exception_handler_t);
}
free(nhead);

// call default handler
// ignore invalid return value, treat to EXCEPTION_CONTINUE_SEARCH
Expand All @@ -265,12 +269,7 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
goto failed_end;
}

if(EXCEPTION_CONTINUE_EXECUTION == status)
{
//exception is handled, decrease the nested exception count
thread_data->exception_flag--;
}
else
if(EXCEPTION_CONTINUE_EXECUTION != status)
{
//exception cannot be handled
thread_data->exception_flag = -1;
Expand Down

0 comments on commit 9671c99

Please sign in to comment.