Skip to content

Commit 2eed50b

Browse files
authored
Document how to use WASI threads in AOT mode (bytecodealliance#1905)
Describe how to use WASI threads in AOT mode, following the discussion below: bytecodealliance#1867 (comment) Make aux stack boundary checks of wasi-threads always successful by setting `exec_env->aux_stack_bottom` to UINT32_MAX and `exec_env->aux_stack_boundary` to 0
1 parent 42f8fed commit 2eed50b

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,18 +1780,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
17801780
global = globals + global_idx;
17811781
global_addr = get_global_addr(global_data, global);
17821782
aux_stack_top = *(uint32 *)(frame_sp - 1);
1783-
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) {
1784-
if (aux_stack_top
1785-
<= exec_env->aux_stack_boundary.boundary) {
1786-
wasm_set_exception(module,
1787-
"wasm auxiliary stack overflow");
1788-
goto got_exception;
1789-
}
1790-
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
1791-
wasm_set_exception(module,
1792-
"wasm auxiliary stack underflow");
1793-
goto got_exception;
1794-
}
1783+
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
1784+
wasm_set_exception(module, "wasm auxiliary stack overflow");
1785+
goto got_exception;
1786+
}
1787+
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
1788+
wasm_set_exception(module,
1789+
"wasm auxiliary stack underflow");
1790+
goto got_exception;
17951791
}
17961792
*(int32 *)global_addr = aux_stack_top;
17971793
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
@@ -586,6 +586,11 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
586586
goto fail3;
587587
}
588588
}
589+
else {
590+
/* Disable aux stack */
591+
new_exec_env->aux_stack_boundary.boundary = 0;
592+
new_exec_env->aux_stack_bottom.bottom = UINT32_MAX;
593+
}
589594

590595
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
591596
goto fail3;

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)