mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
Document how to use WASI threads in AOT mode (#1905)
Describe how to use WASI threads in AOT mode, following the discussion below: https://github.com/bytecodealliance/wasm-micro-runtime/pull/1867#discussion_r1070268062 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
This commit is contained in:
parent
42f8fed20e
commit
2eed50b303
|
@ -1780,18 +1780,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
global = globals + global_idx;
|
global = globals + global_idx;
|
||||||
global_addr = get_global_addr(global_data, global);
|
global_addr = get_global_addr(global_data, global);
|
||||||
aux_stack_top = *(uint32 *)(frame_sp - 1);
|
aux_stack_top = *(uint32 *)(frame_sp - 1);
|
||||||
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) {
|
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
|
||||||
if (aux_stack_top
|
wasm_set_exception(module, "wasm auxiliary stack overflow");
|
||||||
<= exec_env->aux_stack_boundary.boundary) {
|
goto got_exception;
|
||||||
wasm_set_exception(module,
|
}
|
||||||
"wasm auxiliary stack overflow");
|
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
|
||||||
goto got_exception;
|
wasm_set_exception(module,
|
||||||
}
|
"wasm auxiliary stack underflow");
|
||||||
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
|
goto got_exception;
|
||||||
wasm_set_exception(module,
|
|
||||||
"wasm auxiliary stack underflow");
|
|
||||||
goto got_exception;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*(int32 *)global_addr = aux_stack_top;
|
*(int32 *)global_addr = aux_stack_top;
|
||||||
frame_sp--;
|
frame_sp--;
|
||||||
|
|
|
@ -1576,18 +1576,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
global = globals + global_idx;
|
global = globals + global_idx;
|
||||||
global_addr = get_global_addr(global_data, global);
|
global_addr = get_global_addr(global_data, global);
|
||||||
aux_stack_top = frame_lp[GET_OFFSET()];
|
aux_stack_top = frame_lp[GET_OFFSET()];
|
||||||
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) {
|
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
|
||||||
if (aux_stack_top
|
wasm_set_exception(module, "wasm auxiliary stack overflow");
|
||||||
<= exec_env->aux_stack_boundary.boundary) {
|
goto got_exception;
|
||||||
wasm_set_exception(module,
|
}
|
||||||
"wasm auxiliary stack overflow");
|
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
|
||||||
goto got_exception;
|
wasm_set_exception(module,
|
||||||
}
|
"wasm auxiliary stack underflow");
|
||||||
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
|
goto got_exception;
|
||||||
wasm_set_exception(module,
|
|
||||||
"wasm auxiliary stack underflow");
|
|
||||||
goto got_exception;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*(int32 *)global_addr = aux_stack_top;
|
*(int32 *)global_addr = aux_stack_top;
|
||||||
#if WASM_ENABLE_MEMORY_PROFILING != 0
|
#if WASM_ENABLE_MEMORY_PROFILING != 0
|
||||||
|
|
|
@ -586,6 +586,11 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||||
goto fail3;
|
goto fail3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* Disable aux stack */
|
||||||
|
new_exec_env->aux_stack_boundary.boundary = 0;
|
||||||
|
new_exec_env->aux_stack_bottom.bottom = UINT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
|
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
|
||||||
goto fail3;
|
goto fail3;
|
||||||
|
|
|
@ -10,7 +10,7 @@ make \
|
||||||
THREAD_MODEL=posix
|
THREAD_MODEL=posix
|
||||||
```
|
```
|
||||||
|
|
||||||
Build and run the samples
|
## Build and run the samples
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ mkdir build
|
$ mkdir build
|
||||||
|
@ -22,3 +22,10 @@ $ ./iwasm wasm-apps/no_pthread.wasm
|
||||||
...
|
...
|
||||||
$ ./iwasm wasm-apps/exception_propagation.wasm
|
$ ./iwasm wasm-apps/exception_propagation.wasm
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Run samples in AOT mode
|
||||||
|
```shell
|
||||||
|
$ ../../../wamr-compiler/build/wamrc \
|
||||||
|
-o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm
|
||||||
|
$ ./iwasm wasm-apps/no_pthread.aot
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user