@@ -11234,6 +11234,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
11234
11234
bool disable_emit, preserve_local = false, if_condition_available = true;
11235
11235
float32 f32_const;
11236
11236
float64 f64_const;
11237
+ /*
11238
+ * It means that the fast interpreter detected an exception while preparing,
11239
+ * typically near the block opcode, but it did not immediately trigger
11240
+ * the exception. The loader should be capable of identifying it near
11241
+ * the end opcode and then raising the exception.
11242
+ */
11243
+ bool pending_exception = false;
11237
11244
11238
11245
LOG_OP("\nProcessing func | [%d] params | [%d] locals | [%d] return\n",
11239
11246
func->param_cell_num, func->local_cell_num, func->ret_cell_num);
@@ -11584,6 +11591,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
11584
11591
cell_num = wasm_value_type_cell_num(
11585
11592
wasm_type->types[wasm_type->param_count - i - 1]);
11586
11593
loader_ctx->frame_offset -= cell_num;
11594
+
11595
+ if (loader_ctx->frame_offset
11596
+ < loader_ctx->frame_offset_bottom) {
11597
+ LOG_DEBUG(
11598
+ "frame_offset underflow, roll back and "
11599
+ "let following stack checker report it\n");
11600
+ loader_ctx->frame_offset += cell_num;
11601
+ pending_exception = true;
11602
+ break;
11603
+ }
11587
11604
#endif
11588
11605
}
11589
11606
}
@@ -12106,6 +12123,15 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
12106
12123
}
12107
12124
}
12108
12125
12126
+ #if WASM_ENABLE_FAST_INTERP != 0
12127
+ if (pending_exception) {
12128
+ set_error_buf(
12129
+ error_buf, error_buf_size,
12130
+ "There is a pending exception needs to be handled");
12131
+ goto fail;
12132
+ }
12133
+ #endif
12134
+
12109
12135
break;
12110
12136
}
12111
12137
0 commit comments