Skip to content

Commit c197b34

Browse files
authored
Merge pull request #692 from bytecodealliance/main
Merge bytecodealliance:main into wenyongh:main
2 parents 541668b + 1f4580f commit c197b34

File tree

8 files changed

+65
-20
lines changed

8 files changed

+65
-20
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ jobs:
424424

425425
- name: set env variable(if x86_32 test needed)
426426
if: >
427-
(matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS')
427+
(matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS'
428+
|| matrix.test_option == '$WASI_TEST_OPTIONS')
428429
&& matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit'
429430
run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV
430431

core/iwasm/aot/aot_loader.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,10 @@ load_import_globals(const uint8 **p_buf, const uint8 *buf_end,
12261226
}
12271227
import_globals[i].global_data_linked =
12281228
tmp_global.global_data_linked;
1229+
import_globals[i].is_linked = true;
12291230
}
1231+
#else
1232+
import_globals[i].is_linked = false;
12301233
#endif
12311234

12321235
import_globals[i].size = wasm_value_type_size(import_globals[i].type);

core/iwasm/aot/aot_runtime.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,26 @@ execute_memory_init_function(AOTModuleInstance *module_inst)
976976
}
977977
#endif
978978

979+
static bool
980+
check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size)
981+
{
982+
uint32 i;
983+
984+
/* init_func_ptrs() will go through import functions */
985+
986+
for (i = 0; i < module->import_global_count; i++) {
987+
AOTImportGlobal *global = module->import_globals + i;
988+
if (!global->is_linked) {
989+
set_error_buf_v(error_buf, error_buf_size,
990+
"failed to link import global (%s, %s)",
991+
global->module_name, global->global_name);
992+
return false;
993+
}
994+
}
995+
996+
return true;
997+
}
998+
979999
AOTModuleInstance *
9801000
aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
9811001
uint32 heap_size, char *error_buf, uint32 error_buf_size)
@@ -1059,6 +1079,9 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
10591079
if (!init_func_type_indexes(module_inst, module, error_buf, error_buf_size))
10601080
goto fail;
10611081

1082+
if (!check_linked_symbol(module, error_buf, error_buf_size))
1083+
goto fail;
1084+
10621085
if (!create_exports(module_inst, module, error_buf, error_buf_size))
10631086
goto fail;
10641087

core/iwasm/common/wasm_c_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,6 +4555,7 @@ aot_link_global(const AOTModule *module_aot, uint16 global_idx_rt,
45554555
}
45564556

45574557
import->global_idx_rt = global_idx_rt;
4558+
import_aot_global->is_linked = true;
45584559
return true;
45594560

45604561
failed:

core/iwasm/compilation/aot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ typedef struct AOTImportGlobal {
149149
uint32 data_offset;
150150
/* global data after linked */
151151
WASMValue global_data_linked;
152+
bool is_linked;
152153
} AOTImportGlobal;
153154

154155
/**

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
12351235
#if WASM_ENABLE_WAMR_COMPILER == 0
12361236
LOG_WARNING("warning: failed to link import function (%s, %s)",
12371237
func->module_name, func->field_name);
1238+
/* will throw exception only if calling */
12381239
#else
12391240
/* do nothing to avoid confused message */
12401241
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */
@@ -1250,8 +1251,10 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
12501251
return false;
12511252
#else
12521253
#if WASM_ENABLE_WAMR_COMPILER == 0
1253-
LOG_DEBUG("warning: failed to link import global (%s, %s)",
1254-
global->module_name, global->field_name);
1254+
set_error_buf_v(error_buf, error_buf_size,
1255+
"failed to link import global (%s, %s)",
1256+
global->module_name, global->field_name);
1257+
return false;
12551258
#else
12561259
/* do nothing to avoid confused message */
12571260
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */

core/shared/platform/windows/platform_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ typedef struct os_thread_wait_node *os_thread_wait_list;
7272
typedef struct korp_cond {
7373
korp_mutex wait_list_lock;
7474
os_thread_wait_list thread_wait_list;
75+
struct os_thread_wait_node *thread_wait_list_end;
7576
} korp_cond;
7677

7778
#define bh_socket_t SOCKET

core/shared/platform/windows/win_thread.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef struct os_thread_data {
3737
korp_mutex wait_lock;
3838
/* Waiting list of other threads who are joining this thread */
3939
os_thread_wait_list thread_wait_list;
40+
/* End node of the waiting list */
41+
os_thread_wait_node *thread_wait_list_end;
4042
/* Whether the thread has exited */
4143
bool thread_exited;
4244
/* Thread return value */
@@ -174,7 +176,8 @@ os_thread_cleanup(void *retval)
174176
os_sem_signal(&head->sem);
175177
head = next;
176178
}
177-
thread_data->thread_wait_list = NULL;
179+
thread_data->thread_wait_list = thread_data->thread_wait_list_end =
180+
NULL;
178181
}
179182
/* Set thread status and thread return value */
180183
thread_data->thread_exited = true;
@@ -313,14 +316,14 @@ os_thread_join(korp_tid thread, void **p_retval)
313316
}
314317

315318
/* Thread is running */
316-
if (!thread_data->thread_wait_list)
317-
thread_data->thread_wait_list = &curr_thread_data->wait_node;
318-
else {
319+
if (!thread_data->thread_wait_list) { /* Waiting list is empty */
320+
thread_data->thread_wait_list = thread_data->thread_wait_list_end =
321+
&curr_thread_data->wait_node;
322+
}
323+
else { /* Waiting list isn't empty */
319324
/* Add to end of waiting list */
320-
os_thread_wait_node *p = thread_data->thread_wait_list;
321-
while (p->next)
322-
p = p->next;
323-
p->next = &curr_thread_data->wait_node;
325+
thread_data->thread_wait_list_end->next = &curr_thread_data->wait_node;
326+
thread_data->thread_wait_list_end = &curr_thread_data->wait_node;
324327
}
325328

326329
os_mutex_unlock(&thread_data->wait_lock);
@@ -545,7 +548,7 @@ os_cond_init(korp_cond *cond)
545548
if (os_mutex_init(&cond->wait_list_lock) != BHT_OK)
546549
return BHT_ERROR;
547550

548-
cond->thread_wait_list = NULL;
551+
cond->thread_wait_list = cond->thread_wait_list_end = NULL;
549552
return BHT_OK;
550553
}
551554

@@ -568,14 +571,13 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
568571
bh_assert(cond);
569572
bh_assert(mutex);
570573
os_mutex_lock(&cond->wait_list_lock);
571-
if (!cond->thread_wait_list)
572-
cond->thread_wait_list = node;
573-
else {
574+
if (!cond->thread_wait_list) { /* Waiting list is empty */
575+
cond->thread_wait_list = cond->thread_wait_list_end = node;
576+
}
577+
else { /* Waiting list isn't empty */
574578
/* Add to end of wait list */
575-
os_thread_wait_node *p = cond->thread_wait_list;
576-
while (p->next)
577-
p = p->next;
578-
p->next = node;
579+
cond->thread_wait_list_end->next = node;
580+
cond->thread_wait_list_end = node;
579581
}
580582
os_mutex_unlock(&cond->wait_list_lock);
581583

@@ -590,14 +592,24 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
590592

591593
/* Remove wait node from wait list */
592594
os_mutex_lock(&cond->wait_list_lock);
593-
if (cond->thread_wait_list == node)
595+
if (cond->thread_wait_list == node) {
594596
cond->thread_wait_list = node->next;
597+
598+
if (cond->thread_wait_list_end == node) {
599+
bh_assert(node->next == NULL);
600+
cond->thread_wait_list_end = NULL;
601+
}
602+
}
595603
else {
596604
/* Remove from the wait list */
597605
os_thread_wait_node *p = cond->thread_wait_list;
598606
while (p->next != node)
599607
p = p->next;
600608
p->next = node->next;
609+
610+
if (cond->thread_wait_list_end == node) {
611+
cond->thread_wait_list_end = p;
612+
}
601613
}
602614
os_mutex_unlock(&cond->wait_list_lock);
603615

0 commit comments

Comments
 (0)