Skip to content

Commit 1a826f3

Browse files
committed
Merge main into dev/fast_jit
2 parents 6e4b2db + 625d591 commit 1a826f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+898
-432
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ if (NOT DEFINED WAMR_BUILD_TARGET)
2525
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
2626
# Build as X86_64 by default in 64-bit platform
2727
set (WAMR_BUILD_TARGET "X86_64")
28-
else ()
28+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
2929
# Build as X86_32 by default in 32-bit platform
3030
set (WAMR_BUILD_TARGET "X86_32")
31+
else ()
32+
message(SEND_ERROR "Unsupported build target platform!")
3133
endif ()
3234
endif ()
3335

build-scripts/runtime_lib.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ if (NOT DEFINED WAMR_BUILD_TARGET)
4141
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
4242
# Build as X86_64 by default in 64-bit platform
4343
set (WAMR_BUILD_TARGET "X86_64")
44-
else ()
44+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
4545
# Build as X86_32 by default in 32-bit platform
4646
set (WAMR_BUILD_TARGET "X86_32")
47+
else ()
48+
message(SEND_ERROR "Unsupported build target platform!")
4749
endif ()
4850
endif ()
4951

core/iwasm/aot/aot_runtime.c

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,9 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
15111511

15121512
#if WASM_ENABLE_DUMP_CALL_STACK != 0
15131513
if (!ret) {
1514-
aot_dump_call_stack(exec_env);
1514+
if (aot_create_call_stack(exec_env)) {
1515+
aot_dump_call_stack(exec_env, true, NULL, 0);
1516+
}
15151517
}
15161518
#endif
15171519

@@ -1568,7 +1570,9 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
15681570

15691571
#if WASM_ENABLE_DUMP_CALL_STACK != 0
15701572
if (aot_get_exception(module_inst)) {
1571-
aot_dump_call_stack(exec_env);
1573+
if (aot_create_call_stack(exec_env)) {
1574+
aot_dump_call_stack(exec_env, true, NULL, 0);
1575+
}
15721576
}
15731577
#endif
15741578

@@ -3018,38 +3022,24 @@ aot_free_frame(WASMExecEnv *exec_env)
30183022
|| (WASM_ENABLE_PERF_PROFILING != 0) */
30193023

30203024
#if WASM_ENABLE_DUMP_CALL_STACK != 0
3021-
void
3022-
aot_dump_call_stack(WASMExecEnv *exec_env)
3025+
bool
3026+
aot_create_call_stack(struct WASMExecEnv *exec_env)
30233027
{
30243028
AOTFrame *cur_frame = (AOTFrame *)exec_env->cur_frame,
30253029
*first_frame = cur_frame;
30263030
AOTModuleInstance *module_inst = (AOTModuleInstance *)exec_env->module_inst;
3027-
const char *func_name;
30283031
uint32 n = 0;
30293032

3030-
os_printf("\n");
30313033
while (cur_frame) {
3032-
func_name =
3033-
get_func_name_from_index(module_inst, cur_frame->func_index);
3034-
3035-
/* function name not exported, print number instead */
3036-
if (func_name == NULL) {
3037-
os_printf("#%02d $f%d \n", n, cur_frame->func_index);
3038-
}
3039-
else {
3040-
os_printf("#%02d %s \n", n, func_name);
3041-
}
3042-
30433034
cur_frame = cur_frame->prev_frame;
30443035
n++;
30453036
}
3046-
os_printf("\n");
30473037

30483038
/* release previous stack frames and create new ones */
30493039
if (!bh_vector_destroy(module_inst->frames.ptr)
30503040
|| !bh_vector_init(module_inst->frames.ptr, n, sizeof(WASMCApiFrame),
30513041
false)) {
3052-
return;
3042+
return false;
30533043
}
30543044

30553045
cur_frame = first_frame;
@@ -3059,14 +3049,85 @@ aot_dump_call_stack(WASMExecEnv *exec_env)
30593049
frame.module_offset = 0;
30603050
frame.func_index = cur_frame->func_index;
30613051
frame.func_offset = 0;
3052+
frame.func_name_wp =
3053+
get_func_name_from_index(module_inst, cur_frame->func_index);
30623054

30633055
if (!bh_vector_append(module_inst->frames.ptr, &frame)) {
30643056
bh_vector_destroy(module_inst->frames.ptr);
3065-
return;
3057+
return false;
30663058
}
30673059

30683060
cur_frame = cur_frame->prev_frame;
30693061
}
3062+
3063+
return true;
3064+
}
3065+
3066+
#define PRINT_OR_DUMP() \
3067+
do { \
3068+
total_len += \
3069+
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
3070+
if ((!print) && buf && (len == 0)) { \
3071+
return total_len; \
3072+
} \
3073+
} while (0)
3074+
3075+
uint32
3076+
aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
3077+
{
3078+
AOTModuleInstance *module_inst = (AOTModuleInstance *)exec_env->module_inst;
3079+
uint32 n = 0, total_len = 0, total_frames;
3080+
/* reserve 256 bytes for line buffer, any line longer than 256 bytes
3081+
* will be truncated */
3082+
char line_buf[256];
3083+
3084+
if (!module_inst->frames.ptr) {
3085+
return 0;
3086+
}
3087+
3088+
total_frames = bh_vector_size(module_inst->frames.ptr);
3089+
if (total_frames == 0) {
3090+
return 0;
3091+
}
3092+
3093+
snprintf(line_buf, sizeof(line_buf), "\n");
3094+
PRINT_OR_DUMP();
3095+
3096+
while (n < total_frames) {
3097+
WASMCApiFrame frame = { 0 };
3098+
uint32 line_length, i;
3099+
3100+
if (!bh_vector_get(module_inst->frames.ptr, n, &frame)) {
3101+
return 0;
3102+
}
3103+
3104+
/* function name not exported, print number instead */
3105+
if (frame.func_name_wp == NULL) {
3106+
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n",
3107+
n, frame.func_index);
3108+
}
3109+
else {
3110+
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
3111+
frame.func_name_wp);
3112+
}
3113+
3114+
if (line_length >= sizeof(line_buf)) {
3115+
uint32 line_buffer_len = sizeof(line_buf);
3116+
/* If line too long, ensure the last character is '\n' */
3117+
for (i = line_buffer_len - 5; i < line_buffer_len - 2; i++) {
3118+
line_buf[i] = '.';
3119+
}
3120+
line_buf[line_buffer_len - 2] = '\n';
3121+
}
3122+
3123+
PRINT_OR_DUMP();
3124+
3125+
n++;
3126+
}
3127+
snprintf(line_buf, sizeof(line_buf), "\n");
3128+
PRINT_OR_DUMP();
3129+
3130+
return total_len + 1;
30703131
}
30713132
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */
30723133

core/iwasm/aot/aot_runtime.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,24 @@ aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
731731
void
732732
aot_free_frame(WASMExecEnv *exec_env);
733733

734-
void
735-
aot_dump_call_stack(WASMExecEnv *exec_env);
734+
bool
735+
aot_create_call_stack(struct WASMExecEnv *exec_env);
736+
737+
/**
738+
* @brief Dump wasm call stack or get the size
739+
*
740+
* @param exec_env the execution environment
741+
* @param print whether to print to stdout or not
742+
* @param buf buffer to store the dumped content
743+
* @param len length of the buffer
744+
*
745+
* @return when print is true, return the bytes printed out to stdout; when
746+
* print is false and buf is NULL, return the size required to store the
747+
* callstack content; when print is false and buf is not NULL, return the size
748+
* dumped to the buffer, 0 means error and data in buf may be invalid
749+
*/
750+
uint32
751+
aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
736752

737753
void
738754
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);

core/iwasm/common/wasm_runtime_common.c

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
30703070
typedef void (*GenericFunctionPointer)();
3071-
int64
3071+
void
30723072
invokeNative(GenericFunctionPointer f, uint32 *args, uint32 n_stacks);
30733073

30743074
typedef float64 (*Float64FuncPtr)(GenericFunctionPointer, uint32 *, uint32);
@@ -3077,13 +3077,16 @@ typedef int64 (*Int64FuncPtr)(GenericFunctionPointer, uint32 *, uint32);
30773077
typedef int32 (*Int32FuncPtr)(GenericFunctionPointer, uint32 *, uint32);
30783078
typedef 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)
35413544
typedef void (*GenericFunctionPointer)();
3542-
int64
3545+
void
35433546
invokeNative(GenericFunctionPointer f, uint32 *args, uint32 sz);
35443547

35453548
typedef float64 (*Float64FuncPtr)(GenericFunctionPointer f, uint32 *, uint32);
@@ -3548,13 +3551,16 @@ typedef int64 (*Int64FuncPtr)(GenericFunctionPointer f, uint32 *, uint32);
35483551
typedef int32 (*Int32FuncPtr)(GenericFunctionPointer f, uint32 *, uint32);
35493552
typedef 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

35593565
static inline void
35603566
word_copy(uint32 *dest, uint32 *src, unsigned num)
@@ -3781,33 +3787,25 @@ typedef uint32x4_t __m128i;
37813787
#endif /* end of WASM_ENABLE_SIMD != 0 */
37823788

37833789
typedef 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-
*/
37913790
void
37923791
invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
3793-
#else
3794-
int64
3795-
invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
3796-
#endif
37973792

37983793
typedef float64 (*Float64FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
37993794
typedef float32 (*Float32FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
38003795
typedef int64 (*Int64FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
38013796
typedef int32 (*Int32FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
38023797
typedef 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
38133811
typedef 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+
45494571
void
45504572
wasm_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

Comments
 (0)