Implement memory access bound check with hardware trap for 64-bit platforms (#293)
Also implement native stack overflow check with hardware trap for 64-bit platforms Refine classic interpreter and fast interpreter to improve performance Update document
This commit is contained in:
@ -3889,13 +3889,13 @@ wasm_loader_check_br(WASMLoaderContext *ctx, uint32 depth,
|
||||
LOG_OP("%d\t", byte); \
|
||||
} while (0)
|
||||
|
||||
#define emit_leb() do { \
|
||||
wasm_loader_emit_leb(loader_ctx, p_org, p); \
|
||||
#define emit_uint32(ctx, value) do { \
|
||||
wasm_loader_emit_uint32(ctx, value); \
|
||||
LOG_OP("%d\t", value); \
|
||||
} while (0)
|
||||
|
||||
#define emit_const(value) do { \
|
||||
GET_CONST_OFFSET(VALUE_TYPE_I32, value); \
|
||||
emit_operand(loader_ctx, operand_offset); \
|
||||
#define emit_leb() do { \
|
||||
wasm_loader_emit_leb(loader_ctx, p_org, p); \
|
||||
} while (0)
|
||||
|
||||
static bool
|
||||
@ -3930,6 +3930,17 @@ wasm_loader_ctx_reinit(WASMLoaderContext *ctx)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
wasm_loader_emit_uint32(WASMLoaderContext *ctx, uint32 value)
|
||||
{
|
||||
if (ctx->p_code_compiled) {
|
||||
*(uint32*)(ctx->p_code_compiled) = value;
|
||||
ctx->p_code_compiled += sizeof(uint32);
|
||||
}
|
||||
else
|
||||
ctx->code_compiled_size += sizeof(uint32);
|
||||
}
|
||||
|
||||
static void
|
||||
wasm_loader_emit_int16(WASMLoaderContext *ctx, int16 value)
|
||||
{
|
||||
@ -5036,7 +5047,7 @@ re_scan:
|
||||
|
||||
read_leb_uint32(p, p_end, count);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(count);
|
||||
emit_uint32(loader_ctx, count);
|
||||
#endif
|
||||
POP_I32();
|
||||
|
||||
@ -5097,7 +5108,7 @@ re_scan:
|
||||
read_leb_uint32(p, p_end, func_idx);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
// we need to emit func_idx before arguments
|
||||
emit_const(func_idx);
|
||||
emit_uint32(loader_ctx, func_idx);
|
||||
#endif
|
||||
|
||||
if (func_idx >= module->import_function_count + module->function_count) {
|
||||
@ -5150,7 +5161,7 @@ re_scan:
|
||||
read_leb_uint32(p, p_end, type_idx);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
// we need to emit func_idx before arguments
|
||||
emit_const(type_idx);
|
||||
emit_uint32(loader_ctx, type_idx);
|
||||
#endif
|
||||
|
||||
/* reserved byte 0x00 */
|
||||
@ -5476,7 +5487,7 @@ re_scan:
|
||||
|
||||
PUSH_TYPE(global_type);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(global_idx);
|
||||
emit_uint32(loader_ctx, global_idx);
|
||||
PUSH_OFFSET_TYPE(global_type);
|
||||
#endif
|
||||
break;
|
||||
@ -5513,7 +5524,7 @@ re_scan:
|
||||
|
||||
POP_TYPE(global_type);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(global_idx);
|
||||
emit_uint32(loader_ctx, global_idx);
|
||||
POP_OFFSET_TYPE(global_type);
|
||||
#endif
|
||||
break;
|
||||
@ -5572,7 +5583,7 @@ re_scan:
|
||||
goto fail;
|
||||
}
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(mem_offset);
|
||||
emit_uint32(loader_ctx, mem_offset);
|
||||
#endif
|
||||
switch (opcode)
|
||||
{
|
||||
@ -5951,7 +5962,7 @@ re_scan:
|
||||
case WASM_OP_MEMORY_INIT:
|
||||
read_leb_uint32(p, p_end, segment_index);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(segment_index);
|
||||
emit_uint32(loader_ctx, segment_index);
|
||||
#endif
|
||||
if (module->import_memory_count == 0 && module->memory_count == 0)
|
||||
goto fail_unknown_memory;
|
||||
@ -5977,7 +5988,7 @@ re_scan:
|
||||
case WASM_OP_DATA_DROP:
|
||||
read_leb_uint32(p, p_end, segment_index);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
emit_const(segment_index);
|
||||
emit_uint32(loader_ctx, segment_index);
|
||||
#endif
|
||||
if (segment_index >= module->data_seg_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
|
||||
Reference in New Issue
Block a user