Skip to content

Commit fc3077b

Browse files
author
Georgii Rylov
committed
address comments
1 parent 99cb6ec commit fc3077b

File tree

8 files changed

+45
-31
lines changed

8 files changed

+45
-31
lines changed

core/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@
193193
#error "Heap aux stack allocation must be enabled for WASI threads"
194194
#endif
195195

196+
#ifndef WAMR_ENABLE_COPY_CALLSTACK
197+
#define WAMR_ENABLE_COPY_CALLSTACK 0
198+
#endif
199+
196200
#ifndef WASM_ENABLE_BASE_LIB
197201
#define WASM_ENABLE_BASE_LIB 0
198202
#endif

core/iwasm/aot/aot_runtime.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../common/wasm_runtime_common.h"
1111
#include "../common/wasm_memory.h"
1212
#include "../interpreter/wasm_runtime.h"
13+
#include <string.h>
1314
#if WASM_ENABLE_SHARED_MEMORY != 0
1415
#include "../common/wasm_shared_memory.h"
1516
#endif
@@ -4105,8 +4106,8 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame)
41054106

41064107
#if WAMR_ENABLE_COPY_CALLSTACK != 0
41074108
uint32
4108-
aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
4109-
const uint32 length, const uint32 skip_n)
4109+
aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_t* buffer,
4110+
const uint32 length, const uint32 skip_n, char *error_buf, uint32 error_buf_size)
41104111
{
41114112
/*
41124113
* Note for devs: please refrain from such modifications inside of
@@ -4126,12 +4127,16 @@ aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
41264127
bool is_top_index_in_range =
41274128
top_boundary >= top && top >= (bottom + sizeof(AOTTinyFrame));
41284129
if (!is_top_index_in_range) {
4129-
return count;
4130+
char* err_msg = "Top of the stack pointer is outside of the stack boundaries";
4131+
strncpy(error_buf, err_msg, error_buf_size);
4132+
return 0;
41304133
}
41314134
bool is_top_aligned_with_bottom =
41324135
(unsigned long)(top - bottom) % sizeof(AOTTinyFrame) == 0;
41334136
if (!is_top_aligned_with_bottom) {
4134-
return count;
4137+
char* err_msg = "Top of the stack is not aligned with the bottom";
4138+
strncpy(error_buf, err_msg, error_buf_size);
4139+
return 0;
41354140
}
41364141

41374142
AOTTinyFrame *frame = (AOTTinyFrame *)(top - sizeof(AOTTinyFrame));
@@ -4155,8 +4160,8 @@ aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
41554160

41564161
uint32
41574162
aot_copy_callstack_standard_frame(WASMExecEnv *exec_env,
4158-
wasm_frame_ptr_t buffer, const uint32 length,
4159-
const uint32 skip_n)
4163+
wasm_frame_t* buffer, const uint32 length,
4164+
const uint32 skip_n, char *error_buf, uint32_t error_buf_size)
41604165
{
41614166
/*
41624167
* Note for devs: please refrain from such modifications inside of
@@ -4203,8 +4208,8 @@ aot_copy_callstack_standard_frame(WASMExecEnv *exec_env,
42034208
}
42044209

42054210
uint32
4206-
aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
4207-
const uint32 length, const uint32 skip_n)
4211+
aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t* buffer,
4212+
const uint32 length, const uint32 skip_n, char *error_buf, uint32_t error_buf_size)
42084213
{
42094214
/*
42104215
* Note for devs: please refrain from such modifications inside of
@@ -4217,10 +4222,10 @@ aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
42174222
*/
42184223
if (!is_tiny_frame(exec_env)) {
42194224
return aot_copy_callstack_standard_frame(exec_env, buffer, length,
4220-
skip_n);
4225+
skip_n, error_buf, error_buf_size);
42214226
}
42224227
else {
4223-
return aot_copy_callstack_tiny_frame(exec_env, buffer, length, skip_n);
4228+
return aot_copy_callstack_tiny_frame(exec_env, buffer, length, skip_n, error_buf, error_buf_size);
42244229
}
42254230
}
42264231
#endif // WAMR_ENABLE_COPY_CALLSTACK

core/iwasm/aot/aot_runtime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,9 @@ aot_create_call_stack(struct WASMExecEnv *exec_env);
779779

780780
#if WAMR_ENABLE_COPY_CALLSTACK != 0
781781
uint32
782-
aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
783-
const uint32 length, const uint32 skip_n);
782+
aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
783+
const uint32 length, const uint32 skip_n, char *error_buf,
784+
uint32_t error_buf_size);
784785
#endif // WAMR_ENABLE_COPY_CALLSTACK
785786

786787
/**

core/iwasm/common/wasm_runtime_common.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,8 +1742,9 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env)
17421742

17431743
#if WAMR_ENABLE_COPY_CALLSTACK != 0
17441744
uint32
1745-
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_ptr_t buffer,
1746-
const uint32 length, const uint32 skip_n)
1745+
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
1746+
const uint32 length, const uint32 skip_n, char *error_buf,
1747+
uint32_t error_buf_size)
17471748
{
17481749
/*
17491750
* Note for devs: please refrain from such modifications inside of
@@ -1760,13 +1761,15 @@ wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_ptr_t buffer,
17601761

17611762
#if WASM_ENABLE_INTERP != 0
17621763
if (module_inst->module_type == Wasm_Module_Bytecode) {
1763-
return wasm_interp_copy_callstack(exec_env, buffer, length, skip_n);
1764+
return wasm_interp_copy_callstack(exec_env, buffer, length, skip_n,
1765+
error_buf, error_buf_size);
17641766
}
17651767
#endif
17661768

17671769
#if WASM_ENABLE_AOT != 0
17681770
if (module_inst->module_type == Wasm_Module_AoT) {
1769-
return aot_copy_callstack(exec_env, buffer, length, skip_n);
1771+
return aot_copy_callstack(exec_env, buffer, length, skip_n, error_buf,
1772+
error_buf_size);
17701773
}
17711774
#endif
17721775
#endif

core/iwasm/common/wasm_runtime_common.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,11 @@ wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
639639
WASM_RUNTIME_API_EXTERN void
640640
wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
641641

642-
#ifndef WAMR_ENABLE_COPY_CALLSTACK
643-
#define WAMR_ENABLE_COPY_CALLSTACK 0
644-
#endif
645-
646642
#if WAMR_ENABLE_COPY_CALLSTACK != 0
647643
WASM_RUNTIME_API_EXTERN uint32_t
648-
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_ptr_t buffer,
649-
const uint32 length, const uint32 skip_n);
644+
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
645+
const uint32 length, const uint32 skip_n, char *error_buf,
646+
uint32 error_buf_size);
650647
#endif // WAMR_ENABLE_COPY_CALLSTACK
651648

652649
/* See wasm_export.h for description */

core/iwasm/include/wasm_export.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ typedef struct wasm_frame_t {
139139
uint32_t *lp;
140140
} WASMCApiFrame;
141141

142-
typedef struct wasm_frame_t *wasm_frame_ptr_t;
142+
typedef WASMCApiFrame wasm_frame_t;
143143

144144
/* WASM section */
145145
typedef struct wasm_section_t {
@@ -896,16 +896,17 @@ wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
896896
* - exec_env->module_inst->module
897897
*
898898
* @param exec_env the execution environment that containes frames
899-
* @param buffer the buffer of size equal length * sizeof(frame) to copy frames
900-
* to
899+
* @param buffer the buffer of size equal length * sizeof(wasm_frame_t) to copy
900+
* frames to
901901
* @param length the number of frames to copy
902902
* @param skip_n the number of frames to skip from the top of the stack
903903
*
904904
* @return number of copied frames
905905
*/
906906
WASM_RUNTIME_API_EXTERN uint32_t
907-
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_ptr_t buffer,
908-
const uint32_t length, const uint32_t skip_n);
907+
wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
908+
const uint32_t length, const uint32_t skip_n,
909+
char *error_buf, uint32_t error_buf_size);
909910

910911
/**
911912
* Get the singleton execution environment for the instance.

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "wasm_runtime.h"
77
#include "wasm.h"
8+
#include "wasm_c_api.h"
89
#include "wasm_exec_env.h"
910
#include "wasm_loader.h"
1011
#include "wasm_interp.h"
@@ -4198,8 +4199,9 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst,
41984199

41994200
#if WAMR_ENABLE_COPY_CALLSTACK != 0
42004201
uint32
4201-
wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
4202-
uint32 length, uint32 skip_n)
4202+
wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
4203+
uint32 length, uint32 skip_n, char *error_buf,
4204+
uint32_t error_buf_size)
42034205
{
42044206
/*
42054207
* Note for devs: please refrain from such modifications inside of

core/iwasm/interpreter/wasm_runtime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,9 @@ wasm_get_table_inst(const WASMModuleInstance *module_inst, uint32 tbl_idx)
733733

734734
#if WAMR_ENABLE_COPY_CALLSTACK != 0
735735
uint32
736-
wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_ptr_t buffer,
737-
uint32 length, uint32 skip_n);
736+
wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
737+
uint32 length, uint32 skip_n, char *error_buf,
738+
uint32_t error_buf_size);
738739
#endif // WAMR_ENABLE_COPY_CALLSTACK
739740

740741
bool

0 commit comments

Comments
 (0)