Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,29 @@ aot_compile_wasm_file_init();
void
aot_compile_wasm_file_destroy();

uint8*
aot_compile_wasm_file(const uint8 *wasm_file_buf, uint32 wasm_file_size,
uint32 opt_level, uint32 size_level,
char *error_buf, uint32 error_buf_size,
uint8 *
aot_compile_wasm_file(const uint8 *wasm_file_buf,
uint32 wasm_file_size,
uint32 opt_level,
uint32 size_level,
char *error_buf,
uint32 error_buf_size,
uint32 *p_aot_file_size);
#endif

/* Runtime Environment */
own wasm_config_t *
wasm_config_new(void)
{
return NULL;
}

void
wasm_config_delete(own wasm_config_t *config)
{
(void)config;
}

static void
wasm_engine_delete_internal(wasm_engine_t *engine)
{
Expand Down Expand Up @@ -351,7 +366,7 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
/* global engine instance */
static wasm_engine_t *singleton_engine = NULL;

wasm_engine_t *
own wasm_engine_t *
wasm_engine_new()
{
if (!singleton_engine) {
Expand All @@ -361,7 +376,14 @@ wasm_engine_new()
return singleton_engine;
}

wasm_engine_t *
own wasm_engine_t *
wasm_engine_new_with_config(own wasm_config_t *config)
{
(void)config;
return wasm_engine_new();
}

own wasm_engine_t *
wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
{
if (!singleton_engine) {
Expand Down
31 changes: 31 additions & 0 deletions core/iwasm/include/wasm_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@ WASM_DECLARE_OWN(engine)
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*);

#ifndef MEM_ALLOC_OPTION_DEFINED
#define MEM_ALLOC_OPTION_DEFINED
/* same definition from wasm_export.h */
/* Memory allocator type */
typedef enum {
/* pool mode, allocate memory from user defined heap buffer */
Alloc_With_Pool = 0,
/* user allocator mode, allocate memory from user defined
malloc function */
Alloc_With_Allocator,
/* system allocator mode, allocate memory from system allocator,
or, platform's os_malloc function */
Alloc_With_System_Allocator,
} mem_alloc_type_t;

/* Memory allocator option */
typedef union MemAllocOption {
struct {
void *heap_buf;
uint32_t heap_size;
} pool;
struct {
void *malloc_func;
void *realloc_func;
void *free_func;
} allocator;
} MemAllocOption;
#endif

WASM_API_EXTERN own wasm_engine_t *
wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);

// Store

Expand Down
3 changes: 3 additions & 0 deletions core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ typedef enum {
Package_Type_Unknown = 0xFFFF
} package_type_t;

#ifndef MEM_ALLOC_OPTION_DEFINED
#define MEM_ALLOC_OPTION_DEFINED
/* Memory allocator type */
typedef enum {
/* pool mode, allocate memory from user defined heap buffer */
Expand All @@ -117,6 +119,7 @@ typedef union MemAllocOption {
void *free_func;
} allocator;
} MemAllocOption;
#endif

/* WASM runtime initialize arguments */
typedef struct RuntimeInitArgs {
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3371,6 +3371,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
wasm_set_exception(module, "out of bounds memory access");

got_exception:
SYNC_ALL_TO_FRAME();
return;

#if WASM_ENABLE_LABELS_AS_VALUES == 0
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3428,6 +3428,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
wasm_set_exception(module, "out of bounds memory access");

got_exception:
SYNC_ALL_TO_FRAME();
return;

#if WASM_ENABLE_LABELS_AS_VALUES == 0
Expand Down
11 changes: 9 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
WASMCApiFrame frame = { 0 };
WASMFunctionInstance *func_inst = cur_frame->function;
const char *func_name = NULL;
const uint8 *func_code_base = NULL;

if (!func_inst) {
cur_frame = cur_frame->prev_frame;
Expand All @@ -2473,8 +2474,14 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
frame.instance = module_inst;
frame.module_offset = 0;
frame.func_index = func_inst - module_inst->functions;
frame.func_offset =
cur_frame->ip ? cur_frame->ip - func_inst->u.func->code : 0;

func_code_base = wasm_get_func_code(func_inst);
if (!cur_frame->ip || !func_code_base) {
frame.func_offset = 0;
}
else {
frame.func_offset = cur_frame->ip - func_code_base;
}

/* look for the function name */
if (func_inst->is_import_func) {
Expand Down
2 changes: 1 addition & 1 deletion product-mini/platforms/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ endif ()
# UNDEFINED BEHAVIOR
# refer to https://en.cppreference.com/w/cpp/language/ub
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=bounds-strict,undefined -fno-sanitize-recover")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
endif()

set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
Expand Down