From 9d2576d8e07508cea5fd2519c71c9887c4bae671 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Thu, 6 Jan 2022 11:43:34 +0800 Subject: [PATCH] Wrap data width according to atomic opcode specified (#936) Wrap data width according to atomic opcode specified Signed-off-by: Huang Qi --- core/iwasm/interpreter/wasm_interp_classic.c | 5 +++++ core/iwasm/interpreter/wasm_interp_fast.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 419d6d49..0bfa02fc 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -3389,6 +3389,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); + expect = (uint8)expect; os_mutex_lock(&memory->mem_lock); readv = (uint32)(*(uint8 *)maddr); if (readv == expect) @@ -3399,6 +3400,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); + expect = (uint16)expect; os_mutex_lock(&memory->mem_lock); readv = (uint32)LOAD_U16(maddr); if (readv == expect) @@ -3433,6 +3435,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); + expect = (uint8)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)(*(uint8 *)maddr); if (readv == expect) @@ -3443,6 +3446,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); + expect = (uint16)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)LOAD_U16(maddr); if (readv == expect) @@ -3453,6 +3457,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); + expect = (uint32)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)LOAD_U32(maddr); if (readv == expect) diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 9bb57021..0b567137 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -3308,6 +3308,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); + expect = (uint8)expect; os_mutex_lock(&memory->mem_lock); readv = (uint32)(*(uint8 *)maddr); if (readv == expect) @@ -3318,6 +3319,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); + expect = (uint16)expect; os_mutex_lock(&memory->mem_lock); readv = (uint32)LOAD_U16(maddr); if (readv == expect) @@ -3352,6 +3354,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); + expect = (uint8)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)(*(uint8 *)maddr); if (readv == expect) @@ -3362,6 +3365,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); + expect = (uint16)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)LOAD_U16(maddr); if (readv == expect) @@ -3372,6 +3376,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); + expect = (uint32)expect; os_mutex_lock(&memory->mem_lock); readv = (uint64)LOAD_U32(maddr); if (readv == expect)