Marcin Kolny
2024-05-13 04:03:38 +01:00
committed by GitHub
parent c85bada2a9
commit fe5e7a9981
26 changed files with 521 additions and 294 deletions

View File

@ -9,6 +9,7 @@
#include "wasm.h"
#include "wasm_opcode.h"
#include "wasm_runtime.h"
#include "wasm_loader_common.h"
#include "../common/wasm_native.h"
#include "../common/wasm_memory.h"
#if WASM_ENABLE_GC != 0
@ -2755,43 +2756,6 @@ check_memory_max_size(bool is_memory64, uint32 init_size, uint32 max_size,
return true;
}
static bool
check_memory_flag(const uint8 mem_flag, char *error_buf, uint32 error_buf_size)
{
/* Check whether certain features indicated by mem_flag are enabled in
* runtime */
if (mem_flag > MAX_PAGE_COUNT_FLAG) {
#if WASM_ENABLE_SHARED_MEMORY == 0
if (mem_flag & SHARED_MEMORY_FLAG) {
LOG_VERBOSE("shared memory flag was found, please enable shared "
"memory, lib-pthread or lib-wasi-threads");
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
return false;
}
#endif
#if WASM_ENABLE_MEMORY64 == 0
if (mem_flag & MEMORY64_FLAG) {
LOG_VERBOSE("memory64 flag was found, please enable memory64");
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
return false;
}
#endif
}
if (mem_flag > MAX_PAGE_COUNT_FLAG + SHARED_MEMORY_FLAG + MEMORY64_FLAG) {
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
return false;
}
else if ((mem_flag & SHARED_MEMORY_FLAG)
&& !(mem_flag & MAX_PAGE_COUNT_FLAG)) {
set_error_buf(error_buf, error_buf_size,
"shared memory must have maximum");
return false;
}
return true;
}
static bool
load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
WASMModule *parent_module, const char *sub_module_name,
@ -2824,7 +2788,7 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
return false;
}
if (!check_memory_flag(mem_flag, error_buf, error_buf_size)) {
if (!wasm_memory_check_flags(mem_flag, error_buf, error_buf_size, false)) {
return false;
}
@ -3226,7 +3190,8 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
return false;
}
if (!check_memory_flag(memory->flags, error_buf, error_buf_size)) {
if (!wasm_memory_check_flags(memory->flags, error_buf, error_buf_size,
false)) {
return false;
}
@ -14762,9 +14727,9 @@ re_scan:
goto fail;
}
read_leb_uint32(p, p_end, mem_offset); /* offset */
read_leb_mem_offset(p, p_end, mem_offset); /* offset */
POP_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_V128);
POP_AND_PUSH(mem_offset_type, VALUE_TYPE_V128);
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
func->has_memory_operations = true;
#endif
@ -14781,10 +14746,10 @@ re_scan:
goto fail;
}
read_leb_uint32(p, p_end, mem_offset); /* offset */
read_leb_mem_offset(p, p_end, mem_offset); /* offset */
POP_V128();
POP_I32();
POP_MEM_OFFSET();
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
func->has_memory_operations = true;
#endif
@ -14999,7 +14964,7 @@ re_scan:
goto fail;
}
read_leb_uint32(p, p_end, mem_offset); /* offset */
read_leb_mem_offset(p, p_end, mem_offset); /* offset */
CHECK_BUF(p, p_end, 1);
lane = read_uint8(p);
@ -15009,7 +14974,7 @@ re_scan:
}
POP_V128();
POP_I32();
POP_MEM_OFFSET();
if (opcode1 < SIMD_v128_store8_lane) {
PUSH_V128();
}
@ -15030,9 +14995,9 @@ re_scan:
goto fail;
}
read_leb_uint32(p, p_end, mem_offset); /* offset */
read_leb_mem_offset(p, p_end, mem_offset); /* offset */
POP_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_V128);
POP_AND_PUSH(mem_offset_type, VALUE_TYPE_V128);
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
func->has_memory_operations = true;
#endif