New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
per-host function override of native stack requirement #3325
Comments
Hi, it seems both two methods are not so straightforward, how about we just introduce a new API to set the native stack size required for the host native APIs? Some what like: struct NativeSymbolStack {
const char *name;
uint32 stack_size;
}
wasm_runtime_set_native_api_stacks(NativeSymbolStack *native_stacks, uint32 n_symbol_stack); And the info will be propagated into a field in WASMFunctionImport and AOTFuncImport, and runtime does native stack overflow check according to the field's value before calling the native API, and by default the field value is WASM_STACK_GUARD_SIZE if it isn't set by the API. Also runtime can set the field value of some native APIs after registering some built-in native APIs. |
at this point, i don't have strong opinion on the api. (how to give the n_symbol_stack value.)
|
Yes, it is very similar to the first approach, but no need to make changes for current runtime native libraries implementation and developer's native library registration if there is no extra requirement from him. For the last item, yes, had better let aot compiler emit the check directly, not sure whether it is good to pass the native stack size info to wamrc like registering the empty native apis for it with |
BTW, the api had better use module name as the first argument, like wasm_runtime_register_natives: |
Or just reuse the option |
even with the first approach, users who don't care can leave it default.
with the first approach,
i'm not sure how it looks like.
do you mean to export an extra symbol? anyway, my original concern was not really about |
OK, b is also good as long as it is not very trivial for you to add checks in the native apis. |
This is a test code to examine native stack overflow detection logic. The current output on my environment (macOS amd64): ```shell ====== Interpreter stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 14704 | failed | leaked | Exception: native stack overflow 14704 - 17904 | failed | ok | Exception: native stack overflow 17904 - 24576 | ok | ok | ====== AOT stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 18176 | failed | leaked | Exception: native stack overflow 18176 - 24576 | ok | ok | ====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1 stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 1968 | failed | ok | Exception: native stack overflow 1968 - 24576 | ok | ok | ``` This is a preparation to work on relevant issues, including: bytecodealliance#3325 bytecodealliance#3320 bytecodealliance#3314 bytecodealliance#3297
This is a test code to examine native stack overflow detection logic. The current output on my environment (macOS amd64): ```shell ====== Interpreter stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 14704 | failed | leaked | Exception: native stack overflow 14704 - 17904 | failed | ok | Exception: native stack overflow 17904 - 24576 | ok | ok | ====== AOT stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 18176 | failed | leaked | Exception: native stack overflow 18176 - 24576 | ok | ok | ====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1 stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 1968 | failed | ok | Exception: native stack overflow 1968 - 24576 | ok | ok | ``` This is a preparation to work on relevant issues, including: #3325 #3320 #3314 #3297
This allows each native function to require more native stack. cf. bytecodealliance#3325
This allows each native function to require more native stack. cf. bytecodealliance#3325
This allows each native function to require more native stack. cf. bytecodealliance#3325
- Add a few API (#3325) ```c wasm_runtime_detect_native_stack_overflow_size wasm_runtime_detect_native_stack_overflow ``` - Adapt the runtime to use them - Adapt samples/native-stack-overflow to use them - Add a few missing overflow checks in the interpreters - Build and run the sample on the CI
This is a test code to examine native stack overflow detection logic. The current output on my environment (macOS amd64): ```shell ====== Interpreter stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 14704 | failed | leaked | Exception: native stack overflow 14704 - 17904 | failed | ok | Exception: native stack overflow 17904 - 24576 | ok | ok | ====== AOT stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 18176 | failed | leaked | Exception: native stack overflow 18176 - 24576 | ok | ok | ====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1 stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 1968 | failed | ok | Exception: native stack overflow 1968 - 24576 | ok | ok | ``` This is a preparation to work on relevant issues, including: bytecodealliance#3325 bytecodealliance#3320 bytecodealliance#3314 bytecodealliance#3297
…3355) - Add a few API (bytecodealliance#3325) ```c wasm_runtime_detect_native_stack_overflow_size wasm_runtime_detect_native_stack_overflow ``` - Adapt the runtime to use them - Adapt samples/native-stack-overflow to use them - Add a few missing overflow checks in the interpreters - Build and run the sample on the CI
This is a test code to examine native stack overflow detection logic. The current output on my environment (macOS amd64): ```shell ====== Interpreter stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 14704 | failed | leaked | Exception: native stack overflow 14704 - 17904 | failed | ok | Exception: native stack overflow 17904 - 24576 | ok | ok | ====== AOT stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 18176 | failed | leaked | Exception: native stack overflow 18176 - 24576 | ok | ok | ====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1 stack size | fail? | leak? | exception --------------------------------------------------------------------------- 0 - 1968 | failed | ok | Exception: native stack overflow 1968 - 24576 | ok | ok | ``` This is a preparation to work on relevant issues, including: bytecodealliance#3325 bytecodealliance#3320 bytecodealliance#3314 bytecodealliance#3297 Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…3355) - Add a few API (bytecodealliance#3325) ```c wasm_runtime_detect_native_stack_overflow_size wasm_runtime_detect_native_stack_overflow ``` - Adapt the runtime to use them - Adapt samples/native-stack-overflow to use them - Add a few missing overflow checks in the interpreters - Build and run the sample on the CI Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
consider that you have a few host functions which require huge native stack to run.
right now, you need to bump WASM_STACK_GUARD_SIZE enough for the largest possible consumer
even when you precisely know which instances/threads would use such functions.
it would be nicer to provide a way to keep WASM_STACK_GUARD_SIZE small while allowing a few host functions to consume more stack so that you can use large native stack only for instances/threads which actually need it.
even within our tree, some native functions require more native stack than others.
eg.
wasm-micro-runtime/core/config.h
Line 451 in d39d2ba
eg. #2332
possible implementation approaches:
a. extend NativeSymbol with necessary info. (eg. size_t native_stack_size)
make aot_call_function/aot_call_indirect etc detect overflows using the value.
pros:
cons:
maybe we need to copy it to eg. AOTImportFunc.
(it should be ok for 2.0 though)
needs something different. maybe the aot compiler can emit the check.
however, it would effectively make the stack requirement of the native
function a part of the AOT ABI. i'm not sure if it's acceptable.
a'. wasm_runtime_set_native_api_stacks
use similar detection logic as (a), but a different api to tell stack size.
cons:
wamrc --native-lib
needs extra careb. add an extra overflow detection logic to each possible stack-hogging functions
like this:
pros:
cons:
(eg. libc-uvwasi)
and possibly break the check.
The text was updated successfully, but these errors were encountered: