From e414a327a0d0afaaf13ec4036f2b4f05c8a81c64 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 24 Jun 2025 20:38:30 +0800 Subject: [PATCH] Refactor copy callstack feature (#4401) - Change `WAMR_ENABLE_COPY_CALLSTACK` to `WAMR_BUILD_COPY_CALL_STACK`, as `WAMR_BUILD` is the prefix for a command line option. - Change `WAMR_ENABLE_COPY_CALLSTACK` to `WASM_ENABLE_COPY_CALL_STACK`, as `WASM_ENABLE` is the prefix for a macro in the source code. - Change `CALLSTACK` to `CALL_STACK` to align with the existing `DUMP_CALL_STACK` feature. - Continue using `WASMCApiFrame` instead of `wasm_frame_t` outside of *wasm_c_api.xxx* to avoid a typedef redefinition warning, which is identified by Clang. --- CMakeLists.txt | 4 ++-- build-scripts/config_common.cmake | 9 ++------- core/config.h | 4 ++-- core/iwasm/aot/aot_runtime.c | 10 +++++----- core/iwasm/aot/aot_runtime.h | 6 +++--- core/iwasm/common/wasm_runtime_common.c | 6 +++--- core/iwasm/common/wasm_runtime_common.h | 6 +++--- core/iwasm/include/wasm_export.h | 4 +--- core/iwasm/interpreter/wasm_runtime.c | 6 +++--- core/iwasm/interpreter/wasm_runtime.h | 6 +++--- 10 files changed, 27 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88a1642b8..4b28fa89c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,9 +99,9 @@ if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS) set (WAMR_BUILD_LIB_WASI_THREADS 0) endif () -if (NOT DEFINED WAMR_ENABLE_COPY_CALLSTACK) +if (NOT DEFINED WAMR_BUILD_COPY_CALL_STACK) # Disable copy callstack by default - set (WAMR_ENABLE_COPY_CALLSTACK 0) + set (WAMR_BUILD_COPY_CALL_STACK 0) endif() if (NOT DEFINED WAMR_BUILD_MINI_LOADER) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index b4013210a..ca9360a63 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -334,15 +334,10 @@ if (WAMR_BUILD_SHARED_HEAP EQUAL 1) add_definitions (-DWASM_ENABLE_SHARED_HEAP=1) message (" Shared heap enabled") endif() - -if (WAMR_ENABLE_COPY_CALLSTACK EQUAL 1) - add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=1) +if (WAMR_BUILD_COPY_CALL_STACK EQUAL 1) + add_definitions (-DWASM_ENABLE_COPY_CALL_STACK=1) message(" Copy callstack enabled") -else () - add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=0) - message(" Copy callstack disabled") endif() - if (WAMR_BUILD_MEMORY64 EQUAL 1) # if native is 32-bit or cross-compiled to 32-bit if (NOT WAMR_BUILD_TARGET MATCHES ".*64.*") diff --git a/core/config.h b/core/config.h index a4e1499e3..c43a1bfe4 100644 --- a/core/config.h +++ b/core/config.h @@ -193,8 +193,8 @@ #error "Heap aux stack allocation must be enabled for WASI threads" #endif -#ifndef WAMR_ENABLE_COPY_CALLSTACK -#define WAMR_ENABLE_COPY_CALLSTACK 0 +#ifndef WASM_ENABLE_COPY_CALL_STACK +#define WASM_ENABLE_COPY_CALL_STACK 0 #endif #ifndef WASM_ENABLE_BASE_LIB diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index c5e143189..f93e03dac 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -4137,9 +4137,9 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame) } #endif /* end of WASM_ENABLE_AOT_STACK_FRAME != 0 */ -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 uint32 -aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer, +aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32 error_buf_size) { @@ -4193,7 +4193,7 @@ aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer, } uint32 -aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer, +aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32_t error_buf_size) { @@ -4243,7 +4243,7 @@ aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer, } uint32 -aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, +aot_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32_t error_buf_size) { @@ -4265,7 +4265,7 @@ aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, error_buf, error_buf_size); } } -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK #if WASM_ENABLE_DUMP_CALL_STACK != 0 bool diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index e5678a8d6..e957f3959 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -787,12 +787,12 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame); bool aot_create_call_stack(struct WASMExecEnv *exec_env); -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 uint32 -aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, +aot_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32_t error_buf_size); -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK /** * @brief Dump wasm call stack or get the size diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index dcee0aeaf..e1d3542b9 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -1743,9 +1743,9 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env) wasm_exec_env_destroy(exec_env); } -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 uint32 -wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer, +wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32_t error_buf_size) { @@ -1780,7 +1780,7 @@ wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer, strncpy(error_buf, err_msg, error_buf_size); return 0; } -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK bool wasm_runtime_init_thread_env(void) diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index 64a6cd793..ad22ea10b 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -758,12 +758,12 @@ wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst, WASM_RUNTIME_API_EXTERN void wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env); -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 WASM_RUNTIME_API_EXTERN uint32_t -wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer, +wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer, const uint32 length, const uint32 skip_n, char *error_buf, uint32 error_buf_size); -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK /* See wasm_export.h for description */ WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon * diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index b4ab34bea..ca96f5824 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -139,8 +139,6 @@ typedef struct wasm_frame_t { uint32_t *lp; } WASMCApiFrame; -typedef WASMCApiFrame wasm_frame_t; - /* WASM section */ typedef struct wasm_section_t { struct wasm_section_t *next; @@ -904,7 +902,7 @@ wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env); * @return number of copied frames */ WASM_RUNTIME_API_EXTERN uint32_t -wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer, +wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer, const uint32_t length, const uint32_t skip_n, char *error_buf, uint32_t error_buf_size); diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 3cc2afe04..15d07ae98 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -4195,9 +4195,9 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst, #endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0) \ || (WASM_ENABLE_MEMORY_TRACING != 0) */ -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 uint32 -wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, +wasm_interp_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer, uint32 length, uint32 skip_n, char *error_buf, uint32_t error_buf_size) { @@ -4242,7 +4242,7 @@ wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, } return count >= skip_n ? count - skip_n : 0; } -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK #if WASM_ENABLE_DUMP_CALL_STACK != 0 bool diff --git a/core/iwasm/interpreter/wasm_runtime.h b/core/iwasm/interpreter/wasm_runtime.h index 8d38c8831..3d91d8b60 100644 --- a/core/iwasm/interpreter/wasm_runtime.h +++ b/core/iwasm/interpreter/wasm_runtime.h @@ -731,12 +731,12 @@ wasm_get_table_inst(const WASMModuleInstance *module_inst, uint32 tbl_idx) #if WASM_ENABLE_DUMP_CALL_STACK != 0 -#if WAMR_ENABLE_COPY_CALLSTACK != 0 +#if WASM_ENABLE_COPY_CALL_STACK != 0 uint32 -wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer, +wasm_interp_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer, uint32 length, uint32 skip_n, char *error_buf, uint32_t error_buf_size); -#endif // WAMR_ENABLE_COPY_CALLSTACK +#endif // WASM_ENABLE_COPY_CALL_STACK bool wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);