Skip to content

Commit ea06c19

Browse files
authored
Implement wasm-c-api wasm_config related APIs (#665)
And add wasm_engine_new_with_args() declaration in wasm_c_api.h Fix wasm-c-api frame func_offset issue in fast interp mode Remove sanitize compiler flag in product-mini linux CMakeLists.txt
1 parent 0f1ce9e commit ea06c19

File tree

7 files changed

+74
-9
lines changed

7 files changed

+74
-9
lines changed

core/iwasm/common/wasm_c_api.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,29 @@ aot_compile_wasm_file_init();
264264
void
265265
aot_compile_wasm_file_destroy();
266266

267-
uint8*
268-
aot_compile_wasm_file(const uint8 *wasm_file_buf, uint32 wasm_file_size,
269-
uint32 opt_level, uint32 size_level,
270-
char *error_buf, uint32 error_buf_size,
267+
uint8 *
268+
aot_compile_wasm_file(const uint8 *wasm_file_buf,
269+
uint32 wasm_file_size,
270+
uint32 opt_level,
271+
uint32 size_level,
272+
char *error_buf,
273+
uint32 error_buf_size,
271274
uint32 *p_aot_file_size);
272275
#endif
273276

274277
/* Runtime Environment */
278+
own wasm_config_t *
279+
wasm_config_new(void)
280+
{
281+
return NULL;
282+
}
283+
284+
void
285+
wasm_config_delete(own wasm_config_t *config)
286+
{
287+
(void)config;
288+
}
289+
275290
static void
276291
wasm_engine_delete_internal(wasm_engine_t *engine)
277292
{
@@ -351,7 +366,7 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
351366
/* global engine instance */
352367
static wasm_engine_t *singleton_engine = NULL;
353368

354-
wasm_engine_t *
369+
own wasm_engine_t *
355370
wasm_engine_new()
356371
{
357372
if (!singleton_engine) {
@@ -361,7 +376,14 @@ wasm_engine_new()
361376
return singleton_engine;
362377
}
363378

364-
wasm_engine_t *
379+
own wasm_engine_t *
380+
wasm_engine_new_with_config(own wasm_config_t *config)
381+
{
382+
(void)config;
383+
return wasm_engine_new();
384+
}
385+
386+
own wasm_engine_t *
365387
wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
366388
{
367389
if (!singleton_engine) {

core/iwasm/include/wasm_c_api.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ WASM_DECLARE_OWN(engine)
145145
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
146146
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*);
147147

148+
#ifndef MEM_ALLOC_OPTION_DEFINED
149+
#define MEM_ALLOC_OPTION_DEFINED
150+
/* same definition from wasm_export.h */
151+
/* Memory allocator type */
152+
typedef enum {
153+
/* pool mode, allocate memory from user defined heap buffer */
154+
Alloc_With_Pool = 0,
155+
/* user allocator mode, allocate memory from user defined
156+
malloc function */
157+
Alloc_With_Allocator,
158+
/* system allocator mode, allocate memory from system allocator,
159+
or, platform's os_malloc function */
160+
Alloc_With_System_Allocator,
161+
} mem_alloc_type_t;
162+
163+
/* Memory allocator option */
164+
typedef union MemAllocOption {
165+
struct {
166+
void *heap_buf;
167+
uint32_t heap_size;
168+
} pool;
169+
struct {
170+
void *malloc_func;
171+
void *realloc_func;
172+
void *free_func;
173+
} allocator;
174+
} MemAllocOption;
175+
#endif
176+
177+
WASM_API_EXTERN own wasm_engine_t *
178+
wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);
148179

149180
// Store
150181

core/iwasm/include/wasm_export.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ typedef enum {
9393
Package_Type_Unknown = 0xFFFF
9494
} package_type_t;
9595

96+
#ifndef MEM_ALLOC_OPTION_DEFINED
97+
#define MEM_ALLOC_OPTION_DEFINED
9698
/* Memory allocator type */
9799
typedef enum {
98100
/* pool mode, allocate memory from user defined heap buffer */
@@ -117,6 +119,7 @@ typedef union MemAllocOption {
117119
void *free_func;
118120
} allocator;
119121
} MemAllocOption;
122+
#endif
120123

121124
/* WASM runtime initialize arguments */
122125
typedef struct RuntimeInitArgs {

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,6 +3371,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
33713371
wasm_set_exception(module, "out of bounds memory access");
33723372

33733373
got_exception:
3374+
SYNC_ALL_TO_FRAME();
33743375
return;
33753376

33763377
#if WASM_ENABLE_LABELS_AS_VALUES == 0

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
34283428
wasm_set_exception(module, "out of bounds memory access");
34293429

34303430
got_exception:
3431+
SYNC_ALL_TO_FRAME();
34313432
return;
34323433

34333434
#if WASM_ENABLE_LABELS_AS_VALUES == 0

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
24632463
WASMCApiFrame frame = { 0 };
24642464
WASMFunctionInstance *func_inst = cur_frame->function;
24652465
const char *func_name = NULL;
2466+
const uint8 *func_code_base = NULL;
24662467

24672468
if (!func_inst) {
24682469
cur_frame = cur_frame->prev_frame;
@@ -2473,8 +2474,14 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
24732474
frame.instance = module_inst;
24742475
frame.module_offset = 0;
24752476
frame.func_index = func_inst - module_inst->functions;
2476-
frame.func_offset =
2477-
cur_frame->ip ? cur_frame->ip - func_inst->u.func->code : 0;
2477+
2478+
func_code_base = wasm_get_func_code(func_inst);
2479+
if (!cur_frame->ip || !func_code_base) {
2480+
frame.func_offset = 0;
2481+
}
2482+
else {
2483+
frame.func_offset = cur_frame->ip - func_code_base;
2484+
}
24782485

24792486
/* look for the function name */
24802487
if (func_inst->is_import_func) {

product-mini/platforms/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ endif ()
9797
# UNDEFINED BEHAVIOR
9898
# refer to https://en.cppreference.com/w/cpp/language/ub
9999
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
100-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=bounds-strict,undefined -fno-sanitize-recover")
100+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
101101
endif()
102102

103103
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

0 commit comments

Comments
 (0)