mirror of
				https://github.com/bytecodealliance/wasm-micro-runtime.git
				synced 2025-10-31 13:17:31 +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 }, | ||||
|  | @ -58,23 +45,24 @@ static const aot_intrinsic g_intrinsic_mapping[] = { | |||
|     { "llvm.cttz.i64", "aot_intrinsic_ctz_i64", AOT_INTRINSIC_FLAG_I64_CTZ }, | ||||
|     { "llvm.ctpop.i32", "aot_intrinsic_popcnt_i32", AOT_INTRINSIC_FLAG_I32_POPCNT }, | ||||
|     { "llvm.ctpop.i64", "aot_intrinsic_popcnt_i64", AOT_INTRINSIC_FLAG_I64_POPCNT }, | ||||
|     { "f64_convert_i32_s", "aot_intrinsic_i32_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64}, | ||||
|     { "f64_convert_i32_u", "aot_intrinsic_u32_to_f64", AOT_INTRINSIC_FLAG_U32_TO_F64}, | ||||
|     { "f32_convert_i32_s", "aot_intrinsic_i32_to_f32", AOT_INTRINSIC_FLAG_I32_TO_F32}, | ||||
|     { "f32_convert_i32_u", "aot_intrinsic_u32_to_f32", AOT_INTRINSIC_FLAG_U32_TO_F32}, | ||||
|     { "f64_convert_i64_s", "aot_intrinsic_i64_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64}, | ||||
|     { "f64_convert_i64_u", "aot_intrinsic_u64_to_f64", AOT_INTRINSIC_FLAG_U64_TO_F64}, | ||||
|     { "f32_convert_i64_s", "aot_intrinsic_i64_to_f32", AOT_INTRINSIC_FLAG_I64_TO_F32}, | ||||
|     { "f32_convert_i64_u", "aot_intrinsic_u64_to_f32", AOT_INTRINSIC_FLAG_U64_TO_F32}, | ||||
|     { "i32_trunc_f64_u", "aot_intrinsic_f64_to_u32", AOT_INTRINSIC_FLAG_I32_TO_F64}, | ||||
|     { "f32_demote_f64", "aot_intrinsic_f64_to_f32", AOT_INTRINSIC_FLAG_F64_TO_F32}, | ||||
|     { "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64}, | ||||
|     { "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP}, | ||||
|     { "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP}, | ||||
|     { "f64_convert_i32_s", "aot_intrinsic_i32_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64 }, | ||||
|     { "f64_convert_i32_u", "aot_intrinsic_u32_to_f64", AOT_INTRINSIC_FLAG_U32_TO_F64 }, | ||||
|     { "f32_convert_i32_s", "aot_intrinsic_i32_to_f32", AOT_INTRINSIC_FLAG_I32_TO_F32 }, | ||||
|     { "f32_convert_i32_u", "aot_intrinsic_u32_to_f32", AOT_INTRINSIC_FLAG_U32_TO_F32 }, | ||||
|     { "f64_convert_i64_s", "aot_intrinsic_i64_to_f64", AOT_INTRINSIC_FLAG_I32_TO_F64 }, | ||||
|     { "f64_convert_i64_u", "aot_intrinsic_u64_to_f64", AOT_INTRINSIC_FLAG_U64_TO_F64 }, | ||||
|     { "f32_convert_i64_s", "aot_intrinsic_i64_to_f32", AOT_INTRINSIC_FLAG_I64_TO_F32 }, | ||||
|     { "f32_convert_i64_u", "aot_intrinsic_u64_to_f32", AOT_INTRINSIC_FLAG_U64_TO_F32 }, | ||||
|     { "i32_trunc_f64_u", "aot_intrinsic_f64_to_u32", AOT_INTRINSIC_FLAG_I32_TO_F64 }, | ||||
|     { "f32_demote_f64", "aot_intrinsic_f64_to_f32", AOT_INTRINSIC_FLAG_F64_TO_F32 }, | ||||
|     { "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64 }, | ||||
|     { "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); | ||||
|     sizeof(g_intrinsic_mapping) / sizeof(aot_intrinsic); | ||||
| 
 | ||||
| float32 | ||||
| aot_intrinsic_fadd_f32(float32 a, float32 b) | ||||
|  | @ -223,7 +211,7 @@ float64 | |||
| aot_intrinsic_fmin_f64(float64 a, float64 b) | ||||
| { | ||||
|     float64 c = fmin(a, b); | ||||
|     if (c==0 && a==b) | ||||
|     if (c == 0 && a == b) | ||||
|         return signbit(a) ? a : b; | ||||
|     return c; | ||||
| } | ||||
|  | @ -243,7 +231,7 @@ float64 | |||
| aot_intrinsic_fmax_f64(float64 a, float64 b) | ||||
| { | ||||
|     float64 c = fmax(a, b); | ||||
|     if (c==0 && a==b) | ||||
|     if (c == 0 && a == b) | ||||
|         return signbit(a) ? b : a; | ||||
|     return c; | ||||
| } | ||||
|  | @ -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); | ||||
|         } | ||||
|  | @ -611,7 +600,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) | |||
|         } | ||||
|     } | ||||
|     else if (!strncmp(comp_ctx->target_arch, "riscv", 5)) { | ||||
|         /* 
 | ||||
|         /*
 | ||||
|          * Note: Use builtin intrinsics since hardware float operation | ||||
|          * will cause rodata relocation | ||||
|          */ | ||||
|  |  | |||
|  | @ -22,14 +22,15 @@ extern "C" { | |||
|  *   - The lower 48 bits are the intrinsic capability mask | ||||
|  */ | ||||
| 
 | ||||
| #define AOT_INTRINSIC_FLAG(group, number)                                     \ | ||||
| #define AOT_INTRINSIC_FLAG(group, number) \ | ||||
|     ((((uint64)(group & 0xffffLL)) << 48) | ((uint64)1 << number)) | ||||
| 
 | ||||
| #define AOT_INTRINSIC_FLAG_MASK (0x0000ffffffffffffLL) | ||||
| 
 | ||||
| #define AOT_INTRINSIC_GET_GROUP_FROM_FLAG(flag)                               \ | ||||
| #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,15 +3,23 @@ | |||
|  * 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; | ||||
| 
 | ||||
| #define REG_SYM(symbol) { #symbol, (void*)symbol } | ||||
| /* clang-format off */ | ||||
| #define REG_SYM(symbol) { #symbol, (void *)symbol } | ||||
| 
 | ||||
| #if WASM_ENABLE_BULK_MEMORY != 0 | ||||
| #define REG_BULK_MEMORY_SYM()             \ | ||||
|  | @ -122,10 +130,11 @@ typedef struct { | |||
|     REG_AOT_TRACE_SYM()                   \ | ||||
|     REG_INTRINSIC_SYM()                   \ | ||||
| 
 | ||||
| #define CHECK_RELOC_OFFSET(data_size) do {                                  \ | ||||
|     if (!check_reloc_offset(target_section_size, reloc_offset, data_size,   \ | ||||
|                             error_buf, error_buf_size))                     \ | ||||
|         return false;                                                       \ | ||||
| #define CHECK_RELOC_OFFSET(data_size) do {              \ | ||||
|     if (!check_reloc_offset(target_section_size,        \ | ||||
|                             reloc_offset, data_size,    \ | ||||
|                             error_buf, error_buf_size)) \ | ||||
|         return false;                                   \ | ||||
|   } while (0) | ||||
| 
 | ||||
| SymbolMap * | ||||
|  | @ -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 | ||||
|  | @ -328,7 +330,7 @@ typedef struct AOTModuleInstance { | |||
|      * TODO: for now we treate imported table like a local table | ||||
|      */ | ||||
|     uint32 table_count; | ||||
|    /* points to global_data */ | ||||
|     /* points to global_data */ | ||||
|     AOTPointer global_data; | ||||
|     /* points to AOTTableInstance[] */ | ||||
|     AOTPointer tables; | ||||
|  | @ -373,15 +375,15 @@ typedef struct AOTModuleInstance { | |||
|     /* reserved */ | ||||
|     uint32 reserved[6]; | ||||
| 
 | ||||
|    /*
 | ||||
|     * +------------------------------+ <-- memories.ptr | ||||
|     * | #0 AOTMemoryInstance | ||||
|     * +------------------------------+ <-- global_data.ptr | ||||
|     * | global data | ||||
|     * +------------------------------+ <-- tables.ptr | ||||
|     * | AOTTableInstance[table_count] | ||||
|     * +------------------------------+ | ||||
|     */ | ||||
|     /*
 | ||||
|      * +------------------------------+ <-- memories.ptr | ||||
|      * | #0 AOTMemoryInstance | ||||
|      * +------------------------------+ <-- global_data.ptr | ||||
|      * | global data | ||||
|      * +------------------------------+ <-- tables.ptr | ||||
|      * | AOTTableInstance[table_count] | ||||
|      * +------------------------------+ | ||||
|      */ | ||||
|     union { | ||||
|         uint64 _make_it_8_byte_aligned_; | ||||
|         AOTMemoryInstance memory_instances[1]; | ||||
|  | @ -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 */ | ||||
|  | @ -436,9 +437,9 @@ 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); | ||||
| AOTModule * | ||||
| 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. | ||||
|  | @ -449,9 +450,9 @@ 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); | ||||
| AOTModule * | ||||
| aot_load_from_sections(AOTSection *section_list, char *error_buf, | ||||
|                        uint32 error_buf_size); | ||||
| 
 | ||||
| #if WASM_ENABLE_JIT != 0 | ||||
| /**
 | ||||
|  | @ -463,9 +464,9 @@ 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); | ||||
| AOTModule * | ||||
| aot_convert_wasm_module(WASMModule *wasm_module, char *error_buf, | ||||
|                         uint32 error_buf_size); | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -490,10 +491,9 @@ 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); | ||||
| AOTModuleInstance * | ||||
| 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. | ||||
|  | @ -514,9 +514,9 @@ 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); | ||||
| AOTFunctionInstance * | ||||
| 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. | ||||
|  | @ -567,7 +564,7 @@ aot_set_exception_with_id(AOTModuleInstance *module_inst, | |||
|  * | ||||
|  * @return the exception string | ||||
|  */ | ||||
| const char* | ||||
| const char * | ||||
| aot_get_exception(AOTModuleInstance *module_inst); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -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_ */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,37 +5,39 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_AARCH64_MOVW_UABS_G0          263 | ||||
| #define R_AARCH64_MOVW_UABS_G0_NC       264 | ||||
| #define R_AARCH64_MOVW_UABS_G1          265 | ||||
| #define R_AARCH64_MOVW_UABS_G1_NC       266 | ||||
| #define R_AARCH64_MOVW_UABS_G2          267 | ||||
| #define R_AARCH64_MOVW_UABS_G2_NC       268 | ||||
| #define R_AARCH64_MOVW_UABS_G3          269 | ||||
| #define R_AARCH64_MOVW_UABS_G0 263 | ||||
| #define R_AARCH64_MOVW_UABS_G0_NC 264 | ||||
| #define R_AARCH64_MOVW_UABS_G1 265 | ||||
| #define R_AARCH64_MOVW_UABS_G1_NC 266 | ||||
| #define R_AARCH64_MOVW_UABS_G2 267 | ||||
| #define R_AARCH64_MOVW_UABS_G2_NC 268 | ||||
| #define R_AARCH64_MOVW_UABS_G3 269 | ||||
| 
 | ||||
| #define R_AARCH64_MOVW_SABS_G0          270 | ||||
| #define R_AARCH64_MOVW_SABS_G1          271 | ||||
| #define R_AARCH64_MOVW_SABS_G2          272 | ||||
| #define R_AARCH64_MOVW_SABS_G0 270 | ||||
| #define R_AARCH64_MOVW_SABS_G1 271 | ||||
| #define R_AARCH64_MOVW_SABS_G2 272 | ||||
| 
 | ||||
| #define R_AARCH64_ADR_PREL_LO19         273 | ||||
| #define R_AARCH64_ADR_PREL_LO21         274 | ||||
| #define R_AARCH64_ADR_PREL_PG_HI21      275 | ||||
| #define R_AARCH64_ADR_PREL_PG_HI21_NC   276 | ||||
| #define R_AARCH64_ADR_PREL_LO19 273 | ||||
| #define R_AARCH64_ADR_PREL_LO21 274 | ||||
| #define R_AARCH64_ADR_PREL_PG_HI21 275 | ||||
| #define R_AARCH64_ADR_PREL_PG_HI21_NC 276 | ||||
| 
 | ||||
| #define R_AARCH64_ADD_ABS_LO12_NC       277 | ||||
| #define R_AARCH64_ADD_ABS_LO12_NC 277 | ||||
| 
 | ||||
| #define R_AARCH64_LDST8_ABS_LO12_NC     278 | ||||
| #define R_AARCH64_LDST16_ABS_LO12_NC    284 | ||||
| #define R_AARCH64_LDST32_ABS_LO12_NC    285 | ||||
| #define R_AARCH64_LDST64_ABS_LO12_NC    286 | ||||
| #define R_AARCH64_LDST128_ABS_LO12_NC   299 | ||||
| #define R_AARCH64_LDST8_ABS_LO12_NC 278 | ||||
| #define R_AARCH64_LDST16_ABS_LO12_NC 284 | ||||
| #define R_AARCH64_LDST32_ABS_LO12_NC 285 | ||||
| #define R_AARCH64_LDST64_ABS_LO12_NC 286 | ||||
| #define R_AARCH64_LDST128_ABS_LO12_NC 299 | ||||
| 
 | ||||
| #define R_AARCH64_JUMP26                282 | ||||
| #define R_AARCH64_CALL26                283 | ||||
| #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) | ||||
|  | @ -55,7 +57,7 @@ get_target_symbol_map(uint32 *sym_num) | |||
| void | ||||
| get_current_target(char *target_buf, uint32 target_buf_size) | ||||
| { | ||||
|     const char * s =  BUILD_TARGET; | ||||
|     const char *s = BUILD_TARGET; | ||||
|     size_t s_size = sizeof(BUILD_TARGET); | ||||
|     char *d = target_buf; | ||||
| 
 | ||||
|  | @ -64,14 +66,14 @@ get_current_target(char *target_buf, uint32 target_buf_size) | |||
|         s = BUILD_TARGET_AARCH64_DEFAULT; | ||||
|         s_size = sizeof(BUILD_TARGET_AARCH64_DEFAULT); | ||||
|     } | ||||
|     if(target_buf_size < s_size){ | ||||
|     if (target_buf_size < s_size) { | ||||
|         s_size = target_buf_size; | ||||
|     } | ||||
|     while (--s_size) { | ||||
|         if (*s >= 'A' && *s <= 'Z') | ||||
|             *d++ = *s++ + 'a' - 'A'; | ||||
|         else | ||||
|             *d++ = *s++ ; | ||||
|             *d++ = *s++; | ||||
|     } | ||||
|     /* Ensure the string is null byte ('\0') terminated */ | ||||
|     *d = '\0'; | ||||
|  | @ -90,15 +92,16 @@ init_plt_table(uint8 *plt) | |||
| { | ||||
|     uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap); | ||||
|     for (i = 0; i < num; i++) { | ||||
|         uint32 *p = (uint32*)plt; | ||||
|         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  */ | ||||
|         *p++ = 0xd61f03c0; /* br   x30          */ | ||||
|         /* symbol addr */ | ||||
|         *(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         *(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         p += 2; | ||||
|         plt += get_plt_item_size(); | ||||
|     } | ||||
|  | @ -110,17 +113,18 @@ 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 { \ | ||||
|     int64 m = (int64)((uint64)1 << (bits - 1));       \ | ||||
|     val_ext = ((int64)val ^ m) - m;                   \ | ||||
| } while (0) | ||||
| #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) | ||||
| 
 | ||||
| #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,22 +136,21 @@ 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: | ||||
|         { | ||||
|             void *S, *P = (void*)(target_section_addr + reloc_offset); | ||||
|             void *S, *P = (void *)(target_section_addr + reloc_offset); | ||||
|             int64 X, A, initial_addend; | ||||
|             int32 insn, imm26; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             insn = *(int32*)P; | ||||
|             insn = *(int32 *)P; | ||||
|             imm26 = insn & 0x3FFFFFF; | ||||
|             SIGN_EXTEND_TO_INT64(imm26 << 2, 28, initial_addend); | ||||
|             A = initial_addend; | ||||
|  | @ -164,17 +167,18 @@ apply_relocation(AOTModule *module, | |||
|             else { | ||||
|                 uint8 *plt; | ||||
|                 if (reloc_addend > 0) { | ||||
|                      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; | ||||
|                     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; | ||||
|                 } | ||||
|                 /* Symbol address is not an AOT function,
 | ||||
|                  * but a function of runtime or native. Its address is | ||||
|                  * beyond of the +-128MB space. Apply relocation with | ||||
|                  * the PLT which branch to the target symbol address. | ||||
|                  */ | ||||
|                 S = plt = (uint8*)module->code + module->code_size | ||||
|                 S = plt = (uint8 *)module->code + module->code_size | ||||
|                           - get_plt_table_size() | ||||
|                           + get_plt_item_size() * symbol_index; | ||||
|             } | ||||
|  | @ -191,7 +195,7 @@ apply_relocation(AOTModule *module, | |||
|             } | ||||
| 
 | ||||
|             /* write the imm26 back to instruction */ | ||||
|             *(int32*)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF)); | ||||
|             *(int32 *)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF)); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -203,13 +207,14 @@ 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; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             insn = *(int32*)P; | ||||
|             insn = *(int32 *)P; | ||||
|             imm16 = (insn >> 5) & 0xFFFF; | ||||
| 
 | ||||
|             SIGN_EXTEND_TO_INT64(imm16, 16, initial_addend); | ||||
|  | @ -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,13 +273,14 @@ 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; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             insn = *(int32*)P; | ||||
|             insn = *(int32 *)P; | ||||
|             immhi19 = (insn >> 5) & 0x7FFFF; | ||||
|             immlo2 = (insn >> 29) & 0x3; | ||||
|             imm21 = (immhi19 << 2) | immlo2; | ||||
|  | @ -290,20 +300,21 @@ apply_relocation(AOTModule *module, | |||
|             /* write the imm21 back to instruction */ | ||||
|             immhi19 = (int32)(((X >> 12) >> 2) & 0x7FFFF); | ||||
|             immlo2 = (int32)((X >> 12) & 0x3); | ||||
|             *(int32*)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5); | ||||
|             *(int32 *)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5); | ||||
| 
 | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         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; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             insn = *(int32*)P; | ||||
|             insn = *(int32 *)P; | ||||
|             imm12 = (insn >> 10) & 0xFFF; | ||||
| 
 | ||||
|             SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend); | ||||
|  | @ -316,7 +327,7 @@ apply_relocation(AOTModule *module, | |||
|             /* No need to check overflow for this reloction type */ | ||||
| 
 | ||||
|             /* write the imm12 back to instruction */ | ||||
|             *(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10)); | ||||
|             *(int32 *)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10)); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -326,13 +337,14 @@ 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; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             insn = *(int32*)P; | ||||
|             insn = *(int32 *)P; | ||||
|             imm12 = (insn >> 10) & 0xFFF; | ||||
| 
 | ||||
|             SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend); | ||||
|  | @ -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); | ||||
|  |  | |||
|  | @ -5,13 +5,14 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_ARC_S21H_PCREL    14 | ||||
| #define R_ARC_S21W_PCREL    15 | ||||
| #define R_ARC_S25H_PCREL    16 | ||||
| #define R_ARC_S25W_PCREL    17 | ||||
| #define R_ARC_32            4 | ||||
| #define R_ARC_32_ME         27 | ||||
| #define R_ARC_S21H_PCREL 14 | ||||
| #define R_ARC_S21W_PCREL 15 | ||||
| #define R_ARC_S25H_PCREL 16 | ||||
| #define R_ARC_S25W_PCREL 17 | ||||
| #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), | ||||
|  | @ -81,29 +85,28 @@ static SymbolMap target_sym_map[] = { | |||
|     REG_SYM(__ld_r13_to_r23), | ||||
|     REG_SYM(__ld_r13_to_r24), | ||||
|     REG_SYM(__ld_r13_to_r25), | ||||
|     REG_SYM (__adddf3), | ||||
|     REG_SYM (__addsf3), | ||||
|     REG_SYM (__divdf3), | ||||
|     REG_SYM (__divdi3), | ||||
|     REG_SYM (__divsf3), | ||||
|     REG_SYM (__divsi3), | ||||
|     REG_SYM (__eqsf2), | ||||
|     REG_SYM (__extendsfdf2), | ||||
|     REG_SYM (__fixdfsi), | ||||
|     REG_SYM (__floatsidf), | ||||
|     REG_SYM (__floatsisf), | ||||
|     REG_SYM (__gedf2), | ||||
|     REG_SYM (__gtdf2), | ||||
|     REG_SYM (__ledf2), | ||||
|     REG_SYM (__lesf2), | ||||
|     REG_SYM (__ltdf2), | ||||
|     REG_SYM (__muldf3), | ||||
|     REG_SYM (__mulsf3), | ||||
|     REG_SYM (__subdf3), | ||||
|     REG_SYM (__subsf3), | ||||
|     REG_SYM (__truncdfsf2), | ||||
|     REG_SYM (__unorddf2), | ||||
| 
 | ||||
|     REG_SYM(__adddf3), | ||||
|     REG_SYM(__addsf3), | ||||
|     REG_SYM(__divdf3), | ||||
|     REG_SYM(__divdi3), | ||||
|     REG_SYM(__divsf3), | ||||
|     REG_SYM(__divsi3), | ||||
|     REG_SYM(__eqsf2), | ||||
|     REG_SYM(__extendsfdf2), | ||||
|     REG_SYM(__fixdfsi), | ||||
|     REG_SYM(__floatsidf), | ||||
|     REG_SYM(__floatsisf), | ||||
|     REG_SYM(__gedf2), | ||||
|     REG_SYM(__gtdf2), | ||||
|     REG_SYM(__ledf2), | ||||
|     REG_SYM(__lesf2), | ||||
|     REG_SYM(__ltdf2), | ||||
|     REG_SYM(__muldf3), | ||||
|     REG_SYM(__mulsf3), | ||||
|     REG_SYM(__subdf3), | ||||
|     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: | ||||
|  | @ -172,7 +174,7 @@ apply_relocation(AOTModule *module, | |||
|             int32 addend, value; | ||||
|             uintptr_t S, A, P; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(void*)); | ||||
|             CHECK_RELOC_OFFSET(sizeof(void *)); | ||||
| 
 | ||||
|             /* Convert from middle endian */ | ||||
|             insn = middle_endian_convert(insn); | ||||
|  | @ -187,7 +189,7 @@ apply_relocation(AOTModule *module, | |||
|             addend = addend << 2; | ||||
| 
 | ||||
|             /* (S + A) - P */ | ||||
|             S = (uintptr_t)(uint8*)symbol_addr; | ||||
|             S = (uintptr_t)(uint8 *)symbol_addr; | ||||
|             A = (uintptr_t)reloc_addend; | ||||
|             P = (uintptr_t)(target_section_addr + reloc_offset); | ||||
|             P &= (uintptr_t)~3; | ||||
|  | @ -209,11 +211,10 @@ apply_relocation(AOTModule *module, | |||
|         { | ||||
|             uint32 insn; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(void*)); | ||||
|             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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,10 +5,11 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_ARM_CALL      28  /* PC relative 24 bit (BL, BLX).  */ | ||||
| #define R_ARM_JMP24     29  /* PC relative 24 bit (B/BL<cond>).  */ | ||||
| #define R_ARM_ABS32     2   /* Direct 32 bit */ | ||||
| #define R_ARM_CALL 28  /* PC relative 24 bit (BL, BLX).  */ | ||||
| #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), | ||||
|  | @ -122,7 +126,7 @@ get_target_symbol_map(uint32 *sym_num) | |||
| void | ||||
| get_current_target(char *target_buf, uint32 target_buf_size) | ||||
| { | ||||
|     const char * s =  BUILD_TARGET; | ||||
|     const char *s = BUILD_TARGET; | ||||
|     size_t s_size = sizeof(BUILD_TARGET); | ||||
|     char *d = target_buf; | ||||
| 
 | ||||
|  | @ -131,14 +135,14 @@ get_current_target(char *target_buf, uint32 target_buf_size) | |||
|         s = BUILD_TARGET_ARM_DEFAULT; | ||||
|         s_size = sizeof(BUILD_TARGET_ARM_DEFAULT); | ||||
|     } | ||||
|     if(target_buf_size < s_size){ | ||||
|     if (target_buf_size < s_size) { | ||||
|         s_size = target_buf_size; | ||||
|     } | ||||
|     while (--s_size) { | ||||
|         if (*s >= 'A' && *s <= 'Z') | ||||
|             *d++ = *s++ + 'a' - 'A'; | ||||
|         else | ||||
|             *d++ = *s++ ; | ||||
|             *d++ = *s++; | ||||
|     } | ||||
|     /* Ensure the string is null byte ('\0') terminated */ | ||||
|     *d = '\0'; | ||||
|  | @ -163,7 +167,7 @@ init_plt_table(uint8 *plt) | |||
| { | ||||
|     uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap); | ||||
|     for (i = 0; i < num; i++) { | ||||
|         uint32 *p = (uint32*)plt; | ||||
|         uint32 *p = (uint32 *)plt; | ||||
|         /* ldr pc, [pc] */ | ||||
|         *p++ = 0xe59ff000; | ||||
|         /* nop */ | ||||
|  | @ -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: | ||||
|  | @ -201,10 +204,10 @@ apply_relocation(AOTModule *module, | |||
|         { | ||||
|             intptr_t result; | ||||
|             int32 RESULT_MASK = 0x03FFFFFE; | ||||
|             int32 insn = *(int32*)(target_section_addr + reloc_offset); | ||||
|             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,17 +217,18 @@ 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 | ||||
|                           - (target_section_addr + reloc_offset)); | ||||
|                 /* 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, | ||||
|                                    "AOT module load failed: relocate to plt table " | ||||
|                                    "with reloc addend larger than 0 is unsupported."); | ||||
|                      return false; | ||||
|                     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; | ||||
|                 } | ||||
| 
 | ||||
|                 /* Symbol address is not an AOT function,
 | ||||
|  | @ -232,12 +236,13 @@ 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 | ||||
|                           - (target_section_addr + reloc_offset)); | ||||
|                 result = (intptr_t)(plt + reloc_addend | ||||
|                                     - (target_section_addr + reloc_offset)); | ||||
|             } | ||||
| 
 | ||||
|             result += initial_addend; | ||||
|  | @ -250,20 +255,20 @@ apply_relocation(AOTModule *module, | |||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             *(int32*)(target_section_addr + reloc_offset) = | ||||
|                 (int32) | ||||
|                 ((insn & 0xff000000) | ||||
|                  | (((int32)result & RESULT_MASK) >> 2)); | ||||
|             *(int32 *)(target_section_addr + reloc_offset) = | ||||
|                 (int32)((insn & 0xff000000) | ||||
|                         | (((int32)result & RESULT_MASK) >> 2)); | ||||
|             break; | ||||
|         } | ||||
|         case R_ARM_ABS32: | ||||
|         { | ||||
|             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; | ||||
|             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; | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -278,4 +283,3 @@ apply_relocation(AOTModule *module, | |||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,12 +5,14 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_MIPS_32       2   /* Direct 32 bit */ | ||||
| #define R_MIPS_26       4   /* Direct 26 bit shifted */ | ||||
| #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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,25 +5,29 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_RISCV_32       1 | ||||
| #define R_RISCV_64       2 | ||||
| #define R_RISCV_CALL     18 | ||||
| #define R_RISCV_32 1 | ||||
| #define R_RISCV_64 2 | ||||
| #define R_RISCV_CALL 18 | ||||
| #define R_RISCV_CALL_PLT 19 | ||||
| #define R_RISCV_HI20     26 | ||||
| #define R_RISCV_LO12_I   27 | ||||
| #define R_RISCV_LO12_S   28 | ||||
| #define R_RISCV_HI20 26 | ||||
| #define R_RISCV_LO12_I 27 | ||||
| #define R_RISCV_LO12_S 28 | ||||
| 
 | ||||
| #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), | ||||
|  | @ -132,20 +136,20 @@ init_plt_table(uint8 *plt) | |||
|     for (i = 0; i < num; i++) { | ||||
|         p = plt; | ||||
|         /* auipc t1, 0 */ | ||||
|         *(uint16*)p = 0x0317; | ||||
|         *(uint16 *)p = 0x0317; | ||||
|         p += 2; | ||||
|         *(uint16*)p = 0x0000; | ||||
|         *(uint16 *)p = 0x0000; | ||||
|         p += 2; | ||||
|         /* ld t1, 8(t1) */ | ||||
|         *(uint16*)p = 0x3303; | ||||
|         *(uint16 *)p = 0x3303; | ||||
|         p += 2; | ||||
|         *(uint16*)p = 0x00C3; | ||||
|         *(uint16 *)p = 0x00C3; | ||||
|         p += 2; | ||||
|         /* jr t1 */ | ||||
|         *(uint16*)p = 0x8302; | ||||
|         *(uint16 *)p = 0x8302; | ||||
|         p += 2; | ||||
|         /* nop */ | ||||
|         *(uint16*)p = 0x0001; | ||||
|         *(uint16 *)p = 0x0001; | ||||
|         p += 2; | ||||
|         bh_memcpy_s(p, 8, &target_sym_map[i].symbol_addr, 8); | ||||
|         p += 8; | ||||
|  | @ -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; | ||||
|  | @ -237,10 +243,10 @@ apply_relocation(AOTModule *module, | |||
|             if (val != (intptr_t)((uint8 *)symbol_addr - addr)) { | ||||
|                 if (symbol_index >= 0) { | ||||
|                     /* Call runtime function by plt code */ | ||||
|                     symbol_addr = (uint8*)module->code + module->code_size | ||||
|                     symbol_addr = (uint8 *)module->code + module->code_size | ||||
|                                   - get_plt_table_size() | ||||
|                                   + get_plt_item_size() * symbol_index; | ||||
|                     val = (int32)(intptr_t)((uint8*)symbol_addr - addr); | ||||
|                     val = (int32)(intptr_t)((uint8 *)symbol_addr - addr); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|  | @ -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; | ||||
|         } | ||||
|  |  | |||
|  | @ -5,9 +5,10 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_ARM_THM_CALL  10  /* PC relative (Thumb BL and ARMv5 Thumb BLX). */ | ||||
| #define R_ARM_THM_JMP24 30  /* B.W */ | ||||
| #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), | ||||
|  | @ -162,14 +166,14 @@ get_current_target(char *target_buf, uint32 target_buf_size) | |||
|         s = BUILD_TARGET_THUMB_V4T; | ||||
|         s_size = sizeof(BUILD_TARGET_THUMB_V4T); | ||||
|     } | ||||
|     if(target_buf_size < s_size){ | ||||
|     if (target_buf_size < s_size) { | ||||
|         s_size = target_buf_size; | ||||
|     } | ||||
|     while (--s_size) { | ||||
|         if (*s >= 'A' && *s <= 'Z') | ||||
|             *d++ = *s++ + 'a' - 'A'; | ||||
|         else | ||||
|             *d++ = *s++ ; | ||||
|             *d++ = *s++; | ||||
|     } | ||||
|     /* Ensure the string is null byte ('\0') terminated */ | ||||
|     *d = '\0'; | ||||
|  | @ -194,7 +198,7 @@ init_plt_table(uint8 *plt) | |||
| { | ||||
|     uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap); | ||||
|     for (i = 0; i < num; i++) { | ||||
|         uint16 *p = (uint16*)plt; | ||||
|         uint16 *p = (uint16 *)plt; | ||||
|         /* nop */ | ||||
|         *p++ = 0xbf00; | ||||
|         /* push {r4} */ | ||||
|  | @ -212,15 +216,15 @@ init_plt_table(uint8 *plt) | |||
|         /* nop */ | ||||
|         *p++ = 0xbf00; | ||||
|         /* symbol addr */ | ||||
|         *(uint32*)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         *(uint32 *)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         plt += get_plt_item_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)) { | ||||
|  | @ -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: | ||||
|  | @ -250,7 +253,7 @@ apply_relocation(AOTModule *module, | |||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|             reloc_addr = (int16*)(target_section_addr + reloc_offset); | ||||
|             reloc_addr = (int16 *)(target_section_addr + reloc_offset); | ||||
|             initial_addend_0 = (*reloc_addr) & 0x7FF; | ||||
|             initial_addend_1 = (*(reloc_addr + 1)) & 0x7FF; | ||||
|             sign = (initial_addend_0 & 0x400) ? true : false; | ||||
|  | @ -263,16 +266,20 @@ 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) | ||||
|                                  - (intptr_t)(target_section_addr + reloc_offset)); | ||||
|                 /* 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, | ||||
|                                    "AOT module load failed: relocate to plt table " | ||||
|                                    "with reloc addend larger than 0 is unsupported."); | ||||
|                      return false; | ||||
|                     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; | ||||
|                 } | ||||
| 
 | ||||
|                 /* Symbol address is not an AOT function,
 | ||||
|  | @ -280,11 +287,14 @@ 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) | ||||
|                                  - (intptr_t)(target_section_addr + reloc_offset)); | ||||
|                 result = | ||||
|                     (int32)(((intptr_t)plt | 1) | ||||
|                             - (intptr_t)(target_section_addr + reloc_offset)); | ||||
|             } | ||||
| 
 | ||||
|             result += initial_addend; | ||||
|  | @ -316,4 +326,3 @@ apply_relocation(AOTModule *module, | |||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,17 +5,19 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_386_32        1   /* Direct 32 bit  */ | ||||
| #define R_386_PC32      2   /* PC relative 32 bit */ | ||||
| #define R_386_32 1   /* Direct 32 bit  */ | ||||
| #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) | ||||
| #pragma function(floor) | ||||
| #pragma function(ceil) | ||||
| 
 | ||||
| static int64 | ||||
| __divdi3(int64 a, int64 b) | ||||
|  | @ -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,21 +102,20 @@ 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: | ||||
|         { | ||||
|             intptr_t value; | ||||
| 
 | ||||
|             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 */ | ||||
|             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 */ | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -120,12 +123,12 @@ apply_relocation(AOTModule *module, | |||
|         { | ||||
|             int32 value; | ||||
| 
 | ||||
|             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 | ||||
|                  - (uint8*)(target_section_addr + (uint32)reloc_offset) | ||||
|                  + value);  /* S + A - P */ | ||||
|             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 | ||||
|                          - (uint8 *)(target_section_addr + (uint32)reloc_offset) | ||||
|                          + value); /* S + A - P */ | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -139,4 +142,3 @@ apply_relocation(AOTModule *module, | |||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,30 +6,34 @@ | |||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #if !defined(BH_PLATFORM_WINDOWS) | ||||
| #define R_X86_64_64    1  /* Direct 64 bit  */ | ||||
| #define R_X86_64_PC32  2  /* PC relative 32 bit signed */ | ||||
| #define R_X86_64_PLT32 4  /* 32 bit PLT address */ | ||||
| #define R_X86_64_32    10 /* Direct 32 bit zero extended */ | ||||
| #define R_X86_64_32S   11 /* Direct 32 bit sign extended */ | ||||
| #define R_X86_64_64 1    /* Direct 64 bit  */ | ||||
| #define R_X86_64_PC32 2  /* PC relative 32 bit signed */ | ||||
| #define R_X86_64_PLT32 4 /* 32 bit PLT address */ | ||||
| #define R_X86_64_32 10   /* Direct 32 bit zero extended */ | ||||
| #define R_X86_64_32S 11  /* Direct 32 bit sign extended */ | ||||
| #else | ||||
| #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 | ||||
| 
 | ||||
| #if defined(BH_PLATFORM_WINDOWS) | ||||
| #pragma function (floor) | ||||
| #pragma function (ceil) | ||||
| #pragma function (floorf) | ||||
| #pragma function (ceilf) | ||||
| #pragma function(floor) | ||||
| #pragma function(ceil) | ||||
| #pragma function(floorf) | ||||
| #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 | ||||
|  | @ -80,7 +84,7 @@ init_plt_table(uint8 *plt) | |||
|         /* mov symbol_addr, rax */ | ||||
|         *p++ = 0x48; | ||||
|         *p++ = 0xB8; | ||||
|         *(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         *(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr; | ||||
|         p += sizeof(uint64); | ||||
|         /* jmp rax */ | ||||
|         *p++ = 0xFF; | ||||
|  | @ -92,19 +96,19 @@ init_plt_table(uint8 *plt) | |||
|     p = plt; | ||||
|     /* mov exception_handler, rax */ | ||||
|     *p++ = 0x48; | ||||
| 	*p++ = 0xB8; | ||||
|     *(uint64*)p = 0;/*(uint64)(uintptr_t)aot_exception_handler;*/ | ||||
|     *p++ = 0xB8; | ||||
|     *(uint64 *)p = 0; /*(uint64)(uintptr_t)aot_exception_handler;*/ | ||||
|     p += sizeof(uint64); | ||||
|     /* jmp rax */ | ||||
| 	*p++ = 0xFF; | ||||
| 	*p++ = 0xE0; | ||||
|     *p++ = 0xFF; | ||||
|     *p++ = 0xE0; | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| 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) | ||||
|  | @ -131,10 +134,10 @@ apply_relocation(AOTModule *module, | |||
|         { | ||||
|             intptr_t value; | ||||
| 
 | ||||
|             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 */ | ||||
|             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 */ | ||||
|             break; | ||||
|         } | ||||
| #if defined(BH_PLATFORM_WINDOWS) | ||||
|  | @ -144,14 +147,14 @@ apply_relocation(AOTModule *module, | |||
|             uintptr_t target_addr; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(void *)); | ||||
|             value = *(int32*)(target_section_addr + (uint32)reloc_offset); | ||||
|             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, | ||||
|                   "AOT module load failed: " | ||||
|                   "relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. " | ||||
|                   "Try using wamrc with --size-level=1 option."); | ||||
|                 set_error_buf(error_buf, error_buf_size, | ||||
|                               "AOT module load failed: " | ||||
|                               "relocation truncated to fit " | ||||
|                               "IMAGE_REL_AMD64_ADDR32 failed. " | ||||
|                               "Try using wamrc with --size-level=1 option."); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|  | @ -162,20 +165,21 @@ apply_relocation(AOTModule *module, | |||
| #if !defined(BH_PLATFORM_WINDOWS) | ||||
|         case R_X86_64_PC32: | ||||
|         { | ||||
|             intptr_t target_addr = (intptr_t)   /* S + A - P */ | ||||
|                                    ((uint8*)symbol_addr + reloc_addend | ||||
|                                     - (target_section_addr + reloc_offset)); | ||||
|             intptr_t target_addr = (intptr_t) /* S + A - P */ | ||||
|                 ((uint8 *)symbol_addr + reloc_addend | ||||
|                  - (target_section_addr + reloc_offset)); | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
|             if ((int32)target_addr != target_addr) { | ||||
|                 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."); | ||||
|                 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."); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             *(int32*)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             *(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             break; | ||||
|         } | ||||
|         case R_X86_64_32: | ||||
|  | @ -183,7 +187,7 @@ apply_relocation(AOTModule *module, | |||
|         { | ||||
|             char buf[128]; | ||||
|             uintptr_t target_addr = (uintptr_t) /* S + A */ | ||||
|                                     ((uint8*)symbol_addr + reloc_addend); | ||||
|                 ((uint8 *)symbol_addr + reloc_addend); | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(sizeof(int32)); | ||||
| 
 | ||||
|  | @ -192,16 +196,16 @@ apply_relocation(AOTModule *module, | |||
|                 || (reloc_type == R_X86_64_32S | ||||
|                     && (int32)target_addr != (int64)target_addr)) { | ||||
|                 snprintf(buf, sizeof(buf), | ||||
|                         "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"); | ||||
|                          "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"); | ||||
|                 set_error_buf(error_buf, error_buf_size, buf); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             *(int32*)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             *(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             break; | ||||
|         } | ||||
| #endif | ||||
|  | @ -217,16 +221,16 @@ 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)); | ||||
|                 target_addr = (intptr_t) /* L + A - P */ | ||||
|                     (plt + reloc_addend - (target_section_addr + reloc_offset)); | ||||
|             } | ||||
|             else { | ||||
|                 target_addr = (intptr_t)   /* L + A - P */ | ||||
|                               ((uint8*)symbol_addr + reloc_addend | ||||
|                                - (target_section_addr + reloc_offset)); | ||||
|                 target_addr = (intptr_t) /* L + A - P */ | ||||
|                     ((uint8 *)symbol_addr + reloc_addend | ||||
|                      - (target_section_addr + reloc_offset)); | ||||
|             } | ||||
| 
 | ||||
| #if defined(BH_PLATFORM_WINDOWS) | ||||
|  | @ -244,7 +248,7 @@ apply_relocation(AOTModule *module, | |||
|                               "Try using wamrc with --size-level=1 option."); | ||||
|                 return false; | ||||
|             } | ||||
|             *(int32*)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             *(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr; | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -259,4 +263,3 @@ apply_relocation(AOTModule *module, | |||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,9 +5,10 @@ | |||
| 
 | ||||
| #include "aot_reloc.h" | ||||
| 
 | ||||
| #define R_XTENSA_32        1   /* Direct 32 bit */ | ||||
| #define R_XTENSA_SLOT0_OP  20  /* PC relative */ | ||||
| #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)) { | ||||
|  | @ -106,18 +107,18 @@ put_imm16_to_addr(int16 imm16, int16 *addr) | |||
|     int8 bytes[8]; | ||||
|     int32 *addr_aligned1, *addr_aligned2; | ||||
| 
 | ||||
|     addr_aligned1 = (int32*)((intptr_t)addr & ~3); | ||||
|     addr_aligned1 = (int32 *)((intptr_t)addr & ~3); | ||||
| 
 | ||||
|     if ((intptr_t)addr % 4 != 3) { | ||||
|         *(int32*)bytes = *addr_aligned1; | ||||
|         *(int16*)(bytes + ((intptr_t)addr % 4)) = imm16; | ||||
|         *(int32 *)bytes = *addr_aligned1; | ||||
|         *(int16 *)(bytes + ((intptr_t)addr % 4)) = imm16; | ||||
|         memcpy(addr_aligned1, bytes, 4); | ||||
|     } | ||||
|     else { | ||||
|         addr_aligned2 = (int32*)(((intptr_t)addr + 3) & ~3); | ||||
|         *(int32*)bytes = *addr_aligned1; | ||||
|         *(int32*)(bytes + 4) = *addr_aligned2; | ||||
|         *(int16*)(bytes + 3) = imm16; | ||||
|         addr_aligned2 = (int32 *)(((intptr_t)addr + 3) & ~3); | ||||
|         *(int32 *)bytes = *addr_aligned1; | ||||
|         *(int32 *)(bytes + 4) = *addr_aligned2; | ||||
|         *(int16 *)(bytes + 3) = imm16; | ||||
|         memcpy(addr_aligned1, bytes, 8); | ||||
|     } | ||||
| } | ||||
|  | @ -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: | ||||
|  | @ -161,19 +161,20 @@ apply_relocation(AOTModule *module, | |||
|                 return false; | ||||
|             } | ||||
|             CHECK_RELOC_OFFSET(4); | ||||
|             initial_addend = *(int32*)insn_addr; | ||||
|             *(uint8**)insn_addr | ||||
|                 = (uint8*)symbol_addr + initial_addend + reloc_addend; | ||||
|             initial_addend = *(int32 *)insn_addr; | ||||
|             *(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 */; | ||||
|             int32 relative_offset /*, initial_addend */; | ||||
|             int16 imm16; | ||||
| 
 | ||||
|             CHECK_RELOC_OFFSET(3); /* size of l32r instruction */ | ||||
|  | @ -184,7 +185,7 @@ apply_relocation(AOTModule *module, | |||
|             initial_addend = (int32)imm16 << 2; | ||||
|             */ | ||||
| 
 | ||||
|             reloc_addr = (uint8*)symbol_addr + reloc_addend; | ||||
|             reloc_addr = (uint8 *)symbol_addr + reloc_addend; | ||||
| 
 | ||||
|             if ((intptr_t)reloc_addr & 3) { | ||||
|                 set_error_buf(error_buf, error_buf_size, | ||||
|  | @ -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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -114,12 +114,13 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size) | |||
|         if (sh_table) { | ||||
|             read_section_header_table64(eh, sh_table); | ||||
|             sh_str = get_section64(eh, sh_table[eh->e_shstrndx]); | ||||
|             for (i= 0; i < eh->e_shnum; i++) { | ||||
|             for (i = 0; i < eh->e_shnum; i++) { | ||||
|                 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; | ||||
|                 } | ||||
|  | @ -134,12 +135,13 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size) | |||
|         if (sh_table) { | ||||
|             read_section_header_table(eh, sh_table); | ||||
|             sh_str = get_section(eh, sh_table[eh->e_shstrndx]); | ||||
|             for (i= 0; i < eh->e_shnum; i++) { | ||||
|             for (i = 0; i < eh->e_shnum; i++) { | ||||
|                 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; | ||||
|                 } | ||||
|  |  | |||
|  | @ -12,14 +12,14 @@ | |||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *  | ||||
|  * | ||||
|  * Copyright (C) 2021 Ant Group.  All rights reserved. | ||||
|  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
|  */ | ||||
| 
 | ||||
| #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,11 +6,12 @@ | |||
| #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)); | ||||
|     bh_assert(argc >= sizeof(WASMExecEnv *) / sizeof(uint32)); | ||||
| 
 | ||||
|     switch(argc) { | ||||
|     switch (argc) { | ||||
|         case 0: | ||||
|             native_code(); | ||||
|             break; | ||||
|  | @ -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; | ||||
|             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; | ||||
|     } | ||||
|  | @ -52,29 +49,31 @@ static union { | |||
|  * Implementation of wasm_application_execute_main() | ||||
|  */ | ||||
| 
 | ||||
| static WASMFunctionInstanceCommon* | ||||
| resolve_function(const WASMModuleInstanceCommon *module_inst, | ||||
|                  const char *name); | ||||
| static WASMFunctionInstanceCommon * | ||||
| 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"); | ||||
|         || type->result_count > 1) { | ||||
|         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"); | ||||
|              && type->types[1] == VALUE_TYPE_I32)) { | ||||
|         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,25 +112,23 @@ 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; | ||||
|     } | ||||
| 
 | ||||
| #if WASM_ENABLE_INTERP != 0 | ||||
|     if (module_inst->module_type == Wasm_Module_Bytecode) { | ||||
|         is_import_func = ((WASMFunctionInstance*)func)->is_import_func; | ||||
|         is_import_func = ((WASMFunctionInstance *)func)->is_import_func; | ||||
|     } | ||||
| #endif | ||||
| #if WASM_ENABLE_AOT != 0 | ||||
|     if (module_inst->module_type == Wasm_Module_AoT) { | ||||
|         is_import_func = ((AOTFunctionInstance*)func)->is_import_func; | ||||
|         is_import_func = ((AOTFunctionInstance *)func)->is_import_func; | ||||
|     } | ||||
| #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,34 +154,34 @@ 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; | ||||
|         } | ||||
| 
 | ||||
|         p = argv_buf; | ||||
|         argv_offsets = (uint32*)(p + total_argv_size); | ||||
|         argv_offsets = (uint32 *)(p + total_argv_size); | ||||
|         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]; | ||||
|         *(int *)argv = (int)argv1[0]; | ||||
| 
 | ||||
|     if (argv_buf_offset) | ||||
|         wasm_runtime_module_free(module_inst, argv_buf_offset); | ||||
|  | @ -197,7 +194,7 @@ get_sub_module_inst(const WASMModuleInstance *parent_module_inst, | |||
|                     const char *sub_module_name) | ||||
| { | ||||
|     WASMSubModInstNode *node = | ||||
|       bh_list_first_elem(parent_module_inst->sub_module_inst_list); | ||||
|         bh_list_first_elem(parent_module_inst->sub_module_inst_list); | ||||
| 
 | ||||
|     while (node && strcmp(node->module_name, sub_module_name)) { | ||||
|         node = bh_list_elem_next(node); | ||||
|  | @ -241,9 +238,8 @@ parse_function_name(char *orig_function_name, char **p_module_name, | |||
|  * Implementation of wasm_application_execute_func() | ||||
|  */ | ||||
| 
 | ||||
| static WASMFunctionInstanceCommon* | ||||
| resolve_function(const WASMModuleInstanceCommon *module_inst, | ||||
|                  const char *name) | ||||
| static WASMFunctionInstanceCommon * | ||||
| 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; | ||||
|  | @ -281,26 +277,26 @@ resolve_function(const WASMModuleInstanceCommon *module_inst, | |||
| 
 | ||||
| #if WASM_ENABLE_INTERP != 0 | ||||
|     if (module_inst->module_type == Wasm_Module_Bytecode) { | ||||
|         WASMModuleInstance *wasm_inst = (WASMModuleInstance*)module_inst; | ||||
|         WASMModuleInstance *wasm_inst = (WASMModuleInstance *)module_inst; | ||||
| 
 | ||||
| #if WASM_ENABLE_MULTI_MODULE != 0 | ||||
|         wasm_inst = sub_module_inst ? sub_module_inst : wasm_inst; | ||||
| #endif /* WASM_ENABLE_MULTI_MODULE */ | ||||
| 
 | ||||
|         for (i = 0; i < wasm_inst->export_func_count; i++) { | ||||
|            if (!strcmp(wasm_inst->export_functions[i].name, function_name)) { | ||||
|             if (!strcmp(wasm_inst->export_functions[i].name, function_name)) { | ||||
|                 ret = wasm_inst->export_functions[i].function; | ||||
|                 break; | ||||
|            } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| #endif /* WASM_ENABLE_INTERP */ | ||||
| 
 | ||||
| #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; | ||||
|         AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst; | ||||
|         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]; | ||||
|  | @ -323,14 +319,14 @@ union ieee754_float { | |||
|     /* This is the IEEE 754 single-precision format.  */ | ||||
|     union { | ||||
|         struct { | ||||
|             unsigned int negative:1; | ||||
|             unsigned int exponent:8; | ||||
|             unsigned int mantissa:23; | ||||
|             unsigned int negative : 1; | ||||
|             unsigned int exponent : 8; | ||||
|             unsigned int mantissa : 23; | ||||
|         } ieee_big_endian; | ||||
|         struct { | ||||
|             unsigned int mantissa:23; | ||||
|             unsigned int exponent:8; | ||||
|             unsigned int negative:1; | ||||
|             unsigned int mantissa : 23; | ||||
|             unsigned int exponent : 8; | ||||
|             unsigned int negative : 1; | ||||
|         } ieee_little_endian; | ||||
|     } ieee; | ||||
| }; | ||||
|  | @ -341,19 +337,19 @@ union ieee754_double { | |||
|     /* This is the IEEE 754 double-precision format.  */ | ||||
|     union { | ||||
|         struct { | ||||
|             unsigned int negative:1; | ||||
|             unsigned int exponent:11; | ||||
|             unsigned int negative : 1; | ||||
|             unsigned int exponent : 11; | ||||
|             /* Together these comprise the mantissa.  */ | ||||
|             unsigned int mantissa0:20; | ||||
|             unsigned int mantissa1:32; | ||||
|             unsigned int mantissa0 : 20; | ||||
|             unsigned int mantissa1 : 32; | ||||
|         } ieee_big_endian; | ||||
| 
 | ||||
|         struct { | ||||
|             /* Together these comprise the mantissa.  */ | ||||
|             unsigned int mantissa1:32; | ||||
|             unsigned int mantissa0:20; | ||||
|             unsigned int exponent:11; | ||||
|             unsigned int negative:1; | ||||
|             unsigned int mantissa1 : 32; | ||||
|             unsigned int mantissa0 : 20; | ||||
|             unsigned int exponent : 11; | ||||
|             unsigned int negative : 1; | ||||
|         } ieee_little_endian; | ||||
|     } ieee; | ||||
| }; | ||||
|  | @ -382,7 +378,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst, | |||
| 
 | ||||
| #if WASM_ENABLE_INTERP != 0 | ||||
|     if (module_inst->module_type == Wasm_Module_Bytecode) { | ||||
|         WASMFunctionInstance *wasm_func = (WASMFunctionInstance*)func; | ||||
|         WASMFunctionInstance *wasm_func = (WASMFunctionInstance *)func; | ||||
|         if (wasm_func->is_import_func | ||||
| #if WASM_ENABLE_MULTI_MODULE != 0 | ||||
|             && !wasm_func->import_func_inst | ||||
|  | @ -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] == '-') { | ||||
|  | @ -506,11 +506,11 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst, | |||
|             { | ||||
|                 /* it likes 0x123\0x234 or 123\234 */ | ||||
|                 /* retrive first i64 */ | ||||
|                 *(uint64*)(argv1 + p) = strtoull(argv[i], &endptr, 0); | ||||
|                 *(uint64 *)(argv1 + p) = strtoull(argv[i], &endptr, 0); | ||||
|                 /* skip \ */ | ||||
|                 endptr++; | ||||
|                 /* retrive second i64 */ | ||||
|                 *(uint64*)(argv1 + p + 2) = strtoull(endptr, &endptr, 0); | ||||
|                 *(uint64 *)(argv1 + p + 2) = strtoull(endptr, &endptr, 0); | ||||
|                 p += 4; | ||||
|                 break; | ||||
|             } | ||||
|  | @ -541,7 +541,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst, | |||
|                     if (!wasm_externref_obj2ref(module_inst, extern_obj, | ||||
|                                                 &externref_idx)) { | ||||
|                         wasm_runtime_set_exception( | ||||
|                           module_inst, "map extern object to ref failed"); | ||||
|                             module_inst, "map extern object to ref failed"); | ||||
|                         goto fail; | ||||
|                     } | ||||
|                     argv1[p++] = externref_idx; | ||||
|  | @ -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,12 +579,15 @@ 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; | ||||
| #ifdef PRIx64 | ||||
|                 os_printf("0x%"PRIx64":i64", u.val); | ||||
|                 os_printf("0x%" PRIx64 ":i64", u.val); | ||||
| #else | ||||
|                 char buf[16]; | ||||
|                 if (sizeof(long) == 4) | ||||
|  | @ -597,13 +600,16 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst, | |||
|             } | ||||
|             case VALUE_TYPE_F32: | ||||
|             { | ||||
|                 os_printf("%.7g:f32", *(float32*)(argv1 + k)); | ||||
|                 os_printf("%.7g:f32", *(float32 *)(argv1 + k)); | ||||
|                 k++; | ||||
|                 break; | ||||
|             } | ||||
|             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; | ||||
|  | @ -638,9 +644,10 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst, | |||
| #if WASM_ENABLE_SIMD != 0 | ||||
|             case VALUE_TYPE_V128: | ||||
|             { | ||||
|                 uint64 *v = (uint64*)(argv1 + k); | ||||
|                 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)); | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -89,7 +89,7 @@ typedef struct WASMExecEnv { | |||
|     void *thread_ret_value; | ||||
| 
 | ||||
|     /* Must be provided by thread library */ | ||||
|     void* (*thread_start_routine)(void *); | ||||
|     void *(*thread_start_routine)(void *); | ||||
|     void *thread_arg; | ||||
| 
 | ||||
|     /* pointer to the cluster */ | ||||
|  | @ -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; | ||||
|     } | ||||
|  | @ -215,7 +215,7 @@ wasm_exec_env_free_wasm_frame(WASMExecEnv *exec_env, void *prev_top) | |||
|  * | ||||
|  * @return the current WASM stack top pointer | ||||
|  */ | ||||
| static inline void* | ||||
| static inline void * | ||||
| wasm_exec_env_wasm_stack_top(WASMExecEnv *exec_env) | ||||
| { | ||||
|     return exec_env->wasm_stack.s.top; | ||||
|  | @ -241,7 +241,7 @@ wasm_exec_env_set_cur_frame(WASMExecEnv *exec_env, | |||
|  * | ||||
|  * @return the current frame pointer | ||||
|  */ | ||||
| static inline struct WASMInterpFrame* | ||||
| static inline struct WASMInterpFrame * | ||||
| wasm_exec_env_get_cur_frame(WASMExecEnv *exec_env) | ||||
| { | ||||
|     return exec_env->cur_frame; | ||||
|  | @ -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,9 +62,10 @@ 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, | ||||
|                                                alloc_option->allocator.realloc_func, | ||||
|                                                alloc_option->allocator.free_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) | ||||
|         return wasm_memory_init_with_allocator(os_malloc, os_realloc, os_free); | ||||
|     else | ||||
|  | @ -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 */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
| #define ENABLE_SORT_DEBUG 0 | ||||
| 
 | ||||
| #if ENABLE_SORT_DEBUG != 0 | ||||
| #include<sys/time.h> | ||||
| #include <sys/time.h> | ||||
| #endif | ||||
| 
 | ||||
| static NativeSymbolsList g_native_symbols_list = NULL; | ||||
|  | @ -80,7 +80,7 @@ check_symbol_signature(const WASMType *type, const char *signature) | |||
| #if WASM_ENABLE_REF_TYPES != 0 | ||||
|             || (sig == 'i' && type->types[i] == VALUE_TYPE_EXTERNREF) | ||||
| #endif | ||||
|            ) | ||||
|         ) | ||||
|             /* normal parameter */ | ||||
|             continue; | ||||
| 
 | ||||
|  | @ -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; | ||||
|  | @ -143,7 +142,7 @@ sort_symbol_ptr(NativeSymbol *native_symbols, uint32 n_native_symbols) | |||
| } | ||||
| #else | ||||
| static void | ||||
| swap_symbol(NativeSymbol* left, NativeSymbol* right) | ||||
| swap_symbol(NativeSymbol *left, NativeSymbol *right) | ||||
| { | ||||
|     NativeSymbol temp = *left; | ||||
|     *left = *right; | ||||
|  | @ -151,7 +150,7 @@ swap_symbol(NativeSymbol* left, NativeSymbol* right) | |||
| } | ||||
| 
 | ||||
| static void | ||||
| quick_sort_symbols(NativeSymbol* native_symbols, int left, int right) | ||||
| quick_sort_symbols(NativeSymbol *native_symbols, int left, int right) | ||||
| { | ||||
|     NativeSymbol base_symbol; | ||||
|     int pin_left = left; | ||||
|  | @ -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++; | ||||
|         } | ||||
| 
 | ||||
|  | @ -216,7 +214,7 @@ lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols, | |||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| void* | ||||
| void * | ||||
| wasm_native_resolve_symbol(const char *module_name, const char *field_name, | ||||
|                            const WASMType *func_type, const char **p_signature, | ||||
|                            void **p_attachment, bool *p_call_conv_raw) | ||||
|  | @ -229,15 +227,14 @@ 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, | ||||
|                                           field_name, &signature, &attachment)) | ||||
|             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)))) | ||||
|             break; | ||||
|                     && (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 */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -49,7 +49,7 @@ wasm_native_lookup_libc_builtin_global(const char *module_name, | |||
|  * | ||||
|  * @return the native function pointer if success, NULL otherwise | ||||
|  */ | ||||
| void* | ||||
| void * | ||||
| wasm_native_resolve_symbol(const char *module_name, const char *field_name, | ||||
|                            const WASMType *func_type, const char **p_signature, | ||||
|                            void **p_attachment, bool *p_call_conv_raw); | ||||
|  | @ -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,151 +27,187 @@ extern "C" { | |||
| 
 | ||||
| #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 | ||||
| 
 | ||||
| #define PUT_I64_TO_ADDR(addr, value) do {       \ | ||||
|     *(int64*)(addr) = (int64)(value);           \ | ||||
|   } while (0) | ||||
| #define PUT_F64_TO_ADDR(addr, value) do {       \ | ||||
|     *(float64*)(addr) = (float64)(value);       \ | ||||
|   } while (0) | ||||
| #define PUT_I64_TO_ADDR(addr, value)       \ | ||||
|     do {                                   \ | ||||
|         *(int64 *)(addr) = (int64)(value); \ | ||||
|     } while (0) | ||||
| #define PUT_F64_TO_ADDR(addr, value)           \ | ||||
|     do {                                       \ | ||||
|         *(float64 *)(addr) = (float64)(value); \ | ||||
|     } while (0) | ||||
| 
 | ||||
| #define GET_I64_FROM_ADDR(addr) (*(int64*)(addr)) | ||||
| #define GET_F64_FROM_ADDR(addr) (*(float64*)(addr)) | ||||
| #define GET_I64_FROM_ADDR(addr) (*(int64 *)(addr)) | ||||
| #define GET_F64_FROM_ADDR(addr) (*(float64 *)(addr)) | ||||
| 
 | ||||
| /* For STORE opcodes */ | ||||
| #define STORE_I64 PUT_I64_TO_ADDR | ||||
| #define STORE_U32(addr, value) do {             \ | ||||
|     *(uint32*)(addr) = (uint32)(value);         \ | ||||
|   } while (0) | ||||
| #define STORE_U16(addr, value) do {             \ | ||||
|     *(uint16*)(addr) = (uint16)(value);         \ | ||||
|   } while (0) | ||||
| #define STORE_U32(addr, value)               \ | ||||
|     do {                                     \ | ||||
|         *(uint32 *)(addr) = (uint32)(value); \ | ||||
|     } while (0) | ||||
| #define STORE_U16(addr, value)               \ | ||||
|     do {                                     \ | ||||
|         *(uint16 *)(addr) = (uint16)(value); \ | ||||
|     } while (0) | ||||
| 
 | ||||
| /* For LOAD opcodes */ | ||||
| #define LOAD_I64(addr) (*(int64*)(addr)) | ||||
| #define LOAD_F64(addr) (*(float64*)(addr)) | ||||
| #define LOAD_I32(addr) (*(int32*)(addr)) | ||||
| #define LOAD_U32(addr) (*(uint32*)(addr)) | ||||
| #define LOAD_I16(addr) (*(int16*)(addr)) | ||||
| #define LOAD_U16(addr) (*(uint16*)(addr)) | ||||
| #define LOAD_I64(addr) (*(int64 *)(addr)) | ||||
| #define LOAD_F64(addr) (*(float64 *)(addr)) | ||||
| #define LOAD_I32(addr) (*(int32 *)(addr)) | ||||
| #define LOAD_U32(addr) (*(uint32 *)(addr)) | ||||
| #define LOAD_I16(addr) (*(int16 *)(addr)) | ||||
| #define LOAD_U16(addr) (*(uint16 *)(addr)) | ||||
| 
 | ||||
| #define STORE_PTR(addr, ptr) do {               \ | ||||
|     *(void**)addr = (void*)ptr;                 \ | ||||
|   } while (0) | ||||
| #define STORE_PTR(addr, ptr)          \ | ||||
|     do {                              \ | ||||
|         *(void **)addr = (void *)ptr; \ | ||||
|     } while (0) | ||||
| 
 | ||||
| #else  /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ | ||||
| #else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ | ||||
| 
 | ||||
| #define PUT_I64_TO_ADDR(addr, value) do {       \ | ||||
|     uint32 *addr_u32 = (uint32*)(addr);         \ | ||||
|     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 {       \ | ||||
|     uint32 *addr_u32 = (uint32*)(addr);         \ | ||||
|     union { float64 val; uint32 parts[2]; } u;  \ | ||||
|     u.val = (value);                            \ | ||||
|     addr_u32[0] = u.parts[0];                   \ | ||||
|     addr_u32[1] = u.parts[1];                   \ | ||||
|   } while (0) | ||||
| #define PUT_I64_TO_ADDR(addr, value)         \ | ||||
|     do {                                     \ | ||||
|         uint32 *addr_u32 = (uint32 *)(addr); \ | ||||
|         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 {                                     \ | ||||
|         uint32 *addr_u32 = (uint32 *)(addr); \ | ||||
|         union {                              \ | ||||
|             float64 val;                     \ | ||||
|             uint32 parts[2];                 \ | ||||
|         } u;                                 \ | ||||
|         u.val = (value);                     \ | ||||
|         addr_u32[0] = u.parts[0];            \ | ||||
|         addr_u32[1] = u.parts[1];            \ | ||||
|     } while (0) | ||||
| 
 | ||||
| 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; | ||||
| } | ||||
| 
 | ||||
| static inline float64 | ||||
| GET_F64_FROM_ADDR (uint32 *addr) | ||||
| 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 {             \ | ||||
|     uintptr_t addr1 = (uintptr_t)(addr);        \ | ||||
|     union { int64 val; uint32 u32[2];           \ | ||||
|             uint16 u16[4]; uint8 u8[8]; } u;    \ | ||||
|     if ((addr1 & (uintptr_t)7) == 0)            \ | ||||
|       *(int64*)(addr) = (int64)(value);         \ | ||||
|     else {                                      \ | ||||
|         u.val = (int64)(value);                 \ | ||||
|         if ((addr1 & (uintptr_t)3) == 0) {      \ | ||||
|             ((uint32*)(addr))[0] = u.u32[0];    \ | ||||
|             ((uint32*)(addr))[1] = u.u32[1];    \ | ||||
|         }                                       \ | ||||
|         else if ((addr1 & (uintptr_t)1) == 0) { \ | ||||
|             ((uint16*)(addr))[0] = u.u16[0];    \ | ||||
|             ((uint16*)(addr))[1] = u.u16[1];    \ | ||||
|             ((uint16*)(addr))[2] = u.u16[2];    \ | ||||
|             ((uint16*)(addr))[3] = u.u16[3];    \ | ||||
|         }                                       \ | ||||
|         else {                                  \ | ||||
|             int32 t;                            \ | ||||
|             for (t = 0; t < 8; t++)             \ | ||||
|                 ((uint8*)(addr))[t] = u.u8[t];  \ | ||||
|         }                                       \ | ||||
|     }                                           \ | ||||
|   } while (0) | ||||
| #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;                                        \ | ||||
|         if ((addr1 & (uintptr_t)7) == 0)            \ | ||||
|             *(int64 *)(addr) = (int64)(value);      \ | ||||
|         else {                                      \ | ||||
|             u.val = (int64)(value);                 \ | ||||
|             if ((addr1 & (uintptr_t)3) == 0) {      \ | ||||
|                 ((uint32 *)(addr))[0] = u.u32[0];   \ | ||||
|                 ((uint32 *)(addr))[1] = u.u32[1];   \ | ||||
|             }                                       \ | ||||
|             else if ((addr1 & (uintptr_t)1) == 0) { \ | ||||
|                 ((uint16 *)(addr))[0] = u.u16[0];   \ | ||||
|                 ((uint16 *)(addr))[1] = u.u16[1];   \ | ||||
|                 ((uint16 *)(addr))[2] = u.u16[2];   \ | ||||
|                 ((uint16 *)(addr))[3] = u.u16[3];   \ | ||||
|             }                                       \ | ||||
|             else {                                  \ | ||||
|                 int32 t;                            \ | ||||
|                 for (t = 0; t < 8; t++)             \ | ||||
|                     ((uint8 *)(addr))[t] = u.u8[t]; \ | ||||
|             }                                       \ | ||||
|         }                                           \ | ||||
|     } while (0) | ||||
| 
 | ||||
| #define STORE_U32(addr, value) do {             \ | ||||
|     uintptr_t addr1 = (uintptr_t)(addr);        \ | ||||
|     union { uint32 val;                         \ | ||||
|             uint16 u16[2]; uint8 u8[4]; } u;    \ | ||||
|     if ((addr1 & (uintptr_t)3) == 0)            \ | ||||
|       *(uint32*)(addr) = (uint32)(value);       \ | ||||
|     else {                                      \ | ||||
|         u.val = (uint32)(value);                \ | ||||
|         if ((addr1 & (uintptr_t)1) == 0) {      \ | ||||
|             ((uint16*)(addr))[0] = u.u16[0];    \ | ||||
|             ((uint16*)(addr))[1] = u.u16[1];    \ | ||||
|         }                                       \ | ||||
|         else {                                  \ | ||||
|             ((uint8*)(addr))[0] = u.u8[0];      \ | ||||
|             ((uint8*)(addr))[1] = u.u8[1];      \ | ||||
|             ((uint8*)(addr))[2] = u.u8[2];      \ | ||||
|             ((uint8*)(addr))[3] = u.u8[3];      \ | ||||
|         }                                       \ | ||||
|     }                                           \ | ||||
|   } while (0) | ||||
| #define STORE_U32(addr, value)                    \ | ||||
|     do {                                          \ | ||||
|         uintptr_t addr1 = (uintptr_t)(addr);      \ | ||||
|         union {                                   \ | ||||
|             uint32 val;                           \ | ||||
|             uint16 u16[2];                        \ | ||||
|             uint8 u8[4];                          \ | ||||
|         } u;                                      \ | ||||
|         if ((addr1 & (uintptr_t)3) == 0)          \ | ||||
|             *(uint32 *)(addr) = (uint32)(value);  \ | ||||
|         else {                                    \ | ||||
|             u.val = (uint32)(value);              \ | ||||
|             if ((addr1 & (uintptr_t)1) == 0) {    \ | ||||
|                 ((uint16 *)(addr))[0] = u.u16[0]; \ | ||||
|                 ((uint16 *)(addr))[1] = u.u16[1]; \ | ||||
|             }                                     \ | ||||
|             else {                                \ | ||||
|                 ((uint8 *)(addr))[0] = u.u8[0];   \ | ||||
|                 ((uint8 *)(addr))[1] = u.u8[1];   \ | ||||
|                 ((uint8 *)(addr))[2] = u.u8[2];   \ | ||||
|                 ((uint8 *)(addr))[3] = u.u8[3];   \ | ||||
|             }                                     \ | ||||
|         }                                         \ | ||||
|     } while (0) | ||||
| 
 | ||||
| #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];              \ | ||||
|   } while (0) | ||||
| #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]; \ | ||||
|     } while (0) | ||||
| 
 | ||||
| /* For LOAD opcodes */ | ||||
| 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; | ||||
|         return *(int64 *)addr; | ||||
| 
 | ||||
|     if ((addr1 & (uintptr_t)3) == 0) { | ||||
|         u.u32[0] = ((uint32*)addr)[0]; | ||||
|         u.u32[1] = ((uint32*)addr)[1]; | ||||
|         u.u32[0] = ((uint32 *)addr)[0]; | ||||
|         u.u32[1] = ((uint32 *)addr)[1]; | ||||
|     } | ||||
|     else if ((addr1 & (uintptr_t)1) == 0) { | ||||
|         u.u16[0] = ((uint16*)addr)[0]; | ||||
|         u.u16[1] = ((uint16*)addr)[1]; | ||||
|         u.u16[2] = ((uint16*)addr)[2]; | ||||
|         u.u16[3] = ((uint16*)addr)[3]; | ||||
|         u.u16[0] = ((uint16 *)addr)[0]; | ||||
|         u.u16[1] = ((uint16 *)addr)[1]; | ||||
|         u.u16[2] = ((uint16 *)addr)[2]; | ||||
|         u.u16[3] = ((uint16 *)addr)[3]; | ||||
|     } | ||||
|     else { | ||||
|         int32 t; | ||||
|         for (t = 0; t < 8; t++) | ||||
|             u.u8[t] = ((uint8*)addr)[t]; | ||||
|             u.u8[t] = ((uint8 *)addr)[t]; | ||||
|     } | ||||
|     return u.val; | ||||
| } | ||||
|  | @ -180,25 +216,29 @@ 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; | ||||
|         return *(float64 *)addr; | ||||
| 
 | ||||
|     if ((addr1 & (uintptr_t)3) == 0) { | ||||
|         u.u32[0] = ((uint32*)addr)[0]; | ||||
|         u.u32[1] = ((uint32*)addr)[1]; | ||||
|         u.u32[0] = ((uint32 *)addr)[0]; | ||||
|         u.u32[1] = ((uint32 *)addr)[1]; | ||||
|     } | ||||
|     else if ((addr1 & (uintptr_t)1) == 0) { | ||||
|         u.u16[0] = ((uint16*)addr)[0]; | ||||
|         u.u16[1] = ((uint16*)addr)[1]; | ||||
|         u.u16[2] = ((uint16*)addr)[2]; | ||||
|         u.u16[3] = ((uint16*)addr)[3]; | ||||
|         u.u16[0] = ((uint16 *)addr)[0]; | ||||
|         u.u16[1] = ((uint16 *)addr)[1]; | ||||
|         u.u16[2] = ((uint16 *)addr)[2]; | ||||
|         u.u16[3] = ((uint16 *)addr)[3]; | ||||
|     } | ||||
|     else { | ||||
|         int32 t; | ||||
|         for (t = 0; t < 8; t++) | ||||
|             u.u8[t] = ((uint8*)addr)[t]; | ||||
|             u.u8[t] = ((uint8 *)addr)[t]; | ||||
|     } | ||||
|     return u.val; | ||||
| } | ||||
|  | @ -207,19 +247,23 @@ 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; | ||||
|         return *(int32 *)addr; | ||||
| 
 | ||||
|     if ((addr1 & (uintptr_t)1) == 0) { | ||||
|         u.u16[0] = ((uint16*)addr)[0]; | ||||
|         u.u16[1] = ((uint16*)addr)[1]; | ||||
|         u.u16[0] = ((uint16 *)addr)[0]; | ||||
|         u.u16[1] = ((uint16 *)addr)[1]; | ||||
|     } | ||||
|     else { | ||||
|         u.u8[0] = ((uint8*)addr)[0]; | ||||
|         u.u8[1] = ((uint8*)addr)[1]; | ||||
|         u.u8[2] = ((uint8*)addr)[2]; | ||||
|         u.u8[3] = ((uint8*)addr)[3]; | ||||
|         u.u8[0] = ((uint8 *)addr)[0]; | ||||
|         u.u8[1] = ((uint8 *)addr)[1]; | ||||
|         u.u8[2] = ((uint8 *)addr)[2]; | ||||
|         u.u8[3] = ((uint8 *)addr)[3]; | ||||
|     } | ||||
|     return u.val; | ||||
| } | ||||
|  | @ -228,13 +272,16 @@ 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]; | ||||
|         u.u8[0] = ((uint8 *)addr)[0]; | ||||
|         u.u8[1] = ((uint8 *)addr)[1]; | ||||
|         return u.val; | ||||
|     } | ||||
|     return *(int16*)addr; | ||||
|     return *(int16 *)addr; | ||||
| } | ||||
| 
 | ||||
| #define LOAD_U32(addr) ((uint32)LOAD_I32(addr)) | ||||
|  | @ -246,7 +293,7 @@ LOAD_I16(void *addr) | |||
| #define STORE_PTR(addr, ptr) STORE_I64(addr, (uintptr_t)ptr) | ||||
| #endif | ||||
| 
 | ||||
| #endif  /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ | ||||
| #endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ | ||||
| 
 | ||||
| typedef struct WASMModuleCommon { | ||||
|     /* Module type, for module loaded from WASM bytecode binary,
 | ||||
|  | @ -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 | ||||
|  | @ -396,7 +443,7 @@ wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst); | |||
| 
 | ||||
| /* See wasm_export.h for description */ | ||||
| WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon * | ||||
| wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst, | ||||
| wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst, | ||||
|                              const char *name, const char *signature); | ||||
| 
 | ||||
| /* Internal API */ | ||||
|  | @ -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,14 +512,13 @@ 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, | ||||
|                                            uint32 argc, uint32 argv[]); | ||||
| wasm_runtime_create_exec_env_and_call_wasm( | ||||
|     WASMModuleInstanceCommon *module_inst, WASMFunctionInstanceCommon *function, | ||||
|     uint32 argc, uint32 argv[]); | ||||
| 
 | ||||
| bool | ||||
| wasm_runtime_create_exec_env_singleton(WASMModuleInstanceCommon *module_inst); | ||||
|  | @ -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, | ||||
|                            int stdinfd, int stdoutfd, int stderrfd); | ||||
| 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 | ||||
|  | @ -711,7 +752,7 @@ wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst); | |||
| #endif /* end of WASM_ENABLE_REF_TYPES */ | ||||
| 
 | ||||
| /* Get module of the current exec_env */ | ||||
| WASMModuleCommon* | ||||
| WASMModuleCommon * | ||||
| wasm_exec_env_get_module(WASMExecEnv *exec_env); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -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; | ||||
|     } | ||||
|  | @ -66,7 +67,7 @@ wasm_shared_memory_destroy() | |||
|     } | ||||
| } | ||||
| 
 | ||||
| static WASMSharedMemNode* | ||||
| static WASMSharedMemNode * | ||||
| search_module(WASMModuleCommon *module) | ||||
| { | ||||
|     WASMSharedMemNode *node; | ||||
|  | @ -86,7 +87,7 @@ search_module(WASMModuleCommon *module) | |||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| WASMSharedMemNode* | ||||
| WASMSharedMemNode * | ||||
| wasm_module_get_shared_memory(WASMModuleCommon *module) | ||||
| { | ||||
|     return search_module(module); | ||||
|  | @ -128,13 +129,13 @@ shared_memory_dec_reference(WASMModuleCommon *module) | |||
|     return -1; | ||||
| } | ||||
| 
 | ||||
| WASMMemoryInstanceCommon* | ||||
| WASMMemoryInstanceCommon * | ||||
| shared_memory_get_memory_inst(WASMSharedMemNode *node) | ||||
| { | ||||
|     return node->memory_inst; | ||||
| } | ||||
| 
 | ||||
| WASMSharedMemNode* | ||||
| WASMSharedMemNode * | ||||
| shared_memory_set_memory_inst(WASMModuleCommon *module, | ||||
|                               WASMMemoryInstanceCommon *memory) | ||||
| { | ||||
|  | @ -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); | ||||
|  | @ -333,8 +331,8 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, | |||
| 
 | ||||
|     os_mutex_lock(&wait_info->wait_list_lock); | ||||
| 
 | ||||
|     if ((!wait64 && *(uint32*)address != (uint32)expect) | ||||
|         || (wait64 && *(uint64*)address != expect)) { | ||||
|     if ((!wait64 && *(uint32 *)address != (uint32)expect) | ||||
|         || (wait64 && *(uint64 *)address != expect)) { | ||||
|         os_mutex_unlock(&wait_info->wait_list_lock); | ||||
|         return 1; | ||||
|     } | ||||
|  | @ -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; | ||||
|  |  | |||
|  | @ -37,7 +37,7 @@ wasm_shared_memory_init(); | |||
| void | ||||
| wasm_shared_memory_destroy(); | ||||
| 
 | ||||
| WASMSharedMemNode* | ||||
| WASMSharedMemNode * | ||||
| wasm_module_get_shared_memory(WASMModuleCommon *module); | ||||
| 
 | ||||
| int32 | ||||
|  | @ -46,10 +46,10 @@ shared_memory_inc_reference(WASMModuleCommon *module); | |||
| int32 | ||||
| shared_memory_dec_reference(WASMModuleCommon *module); | ||||
| 
 | ||||
| WASMMemoryInstanceCommon* | ||||
| WASMMemoryInstanceCommon * | ||||
| shared_memory_get_memory_inst(WASMSharedMemNode *node); | ||||
| 
 | ||||
| WASMSharedMemNode* | ||||
| WASMSharedMemNode * | ||||
| shared_memory_set_memory_inst(WASMModuleCommon *module, | ||||
|                               WASMMemoryInstanceCommon *memory); | ||||
| 
 | ||||
|  | @ -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 | ||||
|  | @ -27,9 +26,9 @@ void | |||
| aot_destroy_comp_data(aot_comp_data_t comp_data); | ||||
| 
 | ||||
| #if WASM_ENABLE_DEBUG_AOT != 0 | ||||
| typedef void * dwar_extractor_handle_t; | ||||
| typedef void *dwar_extractor_handle_t; | ||||
| dwar_extractor_handle_t | ||||
| create_dwarf_extractor(aot_comp_data_t comp_data, char * file_name); | ||||
| create_dwarf_extractor(aot_comp_data_t comp_data, char *file_name); | ||||
| #endif | ||||
| 
 | ||||
| enum { | ||||
|  | @ -39,7 +38,7 @@ enum { | |||
|     AOT_LLVMIR_OPT_FILE, | ||||
| }; | ||||
| 
 | ||||
| typedef struct AOTCompOption{ | ||||
| typedef struct AOTCompOption { | ||||
|     bool is_jit_mode; | ||||
|     bool is_indirect_mode; | ||||
|     char *target_arch; | ||||
|  | @ -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 | ||||
|  | @ -88,16 +85,15 @@ aot_destroy_aot_file(uint8_t *aot_file); | |||
| bool | ||||
| aot_compile_wasm_file_init(); | ||||
| 
 | ||||
| uint8_t* | ||||
| 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(); | ||||
| 
 | ||||
| char* | ||||
| char * | ||||
| aot_get_last_error(); | ||||
| 
 | ||||
| uint32_t | ||||
|  |  | |||
|  | @ -21,18 +21,22 @@ 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} | ||||
|     { #symbol, (void *)symbol, signature, NULL } | ||||
| #define EXPORT_WASM_API_WITH_SIG2(symbol, signature) \ | ||||
|                                  {#symbol, (void*)symbol##_wrapper, signature, NULL} | ||||
|     { #symbol, (void *)symbol##_wrapper, signature, NULL } | ||||
| 
 | ||||
| #define EXPORT_WASM_API_WITH_ATT(symbol, signature, attachment) \ | ||||
|                                  {#symbol, (void*)symbol, signature, attachment} | ||||
|     { #symbol, (void *)symbol, signature, attachment } | ||||
| #define EXPORT_WASM_API_WITH_ATT2(symbol, signature, attachment) \ | ||||
|                                  {#symbol, (void*)symbol##_wrapper, 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> | ||||
|  | @ -11,11 +11,11 @@ | |||
| 
 | ||||
| #ifndef WASM_API_EXTERN | ||||
| #if defined(_MSC_BUILD) | ||||
|     #if defined(COMPILING_WASM_RUNTIME_API) | ||||
|         #define WASM_API_EXTERN __declspec(dllexport) | ||||
|     #else | ||||
|         #define WASM_API_EXTERN __declspec(dllimport) | ||||
|     #endif | ||||
| #if defined(COMPILING_WASM_RUNTIME_API) | ||||
| #define WASM_API_EXTERN __declspec(dllexport) | ||||
| #else | ||||
| #define WASM_API_EXTERN __declspec(dllimport) | ||||
| #endif | ||||
| #else | ||||
| #define WASM_API_EXTERN | ||||
| #endif | ||||
|  | @ -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"
 | ||||
| } // extern "C"
 | ||||
| #endif | ||||
| 
 | ||||
| #endif  // #ifdef WASM_H
 | ||||
| #endif // #ifdef _WASM_C_API_H_
 | ||||
|  |  | |||
|  | @ -10,14 +10,13 @@ | |||
| #include <stdbool.h> | ||||
| #include "lib_export.h" | ||||
| 
 | ||||
| 
 | ||||
| #ifndef WASM_RUNTIME_API_EXTERN | ||||
| #if defined(_MSC_BUILD ) | ||||
|     #if defined(COMPILING_WASM_RUNTIME_API) | ||||
|         #define WASM_RUNTIME_API_EXTERN __declspec(dllexport) | ||||
|     #else | ||||
|         #define WASM_RUNTIME_API_EXTERN __declspec(dllimport) | ||||
|     #endif | ||||
| #if defined(_MSC_BUILD) | ||||
| #if defined(COMPILING_WASM_RUNTIME_API) | ||||
| #define WASM_RUNTIME_API_EXTERN __declspec(dllexport) | ||||
| #else | ||||
| #define WASM_RUNTIME_API_EXTERN __declspec(dllimport) | ||||
| #endif | ||||
| #else | ||||
| #define WASM_RUNTIME_API_EXTERN | ||||
| #endif | ||||
|  | @ -27,6 +26,8 @@ | |||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* clang-format off */ | ||||
| 
 | ||||
| #define get_module_inst(exec_env) \ | ||||
|     wasm_runtime_get_module_inst(exec_env) | ||||
| 
 | ||||
|  | @ -48,13 +49,12 @@ extern "C" { | |||
| #define module_free(offset) \ | ||||
|     wasm_runtime_module_free(module_inst, offset) | ||||
| 
 | ||||
| #define native_raw_return_type(type, args) type *raw_ret = (type*)(args) | ||||
| #define native_raw_return_type(type, args) type *raw_ret = (type *)(args) | ||||
| 
 | ||||
| #define native_raw_get_arg(type, name, args) type name = *((type*)(args++)) | ||||
| #define native_raw_get_arg(type, name, args) type name = *((type *)(args++)) | ||||
| 
 | ||||
| #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
 | ||||
|  | @ -158,14 +158,14 @@ enum wasm_valkind_enum { | |||
| struct wasm_ref_t; | ||||
| 
 | ||||
| typedef struct wasm_val_t { | ||||
|   wasm_valkind_t kind; | ||||
|   union { | ||||
|     int32_t i32; | ||||
|     int64_t i64; | ||||
|     float f32; | ||||
|     double f64; | ||||
|     struct wasm_ref_t* ref; | ||||
|   } of; | ||||
|     wasm_valkind_t kind; | ||||
|     union { | ||||
|         int32_t i32; | ||||
|         int64_t i64; | ||||
|         float f32; | ||||
|         double f64; | ||||
|         struct wasm_ref_t *ref; | ||||
|     } of; | ||||
| } wasm_val_t; | ||||
| #endif | ||||
| 
 | ||||
|  | @ -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. | ||||
|  */ | ||||
|  | @ -740,31 +744,31 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst, | |||
|                                    uint8_t **p_native_end_addr); | ||||
| 
 | ||||
| /**
 | ||||
|   * Register native functions with same module name | ||||
|   * | ||||
|   * @param module_name the module name of the native functions | ||||
|   * @param native_symbols specifies an array of NativeSymbol structures which | ||||
|   *        contain the names, function pointers and signatures | ||||
|   *        Note: WASM runtime will not allocate memory to clone the data, so | ||||
|   *              user must ensure the array can be used forever | ||||
|   *        Meanings of letters in function signature: | ||||
|   *          'i': the parameter is i32 type | ||||
|   *          'I': the parameter is i64 type | ||||
|   *          'f': the parameter is f32 type | ||||
|   *          'F': the parameter is f64 type | ||||
|   *          '*': the parameter is a pointer (i32 in WASM), and runtime will | ||||
|   *               auto check its boundary before calling the native function. | ||||
|   *               If it is followed by '~', the checked length of the pointer | ||||
|   *               is gotten from the following parameter, if not, the checked | ||||
|   *               length of the pointer is 1. | ||||
|   *          '~': the parameter is the pointer's length with i32 type, and must | ||||
|   *               follow after '*' | ||||
|   *          '$': the parameter is a string (i32 in WASM), and runtime will | ||||
|   *               auto check its boundary before calling the native function | ||||
|   * @param n_native_symbols specifies the number of native symbols in the array | ||||
|   * | ||||
|   * @return true if success, false otherwise | ||||
|   */ | ||||
|  * Register native functions with same module name | ||||
|  * | ||||
|  * @param module_name the module name of the native functions | ||||
|  * @param native_symbols specifies an array of NativeSymbol structures which | ||||
|  *        contain the names, function pointers and signatures | ||||
|  *        Note: WASM runtime will not allocate memory to clone the data, so | ||||
|  *              user must ensure the array can be used forever | ||||
|  *        Meanings of letters in function signature: | ||||
|  *          'i': the parameter is i32 type | ||||
|  *          'I': the parameter is i64 type | ||||
|  *          'f': the parameter is f32 type | ||||
|  *          'F': the parameter is f64 type | ||||
|  *          '*': the parameter is a pointer (i32 in WASM), and runtime will | ||||
|  *               auto check its boundary before calling the native function. | ||||
|  *               If it is followed by '~', the checked length of the pointer | ||||
|  *               is gotten from the following parameter, if not, the checked | ||||
|  *               length of the pointer is 1. | ||||
|  *          '~': the parameter is the pointer's length with i32 type, and must | ||||
|  *               follow after '*' | ||||
|  *          '$': the parameter is a string (i32 in WASM), and runtime will | ||||
|  *               auto check its boundary before calling the native function | ||||
|  * @param n_native_symbols specifies the number of native symbols in the array | ||||
|  * | ||||
|  * @return true if success, false otherwise | ||||
|  */ | ||||
| WASM_RUNTIME_API_EXTERN bool | ||||
| wasm_runtime_register_natives(const char *module_name, | ||||
|                               NativeSymbol *native_symbols, | ||||
|  | @ -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. | ||||
|  * | ||||
|  | @ -835,7 +838,7 @@ WASM_RUNTIME_API_EXTERN void | |||
| wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst); | ||||
| 
 | ||||
| /* wasm thread callback function type */ | ||||
| typedef void* (*wasm_thread_callback_t)(wasm_exec_env_t, void *); | ||||
| typedef void *(*wasm_thread_callback_t)(wasm_exec_env_t, void *); | ||||
| /* wasm thread type */ | ||||
| typedef uintptr_t wasm_thread_t; | ||||
| 
 | ||||
|  | @ -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) | ||||
| ``` | ||||
|  | @ -87,4 +87,4 @@ wamrc -o test.aot test.wasm | |||
| lldb-12 iwasm -- test.aot | ||||
| ``` | ||||
| 
 | ||||
| Then you can use lldb commands to debug both wamr runtime and your wasm application in ***current terminal*** | ||||
| Then you can use lldb commands to debug both wamr runtime and your wasm application in ***current terminal*** | ||||
|  |  | |||
|  | @ -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 | ||||
|         git reset --hard origin/main | ||||
|         cd .. | ||||
|         make -C wabt gcc-release | ||||
|     fi | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Wenyong Huang
						Wenyong Huang