Refactor APIs and data structures as preliminary work for Memory64 (#3209)

# Change the data type representing linear memory address from u32 to u64

## APIs signature changes
- (Export)wasm_runtime_module_malloc
  - wasm_module_malloc
    - wasm_module_malloc_internal
  - aot_module_malloc
    - aot_module_malloc_internal
- wasm_runtime_module_realloc
  - wasm_module_realloc
    - wasm_module_realloc_internal
  - aot_module_realloc
    - aot_module_realloc_internal
- (Export)wasm_runtime_module_free
  - wasm_module_free
    - wasm_module_free_internal
  - aot_module_malloc
    - aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
  - wasm_module_dup_data
  - aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
  and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack

## Data structure changes
- WASMModule and AOTModule
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
  - field aux_stack_boundary and aux_stack_bottom
- AOTCompData
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
  - field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
  - field total_size and memories_size
- WASMDebugExecutionMemory
  - field start_offset and current_pos
- WASMCluster
  - field stack_tops

## Components that are affected by the APIs and data structure changes
- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager
This commit is contained in:
Wenyong Huang
2024-03-12 11:38:50 +08:00
committed by GitHub
parent b6216a5f8a
commit 0ee5ffce85
46 changed files with 1006 additions and 754 deletions

View File

@ -409,7 +409,7 @@ wasm_debug_instance_create(WASMCluster *cluster, int32 port)
* expressions */
instance->exec_mem_info.size = DEBUG_EXECUTION_MEMORY_SIZE;
instance->exec_mem_info.start_offset = wasm_runtime_module_malloc(
module_inst, instance->exec_mem_info.size, NULL);
module_inst, (uint64)instance->exec_mem_info.size, NULL);
if (instance->exec_mem_info.start_offset == 0) {
LOG_WARNING(
"WASM Debug Engine warning: failed to allocate linear memory for "
@ -1393,7 +1393,7 @@ wasm_debug_instance_mmap(WASMDebugInstance *instance, uint32 size,
return 0;
}
if ((uint64)instance->exec_mem_info.current_pos
if (instance->exec_mem_info.current_pos
- instance->exec_mem_info.start_offset + size
<= (uint64)instance->exec_mem_info.size) {
offset = instance->exec_mem_info.current_pos;

View File

@ -53,9 +53,9 @@ typedef enum debug_state_t {
} debug_state_t;
typedef struct WASMDebugExecutionMemory {
uint32 start_offset;
uint64 start_offset;
uint64 current_pos;
uint32 size;
uint32 current_pos;
} WASMDebugExecutionMemory;
struct WASMDebugInstance {

View File

@ -558,7 +558,8 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
ThreadRoutineArgs *routine_args = NULL;
uint32 thread_handle;
uint32 stack_size = 8192;
uint32 aux_stack_start = 0, aux_stack_size;
uint32 aux_stack_size;
uint64 aux_stack_start = 0;
int32 ret = -1;
bh_assert(module);
@ -669,14 +670,14 @@ pthread_join_wrapper(wasm_exec_env_t exec_env, uint32 thread,
/* validate addr, we can use current thread's
module instance here as the memory is shared */
if (!validate_app_addr(retval_offset, sizeof(int32))) {
if (!validate_app_addr((uint64)retval_offset, (uint64)sizeof(int32))) {
/* Join failed, but we don't want to terminate all threads,
do not spread exception here */
wasm_runtime_set_exception(module_inst, NULL);
return -1;
}
retval = (void **)addr_app_to_native(retval_offset);
retval = (void **)addr_app_to_native((uint64)retval_offset);
node = get_thread_info(exec_env, thread);
if (!node) {
@ -1263,7 +1264,7 @@ sem_getvalue_wrapper(wasm_exec_env_t exec_env, uint32 sem, int32 *sval)
(void)exec_env;
SemCallbackArgs args = { sem, NULL };
if (validate_native_addr(sval, sizeof(int32))) {
if (validate_native_addr(sval, (uint64)sizeof(int32))) {
bh_hash_map_traverse(sem_info_map, sem_fetch_cb, &args);

View File

@ -233,7 +233,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
return false;
}
s = start = addr_app_to_native(s_offset);
s = start = addr_app_to_native((uint64)s_offset);
str_len = (uint32)strlen(start);
if (str_len >= UINT32_MAX - 64) {
@ -401,7 +401,7 @@ printf_wrapper(wasm_exec_env_t exec_env, const char *format, _va_list va_args)
struct str_context ctx = { NULL, 0, 0 };
/* format has been checked by runtime */
if (!validate_native_addr(va_args, sizeof(int32)))
if (!validate_native_addr(va_args, (uint64)sizeof(int32)))
return 0;
if (!_vprintf_wa((out_func_t)printf_out, &ctx, format, va_args,
@ -420,7 +420,7 @@ sprintf_wrapper(wasm_exec_env_t exec_env, char *str, const char *format,
struct str_context ctx;
/* str and format have been checked by runtime */
if (!validate_native_addr(va_args, sizeof(uint32)))
if (!validate_native_addr(va_args, (uint64)sizeof(uint32)))
return 0;
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8 *)str, NULL,
@ -452,7 +452,7 @@ snprintf_wrapper(wasm_exec_env_t exec_env, char *str, uint32 size,
struct str_context ctx;
/* str and format have been checked by runtime */
if (!validate_native_addr(va_args, sizeof(uint32)))
if (!validate_native_addr(va_args, (uint64)sizeof(uint32)))
return 0;
ctx.str = str;
@ -499,7 +499,7 @@ strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
if (str) {
len = (uint32)strlen(str) + 1;
str_ret_offset = module_malloc(len, (void **)&str_ret);
str_ret_offset = (uint32)module_malloc((uint64)len, (void **)&str_ret);
if (str_ret_offset) {
bh_memcpy_s(str_ret, len, str, len);
}
@ -521,7 +521,7 @@ memcmp_wrapper(wasm_exec_env_t exec_env, const void *s1, const void *s2,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
/* s2 has been checked by runtime */
if (!validate_native_addr((void *)s1, size))
if (!validate_native_addr((void *)s1, (uint64)size))
return 0;
return memcmp(s1, s2, size);
@ -532,13 +532,13 @@ 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);
uint32 dst_offset = addr_native_to_app(dst);
uint32 dst_offset = (uint32)addr_native_to_app(dst);
if (size == 0)
return dst_offset;
/* src has been checked by runtime */
if (!validate_native_addr(dst, size))
if (!validate_native_addr(dst, (uint64)size))
return dst_offset;
bh_memcpy_s(dst, size, src, size);
@ -549,13 +549,13 @@ 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);
uint32 dst_offset = addr_native_to_app(dst);
uint32 dst_offset = (uint32)addr_native_to_app(dst);
if (size == 0)
return dst_offset;
/* src has been checked by runtime */
if (!validate_native_addr(dst, size))
if (!validate_native_addr(dst, (uint64)size))
return dst_offset;
memmove(dst, src, size);
@ -566,9 +566,9 @@ 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);
uint32 s_offset = addr_native_to_app(s);
uint32 s_offset = (uint32)addr_native_to_app(s);
if (!validate_native_addr(s, size))
if (!validate_native_addr(s, (uint64)size))
return s_offset;
memset(s, c, size);
@ -583,7 +583,7 @@ strchr_wrapper(wasm_exec_env_t exec_env, const char *s, int32 c)
/* s has been checked by runtime */
ret = strchr(s, c);
return ret ? addr_native_to_app(ret) : 0;
return ret ? (uint32)addr_native_to_app(ret) : 0;
}
static int32
@ -602,7 +602,7 @@ strncmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
/* s2 has been checked by runtime */
if (!validate_native_addr((void *)s1, size))
if (!validate_native_addr((void *)s1, (uint64)size))
return 0;
return strncmp(s1, s2, size);
@ -615,7 +615,7 @@ strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
uint32 len = (uint32)strlen(src) + 1;
/* src has been checked by runtime */
if (!validate_native_addr(dst, len))
if (!validate_native_addr(dst, (uint64)len))
return 0;
#ifndef BH_PLATFORM_WINDOWS
@ -623,7 +623,7 @@ strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
#else
strncpy_s(dst, len, src, len);
#endif
return addr_native_to_app(dst);
return (uint32)addr_native_to_app(dst);
}
static uint32
@ -633,7 +633,7 @@ strncpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
/* src has been checked by runtime */
if (!validate_native_addr(dst, size))
if (!validate_native_addr(dst, (uint64)size))
return 0;
#ifndef BH_PLATFORM_WINDOWS
@ -641,7 +641,7 @@ strncpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src,
#else
strncpy_s(dst, size, src, size);
#endif
return addr_native_to_app(dst);
return (uint32)addr_native_to_app(dst);
}
static uint32
@ -657,7 +657,7 @@ 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);
return (uint32)module_malloc((uint64)size, NULL);
}
static uint32
@ -671,7 +671,7 @@ calloc_wrapper(wasm_exec_env_t exec_env, uint32 nmemb, uint32 size)
if (total_size >= UINT32_MAX)
return 0;
ret_offset = module_malloc((uint32)total_size, (void **)&ret_ptr);
ret_offset = (uint32)module_malloc(total_size, (void **)&ret_ptr);
if (ret_offset) {
memset(ret_ptr, 0, (uint32)total_size);
}
@ -692,7 +692,7 @@ free_wrapper(wasm_exec_env_t exec_env, void *ptr)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!validate_native_addr(ptr, sizeof(uint32)))
if (!validate_native_addr(ptr, (uint64)sizeof(uint32)))
return;
module_free(addr_native_to_app(ptr));
@ -723,11 +723,11 @@ strtol_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
int32 num = 0;
/* nptr has been checked by runtime */
if (!validate_native_addr(endptr, sizeof(uint32)))
if (!validate_native_addr(endptr, (uint64)sizeof(uint32)))
return 0;
num = (int32)strtol(nptr, endptr, base);
*(uint32 *)endptr = addr_native_to_app(*endptr);
*(uint32 *)endptr = (uint32)addr_native_to_app(*endptr);
return num;
}
@ -740,11 +740,11 @@ strtoul_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
uint32 num = 0;
/* nptr has been checked by runtime */
if (!validate_native_addr(endptr, sizeof(uint32)))
if (!validate_native_addr(endptr, (uint64)sizeof(uint32)))
return 0;
num = (uint32)strtoul(nptr, endptr, base);
*(uint32 *)endptr = addr_native_to_app(*endptr);
*(uint32 *)endptr = (uint32)addr_native_to_app(*endptr);
return num;
}
@ -755,11 +755,11 @@ memchr_wrapper(wasm_exec_env_t exec_env, const void *s, int32 c, uint32 n)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
void *res;
if (!validate_native_addr((void *)s, n))
if (!validate_native_addr((void *)s, (uint64)n))
return 0;
res = memchr(s, c, n);
return addr_native_to_app(res);
return (uint32)addr_native_to_app(res);
}
static int32
@ -796,7 +796,7 @@ strstr_wrapper(wasm_exec_env_t exec_env, const char *s, const char *find)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
/* s and find have been checked by runtime */
char *res = strstr(s, find);
return addr_native_to_app(res);
return (uint32)addr_native_to_app(res);
}
static int32
@ -884,10 +884,10 @@ 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);
uint32 dst_offset = addr_native_to_app(dst);
uint32 dst_offset = (uint32)addr_native_to_app(dst);
/* src has been checked by runtime */
if (!validate_native_addr(dst, size))
if (!validate_native_addr(dst, (uint64)size))
return dst_offset;
bh_memcpy_s(dst, size, src, size);
@ -925,7 +925,7 @@ 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);
uint32 exception = module_malloc(thrown_size, NULL);
uint32 exception = (uint32)module_malloc((uint64)thrown_size, NULL);
if (!exception)
return 0;
@ -968,7 +968,7 @@ clock_gettime_wrapper(wasm_exec_env_t exec_env, uint32 clk_id,
(void)clk_id;
if (!validate_native_addr(ts_app, sizeof(struct timespec_app)))
if (!validate_native_addr(ts_app, (uint64)sizeof(struct timespec_app)))
return (uint32)-1;
time = os_time_get_boot_us();

View File

@ -184,7 +184,8 @@ __sys_stat64_wrapper(wasm_exec_env_t exec_env, const char *pathname,
int ret;
struct stat statbuf;
if (!validate_native_addr((void *)statbuf_app, sizeof(struct stat_emcc)))
if (!validate_native_addr((void *)statbuf_app,
(uint64)sizeof(struct stat_emcc)))
return -1;
if (pathname == NULL)
@ -204,7 +205,8 @@ __sys_fstat64_wrapper(wasm_exec_env_t exec_env, int fd,
int ret;
struct stat statbuf;
if (!validate_native_addr((void *)statbuf_app, sizeof(struct stat_emcc)))
if (!validate_native_addr((void *)statbuf_app,
(uint64)sizeof(struct stat_emcc)))
return -1;
if (fd <= 0)
@ -225,7 +227,7 @@ mmap_wrapper(wasm_exec_env_t exec_env, void *addr, int length, int prot,
char *buf;
int size_read;
buf_offset = module_malloc(length, (void **)&buf);
buf_offset = module_malloc((uint64)length, (void **)&buf);
if (buf_offset == 0)
return -1;
@ -244,7 +246,7 @@ static int
munmap_wrapper(wasm_exec_env_t exec_env, uint32 buf_offset, int length)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
module_free(buf_offset);
module_free((uint64)buf_offset);
return 0;
}
@ -422,7 +424,7 @@ __sys_getcwd_wrapper(wasm_exec_env_t exec_env, char *buf, uint32 size)
return -1;
ret = getcwd(buf, size);
return ret ? addr_native_to_app(ret) : 0;
return ret ? (uint32)addr_native_to_app(ret) : 0;
}
#include <sys/utsname.h>
@ -443,7 +445,7 @@ __sys_uname_wrapper(wasm_exec_env_t exec_env, struct utsname_app *uname_app)
struct utsname uname_native = { 0 };
uint32 length;
if (!validate_native_addr(uname_app, sizeof(struct utsname_app)))
if (!validate_native_addr(uname_app, (uint64)sizeof(struct utsname_app)))
return -1;
if (uname(&uname_native) != 0) {

View File

@ -115,9 +115,9 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
total_size = sizeof(int32) * ((uint64)argc + 1);
if (total_size >= UINT32_MAX
|| !validate_native_addr(argv_offsets, (uint32)total_size)
|| !validate_native_addr(argv_offsets, total_size)
|| argv_buf_size >= UINT32_MAX
|| !validate_native_addr(argv_buf, (uint32)argv_buf_size))
|| !validate_native_addr(argv_buf, (uint64)argv_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char *) * ((uint64)argc + 1);
@ -132,7 +132,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
}
for (i = 0; i < argc; i++)
argv_offsets[i] = addr_native_to_app(argv[i]);
argv_offsets[i] = (uint32)addr_native_to_app(argv[i]);
wasm_runtime_free(argv);
return 0;
@ -150,8 +150,8 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(argc_app, sizeof(uint32))
|| !validate_native_addr(argv_buf_size_app, sizeof(uint32)))
if (!validate_native_addr(argc_app, (uint64)sizeof(uint32))
|| !validate_native_addr(argv_buf_size_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = uvwasi_args_sizes_get(uvwasi, &argc, &argv_buf_size);
@ -170,7 +170,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env, wasi_clockid_t clock_id,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
if (!validate_native_addr(resolution, (uint64)sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
return uvwasi_clock_res_get(uvwasi, clock_id, resolution);
@ -183,7 +183,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env, wasi_clockid_t clock_id,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
if (!validate_native_addr(time, (uint64)sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
return uvwasi_clock_time_get(uvwasi, clock_id, precision, time);
@ -212,9 +212,9 @@ wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
total_size = sizeof(int32) * ((uint64)environ_count + 1);
if (total_size >= UINT32_MAX
|| !validate_native_addr(environ_offsets, (uint32)total_size)
|| !validate_native_addr(environ_offsets, total_size)
|| environ_buf_size >= UINT32_MAX
|| !validate_native_addr(environ_buf, (uint32)environ_buf_size))
|| !validate_native_addr(environ_buf, (uint64)environ_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char *) * (((uint64)environ_count + 1));
@ -230,7 +230,7 @@ wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
}
for (i = 0; i < environ_count; i++)
environ_offsets[i] = addr_native_to_app(environs[i]);
environ_offsets[i] = (uint32)addr_native_to_app(environs[i]);
wasm_runtime_free(environs);
return 0;
@ -248,8 +248,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(environ_count_app, sizeof(uint32))
|| !validate_native_addr(environ_buf_size_app, sizeof(uint32)))
if (!validate_native_addr(environ_count_app, (uint64)sizeof(uint32))
|| !validate_native_addr(environ_buf_size_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = uvwasi_environ_sizes_get(uvwasi, &environ_count, &environ_buf_size);
@ -273,7 +273,7 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(prestat_app, sizeof(wasi_prestat_app_t)))
if (!validate_native_addr(prestat_app, (uint64)sizeof(wasi_prestat_app_t)))
return (wasi_errno_t)-1;
err = uvwasi_fd_prestat_get(uvwasi, fd, &prestat);
@ -338,9 +338,9 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nread_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr(iovec_app, (uint32)total_size))
|| !validate_native_addr(iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
@ -350,11 +350,12 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
iovec = iovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
@ -389,9 +390,9 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nwritten_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -401,11 +402,12 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec = ciovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
@ -440,9 +442,9 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nread_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
@ -452,11 +454,12 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
iovec = iovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
@ -496,7 +499,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return uvwasi_fd_seek(uvwasi, fd, offset, whence, newoffset);
@ -511,7 +514,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return uvwasi_fd_tell(uvwasi, fd, newoffset);
@ -529,7 +532,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t)))
if (!validate_native_addr(fdstat_app, (uint64)sizeof(wasi_fdstat_t)))
return (wasi_errno_t)-1;
err = uvwasi_fd_fdstat_get(uvwasi, fd, &fdstat);
@ -597,9 +600,9 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nwritten_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -609,11 +612,12 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec = ciovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
@ -725,7 +729,7 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
if (!validate_native_addr(fd_app, (uint64)sizeof(wasi_fd_t)))
return (wasi_errno_t)-1;
err = uvwasi_path_open(uvwasi, dirfd, dirflags, path, path_len, oflags,
@ -747,7 +751,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(bufused_app, sizeof(uint32)))
if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = uvwasi_fd_readdir(uvwasi, fd, buf, buf_len, cookie, &bufused);
@ -771,7 +775,7 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(bufused_app, sizeof(uint32)))
if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = uvwasi_path_readlink(uvwasi, fd, path, path_len, buf, buf_len,
@ -808,7 +812,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return uvwasi_fd_filestat_get(uvwasi, fd, filestat);
@ -852,7 +856,7 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return uvwasi_path_filestat_get(uvwasi, fd, flags, path, path_len,
@ -928,9 +932,9 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
if (!uvwasi)
return (wasi_errno_t)-1;
if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
|| !validate_native_addr(out, sizeof(wasi_event_t))
|| !validate_native_addr(nevents_app, sizeof(uint32)))
if (!validate_native_addr((void *)in, (uint64)sizeof(wasi_subscription_t))
|| !validate_native_addr(out, (uint64)sizeof(wasi_event_t))
|| !validate_native_addr(nevents_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = uvwasi_poll_oneoff(uvwasi, in, out, nsubscriptions, &nevents);
@ -1002,11 +1006,12 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
iovec = iovec_begin;
for (i = 0; i < ri_data_len; i++, ri_data++, iovec++) {
if (!validate_app_addr(ri_data->buf_offset, ri_data->buf_len)) {
if (!validate_app_addr((uint64)ri_data->buf_offset,
(uint64)ri_data->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void *)addr_app_to_native(ri_data->buf_offset);
iovec->buf = (void *)addr_app_to_native((uint64)ri_data->buf_offset);
iovec->buf_len = ri_data->buf_len;
}
@ -1042,9 +1047,9 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)si_data_len;
if (!validate_native_addr(so_datalen_app, sizeof(uint32))
if (!validate_native_addr(so_datalen_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)si_data, (uint32)total_size))
|| !validate_native_addr((void *)si_data, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)si_data_len;
@ -1054,11 +1059,12 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
ciovec = ciovec_begin;
for (i = 0; i < si_data_len; i++, si_data++, ciovec++) {
if (!validate_app_addr(si_data->buf_offset, si_data->buf_len)) {
if (!validate_app_addr((uint64)si_data->buf_offset,
(uint64)si_data->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char *)addr_app_to_native(si_data->buf_offset);
ciovec->buf = (char *)addr_app_to_native((uint64)si_data->buf_offset);
ciovec->buf_len = si_data->buf_len;
}

View File

@ -132,9 +132,9 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
total_size = sizeof(int32) * ((uint64)argc + 1);
if (total_size >= UINT32_MAX
|| !validate_native_addr(argv_offsets, (uint32)total_size)
|| !validate_native_addr(argv_offsets, total_size)
|| argv_buf_size >= UINT32_MAX
|| !validate_native_addr(argv_buf, (uint32)argv_buf_size))
|| !validate_native_addr(argv_buf, (uint64)argv_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char *) * ((uint64)argc + 1);
@ -149,7 +149,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
}
for (i = 0; i < argc; i++)
argv_offsets[i] = addr_native_to_app(argv[i]);
argv_offsets[i] = (uint32)addr_native_to_app(argv[i]);
wasm_runtime_free(argv);
return 0;
@ -168,8 +168,8 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(argc_app, sizeof(uint32))
|| !validate_native_addr(argv_buf_size_app, sizeof(uint32)))
if (!validate_native_addr(argc_app, (uint64)sizeof(uint32))
|| !validate_native_addr(argv_buf_size_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
argv_environ = wasi_ctx->argv_environ;
@ -190,7 +190,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
if (!validate_native_addr(resolution, (uint64)sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
return os_clock_res_get(clock_id, resolution);
@ -204,7 +204,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
if (!validate_native_addr(time, (uint64)sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
return os_clock_time_get(clock_id, precision, time);
@ -233,9 +233,9 @@ wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
total_size = sizeof(int32) * ((uint64)environ_count + 1);
if (total_size >= UINT32_MAX
|| !validate_native_addr(environ_offsets, (uint32)total_size)
|| !validate_native_addr(environ_offsets, total_size)
|| environ_buf_size >= UINT32_MAX
|| !validate_native_addr(environ_buf, (uint32)environ_buf_size))
|| !validate_native_addr(environ_buf, (uint64)environ_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char *) * (((uint64)environ_count + 1));
@ -251,7 +251,7 @@ wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
}
for (i = 0; i < environ_count; i++)
environ_offsets[i] = addr_native_to_app(environs[i]);
environ_offsets[i] = (uint32)addr_native_to_app(environs[i]);
wasm_runtime_free(environs);
return 0;
@ -271,8 +271,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(environ_count_app, sizeof(uint32))
|| !validate_native_addr(environ_buf_size_app, sizeof(uint32)))
if (!validate_native_addr(environ_count_app, (uint64)sizeof(uint32))
|| !validate_native_addr(environ_buf_size_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
@ -299,7 +299,7 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(prestat_app, sizeof(wasi_prestat_app_t)))
if (!validate_native_addr(prestat_app, (uint64)sizeof(wasi_prestat_app_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_prestat_get(prestats, fd, &prestat);
@ -369,9 +369,9 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nread_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr(iovec_app, (uint32)total_size))
|| !validate_native_addr(iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
@ -382,11 +382,12 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
iovec = iovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
@ -423,9 +424,9 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nwritten_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -436,11 +437,12 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec = ciovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
@ -476,9 +478,9 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nread_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
@ -489,11 +491,12 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
iovec = iovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
@ -537,7 +540,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence,
@ -554,7 +557,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_tell(exec_env, curfds, fd, newoffset);
@ -573,7 +576,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t)))
if (!validate_native_addr(fdstat_app, (uint64)sizeof(wasi_fdstat_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_fdstat_get(exec_env, curfds, fd, &fdstat);
@ -645,9 +648,9 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
return (wasi_errno_t)-1;
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
if (!validate_native_addr(nwritten_app, (uint64)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -658,11 +661,12 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec = ciovec_begin;
for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
if (!validate_app_addr((uint64)iovec_app->buf_offset,
(uint64)iovec_app->buf_len)) {
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
@ -759,7 +763,7 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
if (!validate_native_addr(fd_app, (uint64)sizeof(wasi_fd_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path,
@ -783,7 +787,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(bufused_app, sizeof(uint32)))
if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie,
@ -809,7 +813,7 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(bufused_app, sizeof(uint32)))
if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf,
@ -849,7 +853,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_filestat_get(exec_env, curfds, fd, filestat);
@ -897,7 +901,7 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path,
@ -1083,9 +1087,9 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
|| !validate_native_addr(out, sizeof(wasi_event_t))
|| !validate_native_addr(nevents_app, sizeof(uint32)))
if (!validate_native_addr((void *)in, (uint64)sizeof(wasi_subscription_t))
|| !validate_native_addr(out, (uint64)sizeof(wasi_event_t))
|| !validate_native_addr(nevents_app, (uint64)sizeof(uint32)))
return (wasi_errno_t)-1;
#if WASM_ENABLE_THREAD_MGR == 0
@ -1160,7 +1164,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(addr, sizeof(__wasi_addr_t)))
if (!validate_native_addr(addr, (uint64)sizeof(__wasi_addr_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1179,7 +1183,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(addr, sizeof(__wasi_addr_t)))
if (!validate_native_addr(addr, (uint64)sizeof(__wasi_addr_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1264,7 +1268,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1283,7 +1287,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1302,8 +1306,8 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool))
|| !validate_native_addr(linger_s, sizeof(int)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool))
|| !validate_native_addr(linger_s, (uint64)sizeof(int)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1323,7 +1327,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(size, sizeof(wasi_size_t)))
if (!validate_native_addr(size, (uint64)sizeof(wasi_size_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1342,7 +1346,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(timeout_us, sizeof(uint64_t)))
if (!validate_native_addr(timeout_us, (uint64)sizeof(uint64_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1361,7 +1365,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1380,7 +1384,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1399,7 +1403,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(size, sizeof(__wasi_size_t)))
if (!validate_native_addr(size, (uint64)sizeof(__wasi_size_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1418,7 +1422,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(timeout_us, sizeof(uint64_t)))
if (!validate_native_addr(timeout_us, (uint64)sizeof(uint64_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1437,7 +1441,7 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1457,7 +1461,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1476,7 +1480,7 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1496,7 +1500,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(time_s, sizeof(uint32_t)))
if (!validate_native_addr(time_s, (uint64)sizeof(uint32_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1515,7 +1519,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(time_s, sizeof(uint32_t)))
if (!validate_native_addr(time_s, (uint64)sizeof(uint32_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1534,7 +1538,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1553,7 +1557,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s)
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(ttl_s, sizeof(uint8_t)))
if (!validate_native_addr(ttl_s, (uint64)sizeof(uint8_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1572,7 +1576,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(ttl_s, sizeof(uint8_t)))
if (!validate_native_addr(ttl_s, (uint64)sizeof(uint8_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1591,7 +1595,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(is_enabled, sizeof(bool)))
if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1884,7 +1888,7 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(imr_multiaddr, sizeof(__wasi_addr_ip_t)))
if (!validate_native_addr(imr_multiaddr, (uint64)sizeof(__wasi_addr_ip_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1905,7 +1909,7 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
if (!validate_native_addr(imr_multiaddr, sizeof(__wasi_addr_ip_t)))
if (!validate_native_addr(imr_multiaddr, (uint64)sizeof(__wasi_addr_ip_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(wasi_ctx);
@ -1975,7 +1979,7 @@ allocate_iovec_app_buffer(wasm_module_inst_t module_inst,
total_size = sizeof(iovec_app_t) * (uint64)data_len;
if (total_size >= UINT32_MAX
|| !validate_native_addr((void *)data, (uint32)total_size))
|| !validate_native_addr((void *)data, total_size))
return __WASI_EINVAL;
for (total_size = 0, i = 0; i < data_len; i++, data++) {
@ -2013,7 +2017,8 @@ copy_buffer_to_iovec_app(wasm_module_inst_t module_inst, uint8 *buf_begin,
for (i = 0; i < data_len; data++, i++) {
char *native_addr;
if (!validate_app_addr(data->buf_offset, data->buf_len)) {
if (!validate_app_addr((uint64)data->buf_offset,
(uint64)data->buf_len)) {
return __WASI_EINVAL;
}
@ -2032,7 +2037,7 @@ copy_buffer_to_iovec_app(wasm_module_inst_t module_inst, uint8 *buf_begin,
*/
size_to_copy_into_iovec = min_uint32(data->buf_len, size_to_copy);
native_addr = (void *)addr_app_to_native(data->buf_offset);
native_addr = (void *)addr_app_to_native((uint64)data->buf_offset);
bh_memcpy_s(native_addr, size_to_copy_into_iovec, buf,
size_to_copy_into_iovec);
buf += size_to_copy_into_iovec;
@ -2064,7 +2069,7 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
return __WASI_EINVAL;
}
if (!validate_native_addr(ro_data_len, (uint32)sizeof(uint32)))
if (!validate_native_addr(ro_data_len, (uint64)sizeof(uint32)))
return __WASI_EINVAL;
err = allocate_iovec_app_buffer(module_inst, ri_data, ri_data_len,
@ -2103,7 +2108,7 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
__wasi_addr_t src_addr;
wasi_errno_t error;
if (!validate_native_addr(ro_flags, (uint32)sizeof(wasi_roflags_t)))
if (!validate_native_addr(ro_flags, (uint64)sizeof(wasi_roflags_t)))
return __WASI_EINVAL;
error = wasi_sock_recv_from(exec_env, sock, ri_data, ri_data_len, ri_flags,
@ -2134,12 +2139,13 @@ convert_iovec_app_to_buffer(wasm_module_inst_t module_inst,
for (i = 0; i < si_data_len; i++, si_data++) {
char *native_addr;
if (!validate_app_addr(si_data->buf_offset, si_data->buf_len)) {
if (!validate_app_addr((uint64)si_data->buf_offset,
(uint64)si_data->buf_len)) {
wasm_runtime_free(*buf_ptr);
return __WASI_EINVAL;
}
native_addr = (char *)addr_app_to_native(si_data->buf_offset);
native_addr = (char *)addr_app_to_native((uint64)si_data->buf_offset);
bh_memcpy_s(buf, si_data->buf_len, native_addr, si_data->buf_len);
buf += si_data->buf_len;
}
@ -2168,7 +2174,7 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
return __WASI_EINVAL;
}
if (!validate_native_addr(so_data_len, sizeof(uint32)))
if (!validate_native_addr(so_data_len, (uint64)sizeof(uint32)))
return __WASI_EINVAL;
err = convert_iovec_app_to_buffer(module_inst, si_data, si_data_len, &buf,
@ -2209,7 +2215,7 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock,
return __WASI_EINVAL;
}
if (!validate_native_addr(so_data_len, sizeof(uint32)))
if (!validate_native_addr(so_data_len, (uint64)sizeof(uint32)))
return __WASI_EINVAL;
err = convert_iovec_app_to_buffer(module_inst, si_data, si_data_len, &buf,

View File

@ -139,14 +139,14 @@ final:
/* The caller must not have any locks */
bool
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint64 *p_start,
uint32 *p_size)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
#if WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION != 0
WASMModuleInstanceCommon *module_inst =
wasm_exec_env_get_module_inst(exec_env);
uint32 stack_end;
uint64 stack_end;
stack_end = wasm_runtime_module_malloc_internal(module_inst, exec_env,
cluster->stack_size, NULL);
@ -185,7 +185,7 @@ wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
/* The caller must not have any locks */
bool
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start)
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint64 start)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
@ -223,7 +223,8 @@ WASMCluster *
wasm_cluster_create(WASMExecEnv *exec_env)
{
WASMCluster *cluster;
uint32 aux_stack_start, aux_stack_size;
uint32 aux_stack_size;
uint64 aux_stack_start;
bh_assert(exec_env->cluster == NULL);
if (!(cluster = wasm_runtime_malloc(sizeof(WASMCluster)))) {
@ -280,7 +281,7 @@ wasm_cluster_create(WASMExecEnv *exec_env)
#if WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION == 0
if (cluster_max_thread_num != 0) {
uint64 total_size = cluster_max_thread_num * sizeof(uint32);
uint64 total_size = cluster_max_thread_num * sizeof(uint64);
uint32 i;
if (total_size >= UINT32_MAX
|| !(cluster->stack_tops =
@ -496,7 +497,8 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_module_t module;
wasm_module_inst_t new_module_inst;
WASMExecEnv *new_exec_env;
uint32 aux_stack_start, aux_stack_size;
uint32 aux_stack_size;
uint64 aux_stack_start;
uint32 stack_size = 8192;
if (!module_inst || !(module = wasm_exec_env_get_module(exec_env))) {
@ -603,7 +605,7 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env_tls,
exec_env->aux_stack_bottom.bottom);
(uint64)exec_env->aux_stack_bottom);
os_mutex_lock(&cluster->lock);
@ -653,7 +655,7 @@ thread_manager_start_routine(void *arg)
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
wasm_cluster_free_aux_stack(exec_env, (uint64)exec_env->aux_stack_bottom);
os_mutex_lock(&cluster_list_lock);
@ -693,7 +695,7 @@ thread_manager_start_routine(void *arg)
int32
wasm_cluster_create_thread(WASMExecEnv *exec_env,
wasm_module_inst_t module_inst,
bool is_aux_stack_allocated, uint32 aux_stack_start,
bool is_aux_stack_allocated, uint64 aux_stack_start,
uint32 aux_stack_size,
void *(*thread_routine)(void *), void *arg)
{
@ -724,8 +726,8 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
}
else {
/* Disable aux stack */
new_exec_env->aux_stack_boundary.boundary = 0;
new_exec_env->aux_stack_bottom.bottom = UINT32_MAX;
new_exec_env->aux_stack_boundary = 0;
new_exec_env->aux_stack_bottom = UINTPTR_MAX;
}
/* Inherit suspend_flags of parent thread */
@ -1050,7 +1052,7 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
wasm_cluster_free_aux_stack(exec_env, (uint64)exec_env->aux_stack_bottom);
/* App exit the thread, free the resources before exit native thread */

View File

@ -30,7 +30,7 @@ struct WASMCluster {
/* The aux stack of a module with shared memory will be
divided into several segments. This array store the
stack top of different segments */
uint32 *stack_tops;
uint64 *stack_tops;
/* Record which segments are occupied */
bool *stack_segment_occupied;
#endif
@ -89,7 +89,7 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
int32
wasm_cluster_create_thread(WASMExecEnv *exec_env,
wasm_module_inst_t module_inst,
bool is_aux_stack_allocated, uint32 aux_stack_start,
bool is_aux_stack_allocated, uint64 aux_stack_start,
uint32 aux_stack_size,
void *(*thread_routine)(void *), void *arg);
@ -231,11 +231,11 @@ void
wasm_cluster_traverse_unlock(WASMExecEnv *exec_env);
bool
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint64 *p_start,
uint32 *p_size);
bool
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start);
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint64 start);
#ifdef __cplusplus
}

View File

@ -10,14 +10,15 @@ graph_builder_app_native(wasm_module_inst_t instance,
graph_builder_wasm *builder_wasm,
graph_builder *builder)
{
if (!wasm_runtime_validate_app_addr(instance, builder_wasm->buf_offset,
builder_wasm->size * sizeof(uint8_t))) {
if (!wasm_runtime_validate_app_addr(
instance, (uint64)builder_wasm->buf_offset,
(uint64)builder_wasm->size * sizeof(uint8_t))) {
NN_ERR_PRINTF("builder_wasm->buf_offset is invalid");
return invalid_argument;
}
builder->buf = (uint8_t *)wasm_runtime_addr_app_to_native(
instance, builder_wasm->buf_offset);
instance, (uint64)builder_wasm->buf_offset);
builder->size = builder_wasm->size;
return success;
}
@ -27,8 +28,9 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
graph_builder_array_wasm *builder_array_wasm,
graph_builder_array *builder_array)
{
if (!wasm_runtime_validate_native_addr(instance, builder_array_wasm,
sizeof(graph_builder_array_wasm))) {
if (!wasm_runtime_validate_native_addr(
instance, builder_array_wasm,
(uint64)sizeof(graph_builder_array_wasm))) {
NN_ERR_PRINTF("builder_array_wasm is invalid");
return invalid_argument;
}
@ -37,15 +39,15 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
builder_array_wasm->size);
if (!wasm_runtime_validate_app_addr(
instance, builder_array_wasm->buf_offset,
builder_array_wasm->size * sizeof(graph_builder_wasm))) {
instance, (uint64)builder_array_wasm->buf_offset,
(uint64)builder_array_wasm->size * sizeof(graph_builder_wasm))) {
NN_ERR_PRINTF("builder_array_wasm->buf_offset is invalid");
return invalid_argument;
}
graph_builder_wasm *builder_wasm =
(graph_builder_wasm *)wasm_runtime_addr_app_to_native(
instance, builder_array_wasm->buf_offset);
instance, (uint64)builder_array_wasm->buf_offset);
graph_builder *builder = (graph_builder *)wasm_runtime_malloc(
builder_array_wasm->size * sizeof(graph_builder));
@ -74,13 +76,14 @@ static error
tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
tensor_wasm *input_tensor_wasm, tensor_data *data)
{
if (!wasm_runtime_validate_app_addr(
instance, input_tensor_wasm->data_offset, total_elements)) {
if (!wasm_runtime_validate_app_addr(instance,
(uint64)input_tensor_wasm->data_offset,
(uint64)total_elements)) {
NN_ERR_PRINTF("input_tensor_wasm->data_offset is invalid");
return invalid_argument;
}
*data = (tensor_data)wasm_runtime_addr_app_to_native(
instance, input_tensor_wasm->data_offset);
instance, (uint64)input_tensor_wasm->data_offset);
return success;
}
@ -89,19 +92,20 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
tensor_wasm *input_tensor_wasm,
tensor_dimensions **dimensions)
{
if (!wasm_runtime_validate_app_addr(instance,
input_tensor_wasm->dimensions_offset,
sizeof(tensor_dimensions_wasm))) {
if (!wasm_runtime_validate_app_addr(
instance, (uint64)input_tensor_wasm->dimensions_offset,
(uint64)sizeof(tensor_dimensions_wasm))) {
NN_ERR_PRINTF("input_tensor_wasm->dimensions_offset is invalid");
return invalid_argument;
}
tensor_dimensions_wasm *dimensions_wasm =
(tensor_dimensions_wasm *)wasm_runtime_addr_app_to_native(
instance, input_tensor_wasm->dimensions_offset);
instance, (uint64)input_tensor_wasm->dimensions_offset);
if (!wasm_runtime_validate_app_addr(instance, dimensions_wasm->buf_offset,
sizeof(tensor_dimensions))) {
if (!wasm_runtime_validate_app_addr(instance,
(uint64)dimensions_wasm->buf_offset,
(uint64)sizeof(tensor_dimensions))) {
NN_ERR_PRINTF("dimensions_wasm->buf_offset is invalid");
return invalid_argument;
}
@ -113,7 +117,7 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
(*dimensions)->size = dimensions_wasm->size;
(*dimensions)->buf = (uint32_t *)wasm_runtime_addr_app_to_native(
instance, dimensions_wasm->buf_offset);
instance, (uint64)dimensions_wasm->buf_offset);
NN_DBG_PRINTF("Number of dimensions: %d", (*dimensions)->size);
return success;
@ -125,7 +129,7 @@ tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
{
NN_DBG_PRINTF("Converting tensor_wasm to tensor");
if (!wasm_runtime_validate_native_addr(instance, input_tensor_wasm,
sizeof(tensor_wasm))) {
(uint64)sizeof(tensor_wasm))) {
NN_ERR_PRINTF("input_tensor_wasm is invalid");
return invalid_argument;
}

View File

@ -211,7 +211,8 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
&builder_native)))
return res;
if (!wasm_runtime_validate_native_addr(instance, g, sizeof(graph))) {
if (!wasm_runtime_validate_native_addr(instance, g,
(uint64)sizeof(graph))) {
NN_ERR_PRINTF("graph is invalid");
res = invalid_argument;
goto fail;
@ -248,8 +249,8 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g,
if (success != (res = is_model_initialized(wasi_nn_ctx)))
return res;
if (!wasm_runtime_validate_native_addr(instance, ctx,
sizeof(graph_execution_context))) {
if (!wasm_runtime_validate_native_addr(
instance, ctx, (uint64)sizeof(graph_execution_context))) {
NN_ERR_PRINTF("ctx is invalid");
return invalid_argument;
}
@ -331,7 +332,7 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
return res;
if (!wasm_runtime_validate_native_addr(instance, output_tensor_size,
sizeof(uint32_t))) {
(uint64)sizeof(uint32_t))) {
NN_ERR_PRINTF("output_tensor_size is invalid");
return invalid_argument;
}