Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
837ff63
Use 64-bit wasm_runtime_enlarge_memory() increment (#3573)
bnason-nf Jun 27, 2024
ea582fb
wasm-mutator-fuzz: Make compilers overridable (#3578)
yamt Jul 1, 2024
77da87c
wasi-nn: Use numpy v1 in wasi-nn test requirements.txt (#3582)
tonibofarull Jul 2, 2024
a5753ea
interp debugger: Fix setting invalid value to step_count (#3583)
TianlongLiang Jul 2, 2024
fe4ed6a
Fix compilation errors in aot-analyzer tool (#3584)
HongxiaWangSSSS Jul 2, 2024
0d9cea4
wasm-mutator-fuzz: Set compilers earlier (#3585)
yamt Jul 2, 2024
212d830
aot-analyzer: Fix macos build (#3589)
yamt Jul 2, 2024
3d4d8e6
aot-analyzer: Fix a few printf formats (#3590)
yamt Jul 2, 2024
f118492
Add integer overflow check for some indices in wasm/aot loader (#3579)
lum1n0us Jul 2, 2024
e3074dc
Add more arm AOT reloc entries (#3587)
bnason-nf Jul 3, 2024
1f94cd4
wasm loader: Fix push_frame_offset when pushing v128 type (#3588)
wenyongh Jul 3, 2024
7771212
CMakeLists.txt: Fix Android pthread linkage (#3591)
bnason-nf Jul 4, 2024
0feae05
wasm loader: Fix several issues in GC and exception handling (#3586)
wenyongh Jul 5, 2024
8aba858
Avoid redefining WASMMemoryType (#3602)
bnason-nf Jul 10, 2024
8a6379b
Add wasm_runtime_get_module_package_type() and wasm_runtime_get_file_…
bnason-nf Jul 10, 2024
fc34151
Bump ocaml/setup-ocaml from 2 to 3 (#3604)
dependabot[bot] Jul 10, 2024
2cf48c8
Fix typos in wamrc and wasm_export.h (#3609)
byeongjee Jul 10, 2024
1b1ec71
wasm loader: Reject v128 for interpreters (#3611)
yamt Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ jobs:
uses: actions/checkout@v4

- name: Set-up OCaml
uses: ocaml/setup-ocaml@v2
uses: ocaml/setup-ocaml@v3
if: matrix.test_option == '$GC_TEST_OPTIONS' || matrix.test_option == '$MEMORY64_TEST_OPTIONS'
with:
ocaml-compiler: 4.13
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ endif ()

include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)

set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# STATIC LIBRARY
if (WAMR_BUILD_STATIC)
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT})
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
endif ()
Expand All @@ -160,7 +163,7 @@ if (WAMR_BUILD_SHARED)
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT})
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
endif ()
Expand Down
7 changes: 7 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,9 @@ load_global_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
const uint8 *buf = *p_buf;

read_uint32(buf, buf_end, module->global_count);
if (is_indices_overflow(module->import_global_count, module->global_count,
error_buf, error_buf_size))
return false;

/* load globals */
if (module->global_count > 0
Expand Down Expand Up @@ -2481,6 +2484,10 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,

/* load function count and start function index */
read_uint32(p, p_end, module->func_count);
if (is_indices_overflow(module->import_func_count, module->func_count,
error_buf, error_buf_size))
return false;

read_uint32(p, p_end, module->start_func_index);

/* check start function index */
Expand Down
35 changes: 32 additions & 3 deletions core/iwasm/aot/arch/aot_reloc_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,48 @@
/* clang-format off */
void __adddf3();
void __addsf3();
void __aeabi_d2f();
void __aeabi_d2iz();
void __aeabi_d2lz();
void __aeabi_d2uiz();
void __aeabi_d2ulz();
void __aeabi_dadd();
void __aeabi_dcmpeq();
void __aeabi_dcmpge();
void __aeabi_dcmpgt();
void __aeabi_dcmple();
void __aeabi_dcmplt();
void __aeabi_dcmpun();
void __aeabi_ddiv();
void __aeabi_dmul();
void __aeabi_dsub();
void __aeabi_f2d();
void __aeabi_f2iz();
void __aeabi_f2lz();
void __aeabi_f2ulz();
void __aeabi_fadd();
void __aeabi_fcmpeq();
void __aeabi_fcmpge();
void __aeabi_fcmpgt();
void __aeabi_fcmple();
void __aeabi_fcmplt();
void __aeabi_fcmpun();
void __aeabi_fdiv();
void __aeabi_fmul();
void __aeabi_fsub();
void __aeabi_i2d();
void __aeabi_i2f();
void __aeabi_idiv();
void __aeabi_idivmod();
void __aeabi_l2d();
void __aeabi_l2f();
void __aeabi_ldivmod();
void __aeabi_memclr();
void __aeabi_memcpy();
void __aeabi_memmove();
void __aeabi_memset();
void __aeabi_memclr();
void __aeabi_ui2d();
void __aeabi_ui2f();
void __aeabi_uidiv();
void __aeabi_uidivmod();
void __aeabi_ul2d();
Expand Down Expand Up @@ -101,33 +116,48 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__adddf3),
REG_SYM(__addsf3),
/* clang-format on */
REG_SYM(__aeabi_d2f),
REG_SYM(__aeabi_d2iz),
REG_SYM(__aeabi_d2lz),
REG_SYM(__aeabi_d2uiz),
REG_SYM(__aeabi_d2ulz),
REG_SYM(__aeabi_dadd),
REG_SYM(__aeabi_dcmpeq),
REG_SYM(__aeabi_dcmpge),
REG_SYM(__aeabi_dcmpgt),
REG_SYM(__aeabi_dcmple),
REG_SYM(__aeabi_dcmplt),
REG_SYM(__aeabi_dcmpun),
REG_SYM(__aeabi_ddiv),
REG_SYM(__aeabi_dmul),
REG_SYM(__aeabi_dsub),
REG_SYM(__aeabi_f2d),
REG_SYM(__aeabi_f2iz),
REG_SYM(__aeabi_f2lz),
REG_SYM(__aeabi_f2ulz),
REG_SYM(__aeabi_fadd),
REG_SYM(__aeabi_fcmpeq),
REG_SYM(__aeabi_fcmpge),
REG_SYM(__aeabi_fcmpgt),
REG_SYM(__aeabi_fcmple),
REG_SYM(__aeabi_fcmplt),
REG_SYM(__aeabi_fcmpun),
REG_SYM(__aeabi_fdiv),
REG_SYM(__aeabi_fmul),
REG_SYM(__aeabi_fsub),
REG_SYM(__aeabi_i2d),
REG_SYM(__aeabi_i2f),
REG_SYM(__aeabi_idiv),
REG_SYM(__aeabi_idivmod),
REG_SYM(__aeabi_l2d),
REG_SYM(__aeabi_l2f),
REG_SYM(__aeabi_ldivmod),
REG_SYM(__aeabi_memclr),
REG_SYM(__aeabi_memcpy),
REG_SYM(__aeabi_memmove),
REG_SYM(__aeabi_memset),
REG_SYM(__aeabi_memclr),
REG_SYM(__aeabi_ui2d),
REG_SYM(__aeabi_ui2f),
REG_SYM(__aeabi_uidiv),
REG_SYM(__aeabi_uidivmod),
REG_SYM(__aeabi_ul2d),
Expand Down Expand Up @@ -166,7 +196,6 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__moddi3),
REG_SYM(__modsi3),
REG_SYM(__muldf3),
REG_SYM(__muldf3),
REG_SYM(__mulsf3),
REG_SYM(__nedf2),
REG_SYM(__nesf2),
Expand Down
32 changes: 32 additions & 0 deletions core/iwasm/common/wasm_loader_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ is_valid_value_type(uint8 type)
return false;
}

bool
is_valid_value_type_for_interpreter(uint8 value_type)
{
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0)
/*
* Note: regardless of WASM_ENABLE_SIMD, our interpreters don't have
* SIMD implemented. It's safer to reject v128, especially for the
* fast interpreter.
*/
if (value_type == VALUE_TYPE_V128)
return false;
#endif
return is_valid_value_type(value_type);
}

bool
is_valid_func_type(const WASMFuncType *func_type)
{
Expand All @@ -96,3 +111,20 @@ is_valid_func_type(const WASMFuncType *func_type)

return true;
}

/*
* Indices are represented as a u32.
*/
bool
is_indices_overflow(uint32 import, uint32 other, char *error_buf,
uint32 error_buf_size)
{
if (import > UINT32_MAX - other) {
snprintf(error_buf, error_buf_size,
"too many items in the index space(%" PRIu32 "+%" PRIu32 ").",
import, other);
return true;
}

return false;
}
9 changes: 8 additions & 1 deletion core/iwasm/common/wasm_loader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
bool
is_valid_value_type(uint8 value_tpye);

bool
is_valid_value_type_for_interpreter(uint8 value_tpye);

bool
is_valid_func_type(const WASMFuncType *func_type);

bool
is_indices_overflow(uint32 import, uint32 other, char *error_buf,
uint32 error_buf_size);

#ifdef __cplusplus
}
#endif

#endif /* end of _WASM_LOADER_COMMON_H */
#endif /* end of _WASM_LOADER_COMMON_H */
6 changes: 5 additions & 1 deletion core/iwasm/common/wasm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,12 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)

bool
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst,
uint32_t inc_page_count)
uint64 inc_page_count)
{
if (inc_page_count > UINT32_MAX) {
return false;
}

#if WASM_ENABLE_AOT != 0
if (module_inst->module_type == Wasm_Module_AoT) {
return aot_enlarge_memory((AOTModuleInstance *)module_inst,
Expand Down
16 changes: 16 additions & 0 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,22 @@ get_package_type(const uint8 *buf, uint32 size)
return Package_Type_Unknown;
}

PackageType
wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size)
{
return get_package_type(buf, size);
}

PackageType
wasm_runtime_get_module_package_type(WASMModuleCommon *module)
{
if (!module) {
return Package_Type_Unknown;
}

return module->module_type;
}

#if WASM_ENABLE_AOT != 0
static uint8 *
align_ptr(const uint8 *p, uint32 b)
Expand Down
39 changes: 36 additions & 3 deletions core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ typedef struct WASMTableType *wasm_table_type_t;
struct WASMGlobalType;
typedef struct WASMGlobalType *wasm_global_type_t;

#ifndef WASM_MEMORY_T_DEFINED
#define WASM_MEMORY_T_DEFINED
struct WASMMemory;
typedef struct WASMMemory WASMMemoryType;
#endif
typedef WASMMemoryType *wasm_memory_type_t;

typedef struct wasm_import_t {
Expand Down Expand Up @@ -419,6 +422,28 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
WASM_RUNTIME_API_EXTERN package_type_t
get_package_type(const uint8_t *buf, uint32_t size);

/**
* Get the package type of a buffer (same as get_package_type).
*
* @param buf the package buffer
* @param size the package buffer size
*
* @return the package type, return Package_Type_Unknown if the type is unknown
*/
WASM_RUNTIME_API_EXTERN package_type_t
wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size);

/**
* Get the package type of a module.
*
* @param module the module
*
* @return the package type, return Package_Type_Unknown if the type is
* unknown
*/
WASM_RUNTIME_API_EXTERN package_type_t
wasm_runtime_get_module_package_type(wasm_module_t module);

/**
* Check whether a file is an AOT XIP (Execution In Place) file
*
Expand Down Expand Up @@ -1202,7 +1227,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
void *native_ptr, uint64_t size);

/**
* Convert app address(relative address) to native address(absolute address)
* Convert app address (relative address) to native address (absolute address)
*
* Note that native addresses to module instance memory can be invalidated
* on a memory growth. (Except shared memory, whose native addresses are
Expand All @@ -1218,7 +1243,7 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
uint64_t app_offset);

/**
* Convert native address(absolute address) to app address(relative address)
* Convert native address (absolute address) to app address (relative address)
*
* @param module_inst the WASM module instance
* @param native_ptr the native address
Expand Down Expand Up @@ -1842,9 +1867,17 @@ WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_import_global_linked(const char *module_name,
const char *global_name);

/**
* Enlarge the memory region for a module instance
*
* @param module_inst the module instance
* @param inc_page_count the number of pages to add
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst,
uint32_t inc_page_count);
uint64_t inc_page_count);

typedef enum {
INTERNAL_ERROR,
Expand Down
6 changes: 5 additions & 1 deletion core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ typedef struct WASMMemory {
uint32 num_bytes_per_page;
uint32 init_page_count;
uint32 max_page_count;
} WASMMemory, WASMMemoryType;
} WASMMemory;
#ifndef WASM_MEMORY_T_DEFINED
#define WASM_MEMORY_T_DEFINED
typedef struct WASMMemory WASMMemoryType;
#endif

typedef struct WASMTableImport {
char *module_name;
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
#define HANDLE_OP_END() \
os_mutex_lock(&exec_env->wait_lock); \
if (exec_env->current_status->signal_flag == WAMR_SIG_SINGSTEP \
&& exec_env->current_status->step_count++ == 2) { \
&& exec_env->current_status->step_count++ == 1) { \
exec_env->current_status->step_count = 0; \
SYNC_ALL_TO_FRAME(); \
wasm_cluster_thread_waiting_run(exec_env); \
Expand Down
Loading