Skip to content

Commit 84411c6

Browse files
authored
Merge pull request #3613 from bytecodealliance/main
Merge branch main into dev/shared_heap
2 parents 65bf04e + 1b1ec71 commit 84411c6

File tree

18 files changed

+288
-81
lines changed

18 files changed

+288
-81
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ jobs:
645645
uses: actions/checkout@v4
646646

647647
- name: Set-up OCaml
648-
uses: ocaml/setup-ocaml@v2
648+
uses: ocaml/setup-ocaml@v3
649649
if: matrix.test_option == '$GC_TEST_OPTIONS' || matrix.test_option == '$MEMORY64_TEST_OPTIONS'
650650
with:
651651
ocaml-compiler: 4.13

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,15 @@ endif ()
142142

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

145+
set (THREADS_PREFER_PTHREAD_FLAG ON)
146+
find_package(Threads REQUIRED)
147+
145148
# STATIC LIBRARY
146149
if (WAMR_BUILD_STATIC)
147150
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
148151
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
149152
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
150-
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
153+
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT})
151154
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
152155
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
153156
endif ()
@@ -160,7 +163,7 @@ if (WAMR_BUILD_SHARED)
160163
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
161164
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
162165
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
163-
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
166+
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT})
164167
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
165168
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
166169
endif ()

core/iwasm/aot/aot_loader.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,9 @@ load_global_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
22172217
const uint8 *buf = *p_buf;
22182218

22192219
read_uint32(buf, buf_end, module->global_count);
2220+
if (is_indices_overflow(module->import_global_count, module->global_count,
2221+
error_buf, error_buf_size))
2222+
return false;
22202223

22212224
/* load globals */
22222225
if (module->global_count > 0
@@ -2481,6 +2484,10 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
24812484

24822485
/* load function count and start function index */
24832486
read_uint32(p, p_end, module->func_count);
2487+
if (is_indices_overflow(module->import_func_count, module->func_count,
2488+
error_buf, error_buf_size))
2489+
return false;
2490+
24842491
read_uint32(p, p_end, module->start_func_index);
24852492

24862493
/* check start function index */

core/iwasm/aot/arch/aot_reloc_arm.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,48 @@
1414
/* clang-format off */
1515
void __adddf3();
1616
void __addsf3();
17+
void __aeabi_d2f();
1718
void __aeabi_d2iz();
1819
void __aeabi_d2lz();
20+
void __aeabi_d2uiz();
1921
void __aeabi_d2ulz();
2022
void __aeabi_dadd();
23+
void __aeabi_dcmpeq();
2124
void __aeabi_dcmpge();
25+
void __aeabi_dcmpgt();
2226
void __aeabi_dcmple();
2327
void __aeabi_dcmplt();
2428
void __aeabi_dcmpun();
2529
void __aeabi_ddiv();
30+
void __aeabi_dmul();
31+
void __aeabi_dsub();
2632
void __aeabi_f2d();
2733
void __aeabi_f2iz();
2834
void __aeabi_f2lz();
2935
void __aeabi_f2ulz();
36+
void __aeabi_fadd();
37+
void __aeabi_fcmpeq();
3038
void __aeabi_fcmpge();
39+
void __aeabi_fcmpgt();
3140
void __aeabi_fcmple();
3241
void __aeabi_fcmplt();
3342
void __aeabi_fcmpun();
43+
void __aeabi_fdiv();
44+
void __aeabi_fmul();
45+
void __aeabi_fsub();
3446
void __aeabi_i2d();
47+
void __aeabi_i2f();
3548
void __aeabi_idiv();
3649
void __aeabi_idivmod();
3750
void __aeabi_l2d();
3851
void __aeabi_l2f();
3952
void __aeabi_ldivmod();
53+
void __aeabi_memclr();
4054
void __aeabi_memcpy();
4155
void __aeabi_memmove();
4256
void __aeabi_memset();
43-
void __aeabi_memclr();
57+
void __aeabi_ui2d();
58+
void __aeabi_ui2f();
4459
void __aeabi_uidiv();
4560
void __aeabi_uidivmod();
4661
void __aeabi_ul2d();
@@ -101,33 +116,48 @@ static SymbolMap target_sym_map[] = {
101116
REG_SYM(__adddf3),
102117
REG_SYM(__addsf3),
103118
/* clang-format on */
119+
REG_SYM(__aeabi_d2f),
104120
REG_SYM(__aeabi_d2iz),
105121
REG_SYM(__aeabi_d2lz),
122+
REG_SYM(__aeabi_d2uiz),
106123
REG_SYM(__aeabi_d2ulz),
107124
REG_SYM(__aeabi_dadd),
125+
REG_SYM(__aeabi_dcmpeq),
108126
REG_SYM(__aeabi_dcmpge),
127+
REG_SYM(__aeabi_dcmpgt),
109128
REG_SYM(__aeabi_dcmple),
110129
REG_SYM(__aeabi_dcmplt),
111130
REG_SYM(__aeabi_dcmpun),
112131
REG_SYM(__aeabi_ddiv),
132+
REG_SYM(__aeabi_dmul),
133+
REG_SYM(__aeabi_dsub),
113134
REG_SYM(__aeabi_f2d),
114135
REG_SYM(__aeabi_f2iz),
115136
REG_SYM(__aeabi_f2lz),
116137
REG_SYM(__aeabi_f2ulz),
138+
REG_SYM(__aeabi_fadd),
139+
REG_SYM(__aeabi_fcmpeq),
117140
REG_SYM(__aeabi_fcmpge),
141+
REG_SYM(__aeabi_fcmpgt),
118142
REG_SYM(__aeabi_fcmple),
119143
REG_SYM(__aeabi_fcmplt),
120144
REG_SYM(__aeabi_fcmpun),
145+
REG_SYM(__aeabi_fdiv),
146+
REG_SYM(__aeabi_fmul),
147+
REG_SYM(__aeabi_fsub),
121148
REG_SYM(__aeabi_i2d),
149+
REG_SYM(__aeabi_i2f),
122150
REG_SYM(__aeabi_idiv),
123151
REG_SYM(__aeabi_idivmod),
124152
REG_SYM(__aeabi_l2d),
125153
REG_SYM(__aeabi_l2f),
126154
REG_SYM(__aeabi_ldivmod),
155+
REG_SYM(__aeabi_memclr),
127156
REG_SYM(__aeabi_memcpy),
128157
REG_SYM(__aeabi_memmove),
129158
REG_SYM(__aeabi_memset),
130-
REG_SYM(__aeabi_memclr),
159+
REG_SYM(__aeabi_ui2d),
160+
REG_SYM(__aeabi_ui2f),
131161
REG_SYM(__aeabi_uidiv),
132162
REG_SYM(__aeabi_uidivmod),
133163
REG_SYM(__aeabi_ul2d),
@@ -166,7 +196,6 @@ static SymbolMap target_sym_map[] = {
166196
REG_SYM(__moddi3),
167197
REG_SYM(__modsi3),
168198
REG_SYM(__muldf3),
169-
REG_SYM(__muldf3),
170199
REG_SYM(__mulsf3),
171200
REG_SYM(__nedf2),
172201
REG_SYM(__nesf2),

core/iwasm/common/wasm_loader_common.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ is_valid_value_type(uint8 type)
8585
return false;
8686
}
8787

88+
bool
89+
is_valid_value_type_for_interpreter(uint8 value_type)
90+
{
91+
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0)
92+
/*
93+
* Note: regardless of WASM_ENABLE_SIMD, our interpreters don't have
94+
* SIMD implemented. It's safer to reject v128, especially for the
95+
* fast interpreter.
96+
*/
97+
if (value_type == VALUE_TYPE_V128)
98+
return false;
99+
#endif
100+
return is_valid_value_type(value_type);
101+
}
102+
88103
bool
89104
is_valid_func_type(const WASMFuncType *func_type)
90105
{
@@ -96,3 +111,20 @@ is_valid_func_type(const WASMFuncType *func_type)
96111

97112
return true;
98113
}
114+
115+
/*
116+
* Indices are represented as a u32.
117+
*/
118+
bool
119+
is_indices_overflow(uint32 import, uint32 other, char *error_buf,
120+
uint32 error_buf_size)
121+
{
122+
if (import > UINT32_MAX - other) {
123+
snprintf(error_buf, error_buf_size,
124+
"too many items in the index space(%" PRIu32 "+%" PRIu32 ").",
125+
import, other);
126+
return true;
127+
}
128+
129+
return false;
130+
}

core/iwasm/common/wasm_loader_common.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
2020
bool
2121
is_valid_value_type(uint8 value_tpye);
2222

23+
bool
24+
is_valid_value_type_for_interpreter(uint8 value_tpye);
25+
2326
bool
2427
is_valid_func_type(const WASMFuncType *func_type);
2528

29+
bool
30+
is_indices_overflow(uint32 import, uint32 other, char *error_buf,
31+
uint32 error_buf_size);
32+
2633
#ifdef __cplusplus
2734
}
2835
#endif
2936

30-
#endif /* end of _WASM_LOADER_COMMON_H */
37+
#endif /* end of _WASM_LOADER_COMMON_H */

core/iwasm/common/wasm_memory.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,12 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
921921

922922
bool
923923
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst,
924-
uint32_t inc_page_count)
924+
uint64 inc_page_count)
925925
{
926+
if (inc_page_count > UINT32_MAX) {
927+
return false;
928+
}
929+
926930
#if WASM_ENABLE_AOT != 0
927931
if (module_inst->module_type == Wasm_Module_AoT) {
928932
return aot_enlarge_memory((AOTModuleInstance *)module_inst,

core/iwasm/common/wasm_runtime_common.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,22 @@ get_package_type(const uint8 *buf, uint32 size)
871871
return Package_Type_Unknown;
872872
}
873873

874+
PackageType
875+
wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size)
876+
{
877+
return get_package_type(buf, size);
878+
}
879+
880+
PackageType
881+
wasm_runtime_get_module_package_type(WASMModuleCommon *module)
882+
{
883+
if (!module) {
884+
return Package_Type_Unknown;
885+
}
886+
887+
return module->module_type;
888+
}
889+
874890
#if WASM_ENABLE_AOT != 0
875891
static uint8 *
876892
align_ptr(const uint8 *p, uint32 b)

core/iwasm/include/wasm_export.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ typedef struct WASMTableType *wasm_table_type_t;
8181
struct WASMGlobalType;
8282
typedef struct WASMGlobalType *wasm_global_type_t;
8383

84+
#ifndef WASM_MEMORY_T_DEFINED
85+
#define WASM_MEMORY_T_DEFINED
8486
struct WASMMemory;
8587
typedef struct WASMMemory WASMMemoryType;
88+
#endif
8689
typedef WASMMemoryType *wasm_memory_type_t;
8790

8891
typedef struct wasm_import_t {
@@ -419,6 +422,28 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
419422
WASM_RUNTIME_API_EXTERN package_type_t
420423
get_package_type(const uint8_t *buf, uint32_t size);
421424

425+
/**
426+
* Get the package type of a buffer (same as get_package_type).
427+
*
428+
* @param buf the package buffer
429+
* @param size the package buffer size
430+
*
431+
* @return the package type, return Package_Type_Unknown if the type is unknown
432+
*/
433+
WASM_RUNTIME_API_EXTERN package_type_t
434+
wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size);
435+
436+
/**
437+
* Get the package type of a module.
438+
*
439+
* @param module the module
440+
*
441+
* @return the package type, return Package_Type_Unknown if the type is
442+
* unknown
443+
*/
444+
WASM_RUNTIME_API_EXTERN package_type_t
445+
wasm_runtime_get_module_package_type(wasm_module_t module);
446+
422447
/**
423448
* Check whether a file is an AOT XIP (Execution In Place) file
424449
*
@@ -1202,7 +1227,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
12021227
void *native_ptr, uint64_t size);
12031228

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

12201245
/**
1221-
* Convert native address(absolute address) to app address(relative address)
1246+
* Convert native address (absolute address) to app address (relative address)
12221247
*
12231248
* @param module_inst the WASM module instance
12241249
* @param native_ptr the native address
@@ -1842,9 +1867,17 @@ WASM_RUNTIME_API_EXTERN bool
18421867
wasm_runtime_is_import_global_linked(const char *module_name,
18431868
const char *global_name);
18441869

1870+
/**
1871+
* Enlarge the memory region for a module instance
1872+
*
1873+
* @param module_inst the module instance
1874+
* @param inc_page_count the number of pages to add
1875+
*
1876+
* @return true if success, false otherwise
1877+
*/
18451878
WASM_RUNTIME_API_EXTERN bool
18461879
wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst,
1847-
uint32_t inc_page_count);
1880+
uint64_t inc_page_count);
18481881

18491882
typedef enum {
18501883
INTERNAL_ERROR,

core/iwasm/interpreter/wasm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ typedef struct WASMMemory {
518518
uint32 num_bytes_per_page;
519519
uint32 init_page_count;
520520
uint32 max_page_count;
521-
} WASMMemory, WASMMemoryType;
521+
} WASMMemory;
522+
#ifndef WASM_MEMORY_T_DEFINED
523+
#define WASM_MEMORY_T_DEFINED
524+
typedef struct WASMMemory WASMMemoryType;
525+
#endif
522526

523527
typedef struct WASMTableImport {
524528
char *module_name;

0 commit comments

Comments
 (0)