Skip to content

Commit b4826d7

Browse files
committed
Fix post-rebase bugs
1 parent 77d30b2 commit b4826d7

File tree

7 files changed

+59
-76
lines changed

7 files changed

+59
-76
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bh_static_assert(offsetof(AOTModuleInstance, c_api_func_imports)
5353
bh_static_assert(offsetof(AOTModuleInstance, global_table_data)
5454
== 13 * sizeof(uint64) + 128 + 14 * sizeof(uint64));
5555

56-
bh_static_assert(sizeof(AOTMemoryInstance) == 120);
56+
bh_static_assert(sizeof(AOTMemoryInstance) == 128);
5757
bh_static_assert(offsetof(AOTTableInstance, elems) == 24);
5858

5959
bh_static_assert(offsetof(AOTModuleInstanceExtra, stack_sizes) == 0);
@@ -2013,19 +2013,6 @@ aot_lookup_global(const AOTModuleInstance *module_inst, const char *name)
20132013
return NULL;
20142014
}
20152015

2016-
AOTGlobalInstance*
2017-
aot_lookup_global(const AOTModuleInstance *module_inst, const char *name)
2018-
{
2019-
uint32 i;
2020-
AOTGlobalInstance *export_globs =
2021-
(AOTGlobalInstance*)module_inst->export_globals;
2022-
2023-
for (i = 0; i < module_inst->export_global_count; i++)
2024-
if (!strcmp(export_globs[i].name, name))
2025-
return &export_globs[i];
2026-
return NULL;
2027-
}
2028-
20292016
#ifdef OS_ENABLE_HW_BOUND_CHECK
20302017
static bool
20312018
invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
@@ -2416,7 +2403,7 @@ aot_poll_pending_signal(WASMExecEnv *exec_env)
24162403
/* Patch function pointer in case of reassignment */
24172404
uint32 func_idx = wali_sigtable[signo].func_idx;
24182405
uint32 func_type_idx = module_inst->func_type_indexes[func_idx];
2419-
sigfn->u.func.func_type = ((AOTModule*)module_inst->module)->func_types[func_type_idx];
2406+
sigfn->u.func.func_type = ((AOTModule*)module_inst->module)->types[func_type_idx];
24202407
sigfn->u.func.func_ptr = module_inst->func_ptrs[func_idx];
24212408
/* */
24222409
pthread_mutex_unlock(&sigtable_mut);
@@ -2868,8 +2855,9 @@ aot_get_indirect_function (AOTModuleInstance *module_inst, uint32 tbl_idx,
28682855

28692856
AOTModule *aot_module = (AOTModule *)module_inst->module;
28702857
AOTTableInstance *tbl_inst = NULL;
2871-
uint32 func_idx = NULL_REF;
2858+
table_elem_type_t tbl_elem_val = NULL_REF;
28722859
uint32 *func_type_indexes = module_inst->func_type_indexes;
2860+
uint32 func_idx;
28732861
uint32 func_type_idx;
28742862
void **func_ptrs = module_inst->func_ptrs;
28752863

@@ -2880,14 +2868,21 @@ aot_get_indirect_function (AOTModuleInstance *module_inst, uint32 tbl_idx,
28802868
goto fail;
28812869
}
28822870

2883-
func_idx = tbl_inst->elems[table_elem_idx];
2884-
if (func_idx == NULL_REF) {
2871+
tbl_elem_val = tbl_inst->elems[table_elem_idx];
2872+
if (tbl_elem_val == NULL_REF) {
28852873
aot_set_exception_with_id(module_inst, EXCE_UNINITIALIZED_ELEMENT);
28862874
goto fail;
28872875
}
28882876

2877+
#if WASM_ENABLE_GC == 0
2878+
func_idx = tbl_elem_val;
2879+
#else
2880+
func_idx =
2881+
wasm_func_obj_get_func_idx_bound((WASMFuncObjectRef)tbl_elem_val);
2882+
#endif
2883+
28892884
func_type_idx = func_type_indexes[func_idx];
2890-
*func_type_addr = aot_module->func_types[func_type_idx];
2885+
*func_type_addr = aot_module->types[func_type_idx];
28912886

28922887
if (func_idx >= aot_module->import_func_count) {
28932888
/* func pointer was looked up previously */
@@ -2913,8 +2908,7 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
29132908
AOTModule *aot_module = (AOTModule *)module_inst->module;
29142909
AOTFuncType *func_type;
29152910
void **func_ptrs = module_inst->func_ptrs, *func_ptr;
2916-
uint32 func_type_idx, func_idx, ext_ret_count;
2917-
table_elem_type_t tbl_elem_val = NULL_REF;
2911+
uint32 func_idx, ext_ret_count;
29182912
AOTImportFunc *import_func;
29192913
const char *signature = NULL;
29202914
void *attachment = NULL;
@@ -2937,27 +2931,6 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
29372931
goto fail;
29382932
}
29392933

2940-
tbl_elem_val = ((table_elem_type_t *)tbl_inst->elems)[table_elem_idx];
2941-
if (tbl_elem_val == NULL_REF) {
2942-
aot_set_exception_with_id(module_inst, EXCE_UNINITIALIZED_ELEMENT);
2943-
goto fail;
2944-
}
2945-
2946-
#if WASM_ENABLE_GC == 0
2947-
func_idx = tbl_elem_val;
2948-
#else
2949-
func_idx =
2950-
wasm_func_obj_get_func_idx_bound((WASMFuncObjectRef)tbl_elem_val);
2951-
#endif
2952-
2953-
func_type_idx = func_type_indexes[func_idx];
2954-
func_type = (AOTFuncType *)aot_module->types[func_type_idx];
2955-
2956-
if (func_idx >= aot_module->import_func_count) {
2957-
/* func pointer was looked up previously */
2958-
bh_assert(func_ptrs[func_idx] != NULL);
2959-
}
2960-
29612934
if (!(func_ptr = func_ptrs[func_idx])) {
29622935
bh_assert(func_idx < aot_module->import_func_count);
29632936
import_func = aot_module->import_funcs + func_idx;

core/iwasm/common/wasm_application.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#endif
1616
#if WASM_ENABLE_GC != 0
1717
#include "gc/gc_object.h"
18+
#endif
1819
#if WASM_ENABLE_STRINGREF != 0
1920
#include "string_object.h"
2021
#endif

core/iwasm/common/wasm_memory.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ wasm_mmap_linear_memory(uint64_t map_size, uint64 commit_size)
736736
}
737737

738738
bool
739-
wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count, bool is_mmap)
739+
wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count, bool pre_mapped)
740740
{
741741
WASMMemoryInstance *memory = wasm_get_default_memory(module);
742742
uint8 *memory_data_old, *memory_data_new, *heap_data_old;
@@ -788,35 +788,35 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count,
788788

789789
bh_assert(total_size_new <= MAX_LINEAR_MEMORY_SIZE);
790790

791-
if (is_mmap) {
792-
LOG_VERBOSE("NOTE: Enlarging memory with mmap syscall by %d pages", inc_page_count);
793-
/*** Added for WALI ***/
794-
goto set_bound_check;
795-
/* */
796-
}
797-
LOG_ERROR("NOTE: Enlarging memory without mmap... There might be errors here..");
798-
799791
if (full_size_mmaped) {
800792

801-
#ifdef BH_PLATFORM_WINDOWS
802-
if (!os_mem_commit(memory->memory_data_end,
803-
(uint32)(total_size_new - total_size_old),
804-
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
805-
ret = false;
806-
goto return_func;
793+
if (pre_mapped) {
794+
LOG_VERBOSE("NOTE: Enlarging memory with mmap syscall by %d pages", inc_page_count);
807795
}
796+
else
797+
{
798+
LOG_VERBOSE("NOTE: Enlarging memory with memory.grow by %d pages... There may be errors here", inc_page_count);
799+
800+
#ifdef BH_PLATFORM_WINDOWS
801+
if (!os_mem_commit(memory->memory_data_end,
802+
(uint32)(total_size_new - total_size_old),
803+
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
804+
ret = false;
805+
goto return_func;
806+
}
808807
#endif
809808

810-
if (os_mprotect(memory->memory_data_end,
811-
(uint32)(total_size_new - total_size_old),
812-
MMAP_PROT_READ | MMAP_PROT_WRITE)
813-
!= 0) {
809+
if (os_mprotect(memory->memory_data_end,
810+
(uint32)(total_size_new - total_size_old),
811+
MMAP_PROT_READ | MMAP_PROT_WRITE)
812+
!= 0) {
814813
#ifdef BH_PLATFORM_WINDOWS
815-
os_mem_decommit(memory->memory_data_end,
816-
(uint32)(total_size_new - total_size_old));
814+
os_mem_decommit(memory->memory_data_end,
815+
(uint32)(total_size_new - total_size_old));
817816
#endif
818-
ret = false;
819-
goto return_func;
817+
ret = false;
818+
goto return_func;
819+
}
820820
}
821821
}
822822
else {
@@ -856,7 +856,6 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count,
856856
#endif
857857
}
858858

859-
set_bound_check:
860859
memory->num_bytes_per_page = num_bytes_per_page;
861860
memory->cur_page_count = total_page_count;
862861
memory->max_page_count = max_page_count;
@@ -896,15 +895,15 @@ wasm_runtime_set_enlarge_mem_error_callback(
896895
}
897896

898897
bool
899-
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count, bool is_mmap)
898+
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count, bool pre_mapped)
900899
{
901900
bool ret = false;
902901

903902
#if WASM_ENABLE_SHARED_MEMORY != 0
904903
if (module->memory_count > 0)
905904
shared_memory_lock(module->memories[0]);
906905
#endif
907-
ret = wasm_enlarge_memory_internal(module, inc_page_count, is_mmap);
906+
ret = wasm_enlarge_memory_internal(module, inc_page_count, pre_mapped);
908907
#if WASM_ENABLE_SHARED_MEMORY != 0
909908
if (module->memory_count > 0)
910909
shared_memory_unlock(module->memories[0]);

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,12 +3495,12 @@ wasm_get_indirect_function (WASMModuleInstance *module_inst, uint32 tbl_idx,
34953495
goto got_exception;
34963496
}
34973497

3498-
if (tbl_elem_idx >= table_inst->cur_size) {
3498+
if (elem_idx >= table_inst->cur_size) {
34993499
wasm_set_exception(module_inst, "undefined element");
35003500
goto got_exception;
35013501
}
35023502

3503-
tbl_elem_val = ((table_elem_type_t *)table_inst->elems)[tbl_elem_idx];
3503+
tbl_elem_val = ((table_elem_type_t *)table_inst->elems)[elem_idx];
35043504
if (tbl_elem_val == NULL_REF) {
35053505
wasm_set_exception(module_inst, "uninitialized element");
35063506
goto got_exception;

core/iwasm/interpreter/wasm_runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ bool
643643
wasm_can_enlarge_memory(WASMModuleInstance *module_inst, uint32 inc_page_count);
644644

645645
bool
646-
wasm_enlarge_memory(WASMModuleInstance *module_inst, uint32 inc_page_count, bool is_mmap);
646+
wasm_enlarge_memory(WASMModuleInstance *module_inst, uint32 inc_page_count, bool pre_mapped);
647647

648648
WASMFunctionInstance*
649649
wasm_get_indirect_function (WASMModuleInstance *module_inst, uint32 tbl_idx,

core/iwasm/libraries/libc-wali/wali.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void wali_init_native(wasm_module_inst_t module_inst) {
166166
/** Helper methods **/
167167
static uint32_t get_current_memory_size(wasm_exec_env_t exec_env) {
168168
wasm_module_inst_t module_inst = get_module_inst(exec_env);
169-
wasm_function_inst_t memorysize_fn = wasm_runtime_lookup_function(module_inst, "wasm_memory_size", "()i");
169+
wasm_function_inst_t memorysize_fn = wasm_runtime_lookup_function(module_inst, "wasm_memory_size");
170170
uint32_t cur_wasm_pages[1];
171171
uint32_t mem_size = 0;
172172
if (memorysize_fn && wasm_runtime_call_wasm(exec_env, memorysize_fn, 0, cur_wasm_pages)) {
@@ -185,7 +185,7 @@ static uint32_t get_current_memory_size(wasm_exec_env_t exec_env) {
185185
* any mmap specifications */
186186
static void grow_memory_size(wasm_exec_env_t exec_env, uint32_t inc_wasm_pages) {
187187
wasm_module_inst_t module_inst = get_module_inst(exec_env);
188-
wasm_function_inst_t memorygrow_fn = wasm_runtime_lookup_function(module_inst, "wasm_memory_grow", "(i)i");
188+
wasm_function_inst_t memorygrow_fn = wasm_runtime_lookup_function(module_inst, "wasm_memory_grow");
189189
uint32_t prev_wasm_pages[1] = { inc_wasm_pages };
190190
if (memorygrow_fn && wasm_runtime_call_wasm(exec_env, memorygrow_fn, 1, prev_wasm_pages)) {
191191
// Success
@@ -1692,7 +1692,7 @@ int wali_wasm_thread_spawn (wasm_exec_env_t exec_env, int setup_fnptr, int arg_w
16921692

16931693
/* New module instance -- custom data, import function registration, etc. */
16941694
if (!(new_module_inst = wasm_runtime_instantiate_internal(
1695-
module, module_inst, exec_env, stack_size, 0, NULL, 0)))
1695+
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0)))
16961696
return -1;
16971697

16981698
wasm_runtime_set_custom_data_internal(
@@ -1719,7 +1719,7 @@ int wali_wasm_thread_spawn (wasm_exec_env_t exec_env, int setup_fnptr, int arg_w
17191719
* Thread ID of the created thread is sent back to parent */
17201720
volatile int child_tid = -1;
17211721
pthread_mutex_lock(&clone_lock);
1722-
ret = wasm_cluster_create_thread(exec_env, new_module_inst, false,
1722+
ret = wasm_cluster_create_thread(exec_env, new_module_inst, false, 0, 0,
17231723
wali_dispatch_thread_libc, thread_start_arg);
17241724
if (ret != 0) {
17251725
FATALSC(wasm_thread_spawn, "Failed to spawn a new thread");

wamr-compiler/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1)
266266
message ("-- Libc WASI enabled")
267267
endif ()
268268

269+
if (WAMR_BUILD_LIBC_WALI EQUAL 1)
270+
message ("-- Libc WALI enabled")
271+
endif ()
272+
269273
if ((NOT WAMR_BUILD_LIBC_WASI) AND (NOT WAMR_BUILD_LIBC_UVWASI))
270274
message ("-- Libc WASI disabled")
271275
endif ()
@@ -311,6 +315,10 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1)
311315
include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
312316
endif ()
313317

318+
if (WAMR_BUILD_LIBC_WALI EQUAL 1)
319+
include (${IWASM_DIR}/libraries/libc-wali/libc_wali.cmake)
320+
endif ()
321+
314322
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
315323
include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
316324
endif ()
@@ -372,7 +380,9 @@ add_library (vmlib
372380
${IWASM_COMMON_SOURCE}
373381
${IWASM_INTERP_SOURCE}
374382
${IWASM_AOT_SOURCE}
375-
${IWASM_GC_SOURCE})
383+
${IWASM_GC_SOURCE}
384+
${LIBC_WALI_SOURCE}
385+
)
376386

377387
add_library (aotclib ${IWASM_COMPL_SOURCE})
378388

0 commit comments

Comments
 (0)