Skip to content

Commit 78063f5

Browse files
committed
Add API for disabling native stack boundary checks
This API can be helpful if e.g. module is working in a reactor mode, and the module is being used from multiple threads (where the caller guarantees that no two threads execute code on the same execution environment). Currently this usecase fails because the native stack boundaries for each thread are different. Alternative to this solution would be to update the boundary on every thread switch but that might not be desired due to performance.
1 parent b6dea22 commit 78063f5

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

core/iwasm/common/wasm_exec_env.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
282282
os_mutex_lock(&exec_env->wait_lock);
283283
#endif
284284
exec_env->handle = os_self_thread();
285-
if (exec_env->user_native_stack_boundary)
285+
if (exec_env->user_native_stack_boundary = (void *)UINTPTR_MAX)
286+
exec_env->native_stack_boundary = NULL;
287+
else if (exec_env->user_native_stack_boundary)
286288
/* WASM_STACK_GUARD_SIZE isn't added for flexibility to developer,
287289
he must ensure that enough guard bytes are kept. */
288290
exec_env->native_stack_boundary = exec_env->user_native_stack_boundary;

core/iwasm/common/wasm_runtime_common.c

+6
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,12 @@ wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env,
22322232
exec_env->user_native_stack_boundary = native_stack_boundary;
22332233
}
22342234

2235+
void
2236+
wasm_runtime_disable_native_stack_boundary_check(WASMExecEnv *exec_env)
2237+
{
2238+
exec_env->user_native_stack_boundary = (void *)UINTPTR_MAX;
2239+
}
2240+
22352241
#ifdef OS_ENABLE_HW_BOUND_CHECK
22362242
void
22372243
wasm_runtime_access_exce_check_guard_page()

core/iwasm/common/wasm_runtime_common.h

+4
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ WASM_RUNTIME_API_EXTERN void
678678
wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env,
679679
uint8 *native_stack_boundary);
680680

681+
/* See wasm_export.h for description */
682+
WASM_RUNTIME_API_EXTERN void
683+
wasm_runtime_disable_native_stack_boundary_check(WASMExecEnv *exec_env);
684+
681685
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
682686
/* See wasm_export.h for description */
683687
WASM_RUNTIME_API_EXTERN void

core/iwasm/include/wasm_export.h

+8
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,14 @@ WASM_RUNTIME_API_EXTERN void
17771777
wasm_runtime_set_native_stack_boundary(wasm_exec_env_t exec_env,
17781778
uint8_t *native_stack_boundary);
17791779

1780+
/**
1781+
* Disable native stack boundary check.
1782+
*
1783+
* @param exec_env the execution environment
1784+
*/
1785+
WASM_RUNTIME_API_EXTERN void
1786+
wasm_runtime_disable_native_stack_boundary_check(wasm_exec_env_t exec_env);
1787+
17801788
/**
17811789
* Dump runtime memory consumption, including:
17821790
* Exec env memory consumption

0 commit comments

Comments
 (0)