Fix data/elem drop (#2747)
Currently, `data.drop` instruction is implemented by directly modifying the underlying module. It breaks use cases where you have multiple instances sharing a single loaded module. `elem.drop` has the same problem too. This PR fixes the issue by keeping track of which data/elem segments have been dropped by using bitmaps for each module instances separately, and add a sample to demonstrate the issue and make the CI run it. Also add a missing check of dropped elements to the fast-jit `table.init`. Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2735 Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2772
This commit is contained in:
@ -3005,10 +3005,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
goto out_of_bounds;
|
||||
maddr = memory->memory_data + (uint32)addr;
|
||||
#endif
|
||||
if (bh_bitmap_get_bit(module->e->common.data_dropped,
|
||||
segment)) {
|
||||
seg_len = 0;
|
||||
data = NULL;
|
||||
}
|
||||
else {
|
||||
|
||||
seg_len = (uint64)module->module->data_segments[segment]
|
||||
->data_length;
|
||||
data = module->module->data_segments[segment]->data;
|
||||
seg_len =
|
||||
(uint64)module->module->data_segments[segment]
|
||||
->data_length;
|
||||
data = module->module->data_segments[segment]->data;
|
||||
}
|
||||
if (offset + bytes > seg_len)
|
||||
goto out_of_bounds;
|
||||
|
||||
@ -3021,8 +3029,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
uint32 segment;
|
||||
|
||||
segment = read_uint32(frame_ip);
|
||||
|
||||
module->module->data_segments[segment]->data_length = 0;
|
||||
bh_bitmap_set_bit(module->e->common.data_dropped,
|
||||
segment);
|
||||
break;
|
||||
}
|
||||
case WASM_OP_MEMORY_COPY:
|
||||
@ -3114,8 +3122,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
break;
|
||||
}
|
||||
|
||||
if (module->module->table_segments[elem_idx]
|
||||
.is_dropped) {
|
||||
if (bh_bitmap_get_bit(module->e->common.elem_dropped,
|
||||
elem_idx)) {
|
||||
wasm_set_exception(module,
|
||||
"out of bounds table access");
|
||||
goto got_exception;
|
||||
@ -3144,9 +3152,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
{
|
||||
uint32 elem_idx = read_uint32(frame_ip);
|
||||
bh_assert(elem_idx < module->module->table_seg_count);
|
||||
|
||||
module->module->table_segments[elem_idx].is_dropped =
|
||||
true;
|
||||
bh_bitmap_set_bit(module->e->common.elem_dropped,
|
||||
elem_idx);
|
||||
break;
|
||||
}
|
||||
case WASM_OP_TABLE_COPY:
|
||||
|
||||
Reference in New Issue
Block a user