Skip to content

Commit 1ab7858

Browse files
committed
fix(wasi-threads): allow using WASI threads in AOT mode
1 parent 5f0f8fe commit 1ab7858

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,18 +1783,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
17831783
global = globals + global_idx;
17841784
global_addr = get_global_addr(global_data, global);
17851785
aux_stack_top = *(uint32 *)(frame_sp - 1);
1786-
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) {
1787-
if (aux_stack_top
1788-
<= exec_env->aux_stack_boundary.boundary) {
1789-
wasm_set_exception(module,
1790-
"wasm auxiliary stack overflow");
1786+
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
1787+
wasm_set_exception(module, "wasm auxiliary stack overflow");
17911788
goto got_exception;
17921789
}
17931790
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
17941791
wasm_set_exception(module,
17951792
"wasm auxiliary stack underflow");
17961793
goto got_exception;
1797-
}
17981794
}
17991795
*(int32 *)global_addr = aux_stack_top;
18001796
frame_sp--;

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,18 +1576,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
15761576
global = globals + global_idx;
15771577
global_addr = get_global_addr(global_data, global);
15781578
aux_stack_top = frame_lp[GET_OFFSET()];
1579-
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) {
1580-
if (aux_stack_top
1581-
<= exec_env->aux_stack_boundary.boundary) {
1582-
wasm_set_exception(module,
1583-
"wasm auxiliary stack overflow");
1584-
goto got_exception;
1585-
}
1586-
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
1587-
wasm_set_exception(module,
1588-
"wasm auxiliary stack underflow");
1589-
goto got_exception;
1590-
}
1579+
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
1580+
wasm_set_exception(module, "wasm auxiliary stack overflow");
1581+
goto got_exception;
1582+
}
1583+
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
1584+
wasm_set_exception(module,
1585+
"wasm auxiliary stack underflow");
1586+
goto got_exception;
15911587
}
15921588
*(int32 *)global_addr = aux_stack_top;
15931589
#if WASM_ENABLE_MEMORY_PROFILING != 0

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
567567
goto fail2;
568568
}
569569
}
570+
else {
571+
// Disable aux stack
572+
new_exec_env->aux_stack_boundary.boundary = 0;
573+
new_exec_env->aux_stack_bottom.bottom = UINT32_MAX;
574+
}
570575

571576
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
572577
goto fail2;

samples/wasi-threads/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ make \
1010
THREAD_MODEL=posix
1111
```
1212

13-
Build and run the samples
13+
## Build and run the samples
1414

1515
```shell
1616
$ mkdir build
@@ -22,3 +22,10 @@ $ ./iwasm wasm-apps/no_pthread.wasm
2222
...
2323
$ ./iwasm wasm-apps/exception_propagation.wasm
2424
```
25+
26+
## Run samples in AOT mode
27+
```shell
28+
$ ../../../wamr-compiler/build/wamrc \
29+
-o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm
30+
$ ./iwasm wasm-apps/no_pthread.aot
31+
```

0 commit comments

Comments
 (0)