Access linear memory size atomically (#2834)

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2804
This commit is contained in:
Enrico Loparco
2023-11-29 12:27:17 +00:00
committed by GitHub
parent b81abd01ef
commit 0455071fc1
4 changed files with 38 additions and 16 deletions

View File

@ -36,7 +36,7 @@ typedef float64 CellType_F64;
* multi-threading mode since it may be changed by other
* threads in memory.grow
*/
#define get_linear_mem_size() memory->memory_data_size
#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
#endif
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
@ -1155,7 +1155,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
uint32 linear_mem_size = memory ? memory->memory_data_size : 0;
uint32 linear_mem_size = 0;
if (memory)
#if WASM_ENABLE_THREAD_MGR == 0
linear_mem_size = memory->memory_data_size;
#else
linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
#endif
#endif
WASMType **wasm_types = module->module->types;
WASMGlobalInstance *globals = module->e->globals, *global;
@ -2143,7 +2149,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
linear_mem_size = memory->memory_data_size;
linear_mem_size = get_linear_mem_size();
#endif
}
@ -3148,7 +3154,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
addr = (uint32)POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
linear_mem_size = memory->memory_data_size;
linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@ -3199,7 +3205,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
linear_mem_size = memory->memory_data_size;
linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@ -3230,7 +3236,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
linear_mem_size = memory->memory_data_size;
linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@ -3907,7 +3913,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
if (memory)
linear_mem_size = memory->memory_data_size;
linear_mem_size = get_linear_mem_size();
#endif
if (wasm_copy_exception(module, NULL))
goto got_exception;