Change wasm app offset type from int32 to uint32 (#361)
And fix some sign/unsigned conversion compilation warnings.
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user