Merge branch main into dev/wasi-libc-windows
This commit is contained in:
@ -4009,10 +4009,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
/* ASAN is not designed to work with custom stack unwind or other low-level \
|
||||
things. > Ignore a function that does some low-level magic. (e.g. walking \
|
||||
through the thread's stack bypassing the frame boundaries) */
|
||||
#if defined(__GNUC__)
|
||||
/*
|
||||
* ASAN is not designed to work with custom stack unwind or other low-level
|
||||
* things. Ignore a function that does some low-level magic. (e.g. walking
|
||||
* through the thread's stack bypassing the frame boundaries)
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
__attribute__((no_sanitize_address))
|
||||
#endif
|
||||
static void
|
||||
|
||||
@ -1128,12 +1128,27 @@ wasm_interp_dump_op_count()
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#else
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr = label_base + *(int16 *)frame_ip; \
|
||||
frame_ip += sizeof(int16); \
|
||||
goto *p_label_addr; \
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr; \
|
||||
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
||||
/* int32 relative offset was emitted in 64-bit target */ \
|
||||
p_label_addr = label_base + (int32)LOAD_U32_WITH_2U16S(frame_ip); \
|
||||
frame_ip += sizeof(int32); \
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#else
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr; \
|
||||
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
||||
/* uint32 label address was emitted in 32-bit target */ \
|
||||
p_label_addr = (void *)(uintptr_t)LOAD_U32_WITH_2U16S(frame_ip); \
|
||||
frame_ip += sizeof(int32); \
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#define HANDLE_OP_END() FETCH_OPCODE_AND_DISPATCH()
|
||||
|
||||
@ -1183,7 +1198,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
register uint8 *frame_ip = &opcode_IMPDEP; /* cache of frame->ip */
|
||||
register uint32 *frame_lp = NULL; /* cache of frame->lp */
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 && UINTPTR_MAX == UINT64_MAX
|
||||
/* cache of label base addr */
|
||||
register uint8 *label_base = &&HANDLE_WASM_OP_UNREACHABLE;
|
||||
#endif
|
||||
|
||||
@ -173,7 +173,6 @@ fail:
|
||||
|
||||
#define read_uint8(p) TEMPLATE_READ_VALUE(uint8, p)
|
||||
#define read_uint32(p) TEMPLATE_READ_VALUE(uint32, p)
|
||||
#define read_bool(p) TEMPLATE_READ_VALUE(bool, p)
|
||||
|
||||
#define read_leb_int64(p, p_end, res) \
|
||||
do { \
|
||||
@ -490,6 +489,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end,
|
||||
if (type != VALUE_TYPE_V128)
|
||||
goto fail_type_mismatch;
|
||||
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
flag = read_uint8(p);
|
||||
(void)flag;
|
||||
|
||||
@ -1375,7 +1375,15 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
|
||||
return false;
|
||||
}
|
||||
if (memory->flags > 1) {
|
||||
set_error_buf(error_buf, error_buf_size, "integer too large");
|
||||
if (memory->flags & 2) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"shared memory flag was found, "
|
||||
"please enable shared memory, lib-pthread "
|
||||
"or lib-wasi-threads");
|
||||
}
|
||||
else {
|
||||
set_error_buf(error_buf, error_buf_size, "invalid memory flags");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
@ -5389,21 +5397,27 @@ fail:
|
||||
LOG_OP("\ndelete last op\n"); \
|
||||
} while (0)
|
||||
#else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
#define emit_label(opcode) \
|
||||
do { \
|
||||
int32 offset = \
|
||||
(int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \
|
||||
if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \
|
||||
set_error_buf(error_buf, error_buf_size, \
|
||||
"pre-compiled label offset out of range"); \
|
||||
goto fail; \
|
||||
} \
|
||||
wasm_loader_emit_int16(loader_ctx, offset); \
|
||||
/* emit int32 relative offset in 64-bit target */ \
|
||||
wasm_loader_emit_uint32(loader_ctx, offset); \
|
||||
LOG_OP("\nemit_op [%02x]\t", opcode); \
|
||||
} while (0)
|
||||
#else
|
||||
#define emit_label(opcode) \
|
||||
do { \
|
||||
uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \
|
||||
/* emit uint32 label address in 32-bit target */ \
|
||||
wasm_loader_emit_uint32(loader_ctx, label_addr); \
|
||||
LOG_OP("\nemit_op [%02x]\t", opcode); \
|
||||
} while (0)
|
||||
#endif
|
||||
#define skip_label() \
|
||||
do { \
|
||||
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
|
||||
wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \
|
||||
LOG_OP("\ndelete last op\n"); \
|
||||
} while (0)
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
@ -5733,12 +5747,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
|
||||
(void)error_buf;
|
||||
(void)error_buf_size;
|
||||
return true;
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
||||
fail:
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -7130,6 +7138,7 @@ re_scan:
|
||||
BlockType block_type;
|
||||
|
||||
p_org = p - 1;
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
value_type = read_uint8(p);
|
||||
if (is_byte_a_type(value_type)) {
|
||||
/* If the first byte is one of these special values:
|
||||
@ -7793,6 +7802,9 @@ re_scan:
|
||||
uint8 ref_type;
|
||||
BranchBlock *cur_block = loader_ctx->frame_csp - 1;
|
||||
int32 available_stack_cell;
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
|
||||
#endif
|
||||
|
||||
POP_I32();
|
||||
|
||||
@ -7821,26 +7833,26 @@ re_scan:
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
if (loader_ctx->p_code_compiled) {
|
||||
uint8 opcode_tmp = WASM_OP_SELECT_64;
|
||||
uint8 *p_code_compiled_tmp =
|
||||
loader_ctx->p_code_compiled - 2;
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
*(void **)(p_code_compiled_tmp
|
||||
- sizeof(void *)) =
|
||||
handle_table[opcode_tmp];
|
||||
#else
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
/* emit int32 relative offset in 64-bit target
|
||||
*/
|
||||
int32 offset =
|
||||
(int32)((uint8 *)handle_table[opcode_tmp]
|
||||
- (uint8 *)handle_table[0]);
|
||||
if (!(offset >= INT16_MIN
|
||||
&& offset < INT16_MAX)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"pre-compiled label offset "
|
||||
"out of range");
|
||||
goto fail;
|
||||
}
|
||||
*(int16 *)(p_code_compiled_tmp
|
||||
- sizeof(int16)) = (int16)offset;
|
||||
*(int32 *)(p_code_compiled_tmp
|
||||
- sizeof(int32)) = offset;
|
||||
#else
|
||||
/* emit uint32 label address in 32-bit target */
|
||||
*(uint32 *)(p_code_compiled_tmp
|
||||
- sizeof(uint32)) =
|
||||
(uint32)(uintptr_t)handle_table[opcode_tmp];
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
@ -7934,16 +7946,17 @@ re_scan:
|
||||
*(void **)(p_code_compiled_tmp - sizeof(void *)) =
|
||||
handle_table[opcode_tmp];
|
||||
#else
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
/* emit int32 relative offset in 64-bit target */
|
||||
int32 offset = (int32)((uint8 *)handle_table[opcode_tmp]
|
||||
- (uint8 *)handle_table[0]);
|
||||
if (!(offset >= INT16_MIN && offset < INT16_MAX)) {
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"pre-compiled label offset out of range");
|
||||
goto fail;
|
||||
}
|
||||
*(int16 *)(p_code_compiled_tmp - sizeof(int16)) =
|
||||
(int16)offset;
|
||||
*(int32 *)(p_code_compiled_tmp - sizeof(int32)) =
|
||||
offset;
|
||||
#else
|
||||
/* emit uint32 label address in 32-bit target */
|
||||
*(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) =
|
||||
(uint32)(uintptr_t)handle_table[opcode_tmp];
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
@ -9087,6 +9100,7 @@ re_scan:
|
||||
{
|
||||
uint32 opcode1;
|
||||
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
opcode1 = read_uint8(p);
|
||||
/* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h
|
||||
*/
|
||||
@ -9748,6 +9762,7 @@ re_scan:
|
||||
{
|
||||
uint32 opcode1;
|
||||
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
opcode1 = read_uint8(p);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_byte(loader_ctx, opcode1);
|
||||
|
||||
@ -4009,21 +4009,27 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf,
|
||||
LOG_OP("\ndelete last op\n"); \
|
||||
} while (0)
|
||||
#else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
#define emit_label(opcode) \
|
||||
do { \
|
||||
int32 offset = \
|
||||
(int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \
|
||||
if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \
|
||||
set_error_buf(error_buf, error_buf_size, \
|
||||
"pre-compiled label offset out of range"); \
|
||||
goto fail; \
|
||||
} \
|
||||
wasm_loader_emit_int16(loader_ctx, offset); \
|
||||
/* emit int32 relative offset in 64-bit target */ \
|
||||
wasm_loader_emit_uint32(loader_ctx, offset); \
|
||||
LOG_OP("\nemit_op [%02x]\t", opcode); \
|
||||
} while (0)
|
||||
#else
|
||||
#define emit_label(opcode) \
|
||||
do { \
|
||||
uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \
|
||||
/* emit uint32 label address in 32-bit target */ \
|
||||
wasm_loader_emit_uint32(loader_ctx, label_addr); \
|
||||
LOG_OP("\nemit_op [%02x]\t", opcode); \
|
||||
} while (0)
|
||||
#endif
|
||||
#define skip_label() \
|
||||
do { \
|
||||
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
|
||||
wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \
|
||||
LOG_OP("\ndelete last op\n"); \
|
||||
} while (0)
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
@ -4351,13 +4357,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
||||
fail:
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -6146,6 +6145,9 @@ re_scan:
|
||||
uint8 ref_type;
|
||||
BranchBlock *cur_block = loader_ctx->frame_csp - 1;
|
||||
int32 available_stack_cell;
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
|
||||
#endif
|
||||
|
||||
POP_I32();
|
||||
|
||||
@ -6168,26 +6170,26 @@ re_scan:
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
if (loader_ctx->p_code_compiled) {
|
||||
uint8 opcode_tmp = WASM_OP_SELECT_64;
|
||||
uint8 *p_code_compiled_tmp =
|
||||
loader_ctx->p_code_compiled - 2;
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
*(void **)(p_code_compiled_tmp
|
||||
- sizeof(void *)) =
|
||||
handle_table[opcode_tmp];
|
||||
#else
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
/* emit int32 relative offset in 64-bit target
|
||||
*/
|
||||
int32 offset =
|
||||
(int32)((uint8 *)handle_table[opcode_tmp]
|
||||
- (uint8 *)handle_table[0]);
|
||||
if (!(offset >= INT16_MIN
|
||||
&& offset < INT16_MAX)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"pre-compiled label offset "
|
||||
"out of range");
|
||||
goto fail;
|
||||
}
|
||||
*(int16 *)(p_code_compiled_tmp
|
||||
- sizeof(int16)) = (int16)offset;
|
||||
*(int32 *)(p_code_compiled_tmp
|
||||
- sizeof(int32)) = offset;
|
||||
#else
|
||||
/* emit uint32 label address in 32-bit target */
|
||||
*(uint32 *)(p_code_compiled_tmp
|
||||
- sizeof(uint32)) =
|
||||
(uint32)(uintptr_t)handle_table[opcode_tmp];
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
@ -6263,15 +6265,16 @@ re_scan:
|
||||
*(void **)(p_code_compiled_tmp - sizeof(void *)) =
|
||||
handle_table[opcode_tmp];
|
||||
#else
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
/* emit int32 relative offset in 64-bit target */
|
||||
int32 offset = (int32)((uint8 *)handle_table[opcode_tmp]
|
||||
- (uint8 *)handle_table[0]);
|
||||
if (!(offset >= INT16_MIN && offset < INT16_MAX)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"pre-compiled label offset out of range");
|
||||
goto fail;
|
||||
}
|
||||
*(int16 *)(p_code_compiled_tmp - sizeof(int16)) =
|
||||
(int16)offset;
|
||||
*(int32 *)(p_code_compiled_tmp - sizeof(int32)) = offset;
|
||||
#else
|
||||
/* emit uint32 label address in 32-bit target */
|
||||
*(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) =
|
||||
(uint32)(uintptr_t)handle_table[opcode_tmp];
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "bh_log.h"
|
||||
#include "mem_alloc.h"
|
||||
#include "../common/wasm_runtime_common.h"
|
||||
#include "../common/wasm_memory.h"
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
#include "../common/wasm_shared_memory.h"
|
||||
#endif
|
||||
@ -167,7 +168,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
WASMModule *module = module_inst->module;
|
||||
uint64 memory_data_size;
|
||||
uint64 memory_data_size, max_memory_data_size;
|
||||
uint32 heap_offset = num_bytes_per_page * init_page_count;
|
||||
uint32 inc_page_count, aux_heap_base, global_idx;
|
||||
uint32 bytes_of_last_page, bytes_to_page_end;
|
||||
@ -275,6 +276,12 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
if (max_page_count > DEFAULT_MAX_PAGES)
|
||||
max_page_count = DEFAULT_MAX_PAGES;
|
||||
}
|
||||
else { /* heap_size == 0 */
|
||||
if (init_page_count == DEFAULT_MAX_PAGES) {
|
||||
num_bytes_per_page = UINT32_MAX;
|
||||
init_page_count = max_page_count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_VERBOSE("Memory instantiate:");
|
||||
LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u",
|
||||
@ -282,22 +289,33 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
|
||||
|
||||
memory_data_size = (uint64)num_bytes_per_page * init_page_count;
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (is_shared_memory) {
|
||||
/* Allocate max page for shared memory */
|
||||
memory_data_size = (uint64)num_bytes_per_page * max_page_count;
|
||||
}
|
||||
#endif
|
||||
bh_assert(memory_data_size <= 4 * (uint64)BH_GB);
|
||||
max_memory_data_size = (uint64)num_bytes_per_page * max_page_count;
|
||||
bh_assert(memory_data_size <= UINT32_MAX);
|
||||
bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB);
|
||||
(void)max_memory_data_size;
|
||||
|
||||
bh_assert(memory != NULL);
|
||||
#ifndef OS_ENABLE_HW_BOUND_CHECK
|
||||
if (memory_data_size > 0
|
||||
&& !(memory->memory_data =
|
||||
runtime_malloc(memory_data_size, error_buf, error_buf_size))) {
|
||||
goto fail1;
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (is_shared_memory) {
|
||||
/* Allocate maximum memory size when memory is shared */
|
||||
if (max_memory_data_size > 0
|
||||
&& !(memory->memory_data = runtime_malloc(
|
||||
max_memory_data_size, error_buf, error_buf_size))) {
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Allocate initial memory size when memory is not shared */
|
||||
if (memory_data_size > 0
|
||||
&& !(memory->memory_data = runtime_malloc(
|
||||
memory_data_size, error_buf, error_buf_size))) {
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
|
||||
memory_data_size = (memory_data_size + page_size - 1) & ~(page_size - 1);
|
||||
|
||||
/* Totally 8G is mapped, the opcode load/store address range is 0 to 8G:
|
||||
@ -327,12 +345,13 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
set_error_buf(error_buf, error_buf_size, "mprotect memory failed");
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
/* Newly allocated pages are filled with zero by the OS, we don't fill it
|
||||
* again here */
|
||||
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
|
||||
|
||||
if (memory_data_size > UINT32_MAX)
|
||||
memory_data_size = (uint32)memory_data_size;
|
||||
memory_data_size = UINT32_MAX;
|
||||
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
|
||||
|
||||
memory->module_type = Wasm_Module_Bytecode;
|
||||
memory->num_bytes_per_page = num_bytes_per_page;
|
||||
@ -360,26 +379,13 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
}
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0
|
||||
if (memory_data_size > 0) {
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
memory->mem_bound_check_1byte.u64 = memory_data_size - 1;
|
||||
memory->mem_bound_check_2bytes.u64 = memory_data_size - 2;
|
||||
memory->mem_bound_check_4bytes.u64 = memory_data_size - 4;
|
||||
memory->mem_bound_check_8bytes.u64 = memory_data_size - 8;
|
||||
memory->mem_bound_check_16bytes.u64 = memory_data_size - 16;
|
||||
#else
|
||||
memory->mem_bound_check_1byte.u32[0] = (uint32)memory_data_size - 1;
|
||||
memory->mem_bound_check_2bytes.u32[0] = (uint32)memory_data_size - 2;
|
||||
memory->mem_bound_check_4bytes.u32[0] = (uint32)memory_data_size - 4;
|
||||
memory->mem_bound_check_8bytes.u32[0] = (uint32)memory_data_size - 8;
|
||||
memory->mem_bound_check_16bytes.u32[0] = (uint32)memory_data_size - 16;
|
||||
#endif
|
||||
wasm_runtime_set_mem_bound_check_bytes(memory, memory_data_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (is_shared_memory) {
|
||||
memory->is_shared_memory = true;
|
||||
memory->ref_count = 1;
|
||||
}
|
||||
#endif
|
||||
@ -1780,6 +1786,10 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
|
||||
if (data_seg->is_passive)
|
||||
continue;
|
||||
#endif
|
||||
if (is_sub_inst)
|
||||
/* Ignore setting memory init data if the memory has been
|
||||
initialized */
|
||||
continue;
|
||||
|
||||
/* has check it in loader */
|
||||
memory = module_inst->memories[data_seg->memory_index];
|
||||
@ -2473,15 +2483,20 @@ void
|
||||
wasm_module_free_internal(WASMModuleInstance *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 ptr)
|
||||
{
|
||||
WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
|
||||
|
||||
if (!memory) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ptr) {
|
||||
WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
|
||||
uint8 *addr;
|
||||
uint8 *addr = memory->memory_data + ptr;
|
||||
uint8 *memory_data_end;
|
||||
|
||||
if (!memory) {
|
||||
return;
|
||||
}
|
||||
|
||||
addr = memory->memory_data + ptr;
|
||||
/* memory->memory_data_end may be changed in memory grow */
|
||||
SHARED_MEMORY_LOCK(memory);
|
||||
memory_data_end = memory->memory_data_end;
|
||||
SHARED_MEMORY_UNLOCK(memory);
|
||||
|
||||
if (memory->heap_handle && memory->heap_data <= addr
|
||||
&& addr < memory->heap_data_end) {
|
||||
@ -2489,7 +2504,7 @@ wasm_module_free_internal(WASMModuleInstance *module_inst,
|
||||
}
|
||||
else if (module_inst->e->malloc_function
|
||||
&& module_inst->e->free_function && memory->memory_data <= addr
|
||||
&& addr < memory->memory_data_end) {
|
||||
&& addr < memory_data_end) {
|
||||
execute_free_function(module_inst, exec_env,
|
||||
module_inst->e->free_function, ptr);
|
||||
}
|
||||
@ -3151,7 +3166,9 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
|
||||
maddr = wasm_runtime_addr_app_to_native(
|
||||
(WASMModuleInstanceCommon *)module_inst, dst);
|
||||
|
||||
SHARED_MEMORY_LOCK(memory_inst);
|
||||
bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len);
|
||||
SHARED_MEMORY_UNLOCK(memory_inst);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -79,8 +79,11 @@ typedef union {
|
||||
struct WASMMemoryInstance {
|
||||
/* Module type */
|
||||
uint32 module_type;
|
||||
|
||||
bool is_shared_memory;
|
||||
|
||||
/* Shared memory flag */
|
||||
bh_atomic_32_t ref_count; /* 0: non-shared, > 0: reference count */
|
||||
bh_atomic_16_t ref_count; /* 0: non-shared, > 0: reference count */
|
||||
|
||||
/* Number bytes per page */
|
||||
uint32 num_bytes_per_page;
|
||||
|
||||
Reference in New Issue
Block a user