@@ -224,7 +224,8 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
224224 continue_execution (info);
225225 }
226226
227- if ((nhead = (uintptr_t *)malloc (size)) == NULL )
227+ // The customer handler may never return, use alloca instead of malloc
228+ if ((nhead = (uintptr_t *)alloca (size)) == NULL )
228229 {
229230 sgx_spin_unlock (&g_handler_lock);
230231 goto failed_end;
@@ -241,6 +242,10 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
241242 // read unlock
242243 sgx_spin_unlock (&g_handler_lock);
243244
245+ // decrease the nested exception count before the customer
246+ // handler execution, becasue the handler may never return
247+ thread_data->exception_flag --;
248+
244249 // call exception handler until EXCEPTION_CONTINUE_EXECUTION is returned
245250 ntmp = nhead;
246251 while (size > 0 )
@@ -254,7 +259,6 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
254259 ntmp++;
255260 size -= sizeof (sgx_exception_handler_t );
256261 }
257- free (nhead);
258262
259263 // call default handler
260264 // ignore invalid return value, treat to EXCEPTION_CONTINUE_SEARCH
@@ -265,12 +269,7 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
265269 goto failed_end;
266270 }
267271
268- if (EXCEPTION_CONTINUE_EXECUTION == status)
269- {
270- // exception is handled, decrease the nested exception count
271- thread_data->exception_flag --;
272- }
273- else
272+ if (EXCEPTION_CONTINUE_EXECUTION != status)
274273 {
275274 // exception cannot be handled
276275 thread_data->exception_flag = -1 ;
0 commit comments