mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2024-11-26 15:32:05 +00:00
Change wasm app offset type from int32 to uint32 (#361)
And fix some sign/unsigned conversion compilation warnings.
This commit is contained in:
parent
049760b849
commit
034606b0a9
|
@ -885,7 +885,8 @@ aot_signal_handler(void *sig_addr)
|
|||
AOTModuleInstance *module_inst;
|
||||
AOTMemoryInstance *memory_inst;
|
||||
WASMJmpBuf *jmpbuf_node;
|
||||
uint8 *mapped_mem_start_addr, *mapped_mem_end_addr;
|
||||
uint8 *mapped_mem_start_addr = NULL;
|
||||
uint8 *mapped_mem_end_addr = NULL;
|
||||
uint8 *stack_min_addr;
|
||||
uint32 page_size;
|
||||
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;
|
||||
|
@ -1265,7 +1266,7 @@ execute_free_function(AOTModuleInstance *module_inst,
|
|||
}
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
|
||||
void **p_native_addr)
|
||||
{
|
||||
|
@ -1298,11 +1299,11 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
|
|||
}
|
||||
if (p_native_addr)
|
||||
*p_native_addr = addr;
|
||||
return (int32)(addr - (uint8*)memory_inst->memory_data.ptr);
|
||||
return (uint32)(addr - (uint8*)memory_inst->memory_data.ptr);
|
||||
}
|
||||
|
||||
void
|
||||
aot_module_free(AOTModuleInstance *module_inst, int32 ptr)
|
||||
aot_module_free(AOTModuleInstance *module_inst, uint32 ptr)
|
||||
{
|
||||
AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
|
||||
AOTModule *module = (AOTModule *)module_inst->aot_module.ptr;
|
||||
|
@ -1322,18 +1323,18 @@ aot_module_free(AOTModuleInstance *module_inst, int32 ptr)
|
|||
aot_lookup_function(module_inst, "free", "(i)i");
|
||||
|
||||
bh_assert(free_func);
|
||||
execute_free_function(module_inst, free_func, (uint32)ptr);
|
||||
execute_free_function(module_inst, free_func, ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst,
|
||||
const char *src, uint32 size)
|
||||
{
|
||||
char *buffer;
|
||||
int32 buffer_offset = aot_module_malloc(module_inst, size,
|
||||
(void**)&buffer);
|
||||
uint32 buffer_offset = aot_module_malloc(module_inst, size,
|
||||
(void**)&buffer);
|
||||
|
||||
if (buffer_offset != 0) {
|
||||
buffer = aot_addr_app_to_native(module_inst, buffer_offset);
|
||||
|
@ -1344,15 +1345,15 @@ aot_module_dup_data(AOTModuleInstance *module_inst,
|
|||
|
||||
bool
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst,
|
||||
int32 app_offset, uint32 size)
|
||||
uint32 app_offset, uint32 size)
|
||||
{
|
||||
AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
|
||||
|
||||
/* integer overflow check */
|
||||
if((uint32)app_offset + size < (uint32)app_offset) {
|
||||
if(app_offset + size < app_offset) {
|
||||
goto fail;
|
||||
}
|
||||
if ((uint32)app_offset + size <= memory_inst->memory_data_size) {
|
||||
if (app_offset + size <= memory_inst->memory_data_size) {
|
||||
return true;
|
||||
}
|
||||
fail:
|
||||
|
@ -1381,10 +1382,10 @@ fail:
|
|||
}
|
||||
|
||||
void *
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, int32 app_offset)
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset)
|
||||
{
|
||||
AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
|
||||
uint8 *addr = (uint8 *)memory_inst->memory_data.ptr + (uint32)app_offset;
|
||||
uint8 *addr = (uint8 *)memory_inst->memory_data.ptr + app_offset;
|
||||
|
||||
if ((uint8 *)memory_inst->memory_data.ptr <= addr
|
||||
&& addr < (uint8 *)memory_inst->memory_data_end.ptr)
|
||||
|
@ -1392,7 +1393,7 @@ aot_addr_app_to_native(AOTModuleInstance *module_inst, int32 app_offset)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr)
|
||||
{
|
||||
uint8 *addr = (uint8 *)native_ptr;
|
||||
|
@ -1400,24 +1401,24 @@ aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr)
|
|||
|
||||
if ((uint8 *)memory_inst->memory_data.ptr <= addr
|
||||
&& addr < (uint8 *)memory_inst->memory_data_end.ptr)
|
||||
return (int32)(addr - (uint8 *)memory_inst->memory_data.ptr);
|
||||
return (uint32)(addr - (uint8 *)memory_inst->memory_data.ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset)
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset)
|
||||
{
|
||||
AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
|
||||
uint32 memory_data_size = memory_inst->memory_data_size;
|
||||
|
||||
if ((uint32)app_offset < memory_data_size) {
|
||||
if (app_offset < memory_data_size) {
|
||||
if (p_app_start_offset)
|
||||
*p_app_start_offset = 0;
|
||||
if (p_app_end_offset)
|
||||
*p_app_end_offset = (int32)memory_data_size;
|
||||
*p_app_end_offset = memory_data_size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -275,7 +275,7 @@ typedef struct AOTModuleInstance {
|
|||
AOTPointer wasi_ctx;
|
||||
|
||||
/* others */
|
||||
int32 temp_ret;
|
||||
uint32 temp_ret;
|
||||
uint32 llvm_stack;
|
||||
uint32 default_wasm_stack_size;
|
||||
|
||||
|
@ -456,20 +456,20 @@ aot_get_exception(AOTModuleInstance *module_inst);
|
|||
void
|
||||
aot_clear_exception(AOTModuleInstance *module_inst);
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
void
|
||||
aot_module_free(AOTModuleInstance *module_inst, int32 ptr);
|
||||
aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_module_dup_data(AOTModuleInstance *module_inst,
|
||||
const char *src, uint32 size);
|
||||
|
||||
bool
|
||||
aot_validate_app_addr(AOTModuleInstance *module_inst,
|
||||
int32 app_offset, uint32 size);
|
||||
uint32 app_offset, uint32 size);
|
||||
|
||||
|
||||
bool
|
||||
|
@ -477,16 +477,16 @@ aot_validate_native_addr(AOTModuleInstance *module_inst,
|
|||
void *native_ptr, uint32 size);
|
||||
|
||||
void *
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, int32 app_offset);
|
||||
aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset);
|
||||
|
||||
int32
|
||||
uint32
|
||||
aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr);
|
||||
|
||||
bool
|
||||
aot_get_app_addr_range(AOTModuleInstance *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset);
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
|
||||
bool
|
||||
aot_get_native_addr_range(AOTModuleInstance *module_inst,
|
||||
|
|
|
@ -1034,13 +1034,13 @@ argv_to_params(const uint64 *argv,
|
|||
switch (param_def->kind) {
|
||||
case WASM_I32:
|
||||
param->kind = WASM_I32;
|
||||
param->of.i32 = *(uint32 *)argv_p;
|
||||
param->of.i32 = *(int32 *)argv_p;
|
||||
argv_p = (uint32 *)argv_p + 1;
|
||||
argc++;
|
||||
break;
|
||||
case WASM_I64:
|
||||
param->kind = WASM_I64;
|
||||
param->of.i64 = *(uint64 *)argv_p;
|
||||
param->of.i64 = *(int64 *)argv_p;
|
||||
argv_p = (uint64 *)argv_p + 1;
|
||||
argc++;
|
||||
break;
|
||||
|
@ -1081,12 +1081,12 @@ results_to_argv(const wasm_val_t *results,
|
|||
const wasm_val_t *result = results + i;
|
||||
switch (result_def->kind) {
|
||||
case WASM_I32:
|
||||
*(uint32 *)argv_p = result->of.i32;
|
||||
*(int32 *)argv_p = result->of.i32;
|
||||
argv_p = (uint32 *)argv_p + 1;
|
||||
argc++;
|
||||
break;
|
||||
case WASM_I64:
|
||||
*(uint64 *)argv_p = result->of.i64;
|
||||
*(int64 *)argv_p = result->of.i64;
|
||||
argv_p = (uint64 *)argv_p + 1;
|
||||
argc++;
|
||||
break;
|
||||
|
@ -2099,7 +2099,7 @@ interp_link_table(const WASMModule *module_interp,
|
|||
return false;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
interp_link(const wasm_instance_t *inst,
|
||||
const WASMModule *module_interp,
|
||||
wasm_extern_t *imports[])
|
||||
|
@ -2157,7 +2157,7 @@ interp_link(const wasm_instance_t *inst,
|
|||
|
||||
failed:
|
||||
LOG_DEBUG("%s failed", __FUNCTION__);
|
||||
return -1;
|
||||
return (uint32)-1;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -2296,7 +2296,7 @@ failed:
|
|||
return false;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
aot_link(const wasm_instance_t *inst,
|
||||
const AOTModule *module_aot,
|
||||
wasm_extern_t *imports[])
|
||||
|
@ -2346,7 +2346,7 @@ aot_link(const wasm_instance_t *inst,
|
|||
|
||||
failed:
|
||||
LOG_DEBUG("%s failed", __FUNCTION__);
|
||||
return -1;
|
||||
return (uint32)-1;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -2419,7 +2419,7 @@ wasm_instance_new(wasm_store_t *store,
|
|||
char error[128] = { 0 };
|
||||
const uint32 stack_size = 16 * 1024;
|
||||
const uint32 heap_size = 16 * 1024;
|
||||
int32 import_count = 0;
|
||||
uint32 import_count = 0;
|
||||
wasm_instance_t *instance = NULL;
|
||||
uint32 i = 0;
|
||||
(void)traps;
|
||||
|
@ -2459,7 +2459,7 @@ wasm_instance_new(wasm_store_t *store,
|
|||
aot_link(instance, (AOTModule *)*module, (wasm_extern_t **)imports);
|
||||
#endif
|
||||
}
|
||||
if (import_count < 0) {
|
||||
if ((int32)import_count < 0) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols,
|
|||
const char *symbol, const char **p_signature, void **p_attachment)
|
||||
{
|
||||
int low = 0, mid, ret;
|
||||
int high = n_native_symbols - 1;
|
||||
int high = (int32)n_native_symbols - 1;
|
||||
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
|
|
|
@ -957,7 +957,7 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
||||
void **p_native_addr)
|
||||
{
|
||||
|
@ -975,7 +975,7 @@ wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
|||
}
|
||||
|
||||
void
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, int32 ptr)
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
|
@ -991,7 +991,7 @@ wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, int32 ptr)
|
|||
#endif
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||
const char *src, uint32 size)
|
||||
{
|
||||
|
@ -1010,7 +1010,7 @@ wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
|||
|
||||
bool
|
||||
wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset, uint32 size)
|
||||
uint32 app_offset, uint32 size)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
|
@ -1027,9 +1027,9 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
|
|||
|
||||
bool
|
||||
wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_str_offset)
|
||||
uint32 app_str_offset)
|
||||
{
|
||||
int32 app_end_offset;
|
||||
uint32 app_end_offset;
|
||||
char *str, *str_end;
|
||||
|
||||
if (!wasm_runtime_get_app_addr_range(module_inst, app_str_offset,
|
||||
|
@ -1068,7 +1068,7 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
|
|||
|
||||
void *
|
||||
wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset)
|
||||
uint32 app_offset)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
|
@ -1083,7 +1083,7 @@ wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
|
||||
void *native_ptr)
|
||||
{
|
||||
|
@ -1102,9 +1102,9 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
|
|||
|
||||
bool
|
||||
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset)
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
|
@ -1250,7 +1250,7 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
|||
wasi_args->env = env_list;
|
||||
wasi_args->env_count = env_count;
|
||||
wasi_args->argv = argv;
|
||||
wasi_args->argc = argc;
|
||||
wasi_args->argc = (uint32)argc;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1274,11 +1274,11 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
|||
struct argv_environ_values *argv_environ;
|
||||
bool fd_table_inited = false, fd_prestats_inited = false;
|
||||
bool argv_environ_inited = false;
|
||||
int32 offset_argv_offsets = 0, offset_env_offsets = 0;
|
||||
int32 offset_argv_buf = 0, offset_env_buf = 0;
|
||||
int32 offset_curfds = 0;
|
||||
int32 offset_prestats = 0;
|
||||
int32 offset_argv_environ = 0;
|
||||
uint32 offset_argv_offsets = 0, offset_env_offsets = 0;
|
||||
uint32 offset_argv_buf = 0, offset_env_buf = 0;
|
||||
uint32 offset_curfds = 0;
|
||||
uint32 offset_prestats = 0;
|
||||
uint32 offset_argv_environ = 0;
|
||||
__wasi_fd_t wasm_fd = 3;
|
||||
int32 raw_fd;
|
||||
char *path, resolved_path[PATH_MAX];
|
||||
|
@ -1657,9 +1657,10 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
uint32 argc1 = 0, argv1[2] = { 0 };
|
||||
uint32 total_argv_size = 0;
|
||||
uint64 total_size;
|
||||
int32 argv_buf_offset, i;
|
||||
uint32 argv_buf_offset;
|
||||
int32 i;
|
||||
char *argv_buf, *p, *p_end;
|
||||
int32 *argv_offsets;
|
||||
uint32 *argv_offsets;
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
if (wasm_runtime_is_wasi_mode(module_inst)) {
|
||||
|
@ -1724,12 +1725,12 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
|||
}
|
||||
|
||||
p = argv_buf;
|
||||
argv_offsets = (int32*)(p + total_argv_size);
|
||||
argv_offsets = (uint32*)(p + total_argv_size);
|
||||
p_end = p + total_size;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
bh_memcpy_s(p, (uint32)(p_end - p), argv[i], (uint32)(strlen(argv[i]) + 1));
|
||||
argv_offsets[i] = argv_buf_offset + (int32)(p - argv_buf);
|
||||
argv_offsets[i] = argv_buf_offset + (uint32)(p - argv_buf);
|
||||
p += strlen(argv[i]) + 1;
|
||||
}
|
||||
|
||||
|
@ -2173,7 +2174,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
|
|||
NativeRawFuncPtr invokeNativeRaw = (NativeRawFuncPtr)func_ptr;
|
||||
uint64 argv_buf[16] = { 0 }, *argv1 = argv_buf, *argv_dst, size;
|
||||
uint32 *argv_src = argv, i, argc1, ptr_len;
|
||||
int32 arg_i32;
|
||||
uint32 arg_i32;
|
||||
bool ret = false;
|
||||
|
||||
argc1 = func_type->param_count;
|
||||
|
@ -2192,7 +2193,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
|
|||
switch (func_type->types[i]) {
|
||||
case VALUE_TYPE_I32:
|
||||
{
|
||||
*(int32*)argv_dst = arg_i32 = (int32)*argv_src++;
|
||||
*(uint32*)argv_dst = arg_i32 = *argv_src++;
|
||||
if (signature) {
|
||||
if (signature[i + 1] == '*') {
|
||||
/* param is a pointer */
|
||||
|
@ -2729,7 +2730,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
|
|||
int n_fps = 0;
|
||||
#endif
|
||||
|
||||
argc1 = 1 + MAX_REG_FLOATS + func_type->param_count + ext_ret_count;
|
||||
argc1 = 1 + MAX_REG_FLOATS + (uint32)func_type->param_count + ext_ret_count;
|
||||
if (argc1 > sizeof(argv_buf) / sizeof(uint64)) {
|
||||
size = sizeof(uint64) * (uint64)argc1;
|
||||
if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst,
|
||||
|
|
|
@ -49,13 +49,13 @@ typedef struct WASIContext {
|
|||
allocated from app's heap, and the heap space may be re-allocated
|
||||
after memory.grow opcode is executed, the original native address
|
||||
cannot be accessed again. */
|
||||
int32 curfds_offset;
|
||||
int32 prestats_offset;
|
||||
int32 argv_environ_offset;
|
||||
int32 argv_buf_offset;
|
||||
int32 argv_offsets_offset;
|
||||
int32 env_buf_offset;
|
||||
int32 env_offsets_offset;
|
||||
uint32 curfds_offset;
|
||||
uint32 prestats_offset;
|
||||
uint32 argv_environ_offset;
|
||||
uint32 argv_buf_offset;
|
||||
uint32 argv_offsets_offset;
|
||||
uint32 env_buf_offset;
|
||||
uint32 env_offsets_offset;
|
||||
} WASIContext;
|
||||
#endif
|
||||
|
||||
|
@ -227,28 +227,28 @@ void *
|
|||
wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
void
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, int32 ptr);
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||
const char *src, uint32 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset, uint32 size);
|
||||
uint32 app_offset, uint32 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_str_offset);
|
||||
uint32 app_str_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
|
@ -258,19 +258,19 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
|
|||
/* See wasm_export.h for description */
|
||||
void *
|
||||
wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset);
|
||||
uint32 app_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
int32
|
||||
uint32
|
||||
wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
|
||||
void *native_ptr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset);
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
|
|
|
@ -476,11 +476,11 @@ wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
|
|||
* if it is not NULL, and return NULL if memory malloc failed
|
||||
*
|
||||
* @return the allocated memory address, which is a relative offset to the
|
||||
* base address of the module instance's memory space, the value range
|
||||
* is (-heap_size, 0). Note that it is not an absolute address.
|
||||
* base address of the module instance's memory space. Note that
|
||||
* it is not an absolute address.
|
||||
* Return non-zero if success, zero if failed.
|
||||
*/
|
||||
int32_t
|
||||
uint32_t
|
||||
wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
|
||||
void **p_native_addr);
|
||||
|
||||
|
@ -491,7 +491,7 @@ wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
|
|||
* @param ptr the pointer to free
|
||||
*/
|
||||
void
|
||||
wasm_runtime_module_free(wasm_module_inst_t module_inst, int32_t ptr);
|
||||
wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
|
||||
|
||||
/**
|
||||
* Allocate memory from the heap of WASM module instance and initialize
|
||||
|
@ -502,11 +502,11 @@ wasm_runtime_module_free(wasm_module_inst_t module_inst, int32_t ptr);
|
|||
* @param size the size of the source data
|
||||
*
|
||||
* @return the allocated memory address, which is a relative offset to the
|
||||
* base address of the module instance's memory space, the value range
|
||||
* is (-heap_size, 0). Note that it is not an absolute address.
|
||||
* base address of the module instance's memory space. Note that
|
||||
* it is not an absolute address.
|
||||
* Return non-zero if success, zero if failed.
|
||||
*/
|
||||
int32_t
|
||||
uint32_t
|
||||
wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
|
||||
const char *src, uint32_t size);
|
||||
|
||||
|
@ -523,7 +523,7 @@ wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
|
|||
*/
|
||||
bool
|
||||
wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
||||
int32_t app_offset, uint32_t size);
|
||||
uint32_t app_offset, uint32_t size);
|
||||
|
||||
/**
|
||||
* Similar to wasm_runtime_validate_app_addr(), except that the size parameter
|
||||
|
@ -540,7 +540,7 @@ wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
|||
*/
|
||||
bool
|
||||
wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
|
||||
int32_t app_str_offset);
|
||||
uint32_t app_str_offset);
|
||||
|
||||
/**
|
||||
* Validate the native address, check whether it belongs to WASM module
|
||||
|
@ -568,7 +568,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
|
|||
*/
|
||||
void*
|
||||
wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
|
||||
int32_t app_offset);
|
||||
uint32_t app_offset);
|
||||
|
||||
/**
|
||||
* Convert native address(absolute address) to app address(relative address)
|
||||
|
@ -578,7 +578,7 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
|
|||
*
|
||||
* @return the app address converted
|
||||
*/
|
||||
int32_t
|
||||
uint32_t
|
||||
wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
|
||||
void *native_ptr);
|
||||
|
||||
|
@ -594,9 +594,9 @@ wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
|
|||
*/
|
||||
bool
|
||||
wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
|
||||
int32_t app_offset,
|
||||
int32_t *p_app_start_offset,
|
||||
int32_t *p_app_end_offset);
|
||||
uint32_t app_offset,
|
||||
uint32_t *p_app_start_offset,
|
||||
uint32_t *p_app_end_offset);
|
||||
|
||||
/**
|
||||
* Get the native address range (absolute address) that a native address belongs to
|
||||
|
|
|
@ -479,7 +479,8 @@ wasm_type_equal(const WASMType *type1, const WASMType *type2)
|
|||
return (type1->param_count == type2->param_count
|
||||
&& type1->result_count == type2->result_count
|
||||
&& memcmp(type1->types, type2->types,
|
||||
type1->param_count + type1->result_count) == 0)
|
||||
(uint32)(type1->param_count
|
||||
+ type1->result_count)) == 0)
|
||||
? true : false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1191,10 +1191,14 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
|
|||
return false;
|
||||
}
|
||||
#else
|
||||
if (memory->flags > 3 || memory->flags == 2) {
|
||||
if (memory->flags > 3) {
|
||||
set_error_buf(error_buf, error_buf_size, "integer too large");
|
||||
return false;
|
||||
}
|
||||
else if (memory->flags == 2) {
|
||||
set_error_buf(error_buf, error_buf_size, "shared memory must have maximum");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
read_leb_uint32(p, p_end, memory->init_page_count);
|
||||
|
|
|
@ -1562,7 +1562,7 @@ wasm_get_exception(WASMModuleInstance *module_inst)
|
|||
return module_inst->cur_exception;
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
|
||||
void **p_native_addr)
|
||||
{
|
||||
|
@ -1589,15 +1589,15 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
|
|||
}
|
||||
if (p_native_addr)
|
||||
*p_native_addr = addr;
|
||||
return (int32)(addr - memory->memory_data);
|
||||
return (uint32)(addr - memory->memory_data);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_module_free(WASMModuleInstance *module_inst, int32 ptr)
|
||||
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
uint8 *addr = memory->memory_data + (uint32)ptr;
|
||||
uint8 *addr = memory->memory_data + ptr;
|
||||
|
||||
if (memory->heap_handle
|
||||
&& memory->heap_data <= addr
|
||||
|
@ -1610,18 +1610,18 @@ wasm_module_free(WASMModuleInstance *module_inst, int32 ptr)
|
|||
&& addr < memory->memory_data_end) {
|
||||
execute_free_function(module_inst,
|
||||
module_inst->free_function,
|
||||
(uint32)ptr);
|
||||
ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_module_dup_data(WASMModuleInstance *module_inst,
|
||||
const char *src, uint32 size)
|
||||
{
|
||||
char *buffer;
|
||||
int32 buffer_offset = wasm_module_malloc(module_inst, size,
|
||||
(void**)&buffer);
|
||||
uint32 buffer_offset = wasm_module_malloc(module_inst, size,
|
||||
(void**)&buffer);
|
||||
if (buffer_offset != 0) {
|
||||
buffer = wasm_addr_app_to_native(module_inst, buffer_offset);
|
||||
bh_memcpy_s(buffer, size, src, size);
|
||||
|
@ -1631,18 +1631,18 @@ wasm_module_dup_data(WASMModuleInstance *module_inst,
|
|||
|
||||
bool
|
||||
wasm_validate_app_addr(WASMModuleInstance *module_inst,
|
||||
int32 app_offset, uint32 size)
|
||||
uint32 app_offset, uint32 size)
|
||||
{
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
uint32 memory_data_size =
|
||||
memory->num_bytes_per_page * memory->cur_page_count;
|
||||
|
||||
/* integer overflow check */
|
||||
if ((uint32)app_offset + size < (uint32)app_offset) {
|
||||
if (app_offset + size < app_offset) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((uint32)app_offset + size <= memory_data_size) {
|
||||
if (app_offset + size <= memory_data_size) {
|
||||
return true;
|
||||
}
|
||||
fail:
|
||||
|
@ -1673,7 +1673,7 @@ fail:
|
|||
|
||||
void *
|
||||
wasm_addr_app_to_native(WASMModuleInstance *module_inst,
|
||||
int32 app_offset)
|
||||
uint32 app_offset)
|
||||
{
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
uint8 *addr = memory->memory_data + app_offset;
|
||||
|
@ -1684,7 +1684,7 @@ wasm_addr_app_to_native(WASMModuleInstance *module_inst,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_addr_native_to_app(WASMModuleInstance *module_inst,
|
||||
void *native_ptr)
|
||||
{
|
||||
|
@ -1693,21 +1693,21 @@ wasm_addr_native_to_app(WASMModuleInstance *module_inst,
|
|||
|
||||
if (memory->memory_data <= addr
|
||||
&& addr < memory->memory_data_end)
|
||||
return (int32)(addr - memory->memory_data);
|
||||
return (uint32)(addr - memory->memory_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_get_app_addr_range(WASMModuleInstance *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset)
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset)
|
||||
{
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
uint32 memory_data_size =
|
||||
memory->num_bytes_per_page * memory->cur_page_count;
|
||||
|
||||
if ((uint32)app_offset < memory_data_size) {
|
||||
if (app_offset < memory_data_size) {
|
||||
if (p_app_start_offset)
|
||||
*p_app_start_offset = 0;
|
||||
if (p_app_end_offset)
|
||||
|
|
|
@ -313,24 +313,24 @@ wasm_set_exception(WASMModuleInstance *module, const char *exception);
|
|||
const char*
|
||||
wasm_get_exception(WASMModuleInstance *module);
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
void
|
||||
wasm_module_free(WASMModuleInstance *module_inst, int32 ptr);
|
||||
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr);
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_module_dup_data(WASMModuleInstance *module_inst,
|
||||
const char *src, uint32 size);
|
||||
|
||||
bool
|
||||
wasm_validate_app_addr(WASMModuleInstance *module_inst,
|
||||
int32 app_offset, uint32 size);
|
||||
uint32 app_offset, uint32 size);
|
||||
|
||||
bool
|
||||
wasm_validate_app_str_addr(WASMModuleInstance *module_inst,
|
||||
int32 app_offset);
|
||||
uint32 app_offset);
|
||||
|
||||
bool
|
||||
wasm_validate_native_addr(WASMModuleInstance *module_inst,
|
||||
|
@ -338,17 +338,17 @@ wasm_validate_native_addr(WASMModuleInstance *module_inst,
|
|||
|
||||
void *
|
||||
wasm_addr_app_to_native(WASMModuleInstance *module_inst,
|
||||
int32 app_offset);
|
||||
uint32 app_offset);
|
||||
|
||||
int32
|
||||
uint32
|
||||
wasm_addr_native_to_app(WASMModuleInstance *module_inst,
|
||||
void *native_ptr);
|
||||
|
||||
bool
|
||||
wasm_get_app_addr_range(WASMModuleInstance *module_inst,
|
||||
int32 app_offset,
|
||||
int32 *p_app_start_offset,
|
||||
int32 *p_app_end_offset);
|
||||
uint32 app_offset,
|
||||
uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
|
||||
bool
|
||||
wasm_get_native_addr_range(WASMModuleInstance *module_inst,
|
||||
|
|
|
@ -321,10 +321,10 @@ handle_1_to_9:
|
|||
case 's': {
|
||||
char *s;
|
||||
char *start;
|
||||
int32 s_offset;
|
||||
uint32 s_offset;
|
||||
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
s_offset = _va_arg(ap, int32);
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
|
@ -494,13 +494,13 @@ putchar_wrapper(wasm_exec_env_t exec_env, int c)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *str_ret;
|
||||
uint32 len;
|
||||
int32 str_ret_offset = 0;
|
||||
uint32 str_ret_offset = 0;
|
||||
|
||||
/* str has been checked by runtime */
|
||||
if (str) {
|
||||
|
@ -515,7 +515,7 @@ strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
|||
return str_ret_offset;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
_strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
{
|
||||
return strdup_wrapper(exec_env, str);
|
||||
|
@ -534,12 +534,12 @@ memcmp_wrapper(wasm_exec_env_t exec_env,
|
|||
return memcmp(s1, s2, size);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
memcpy_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 dst_offset = addr_native_to_app(dst);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
|
||||
if (size == 0)
|
||||
return dst_offset;
|
||||
|
@ -552,12 +552,12 @@ memcpy_wrapper(wasm_exec_env_t exec_env,
|
|||
return dst_offset;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
memmove_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 dst_offset = addr_native_to_app(dst);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
|
||||
if (size == 0)
|
||||
return dst_offset;
|
||||
|
@ -570,12 +570,12 @@ memmove_wrapper(wasm_exec_env_t exec_env,
|
|||
return dst_offset;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
memset_wrapper(wasm_exec_env_t exec_env,
|
||||
void *s, int32 c, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 s_offset = addr_native_to_app(s);
|
||||
uint32 s_offset = addr_native_to_app(s);
|
||||
|
||||
if (!validate_native_addr(s, size))
|
||||
return s_offset;
|
||||
|
@ -584,7 +584,7 @@ memset_wrapper(wasm_exec_env_t exec_env,
|
|||
return s_offset;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
strchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, int32 c)
|
||||
{
|
||||
|
@ -617,7 +617,7 @@ strncmp_wrapper(wasm_exec_env_t exec_env,
|
|||
return strncmp(s1, s2, size);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
@ -631,7 +631,7 @@ strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
|
|||
return addr_native_to_app(dst);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
strncpy_wrapper(wasm_exec_env_t exec_env,
|
||||
char *dst, const char *src, uint32 size)
|
||||
{
|
||||
|
@ -652,19 +652,19 @@ strlen_wrapper(wasm_exec_env_t exec_env, const char *s)
|
|||
return (uint32)strlen(s);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
malloc_wrapper(wasm_exec_env_t exec_env, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
return module_malloc(size, NULL);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
calloc_wrapper(wasm_exec_env_t exec_env, uint32 nmemb, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint64 total_size = (uint64) nmemb * (uint64) size;
|
||||
int32 ret_offset = 0;
|
||||
uint32 ret_offset = 0;
|
||||
uint8 *ret_ptr;
|
||||
|
||||
if (total_size >= UINT32_MAX)
|
||||
|
@ -672,7 +672,7 @@ calloc_wrapper(wasm_exec_env_t exec_env, uint32 nmemb, uint32 size)
|
|||
|
||||
ret_offset = module_malloc((uint32)total_size, (void**)&ret_ptr);
|
||||
if (ret_offset) {
|
||||
memset(ret_ptr, 0, (uint32) total_size);
|
||||
memset(ret_ptr, 0, (uint32)total_size);
|
||||
}
|
||||
|
||||
return ret_offset;
|
||||
|
@ -717,7 +717,7 @@ strtol_wrapper(wasm_exec_env_t exec_env,
|
|||
return 0;
|
||||
|
||||
num = (int32)strtol(nptr, endptr, base);
|
||||
*(int32*)endptr = addr_native_to_app(*endptr);
|
||||
*(uint32*)endptr = addr_native_to_app(*endptr);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
@ -734,12 +734,12 @@ strtoul_wrapper(wasm_exec_env_t exec_env,
|
|||
return 0;
|
||||
|
||||
num = (uint32)strtoul(nptr, endptr, base);
|
||||
*(int32 *)endptr = addr_native_to_app(*endptr);
|
||||
*(uint32 *)endptr = addr_native_to_app(*endptr);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
memchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *s, int32 c, uint32 n)
|
||||
{
|
||||
|
@ -755,7 +755,7 @@ memchr_wrapper(wasm_exec_env_t exec_env,
|
|||
|
||||
static int32
|
||||
strncasecmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2, int32 n)
|
||||
const char *s1, const char *s2, uint32 n)
|
||||
{
|
||||
/* s1 and s2 have been checked by runtime */
|
||||
return strncasecmp(s1, s2, n);
|
||||
|
@ -777,7 +777,7 @@ strcspn_wrapper(wasm_exec_env_t exec_env,
|
|||
return (uint32)strcspn(s, reject);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
strstr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *find)
|
||||
{
|
||||
|
@ -934,12 +934,12 @@ llvm_stacksave_wrapper(wasm_exec_env_t exec_env)
|
|||
return wasm_runtime_get_llvm_stack(module_inst);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
emscripten_memcpy_big_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 dst_offset = addr_native_to_app(dst);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
|
||||
/* src has been checked by runtime */
|
||||
if (!validate_native_addr(dst, size))
|
||||
|
@ -976,12 +976,12 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
|
|||
wasm_runtime_set_exception(module_inst, buf);
|
||||
}
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
__cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 thrown_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 exception = module_malloc(thrown_size, NULL);
|
||||
uint32 exception = module_malloc(thrown_size, NULL);
|
||||
if (!exception)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -40,14 +40,18 @@ typedef struct wasi_prestat_app {
|
|||
} wasi_prestat_app_t;
|
||||
|
||||
typedef struct iovec_app {
|
||||
int32 buf_offset;
|
||||
uint32 buf_offset;
|
||||
uint32 buf_len;
|
||||
} iovec_app_t;
|
||||
|
||||
typedef struct WASIContext {
|
||||
int32 curfds_offset;
|
||||
int32 prestats_offset;
|
||||
int32 argv_environ_offset;
|
||||
uint32 curfds_offset;
|
||||
uint32 prestats_offset;
|
||||
uint32 argv_environ_offset;
|
||||
uint32 argv_buf_offset;
|
||||
uint32 argv_offsets_offset;
|
||||
uint32 env_buf_offset;
|
||||
uint32 env_offsets_offset;
|
||||
} *wasi_ctx_t;
|
||||
|
||||
wasi_ctx_t
|
||||
|
@ -87,7 +91,7 @@ wasi_ctx_get_prestats(wasm_module_inst_t module_inst,
|
|||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_args_get(wasm_exec_env_t exec_env, int32 *argv_offsets, char *argv_buf)
|
||||
wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
|
@ -191,7 +195,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
|
|||
|
||||
static wasi_errno_t
|
||||
wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
int32 *environ_offsets, char *environ_buf)
|
||||
uint32 *environ_offsets, char *environ_buf)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
|
@ -344,7 +348,7 @@ wasi_fd_pread(wasm_exec_env_t exec_env,
|
|||
wasi_iovec_t *iovec, *iovec_begin;
|
||||
uint64 total_size;
|
||||
size_t nread;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
uint32 i;
|
||||
wasi_errno_t err;
|
||||
|
||||
|
@ -399,7 +403,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
|||
wasi_ciovec_t *ciovec, *ciovec_begin;
|
||||
uint64 total_size;
|
||||
size_t nwritten;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
uint32 i;
|
||||
wasi_errno_t err;
|
||||
|
||||
|
@ -455,7 +459,7 @@ wasi_fd_read(wasm_exec_env_t exec_env,
|
|||
uint64 total_size;
|
||||
size_t nread;
|
||||
uint32 i;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
wasi_errno_t err;
|
||||
|
||||
if (!wasi_ctx)
|
||||
|
@ -626,7 +630,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
|||
wasi_ciovec_t *ciovec, *ciovec_begin;
|
||||
uint64 total_size;
|
||||
size_t nwritten;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
uint32 i;
|
||||
wasi_errno_t err;
|
||||
|
||||
|
@ -753,7 +757,7 @@ wasi_path_open(wasm_exec_env_t exec_env,
|
|||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
|
||||
wasi_fd_t fd = -1; /* set fd_app -1 if path open failed */
|
||||
wasi_fd_t fd = (wasi_fd_t)-1; /* set fd_app -1 if path open failed */
|
||||
wasi_errno_t err;
|
||||
|
||||
if (!wasi_ctx)
|
||||
|
@ -1052,7 +1056,7 @@ wasi_sock_recv(wasm_exec_env_t exec_env,
|
|||
wasi_iovec_t *iovec, *iovec_begin;
|
||||
uint64 total_size;
|
||||
size_t ro_datalen;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
uint32 i;
|
||||
wasi_errno_t err;
|
||||
|
||||
|
@ -1112,7 +1116,7 @@ wasi_sock_send(wasm_exec_env_t exec_env,
|
|||
wasi_ciovec_t *ciovec, *ciovec_begin;
|
||||
uint64 total_size;
|
||||
size_t so_datalen;
|
||||
int32 mem;
|
||||
uint32 mem;
|
||||
uint32 i;
|
||||
wasi_errno_t err;
|
||||
|
||||
|
|
|
@ -660,7 +660,7 @@ static __wasi_errno_t fd_table_insert_fd(
|
|||
if (type == __WASI_FILETYPE_DIRECTORY) {
|
||||
if (!mutex_init(&fo->directory.lock)) {
|
||||
fd_object_release(fo);
|
||||
return -1;
|
||||
return (__wasi_errno_t)-1;
|
||||
}
|
||||
fo->directory.handle = NULL;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ void random_buf(void *buf, size_t len) {
|
|||
if ((size_t)x == len)
|
||||
return;
|
||||
buf = (void *)((unsigned char *)buf + x);
|
||||
len -= x;
|
||||
len -= (size_t)x;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
|
|||
uint8 *addr;
|
||||
uint32 i;
|
||||
|
||||
page_size = getpagesize();
|
||||
page_size = (uint64)getpagesize();
|
||||
request_size = (size + page_size - 1) & ~(page_size - 1);
|
||||
|
||||
if ((size_t)request_size < size)
|
||||
|
@ -60,7 +60,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
|
|||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
uint64 page_size = getpagesize();
|
||||
uint64 page_size = (uint64)getpagesize();
|
||||
uint64 request_size = (size + page_size - 1) & ~(page_size - 1);
|
||||
|
||||
if (addr) {
|
||||
|
@ -75,7 +75,7 @@ int
|
|||
os_mprotect(void *addr, size_t size, int prot)
|
||||
{
|
||||
int map_prot = PROT_NONE;
|
||||
uint64 page_size = getpagesize();
|
||||
uint64 page_size = (uint64)getpagesize();
|
||||
uint64 request_size = (size + page_size - 1) & ~(page_size - 1);
|
||||
|
||||
if (!addr)
|
||||
|
|
|
@ -242,7 +242,8 @@ uint8 *os_thread_get_stack_boundary()
|
|||
uint8 *addr = NULL;
|
||||
size_t stack_size, guard_size;
|
||||
int page_size = getpagesize();
|
||||
size_t max_stack_size = (APP_THREAD_STACK_SIZE_MAX + page_size - 1)
|
||||
size_t max_stack_size = (size_t)
|
||||
(APP_THREAD_STACK_SIZE_MAX + page_size - 1)
|
||||
& ~(page_size - 1);
|
||||
|
||||
if (max_stack_size < APP_THREAD_STACK_SIZE_DEFAULT)
|
||||
|
|
|
@ -143,7 +143,7 @@ There are two runtime APIs available for this purpose.
|
|||
* p_native_addr: return the native address of allocated memory
|
||||
* size: the buffer size to allocate
|
||||
*/
|
||||
int32_t
|
||||
uint32_t
|
||||
wasm_runtime_module_malloc(wasm_module_inst_t module_inst,
|
||||
uint32_t size, void **p_native_addr);
|
||||
|
||||
|
@ -155,20 +155,20 @@ wasm_runtime_module_malloc(wasm_module_inst_t module_inst,
|
|||
* src: the native buffer address
|
||||
* size: the size of buffer to be allocated and copy data
|
||||
*/
|
||||
int32
|
||||
uint32_t
|
||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||
const char *src, uint32 size);
|
||||
const char *src, uint32_t size);
|
||||
|
||||
/* free the memory allocated from module memory space */
|
||||
void
|
||||
wasm_runtime_module_free(wasm_module_inst_t module_inst, int32_t ptr);
|
||||
wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
|
||||
```
|
||||
|
||||
Usage sample:
|
||||
|
||||
```c
|
||||
char * buffer = NULL;
|
||||
int32_t buffer_for_wasm;
|
||||
uint32_t buffer_for_wasm;
|
||||
|
||||
buffer_for_wasm = wasm_runtime_module_malloc(module_inst, 100, &buffer);
|
||||
if (buffer_for_wasm != 0) {
|
||||
|
|
|
@ -32,7 +32,7 @@ int main(int argc, char *argv_main[])
|
|||
wasm_function_inst_t func = NULL;
|
||||
wasm_function_inst_t func2 = NULL;
|
||||
char * native_buffer = NULL;
|
||||
int32_t wasm_buffer = 0;
|
||||
uint32_t wasm_buffer = 0;
|
||||
|
||||
RuntimeInitArgs init_args;
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
|
|
@ -183,7 +183,7 @@ display_map(wasm_exec_env_t exec_env,
|
|||
|
||||
typedef struct display_input_data {
|
||||
lv_point_t point;
|
||||
int32 user_data_offset;
|
||||
uint32 user_data_offset;
|
||||
uint8 state;
|
||||
} display_input_data;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user