mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 15:05:19 +00:00
Apply clang-format for more src files and update spec test script (#775)
Apply clang-format for core/iwasm/include, core/iwasm/common and core/iwasm/aot files. Update spec cases test script: - Checkout latest commit of https://github.com/WebAssembly/spec - Checkout main branch but not master of https://github.com/WebAssembly/threads - Update wabt to latest version And update source debugging document. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
parent
6415e1b006
commit
52b6c73d9c
|
@ -11,43 +11,30 @@ typedef struct {
|
|||
uint64 flag;
|
||||
} aot_intrinsic;
|
||||
|
||||
/* clang-format off */
|
||||
static const aot_intrinsic g_intrinsic_mapping[] = {
|
||||
{ "llvm.experimental.constrained.fadd.f32", "aot_intrinsic_fadd_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FADD },
|
||||
{ "llvm.experimental.constrained.fadd.f64", "aot_intrinsic_fadd_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FADD },
|
||||
{ "llvm.experimental.constrained.fsub.f32", "aot_intrinsic_fsub_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FSUB },
|
||||
{ "llvm.experimental.constrained.fsub.f64", "aot_intrinsic_fsub_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FSUB },
|
||||
{ "llvm.experimental.constrained.fmul.f32", "aot_intrinsic_fmul_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FMUL },
|
||||
{ "llvm.experimental.constrained.fmul.f64", "aot_intrinsic_fmul_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FMUL },
|
||||
{ "llvm.experimental.constrained.fdiv.f32", "aot_intrinsic_fdiv_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FDIV },
|
||||
{ "llvm.experimental.constrained.fdiv.f64", "aot_intrinsic_fdiv_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FDIV },
|
||||
{ "llvm.experimental.constrained.fadd.f32", "aot_intrinsic_fadd_f32", AOT_INTRINSIC_FLAG_F32_FADD },
|
||||
{ "llvm.experimental.constrained.fadd.f64", "aot_intrinsic_fadd_f64", AOT_INTRINSIC_FLAG_F64_FADD },
|
||||
{ "llvm.experimental.constrained.fsub.f32", "aot_intrinsic_fsub_f32", AOT_INTRINSIC_FLAG_F32_FSUB },
|
||||
{ "llvm.experimental.constrained.fsub.f64", "aot_intrinsic_fsub_f64", AOT_INTRINSIC_FLAG_F64_FSUB },
|
||||
{ "llvm.experimental.constrained.fmul.f32", "aot_intrinsic_fmul_f32", AOT_INTRINSIC_FLAG_F32_FMUL },
|
||||
{ "llvm.experimental.constrained.fmul.f64", "aot_intrinsic_fmul_f64", AOT_INTRINSIC_FLAG_F64_FMUL },
|
||||
{ "llvm.experimental.constrained.fdiv.f32", "aot_intrinsic_fdiv_f32", AOT_INTRINSIC_FLAG_F32_FDIV },
|
||||
{ "llvm.experimental.constrained.fdiv.f64", "aot_intrinsic_fdiv_f64", AOT_INTRINSIC_FLAG_F64_FDIV },
|
||||
{ "llvm.fabs.f32", "aot_intrinsic_fabs_f32", AOT_INTRINSIC_FLAG_F32_FABS },
|
||||
{ "llvm.fabs.f64", "aot_intrinsic_fabs_f64", AOT_INTRINSIC_FLAG_F64_FABS },
|
||||
{ "llvm.ceil.f32", "aot_intrinsic_ceil_f32", AOT_INTRINSIC_FLAG_F32_CEIL },
|
||||
{ "llvm.ceil.f64", "aot_intrinsic_ceil_f64", AOT_INTRINSIC_FLAG_F64_CEIL },
|
||||
{ "llvm.floor.f32", "aot_intrinsic_floor_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_FLOOR },
|
||||
{ "llvm.floor.f64", "aot_intrinsic_floor_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_FLOOR },
|
||||
{ "llvm.trunc.f32", "aot_intrinsic_trunc_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_TRUNC },
|
||||
{ "llvm.trunc.f64", "aot_intrinsic_trunc_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_TRUNC },
|
||||
{ "llvm.floor.f32", "aot_intrinsic_floor_f32", AOT_INTRINSIC_FLAG_F32_FLOOR },
|
||||
{ "llvm.floor.f64", "aot_intrinsic_floor_f64", AOT_INTRINSIC_FLAG_F64_FLOOR },
|
||||
{ "llvm.trunc.f32", "aot_intrinsic_trunc_f32", AOT_INTRINSIC_FLAG_F32_TRUNC },
|
||||
{ "llvm.trunc.f64", "aot_intrinsic_trunc_f64", AOT_INTRINSIC_FLAG_F64_TRUNC },
|
||||
{ "llvm.rint.f32", "aot_intrinsic_rint_f32", AOT_INTRINSIC_FLAG_F32_RINT },
|
||||
{ "llvm.rint.f64", "aot_intrinsic_rint_f64", AOT_INTRINSIC_FLAG_F64_RINT },
|
||||
{ "llvm.sqrt.f32", "aot_intrinsic_sqrt_f32", AOT_INTRINSIC_FLAG_F32_SQRT },
|
||||
{ "llvm.sqrt.f64", "aot_intrinsic_sqrt_f64", AOT_INTRINSIC_FLAG_F64_SQRT },
|
||||
{ "llvm.copysign.f32", "aot_intrinsic_copysign_f32",
|
||||
AOT_INTRINSIC_FLAG_F32_COPYSIGN },
|
||||
{ "llvm.copysign.f64", "aot_intrinsic_copysign_f64",
|
||||
AOT_INTRINSIC_FLAG_F64_COPYSIGN },
|
||||
{ "llvm.copysign.f32", "aot_intrinsic_copysign_f32", AOT_INTRINSIC_FLAG_F32_COPYSIGN },
|
||||
{ "llvm.copysign.f64", "aot_intrinsic_copysign_f64", AOT_INTRINSIC_FLAG_F64_COPYSIGN },
|
||||
{ "llvm.minnum.f32", "aot_intrinsic_fmin_f32", AOT_INTRINSIC_FLAG_F32_MIN },
|
||||
{ "llvm.minnum.f64", "aot_intrinsic_fmin_f64", AOT_INTRINSIC_FLAG_F64_MIN },
|
||||
{ "llvm.maxnum.f32", "aot_intrinsic_fmax_f32", AOT_INTRINSIC_FLAG_F32_MAX },
|
||||
|
@ -72,6 +59,7 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
|
|||
{ "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP },
|
||||
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP },
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const uint32 g_intrinsic_count =
|
||||
sizeof(g_intrinsic_mapping) / sizeof(aot_intrinsic);
|
||||
|
@ -600,7 +588,8 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
|
|||
return;
|
||||
|
||||
if (!strncmp(comp_ctx->target_arch, "thumb", 5)) {
|
||||
if (!strcmp(comp_ctx->target_cpu, "cortex-m7")) {}
|
||||
if (!strcmp(comp_ctx->target_cpu, "cortex-m7")) {
|
||||
}
|
||||
else if (!strcmp(comp_ctx->target_cpu, "cortex-m4")) {
|
||||
add_f64_common_intrinsics(comp_ctx);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
#define AOT_INTRINSIC_GET_GROUP_FROM_FLAG(flag) \
|
||||
((((uint64)flag) >> 48) & 0xffffLL)
|
||||
|
||||
/* clang-format off */
|
||||
#define AOT_INTRINSIC_FLAG_F32_FADD AOT_INTRINSIC_FLAG(0, 0)
|
||||
#define AOT_INTRINSIC_FLAG_F32_FSUB AOT_INTRINSIC_FLAG(0, 1)
|
||||
#define AOT_INTRINSIC_FLAG_F32_FMUL AOT_INTRINSIC_FLAG(0, 2)
|
||||
|
@ -83,6 +84,7 @@ extern "C" {
|
|||
#define AOT_INTRINSIC_FLAG_F64_TO_U64 AOT_INTRINSIC_FLAG(1, 23)
|
||||
#define AOT_INTRINSIC_FLAG_F64_TO_F32 AOT_INTRINSIC_FLAG(1, 24)
|
||||
#define AOT_INTRINSIC_FLAG_F64_CMP AOT_INTRINSIC_FLAG(1, 25)
|
||||
/* clang-format on */
|
||||
|
||||
float32
|
||||
aot_intrinsic_fadd_f32(float32 a, float32 b);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,14 +3,22 @@
|
|||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _AOT_RELOC_H_
|
||||
#define _AOT_RELOC_H_
|
||||
|
||||
#include "aot_runtime.h"
|
||||
#include "aot_intrinsic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char *symbol_name;
|
||||
void *symbol_addr;
|
||||
} SymbolMap;
|
||||
|
||||
/* clang-format off */
|
||||
#define REG_SYM(symbol) { #symbol, (void *)symbol }
|
||||
|
||||
#if WASM_ENABLE_BULK_MEMORY != 0
|
||||
|
@ -123,7 +131,8 @@ typedef struct {
|
|||
REG_INTRINSIC_SYM() \
|
||||
|
||||
#define CHECK_RELOC_OFFSET(data_size) do { \
|
||||
if (!check_reloc_offset(target_section_size, reloc_offset, data_size, \
|
||||
if (!check_reloc_offset(target_section_size, \
|
||||
reloc_offset, data_size, \
|
||||
error_buf, error_buf_size)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
@ -146,4 +155,10 @@ apply_relocation(AOTModule *module,
|
|||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _AOT_RELOC_H_ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -95,6 +95,7 @@ typedef struct AOTFunctionInstance {
|
|||
} AOTFunctionInstance;
|
||||
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||
/* clang-format off */
|
||||
typedef struct AOTUnwindInfo {
|
||||
uint8 Version : 3;
|
||||
uint8 Flags : 5;
|
||||
|
@ -111,6 +112,7 @@ typedef struct AOTUnwindInfo {
|
|||
uint16 FrameOffset;
|
||||
} UnwindCode[1];
|
||||
} AOTUnwindInfo;
|
||||
/* clang-format on */
|
||||
|
||||
/* size of mov instruction and jmp instruction */
|
||||
#define PLT_ITEM_SIZE 12
|
||||
|
@ -409,8 +411,7 @@ typedef struct AOTTargetInfo {
|
|||
char arch[16];
|
||||
} AOTTargetInfo;
|
||||
|
||||
typedef struct AOTFuncPerfProfInfo
|
||||
{
|
||||
typedef struct AOTFuncPerfProfInfo {
|
||||
/* total execution time */
|
||||
uint64 total_exec_time;
|
||||
/* total execution count */
|
||||
|
@ -437,8 +438,8 @@ typedef struct AOTFrame {
|
|||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule *
|
||||
aot_load_from_aot_file(const uint8 *buf, uint32 size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
/**
|
||||
* Load a AOT module from a specified AOT section list.
|
||||
|
@ -450,8 +451,8 @@ aot_load_from_aot_file(const uint8 *buf, uint32 size,
|
|||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule *
|
||||
aot_load_from_sections(AOTSection *section_list,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
aot_load_from_sections(AOTSection *section_list, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
#if WASM_ENABLE_JIT != 0
|
||||
/**
|
||||
|
@ -464,8 +465,8 @@ aot_load_from_sections(AOTSection *section_list,
|
|||
* @return return AOT module loaded, NULL if failed
|
||||
*/
|
||||
AOTModule *
|
||||
aot_convert_wasm_module(WASMModule *wasm_module,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
aot_convert_wasm_module(WASMModule *wasm_module, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -491,9 +492,8 @@ aot_unload(AOTModule *module);
|
|||
* @return return the instantiated AOT module instance, NULL if failed
|
||||
*/
|
||||
AOTModuleInstance *
|
||||
aot_instantiate(AOTModule *module, bool is_sub_inst,
|
||||
uint32 stack_size, uint32 heap_size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
uint32 heap_size, char *error_buf, uint32 error_buf_size);
|
||||
|
||||
/**
|
||||
* Deinstantiate a AOT module instance, destroy the resources.
|
||||
|
@ -515,8 +515,8 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
|
|||
* @return the function instance found
|
||||
*/
|
||||
AOTFunctionInstance *
|
||||
aot_lookup_function(const AOTModuleInstance *module_inst,
|
||||
const char *name, const char *signature);
|
||||
aot_lookup_function(const AOTModuleInstance *module_inst, const char *name,
|
||||
const char *signature);
|
||||
/**
|
||||
* Call the given AOT function of a AOT module instance with
|
||||
* arguments.
|
||||
|
@ -533,8 +533,7 @@ aot_lookup_function(const AOTModuleInstance *module_inst,
|
|||
* the caller can call aot_get_exception to get exception info.
|
||||
*/
|
||||
bool
|
||||
aot_call_function(WASMExecEnv *exec_env,
|
||||
AOTFunctionInstance *function,
|
||||
aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
|
||||
unsigned argc, uint32 argv[]);
|
||||
|
||||
bool
|
||||
|
@ -553,12 +552,10 @@ aot_create_exec_env_singleton(AOTModuleInstance *module_inst);
|
|||
* @param exception current exception string
|
||||
*/
|
||||
void
|
||||
aot_set_exception(AOTModuleInstance *module_inst,
|
||||
const char *exception);
|
||||
aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
|
||||
|
||||
void
|
||||
aot_set_exception_with_id(AOTModuleInstance *module_inst,
|
||||
uint32 id);
|
||||
aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
|
||||
|
||||
/**
|
||||
* Get exception info of the AOT module instance.
|
||||
|
@ -583,24 +580,23 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
|
|||
void **p_native_addr);
|
||||
|
||||
uint32
|
||||
aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr,
|
||||
uint32 size, void **p_native_addr);
|
||||
aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
void
|
||||
aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
|
||||
|
||||
uint32
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst,
|
||||
const char *src, uint32 size);
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
|
||||
uint32 size);
|
||||
|
||||
bool
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst,
|
||||
uint32 app_offset, uint32 size);
|
||||
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst, uint32 app_offset,
|
||||
uint32 size);
|
||||
|
||||
bool
|
||||
aot_validate_native_addr(AOTModuleInstance *module_inst,
|
||||
void *native_ptr, uint32 size);
|
||||
aot_validate_native_addr(AOTModuleInstance *module_inst, void *native_ptr,
|
||||
uint32 size);
|
||||
|
||||
void *
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset);
|
||||
|
@ -609,14 +605,11 @@ uint32
|
|||
aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr);
|
||||
|
||||
bool
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst,
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst, uint32 app_offset,
|
||||
uint32 *p_app_start_offset, uint32 *p_app_end_offset);
|
||||
|
||||
bool
|
||||
aot_get_native_addr_range(AOTModuleInstance *module_inst,
|
||||
uint8 *native_ptr,
|
||||
aot_get_native_addr_range(AOTModuleInstance *module_inst, uint8 *native_ptr,
|
||||
uint8 **p_native_start_addr,
|
||||
uint8 **p_native_end_addr);
|
||||
|
||||
|
@ -633,19 +626,18 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
|
|||
* @return true if equal, false otherwise
|
||||
*/
|
||||
bool
|
||||
aot_is_wasm_type_equal(AOTModuleInstance *module_inst,
|
||||
uint32 type1_idx, uint32 type2_idx);
|
||||
aot_is_wasm_type_equal(AOTModuleInstance *module_inst, uint32 type1_idx,
|
||||
uint32 type2_idx);
|
||||
|
||||
/**
|
||||
* Invoke native function from aot code
|
||||
*/
|
||||
bool
|
||||
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
|
||||
uint32 argc, uint32 *argv);
|
||||
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||
uint32 *argv);
|
||||
|
||||
bool
|
||||
aot_call_indirect(WASMExecEnv *exec_env,
|
||||
uint32 tbl_idx, uint32 table_elem_idx,
|
||||
aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
|
||||
uint32 argc, uint32 *argv);
|
||||
|
||||
uint32
|
||||
|
@ -659,8 +651,8 @@ aot_memset(void *s, int c, size_t n);
|
|||
|
||||
#if WASM_ENABLE_BULK_MEMORY != 0
|
||||
bool
|
||||
aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index,
|
||||
uint32 offset, uint32 len, uint32 dst);
|
||||
aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
|
||||
uint32 len, uint32 dst);
|
||||
|
||||
bool
|
||||
aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
|
||||
|
@ -668,12 +660,10 @@ aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
|
|||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
aot_set_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 start_offset, uint32 size);
|
||||
aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
|
||||
|
||||
bool
|
||||
aot_get_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 *start_offset, uint32 *size);
|
||||
aot_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
|
||||
#endif
|
||||
|
||||
#ifdef OS_ENABLE_HW_BOUND_CHECK
|
||||
|
@ -697,18 +687,18 @@ void
|
|||
aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
|
||||
|
||||
void
|
||||
aot_table_init(AOTModuleInstance *module_inst,
|
||||
uint32 tbl_idx, uint32 tbl_seg_idx,
|
||||
uint32 length, uint32 src_offset, uint32 dst_offset);
|
||||
aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
|
||||
uint32 dst_offset);
|
||||
|
||||
void
|
||||
aot_table_copy(AOTModuleInstance *module_inst,
|
||||
uint32 src_tbl_idx, uint32 dst_tbl_idx,
|
||||
uint32 length, uint32 src_offset, uint32 dst_offset);
|
||||
aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
|
||||
uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
|
||||
uint32 dst_offset);
|
||||
|
||||
void
|
||||
aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
uint32 length, uint32 val, uint32 data_offset);
|
||||
aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
|
||||
uint32 val, uint32 data_offset);
|
||||
|
||||
uint32
|
||||
aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
|
||||
|
@ -735,4 +725,3 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
|
|||
#endif
|
||||
|
||||
#endif /* end of _AOT_RUNTIME_H_ */
|
||||
|
||||
|
|
|
@ -33,9 +33,11 @@
|
|||
#define R_AARCH64_JUMP26 282
|
||||
#define R_AARCH64_CALL26 283
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
|
@ -92,7 +94,8 @@ init_plt_table(uint8 *plt)
|
|||
for (i = 0; i < num; i++) {
|
||||
uint32 *p = (uint32 *)plt;
|
||||
*p++ = 0xf81f0ffe; /* str x30, [sp, #-16]! */
|
||||
*p++ = 0x100000be; /* adr x30, #20 ;symbol addr is PC + 5 instructions below */
|
||||
*p++ = 0x100000be; /* adr x30, #20; symbol addr is PC + 5 instructions
|
||||
below */
|
||||
*p++ = 0xf94003de; /* ldr x30, [x30] */
|
||||
*p++ = 0xd63f03c0; /* blr x30 */
|
||||
*p++ = 0xf84107fe; /* ldr x30, [sp], #16 */
|
||||
|
@ -110,7 +113,8 @@ get_plt_table_size()
|
|||
return get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
}
|
||||
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) do { \
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) \
|
||||
do { \
|
||||
int64 m = (int64)((uint64)1 << (bits - 1)); \
|
||||
val_ext = ((int64)val ^ m) - m; \
|
||||
} while (0)
|
||||
|
@ -118,9 +122,9 @@ get_plt_table_size()
|
|||
#define Page(expr) ((expr) & ~0xFFF)
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -132,11 +136,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_CALL26:
|
||||
|
@ -164,7 +167,8 @@ apply_relocation(AOTModule *module,
|
|||
else {
|
||||
uint8 *plt;
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
|
@ -203,7 +207,8 @@ apply_relocation(AOTModule *module,
|
|||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm16;
|
||||
|
||||
|
@ -241,18 +246,22 @@ apply_relocation(AOTModule *module,
|
|||
switch (reloc_type) {
|
||||
case R_AARCH64_MOVW_UABS_G0:
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G1:
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G2:
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
|
@ -264,7 +273,8 @@ apply_relocation(AOTModule *module,
|
|||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, immhi19, immlo2, imm21;
|
||||
|
||||
|
@ -297,7 +307,8 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
|
@ -326,7 +337,8 @@ apply_relocation(AOTModule *module,
|
|||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
|
@ -347,19 +359,24 @@ apply_relocation(AOTModule *module,
|
|||
/* write the imm12 back to instruction */
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define R_ARC_32 4
|
||||
#define R_ARC_32_ME 27
|
||||
|
||||
/* clang-format off */
|
||||
void __st_r13_to_r15();
|
||||
void __st_r13_to_r16();
|
||||
void __st_r13_to_r17();
|
||||
|
@ -56,10 +57,13 @@ void __subdf3();
|
|||
void __subsf3();
|
||||
void __truncdfsf2();
|
||||
void __unorddf2();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__st_r13_to_r15),
|
||||
/* clang-format on */
|
||||
REG_SYM(__st_r13_to_r16),
|
||||
REG_SYM(__st_r13_to_r17),
|
||||
REG_SYM(__st_r13_to_r18),
|
||||
|
@ -103,7 +107,6 @@ static SymbolMap target_sym_map[] = {
|
|||
REG_SYM(__subsf3),
|
||||
REG_SYM(__truncdfsf2),
|
||||
REG_SYM(__unorddf2),
|
||||
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -139,9 +142,9 @@ init_plt_table(uint8 *plt)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -159,11 +162,10 @@ middle_endian_convert(uint32 insn)
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARC_S25W_PCREL:
|
||||
|
@ -212,8 +214,7 @@ apply_relocation(AOTModule *module,
|
|||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
|
||||
/* (S + A) */
|
||||
insn = (uint32)(uintptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend);
|
||||
insn = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
if (reloc_type == R_ARC_32_ME)
|
||||
/* Convert to middle endian */
|
||||
|
@ -234,4 +235,3 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define R_ARM_JMP24 29 /* PC relative 24 bit (B/BL<cond>). */
|
||||
#define R_ARM_ABS32 2 /* Direct 32 bit */
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
|
@ -54,11 +55,14 @@ void __aeabi_fcmple();
|
|||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__udivdi3),
|
||||
REG_SYM(__umoddi3),
|
||||
REG_SYM(__divsi3),
|
||||
|
@ -175,9 +179,9 @@ init_plt_table(uint8 *plt)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -189,11 +193,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_CALL:
|
||||
|
@ -203,8 +206,8 @@ apply_relocation(AOTModule *module,
|
|||
int32 RESULT_MASK = 0x03FFFFFE;
|
||||
int32 insn = *(int32 *)(target_section_addr + reloc_offset);
|
||||
/* Initial addend: sign_extend(insn[23:0] << 2) */
|
||||
int32 initial_addend = ((insn & 0xFFFFFF) << 2)
|
||||
| ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
int32 initial_addend =
|
||||
((insn & 0xFFFFFF) << 2) | ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
|
@ -214,14 +217,15 @@ apply_relocation(AOTModule *module,
|
|||
* Suppose the symbol address is in +-32MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 0 */
|
||||
result = (intptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T
|
||||
* is 0 */
|
||||
result = (intptr_t)((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
|
@ -232,11 +236,12 @@ apply_relocation(AOTModule *module,
|
|||
* beyond of the +-32MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 0 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is
|
||||
* 0 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
result = (intptr_t)
|
||||
(plt + reloc_addend
|
||||
result = (intptr_t)(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
|
@ -251,8 +256,7 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
|
||||
*(int32 *)(target_section_addr + reloc_offset) =
|
||||
(int32)
|
||||
((insn & 0xff000000)
|
||||
(int32)((insn & 0xff000000)
|
||||
| (((int32)result & RESULT_MASK) >> 2));
|
||||
break;
|
||||
}
|
||||
|
@ -261,9 +265,10 @@ apply_relocation(AOTModule *module,
|
|||
intptr_t initial_addend;
|
||||
/* (S + A) | T where T is 0 */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
initial_addend = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
initial_addend =
|
||||
*(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -278,4 +283,3 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
SymbolMap *
|
||||
get_target_symbol_map(uint32 *sym_num)
|
||||
|
@ -44,11 +46,10 @@ get_plt_table_size()
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
/* TODO: implement relocation for mips */
|
||||
|
@ -66,4 +67,3 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,15 +15,19 @@
|
|||
|
||||
#define RV_OPCODE_SW 0x23
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __moddi3();
|
||||
void __muldi3();
|
||||
void __udivdi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__moddi3),
|
||||
REG_SYM(__muldi3),
|
||||
REG_SYM(__udivdi3),
|
||||
|
@ -159,15 +163,15 @@ typedef struct RelocTypeStrMap {
|
|||
char *reloc_str;
|
||||
} RelocTypeStrMap;
|
||||
|
||||
#define RELOC_TYPE_MAP(reloc_type) { reloc_type, #reloc_type }
|
||||
#define RELOC_TYPE_MAP(reloc_type) \
|
||||
{ \
|
||||
reloc_type, #reloc_type \
|
||||
}
|
||||
|
||||
static RelocTypeStrMap reloc_type_str_maps[] = {
|
||||
RELOC_TYPE_MAP(R_RISCV_32),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT),
|
||||
RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT), RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
};
|
||||
|
||||
static const char *
|
||||
|
@ -175,7 +179,8 @@ reloc_type_to_str(uint32 reloc_type)
|
|||
{
|
||||
uint32 i;
|
||||
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap); i++) {
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap);
|
||||
i++) {
|
||||
if (reloc_type_str_maps[i].reloc_type == reloc_type)
|
||||
return reloc_type_str_maps[i].reloc_str;
|
||||
}
|
||||
|
@ -184,9 +189,9 @@ reloc_type_to_str(uint32 reloc_type)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -198,11 +203,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend, uint32 reloc_type,
|
||||
void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
int32 val, imm_hi, imm_lo, insn;
|
||||
uint8 *addr = target_section_addr + reloc_offset;
|
||||
|
@ -211,7 +215,8 @@ apply_relocation(AOTModule *module,
|
|||
switch (reloc_type) {
|
||||
case R_RISCV_32:
|
||||
{
|
||||
uint32 val_32 = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint32 val_32 =
|
||||
(uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(uint32));
|
||||
if (val_32 != (uintptr_t)((uint8 *)symbol_addr + reloc_addend)) {
|
||||
|
@ -223,7 +228,8 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
case R_RISCV_64:
|
||||
{
|
||||
uint64 val_64 = (uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint64 val_64 =
|
||||
(uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
CHECK_RELOC_OFFSET(sizeof(uint64));
|
||||
bh_memcpy_s(addr, 8, &val_64, 8);
|
||||
break;
|
||||
|
@ -253,8 +259,8 @@ apply_relocation(AOTModule *module,
|
|||
rv_add_val((uint16 *)addr, (imm_hi << 12));
|
||||
if ((rv_get_val((uint16 *)(addr + 4)) & 0x7f) == RV_OPCODE_SW) {
|
||||
/* Adjust imm for SW : S-type */
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25)
|
||||
+ (((int32)imm_lo & 0x1f) << 7);
|
||||
|
||||
rv_add_val((uint16 *)(addr + 4), val);
|
||||
}
|
||||
|
@ -310,8 +316,7 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
addr = target_section_addr + reloc_offset;
|
||||
rv_calc_imm(val, &imm_hi, &imm_lo);
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
rv_add_val((uint16 *)addr, val);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define R_ARM_THM_CALL 10 /* PC relative (Thumb BL and ARMv5 Thumb BLX). */
|
||||
#define R_ARM_THM_JMP24 30 /* B.W */
|
||||
|
||||
/* clang-format off */
|
||||
void __ltdf2();
|
||||
void __adddf3();
|
||||
void __eqdf2();
|
||||
|
@ -69,11 +70,14 @@ void __aeabi_fcmple();
|
|||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__ltdf2),
|
||||
/* clang-format on */
|
||||
REG_SYM(__adddf3),
|
||||
REG_SYM(__eqdf2),
|
||||
REG_SYM(__unorddf2),
|
||||
|
@ -218,9 +222,9 @@ init_plt_table(uint8 *plt)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -232,11 +236,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_THM_CALL:
|
||||
|
@ -263,13 +266,17 @@ apply_relocation(AOTModule *module,
|
|||
* Suppose the symbol address is in +-4MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 1 */
|
||||
result = (int32)(((intptr_t)((uint8*)symbol_addr + reloc_addend) | 1)
|
||||
/* operation: ((S + A) | T) - P where S is symbol address
|
||||
and T is 1 */
|
||||
result =
|
||||
(int32)(((intptr_t)((uint8 *)symbol_addr + reloc_addend)
|
||||
| 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
|
@ -280,10 +287,13 @@ apply_relocation(AOTModule *module,
|
|||
* beyond of the +-4MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 1 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address
|
||||
and T is 1 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index + 1;
|
||||
result = (int32)(((intptr_t)plt | 1)
|
||||
result =
|
||||
(int32)(((intptr_t)plt | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
|
@ -316,4 +326,3 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
#define R_386_PC32 2 /* PC relative 32 bit */
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN32_)
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
#else
|
||||
#pragma function(floor)
|
||||
#pragma function(ceil)
|
||||
|
@ -42,6 +44,7 @@ __umoddi3(uint64 a, uint64 b)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
|
@ -50,6 +53,7 @@ static SymbolMap target_sym_map[] = {
|
|||
REG_SYM(__moddi3),
|
||||
REG_SYM(__umoddi3)
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
|
@ -84,9 +88,9 @@ init_plt_table(uint8 *plt)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -98,11 +102,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_386_32:
|
||||
|
@ -111,8 +114,8 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -122,8 +125,8 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(int32 *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint32*)(target_section_addr + (uint32)reloc_offset) = (uint32)
|
||||
((uint8*)symbol_addr + (uint32)reloc_addend
|
||||
*(uint32 *)(target_section_addr + (uint32)reloc_offset) =
|
||||
(uint32)((uint8 *)symbol_addr + (uint32)reloc_addend
|
||||
- (uint8 *)(target_section_addr + (uint32)reloc_offset)
|
||||
+ value); /* S + A - P */
|
||||
break;
|
||||
|
@ -139,4 +142,3 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
#ifndef IMAGE_REL_AMD64_ADDR64
|
||||
#define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */
|
||||
#define IMAGE_REL_AMD64_ADDR32 2 /* The 32-bit VA of the relocation target */
|
||||
/* clang-format off */
|
||||
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
|
||||
the byte following the relocation*/
|
||||
/* clang-format on */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -27,9 +29,11 @@
|
|||
#pragma function(ceilf)
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
|
@ -61,8 +65,8 @@ get_plt_item_size()
|
|||
uint32
|
||||
get_plt_table_size()
|
||||
{
|
||||
uint32 size = get_plt_item_size()
|
||||
* (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
uint32 size =
|
||||
get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||
size += get_plt_item_size() + sizeof(AOTUnwindInfo);
|
||||
#endif
|
||||
|
@ -102,9 +106,9 @@ init_plt_table(uint8 *plt)
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -116,11 +120,10 @@ check_reloc_offset(uint32 target_section_size,
|
|||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
|
@ -133,8 +136,8 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
|
@ -147,10 +150,10 @@ apply_relocation(AOTModule *module,
|
|||
value = *(int32 *)(target_section_addr + (uint32)reloc_offset);
|
||||
target_addr = (uintptr_t)symbol_addr + reloc_addend + value;
|
||||
if ((int32)target_addr != target_addr) {
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. "
|
||||
"relocation truncated to fit "
|
||||
"IMAGE_REL_AMD64_ADDR32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
|
@ -168,7 +171,8 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
if ((int32)target_addr != target_addr) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit R_X86_64_PC32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
|
@ -195,8 +199,8 @@ apply_relocation(AOTModule *module,
|
|||
"AOT module load failed: "
|
||||
"relocation truncated to fit %s failed. "
|
||||
"Try using wamrc with --size-level=1 option.",
|
||||
reloc_type == R_X86_64_32
|
||||
? "R_X86_64_32" : "R_X86_64_32S");
|
||||
reloc_type == R_X86_64_32 ? "R_X86_64_32"
|
||||
: "R_X86_64_32S");
|
||||
set_error_buf(error_buf, error_buf_size, buf);
|
||||
return false;
|
||||
}
|
||||
|
@ -217,11 +221,11 @@ apply_relocation(AOTModule *module,
|
|||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
if (symbol_index >= 0) {
|
||||
plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
(plt + reloc_addend - (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
|
@ -259,4 +263,3 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define R_XTENSA_32 1 /* Direct 32 bit */
|
||||
#define R_XTENSA_SLOT0_OP 20 /* PC relative */
|
||||
|
||||
/* clang-format off */
|
||||
/* for soft-float */
|
||||
void __floatsidf();
|
||||
void __divdf3();
|
||||
|
@ -38,9 +39,9 @@ static SymbolMap target_sym_map[] = {
|
|||
REG_SYM(__muldi3),
|
||||
|
||||
REG_SYM(__modsi3),
|
||||
|
||||
REG_SYM(__divdi3),
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
|
@ -81,9 +82,9 @@ get_plt_table_size()
|
|||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
|
@ -142,11 +143,10 @@ typedef union {
|
|||
} l32r_insn_t;
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_XTENSA_32:
|
||||
|
@ -162,15 +162,16 @@ apply_relocation(AOTModule *module,
|
|||
}
|
||||
CHECK_RELOC_OFFSET(4);
|
||||
initial_addend = *(int32 *)insn_addr;
|
||||
*(uint8**)insn_addr
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
*(uint8 **)insn_addr =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
case R_XTENSA_SLOT0_OP:
|
||||
{
|
||||
uint8 *insn_addr = target_section_addr + reloc_offset;
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP relocation */
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP
|
||||
* relocation */
|
||||
l32r_insn_t *l32r_insn = (l32r_insn_t *)insn_addr;
|
||||
uint8 *reloc_addr;
|
||||
int32 relative_offset /*, initial_addend */;
|
||||
|
@ -193,9 +194,9 @@ apply_relocation(AOTModule *module,
|
|||
return false;
|
||||
}
|
||||
|
||||
relative_offset = (int32)
|
||||
((intptr_t)reloc_addr -
|
||||
(((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
relative_offset =
|
||||
(int32)((intptr_t)reloc_addr
|
||||
- (((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
/* relative_offset += initial_addend; */
|
||||
|
||||
/* check relative offset boundary */
|
||||
|
@ -228,4 +229,3 @@ apply_relocation(AOTModule *module,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,8 +118,9 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
|
|||
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
|
||||
*offset = sh_table[i]->sh_offset;
|
||||
*size = sh_table[i]->sh_size;
|
||||
sh_table[i]->sh_addr = (Elf64_Addr)(uintptr_t)
|
||||
((char *)buf + sh_table[i]->sh_offset);
|
||||
sh_table[i]->sh_addr =
|
||||
(Elf64_Addr)(uintptr_t)((char *)buf
|
||||
+ sh_table[i]->sh_offset);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
|
@ -138,8 +139,9 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
|
|||
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
|
||||
*offset = sh_table[i]->sh_offset;
|
||||
*size = sh_table[i]->sh_size;
|
||||
sh_table[i]->sh_addr = (Elf32_Addr)(uintptr_t)
|
||||
((char *)buf + sh_table[i]->sh_offset);
|
||||
sh_table[i]->sh_addr =
|
||||
(Elf32_Addr)(uintptr_t)((char *)buf
|
||||
+ sh_table[i]->sh_offset);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "bh_log.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_runtime.h"
|
||||
#include "../../interpreter/wasm_runtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
@ -35,11 +35,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
/* clang-format off */
|
||||
typedef enum JITAction {
|
||||
JIT_NOACTION = 0,
|
||||
JIT_REGISTER_FN,
|
||||
JIT_UNREGISTER_FN
|
||||
} JITAction;
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct JITCodeEntry {
|
||||
struct JITCodeEntry *next_;
|
||||
|
@ -78,7 +80,8 @@ void __attribute__((noinline)) __jit_debug_register_code()
|
|||
|
||||
JITDescriptor __jit_debug_descriptor = { 1, JIT_NOACTION, NULL, NULL };
|
||||
#else
|
||||
extern void __jit_debug_register_code();
|
||||
extern void
|
||||
__jit_debug_register_code();
|
||||
extern JITDescriptor __jit_debug_descriptor;
|
||||
#endif
|
||||
|
||||
|
@ -168,8 +171,7 @@ jit_debug_engine_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!(jit_debug_engine =
|
||||
wasm_runtime_malloc(sizeof(WASMJITDebugEngine)))) {
|
||||
if (!(jit_debug_engine = wasm_runtime_malloc(sizeof(WASMJITDebugEngine)))) {
|
||||
LOG_ERROR("WASM JIT Debug Engine error: failed to allocate memory");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#include "../wasm_runtime_common.h"
|
||||
#include "../wasm_exec_env.h"
|
||||
|
||||
void invokeNative(void (*native_code)(), uint32 argv[], uint32 argc)
|
||||
void
|
||||
invokeNative(void (*native_code)(), uint32 argv[], uint32 argc)
|
||||
{
|
||||
bh_assert(argc >= sizeof(WASMExecEnv *) / sizeof(uint32));
|
||||
|
||||
|
@ -33,53 +34,80 @@ void invokeNative(void (*native_code)(), uint32 argv[], uint32 argc)
|
|||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
||||
break;
|
||||
case 7:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6]);
|
||||
break;
|
||||
case 8:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7]);
|
||||
break;
|
||||
case 9:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8]);
|
||||
break;
|
||||
case 10:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9]);
|
||||
break;
|
||||
case 11:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10]);
|
||||
break;
|
||||
case 12:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]);
|
||||
break;
|
||||
case 13:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12]);
|
||||
break;
|
||||
case 14:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13]);
|
||||
break;
|
||||
case 15:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14]);
|
||||
break;
|
||||
case 16:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15]);
|
||||
break;
|
||||
case 17:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15], argv[16]);
|
||||
break;
|
||||
case 18:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16], argv[17]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15], argv[16],
|
||||
argv[17]);
|
||||
break;
|
||||
case 19:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16], argv[17], argv[18]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15], argv[16],
|
||||
argv[17], argv[18]);
|
||||
break;
|
||||
case 20:
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16], argv[17], argv[18], argv[19]);
|
||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15], argv[16],
|
||||
argv[17], argv[18], argv[19]);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
/* FIXME: If this happen, add more cases. */
|
||||
WASMExecEnv *exec_env = *(WASMExecEnv **)argv;
|
||||
WASMModuleInstanceCommon *module_inst = exec_env->module_inst;
|
||||
wasm_runtime_set_exception(module_inst, "the argument number of native function exceeds maximum");
|
||||
wasm_runtime_set_exception(
|
||||
module_inst,
|
||||
"the argument number of native function exceeds maximum");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,12 @@ runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
|
|||
{
|
||||
void *mem;
|
||||
|
||||
if (size >= UINT32_MAX
|
||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||
if (size >= UINT32_MAX || !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||
if (module_inst != NULL) {
|
||||
wasm_runtime_set_exception(module_inst,
|
||||
"allocate memory failed");
|
||||
wasm_runtime_set_exception(module_inst, "allocate memory failed");
|
||||
}
|
||||
else if (error_buf != NULL) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"allocate memory failed");
|
||||
set_error_buf(error_buf, error_buf_size, "allocate memory failed");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -53,28 +50,30 @@ static union {
|
|||
*/
|
||||
|
||||
static WASMFunctionInstanceCommon *
|
||||
resolve_function(const WASMModuleInstanceCommon *module_inst,
|
||||
const char *name);
|
||||
resolve_function(const WASMModuleInstanceCommon *module_inst, const char *name);
|
||||
|
||||
static bool
|
||||
check_main_func_type(const WASMType *type)
|
||||
{
|
||||
if (!(type->param_count == 0 || type->param_count == 2)
|
||||
|| type->result_count > 1) {
|
||||
LOG_ERROR("WASM execute application failed: invalid main function type.\n");
|
||||
LOG_ERROR(
|
||||
"WASM execute application failed: invalid main function type.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type->param_count == 2
|
||||
&& !(type->types[0] == VALUE_TYPE_I32
|
||||
&& type->types[1] == VALUE_TYPE_I32)) {
|
||||
LOG_ERROR("WASM execute application failed: invalid main function type.\n");
|
||||
LOG_ERROR(
|
||||
"WASM execute application failed: invalid main function type.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type->result_count
|
||||
&& type->types[type->param_count] != VALUE_TYPE_I32) {
|
||||
LOG_ERROR("WASM execute application failed: invalid main function type.\n");
|
||||
LOG_ERROR(
|
||||
"WASM execute application failed: invalid main function type.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -82,8 +81,8 @@ check_main_func_type(const WASMType *type)
|
|||
}
|
||||
|
||||
bool
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||
int32 argc, char *argv[])
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
|
||||
char *argv[])
|
||||
{
|
||||
WASMFunctionInstanceCommon *func;
|
||||
WASMType *func_type = NULL;
|
||||
|
@ -103,9 +102,9 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
the actual main function. Directly call main function
|
||||
may cause exception thrown. */
|
||||
if ((func = wasm_runtime_lookup_wasi_start_function(module_inst)))
|
||||
return wasm_runtime_create_exec_env_and_call_wasm(
|
||||
module_inst, func, 0, NULL);
|
||||
/* if no start function is found, we execute
|
||||
return wasm_runtime_create_exec_env_and_call_wasm(module_inst, func,
|
||||
0, NULL);
|
||||
/* If no start function was found, we execute
|
||||
the main function as normal */
|
||||
}
|
||||
#endif /* end of WASM_ENABLE_LIBC_WASI */
|
||||
|
@ -113,8 +112,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
if (!(func = resolve_function(module_inst, "main"))
|
||||
&& !(func = resolve_function(module_inst, "__main_argc_argv"))
|
||||
&& !(func = resolve_function(module_inst, "_main"))) {
|
||||
wasm_runtime_set_exception(module_inst,
|
||||
"lookup main function failed");
|
||||
wasm_runtime_set_exception(module_inst, "lookup main function failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -130,8 +128,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
#endif
|
||||
|
||||
if (is_import_func) {
|
||||
wasm_runtime_set_exception(module_inst,
|
||||
"lookup main function failed");
|
||||
wasm_runtime_set_exception(module_inst, "lookup main function failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -157,11 +154,9 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
total_size = (uint64)total_argv_size + sizeof(int32) * (uint64)argc;
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(argv_buf_offset =
|
||||
wasm_runtime_module_malloc(module_inst, (uint32)total_size,
|
||||
(void**)&argv_buf))) {
|
||||
wasm_runtime_set_exception(module_inst,
|
||||
"allocate memory failed");
|
||||
|| !(argv_buf_offset = wasm_runtime_module_malloc(
|
||||
module_inst, (uint32)total_size, (void **)&argv_buf))) {
|
||||
wasm_runtime_set_exception(module_inst, "allocate memory failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -170,18 +165,20 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
p_end = p + total_size;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
bh_memcpy_s(p, (uint32)(p_end - p), argv[i], (uint32)(strlen(argv[i]) + 1));
|
||||
bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
|
||||
(uint32)(strlen(argv[i]) + 1));
|
||||
argv_offsets[i] = argv_buf_offset + (uint32)(p - argv_buf);
|
||||
p += strlen(argv[i]) + 1;
|
||||
}
|
||||
|
||||
argc1 = 2;
|
||||
argv1[0] = (uint32)argc;
|
||||
argv1[1] = (uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
|
||||
argv1[1] =
|
||||
(uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
|
||||
}
|
||||
|
||||
ret = wasm_runtime_create_exec_env_and_call_wasm(module_inst, func,
|
||||
argc1, argv1);
|
||||
ret = wasm_runtime_create_exec_env_and_call_wasm(module_inst, func, argc1,
|
||||
argv1);
|
||||
if (ret && func_type->result_count > 0 && argc > 0 && argv)
|
||||
/* copy the return value */
|
||||
*(int *)argv = (int)argv1[0];
|
||||
|
@ -242,8 +239,7 @@ parse_function_name(char *orig_function_name, char **p_module_name,
|
|||
*/
|
||||
|
||||
static WASMFunctionInstanceCommon *
|
||||
resolve_function(const WASMModuleInstanceCommon *module_inst,
|
||||
const char *name)
|
||||
resolve_function(const WASMModuleInstanceCommon *module_inst, const char *name)
|
||||
{
|
||||
uint32 i = 0;
|
||||
WASMFunctionInstanceCommon *ret = NULL;
|
||||
|
@ -268,8 +264,8 @@ resolve_function(const WASMModuleInstanceCommon *module_inst,
|
|||
LOG_DEBUG("%s -> %s and %s", name, sub_module_name, function_name);
|
||||
|
||||
if (sub_module_name) {
|
||||
sub_module_inst = get_sub_module_inst(
|
||||
(WASMModuleInstance *)module_inst, sub_module_name);
|
||||
sub_module_inst = get_sub_module_inst((WASMModuleInstance *)module_inst,
|
||||
sub_module_name);
|
||||
if (!sub_module_inst) {
|
||||
LOG_DEBUG("can not find a sub module named %s", sub_module_name);
|
||||
goto LEAVE;
|
||||
|
@ -299,8 +295,8 @@ resolve_function(const WASMModuleInstanceCommon *module_inst,
|
|||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst;
|
||||
AOTFunctionInstance *export_funcs = (AOTFunctionInstance *)
|
||||
aot_inst->export_funcs.ptr;
|
||||
AOTFunctionInstance *export_funcs =
|
||||
(AOTFunctionInstance *)aot_inst->export_funcs.ptr;
|
||||
for (i = 0; i < aot_inst->export_func_count; i++) {
|
||||
if (!strcmp(export_funcs[i].func_name, function_name)) {
|
||||
ret = &export_funcs[i];
|
||||
|
@ -404,8 +400,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
}
|
||||
|
||||
if (type->param_count != (uint32)argc) {
|
||||
wasm_runtime_set_exception(module_inst,
|
||||
"invalid input argument count");
|
||||
wasm_runtime_set_exception(module_inst, "invalid input argument count");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -413,8 +408,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
cell_num = (argc1 > type->ret_cell_num) ? argc1 : type->ret_cell_num;
|
||||
|
||||
total_size = sizeof(uint32) * (uint64)(cell_num > 2 ? cell_num : 2);
|
||||
if ((!(argv1 = runtime_malloc((uint32)total_size, module_inst,
|
||||
NULL, 0)))) {
|
||||
if ((!(argv1 = runtime_malloc((uint32)total_size, module_inst, NULL, 0)))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -433,7 +427,10 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
{
|
||||
union { uint64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
uint64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.val = strtoull(argv[i], &endptr, 0);
|
||||
argv1[p++] = u.parts[0];
|
||||
argv1[p++] = u.parts[1];
|
||||
|
@ -469,7 +466,10 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
}
|
||||
case VALUE_TYPE_F64:
|
||||
{
|
||||
union { float64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
float64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.val = strtod(argv[i], &endptr);
|
||||
if (isnan(u.val)) {
|
||||
if (argv[i][0] == '-') {
|
||||
|
@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
break;
|
||||
}
|
||||
if (endptr && *endptr != '\0' && *endptr != '_') {
|
||||
snprintf(buf, sizeof(buf), "invalid input argument %d: %s",
|
||||
i, argv[i]);
|
||||
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
|
||||
argv[i]);
|
||||
wasm_runtime_set_exception(module_inst, buf);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -563,8 +563,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
bh_assert(p == (int32)argc1);
|
||||
|
||||
wasm_runtime_set_exception(module_inst, NULL);
|
||||
if (!wasm_runtime_create_exec_env_and_call_wasm(module_inst, func,
|
||||
argc1, argv1)) {
|
||||
if (!wasm_runtime_create_exec_env_and_call_wasm(module_inst, func, argc1,
|
||||
argv1)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -579,7 +579,10 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
}
|
||||
case VALUE_TYPE_I64:
|
||||
{
|
||||
union { uint64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
uint64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.parts[0] = argv1[k];
|
||||
u.parts[1] = argv1[k + 1];
|
||||
k += 2;
|
||||
|
@ -603,7 +606,10 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
}
|
||||
case VALUE_TYPE_F64:
|
||||
{
|
||||
union { float64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
float64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.parts[0] = argv1[k];
|
||||
u.parts[1] = argv1[k + 1];
|
||||
k += 2;
|
||||
|
@ -640,7 +646,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
|||
{
|
||||
uint64 *v = (uint64 *)(argv1 + k);
|
||||
#if defined(PRIx64)
|
||||
os_printf("<0x%016"PRIx64" 0x%016"PRIx64">:v128", *v, *(v + 1));
|
||||
os_printf("<0x%016" PRIx64 " 0x%016" PRIx64 ">:v128", *v,
|
||||
*(v + 1));
|
||||
#else
|
||||
if (4 == sizeof(long)) {
|
||||
os_printf("<0x%016llx 0x%016llx>:v128", *v, *(v + 1));
|
||||
|
|
|
@ -166,8 +166,7 @@ failed: \
|
|||
return; \
|
||||
} \
|
||||
\
|
||||
if (!bh_vector_init((Vector *)out, size, \
|
||||
sizeof(wasm_##name##_t *))) { \
|
||||
if (!bh_vector_init((Vector *)out, size, sizeof(wasm_##name##_t *))) { \
|
||||
LOG_DEBUG("bh_vector_init failed"); \
|
||||
goto failed; \
|
||||
} \
|
||||
|
@ -241,13 +240,9 @@ void
|
|||
aot_compile_wasm_file_destroy();
|
||||
|
||||
uint8 *
|
||||
aot_compile_wasm_file(const uint8 *wasm_file_buf,
|
||||
uint32 wasm_file_size,
|
||||
uint32 opt_level,
|
||||
uint32 size_level,
|
||||
char *error_buf,
|
||||
uint32 error_buf_size,
|
||||
uint32 *p_aot_file_size);
|
||||
aot_compile_wasm_file(const uint8 *wasm_file_buf, uint32 wasm_file_size,
|
||||
uint32 opt_level, uint32 size_level, char *error_buf,
|
||||
uint32 error_buf_size, uint32 *p_aot_file_size);
|
||||
#endif
|
||||
|
||||
/* Runtime Environment */
|
||||
|
@ -550,7 +545,8 @@ wasm_functype_new_internal(WASMType *type_rt)
|
|||
}
|
||||
}
|
||||
|
||||
/* WASMType->types[type_rt->param_count : type_rt->result_count) -> type->results */
|
||||
/* WASMType->types[type_rt->param_count : type_rt->result_count) ->
|
||||
* type->results */
|
||||
INIT_VEC(type->results, wasm_valtype_vec_new_uninitialized,
|
||||
type_rt->result_count);
|
||||
for (i = 0; i < type_rt->result_count; ++i) {
|
||||
|
@ -774,8 +770,7 @@ wasm_globaltype_mutability(const wasm_globaltype_t *global_type)
|
|||
}
|
||||
|
||||
static wasm_tabletype_t *
|
||||
wasm_tabletype_new_internal(uint8 val_type_rt,
|
||||
uint32 init_size,
|
||||
wasm_tabletype_new_internal(uint8 val_type_rt, uint32 init_size,
|
||||
uint32 max_size)
|
||||
{
|
||||
wasm_tabletype_t *table_type;
|
||||
|
@ -942,8 +937,7 @@ wasm_externtype_kind(const wasm_externtype_t *extern_type)
|
|||
V(tabletype)
|
||||
|
||||
#define WASM_EXTERNTYPE_AS_OTHERTYPE(name) \
|
||||
wasm_##name##_t *wasm_externtype_as_##name( \
|
||||
wasm_externtype_t *extern_type) \
|
||||
wasm_##name##_t *wasm_externtype_as_##name(wasm_externtype_t *extern_type) \
|
||||
{ \
|
||||
return (wasm_##name##_t *)extern_type; \
|
||||
}
|
||||
|
@ -1031,8 +1025,7 @@ wasm_externtype_delete(wasm_externtype_t *extern_type)
|
|||
wasm_tabletype_delete(wasm_externtype_as_tabletype(extern_type));
|
||||
break;
|
||||
default:
|
||||
LOG_WARNING("%s meets unsupported type", __FUNCTION__,
|
||||
extern_type);
|
||||
LOG_WARNING("%s meets unsupported type", __FUNCTION__, extern_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1298,10 +1291,8 @@ rt_val_to_wasm_val(const uint8 *data, uint8 val_type_rt, wasm_val_t *out)
|
|||
}
|
||||
|
||||
bool
|
||||
wasm_val_to_rt_val(WASMModuleInstanceCommon *inst_comm_rt,
|
||||
uint8 val_type_rt,
|
||||
const wasm_val_t *v,
|
||||
uint8 *data)
|
||||
wasm_val_to_rt_val(WASMModuleInstanceCommon *inst_comm_rt, uint8 val_type_rt,
|
||||
const wasm_val_t *v, uint8 *data)
|
||||
{
|
||||
bool ret = true;
|
||||
switch (val_type_rt) {
|
||||
|
@ -1338,10 +1329,8 @@ wasm_val_to_rt_val(WASMModuleInstanceCommon *inst_comm_rt,
|
|||
}
|
||||
|
||||
wasm_ref_t *
|
||||
wasm_ref_new_internal(wasm_store_t *store,
|
||||
enum wasm_reference_kind kind,
|
||||
uint32 ref_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
wasm_ref_new_internal(wasm_store_t *store, enum wasm_reference_kind kind,
|
||||
uint32 ref_idx_rt, WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_ref_t *ref;
|
||||
|
||||
|
@ -1456,8 +1445,7 @@ wasm_ref_delete(own wasm_ref_t *ref)
|
|||
} \
|
||||
\
|
||||
return wasm_ref_new_internal(name->store, WASM_REF_##name, \
|
||||
name->name##_idx_rt, \
|
||||
name->inst_comm_rt); \
|
||||
name->name##_idx_rt, name->inst_comm_rt); \
|
||||
} \
|
||||
\
|
||||
const wasm_ref_t *wasm_##name##_as_ref_const(const wasm_##name##_t *name) \
|
||||
|
@ -1467,8 +1455,7 @@ wasm_ref_delete(own wasm_ref_t *ref)
|
|||
} \
|
||||
\
|
||||
return wasm_ref_new_internal(name->store, WASM_REF_##name, \
|
||||
name->name##_idx_rt, \
|
||||
name->inst_comm_rt); \
|
||||
name->name##_idx_rt, name->inst_comm_rt); \
|
||||
} \
|
||||
\
|
||||
wasm_##name##_t *wasm_ref_as_##name(wasm_ref_t *ref) \
|
||||
|
@ -1499,10 +1486,8 @@ WASM_DEFINE_REF(memory)
|
|||
WASM_DEFINE_REF(table)
|
||||
|
||||
static wasm_frame_t *
|
||||
wasm_frame_new(wasm_instance_t *instance,
|
||||
size_t module_offset,
|
||||
uint32 func_index,
|
||||
size_t func_offset)
|
||||
wasm_frame_new(wasm_instance_t *instance, size_t module_offset,
|
||||
uint32 func_index, size_t func_offset)
|
||||
{
|
||||
wasm_frame_t *frame;
|
||||
|
||||
|
@ -1756,8 +1741,7 @@ failed:
|
|||
}
|
||||
|
||||
wasm_foreign_t *
|
||||
wasm_foreign_new_internal(wasm_store_t *store,
|
||||
uint32 foreign_idx_rt,
|
||||
wasm_foreign_new_internal(wasm_store_t *store, uint32 foreign_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_foreign_t *foreign = NULL;
|
||||
|
@ -1857,7 +1841,8 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
|
|||
|
||||
pkg_type = get_package_type((uint8 *)binary->data, (uint32)binary->size);
|
||||
|
||||
/* whether the combination of compilation flags are compatable with the package type */
|
||||
/* whether the combination of compilation flags are compatable with the
|
||||
* package type */
|
||||
{
|
||||
bool result = false;
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
|
@ -1935,8 +1920,8 @@ wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary)
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((module_rt = wasm_runtime_load(
|
||||
(uint8 *)binary->data, (uint32)binary->size, error_buf, 128))) {
|
||||
if ((module_rt = wasm_runtime_load((uint8 *)binary->data,
|
||||
(uint32)binary->size, error_buf, 128))) {
|
||||
wasm_runtime_unload(module_rt);
|
||||
return true;
|
||||
}
|
||||
|
@ -1973,12 +1958,10 @@ wasm_module_delete(wasm_module_t *module)
|
|||
}
|
||||
|
||||
void
|
||||
wasm_module_imports(const wasm_module_t *module,
|
||||
own wasm_importtype_vec_t *out)
|
||||
wasm_module_imports(const wasm_module_t *module, own wasm_importtype_vec_t *out)
|
||||
{
|
||||
uint32 i, import_func_count = 0, import_memory_count = 0,
|
||||
import_global_count = 0, import_table_count = 0,
|
||||
import_count = 0;
|
||||
import_global_count = 0, import_table_count = 0, import_count = 0;
|
||||
wasm_byte_vec_t module_name = { 0 }, name = { 0 };
|
||||
wasm_externtype_t *extern_type = NULL;
|
||||
wasm_importtype_t *import_type = NULL;
|
||||
|
@ -2081,8 +2064,8 @@ wasm_module_imports(const wasm_module_t *module,
|
|||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if ((*module)->module_type == Wasm_Module_AoT) {
|
||||
AOTImportGlobal *import =
|
||||
MODULE_AOT(module)->import_globals + (i - import_func_count);
|
||||
AOTImportGlobal *import = MODULE_AOT(module)->import_globals
|
||||
+ (i - import_func_count);
|
||||
module_name_rt = import->module_name;
|
||||
field_name_rt = import->global_name;
|
||||
val_type_rt = import->type;
|
||||
|
@ -2277,7 +2260,8 @@ wasm_module_exports(const wasm_module_t *module, wasm_exporttype_vec_t *out)
|
|||
goto failed;
|
||||
}
|
||||
|
||||
/* WASMExport -> (WASMType, (uint8, bool)) -> (wasm_functype_t, wasm_globaltype_t) -> wasm_externtype_t*/
|
||||
/* WASMExport -> (WASMType, (uint8, bool)) -> (wasm_functype_t,
|
||||
* wasm_globaltype_t) -> wasm_externtype_t*/
|
||||
switch (export->kind) {
|
||||
case EXPORT_KIND_FUNC:
|
||||
{
|
||||
|
@ -2344,8 +2328,8 @@ wasm_module_exports(const wasm_module_t *module, wasm_exporttype_vec_t *out)
|
|||
goto failed;
|
||||
}
|
||||
|
||||
if (!(type = wasm_tabletype_new_internal(
|
||||
elem_type_rt, min_size, max_size))) {
|
||||
if (!(type = wasm_tabletype_new_internal(elem_type_rt, min_size,
|
||||
max_size))) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
@ -2380,8 +2364,7 @@ failed_exporttype_new:
|
|||
}
|
||||
|
||||
static wasm_func_t *
|
||||
wasm_func_new_basic(wasm_store_t *store,
|
||||
const wasm_functype_t *type,
|
||||
wasm_func_new_basic(wasm_store_t *store, const wasm_functype_t *type,
|
||||
wasm_func_callback_t func_callback)
|
||||
{
|
||||
wasm_func_t *func = NULL;
|
||||
|
@ -2404,10 +2387,8 @@ wasm_func_new_basic(wasm_store_t *store,
|
|||
}
|
||||
|
||||
static wasm_func_t *
|
||||
wasm_func_new_with_env_basic(wasm_store_t *store,
|
||||
const wasm_functype_t *type,
|
||||
wasm_func_callback_with_env_t callback,
|
||||
void *env,
|
||||
wasm_func_new_with_env_basic(wasm_store_t *store, const wasm_functype_t *type,
|
||||
wasm_func_callback_with_env_t callback, void *env,
|
||||
void (*finalizer)(void *))
|
||||
{
|
||||
wasm_func_t *func = NULL;
|
||||
|
@ -2432,8 +2413,7 @@ wasm_func_new_with_env_basic(wasm_store_t *store,
|
|||
}
|
||||
|
||||
wasm_func_t *
|
||||
wasm_func_new(wasm_store_t *store,
|
||||
const wasm_functype_t *type,
|
||||
wasm_func_new(wasm_store_t *store, const wasm_functype_t *type,
|
||||
wasm_func_callback_t callback)
|
||||
{
|
||||
bh_assert(singleton_engine);
|
||||
|
@ -2441,10 +2421,8 @@ wasm_func_new(wasm_store_t *store,
|
|||
}
|
||||
|
||||
wasm_func_t *
|
||||
wasm_func_new_with_env(wasm_store_t *store,
|
||||
const wasm_functype_t *type,
|
||||
wasm_func_callback_with_env_t callback,
|
||||
void *env,
|
||||
wasm_func_new_with_env(wasm_store_t *store, const wasm_functype_t *type,
|
||||
wasm_func_callback_with_env_t callback, void *env,
|
||||
void (*finalizer)(void *))
|
||||
{
|
||||
bh_assert(singleton_engine);
|
||||
|
@ -2452,8 +2430,7 @@ wasm_func_new_with_env(wasm_store_t *store,
|
|||
}
|
||||
|
||||
wasm_func_t *
|
||||
wasm_func_new_internal(wasm_store_t *store,
|
||||
uint16 func_idx_rt,
|
||||
wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_func_t *func = NULL;
|
||||
|
@ -2486,7 +2463,8 @@ wasm_func_new_internal(wasm_store_t *store,
|
|||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (inst_comm_rt->module_type == Wasm_Module_AoT) {
|
||||
/* use same index to trace the function type in AOTFuncType **func_types */
|
||||
/* use same index to trace the function type in AOTFuncType **func_types
|
||||
*/
|
||||
AOTModule *module_aot =
|
||||
((AOTModuleInstance *)inst_comm_rt)->aot_module.ptr;
|
||||
if (func_idx_rt < module_aot->import_func_count) {
|
||||
|
@ -2494,9 +2472,9 @@ wasm_func_new_internal(wasm_store_t *store,
|
|||
}
|
||||
else {
|
||||
type_rt =
|
||||
module_aot
|
||||
->func_types[module_aot->func_type_indexes
|
||||
[func_idx_rt - module_aot->import_func_count]];
|
||||
module_aot->func_types[module_aot->func_type_indexes
|
||||
[func_idx_rt
|
||||
- module_aot->import_func_count]];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -2565,8 +2543,8 @@ wasm_func_copy(const wasm_func_t *func)
|
|||
if (!(cloned = func->with_env ? wasm_func_new_with_env_basic(
|
||||
func->store, func->type, func->u.cb_env.cb,
|
||||
func->u.cb_env.env, func->u.cb_env.finalizer)
|
||||
: wasm_func_new_basic(
|
||||
func->store, func->type, func->u.cb))) {
|
||||
: wasm_func_new_basic(func->store, func->type,
|
||||
func->u.cb))) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
@ -2586,10 +2564,8 @@ wasm_func_type(const wasm_func_t *func)
|
|||
}
|
||||
|
||||
static uint32
|
||||
params_to_argv(WASMModuleInstanceCommon *inst_comm_rt,
|
||||
const wasm_val_t *params,
|
||||
const wasm_valtype_vec_t *param_defs,
|
||||
size_t param_arity,
|
||||
params_to_argv(WASMModuleInstanceCommon *inst_comm_rt, const wasm_val_t *params,
|
||||
const wasm_valtype_vec_t *param_defs, size_t param_arity,
|
||||
uint32 *out)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
@ -2630,8 +2606,7 @@ params_to_argv(WASMModuleInstanceCommon *inst_comm_rt,
|
|||
break;
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
case WASM_ANYREF:
|
||||
if (!wasm_externref_obj2ref(inst_comm_rt, param->of.ref,
|
||||
out)) {
|
||||
if (!wasm_externref_obj2ref(inst_comm_rt, param->of.ref, out)) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
@ -2653,10 +2628,8 @@ failed:
|
|||
}
|
||||
|
||||
static uint32
|
||||
argv_to_results(const uint32 *results,
|
||||
const wasm_valtype_vec_t *result_defs,
|
||||
size_t result_arity,
|
||||
wasm_val_t *out)
|
||||
argv_to_results(const uint32 *results, const wasm_valtype_vec_t *result_defs,
|
||||
size_t result_arity, wasm_val_t *out)
|
||||
{
|
||||
size_t i = 0;
|
||||
uint32 argc = 0;
|
||||
|
@ -2738,8 +2711,7 @@ failed:
|
|||
}
|
||||
|
||||
wasm_trap_t *
|
||||
wasm_func_call(const wasm_func_t *func,
|
||||
const wasm_val_vec_t *params,
|
||||
wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params,
|
||||
wasm_val_vec_t *results)
|
||||
{
|
||||
/* parameters count as if all are uint32 */
|
||||
|
@ -2872,8 +2844,7 @@ wasm_func_result_arity(const wasm_func_t *func)
|
|||
}
|
||||
|
||||
wasm_global_t *
|
||||
wasm_global_new(wasm_store_t *store,
|
||||
const wasm_globaltype_t *global_type,
|
||||
wasm_global_new(wasm_store_t *store, const wasm_globaltype_t *global_type,
|
||||
const wasm_val_t *init)
|
||||
{
|
||||
wasm_global_t *global = NULL;
|
||||
|
@ -2971,8 +2942,7 @@ wasm_global_delete(wasm_global_t *global)
|
|||
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
static bool
|
||||
interp_global_set(const WASMModuleInstance *inst_interp,
|
||||
uint16 global_idx_rt,
|
||||
interp_global_set(const WASMModuleInstance *inst_interp, uint16 global_idx_rt,
|
||||
const wasm_val_t *v)
|
||||
{
|
||||
const WASMGlobalInstance *global_interp =
|
||||
|
@ -2992,8 +2962,7 @@ interp_global_set(const WASMModuleInstance *inst_interp,
|
|||
}
|
||||
|
||||
static bool
|
||||
interp_global_get(const WASMModuleInstance *inst_interp,
|
||||
uint16 global_idx_rt,
|
||||
interp_global_get(const WASMModuleInstance *inst_interp, uint16 global_idx_rt,
|
||||
wasm_val_t *out)
|
||||
{
|
||||
WASMGlobalInstance *global_interp = inst_interp->globals + global_idx_rt;
|
||||
|
@ -3013,8 +2982,7 @@ interp_global_get(const WASMModuleInstance *inst_interp,
|
|||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
static bool
|
||||
aot_global_set(const AOTModuleInstance *inst_aot,
|
||||
uint16 global_idx_rt,
|
||||
aot_global_set(const AOTModuleInstance *inst_aot, uint16 global_idx_rt,
|
||||
const wasm_val_t *v)
|
||||
{
|
||||
AOTModule *module_aot = inst_aot->aot_module.ptr;
|
||||
|
@ -3036,13 +3004,12 @@ aot_global_set(const AOTModuleInstance *inst_aot,
|
|||
}
|
||||
|
||||
data = (void *)((uint8 *)inst_aot->global_data.ptr + data_offset);
|
||||
return wasm_val_to_rt_val((WASMModuleInstanceCommon *)inst_aot,
|
||||
val_type_rt, v, data);
|
||||
return wasm_val_to_rt_val((WASMModuleInstanceCommon *)inst_aot, val_type_rt,
|
||||
v, data);
|
||||
}
|
||||
|
||||
static bool
|
||||
aot_global_get(const AOTModuleInstance *inst_aot,
|
||||
uint16 global_idx_rt,
|
||||
aot_global_get(const AOTModuleInstance *inst_aot, uint16 global_idx_rt,
|
||||
wasm_val_t *out)
|
||||
{
|
||||
AOTModule *module_aot = inst_aot->aot_module.ptr;
|
||||
|
@ -3131,8 +3098,7 @@ wasm_global_get(const wasm_global_t *global, wasm_val_t *out)
|
|||
}
|
||||
|
||||
wasm_global_t *
|
||||
wasm_global_new_internal(wasm_store_t *store,
|
||||
uint16 global_idx_rt,
|
||||
wasm_global_new_internal(wasm_store_t *store, uint16 global_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_global_t *global = NULL;
|
||||
|
@ -3259,8 +3225,7 @@ wasm_table_new_basic(wasm_store_t *store, const wasm_tabletype_t *type)
|
|||
}
|
||||
|
||||
wasm_table_t *
|
||||
wasm_table_new_internal(wasm_store_t *store,
|
||||
uint16 table_idx_rt,
|
||||
wasm_table_new_internal(wasm_store_t *store, uint16 table_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_table_t *table = NULL;
|
||||
|
@ -3337,8 +3302,7 @@ wasm_table_new_internal(wasm_store_t *store,
|
|||
|
||||
/* will not actually apply this new table into the runtime */
|
||||
wasm_table_t *
|
||||
wasm_table_new(wasm_store_t *store,
|
||||
const wasm_tabletype_t *table_type,
|
||||
wasm_table_new(wasm_store_t *store, const wasm_tabletype_t *table_type,
|
||||
wasm_ref_t *init)
|
||||
{
|
||||
wasm_table_t *table;
|
||||
|
@ -3440,8 +3404,7 @@ wasm_table_get(const wasm_table_t *table, wasm_table_size_t index)
|
|||
}
|
||||
|
||||
bool
|
||||
wasm_table_set(wasm_table_t *table,
|
||||
wasm_table_size_t index,
|
||||
wasm_table_set(wasm_table_t *table, wasm_table_size_t index,
|
||||
own wasm_ref_t *func_ref)
|
||||
{
|
||||
uint32 *p_func_idx_rt = NULL;
|
||||
|
@ -3554,8 +3517,7 @@ wasm_table_size(const wasm_table_t *table)
|
|||
}
|
||||
|
||||
bool
|
||||
wasm_table_grow(wasm_table_t *table,
|
||||
wasm_table_size_t delta,
|
||||
wasm_table_grow(wasm_table_t *table, wasm_table_size_t delta,
|
||||
own wasm_ref_t *init)
|
||||
{
|
||||
(void)table;
|
||||
|
@ -3609,8 +3571,7 @@ wasm_memory_copy(const wasm_memory_t *src)
|
|||
}
|
||||
|
||||
wasm_memory_t *
|
||||
wasm_memory_new_internal(wasm_store_t *store,
|
||||
uint16 memory_idx_rt,
|
||||
wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt)
|
||||
{
|
||||
wasm_memory_t *memory = NULL;
|
||||
|
@ -3810,10 +3771,8 @@ wasm_memory_grow(wasm_memory_t *memory, wasm_memory_pages_t delta)
|
|||
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
static bool
|
||||
interp_link_func(const wasm_instance_t *inst,
|
||||
const WASMModule *module_interp,
|
||||
uint16 func_idx_rt,
|
||||
wasm_func_t *import)
|
||||
interp_link_func(const wasm_instance_t *inst, const WASMModule *module_interp,
|
||||
uint16 func_idx_rt, wasm_func_t *import)
|
||||
{
|
||||
WASMImport *imported_func_interp = NULL;
|
||||
wasm_func_t *cloned = NULL;
|
||||
|
@ -3850,8 +3809,7 @@ interp_link_func(const wasm_instance_t *inst,
|
|||
}
|
||||
|
||||
static bool
|
||||
interp_link_global(const WASMModule *module_interp,
|
||||
uint16 global_idx_rt,
|
||||
interp_link_global(const WASMModule *module_interp, uint16 global_idx_rt,
|
||||
wasm_global_t *import)
|
||||
{
|
||||
WASMImport *imported_global_interp = NULL;
|
||||
|
@ -3895,8 +3853,7 @@ interp_link_global(const WASMModule *module_interp,
|
|||
}
|
||||
|
||||
static uint32
|
||||
interp_link(const wasm_instance_t *inst,
|
||||
const WASMModule *module_interp,
|
||||
interp_link(const wasm_instance_t *inst, const WASMModule *module_interp,
|
||||
wasm_extern_t *imports[])
|
||||
{
|
||||
uint32 i = 0;
|
||||
|
@ -4035,10 +3992,8 @@ failed:
|
|||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
static bool
|
||||
aot_link_func(const wasm_instance_t *inst,
|
||||
const AOTModule *module_aot,
|
||||
uint32 import_func_idx_rt,
|
||||
wasm_func_t *import)
|
||||
aot_link_func(const wasm_instance_t *inst, const AOTModule *module_aot,
|
||||
uint32 import_func_idx_rt, wasm_func_t *import)
|
||||
{
|
||||
AOTImportFunc *import_aot_func = NULL;
|
||||
wasm_func_t *cloned = NULL;
|
||||
|
@ -4071,8 +4026,7 @@ aot_link_func(const wasm_instance_t *inst,
|
|||
}
|
||||
|
||||
static bool
|
||||
aot_link_global(const AOTModule *module_aot,
|
||||
uint16 global_idx_rt,
|
||||
aot_link_global(const AOTModule *module_aot, uint16 global_idx_rt,
|
||||
wasm_global_t *import)
|
||||
{
|
||||
AOTImportGlobal *import_aot_global = NULL;
|
||||
|
@ -4116,8 +4070,7 @@ failed:
|
|||
}
|
||||
|
||||
static uint32
|
||||
aot_link(const wasm_instance_t *inst,
|
||||
const AOTModule *module_aot,
|
||||
aot_link(const wasm_instance_t *inst, const AOTModule *module_aot,
|
||||
wasm_extern_t *imports[])
|
||||
{
|
||||
uint32 i = 0;
|
||||
|
@ -4169,8 +4122,7 @@ failed:
|
|||
}
|
||||
|
||||
static bool
|
||||
aot_process_export(wasm_store_t *store,
|
||||
const AOTModuleInstance *inst_aot,
|
||||
aot_process_export(wasm_store_t *store, const AOTModuleInstance *inst_aot,
|
||||
wasm_extern_vec_t *externals)
|
||||
{
|
||||
uint32 i;
|
||||
|
@ -4263,21 +4215,17 @@ failed:
|
|||
#endif /* WASM_ENABLE_AOT */
|
||||
|
||||
wasm_instance_t *
|
||||
wasm_instance_new(wasm_store_t *store,
|
||||
const wasm_module_t *module,
|
||||
const wasm_extern_vec_t *imports,
|
||||
own wasm_trap_t **traps)
|
||||
wasm_instance_new(wasm_store_t *store, const wasm_module_t *module,
|
||||
const wasm_extern_vec_t *imports, own wasm_trap_t **traps)
|
||||
{
|
||||
return wasm_instance_new_with_args(store, module, imports, traps,
|
||||
KILOBYTE(32), KILOBYTE(32));
|
||||
}
|
||||
|
||||
wasm_instance_t *
|
||||
wasm_instance_new_with_args(wasm_store_t *store,
|
||||
const wasm_module_t *module,
|
||||
wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
|
||||
const wasm_extern_vec_t *imports,
|
||||
own wasm_trap_t **traps,
|
||||
const uint32 stack_size,
|
||||
own wasm_trap_t **traps, const uint32 stack_size,
|
||||
const uint32 heap_size)
|
||||
{
|
||||
char error_buf[128] = { 0 };
|
||||
|
@ -4308,8 +4256,9 @@ wasm_instance_new_with_args(wasm_store_t *store,
|
|||
import_count);
|
||||
|
||||
if (import_count) {
|
||||
uint32 actual_link_import_count = interp_link(
|
||||
instance, MODULE_INTERP(module), (wasm_extern_t **)imports->data);
|
||||
uint32 actual_link_import_count =
|
||||
interp_link(instance, MODULE_INTERP(module),
|
||||
(wasm_extern_t **)imports->data);
|
||||
/* make sure a complete import list */
|
||||
if ((int32)import_count < 0
|
||||
|| import_count != actual_link_import_count) {
|
||||
|
@ -4387,14 +4336,14 @@ wasm_instance_new_with_args(wasm_store_t *store,
|
|||
/* build the exports list */
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) {
|
||||
uint32 export_cnt =
|
||||
((WASMModuleInstance *)instance->inst_comm_rt)->module->export_count;
|
||||
uint32 export_cnt = ((WASMModuleInstance *)instance->inst_comm_rt)
|
||||
->module->export_count;
|
||||
|
||||
INIT_VEC(instance->exports, wasm_extern_vec_new_uninitialized,
|
||||
export_cnt);
|
||||
|
||||
if (!interp_process_export(
|
||||
store, (WASMModuleInstance *)instance->inst_comm_rt,
|
||||
if (!interp_process_export(store,
|
||||
(WASMModuleInstance *)instance->inst_comm_rt,
|
||||
instance->exports)) {
|
||||
goto failed;
|
||||
}
|
||||
|
|
|
@ -213,33 +213,27 @@ struct wasm_instance_t {
|
|||
};
|
||||
|
||||
wasm_ref_t *
|
||||
wasm_ref_new_internal(wasm_store_t *store,
|
||||
enum wasm_reference_kind kind,
|
||||
wasm_ref_new_internal(wasm_store_t *store, enum wasm_reference_kind kind,
|
||||
uint32 obj_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
|
||||
wasm_foreign_t *
|
||||
wasm_foreign_new_internal(wasm_store_t *store,
|
||||
uint32 foreign_idx_rt,
|
||||
wasm_foreign_new_internal(wasm_store_t *store, uint32 foreign_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
|
||||
wasm_func_t *
|
||||
wasm_func_new_internal(wasm_store_t *store,
|
||||
uint16 func_idx_rt,
|
||||
wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
|
||||
wasm_global_t *
|
||||
wasm_global_new_internal(wasm_store_t *store,
|
||||
uint16 global_idx_rt,
|
||||
wasm_global_new_internal(wasm_store_t *store, uint16 global_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
|
||||
wasm_memory_t *
|
||||
wasm_memory_new_internal(wasm_store_t *store,
|
||||
uint16 memory_idx_rt,
|
||||
wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
|
||||
wasm_table_t *
|
||||
wasm_table_new_internal(wasm_store_t *store,
|
||||
uint16 table_idx_rt,
|
||||
wasm_table_new_internal(wasm_store_t *store, uint16 table_idx_rt,
|
||||
WASMModuleInstanceCommon *inst_comm_rt);
|
||||
#endif /* _WASM_C_API_INTERNAL_H */
|
||||
|
|
|
@ -27,8 +27,8 @@ WASMExecEnv *
|
|||
wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
|
||||
uint32 stack_size)
|
||||
{
|
||||
uint64 total_size = offsetof(WASMExecEnv, wasm_stack.s.bottom)
|
||||
+ (uint64)stack_size;
|
||||
uint64 total_size =
|
||||
offsetof(WASMExecEnv, wasm_stack.s.bottom) + (uint64)stack_size;
|
||||
WASMExecEnv *exec_env;
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
|
@ -122,22 +122,23 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
|||
if (!exec_env)
|
||||
return NULL;
|
||||
|
||||
/* Set the aux_stack_boundary and aux_stack_bottom */
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
/* Set the aux_stack_boundary and aux_stack_bottom */
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
WASMModule *module = ((WASMModuleInstance *)module_inst)->module;
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary = module->aux_stack_bottom
|
||||
- module->aux_stack_size;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
/* Set the aux_stack_boundary and aux_stack_bottom */
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
AOTModule *module =
|
||||
(AOTModule *)(((AOTModuleInstance *)module_inst)->aot_module.ptr);
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary = module->aux_stack_bottom
|
||||
- module->aux_stack_size;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -150,8 +151,8 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
|||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
wasm_debug_instance_create(cluster);
|
||||
#endif
|
||||
#endif /* end of WASM_ENABLE_THREAD_MGR */
|
||||
|
||||
#endif
|
||||
return exec_env;
|
||||
}
|
||||
|
||||
|
@ -162,16 +163,15 @@ wasm_exec_env_destroy(WASMExecEnv *exec_env)
|
|||
/* Terminate all sub-threads */
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
if (cluster) {
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
wasm_cluster_thread_exited(exec_env);
|
||||
wasm_debug_instance_destroy(cluster);
|
||||
#endif
|
||||
#endif
|
||||
wasm_cluster_terminate_all_except_self(cluster, exec_env);
|
||||
wasm_cluster_del_exec_env(cluster, exec_env);
|
||||
}
|
||||
#endif
|
||||
#endif /* end of WASM_ENABLE_THREAD_MGR */
|
||||
|
||||
wasm_exec_env_destroy_internal(exec_env);
|
||||
}
|
||||
|
||||
|
@ -224,4 +224,3 @@ wasm_exec_env_pop_jmpbuf(WASMExecEnv *exec_env)
|
|||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -192,8 +192,8 @@ wasm_exec_env_alloc_wasm_frame(WASMExecEnv *exec_env, unsigned size)
|
|||
|
||||
#if WASM_ENABLE_MEMORY_PROFILING != 0
|
||||
{
|
||||
uint32 wasm_stack_used = exec_env->wasm_stack.s.top
|
||||
- exec_env->wasm_stack.s.bottom;
|
||||
uint32 wasm_stack_used =
|
||||
exec_env->wasm_stack.s.top - exec_env->wasm_stack.s.bottom;
|
||||
if (wasm_stack_used > exec_env->max_wasm_stack_used)
|
||||
exec_env->max_wasm_stack_used = wasm_stack_used;
|
||||
}
|
||||
|
@ -253,7 +253,6 @@ wasm_exec_env_get_module_inst(WASMExecEnv *exec_env);
|
|||
void
|
||||
wasm_exec_env_set_thread_info(WASMExecEnv *exec_env);
|
||||
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
void *
|
||||
wasm_exec_env_get_thread_arg(WASMExecEnv *exec_env);
|
||||
|
|
|
@ -39,8 +39,7 @@ wasm_memory_init_with_pool(void *mem, unsigned int bytes)
|
|||
}
|
||||
|
||||
static bool
|
||||
wasm_memory_init_with_allocator(void *_malloc_func,
|
||||
void *_realloc_func,
|
||||
wasm_memory_init_with_allocator(void *_malloc_func, void *_realloc_func,
|
||||
void *_free_func)
|
||||
{
|
||||
if (_malloc_func && _free_func && _malloc_func != _free_func) {
|
||||
|
@ -50,8 +49,8 @@ wasm_memory_init_with_allocator(void *_malloc_func,
|
|||
free_func = _free_func;
|
||||
return true;
|
||||
}
|
||||
LOG_ERROR("Init memory with allocator (%p, %p, %p) failed.\n",
|
||||
_malloc_func, _realloc_func, _free_func);
|
||||
LOG_ERROR("Init memory with allocator (%p, %p, %p) failed.\n", _malloc_func,
|
||||
_realloc_func, _free_func);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,7 +62,8 @@ wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
|
|||
return wasm_memory_init_with_pool(alloc_option->pool.heap_buf,
|
||||
alloc_option->pool.heap_size);
|
||||
else if (mem_alloc_type == Alloc_With_Allocator)
|
||||
return wasm_memory_init_with_allocator(alloc_option->allocator.malloc_func,
|
||||
return wasm_memory_init_with_allocator(
|
||||
alloc_option->allocator.malloc_func,
|
||||
alloc_option->allocator.realloc_func,
|
||||
alloc_option->allocator.free_func);
|
||||
else if (mem_alloc_type == Alloc_With_System_Allocator)
|
||||
|
@ -93,7 +93,8 @@ static inline void *
|
|||
wasm_runtime_malloc_internal(unsigned int size)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
LOG_WARNING("wasm_runtime_malloc failed: memory hasn't been initialize.\n");
|
||||
LOG_WARNING(
|
||||
"wasm_runtime_malloc failed: memory hasn't been initialize.\n");
|
||||
return NULL;
|
||||
}
|
||||
else if (memory_mode == MEMORY_MODE_POOL) {
|
||||
|
@ -108,7 +109,8 @@ static inline void *
|
|||
wasm_runtime_realloc_internal(void *ptr, unsigned int size)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
LOG_WARNING("wasm_runtime_realloc failed: memory hasn't been initialize.\n");
|
||||
LOG_WARNING(
|
||||
"wasm_runtime_realloc failed: memory hasn't been initialize.\n");
|
||||
return NULL;
|
||||
}
|
||||
else if (memory_mode == MEMORY_MODE_POOL) {
|
||||
|
|
|
@ -25,4 +25,3 @@ wasm_runtime_memory_destroy();
|
|||
#endif
|
||||
|
||||
#endif /* end of _WASM_MEMORY_H */
|
||||
|
||||
|
|
|
@ -91,8 +91,7 @@ check_symbol_signature(const WASMType *type, const char *signature)
|
|||
if (sig == '*') {
|
||||
/* it is a pointer */
|
||||
if (i + 1 < type->param_count
|
||||
&& type->types[i + 1] == VALUE_TYPE_I32
|
||||
&& *p == '~') {
|
||||
&& type->types[i + 1] == VALUE_TYPE_I32 && *p == '~') {
|
||||
/* pointer length followed */
|
||||
i++;
|
||||
p++;
|
||||
|
@ -132,8 +131,8 @@ sort_symbol_ptr(NativeSymbol *native_symbols, uint32 n_native_symbols)
|
|||
|
||||
for (i = 0; i < n_native_symbols - 1; i++) {
|
||||
for (j = i + 1; j < n_native_symbols; j++) {
|
||||
if (strcmp(native_symbols[i].symbol,
|
||||
native_symbols[j].symbol) > 0) {
|
||||
if (strcmp(native_symbols[i].symbol, native_symbols[j].symbol)
|
||||
> 0) {
|
||||
temp = native_symbols[i];
|
||||
native_symbols[i] = native_symbols[j];
|
||||
native_symbols[j] = temp;
|
||||
|
@ -164,8 +163,8 @@ quick_sort_symbols(NativeSymbol* native_symbols, int left, int right)
|
|||
base_symbol = native_symbols[left];
|
||||
while (left < right) {
|
||||
while (left < right
|
||||
&& strcmp(native_symbols[right].symbol,
|
||||
base_symbol.symbol) > 0) {
|
||||
&& strcmp(native_symbols[right].symbol, base_symbol.symbol)
|
||||
> 0) {
|
||||
right--;
|
||||
}
|
||||
|
||||
|
@ -175,8 +174,7 @@ quick_sort_symbols(NativeSymbol* native_symbols, int left, int right)
|
|||
}
|
||||
|
||||
while (left < right
|
||||
&& strcmp(native_symbols[left].symbol,
|
||||
base_symbol.symbol) < 0) {
|
||||
&& strcmp(native_symbols[left].symbol, base_symbol.symbol) < 0) {
|
||||
left++;
|
||||
}
|
||||
|
||||
|
@ -229,14 +227,13 @@ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
|
|||
while (node) {
|
||||
node_next = node->next;
|
||||
if (!strcmp(node->module_name, module_name)) {
|
||||
if ((func_ptr = lookup_symbol(node->native_symbols,
|
||||
node->n_native_symbols,
|
||||
if ((func_ptr =
|
||||
lookup_symbol(node->native_symbols, node->n_native_symbols,
|
||||
field_name, &signature, &attachment))
|
||||
|| (field_name[0] == '_'
|
||||
&& (func_ptr = lookup_symbol(node->native_symbols,
|
||||
node->n_native_symbols,
|
||||
field_name + 1,
|
||||
&signature, &attachment))))
|
||||
&& (func_ptr = lookup_symbol(
|
||||
node->native_symbols, node->n_native_symbols,
|
||||
field_name + 1, &signature, &attachment))))
|
||||
break;
|
||||
}
|
||||
node = node_next;
|
||||
|
@ -246,7 +243,8 @@ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
|
|||
if (signature && signature[0] != '\0') {
|
||||
/* signature is not empty, check its format */
|
||||
if (!check_symbol_signature(func_type, signature)) {
|
||||
#if WASM_ENABLE_WAMR_COMPILER == 0 /* Output warning except running aot compiler */
|
||||
#if WASM_ENABLE_WAMR_COMPILER == 0
|
||||
/* Output warning except running aot compiler */
|
||||
LOG_WARNING("failed to check signature '%s' and resolve "
|
||||
"pointer params for import function (%s %s)\n",
|
||||
signature, module_name, field_name);
|
||||
|
@ -270,10 +268,8 @@ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
|
|||
}
|
||||
|
||||
static bool
|
||||
register_natives(const char *module_name,
|
||||
NativeSymbol *native_symbols,
|
||||
uint32 n_native_symbols,
|
||||
bool call_conv_raw)
|
||||
register_natives(const char *module_name, NativeSymbol *native_symbols,
|
||||
uint32 n_native_symbols, bool call_conv_raw)
|
||||
{
|
||||
NativeSymbolsNode *node;
|
||||
#if ENABLE_SORT_DEBUG != 0
|
||||
|
@ -309,10 +305,10 @@ register_natives(const char *module_name,
|
|||
|
||||
#if ENABLE_SORT_DEBUG != 0
|
||||
gettimeofday(&end, NULL);
|
||||
timer = 1000000 * (end.tv_sec - start.tv_sec)
|
||||
+ (end.tv_usec - start.tv_usec);
|
||||
LOG_ERROR("module_name: %s, nums: %d, sorted used: %ld us",
|
||||
module_name, n_native_symbols, timer);
|
||||
timer =
|
||||
1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
|
||||
LOG_ERROR("module_name: %s, nums: %d, sorted used: %ld us", module_name,
|
||||
n_native_symbols, timer);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -322,7 +318,8 @@ wasm_native_register_natives(const char *module_name,
|
|||
NativeSymbol *native_symbols,
|
||||
uint32 n_native_symbols)
|
||||
{
|
||||
return register_natives(module_name, native_symbols, n_native_symbols, false);
|
||||
return register_natives(module_name, native_symbols, n_native_symbols,
|
||||
false);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -330,7 +327,8 @@ wasm_native_register_natives_raw(const char *module_name,
|
|||
NativeSymbol *native_symbols,
|
||||
uint32 n_native_symbols)
|
||||
{
|
||||
return register_natives(module_name, native_symbols, n_native_symbols, true);
|
||||
return register_natives(module_name, native_symbols, n_native_symbols,
|
||||
true);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -341,41 +339,40 @@ wasm_native_init()
|
|||
|
||||
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
||||
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("env",
|
||||
native_symbols, n_native_symbols))
|
||||
if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
|
||||
return false;
|
||||
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
||||
|
||||
#if WASM_ENABLE_SPEC_TEST
|
||||
n_native_symbols = get_spectest_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("spectest",
|
||||
native_symbols, n_native_symbols))
|
||||
if (!wasm_native_register_natives("spectest", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif /* WASM_ENABLE_SPEC_TEST */
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("wasi_unstable",
|
||||
native_symbols, n_native_symbols))
|
||||
if (!wasm_native_register_natives("wasi_unstable", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
if (!wasm_native_register_natives("wasi_snapshot_preview1",
|
||||
native_symbols, n_native_symbols))
|
||||
if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_BASE_LIB != 0
|
||||
n_native_symbols = get_base_lib_export_apis(&native_symbols);
|
||||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env",
|
||||
native_symbols, n_native_symbols))
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_APP_FRAMEWORK != 0
|
||||
n_native_symbols = get_ext_lib_export_apis(&native_symbols);
|
||||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env",
|
||||
native_symbols, n_native_symbols))
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
|
@ -385,16 +382,16 @@ wasm_native_init()
|
|||
|
||||
n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
|
||||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env",
|
||||
native_symbols, n_native_symbols))
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LIBC_EMCC != 0
|
||||
n_native_symbols = get_libc_emcc_export_apis(&native_symbols);
|
||||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env",
|
||||
native_symbols, n_native_symbols))
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
#endif /* WASM_ENABLE_LIBC_EMCC */
|
||||
|
||||
|
|
|
@ -75,4 +75,3 @@ wasm_native_destroy();
|
|||
#endif
|
||||
|
||||
#endif /* end of _WASM_NATIVE_H */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,10 +27,12 @@ extern "C" {
|
|||
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
||||
|
||||
#define PUT_I64_TO_ADDR(addr, value) do { \
|
||||
#define PUT_I64_TO_ADDR(addr, value) \
|
||||
do { \
|
||||
*(int64 *)(addr) = (int64)(value); \
|
||||
} while (0)
|
||||
#define PUT_F64_TO_ADDR(addr, value) do { \
|
||||
#define PUT_F64_TO_ADDR(addr, value) \
|
||||
do { \
|
||||
*(float64 *)(addr) = (float64)(value); \
|
||||
} while (0)
|
||||
|
||||
|
@ -39,10 +41,12 @@ extern "C" {
|
|||
|
||||
/* For STORE opcodes */
|
||||
#define STORE_I64 PUT_I64_TO_ADDR
|
||||
#define STORE_U32(addr, value) do { \
|
||||
#define STORE_U32(addr, value) \
|
||||
do { \
|
||||
*(uint32 *)(addr) = (uint32)(value); \
|
||||
} while (0)
|
||||
#define STORE_U16(addr, value) do { \
|
||||
#define STORE_U16(addr, value) \
|
||||
do { \
|
||||
*(uint16 *)(addr) = (uint16)(value); \
|
||||
} while (0)
|
||||
|
||||
|
@ -54,22 +58,31 @@ extern "C" {
|
|||
#define LOAD_I16(addr) (*(int16 *)(addr))
|
||||
#define LOAD_U16(addr) (*(uint16 *)(addr))
|
||||
|
||||
#define STORE_PTR(addr, ptr) do { \
|
||||
#define STORE_PTR(addr, ptr) \
|
||||
do { \
|
||||
*(void **)addr = (void *)ptr; \
|
||||
} while (0)
|
||||
|
||||
#else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
|
||||
|
||||
#define PUT_I64_TO_ADDR(addr, value) do { \
|
||||
#define PUT_I64_TO_ADDR(addr, value) \
|
||||
do { \
|
||||
uint32 *addr_u32 = (uint32 *)(addr); \
|
||||
union { int64 val; uint32 parts[2]; } u; \
|
||||
union { \
|
||||
int64 val; \
|
||||
uint32 parts[2]; \
|
||||
} u; \
|
||||
u.val = (int64)(value); \
|
||||
addr_u32[0] = u.parts[0]; \
|
||||
addr_u32[1] = u.parts[1]; \
|
||||
} while (0)
|
||||
#define PUT_F64_TO_ADDR(addr, value) do { \
|
||||
#define PUT_F64_TO_ADDR(addr, value) \
|
||||
do { \
|
||||
uint32 *addr_u32 = (uint32 *)(addr); \
|
||||
union { float64 val; uint32 parts[2]; } u; \
|
||||
union { \
|
||||
float64 val; \
|
||||
uint32 parts[2]; \
|
||||
} u; \
|
||||
u.val = (value); \
|
||||
addr_u32[0] = u.parts[0]; \
|
||||
addr_u32[1] = u.parts[1]; \
|
||||
|
@ -78,7 +91,10 @@ extern "C" {
|
|||
static inline int64
|
||||
GET_I64_FROM_ADDR(uint32 *addr)
|
||||
{
|
||||
union { int64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
int64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.parts[0] = addr[0];
|
||||
u.parts[1] = addr[1];
|
||||
return u.val;
|
||||
|
@ -87,17 +103,25 @@ GET_I64_FROM_ADDR(uint32 *addr)
|
|||
static inline float64
|
||||
GET_F64_FROM_ADDR(uint32 *addr)
|
||||
{
|
||||
union { float64 val; uint32 parts[2]; } u;
|
||||
union {
|
||||
float64 val;
|
||||
uint32 parts[2];
|
||||
} u;
|
||||
u.parts[0] = addr[0];
|
||||
u.parts[1] = addr[1];
|
||||
return u.val;
|
||||
}
|
||||
|
||||
/* For STORE opcodes */
|
||||
#define STORE_I64(addr, value) do { \
|
||||
#define STORE_I64(addr, value) \
|
||||
do { \
|
||||
uintptr_t addr1 = (uintptr_t)(addr); \
|
||||
union { int64 val; uint32 u32[2]; \
|
||||
uint16 u16[4]; uint8 u8[8]; } u; \
|
||||
union { \
|
||||
int64 val; \
|
||||
uint32 u32[2]; \
|
||||
uint16 u16[4]; \
|
||||
uint8 u8[8]; \
|
||||
} u; \
|
||||
if ((addr1 & (uintptr_t)7) == 0) \
|
||||
*(int64 *)(addr) = (int64)(value); \
|
||||
else { \
|
||||
|
@ -120,10 +144,14 @@ GET_F64_FROM_ADDR (uint32 *addr)
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define STORE_U32(addr, value) do { \
|
||||
#define STORE_U32(addr, value) \
|
||||
do { \
|
||||
uintptr_t addr1 = (uintptr_t)(addr); \
|
||||
union { uint32 val; \
|
||||
uint16 u16[2]; uint8 u8[4]; } u; \
|
||||
union { \
|
||||
uint32 val; \
|
||||
uint16 u16[2]; \
|
||||
uint8 u8[4]; \
|
||||
} u; \
|
||||
if ((addr1 & (uintptr_t)3) == 0) \
|
||||
*(uint32 *)(addr) = (uint32)(value); \
|
||||
else { \
|
||||
|
@ -141,8 +169,12 @@ GET_F64_FROM_ADDR (uint32 *addr)
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define STORE_U16(addr, value) do { \
|
||||
union { uint16 val; uint8 u8[2]; } u; \
|
||||
#define STORE_U16(addr, value) \
|
||||
do { \
|
||||
union { \
|
||||
uint16 val; \
|
||||
uint8 u8[2]; \
|
||||
} u; \
|
||||
u.val = (uint16)(value); \
|
||||
((uint8 *)(addr))[0] = u.u8[0]; \
|
||||
((uint8 *)(addr))[1] = u.u8[1]; \
|
||||
|
@ -153,8 +185,12 @@ static inline int64
|
|||
LOAD_I64(void *addr)
|
||||
{
|
||||
uintptr_t addr1 = (uintptr_t)addr;
|
||||
union { int64 val; uint32 u32[2];
|
||||
uint16 u16[4]; uint8 u8[8]; } u;
|
||||
union {
|
||||
int64 val;
|
||||
uint32 u32[2];
|
||||
uint16 u16[4];
|
||||
uint8 u8[8];
|
||||
} u;
|
||||
if ((addr1 & (uintptr_t)7) == 0)
|
||||
return *(int64 *)addr;
|
||||
|
||||
|
@ -180,8 +216,12 @@ static inline float64
|
|||
LOAD_F64(void *addr)
|
||||
{
|
||||
uintptr_t addr1 = (uintptr_t)addr;
|
||||
union { float64 val; uint32 u32[2];
|
||||
uint16 u16[4]; uint8 u8[8]; } u;
|
||||
union {
|
||||
float64 val;
|
||||
uint32 u32[2];
|
||||
uint16 u16[4];
|
||||
uint8 u8[8];
|
||||
} u;
|
||||
if ((addr1 & (uintptr_t)7) == 0)
|
||||
return *(float64 *)addr;
|
||||
|
||||
|
@ -207,7 +247,11 @@ static inline int32
|
|||
LOAD_I32(void *addr)
|
||||
{
|
||||
uintptr_t addr1 = (uintptr_t)addr;
|
||||
union { int32 val; uint16 u16[2]; uint8 u8[4]; } u;
|
||||
union {
|
||||
int32 val;
|
||||
uint16 u16[2];
|
||||
uint8 u8[4];
|
||||
} u;
|
||||
if ((addr1 & (uintptr_t)3) == 0)
|
||||
return *(int32 *)addr;
|
||||
|
||||
|
@ -228,7 +272,10 @@ static inline int16
|
|||
LOAD_I16(void *addr)
|
||||
{
|
||||
uintptr_t addr1 = (uintptr_t)addr;
|
||||
union { int16 val; uint8 u8[2]; } u;
|
||||
union {
|
||||
int16 val;
|
||||
uint8 u8[2];
|
||||
} u;
|
||||
if ((addr1 & (uintptr_t)1)) {
|
||||
u.u8[0] = ((uint8 *)addr)[0];
|
||||
u.u8[1] = ((uint8 *)addr)[1];
|
||||
|
@ -361,8 +408,8 @@ get_package_type(const uint8 *buf, uint32 size);
|
|||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN WASMModuleCommon *
|
||||
wasm_runtime_load(const uint8 *buf, uint32 size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
wasm_runtime_load(const uint8 *buf, uint32 size, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN WASMModuleCommon *
|
||||
|
@ -386,9 +433,9 @@ wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
|
|||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
|
||||
wasm_runtime_instantiate(WASMModuleCommon *module,
|
||||
uint32 stack_size, uint32 heap_size,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size,
|
||||
uint32 heap_size, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
|
@ -432,8 +479,8 @@ wasm_runtime_get_user_data(WASMExecEnv *exec_env);
|
|||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_call_wasm(WASMExecEnv *exec_env,
|
||||
WASMFunctionInstanceCommon *function,
|
||||
uint32 argc, uint32 argv[]);
|
||||
WASMFunctionInstanceCommon *function, uint32 argc,
|
||||
uint32 argv[]);
|
||||
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
|
||||
|
@ -465,13 +512,12 @@ wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
|
|||
* the caller can call wasm_runtime_get_exception to get exception info.
|
||||
*/
|
||||
bool
|
||||
wasm_runtime_call_indirect(WASMExecEnv *exec_env,
|
||||
uint32 element_indices,
|
||||
wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_indices,
|
||||
uint32 argc, uint32 argv[]);
|
||||
|
||||
bool
|
||||
wasm_runtime_create_exec_env_and_call_wasm(WASMModuleInstanceCommon *module_inst,
|
||||
WASMFunctionInstanceCommon *function,
|
||||
wasm_runtime_create_exec_env_and_call_wasm(
|
||||
WASMModuleInstanceCommon *module_inst, WASMFunctionInstanceCommon *function,
|
||||
uint32 argc, uint32 argv[]);
|
||||
|
||||
bool
|
||||
|
@ -482,8 +528,8 @@ wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
|
|||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||
int32 argc, char *argv[]);
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
|
||||
char *argv[]);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
|
@ -559,8 +605,7 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
|
|||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 app_offset, uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
|
@ -600,8 +645,7 @@ wasm_runtime_register_module_internal(const char *module_name,
|
|||
WASMModuleCommon *module,
|
||||
uint8 *orig_file_buf,
|
||||
uint32 orig_file_buf_size,
|
||||
char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
|
||||
void
|
||||
wasm_runtime_unregister_module(const WASMModuleCommon *module);
|
||||
|
@ -610,8 +654,8 @@ bool
|
|||
wasm_runtime_is_module_registered(const char *module_name);
|
||||
|
||||
bool
|
||||
wasm_runtime_add_loading_module(const char *module_name,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
|
||||
uint32 error_buf_size);
|
||||
|
||||
void
|
||||
wasm_runtime_delete_loading_module(const char *module_name);
|
||||
|
@ -628,30 +672,28 @@ wasm_runtime_is_built_in_module(const char *module_name);
|
|||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 *start_offset, uint32 *size);
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset,
|
||||
uint32 *size);
|
||||
|
||||
bool
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env,
|
||||
uint32 start_offset, uint32 size);
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset,
|
||||
uint32 size);
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env_list[], uint32 env_count,
|
||||
char *argv[], int argc,
|
||||
wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
|
||||
uint32 dir_count, const char *map_dir_list[],
|
||||
uint32 map_dir_count, const char *env_list[],
|
||||
uint32 env_count, char *argv[], int argc,
|
||||
int stdinfd, int stdoutfd, int stderrfd);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env_list[], uint32 env_count,
|
||||
char *argv[], int argc);
|
||||
wasm_runtime_set_wasi_args(WASMModuleCommon *module, const char *dir_list[],
|
||||
uint32 dir_count, const char *map_dir_list[],
|
||||
uint32 map_dir_count, const char *env_list[],
|
||||
uint32 env_count, char *argv[], int argc);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
|
@ -665,9 +707,8 @@ bool
|
|||
wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env[], uint32 env_count,
|
||||
char *argv[], uint32 argc,
|
||||
int stdinfd, int stdoutfd, int stderrfd,
|
||||
const char *env[], uint32 env_count, char *argv[],
|
||||
uint32 argc, int stdinfd, int stdoutfd, int stderrfd,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
|
||||
void
|
||||
|
@ -685,8 +726,8 @@ wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst);
|
|||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst,
|
||||
void *extern_obj, uint32 *p_externref_idx);
|
||||
wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
|
||||
uint32 *p_externref_idx);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
|
@ -722,7 +763,8 @@ wasm_exec_env_get_module(WASMExecEnv *exec_env);
|
|||
* @return return true if enlarge successfully, false otherwise
|
||||
*/
|
||||
bool
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module, uint32 inc_page_count);
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module,
|
||||
uint32 inc_page_count);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
|
@ -739,14 +781,14 @@ wasm_runtime_register_natives_raw(const char *module_name,
|
|||
bool
|
||||
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
|
||||
const WASMType *func_type, const char *signature,
|
||||
void *attachment,
|
||||
uint32 *argv, uint32 argc, uint32 *ret);
|
||||
void *attachment, uint32 *argv, uint32 argc,
|
||||
uint32 *ret);
|
||||
|
||||
bool
|
||||
wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
|
||||
const WASMType *func_type, const char *signature,
|
||||
void *attachment,
|
||||
uint32 *argv, uint32 argc, uint32 *ret);
|
||||
void *attachment, uint32 *argv, uint32 argc,
|
||||
uint32 *ret);
|
||||
|
||||
void
|
||||
wasm_runtime_read_v128(const uint8 *bytes, uint64 *ret1, uint64 *ret2);
|
||||
|
@ -755,8 +797,8 @@ void
|
|||
wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module);
|
||||
|
||||
void
|
||||
wasm_runtime_dump_module_inst_mem_consumption(const WASMModuleInstanceCommon
|
||||
*module_inst);
|
||||
wasm_runtime_dump_module_inst_mem_consumption(
|
||||
const WASMModuleInstanceCommon *module_inst);
|
||||
|
||||
void
|
||||
wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env);
|
||||
|
@ -773,37 +815,32 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env,
|
|||
|
||||
bool
|
||||
wasm_runtime_get_export_func_type(const WASMModuleCommon *module_comm,
|
||||
const WASMExport *export_,
|
||||
WASMType **out);
|
||||
const WASMExport *export_, WASMType **out);
|
||||
|
||||
bool
|
||||
wasm_runtime_get_export_global_type(const WASMModuleCommon *module_comm,
|
||||
const WASMExport *export_,
|
||||
uint8 *out_val_type,
|
||||
bool *out_mutability);
|
||||
uint8 *out_val_type, bool *out_mutability);
|
||||
|
||||
bool
|
||||
wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
|
||||
const WASMExport *export_,
|
||||
uint32 *out_min_page,
|
||||
uint32 *out_max_page);
|
||||
uint32 *out_min_page, uint32 *out_max_page);
|
||||
|
||||
bool
|
||||
wasm_runtime_get_export_table_type(const WASMModuleCommon *module_comm,
|
||||
const WASMExport *export_,
|
||||
uint8 *out_elem_type,
|
||||
uint32 *out_min_size,
|
||||
uint8 *out_elem_type, uint32 *out_min_size,
|
||||
uint32 *out_max_size);
|
||||
|
||||
bool
|
||||
wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
|
||||
void *func_ptr, WASMType *func_type,
|
||||
uint32 argc, uint32 *argv,
|
||||
bool with_env, void *wasm_c_api_env);
|
||||
uint32 argc, uint32 *argv, bool with_env,
|
||||
void *wasm_c_api_env);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _WASM_COMMON_H */
|
||||
|
||||
|
|
|
@ -10,9 +10,12 @@ static bh_list shared_memory_list_head;
|
|||
static bh_list *const shared_memory_list = &shared_memory_list_head;
|
||||
static korp_mutex shared_memory_list_lock;
|
||||
|
||||
/* clang-format off */
|
||||
enum {
|
||||
S_WAITING, S_NOTIFIED
|
||||
S_WAITING,
|
||||
S_NOTIFIED
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct AtomicWaitInfo {
|
||||
korp_mutex wait_list_lock;
|
||||
|
@ -45,11 +48,9 @@ wasm_shared_memory_init()
|
|||
if (os_mutex_init(&shared_memory_list_lock) != 0)
|
||||
return false;
|
||||
/* wait map not exists, create new map */
|
||||
if (!(wait_map =
|
||||
bh_hash_map_create(32, true,
|
||||
(HashFunc)wait_address_hash,
|
||||
(KeyEqualFunc)wait_address_equal,
|
||||
NULL, destroy_wait_info))) {
|
||||
if (!(wait_map = bh_hash_map_create(32, true, (HashFunc)wait_address_hash,
|
||||
(KeyEqualFunc)wait_address_equal, NULL,
|
||||
destroy_wait_info))) {
|
||||
os_mutex_destroy(&shared_memory_list_lock);
|
||||
return false;
|
||||
}
|
||||
|
@ -223,16 +224,15 @@ acquire_wait_info(void *address, bool create)
|
|||
AtomicWaitInfo *wait_info = NULL;
|
||||
bh_list_status ret;
|
||||
|
||||
wait_info = (AtomicWaitInfo *)
|
||||
bh_hash_map_find(wait_map, address);
|
||||
wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address);
|
||||
|
||||
if (!create)
|
||||
return wait_info;
|
||||
|
||||
/* No wait info on this address, create new info */
|
||||
if (!wait_info) {
|
||||
if (!(wait_info =
|
||||
(AtomicWaitInfo *)wasm_runtime_malloc(sizeof(AtomicWaitInfo))))
|
||||
if (!(wait_info = (AtomicWaitInfo *)wasm_runtime_malloc(
|
||||
sizeof(AtomicWaitInfo))))
|
||||
return NULL;
|
||||
memset(wait_info, 0, sizeof(AtomicWaitInfo));
|
||||
|
||||
|
@ -247,8 +247,7 @@ acquire_wait_info(void *address, bool create)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!bh_hash_map_insert(wait_map, address,
|
||||
(void *)wait_info)) {
|
||||
if (!bh_hash_map_insert(wait_map, address, (void *)wait_info)) {
|
||||
os_mutex_destroy(&wait_info->wait_list_lock);
|
||||
wasm_runtime_free(wait_info);
|
||||
return NULL;
|
||||
|
@ -283,8 +282,7 @@ destroy_wait_info(void *wait_info)
|
|||
}
|
||||
|
||||
static void
|
||||
release_wait_info(HashMap *wait_map,
|
||||
AtomicWaitInfo *wait_info, void *address)
|
||||
release_wait_info(HashMap *wait_map, AtomicWaitInfo *wait_info, void *address)
|
||||
{
|
||||
if (wait_info->wait_list->len == 0) {
|
||||
bh_hash_map_remove(wait_map, address, NULL, NULL);
|
||||
|
@ -375,8 +373,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
|
|||
|
||||
if (timeout < 0)
|
||||
timeout = BHT_WAIT_FOREVER;
|
||||
os_cond_reltimedwait(&wait_node->wait_cond,
|
||||
&wait_node->wait_lock, timeout);
|
||||
os_cond_reltimedwait(&wait_node->wait_cond, &wait_node->wait_lock, timeout);
|
||||
|
||||
os_mutex_unlock(&wait_node->wait_lock);
|
||||
|
||||
|
@ -400,8 +397,8 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
|
|||
}
|
||||
|
||||
uint32
|
||||
wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module,
|
||||
void *address, uint32 count)
|
||||
wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
|
||||
uint32 count)
|
||||
{
|
||||
uint32 notify_result;
|
||||
AtomicWaitInfo *wait_info;
|
||||
|
|
|
@ -58,8 +58,8 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
|
|||
uint64 expect, int64 timeout, bool wait64);
|
||||
|
||||
uint32
|
||||
wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module,
|
||||
void *address, uint32 count);
|
||||
wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
|
||||
uint32 count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -62,8 +61,7 @@ typedef struct AOTCompOption{
|
|||
} AOTCompOption, *aot_comp_option_t;
|
||||
|
||||
aot_comp_context_t
|
||||
aot_create_comp_context(aot_comp_data_t comp_data,
|
||||
aot_comp_option_t option);
|
||||
aot_create_comp_context(aot_comp_data_t comp_data, aot_comp_option_t option);
|
||||
|
||||
void
|
||||
aot_destroy_comp_context(aot_comp_context_t comp_ctx);
|
||||
|
@ -78,8 +76,7 @@ bool
|
|||
aot_emit_object_file(aot_comp_context_t comp_ctx, const char *file_name);
|
||||
|
||||
bool
|
||||
aot_emit_aot_file(aot_comp_context_t comp_ctx,
|
||||
aot_comp_data_t comp_data,
|
||||
aot_emit_aot_file(aot_comp_context_t comp_ctx, aot_comp_data_t comp_data,
|
||||
const char *file_name);
|
||||
|
||||
void
|
||||
|
@ -90,9 +87,8 @@ aot_compile_wasm_file_init();
|
|||
|
||||
uint8_t *
|
||||
aot_compile_wasm_file(const uint8_t *wasm_file_buf, uint32_t wasm_file_size,
|
||||
uint32_t opt_level, uint32_t size_level,
|
||||
char *error_buf, uint32_t error_buf_size,
|
||||
uint32_t *p_aot_file_size);
|
||||
uint32_t opt_level, uint32_t size_level, char *error_buf,
|
||||
uint32_t error_buf_size, uint32_t *p_aot_file_size);
|
||||
|
||||
void
|
||||
aot_compile_wasm_file_destroy();
|
||||
|
|
|
@ -21,8 +21,11 @@ typedef struct NativeSymbol {
|
|||
void *attachment;
|
||||
} NativeSymbol;
|
||||
|
||||
#define EXPORT_WASM_API(symbol) {#symbol, (void*)symbol, NULL, NULL}
|
||||
#define EXPORT_WASM_API2(symbol) {#symbol, (void*)symbol##_wrapper, NULL, NULL}
|
||||
/* clang-format off */
|
||||
#define EXPORT_WASM_API(symbol) \
|
||||
{ #symbol, (void *)symbol, NULL, NULL }
|
||||
#define EXPORT_WASM_API2(symbol) \
|
||||
{ #symbol, (void *)symbol##_wrapper, NULL, NULL }
|
||||
|
||||
#define EXPORT_WASM_API_WITH_SIG(symbol, signature) \
|
||||
{ #symbol, (void *)symbol, signature, NULL }
|
||||
|
@ -33,6 +36,7 @@ typedef struct NativeSymbol {
|
|||
{ #symbol, (void *)symbol, signature, attachment }
|
||||
#define EXPORT_WASM_API_WITH_ATT2(symbol, signature, attachment) \
|
||||
{ #symbol, (void *)symbol##_wrapper, signature, attachment }
|
||||
/* clang-format on */
|
||||
|
||||
/**
|
||||
* Get the exported APIs of base lib
|
||||
|
@ -48,5 +52,4 @@ get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* end of _LIB_EXPORT_H_ */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// WebAssembly C API
|
||||
|
||||
#ifndef WASM_H
|
||||
#define WASM_H
|
||||
#ifndef _WASM_C_API_H_
|
||||
#define _WASM_C_API_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
@ -25,6 +25,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliaries
|
||||
|
||||
|
@ -776,8 +778,10 @@ static inline void* wasm_val_ptr(const wasm_val_t* val) {
|
|||
|
||||
#undef own
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // #ifdef WASM_H
|
||||
#endif // #ifdef _WASM_C_API_H_
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <stdbool.h>
|
||||
#include "lib_export.h"
|
||||
|
||||
|
||||
#ifndef WASM_RUNTIME_API_EXTERN
|
||||
#if defined(_MSC_BUILD)
|
||||
#if defined(COMPILING_WASM_RUNTIME_API)
|
||||
|
@ -27,6 +26,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
|
@ -54,7 +55,6 @@ extern "C" {
|
|||
|
||||
#define native_raw_set_return(val) *raw_ret = (val)
|
||||
|
||||
|
||||
#ifndef WASM_MODULE_T_DEFINED
|
||||
#define WASM_MODULE_T_DEFINED
|
||||
/* Uninstantiated WASM module loaded from WASM binary file
|
||||
|
@ -652,10 +652,11 @@ wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
|||
|
||||
/**
|
||||
* Similar to wasm_runtime_validate_app_addr(), except that the size parameter
|
||||
* is not provided. This function validates the app string address, check whether it
|
||||
* belongs to WASM module instance's address space, or in its heap space or
|
||||
* memory space. Moreover, it checks whether it is the offset of a string that
|
||||
* is end with '\0'.
|
||||
* is not provided. This function validates the app string address, check
|
||||
* whether it belongs to WASM module instance's address space, or in its heap
|
||||
* space or memory space. Moreover, it checks whether it is the offset of a
|
||||
* string that is end with '\0'.
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param app_str_offset the app address of the string to validate, which is a
|
||||
* relative address
|
||||
|
@ -724,12 +725,15 @@ wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
|
|||
uint32_t *p_app_end_offset);
|
||||
|
||||
/**
|
||||
* Get the native address range (absolute address) that a native address belongs to
|
||||
* Get the native address range (absolute address) that a native address
|
||||
* belongs to
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param native_ptr the native address to retrieve
|
||||
* @param p_native_start_addr buffer to output the native start address if not NULL
|
||||
* @param p_native_end_addr buffer to output the native end address if not NULL
|
||||
* @param p_native_start_addr buffer to output the native start address
|
||||
* if not NULL
|
||||
* @param p_native_end_addr buffer to output the native end address
|
||||
* if not NULL
|
||||
*
|
||||
* @return true if success, false otherwise.
|
||||
*/
|
||||
|
@ -773,7 +777,7 @@ wasm_runtime_register_natives(const char *module_name,
|
|||
/**
|
||||
* Register native functions with same module name, similar to
|
||||
* wasm_runtime_register_natives, the difference is that runtime passes raw
|
||||
* arguments to native API, which means that the native API should be defined as:
|
||||
* arguments to native API, which means that the native API should be defined as
|
||||
* void foo(wasm_exec_env_t exec_env, uint64 *args);
|
||||
* and native API should extract arguments one by one from args array with macro
|
||||
* native_raw_get_arg
|
||||
|
@ -802,8 +806,7 @@ wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
|
|||
* @param user_data the user data to be set
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_set_user_data(wasm_exec_env_t exec_env,
|
||||
void *user_data);
|
||||
wasm_runtime_set_user_data(wasm_exec_env_t exec_env, void *user_data);
|
||||
/**
|
||||
* Get the user data within execution environment.
|
||||
*
|
||||
|
@ -938,6 +941,8 @@ wasm_externref_retain(uint32_t externref_idx);
|
|||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_dump_call_stack(wasm_exec_env_t exec_env);
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@ iwasm -g=127.0.0.1:1234 test.wasm
|
|||
``` bash
|
||||
cd ${WAMR_ROOT}/core/deps/llvm
|
||||
git apply ../../../build-scripts/lldb-wasm.patch
|
||||
mkdir build_lldb && cd build_lldb
|
||||
mkdir build-lldb && cd build-lldb
|
||||
cmake -DCMAKE_BUILD_TYPE:STRING="Release" -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" -DLLVM_ENABLE_LIBXML2:BOOL=ON ../llvm
|
||||
make -j $(nproc)
|
||||
```
|
||||
|
|
|
@ -278,7 +278,7 @@ function spec_test()
|
|||
# restore from XX_ignore_cases.patch
|
||||
# resotre branch
|
||||
git checkout -B master
|
||||
git reset --hard f9770eb75117cac0c878feaa5eaf4a4d9dda61f5
|
||||
git reset --hard 397399a70565609bf142d211891724e21bffd01f
|
||||
git apply ../../spec-test-script/ignore_cases.patch
|
||||
|
||||
# udpate thread cases
|
||||
|
@ -291,7 +291,7 @@ function spec_test()
|
|||
# fetch spec for threads proposal
|
||||
git fetch threads
|
||||
git reset --hard HEAD
|
||||
git checkout threads/master
|
||||
git checkout threads/main
|
||||
|
||||
git apply ../../spec-test-script/thread_proposal_ignore_cases.patch
|
||||
fi
|
||||
|
@ -335,16 +335,16 @@ function spec_test()
|
|||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ ! -f /tmp/wabt-1.0.23-${WABT_PLATFORM}.tar.gz ]; then
|
||||
if [ ! -f /tmp/wabt-1.0.24-${WABT_PLATFORM}.tar.gz ]; then
|
||||
wget \
|
||||
https://github.com/WebAssembly/wabt/releases/download/1.0.23/wabt-1.0.23-${WABT_PLATFORM}.tar.gz \
|
||||
https://github.com/WebAssembly/wabt/releases/download/1.0.24/wabt-1.0.24-${WABT_PLATFORM}.tar.gz \
|
||||
-P /tmp
|
||||
fi
|
||||
|
||||
cd /tmp \
|
||||
&& tar zxf wabt-1.0.23-${WABT_PLATFORM}.tar.gz \
|
||||
&& tar zxf wabt-1.0.24-${WABT_PLATFORM}.tar.gz \
|
||||
&& mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \
|
||||
&& install wabt-1.0.23/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \
|
||||
&& install wabt-1.0.24/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \
|
||||
&& cd -
|
||||
fi
|
||||
else
|
||||
|
@ -356,12 +356,7 @@ function spec_test()
|
|||
echo "upate wabt"
|
||||
cd wabt
|
||||
git pull
|
||||
if [[ ${ENABLE_SIMD} == 0 ]]; then
|
||||
# Use latest version of wabt if simd cases are not tested
|
||||
git reset --hard c6cd63316ac53208900cda4d1089a22618b85256
|
||||
else
|
||||
git reset --hard origin/main
|
||||
fi
|
||||
cd ..
|
||||
make -C wabt gcc-release
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue
Block a user