diff --git a/samples/native-stack-overflow/run.sh b/samples/native-stack-overflow/run.sh index 6447b38c6..12254476d 100755 --- a/samples/native-stack-overflow/run.sh +++ b/samples/native-stack-overflow/run.sh @@ -1,16 +1,18 @@ #!/bin/bash +NAME=${1:-test1} + echo "====== Interpreter" -out/native-stack-overflow out/wasm-apps/testapp.wasm +out/native-stack-overflow out/wasm-apps/testapp.wasm ${NAME} echo echo "====== Interpreter WAMR_DISABLE_HW_BOUND_CHECK=1" -out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm +out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm ${NAME} echo echo "====== AOT" -out/native-stack-overflow out/wasm-apps/testapp.wasm.aot +out/native-stack-overflow out/wasm-apps/testapp.wasm.aot ${NAME} echo echo "====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1" -out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm.aot.bounds-checks +out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm.aot.bounds-checks ${NAME} diff --git a/samples/native-stack-overflow/src/main.c b/samples/native-stack-overflow/src/main.c index 1f24be48d..663e18702 100644 --- a/samples/native-stack-overflow/src/main.c +++ b/samples/native-stack-overflow/src/main.c @@ -40,10 +40,11 @@ main(int argc, char **argv) char *buffer; char error_buf[128]; - if (argc != 2) { + if (argc != 3) { return 2; } - char *module_path = argv[1]; + const char *module_path = argv[1]; + const char *funcname = argv[2]; wasm_module_t module = NULL; uint32 buf_size; @@ -124,7 +125,6 @@ main(int argc, char **argv) goto fail2; } - const char *funcname = "test"; wasm_function_inst_t func = wasm_runtime_lookup_function(module_inst, funcname); if (!func) { diff --git a/samples/native-stack-overflow/src/native_impl.c b/samples/native-stack-overflow/src/native_impl.c index 0a5f77742..1b27bcce6 100644 --- a/samples/native-stack-overflow/src/native_impl.c +++ b/samples/native-stack-overflow/src/native_impl.c @@ -54,7 +54,7 @@ host_consume_stack_and_call_indirect(wasm_exec_env_t exec_env, uint32_t funcidx, return call_indirect(exec_env, funcidx, x); } -static uint32_t +__attribute__((noinline)) static uint32_t consume_stack1(wasm_exec_env_t exec_env, void *base, uint32_t stack) { void *fp = __builtin_frame_address(0); diff --git a/samples/native-stack-overflow/wasm-apps/testapp.c b/samples/native-stack-overflow/wasm-apps/testapp.c index b302ab0d7..23ea32efc 100644 --- a/samples/native-stack-overflow/wasm-apps/testapp.c +++ b/samples/native-stack-overflow/wasm-apps/testapp.c @@ -39,14 +39,9 @@ host_consume_stack_cb(int x) return host_consume_stack(x); } -__attribute__((export_name("test"))) uint32_t -test(uint32_t native_stack, uint32_t recurse_count) +__attribute__((export_name("test1"))) uint32_t +test1(uint32_t native_stack, uint32_t recurse_count) { - uint32_t ret; -#if 0 /* notyet */ - ret = host_consume_stack_and_call_indirect(cb, 321, native_stack); -#endif - /* * ------ os_thread_get_stack_boundary * ^ @@ -65,11 +60,15 @@ test(uint32_t native_stack, uint32_t recurse_count) * * */ - ret = host_consume_stack_and_call_indirect(consume_stack_cb, recurse_count, - native_stack); -#if 0 /* notyet */ - ret = host_consume_stack_and_call_indirect(host_consume_stack_cb, 1000000, - native_stack); -#endif + uint32_t ret = host_consume_stack_and_call_indirect( + consume_stack_cb, recurse_count, native_stack); + return 42; +} + +__attribute__((export_name("test2"))) uint32_t +test2(uint32_t native_stack, uint32_t recurse_count) +{ + uint32_t ret = host_consume_stack_and_call_indirect(host_consume_stack_cb, + 6000, native_stack); return 42; }