@@ -3068,7 +3068,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
30683068 || defined(BUILD_TARGET_RISCV32_ILP32D ) \
30693069 || defined(BUILD_TARGET_RISCV32_ILP32 ) || defined(BUILD_TARGET_ARC )
30703070typedef void (* GenericFunctionPointer )();
3071- int64
3071+ void
30723072invokeNative (GenericFunctionPointer f , uint32 * args , uint32 n_stacks );
30733073
30743074typedef float64 (* Float64FuncPtr )(GenericFunctionPointer , uint32 * , uint32 );
@@ -3077,13 +3077,16 @@ typedef int64 (*Int64FuncPtr)(GenericFunctionPointer, uint32 *, uint32);
30773077typedef int32 (* Int32FuncPtr )(GenericFunctionPointer , uint32 * , uint32 );
30783078typedef void (* VoidFuncPtr )(GenericFunctionPointer , uint32 * , uint32 );
30793079
3080- static Float64FuncPtr invokeNative_Float64 =
3080+ static volatile Float64FuncPtr invokeNative_Float64 =
30813081 (Float64FuncPtr )(uintptr_t )invokeNative ;
3082- static Float32FuncPtr invokeNative_Float32 =
3082+ static volatile Float32FuncPtr invokeNative_Float32 =
30833083 (Float32FuncPtr )(uintptr_t )invokeNative ;
3084- static Int64FuncPtr invokeNative_Int64 = (Int64FuncPtr )(uintptr_t )invokeNative ;
3085- static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr )(uintptr_t )invokeNative ;
3086- static VoidFuncPtr invokeNative_Void = (VoidFuncPtr )(uintptr_t )invokeNative ;
3084+ static volatile Int64FuncPtr invokeNative_Int64 =
3085+ (Int64FuncPtr )(uintptr_t )invokeNative ;
3086+ static volatile Int32FuncPtr invokeNative_Int32 =
3087+ (Int32FuncPtr )(uintptr_t )invokeNative ;
3088+ static volatile VoidFuncPtr invokeNative_Void =
3089+ (VoidFuncPtr )(uintptr_t )invokeNative ;
30873090
30883091#if defined(BUILD_TARGET_ARM_VFP ) || defined(BUILD_TARGET_THUMB_VFP )
30893092#define MAX_REG_INTS 4
@@ -3539,7 +3542,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
35393542 || defined(BUILD_TARGET_THUMB ) || defined(BUILD_TARGET_MIPS ) \
35403543 || defined(BUILD_TARGET_XTENSA )
35413544typedef void (* GenericFunctionPointer )();
3542- int64
3545+ void
35433546invokeNative (GenericFunctionPointer f , uint32 * args , uint32 sz );
35443547
35453548typedef float64 (* Float64FuncPtr )(GenericFunctionPointer f , uint32 * , uint32 );
@@ -3548,13 +3551,16 @@ typedef int64 (*Int64FuncPtr)(GenericFunctionPointer f, uint32 *, uint32);
35483551typedef int32 (* Int32FuncPtr )(GenericFunctionPointer f , uint32 * , uint32 );
35493552typedef void (* VoidFuncPtr )(GenericFunctionPointer f , uint32 * , uint32 );
35503553
3551- static Int64FuncPtr invokeNative_Int64 = (Int64FuncPtr )invokeNative ;
3552- static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr )(uintptr_t )invokeNative ;
3553- static Float64FuncPtr invokeNative_Float64 =
3554+ static volatile Int64FuncPtr invokeNative_Int64 =
3555+ (Int64FuncPtr )(uintptr_t )invokeNative ;
3556+ static volatile Int32FuncPtr invokeNative_Int32 =
3557+ (Int32FuncPtr )(uintptr_t )invokeNative ;
3558+ static volatile Float64FuncPtr invokeNative_Float64 =
35543559 (Float64FuncPtr )(uintptr_t )invokeNative ;
3555- static Float32FuncPtr invokeNative_Float32 =
3560+ static volatile Float32FuncPtr invokeNative_Float32 =
35563561 (Float32FuncPtr )(uintptr_t )invokeNative ;
3557- static VoidFuncPtr invokeNative_Void = (VoidFuncPtr )(uintptr_t )invokeNative ;
3562+ static volatile VoidFuncPtr invokeNative_Void =
3563+ (VoidFuncPtr )(uintptr_t )invokeNative ;
35583564
35593565static inline void
35603566word_copy (uint32 * dest , uint32 * src , unsigned num )
@@ -3781,33 +3787,25 @@ typedef uint32x4_t __m128i;
37813787#endif /* end of WASM_ENABLE_SIMD != 0 */
37823788
37833789typedef void (* GenericFunctionPointer )();
3784- #if defined(__APPLE__ ) || defined(__MACH__ )
3785- /**
3786- * Define the return type as 'void' in MacOS, since after converting
3787- * 'int64 invokeNative' into 'float64 invokeNative_Float64', the
3788- * return value passing might be invalid, the caller reads the return
3789- * value from register rax but not xmm0.
3790- */
37913790void
37923791invokeNative (GenericFunctionPointer f , uint64 * args , uint64 n_stacks );
3793- #else
3794- int64
3795- invokeNative (GenericFunctionPointer f , uint64 * args , uint64 n_stacks );
3796- #endif
37973792
37983793typedef float64 (* Float64FuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
37993794typedef float32 (* Float32FuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
38003795typedef int64 (* Int64FuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
38013796typedef int32 (* Int32FuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
38023797typedef void (* VoidFuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
38033798
3804- static Float64FuncPtr invokeNative_Float64 =
3799+ static volatile Float64FuncPtr invokeNative_Float64 =
38053800 (Float64FuncPtr )(uintptr_t )invokeNative ;
3806- static Float32FuncPtr invokeNative_Float32 =
3801+ static volatile Float32FuncPtr invokeNative_Float32 =
38073802 (Float32FuncPtr )(uintptr_t )invokeNative ;
3808- static Int64FuncPtr invokeNative_Int64 = (Int64FuncPtr )(uintptr_t )invokeNative ;
3809- static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr )(uintptr_t )invokeNative ;
3810- static VoidFuncPtr invokeNative_Void = (VoidFuncPtr )(uintptr_t )invokeNative ;
3803+ static volatile Int64FuncPtr invokeNative_Int64 =
3804+ (Int64FuncPtr )(uintptr_t )invokeNative ;
3805+ static volatile Int32FuncPtr invokeNative_Int32 =
3806+ (Int32FuncPtr )(uintptr_t )invokeNative ;
3807+ static volatile VoidFuncPtr invokeNative_Void =
3808+ (VoidFuncPtr )(uintptr_t )invokeNative ;
38113809
38123810#if WASM_ENABLE_SIMD != 0
38133811typedef v128 (* V128FuncPtr )(GenericFunctionPointer , uint64 * , uint64 );
@@ -4546,21 +4544,86 @@ wasm_externref_retain(uint32 externref_idx)
45464544#endif /* end of WASM_ENABLE_REF_TYPES */
45474545
45484546#if WASM_ENABLE_DUMP_CALL_STACK != 0
4547+ uint32
4548+ wasm_runtime_dump_line_buf_impl (const char * line_buf , bool dump_or_print ,
4549+ char * * buf , uint32 * len )
4550+ {
4551+ if (dump_or_print ) {
4552+ return (uint32 )os_printf ("%s" , line_buf );
4553+ }
4554+ else if (* buf ) {
4555+ uint32 dump_len ;
4556+
4557+ dump_len = snprintf (* buf , * len , "%s" , line_buf );
4558+ if (dump_len >= * len ) {
4559+ dump_len = * len ;
4560+ }
4561+
4562+ * len = * len - dump_len ;
4563+ * buf = * buf + dump_len ;
4564+ return dump_len ;
4565+ }
4566+ else {
4567+ return strlen (line_buf );
4568+ }
4569+ }
4570+
45494571void
45504572wasm_runtime_dump_call_stack (WASMExecEnv * exec_env )
45514573{
45524574 WASMModuleInstanceCommon * module_inst =
45534575 wasm_exec_env_get_module_inst (exec_env );
45544576#if WASM_ENABLE_INTERP != 0
45554577 if (module_inst -> module_type == Wasm_Module_Bytecode ) {
4556- wasm_interp_dump_call_stack (exec_env );
4578+ wasm_interp_dump_call_stack (exec_env , true, NULL , 0 );
4579+ }
4580+ #endif
4581+ #if WASM_ENABLE_AOT != 0
4582+ if (module_inst -> module_type == Wasm_Module_AoT ) {
4583+ aot_dump_call_stack (exec_env , true, NULL , 0 );
4584+ }
4585+ #endif
4586+ }
4587+
4588+ uint32
4589+ wasm_runtime_get_call_stack_buf_size (wasm_exec_env_t exec_env )
4590+ {
4591+ WASMModuleInstanceCommon * module_inst =
4592+ wasm_exec_env_get_module_inst (exec_env );
4593+
4594+ #if WASM_ENABLE_INTERP != 0
4595+ if (module_inst -> module_type == Wasm_Module_Bytecode ) {
4596+ return wasm_interp_dump_call_stack (exec_env , false, NULL , 0 );
4597+ }
4598+ #endif
4599+ #if WASM_ENABLE_AOT != 0
4600+ if (module_inst -> module_type == Wasm_Module_AoT ) {
4601+ return aot_dump_call_stack (exec_env , false, NULL , 0 );
4602+ }
4603+ #endif
4604+
4605+ return 0 ;
4606+ }
4607+
4608+ uint32
4609+ wasm_runtime_dump_call_stack_to_buf (wasm_exec_env_t exec_env , char * buf ,
4610+ uint32 len )
4611+ {
4612+ WASMModuleInstanceCommon * module_inst =
4613+ wasm_exec_env_get_module_inst (exec_env );
4614+
4615+ #if WASM_ENABLE_INTERP != 0
4616+ if (module_inst -> module_type == Wasm_Module_Bytecode ) {
4617+ return wasm_interp_dump_call_stack (exec_env , false, buf , len );
45574618 }
45584619#endif
45594620#if WASM_ENABLE_AOT != 0
45604621 if (module_inst -> module_type == Wasm_Module_AoT ) {
4561- aot_dump_call_stack (exec_env );
4622+ return aot_dump_call_stack (exec_env , false, buf , len );
45624623 }
45634624#endif
4625+
4626+ return 0 ;
45644627}
45654628#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */
45664629
0 commit comments