@@ -224,7 +224,8 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
224
224
continue_execution (info);
225
225
}
226
226
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 )
228
229
{
229
230
sgx_spin_unlock (&g_handler_lock);
230
231
goto failed_end;
@@ -241,6 +242,10 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
241
242
// read unlock
242
243
sgx_spin_unlock (&g_handler_lock);
243
244
245
+ // decrease the nested exception count before the customer
246
+ // handler execution, becasue the handler may never return
247
+ thread_data->exception_flag --;
248
+
244
249
// call exception handler until EXCEPTION_CONTINUE_EXECUTION is returned
245
250
ntmp = nhead;
246
251
while (size > 0 )
@@ -254,7 +259,6 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
254
259
ntmp++;
255
260
size -= sizeof (sgx_exception_handler_t );
256
261
}
257
- free (nhead);
258
262
259
263
// call default handler
260
264
// ignore invalid return value, treat to EXCEPTION_CONTINUE_SEARCH
@@ -265,12 +269,7 @@ extern "C" __attribute__((regparm(1))) void internal_handle_exception(sgx_except
265
269
goto failed_end;
266
270
}
267
271
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)
274
273
{
275
274
// exception cannot be handled
276
275
thread_data->exception_flag = -1 ;
0 commit comments