Skip to content

Commit

Permalink
Fix drop opcode issue in fast interpreter (bytecodealliance#1231)
Browse files Browse the repository at this point in the history
Fix fast interpreter issue reported in bytecodealliance#1230
  • Loading branch information
xujuntwt95329 authored Jun 16, 2022
1 parent e0a8aa0 commit b39f4c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
22 changes: 18 additions & 4 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6552,6 +6552,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
}

#if WASM_ENABLE_FAST_INTERP != 0
/* For the first traverse, the initial value of preserved_local_offset has
* not been determined, we use the INT16_MAX to represent that a slot has
* been copied to preserve space. For second traverse, this field will be
* set to the appropriate value in wasm_loader_ctx_reinit.
* This is for Issue #1230,
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1230, the
* drop opcodes need to know which slots are preserved, so those slots will
* not be treated as dynamically allocated slots */
loader_ctx->preserved_local_offset = INT16_MAX;

re_scan:
if (loader_ctx->code_compiled_size > 0) {
if (!wasm_loader_ctx_reinit(loader_ctx)) {
Expand Down Expand Up @@ -7209,8 +7219,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
loader_ctx->frame_offset--;
if (*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
if ((*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
&& (*(loader_ctx->frame_offset)
< loader_ctx->max_dynamic_offset))
loader_ctx->dynamic_offset--;
#endif
}
Expand All @@ -7223,8 +7235,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
loader_ctx->frame_offset -= 2;
if (*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
if ((*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
&& (*(loader_ctx->frame_offset)
< loader_ctx->max_dynamic_offset))
loader_ctx->dynamic_offset -= 2;
#endif
}
Expand Down
24 changes: 19 additions & 5 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4870,6 +4870,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
}

#if WASM_ENABLE_FAST_INTERP != 0
/* For the first traverse, the initial value of preserved_local_offset has
* not been determined, we use the INT16_MAX to represent that a slot has
* been copied to preserve space. For second traverse, this field will be
* set to the appropriate value in wasm_loader_ctx_reinit.
* This is for Issue #1230,
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1230, the
* drop opcodes need to know which slots are preserved, so those slots will
* not be treated as dynamically allocated slots */
loader_ctx->preserved_local_offset = INT16_MAX;

re_scan:
if (loader_ctx->code_compiled_size > 0) {
if (!wasm_loader_ctx_reinit(loader_ctx)) {
Expand Down Expand Up @@ -5446,8 +5456,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
loader_ctx->frame_offset--;
if (*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
if ((*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
&& (*(loader_ctx->frame_offset)
< loader_ctx->max_dynamic_offset))
loader_ctx->dynamic_offset--;
#endif
}
Expand All @@ -5460,9 +5472,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
loader_ctx->frame_offset -= 2;
if (*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
loader_ctx->dynamic_offset -= 2;
if ((*(loader_ctx->frame_offset)
> loader_ctx->start_dynamic_offset)
&& (*(loader_ctx->frame_offset)
< loader_ctx->max_dynamic_offset))
loader_ctx->dynamic_offset--;
#endif
}
else {
Expand Down

0 comments on commit b39f4c5

Please sign in to comment.