@@ -1509,6 +1509,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
1509
1509
WASMStringviewIterObjectRef stringview_iter_obj ;
1510
1510
#endif
1511
1511
#endif
1512
+ #if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
1513
+ bool is_return_call = false;
1514
+ #endif
1512
1515
#if WASM_ENABLE_MEMORY64 != 0
1513
1516
/* TODO: multi-memories for now assuming the memory idx type is consistent
1514
1517
* across multi-memories */
@@ -6227,6 +6230,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
6227
6230
frame_ip = frame -> ip ;
6228
6231
frame_sp = frame -> sp ;
6229
6232
frame_csp = frame -> csp ;
6233
+ #if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
6234
+ is_return_call = false;
6235
+ #endif
6230
6236
goto call_func_from_entry ;
6231
6237
}
6232
6238
@@ -6320,6 +6326,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
6320
6326
}
6321
6327
FREE_FRAME (exec_env , frame );
6322
6328
wasm_exec_env_set_cur_frame (exec_env , prev_frame );
6329
+ is_return_call = true;
6323
6330
goto call_func_from_entry ;
6324
6331
}
6325
6332
#endif
@@ -6333,6 +6340,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
6333
6340
}
6334
6341
SYNC_ALL_TO_FRAME ();
6335
6342
prev_frame = frame ;
6343
+ #if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
6344
+ is_return_call = false;
6345
+ #endif
6336
6346
}
6337
6347
6338
6348
call_func_from_entry :
@@ -6342,15 +6352,27 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
6342
6352
if (cur_func -> import_func_inst ) {
6343
6353
wasm_interp_call_func_import (module , exec_env , cur_func ,
6344
6354
prev_frame );
6355
+ #if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
6356
+ if (is_return_call ) {
6357
+ /* the frame was freed before tail calling and
6358
+ the prev_frame was set as exec_env's cur_frame,
6359
+ so here we recover context from prev_frame */
6360
+ RECOVER_CONTEXT (prev_frame );
6361
+ }
6362
+ else
6363
+ #endif
6364
+ {
6365
+ prev_frame = frame -> prev_frame ;
6366
+ cur_func = frame -> function ;
6367
+ UPDATE_ALL_FROM_FRAME ();
6368
+ }
6369
+
6345
6370
#if WASM_ENABLE_EXCE_HANDLING != 0
6346
6371
char uncaught_exception [128 ] = { 0 };
6347
6372
bool has_exception =
6348
6373
wasm_copy_exception (module , uncaught_exception );
6349
6374
if (has_exception
6350
6375
&& strstr (uncaught_exception , "uncaught wasm exception" )) {
6351
- /* fix framesp */
6352
- UPDATE_ALL_FROM_FRAME ();
6353
-
6354
6376
uint32 import_exception ;
6355
6377
/* initialize imported exception index to be invalid */
6356
6378
SET_INVALID_TAGINDEX (import_exception );
@@ -6392,12 +6414,22 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
6392
6414
{
6393
6415
wasm_interp_call_func_native (module , exec_env , cur_func ,
6394
6416
prev_frame );
6417
+ #if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
6418
+ if (is_return_call ) {
6419
+ /* the frame was freed before tail calling and
6420
+ the prev_frame was set as exec_env's cur_frame,
6421
+ so here we recover context from prev_frame */
6422
+ RECOVER_CONTEXT (prev_frame );
6423
+ }
6424
+ else
6425
+ #endif
6426
+ {
6427
+ prev_frame = frame -> prev_frame ;
6428
+ cur_func = frame -> function ;
6429
+ UPDATE_ALL_FROM_FRAME ();
6430
+ }
6395
6431
}
6396
6432
6397
- prev_frame = frame -> prev_frame ;
6398
- cur_func = frame -> function ;
6399
- UPDATE_ALL_FROM_FRAME ();
6400
-
6401
6433
/* update memory size, no need to update memory ptr as
6402
6434
it isn't changed in wasm_enlarge_memory */
6403
6435
#if !defined(OS_ENABLE_HW_BOUND_CHECK ) \
0 commit comments