Enable WASI feature, enhance security and add SGX sample (#142)
Change emcc to clang Refine interpreter to improve perforamnce
This commit is contained in:
@ -45,7 +45,7 @@ void bh_memory_destroy();
|
||||
* Get the pool size of memory, if memory is initialized with allocator,
|
||||
* return 1GB by default.
|
||||
*/
|
||||
int bh_memory_pool_size();
|
||||
unsigned bh_memory_pool_size();
|
||||
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING == 0
|
||||
|
||||
|
||||
@ -110,6 +110,15 @@ wasm_runtime_load_from_sections(wasm_section_list_t section_list,
|
||||
void
|
||||
wasm_runtime_unload(wasm_module_t module);
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
void
|
||||
wasm_runtime_set_wasi_args(wasm_module_t module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env[], uint32 env_count,
|
||||
char *argv[], int argc);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Instantiate a WASM module.
|
||||
*
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "wasm_log.h"
|
||||
#include "wasm_memory.h"
|
||||
#include "wasm_platform_log.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
@ -91,7 +92,7 @@ __syscall3_wrapper(WASMModuleInstance *module_inst,
|
||||
uint32 iov_len;
|
||||
} *vec;
|
||||
int32 vec_offset = arg2, str_offset;
|
||||
uint32 iov_count = arg3, i;
|
||||
uint32 iov_count = (uint32)arg3, i;
|
||||
int32 count = 0;
|
||||
char *iov_base, *str;
|
||||
|
||||
@ -110,7 +111,7 @@ __syscall3_wrapper(WASMModuleInstance *module_inst,
|
||||
|
||||
str = addr_app_to_native(str_offset);
|
||||
|
||||
memcpy(str, iov_base, vec->iov_len);
|
||||
bh_memcpy_s(str, vec->iov_len + 1, iov_base, vec->iov_len);
|
||||
str[vec->iov_len] = '\0';
|
||||
count += wasm_printf("%s", str);
|
||||
|
||||
@ -219,7 +220,7 @@ EMCC_SYSCALL_WRAPPER3(221)
|
||||
|
||||
EMCC_SYSCALL_WRAPPER5(140)
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
getTotalMemory_wrapper(WASMModuleInstance *module_inst)
|
||||
{
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199309L)
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE)
|
||||
|
||||
set (PLATFORM_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "wasm_log.h"
|
||||
#include "wasm_memory.h"
|
||||
#include "wasm_platform_log.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
@ -92,7 +93,7 @@ __syscall3_wrapper(WASMModuleInstance *module_inst,
|
||||
return 0;
|
||||
|
||||
wsz = (struct winsize*)addr_app_to_native(arg3);
|
||||
return syscall(54, arg1, arg2, wsz);
|
||||
return (int32)syscall(54, arg1, arg2, wsz);
|
||||
}
|
||||
|
||||
case 146: /* writev */
|
||||
@ -104,7 +105,7 @@ __syscall3_wrapper(WASMModuleInstance *module_inst,
|
||||
uint32 iov_len;
|
||||
} *vec;
|
||||
int32 vec_offset = arg2, str_offset;
|
||||
uint32 iov_count = arg3, i;
|
||||
uint32 iov_count = (uint32)arg3, i;
|
||||
int32 count = 0;
|
||||
char *iov_base, *str;
|
||||
|
||||
@ -123,7 +124,7 @@ __syscall3_wrapper(WASMModuleInstance *module_inst,
|
||||
|
||||
str = addr_app_to_native(str_offset);
|
||||
|
||||
memcpy(str, iov_base, vec->iov_len);
|
||||
bh_memcpy_s(str, vec->iov_len + 1, iov_base, vec->iov_len);
|
||||
str[vec->iov_len] = '\0';
|
||||
count += wasm_printf("%s", str);
|
||||
|
||||
@ -232,7 +233,7 @@ EMCC_SYSCALL_WRAPPER3(221)
|
||||
|
||||
EMCC_SYSCALL_WRAPPER5(140)
|
||||
|
||||
static int32
|
||||
static uint32
|
||||
getTotalMemory_wrapper(WASMModuleInstance *module_inst)
|
||||
{
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199309L)
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE)
|
||||
|
||||
set (PLATFORM_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
|
||||
14
core/iwasm/runtime/platform/zephyr/platform.cmake
Normal file
14
core/iwasm/runtime/platform/zephyr/platform.cmake
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE)
|
||||
|
||||
set (PLATFORM_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${PLATFORM_LIB_DIR})
|
||||
include_directories(${PLATFORM_LIB_DIR}/../include)
|
||||
|
||||
file (GLOB_RECURSE source_all ${PLATFORM_LIB_DIR}/*.c)
|
||||
|
||||
set (WASM_PLATFORM_LIB_SOURCE ${source_all})
|
||||
|
||||
@ -37,7 +37,7 @@ wasm_hash_map_create(uint32 size, bool use_lock,
|
||||
ValueDestroyFunc value_destroy_func)
|
||||
{
|
||||
HashMap *map;
|
||||
uint32 total_size;
|
||||
uint64 total_size;
|
||||
|
||||
if (size > HASH_MAP_MAX_SIZE) {
|
||||
LOG_ERROR("HashMap create failed: size is too large.\n");
|
||||
@ -51,19 +51,21 @@ wasm_hash_map_create(uint32 size, bool use_lock,
|
||||
}
|
||||
|
||||
total_size = offsetof(HashMap, elements) +
|
||||
sizeof(HashMapElem) * size +
|
||||
sizeof(HashMapElem) * (uint64)size +
|
||||
(use_lock ? sizeof(korp_mutex) : 0);
|
||||
|
||||
if (!(map = wasm_malloc(total_size))) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(map = wasm_malloc((uint32)total_size))) {
|
||||
LOG_ERROR("HashMap create failed: alloc memory failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(map, 0, total_size);
|
||||
memset(map, 0, (uint32)total_size);
|
||||
|
||||
if (use_lock) {
|
||||
map->lock = (korp_mutex*)
|
||||
((uint8*)map + offsetof(HashMap, elements) + sizeof(HashMapElem) * size);
|
||||
((uint8*)map + offsetof(HashMap, elements)
|
||||
+ sizeof(HashMapElem) * size);
|
||||
if (ws_mutex_init(map->lock, false)) {
|
||||
LOG_ERROR("HashMap create failed: init map lock failed.\n");
|
||||
wasm_free(map);
|
||||
|
||||
@ -217,6 +217,19 @@ typedef struct BlockAddr {
|
||||
#define BLOCK_ADDR_CACHE_SIZE 64
|
||||
#define BLOCK_ADDR_CONFLICT_SIZE 4
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
typedef struct WASIArguments {
|
||||
const char **dir_list;
|
||||
uint32 dir_count;
|
||||
const char **map_dir_list;
|
||||
uint32 map_dir_count;
|
||||
const char **env;
|
||||
uint32 env_count;
|
||||
const char **argv;
|
||||
uint32 argc;
|
||||
} WASIArguments;
|
||||
#endif
|
||||
|
||||
typedef struct WASMModule {
|
||||
uint32 type_count;
|
||||
uint32 import_count;
|
||||
@ -255,16 +268,19 @@ typedef struct WASMModule {
|
||||
#else
|
||||
BlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
WASIArguments wasi_args;
|
||||
bool is_wasi_module;
|
||||
#endif
|
||||
} WASMModule;
|
||||
|
||||
typedef struct WASMBranchBlock {
|
||||
uint8 block_type;
|
||||
uint8 return_type;
|
||||
uint8 *start_addr;
|
||||
uint8 *else_addr;
|
||||
uint8 *end_addr;
|
||||
uint32 *frame_sp;
|
||||
uint8 *frame_ref;
|
||||
} WASMBranchBlock;
|
||||
|
||||
typedef struct WASMSection {
|
||||
@ -299,7 +315,7 @@ align_uint (unsigned v, unsigned b)
|
||||
inline static uint32
|
||||
wasm_string_hash(const char *str)
|
||||
{
|
||||
unsigned h = strlen(str);
|
||||
unsigned h = (unsigned)strlen(str);
|
||||
const uint8 *p = (uint8*)str;
|
||||
const uint8 *end = p + h;
|
||||
|
||||
@ -356,11 +372,11 @@ wasm_value_type_cell_num(uint8 value_type)
|
||||
inline static uint16
|
||||
wasm_get_cell_num(const uint8 *types, uint32 type_count)
|
||||
{
|
||||
uint16 cell_num = 0;
|
||||
uint32 cell_num = 0;
|
||||
uint32 i;
|
||||
for (i = 0; i < type_count; i++)
|
||||
cell_num += wasm_value_type_cell_num(types[i]);
|
||||
return cell_num;
|
||||
return (uint16)cell_num;
|
||||
}
|
||||
|
||||
inline static uint16
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "wasm_log.h"
|
||||
#include "wasm_memory.h"
|
||||
#include "wasm_platform_log.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
|
||||
static WASMFunctionInstance*
|
||||
@ -55,17 +56,55 @@ check_main_func_type(const WASMType *type)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
static WASMFunctionInstance *
|
||||
lookup_wasi_start_function(WASMModuleInstance *module_inst)
|
||||
{
|
||||
WASMFunctionInstance *func = NULL;
|
||||
uint32 i;
|
||||
for (i = 0; i < module_inst->export_func_count; i++) {
|
||||
if (!strcmp(module_inst->export_functions[i].name, "_start")) {
|
||||
func = module_inst->export_functions[i].function;
|
||||
if (func->u.func->func_type->param_count != 0
|
||||
|| func->u.func->func_type->result_count != 0) {
|
||||
LOG_ERROR("Lookup wasi _start function failed: "
|
||||
"invalid function type.\n");
|
||||
return NULL;
|
||||
}
|
||||
return func;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
wasm_application_execute_main(WASMModuleInstance *module_inst,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
WASMFunctionInstance *func = resolve_main_function(module_inst);
|
||||
WASMFunctionInstance *func;
|
||||
uint32 argc1 = 0, argv1[2] = { 0 };
|
||||
uint32 total_argv_size = 0, total_size;
|
||||
uint32 total_argv_size = 0;
|
||||
uint64 total_size;
|
||||
int32 argv_buf_offset, i;
|
||||
char *argv_buf, *p;
|
||||
char *argv_buf, *p, *p_end;
|
||||
int32 *argv_offsets;
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
if (module_inst->module->is_wasi_module) {
|
||||
/* In wasi mode, we should call function named "_start"
|
||||
which initializes the wasi envrionment and then calls
|
||||
the actual main function. Directly call main function
|
||||
may cause exception thrown. */
|
||||
if ((func = lookup_wasi_start_function(module_inst)))
|
||||
return wasm_runtime_call_wasm(module_inst, NULL,
|
||||
func, 0, NULL);
|
||||
/* if no start function is found, we execute
|
||||
the main function as normal */
|
||||
}
|
||||
#endif
|
||||
|
||||
func = resolve_main_function(module_inst);
|
||||
if (!func || func->is_import_func)
|
||||
return false;
|
||||
|
||||
@ -74,25 +113,28 @@ wasm_application_execute_main(WASMModuleInstance *module_inst,
|
||||
|
||||
if (func->u.func->func_type->param_count) {
|
||||
for (i = 0; i < argc; i++)
|
||||
total_argv_size += strlen(argv[i]) + 1;
|
||||
total_argv_size += (uint32)(strlen(argv[i]) + 1);
|
||||
total_argv_size = align_uint(total_argv_size, 4);
|
||||
|
||||
total_size = total_argv_size + sizeof(int32) * argc;
|
||||
total_size = (uint64)total_argv_size + sizeof(int32) * (uint64)argc;
|
||||
|
||||
if (!(argv_buf_offset = wasm_runtime_module_malloc(module_inst, total_size)))
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(argv_buf_offset =
|
||||
wasm_runtime_module_malloc(module_inst, (uint32)total_size)))
|
||||
return false;
|
||||
|
||||
argv_buf = p = wasm_runtime_addr_app_to_native(module_inst, argv_buf_offset);
|
||||
argv_offsets = (int32*)(p + total_argv_size);
|
||||
p_end = p + total_size;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
memcpy(p, argv[i], strlen(argv[i]) + 1);
|
||||
argv_offsets[i] = argv_buf_offset + (p - argv_buf);
|
||||
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);
|
||||
p += strlen(argv[i]) + 1;
|
||||
}
|
||||
|
||||
argc1 = 2;
|
||||
argv1[0] = argc;
|
||||
argv1[0] = (uint32)argc;
|
||||
argv1[1] = (uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
|
||||
}
|
||||
|
||||
@ -165,6 +207,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
WASMType *type;
|
||||
uint32 argc1, *argv1;
|
||||
int32 i, p;
|
||||
uint64 total_size;
|
||||
const char *exception;
|
||||
|
||||
wasm_assert(argc >= 0);
|
||||
@ -181,15 +224,16 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
}
|
||||
|
||||
argc1 = func->param_cell_num;
|
||||
argv1 = wasm_malloc(sizeof(uint32) * (argc1 > 2 ? argc1 : 2));
|
||||
if (argv1 == NULL) {
|
||||
total_size = sizeof(uint32) * (uint64)(argc1 > 2 ? argc1 : 2);
|
||||
if (total_size >= UINT32_MAX
|
||||
|| (!(argv1 = wasm_malloc((uint32)total_size)))) {
|
||||
LOG_ERROR("Wasm prepare param failed: malloc failed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Parse arguments */
|
||||
for (i = 0, p = 0; i < argc; i++) {
|
||||
char *endptr;
|
||||
char *endptr = NULL;
|
||||
wasm_assert(argv[i] != NULL);
|
||||
if (argv[i][0] == '\0') {
|
||||
LOG_ERROR("Wasm prepare param failed: invalid num (%s).\n", argv[i]);
|
||||
@ -197,7 +241,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
}
|
||||
switch (type->types[i]) {
|
||||
case VALUE_TYPE_I32:
|
||||
argv1[p++] = strtoul(argv[i], &endptr, 0);
|
||||
argv1[p++] = (uint32)strtoul(argv[i], &endptr, 0);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
{
|
||||
@ -217,7 +261,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
if (endptr[0] == ':') {
|
||||
uint32 sig;
|
||||
union ieee754_float u;
|
||||
sig = strtoul(endptr + 1, &endptr, 0);
|
||||
sig = (uint32)strtoul(endptr + 1, &endptr, 0);
|
||||
u.f = f32;
|
||||
if (is_little_endian())
|
||||
u.ieee.ieee_little_endian.mantissa = sig;
|
||||
@ -244,11 +288,11 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
ud.d = u.val;
|
||||
if (is_little_endian()) {
|
||||
ud.ieee.ieee_little_endian.mantissa0 = sig >> 32;
|
||||
ud.ieee.ieee_little_endian.mantissa1 = sig;
|
||||
ud.ieee.ieee_little_endian.mantissa1 = (uint32)sig;
|
||||
}
|
||||
else {
|
||||
ud.ieee.ieee_big_endian.mantissa0 = sig >> 32;
|
||||
ud.ieee.ieee_big_endian.mantissa1 = sig;
|
||||
ud.ieee.ieee_big_endian.mantissa1 = (uint32)sig;
|
||||
}
|
||||
u.val = ud.d;
|
||||
}
|
||||
@ -258,7 +302,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*endptr != '\0' && *endptr != '_') {
|
||||
if (endptr && *endptr != '\0' && *endptr != '_') {
|
||||
LOG_ERROR("Wasm prepare param failed: invalid num (%s).\n", argv[i]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ typedef float64 CellType_F64;
|
||||
#else /* WASM_CPU_SUPPORTS_UNALIGNED_64BIT_ACCESS != 0 */
|
||||
#define PUT_I64_TO_ADDR(addr, value) do { \
|
||||
union { int64 val; uint32 parts[2]; } u; \
|
||||
u.val = (value); \
|
||||
u.val = (int64)(value); \
|
||||
(addr)[0] = u.parts[0]; \
|
||||
(addr)[1] = u.parts[1]; \
|
||||
} while (0)
|
||||
@ -110,36 +110,36 @@ GET_F64_FROM_ADDR (uint32 *addr)
|
||||
} while (0)
|
||||
|
||||
static inline uint32
|
||||
rotl32(uint32 n, unsigned int c)
|
||||
rotl32(uint32 n, uint32 c)
|
||||
{
|
||||
const unsigned int mask = (31);
|
||||
const uint32 mask = (31);
|
||||
c = c % 32;
|
||||
c &= mask;
|
||||
return (n<<c) | (n>>( (-c)&mask ));
|
||||
}
|
||||
|
||||
static inline uint32
|
||||
rotr32(uint32 n, unsigned int c)
|
||||
rotr32(uint32 n, uint32 c)
|
||||
{
|
||||
const unsigned int mask = (31);
|
||||
const uint32 mask = (31);
|
||||
c = c % 32;
|
||||
c &= mask;
|
||||
return (n>>c) | (n<<( (-c)&mask ));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
rotl64(uint64 n, unsigned int c)
|
||||
rotl64(uint64 n, uint64 c)
|
||||
{
|
||||
const unsigned int mask = (63);
|
||||
const uint64 mask = (63);
|
||||
c = c % 64;
|
||||
c &= mask;
|
||||
return (n<<c) | (n>>( (-c)&mask ));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
rotr64(uint64 n, unsigned int c)
|
||||
rotr64(uint64 n, uint64 c)
|
||||
{
|
||||
const unsigned int mask = (63);
|
||||
const uint64 mask = (63);
|
||||
c = c % 64;
|
||||
c &= mask;
|
||||
return (n>>c) | (n<<( (-c)&mask ));
|
||||
@ -237,21 +237,6 @@ popcount64(uint64 u)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline WASMGlobalInstance*
|
||||
get_global(const WASMModuleInstance *module, uint32 global_idx)
|
||||
{
|
||||
if (global_idx >= module->global_count)
|
||||
return NULL;
|
||||
|
||||
return module->globals + global_idx;
|
||||
}
|
||||
|
||||
static inline uint8*
|
||||
get_global_addr(WASMMemoryInstance *memory, WASMGlobalInstance *global)
|
||||
{
|
||||
return memory->global_data + global->data_offset;
|
||||
}
|
||||
|
||||
static uint64
|
||||
read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
{
|
||||
@ -300,7 +285,6 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
frame_csp->block_type = type; \
|
||||
frame_csp->return_type = ret_type; \
|
||||
frame_csp->start_addr = start; \
|
||||
frame_csp->else_addr = else_; \
|
||||
frame_csp->end_addr = end; \
|
||||
frame_csp->frame_sp = frame_sp; \
|
||||
frame_csp++; \
|
||||
@ -315,7 +299,7 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
#define POP_F64() (frame_sp -= 2, GET_F64_FROM_ADDR(frame_sp))
|
||||
|
||||
#define POP_CSP_CHECK_OVERFLOW(n) do { \
|
||||
wasm_assert(frame_csp - n >= frame->csp_bottom); \
|
||||
wasm_assert(frame_csp - n >= frame->csp_bottom); \
|
||||
} while (0)
|
||||
|
||||
#define POP_CSP() do { \
|
||||
@ -355,28 +339,28 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
#define LOCAL_I32(n) (*(int32*)(local_off(n)))
|
||||
|
||||
#define SET_LOCAL_I32(N, val) do { \
|
||||
int n = (N); \
|
||||
uint32 n = (N); \
|
||||
*(int32*)(local_off(n)) = (int32)(val); \
|
||||
} while (0)
|
||||
|
||||
#define LOCAL_F32(n) (*(float32*)(local_off(n)))
|
||||
|
||||
#define SET_LOCAL_F32(N, val) do { \
|
||||
int n = (N); \
|
||||
uint32 n = (N); \
|
||||
*(float32*)(local_off(n)) = (float32)(val); \
|
||||
} while (0)
|
||||
|
||||
#define LOCAL_I64(n) (GET_I64_FROM_ADDR(local_off(n)))
|
||||
|
||||
#define SET_LOCAL_I64(N, val) do { \
|
||||
int n = (N); \
|
||||
uint32 n = (N); \
|
||||
PUT_I64_TO_ADDR(local_off(n), val); \
|
||||
} while (0)
|
||||
|
||||
#define LOCAL_F64(n) (GET_F64_FROM_ADDR(local_off(n)))
|
||||
|
||||
#define SET_LOCAL_F64(N, val) do { \
|
||||
int n = (N); \
|
||||
uint32 n = (N); \
|
||||
PUT_F64_TO_ADDR(local_off(n), val); \
|
||||
} while (0)
|
||||
|
||||
@ -428,15 +412,15 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
p += _off; \
|
||||
} while (0)
|
||||
|
||||
#define RECOVER_CONTEXT(new_frame) do { \
|
||||
frame = (new_frame); \
|
||||
cur_func = frame->function; \
|
||||
prev_frame = frame->prev_frame; \
|
||||
frame_ip = frame->ip; \
|
||||
frame_ip_end = wasm_runtime_get_func_code_end(cur_func); \
|
||||
frame_lp = frame->lp; \
|
||||
frame_sp = frame->sp; \
|
||||
frame_csp = frame->csp; \
|
||||
#define RECOVER_CONTEXT(new_frame) do { \
|
||||
frame = (new_frame); \
|
||||
cur_func = frame->function; \
|
||||
prev_frame = frame->prev_frame; \
|
||||
frame_ip = frame->ip; \
|
||||
frame_ip_end = wasm_runtime_get_func_code_end(cur_func); \
|
||||
frame_lp = frame->lp; \
|
||||
frame_sp = frame->sp; \
|
||||
frame_csp = frame->csp; \
|
||||
} while (0)
|
||||
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
@ -445,56 +429,56 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
#define GET_OPCODE() (void)0
|
||||
#endif
|
||||
|
||||
#define DEF_OP_LOAD(operation) do { \
|
||||
uint32 offset, flags, addr; \
|
||||
GET_OPCODE(); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset); \
|
||||
addr = POP_I32(); \
|
||||
CHECK_MEMORY_OVERFLOW(); \
|
||||
operation; \
|
||||
(void)flags; \
|
||||
#define DEF_OP_LOAD(operation) do { \
|
||||
uint32 offset, flags, addr; \
|
||||
GET_OPCODE(); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset); \
|
||||
addr = POP_I32(); \
|
||||
CHECK_MEMORY_OVERFLOW(); \
|
||||
operation; \
|
||||
(void)flags; \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_STORE(sval_type, sval_op_type, operation) do { \
|
||||
uint32 offset, flags, addr; \
|
||||
sval_type sval; \
|
||||
GET_OPCODE(); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset); \
|
||||
sval = POP_##sval_op_type(); \
|
||||
addr = POP_I32(); \
|
||||
CHECK_MEMORY_OVERFLOW(); \
|
||||
operation; \
|
||||
(void)flags; \
|
||||
#define DEF_OP_STORE(sval_type, sval_op_type, operation) do { \
|
||||
uint32 offset, flags, addr; \
|
||||
sval_type sval; \
|
||||
GET_OPCODE(); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags); \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset); \
|
||||
sval = POP_##sval_op_type(); \
|
||||
addr = POP_I32(); \
|
||||
CHECK_MEMORY_OVERFLOW(); \
|
||||
operation; \
|
||||
(void)flags; \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_I_CONST(ctype, src_op_type) do { \
|
||||
ctype cval; \
|
||||
read_leb_##ctype(frame_ip, frame_ip_end, cval); \
|
||||
PUSH_##src_op_type(cval); \
|
||||
#define DEF_OP_I_CONST(ctype, src_op_type) do { \
|
||||
ctype cval; \
|
||||
read_leb_##ctype(frame_ip, frame_ip_end, cval); \
|
||||
PUSH_##src_op_type(cval); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_EQZ(src_op_type) do { \
|
||||
uint32 val; \
|
||||
val = POP_##src_op_type() == 0; \
|
||||
PUSH_I32(val); \
|
||||
#define DEF_OP_EQZ(src_op_type) do { \
|
||||
int32 val; \
|
||||
val = POP_##src_op_type() == 0; \
|
||||
PUSH_I32(val); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_CMP(src_type, src_op_type, cond) do { \
|
||||
uint32 res; \
|
||||
src_type val1, val2; \
|
||||
val2 = POP_##src_op_type(); \
|
||||
val1 = POP_##src_op_type(); \
|
||||
res = val1 cond val2; \
|
||||
PUSH_I32(res); \
|
||||
#define DEF_OP_CMP(src_type, src_op_type, cond) do { \
|
||||
uint32 res; \
|
||||
src_type val1, val2; \
|
||||
val2 = (src_type)POP_##src_op_type(); \
|
||||
val1 = (src_type)POP_##src_op_type(); \
|
||||
res = val1 cond val2; \
|
||||
PUSH_I32(res); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_BIT_COUNT(src_type, src_op_type, operation) do { \
|
||||
src_type val1, val2; \
|
||||
val1 = POP_##src_op_type(); \
|
||||
val2 = operation(val1); \
|
||||
PUSH_##src_op_type(val2); \
|
||||
#define DEF_OP_BIT_COUNT(src_type, src_op_type, operation) do { \
|
||||
src_type val1, val2; \
|
||||
val1 = (src_type)POP_##src_op_type(); \
|
||||
val2 = (src_type)operation(val1); \
|
||||
PUSH_##src_op_type(val2); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_NUMERIC(src_type1, src_type2, src_op_type, operation) do { \
|
||||
@ -503,50 +487,48 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
||||
*(src_type2*)(frame_sp); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_MATH(src_type, src_op_type, method) do { \
|
||||
src_type val; \
|
||||
val = POP_##src_op_type(); \
|
||||
PUSH_##src_op_type(method(val)); \
|
||||
#define DEF_OP_MATH(src_type, src_op_type, method) do { \
|
||||
src_type val; \
|
||||
val = POP_##src_op_type(); \
|
||||
PUSH_##src_op_type(method(val)); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_TRUNC(dst_type, dst_op_type, src_type, src_op_type, \
|
||||
min_cond, max_cond) do { \
|
||||
src_type value = POP_##src_op_type(); \
|
||||
if (isnan(value)) { \
|
||||
wasm_runtime_set_exception(module, \
|
||||
"invalid conversion to integer"); \
|
||||
goto got_exception; \
|
||||
} \
|
||||
else if (value min_cond || value max_cond) { \
|
||||
wasm_runtime_set_exception(module, "integer overflow"); \
|
||||
goto got_exception; \
|
||||
} \
|
||||
PUSH_##dst_op_type(((dst_type)value)); \
|
||||
#define DEF_OP_TRUNC(dst_type, dst_op_type, src_type, src_op_type, \
|
||||
min_cond, max_cond) do { \
|
||||
src_type value = POP_##src_op_type(); \
|
||||
if (isnan(value)) { \
|
||||
wasm_runtime_set_exception(module, \
|
||||
"invalid conversion to integer"); \
|
||||
goto got_exception; \
|
||||
} \
|
||||
else if (value min_cond || value max_cond) { \
|
||||
wasm_runtime_set_exception(module, "integer overflow"); \
|
||||
goto got_exception; \
|
||||
} \
|
||||
PUSH_##dst_op_type(((dst_type)value)); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_CONVERT(dst_type, dst_op_type, \
|
||||
src_type, src_op_type) do { \
|
||||
dst_type value = (dst_type)(src_type)POP_##src_op_type(); \
|
||||
PUSH_##dst_op_type(value); \
|
||||
#define DEF_OP_CONVERT(dst_type, dst_op_type, \
|
||||
src_type, src_op_type) do { \
|
||||
dst_type value = (dst_type)(src_type)POP_##src_op_type(); \
|
||||
PUSH_##dst_op_type(value); \
|
||||
} while (0)
|
||||
|
||||
#define GET_LOCAL_INDEX_AND_TYPE() do { \
|
||||
param_count = cur_func->u.func->func_type->param_count; \
|
||||
local_count = cur_func->u.func->local_count; \
|
||||
uint32 param_count = cur_func->param_count; \
|
||||
read_leb_uint32(frame_ip, frame_ip_end, local_idx); \
|
||||
wasm_assert(local_idx < param_count + local_count); \
|
||||
wasm_assert(local_idx < param_count + cur_func->local_count); \
|
||||
if (local_idx < param_count) \
|
||||
local_type = cur_func->u.func->func_type->types[local_idx]; \
|
||||
local_type = cur_func->param_types[local_idx]; \
|
||||
else \
|
||||
local_type = \
|
||||
cur_func->u.func->local_types[local_idx - param_count]; \
|
||||
local_type = cur_func->local_types[local_idx - param_count]; \
|
||||
} while (0)
|
||||
|
||||
static inline int32
|
||||
sign_ext_8_32(int8 val)
|
||||
{
|
||||
if (val & 0x80)
|
||||
return val | 0xffffff00;
|
||||
return (int32)val | (int32)0xffffff00;
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -554,7 +536,7 @@ static inline int32
|
||||
sign_ext_16_32(int16 val)
|
||||
{
|
||||
if (val & 0x8000)
|
||||
return val | 0xffff0000;
|
||||
return (int32)val | (int32)0xffff0000;
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -562,7 +544,7 @@ static inline int64
|
||||
sign_ext_8_64(int8 val)
|
||||
{
|
||||
if (val & 0x80)
|
||||
return val | 0xffffffffffffff00;
|
||||
return (int64)val | (int64)0xffffffffffffff00;
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -570,15 +552,15 @@ static inline int64
|
||||
sign_ext_16_64(int16 val)
|
||||
{
|
||||
if (val & 0x8000)
|
||||
return val | 0xffffffffffff0000;
|
||||
return (int64)val | (int64)0xffffffffffff0000;
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline int64
|
||||
sign_ext_32_64(int32 val)
|
||||
{
|
||||
if (val & 0x80000000)
|
||||
return val | 0xffffffff00000000;
|
||||
if (val & (int32)0x80000000)
|
||||
return (int64)val | (int64)0xffffffff00000000;
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -674,10 +656,12 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
WASMMemoryInstance *memory = module->default_memory;
|
||||
uint32 memory_data_size = memory
|
||||
? NumBytesPerPage * memory->cur_page_count : 0;
|
||||
uint32 heap_base_offset = memory ? memory->heap_base_offset : 0;
|
||||
uint32 heap_base_offset = memory ? (uint32)memory->heap_base_offset : 0;
|
||||
uint32 heap_data_size = memory
|
||||
? memory->heap_data_end - memory->heap_data : 0;
|
||||
? (uint32)(memory->heap_data_end - memory->heap_data) : 0;
|
||||
WASMTableInstance *table = module->default_table;
|
||||
WASMGlobalInstance *globals = module->globals;
|
||||
uint8 *global_data = memory ? memory->global_data : NULL;
|
||||
uint8 opcode_IMPDEP2 = WASM_OP_IMPDEP2;
|
||||
WASMInterpFrame *frame = NULL;
|
||||
/* Points to this special opcode so as to jump to the
|
||||
@ -690,10 +674,10 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
uint8 opcode, block_ret_type;
|
||||
uint32 *depths = NULL;
|
||||
uint32 depth_buf[BR_TABLE_TMP_BUF_LEN];
|
||||
uint32 i, depth, cond, count, fidx, tidx, frame_size = 0, all_cell_num = 0;
|
||||
uint32 i, depth, cond, count, fidx, tidx, frame_size = 0;
|
||||
uint64 all_cell_num = 0;
|
||||
int32 didx, val;
|
||||
uint8 *else_addr, *end_addr;
|
||||
uint8 *maddr = NULL;
|
||||
uint8 *else_addr, *end_addr, *maddr = NULL;
|
||||
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
||||
@ -723,7 +707,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
HANDLE_OP_END ();
|
||||
|
||||
HANDLE_OP (WASM_OP_BLOCK):
|
||||
read_leb_uint32(frame_ip, frame_ip_end, block_ret_type);
|
||||
read_leb_uint8(frame_ip, frame_ip_end, block_ret_type);
|
||||
|
||||
if (!wasm_loader_find_block_addr(module->module,
|
||||
frame_ip, frame_ip_end,
|
||||
@ -738,7 +722,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
HANDLE_OP_END ();
|
||||
|
||||
HANDLE_OP (WASM_OP_LOOP):
|
||||
read_leb_uint32(frame_ip, frame_ip_end, block_ret_type);
|
||||
read_leb_uint8(frame_ip, frame_ip_end, block_ret_type);
|
||||
|
||||
if (!wasm_loader_find_block_addr(module->module,
|
||||
frame_ip, frame_ip_end,
|
||||
@ -753,7 +737,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
HANDLE_OP_END ();
|
||||
|
||||
HANDLE_OP (WASM_OP_IF):
|
||||
read_leb_uint32(frame_ip, frame_ip_end, block_ret_type);
|
||||
read_leb_uint8(frame_ip, frame_ip_end, block_ret_type);
|
||||
|
||||
if (!wasm_loader_find_block_addr(module->module,
|
||||
frame_ip, frame_ip_end,
|
||||
@ -764,7 +748,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
cond = POP_I32();
|
||||
cond = (uint32)POP_I32();
|
||||
|
||||
PUSH_CSP(BLOCK_TYPE_IF, block_ret_type, frame_ip, else_addr, end_addr);
|
||||
|
||||
@ -806,7 +790,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
|
||||
HANDLE_OP (WASM_OP_BR_IF):
|
||||
read_leb_uint32(frame_ip, frame_ip_end, depth);
|
||||
cond = POP_I32();
|
||||
cond = (uint32)POP_I32();
|
||||
if (cond)
|
||||
POP_CSP_N(depth);
|
||||
HANDLE_OP_END ();
|
||||
@ -816,7 +800,9 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
if (count <= BR_TABLE_TMP_BUF_LEN)
|
||||
depths = depth_buf;
|
||||
else {
|
||||
if (!(depths = wasm_malloc(sizeof(uint32) * count))) {
|
||||
uint64 total_size = sizeof(uint32) * (uint64)count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(depths = wasm_malloc((uint32)total_size))) {
|
||||
wasm_runtime_set_exception(module,
|
||||
"WASM interp failed: "
|
||||
"allocate memory failed.");
|
||||
@ -916,7 +902,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
|
||||
HANDLE_OP (WASM_OP_SELECT_32):
|
||||
{
|
||||
cond = POP_I32();
|
||||
cond = (uint32)POP_I32();
|
||||
frame_sp--;
|
||||
if (!cond)
|
||||
*(frame_sp - 1) = *frame_sp;
|
||||
@ -925,7 +911,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
|
||||
HANDLE_OP (WASM_OP_SELECT_64):
|
||||
{
|
||||
cond = POP_I32();
|
||||
cond = (uint32)POP_I32();
|
||||
frame_sp -= 2;
|
||||
if (!cond) {
|
||||
*(frame_sp - 2) = *frame_sp;
|
||||
@ -937,7 +923,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
/* variable instructions */
|
||||
HANDLE_OP (WASM_OP_GET_LOCAL):
|
||||
{
|
||||
uint32 local_idx, param_count, local_count;
|
||||
uint32 local_idx;
|
||||
uint8 local_type;
|
||||
|
||||
GET_LOCAL_INDEX_AND_TYPE();
|
||||
@ -960,13 +946,12 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
"invalid local type");
|
||||
goto got_exception;
|
||||
}
|
||||
(void)local_count;
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
|
||||
HANDLE_OP (WASM_OP_SET_LOCAL):
|
||||
{
|
||||
uint32 local_idx, param_count, local_count;
|
||||
uint32 local_idx;
|
||||
uint8 local_type;
|
||||
|
||||
GET_LOCAL_INDEX_AND_TYPE();
|
||||
@ -989,13 +974,12 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
"invalid local type");
|
||||
goto got_exception;
|
||||
}
|
||||
(void)local_count;
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
|
||||
HANDLE_OP (WASM_OP_TEE_LOCAL):
|
||||
{
|
||||
uint32 local_idx, param_count, local_count;
|
||||
uint32 local_idx;
|
||||
uint8 local_type;
|
||||
|
||||
GET_LOCAL_INDEX_AND_TYPE();
|
||||
@ -1017,7 +1001,6 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
wasm_runtime_set_exception(module, "invalid local type");
|
||||
goto got_exception;
|
||||
}
|
||||
(void)local_count;
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
|
||||
@ -1025,24 +1008,26 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
WASMGlobalInstance *global;
|
||||
uint32 global_idx;
|
||||
uint8 *global_addr;
|
||||
|
||||
read_leb_uint32(frame_ip, frame_ip_end, global_idx);
|
||||
|
||||
global = get_global(module, global_idx);
|
||||
wasm_assert(global && global_idx < module->global_count);
|
||||
wasm_assert(global_idx < module->global_count);
|
||||
global = globals + global_idx;
|
||||
global_addr = global_data + global->data_offset;
|
||||
|
||||
switch (global->type) {
|
||||
case VALUE_TYPE_I32:
|
||||
PUSH_I32(*(uint32*)get_global_addr(memory, global));
|
||||
PUSH_I32(*(uint32*)global_addr);
|
||||
break;
|
||||
case VALUE_TYPE_F32:
|
||||
PUSH_F32(*(float32*)get_global_addr(memory, global));
|
||||
PUSH_F32(*(float32*)global_addr);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
PUSH_I64(*(uint64*)get_global_addr(memory, global));
|
||||
PUSH_I64(GET_I64_FROM_ADDR((uint32*)global_addr));
|
||||
break;
|
||||
case VALUE_TYPE_F64:
|
||||
PUSH_F64(*(float64*)get_global_addr(memory, global));
|
||||
PUSH_F64(GET_F64_FROM_ADDR((uint32*)global_addr));
|
||||
break;
|
||||
default:
|
||||
wasm_runtime_set_exception(module, "invalid global type");
|
||||
@ -1059,13 +1044,13 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
|
||||
read_leb_uint32(frame_ip, frame_ip_end, global_idx);
|
||||
|
||||
global = get_global(module, global_idx);
|
||||
wasm_assert(global && global_idx < module->global_count);
|
||||
wasm_assert(global_idx < module->global_count);
|
||||
global = globals + global_idx;
|
||||
global_addr = global_data + global->data_offset;
|
||||
|
||||
global_addr = get_global_addr(memory, global);
|
||||
switch (global->type) {
|
||||
case VALUE_TYPE_I32:
|
||||
*(uint32*)global_addr = POP_I32();
|
||||
*(int32*)global_addr = POP_I32();
|
||||
break;
|
||||
case VALUE_TYPE_F32:
|
||||
*(float32*)global_addr = POP_F32();
|
||||
@ -1103,7 +1088,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
GET_OPCODE();
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags);
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset);
|
||||
addr = POP_I32();
|
||||
addr = (uint32)POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW();
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
static const void *handle_load_table[] = {
|
||||
@ -1184,7 +1169,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags);
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset);
|
||||
frame_sp--;
|
||||
addr = POP_I32();
|
||||
addr = (uint32)POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW();
|
||||
*(uint32*)maddr = frame_sp[1];
|
||||
(void)flags;
|
||||
@ -1198,7 +1183,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags);
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset);
|
||||
frame_sp -= 2;
|
||||
addr = POP_I32();
|
||||
addr = (uint32)POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW();
|
||||
*(uint32*)maddr = frame_sp[1];
|
||||
*((uint32*)maddr + 1) = frame_sp[2];
|
||||
@ -1215,12 +1200,12 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
GET_OPCODE();
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags);
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset);
|
||||
sval = POP_I32();
|
||||
addr = POP_I32();
|
||||
sval = (uint32)POP_I32();
|
||||
addr = (uint32)POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW();
|
||||
switch (opcode) {
|
||||
case WASM_OP_I32_STORE:
|
||||
*(int32*)maddr = sval;
|
||||
*(uint32*)maddr = sval;
|
||||
break;
|
||||
case WASM_OP_I32_STORE8:
|
||||
*(uint8*)maddr = (uint8)sval;
|
||||
@ -1243,8 +1228,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
GET_OPCODE();
|
||||
read_leb_uint32(frame_ip, frame_ip_end, flags);
|
||||
read_leb_uint32(frame_ip, frame_ip_end, offset);
|
||||
sval = POP_I64();
|
||||
addr = POP_I32();
|
||||
sval = (uint64)POP_I64();
|
||||
addr = (uint32)POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW();
|
||||
switch (opcode) {
|
||||
case WASM_OP_I64_STORE:
|
||||
@ -1279,13 +1264,13 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
uint32 reserved, delta, prev_page_count = memory->cur_page_count;
|
||||
|
||||
read_leb_uint32(frame_ip, frame_ip_end, reserved);
|
||||
delta = POP_I32();
|
||||
delta = (uint32)POP_I32();
|
||||
|
||||
if (!wasm_runtime_enlarge_memory(module, delta)) {
|
||||
/* fail to memory.grow, return -1 */
|
||||
PUSH_I32(-1);
|
||||
if (wasm_runtime_get_exception(module)) {
|
||||
printf("%s\n", wasm_runtime_get_exception(module));
|
||||
bh_printf("%s\n", wasm_runtime_get_exception(module));
|
||||
wasm_runtime_set_exception(module, NULL);
|
||||
}
|
||||
}
|
||||
@ -1295,6 +1280,7 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
/* update the memory instance ptr */
|
||||
memory = module->default_memory;
|
||||
memory_data_size = NumBytesPerPage * memory->cur_page_count;
|
||||
global_data = memory->global_data;
|
||||
}
|
||||
|
||||
(void)reserved;
|
||||
@ -1514,8 +1500,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint32 a, b;
|
||||
|
||||
b = POP_I32();
|
||||
a = POP_I32();
|
||||
b = (uint32)POP_I32();
|
||||
a = (uint32)POP_I32();
|
||||
if (b == 0) {
|
||||
wasm_runtime_set_exception(module, "integer divide by zero");
|
||||
goto got_exception;
|
||||
@ -1546,8 +1532,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint32 a, b;
|
||||
|
||||
b = POP_I32();
|
||||
a = POP_I32();
|
||||
b = (uint32)POP_I32();
|
||||
a = (uint32)POP_I32();
|
||||
if (b == 0) {
|
||||
wasm_runtime_set_exception(module, "integer divide by zero");
|
||||
goto got_exception;
|
||||
@ -1584,8 +1570,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint32 a, b;
|
||||
|
||||
b = POP_I32();
|
||||
a = POP_I32();
|
||||
b = (uint32)POP_I32();
|
||||
a = (uint32)POP_I32();
|
||||
PUSH_I32(rotl32(a, b));
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
@ -1594,8 +1580,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint32 a, b;
|
||||
|
||||
b = POP_I32();
|
||||
a = POP_I32();
|
||||
b = (uint32)POP_I32();
|
||||
a = (uint32)POP_I32();
|
||||
PUSH_I32(rotr32(a, b));
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
@ -1647,8 +1633,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint64 a, b;
|
||||
|
||||
b = POP_I64();
|
||||
a = POP_I64();
|
||||
b = (uint64)POP_I64();
|
||||
a = (uint64)POP_I64();
|
||||
if (b == 0) {
|
||||
wasm_runtime_set_exception(module, "integer divide by zero");
|
||||
goto got_exception;
|
||||
@ -1679,8 +1665,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint64 a, b;
|
||||
|
||||
b = POP_I64();
|
||||
a = POP_I64();
|
||||
b = (uint64)POP_I64();
|
||||
a = (uint64)POP_I64();
|
||||
if (b == 0) {
|
||||
wasm_runtime_set_exception(module, "integer divide by zero");
|
||||
goto got_exception;
|
||||
@ -1717,8 +1703,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint64 a, b;
|
||||
|
||||
b = POP_I64();
|
||||
a = POP_I64();
|
||||
b = (uint64)POP_I64();
|
||||
a = (uint64)POP_I64();
|
||||
PUSH_I64(rotl64(a, b));
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
@ -1727,8 +1713,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
{
|
||||
uint64 a, b;
|
||||
|
||||
b = POP_I64();
|
||||
a = POP_I64();
|
||||
b = (uint64)POP_I64();
|
||||
a = (uint64)POP_I64();
|
||||
PUSH_I64(rotr64(a, b));
|
||||
HANDLE_OP_END ();
|
||||
}
|
||||
@ -2092,14 +2078,23 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
goto got_exception;
|
||||
}
|
||||
else {
|
||||
WASMFunction *cur_wasm_func = cur_func->u.func;
|
||||
WASMType *func_type;
|
||||
uint8 ret_type;
|
||||
|
||||
all_cell_num = cur_func->param_cell_num + cur_func->local_cell_num
|
||||
+ cur_func->u.func->max_stack_cell_num
|
||||
+ cur_func->u.func->max_block_num * sizeof(WASMBranchBlock) / 4;
|
||||
frame_size = wasm_interp_interp_frame_size(all_cell_num);
|
||||
func_type = cur_wasm_func->func_type;
|
||||
|
||||
all_cell_num = (uint64)cur_func->param_cell_num
|
||||
+ (uint64)cur_func->local_cell_num
|
||||
+ (uint64)cur_wasm_func->max_stack_cell_num
|
||||
+ ((uint64)cur_wasm_func->max_block_num) * sizeof(WASMBranchBlock) / 4;
|
||||
if (all_cell_num >= UINT32_MAX) {
|
||||
wasm_runtime_set_exception(self->module_inst,
|
||||
"WASM interp failed: stack overflow.");
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
frame_size = wasm_interp_interp_frame_size((uint32)all_cell_num);
|
||||
if (!(frame = ALLOC_FRAME(self, frame_size, prev_frame))) {
|
||||
frame = prev_frame;
|
||||
goto got_exception;
|
||||
@ -2113,19 +2108,18 @@ wasm_interp_call_func_bytecode(WASMThread *self,
|
||||
|
||||
frame_sp = frame->sp_bottom = frame_lp + cur_func->param_cell_num
|
||||
+ cur_func->local_cell_num;
|
||||
frame->sp_boundary = frame->sp_bottom + cur_func->u.func->max_stack_cell_num;
|
||||
frame->sp_boundary = frame->sp_bottom + cur_wasm_func->max_stack_cell_num;
|
||||
|
||||
frame_csp = frame->csp_bottom = (WASMBranchBlock*)frame->sp_boundary;
|
||||
frame->csp_boundary = frame->csp_bottom + cur_func->u.func->max_block_num;
|
||||
frame->csp_boundary = frame->csp_bottom + cur_wasm_func->max_block_num;
|
||||
|
||||
/* Initialize the local varialbes */
|
||||
memset(frame_lp + cur_func->param_cell_num, 0,
|
||||
cur_func->local_cell_num * 4);
|
||||
(uint32)(cur_func->local_cell_num * 4));
|
||||
|
||||
/* Push function block as first block */
|
||||
func_type = cur_func->u.func->func_type;
|
||||
ret_type = func_type->result_count
|
||||
? func_type->types[func_type->param_count]
|
||||
? cur_func->param_types[func_type->param_count]
|
||||
: VALUE_TYPE_VOID;
|
||||
PUSH_CSP(BLOCK_TYPE_FUNCTION, ret_type,
|
||||
frame_ip, NULL, frame_ip_end - 1);
|
||||
|
||||
@ -55,7 +55,8 @@ typedef struct WASMInterpFrame {
|
||||
static inline unsigned
|
||||
wasm_interp_interp_frame_size(unsigned all_cell_num)
|
||||
{
|
||||
return align_uint(offsetof(WASMInterpFrame, lp) + all_cell_num * 5, 4);
|
||||
return align_uint((uint32)offsetof(WASMInterpFrame, lp)
|
||||
+ all_cell_num * 5, 4);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "wasm_log.h"
|
||||
#include "wasm_memory.h"
|
||||
#include "wasm_dlfcn.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
/* Read a value of given type from the address pointed to by the given
|
||||
pointer and increase the pointer to the position just after the
|
||||
@ -108,7 +109,7 @@ read_leb(const uint8 *buf, const uint8 *buf_end,
|
||||
error_buf, error_buf_size)) \
|
||||
return false; \
|
||||
p += off; \
|
||||
res = (uint32)res64; \
|
||||
res = (int32)res64; \
|
||||
} while (0)
|
||||
|
||||
#define read_leb_uint8(p, p_end, res) do { \
|
||||
@ -118,11 +119,11 @@ read_leb(const uint8 *buf, const uint8 *buf_end,
|
||||
error_buf, error_buf_size)) \
|
||||
return false; \
|
||||
p += off; \
|
||||
res = (uint32)res64; \
|
||||
res = (uint8)res64; \
|
||||
} while (0)
|
||||
|
||||
static char*
|
||||
const_str_set_insert(const uint8 *str, int32 len, WASMModule *module,
|
||||
const_str_set_insert(const uint8 *str, uint32 len, WASMModule *module,
|
||||
char* error_buf, uint32 error_buf_size)
|
||||
{
|
||||
HashMap *set = module->const_str_set;
|
||||
@ -135,7 +136,7 @@ const_str_set_insert(const uint8 *str, int32 len, WASMModule *module,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(c_str, str, len);
|
||||
bh_memcpy_s(c_str, len + 1, str, len);
|
||||
c_str[len] = '\0';
|
||||
|
||||
if ((value = wasm_hash_map_find(set, c_str))) {
|
||||
@ -215,6 +216,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end, *p_org;
|
||||
uint32 type_count, param_count, result_count, i, j;
|
||||
uint64 total_size;
|
||||
uint8 flag;
|
||||
WASMType *type;
|
||||
|
||||
@ -222,13 +224,15 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
|
||||
if (type_count) {
|
||||
module->type_count = type_count;
|
||||
if (!(module->types = wasm_malloc(sizeof(WASMType*) * type_count))) {
|
||||
total_size = sizeof(WASMType*) * (uint64)type_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->types = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load type section failed: allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->types, 0, sizeof(WASMType*) * type_count);
|
||||
memset(module->types, 0, (uint32)total_size);
|
||||
|
||||
for (i = 0; i < type_count; i++) {
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
@ -254,8 +258,10 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
CHECK_BUF(p, p_end, result_count);
|
||||
p = p_org;
|
||||
|
||||
if (!(type = module->types[i] = wasm_malloc(offsetof(WASMType, types) +
|
||||
sizeof(uint8) * (param_count + result_count)))) {
|
||||
total_size = offsetof(WASMType, types) +
|
||||
sizeof(uint8) * (uint64)(param_count + result_count);
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(type = module->types[i] = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load type section failed: allocate memory failed.");
|
||||
return false;
|
||||
@ -398,6 +404,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end, *p_old;
|
||||
uint32 import_count, name_len, type_index, i, u32, flags;
|
||||
uint64 total_size;
|
||||
WASMImport *import;
|
||||
WASMImport *import_functions = NULL, *import_tables = NULL;
|
||||
WASMImport *import_memories = NULL, *import_globals = NULL;
|
||||
@ -408,13 +415,15 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
|
||||
if (import_count) {
|
||||
module->import_count = import_count;
|
||||
if (!(module->imports = wasm_malloc(sizeof(WASMImport) * import_count))) {
|
||||
total_size = sizeof(WASMImport) * (uint64)import_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->imports = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load import section failed: allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->imports, 0, sizeof(WASMImport) * import_count);
|
||||
memset(module->imports, 0, (uint32)total_size);
|
||||
|
||||
p_old = p;
|
||||
|
||||
@ -514,6 +523,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
read_leb_uint8(p, p_end, kind);
|
||||
switch (kind) {
|
||||
case IMPORT_KIND_FUNC: /* import function */
|
||||
wasm_assert(import_functions);
|
||||
import = import_functions++;
|
||||
read_leb_uint32(p, p_end, type_index);
|
||||
if (type_index >= module->type_count) {
|
||||
@ -543,6 +553,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
break;
|
||||
|
||||
case IMPORT_KIND_TABLE: /* import table */
|
||||
wasm_assert(import_tables);
|
||||
import = import_tables++;
|
||||
if (!load_table_import(&p, p_end, &import->u.table,
|
||||
error_buf, error_buf_size))
|
||||
@ -554,6 +565,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
break;
|
||||
|
||||
case IMPORT_KIND_MEMORY: /* import memory */
|
||||
wasm_assert(import_memories);
|
||||
import = import_memories++;
|
||||
if (!load_memory_import(&p, p_end, &import->u.memory,
|
||||
error_buf, error_buf_size))
|
||||
@ -565,6 +577,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
break;
|
||||
|
||||
case IMPORT_KIND_GLOBAL: /* import global */
|
||||
wasm_assert(import_globals);
|
||||
import = import_globals++;
|
||||
read_leb_uint8(p, p_end, import->u.global.type);
|
||||
read_leb_uint8(p, p_end, mutable);
|
||||
@ -590,6 +603,16 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
import->u.names.module_name = module_name;
|
||||
import->u.names.field_name = field_name;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
import = module->import_functions;
|
||||
for (i = 0; i < module->import_function_count; i++, import++) {
|
||||
if (!strcmp(import->u.names.module_name, "wasi_unstable")) {
|
||||
module->is_wasi_module = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p != p_end) {
|
||||
@ -613,7 +636,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
const uint8 *p_code = buf_code, *p_code_end, *p_code_save;
|
||||
uint32 func_count, total_size;
|
||||
uint32 func_count;
|
||||
uint64 total_size;
|
||||
uint32 code_count = 0, code_size, type_index, i, j, k, local_type_index;
|
||||
uint32 local_count, local_set_count, sub_local_count;
|
||||
uint8 type;
|
||||
@ -632,13 +656,15 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (func_count) {
|
||||
module->function_count = func_count;
|
||||
if (!(module->functions = wasm_malloc(sizeof(WASMFunction*) * func_count))) {
|
||||
total_size = sizeof(WASMFunction*) * (uint64)func_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->functions = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load function section failed: allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->functions, 0, sizeof(WASMFunction*) * func_count);
|
||||
memset(module->functions, 0, (uint32)total_size);
|
||||
|
||||
for (i = 0; i < func_count; i++) {
|
||||
/* Resolve function type */
|
||||
@ -678,10 +704,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
}
|
||||
|
||||
/* Alloc memory, layout: function structure + local types */
|
||||
code_size = p_code_end - p_code;
|
||||
total_size = sizeof(WASMFunction) + local_count;
|
||||
code_size = (uint32)(p_code_end - p_code);
|
||||
|
||||
if (!(func = module->functions[i] = wasm_malloc(total_size))) {
|
||||
total_size = sizeof(WASMFunction) + (uint64)local_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(func = module->functions[i] = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load function section failed: "
|
||||
"allocate memory failed.");
|
||||
@ -689,7 +716,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
}
|
||||
|
||||
/* Set function type, local count, code size and code body */
|
||||
memset(func, 0, total_size);
|
||||
memset(func, 0, (uint32)total_size);
|
||||
func->func_type = module->types[type_index];
|
||||
func->local_count = local_count;
|
||||
if (local_count > 0)
|
||||
@ -741,6 +768,7 @@ load_table_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 table_count, i;
|
||||
uint64 total_size;
|
||||
WASMTable *table;
|
||||
|
||||
read_leb_uint32(p, p_end, table_count);
|
||||
@ -752,14 +780,16 @@ load_table_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
return false;
|
||||
}
|
||||
module->table_count = table_count;
|
||||
if (!(module->tables = wasm_malloc(sizeof(WASMTable) * table_count))) {
|
||||
total_size = sizeof(WASMTable) * (uint64)table_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->tables = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load table section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->tables, 0, sizeof(WASMTable) * table_count);
|
||||
memset(module->tables, 0, (uint32)total_size);
|
||||
|
||||
/* load each table */
|
||||
table = module->tables;
|
||||
@ -784,6 +814,7 @@ load_memory_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 memory_count, i;
|
||||
uint64 total_size;
|
||||
WASMMemory *memory;
|
||||
|
||||
read_leb_uint32(p, p_end, memory_count);
|
||||
@ -795,14 +826,16 @@ load_memory_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
return false;
|
||||
}
|
||||
module->memory_count = memory_count;
|
||||
if (!(module->memories = wasm_malloc(sizeof(WASMMemory) * memory_count))) {
|
||||
total_size = sizeof(WASMMemory) * (uint64)memory_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->memories = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load memory section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->memories, 0, sizeof(WASMMemory) * memory_count);
|
||||
memset(module->memories, 0, (uint32)total_size);
|
||||
|
||||
/* load each memory */
|
||||
memory = module->memories;
|
||||
@ -827,20 +860,23 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 global_count, i;
|
||||
uint64 total_size;
|
||||
WASMGlobal *global;
|
||||
|
||||
read_leb_uint32(p, p_end, global_count);
|
||||
|
||||
if (global_count) {
|
||||
module->global_count = global_count;
|
||||
if (!(module->globals = wasm_malloc(sizeof(WASMGlobal) * global_count))) {
|
||||
total_size = sizeof(WASMGlobal) * (uint64)global_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->globals = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load global section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->globals, 0, sizeof(WASMGlobal) * global_count);
|
||||
memset(module->globals, 0, (uint32)total_size);
|
||||
|
||||
global = module->globals;
|
||||
|
||||
@ -872,21 +908,24 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 export_count, i, index;
|
||||
uint8 str_len;
|
||||
uint64 total_size;
|
||||
uint32 str_len;
|
||||
WASMExport *export;
|
||||
|
||||
read_leb_uint32(p, p_end, export_count);
|
||||
|
||||
if (export_count) {
|
||||
module->export_count = export_count;
|
||||
if (!(module->exports = wasm_malloc(sizeof(WASMExport) * export_count))) {
|
||||
total_size = sizeof(WASMExport) * (uint64)export_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->exports = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load export section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->exports, 0, sizeof(WASMExport) * export_count);
|
||||
memset(module->exports, 0, (uint32)total_size);
|
||||
|
||||
export = module->exports;
|
||||
for (i = 0; i < export_count; i++, export++) {
|
||||
@ -965,21 +1004,23 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 table_segment_count, i, j, table_index, function_count, function_index;
|
||||
uint64 total_size;
|
||||
WASMTableSeg *table_segment;
|
||||
|
||||
read_leb_uint32(p, p_end, table_segment_count);
|
||||
|
||||
if (table_segment_count) {
|
||||
module->table_seg_count = table_segment_count;
|
||||
if (!(module->table_segments = wasm_malloc
|
||||
(sizeof(WASMTableSeg) * table_segment_count))) {
|
||||
total_size = sizeof(WASMTableSeg) * (uint64)table_segment_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->table_segments = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load table segment section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->table_segments, 0, sizeof(WASMTableSeg) * table_segment_count);
|
||||
memset(module->table_segments, 0, (uint32)total_size);
|
||||
|
||||
table_segment = module->table_segments;
|
||||
for (i = 0; i < table_segment_count; i++, table_segment++) {
|
||||
@ -993,8 +1034,10 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
|
||||
|
||||
read_leb_uint32(p, p_end, function_count);
|
||||
table_segment->function_count = function_count;
|
||||
if (!(table_segment->func_indexes = (uint32 *)
|
||||
wasm_malloc(sizeof(uint32) * function_count))) {
|
||||
total_size = sizeof(uint32) * (uint64)function_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(table_segment->func_indexes = (uint32 *)
|
||||
wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load table segment section failed: "
|
||||
"allocate memory failed.");
|
||||
@ -1025,6 +1068,7 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
||||
{
|
||||
const uint8 *p = buf, *p_end = buf_end;
|
||||
uint32 data_seg_count, i, mem_index, data_seg_len;
|
||||
uint64 total_size;
|
||||
WASMDataSeg *dataseg;
|
||||
InitializerExpression init_expr;
|
||||
|
||||
@ -1032,15 +1076,16 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (data_seg_count) {
|
||||
module->data_seg_count = data_seg_count;
|
||||
if (!(module->data_segments =
|
||||
wasm_malloc(sizeof(WASMDataSeg*) * data_seg_count))) {
|
||||
total_size = sizeof(WASMDataSeg*) * (uint64)data_seg_count;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(module->data_segments = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load data segment section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(module->data_segments, 0, sizeof(WASMDataSeg*) * data_seg_count);
|
||||
memset(module->data_segments, 0, (uint32)total_size);
|
||||
|
||||
for (i = 0; i < data_seg_count; i++) {
|
||||
read_leb_uint32(p, p_end, mem_index);
|
||||
@ -1051,14 +1096,15 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
||||
read_leb_uint32(p, p_end, data_seg_len);
|
||||
|
||||
if (!(dataseg = module->data_segments[i] =
|
||||
wasm_malloc(sizeof(WASMDataSeg)))) {
|
||||
wasm_malloc((uint32)sizeof(WASMDataSeg)))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Load data segment section failed: "
|
||||
"allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&dataseg->base_offset, &init_expr, sizeof(init_expr));
|
||||
bh_memcpy_s(&dataseg->base_offset, sizeof(InitializerExpression),
|
||||
&init_expr, sizeof(InitializerExpression));
|
||||
|
||||
dataseg->memory_index = mem_index;
|
||||
dataseg->data_length = data_seg_len;
|
||||
@ -1343,6 +1389,8 @@ create_sections(const uint8 *buf, uint32 size,
|
||||
uint8 section_type;
|
||||
uint32 section_size;
|
||||
|
||||
wasm_assert(!*p_section_list);
|
||||
|
||||
p += 8;
|
||||
while (p < p_end) {
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
@ -1548,6 +1596,25 @@ wasm_loader_unload(WASMModule *module)
|
||||
wasm_free(module);
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
void
|
||||
wasm_runtime_set_wasi_args(WASMModule *module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env_list[], uint32 env_count,
|
||||
const char *argv[], uint32 argc)
|
||||
{
|
||||
module->wasi_args.dir_list = dir_list;
|
||||
module->wasi_args.dir_count = dir_count;
|
||||
module->wasi_args.map_dir_list = map_dir_list;
|
||||
module->wasi_args.map_dir_count = map_dir_count;
|
||||
module->wasi_args.env = env_list;
|
||||
module->wasi_args.env_count = env_count;
|
||||
module->wasi_args.argv = argv;
|
||||
module->wasi_args.argc = argc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_HASH_BLOCK_ADDR != 0
|
||||
typedef struct block_addr {
|
||||
uint8 block_type;
|
||||
@ -1568,7 +1635,8 @@ wasm_loader_find_block_addr(WASMModule *module,
|
||||
{
|
||||
const uint8 *p = start_addr, *p_end = code_end_addr;
|
||||
uint8 *else_addr = NULL;
|
||||
uint32 block_nested_depth = 1, count, i, u32, u64;
|
||||
uint32 block_nested_depth = 1, count, i, u32;
|
||||
uint64 u64;
|
||||
uint8 opcode, u8;
|
||||
|
||||
#if WASM_ENABLE_HASH_BLOCK_ADDR != 0
|
||||
@ -1586,7 +1654,7 @@ wasm_loader_find_block_addr(WASMModule *module,
|
||||
BlockAddr block_stack[16] = { 0 }, *block;
|
||||
uint32 j, t;
|
||||
|
||||
i = ((uintptr_t)start_addr) ^ ((uintptr_t)start_addr >> 16);
|
||||
i = (uint32)(((uintptr_t)start_addr) ^ ((uintptr_t)start_addr >> 16));
|
||||
i = i % BLOCK_ADDR_CACHE_SIZE;
|
||||
block = module->block_addr_cache[i];
|
||||
for (j = 0; j < BLOCK_ADDR_CONFLICT_SIZE; j++) {
|
||||
@ -1613,7 +1681,7 @@ wasm_loader_find_block_addr(WASMModule *module,
|
||||
case WASM_OP_BLOCK:
|
||||
case WASM_OP_LOOP:
|
||||
case WASM_OP_IF:
|
||||
read_leb_uint32(p, p_end, u32); /* blocktype */
|
||||
read_leb_uint8(p, p_end, u8); /* blocktype */
|
||||
#if WASM_ENABLE_HASH_BLOCK_ADDR == 0
|
||||
if (block_nested_depth < sizeof(block_stack)/sizeof(BlockAddr)) {
|
||||
block_stack[block_nested_depth].start_addr = p;
|
||||
@ -1658,7 +1726,7 @@ wasm_loader_find_block_addr(WASMModule *module,
|
||||
for (t = 0; t < sizeof(block_stack)/sizeof(BlockAddr); t++) {
|
||||
start_addr = block_stack[t].start_addr;
|
||||
if (start_addr) {
|
||||
i = ((uintptr_t)start_addr) ^ ((uintptr_t)start_addr >> 16);
|
||||
i = (uint32)(((uintptr_t)start_addr) ^ ((uintptr_t)start_addr >> 16));
|
||||
i = i % BLOCK_ADDR_CACHE_SIZE;
|
||||
block = module->block_addr_cache[i];
|
||||
for (j = 0; j < BLOCK_ADDR_CONFLICT_SIZE; j++)
|
||||
@ -1937,7 +2005,7 @@ memory_realloc(void *mem_old, uint32 size_old, uint32 size_new)
|
||||
uint8 *mem_new;
|
||||
wasm_assert(size_new > size_old);
|
||||
if ((mem_new = wasm_malloc(size_new))) {
|
||||
memcpy(mem_new, mem_old, size_old);
|
||||
bh_memcpy_s(mem_new, size_new, mem_old, size_old);
|
||||
memset(mem_new + size_old, 0, size_new - size_old);
|
||||
wasm_free(mem_old);
|
||||
}
|
||||
@ -2171,8 +2239,9 @@ pop_type(uint8 type, uint8 **p_frame_ref, uint32 *p_stack_cell_num,
|
||||
#define CHECK_CSP_PUSH() do { \
|
||||
if (frame_csp >= frame_csp_boundary) { \
|
||||
MEM_REALLOC(frame_csp_bottom, frame_csp_size, \
|
||||
frame_csp_size + 8 * sizeof(BranchBlock));\
|
||||
frame_csp_size += 8 * sizeof(BranchBlock); \
|
||||
(uint32)(frame_csp_size \
|
||||
+ 8 * sizeof(BranchBlock))); \
|
||||
frame_csp_size += (uint32)(8 * sizeof(BranchBlock)); \
|
||||
frame_csp_boundary = frame_csp_bottom + \
|
||||
frame_csp_size / sizeof(BranchBlock); \
|
||||
frame_csp = frame_csp_bottom + csp_num; \
|
||||
@ -2281,10 +2350,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
||||
uint32 stack_cell_num = 0, csp_num = 0;
|
||||
uint32 frame_ref_size, frame_csp_size;
|
||||
uint8 *param_types, ret_type, *local_types, local_type, global_type;
|
||||
uint32 count, i, local_idx, global_idx, block_return_type, depth, u32;
|
||||
uint32 count, i, local_idx, global_idx, depth, u32;
|
||||
int32 i32, i32_const = 0;
|
||||
int64 i64;
|
||||
uint8 opcode, u8;
|
||||
uint8 opcode, u8, block_return_type;
|
||||
bool return_value = false, is_i32_const = false;
|
||||
|
||||
global_count = module->import_global_count + module->global_count;
|
||||
@ -2332,18 +2401,18 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
||||
break;
|
||||
|
||||
case WASM_OP_BLOCK:
|
||||
read_leb_uint32(p, p_end, block_return_type);
|
||||
read_leb_uint8(p, p_end, block_return_type);
|
||||
PUSH_CSP(BLOCK_TYPE_BLOCK, block_return_type, p);
|
||||
break;
|
||||
|
||||
case WASM_OP_LOOP:
|
||||
read_leb_uint32(p, p_end, block_return_type);
|
||||
read_leb_uint8(p, p_end, block_return_type);
|
||||
PUSH_CSP(BLOCK_TYPE_LOOP, block_return_type, p);
|
||||
break;
|
||||
|
||||
case WASM_OP_IF:
|
||||
POP_I32();
|
||||
read_leb_uint32(p, p_end, block_return_type);
|
||||
read_leb_uint8(p, p_end, block_return_type);
|
||||
PUSH_CSP(BLOCK_TYPE_IF, block_return_type, p);
|
||||
if (!is_i32_const)
|
||||
(frame_csp - 1)->jumped_by_br = true;
|
||||
@ -2535,8 +2604,10 @@ handle_op_br:
|
||||
func_type =
|
||||
module->functions[func_idx - module->import_function_count]->func_type;
|
||||
|
||||
for (idx = func_type->param_count - 1; idx >= 0; idx--)
|
||||
POP_TYPE(func_type->types[idx]);
|
||||
if (func_type->param_count > 0) {
|
||||
for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--)
|
||||
POP_TYPE(func_type->types[idx]);
|
||||
}
|
||||
|
||||
if (func_type->result_count)
|
||||
PUSH_TYPE(func_type->types[func_type->param_count]);
|
||||
@ -2575,8 +2646,10 @@ handle_op_br:
|
||||
|
||||
func_type = module->types[type_idx];
|
||||
|
||||
for (idx = func_type->param_count - 1; idx >= 0; idx--)
|
||||
POP_TYPE(func_type->types[idx]);
|
||||
if (func_type->param_count > 0) {
|
||||
for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--)
|
||||
POP_TYPE(func_type->types[idx]);
|
||||
}
|
||||
|
||||
PUSH_TYPE(func_type->types[func_type->param_count]);
|
||||
break;
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "wasm_platform_log.h"
|
||||
#include "wasm_memory.h"
|
||||
#include "mem_alloc.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
|
||||
static void
|
||||
@ -77,9 +78,9 @@ wasm_runtime_call_wasm(WASMModuleInstance *module_inst,
|
||||
uint32 stack_size;
|
||||
|
||||
/* Set to 8 bytes align */
|
||||
stack = (stack + 7) & ~7;
|
||||
stack_size = exec_env->stack_size
|
||||
- (stack - (uintptr_t)exec_env->stack);
|
||||
stack = (stack + 7) & (uintptr_t)~7;
|
||||
stack_size = (uint32)(exec_env->stack_size
|
||||
- (stack - (uintptr_t)exec_env->stack));
|
||||
|
||||
if (!exec_env->stack || exec_env->stack_size <= 0
|
||||
|| exec_env->stack_size < stack - (uintptr_t)exec_env->stack) {
|
||||
@ -171,18 +172,19 @@ memory_instantiate(uint32 init_page_count, uint32 max_page_count,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
WASMMemoryInstance *memory;
|
||||
uint32 total_size = offsetof(WASMMemoryInstance, base_addr) +
|
||||
NumBytesPerPage * init_page_count +
|
||||
uint64 total_size = offsetof(WASMMemoryInstance, base_addr) +
|
||||
NumBytesPerPage * (uint64)init_page_count +
|
||||
addr_data_size + global_data_size;
|
||||
|
||||
/* Allocate memory space, addr data and global data */
|
||||
if (!(memory = wasm_malloc(total_size))) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(memory = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate memory failed: allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(memory, 0, total_size);
|
||||
memset(memory, 0, (uint32)total_size);
|
||||
memory->cur_page_count = init_page_count;
|
||||
memory->max_page_count = max_page_count;
|
||||
|
||||
@ -238,23 +240,23 @@ memories_instantiate(const WASMModule *module, uint32 addr_data_size,
|
||||
WASMImport *import;
|
||||
uint32 mem_index = 0, i, memory_count =
|
||||
module->import_memory_count + module->memory_count;
|
||||
uint32 total_size;
|
||||
uint64 total_size;
|
||||
WASMMemoryInstance **memories, *memory;
|
||||
|
||||
if (memory_count == 0 && global_data_size > 0)
|
||||
memory_count = 1;
|
||||
|
||||
total_size = sizeof(WASMMemoryInstance*) * memory_count;
|
||||
memories = wasm_malloc(total_size);
|
||||
total_size = sizeof(WASMMemoryInstance*) * (uint64)memory_count;
|
||||
|
||||
if (!memories) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(memories = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate memory failed: "
|
||||
"allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(memories, 0, total_size);
|
||||
memset(memories, 0, (uint32)total_size);
|
||||
|
||||
/* instantiate memories from import section */
|
||||
import = module->import_memories;
|
||||
@ -329,24 +331,26 @@ tables_instantiate(const WASMModule *module,
|
||||
WASMImport *import;
|
||||
uint32 table_index = 0, i, table_count =
|
||||
module->import_table_count + module->table_count;
|
||||
uint32 total_size = sizeof(WASMTableInstance*) * table_count;
|
||||
WASMTableInstance **tables = wasm_malloc(total_size), *table;
|
||||
uint64 total_size = sizeof(WASMTableInstance*) * (uint64)table_count;
|
||||
WASMTableInstance **tables, *table;
|
||||
|
||||
if (!tables) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(tables = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate table failed: "
|
||||
"allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(tables, 0, total_size);
|
||||
memset(tables, 0, (uint32)total_size);
|
||||
|
||||
/* instantiate tables from import section */
|
||||
import = module->import_tables;
|
||||
for (i = 0; i < module->import_table_count; i++, import++) {
|
||||
total_size = offsetof(WASMTableInstance, base_addr) +
|
||||
sizeof(uint32) * import->u.table.init_size;
|
||||
if (!(table = tables[table_index++] = wasm_malloc(total_size))) {
|
||||
sizeof(uint32) * (uint64)import->u.table.init_size;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(table = tables[table_index++] = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate table failed: "
|
||||
"allocate memory failed.");
|
||||
@ -354,7 +358,7 @@ tables_instantiate(const WASMModule *module,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(table, 0, total_size);
|
||||
memset(table, 0, (uint32)total_size);
|
||||
table->cur_size = import->u.table.init_size;
|
||||
table->max_size = import->u.table.max_size;
|
||||
}
|
||||
@ -362,8 +366,9 @@ tables_instantiate(const WASMModule *module,
|
||||
/* instantiate tables from table section */
|
||||
for (i = 0; i < module->table_count; i++) {
|
||||
total_size = offsetof(WASMTableInstance, base_addr) +
|
||||
sizeof(uint32) * module->tables[i].init_size;
|
||||
if (!(table = tables[table_index++] = wasm_malloc(total_size))) {
|
||||
sizeof(uint32) * (uint64)module->tables[i].init_size;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(table = tables[table_index++] = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate table failed: "
|
||||
"allocate memory failed.");
|
||||
@ -371,7 +376,7 @@ tables_instantiate(const WASMModule *module,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(table, 0, total_size);
|
||||
memset(table, 0, (uint32)total_size);
|
||||
table->cur_size = module->tables[i].init_size;
|
||||
table->max_size = module->tables[i].max_size;
|
||||
}
|
||||
@ -399,24 +404,26 @@ functions_deinstantiate(WASMFunctionInstance *functions, uint32 count)
|
||||
static bool
|
||||
function_init_local_offsets(WASMFunctionInstance *func)
|
||||
{
|
||||
uint16 local_offset = 0;
|
||||
uint32 local_offset = 0;
|
||||
WASMType *param_type = func->u.func->func_type;
|
||||
uint32 param_count = param_type->param_count;
|
||||
uint8 *param_types = param_type->types;
|
||||
uint32 local_count = func->u.func->local_count;
|
||||
uint8 *local_types = func->u.func->local_types;
|
||||
uint32 i, total_size = (param_count + local_count) * sizeof(uint16);
|
||||
uint32 i;
|
||||
uint64 total_size = sizeof(uint16) * (uint64)(param_count + local_count);
|
||||
|
||||
if (!(func->local_offsets = wasm_malloc(total_size)))
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(func->local_offsets = wasm_malloc((uint32)total_size)))
|
||||
return false;
|
||||
|
||||
for (i = 0; i < param_count; i++) {
|
||||
func->local_offsets[i] = local_offset;
|
||||
func->local_offsets[i] = (uint16)local_offset;
|
||||
local_offset += wasm_value_type_cell_num(param_types[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < local_count; i++) {
|
||||
func->local_offsets[param_count + i] = local_offset;
|
||||
func->local_offsets[param_count + i] = (uint16)local_offset;
|
||||
local_offset += wasm_value_type_cell_num(local_types[i]);
|
||||
}
|
||||
|
||||
@ -434,17 +441,18 @@ functions_instantiate(const WASMModule *module,
|
||||
WASMImport *import;
|
||||
uint32 i, function_count =
|
||||
module->import_function_count + module->function_count;
|
||||
uint32 total_size = sizeof(WASMFunctionInstance) * function_count;
|
||||
WASMFunctionInstance *functions = wasm_malloc(total_size), *function;
|
||||
uint64 total_size = sizeof(WASMFunctionInstance) * (uint64)function_count;
|
||||
WASMFunctionInstance *functions, *function;
|
||||
|
||||
if (!functions) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(functions = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate function failed: "
|
||||
"allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(functions, 0, total_size);
|
||||
memset(functions, 0, (uint32)total_size);
|
||||
|
||||
/* instantiate functions from import section */
|
||||
function = functions;
|
||||
@ -459,6 +467,12 @@ functions_instantiate(const WASMModule *module,
|
||||
wasm_type_return_cell_num(import->u.function.func_type);
|
||||
function->local_cell_num = 0;
|
||||
|
||||
function->param_count =
|
||||
(uint16)function->u.func_import->func_type->param_count;
|
||||
function->local_count = 0;
|
||||
function->param_types = function->u.func_import->func_type->types;
|
||||
function->local_types = NULL;
|
||||
|
||||
function++;
|
||||
}
|
||||
|
||||
@ -475,6 +489,11 @@ functions_instantiate(const WASMModule *module,
|
||||
wasm_get_cell_num(function->u.func->local_types,
|
||||
function->u.func->local_count);
|
||||
|
||||
function->param_count = (uint16)function->u.func->func_type->param_count;
|
||||
function->local_count = (uint16)function->u.func->local_count;
|
||||
function->param_types = function->u.func->func_type->types;
|
||||
function->local_types = function->u.func->local_types;
|
||||
|
||||
if (!function_init_local_offsets(function)) {
|
||||
functions_deinstantiate(functions, function_count);
|
||||
return NULL;
|
||||
@ -510,17 +529,18 @@ globals_instantiate(const WASMModule *module,
|
||||
uint32 addr_data_offset = 0, global_data_offset = 0;
|
||||
uint32 i, global_count =
|
||||
module->import_global_count + module->global_count;
|
||||
uint32 total_size = sizeof(WASMGlobalInstance) * global_count;
|
||||
WASMGlobalInstance *globals = wasm_malloc(total_size), *global;
|
||||
uint64 total_size = sizeof(WASMGlobalInstance) * (uint64)global_count;
|
||||
WASMGlobalInstance *globals, *global;
|
||||
|
||||
if (!globals) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(globals = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate global failed: "
|
||||
"allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(globals, 0, total_size);
|
||||
memset(globals, 0, (uint32)total_size);
|
||||
|
||||
/* instantiate globals from import section */
|
||||
global = globals;
|
||||
@ -535,7 +555,7 @@ globals_instantiate(const WASMModule *module,
|
||||
global_data_offset += wasm_value_type_size(global->type);
|
||||
|
||||
if (global->is_addr)
|
||||
addr_data_offset += sizeof(uint32);
|
||||
addr_data_offset += (uint32)sizeof(uint32);
|
||||
|
||||
global++;
|
||||
}
|
||||
@ -550,7 +570,7 @@ globals_instantiate(const WASMModule *module,
|
||||
global_data_offset += wasm_value_type_size(global->type);
|
||||
|
||||
if (global->is_addr)
|
||||
addr_data_offset += sizeof(uint32);
|
||||
addr_data_offset += (uint32)sizeof(uint32);
|
||||
|
||||
global++;
|
||||
}
|
||||
@ -583,7 +603,7 @@ globals_instantiate_fix(WASMGlobalInstance *globals,
|
||||
}
|
||||
else if (!strcmp(import->u.names.field_name, "DYNAMICTOP_PTR")) {
|
||||
global->initial_value.i32 =
|
||||
NumBytesPerPage * module_inst->default_memory->cur_page_count;
|
||||
(int32)(NumBytesPerPage * module_inst->default_memory->cur_page_count);
|
||||
module_inst->DYNAMICTOP_PTR_offset = global->data_offset;
|
||||
}
|
||||
else if (!strcmp(import->u.names.field_name, "STACKTOP")) {
|
||||
@ -604,7 +624,8 @@ globals_instantiate_fix(WASMGlobalInstance *globals,
|
||||
global->initial_value = globals[init_expr->u.global_index].initial_value;
|
||||
}
|
||||
else {
|
||||
memcpy(&global->initial_value, &init_expr->u, sizeof(int64));
|
||||
bh_memcpy_s(&global->initial_value, sizeof(WASMValue),
|
||||
&init_expr->u, sizeof(init_expr->u));
|
||||
}
|
||||
global++;
|
||||
}
|
||||
@ -647,16 +668,18 @@ export_functions_instantiate(const WASMModule *module,
|
||||
{
|
||||
WASMExportFuncInstance *export_funcs, *export_func;
|
||||
WASMExport *export = module->exports;
|
||||
uint32 i, total_size = sizeof(WASMExportFuncInstance) * export_func_count;
|
||||
uint32 i;
|
||||
uint64 total_size = sizeof(WASMExportFuncInstance) * (uint64)export_func_count;
|
||||
|
||||
if (!(export_func = export_funcs = wasm_malloc(total_size))) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(export_func = export_funcs = wasm_malloc((uint32)total_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate export function failed: "
|
||||
"allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(export_funcs, 0, total_size);
|
||||
memset(export_funcs, 0, (uint32)total_size);
|
||||
|
||||
for (i = 0; i < module->export_count; i++, export++)
|
||||
if (export->kind == EXPORT_KIND_FUNC) {
|
||||
@ -710,11 +733,209 @@ execute_start_function(WASMModuleInstance *module_inst)
|
||||
return true;
|
||||
|
||||
wasm_assert(!func->is_import_func && func->param_cell_num == 0
|
||||
&& func->ret_cell_num == 0);
|
||||
&& func->ret_cell_num == 0);
|
||||
|
||||
return wasm_runtime_call_wasm(module_inst, NULL, func, 0, NULL);
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
static bool
|
||||
wasm_runtime_init_wasi(WASMModuleInstance *module_inst,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *argv[], uint32 argc,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
size_t *argv_offsets = NULL;
|
||||
char *argv_buf = NULL;
|
||||
size_t *env_offsets = NULL;
|
||||
char *env_buf = NULL;
|
||||
uint64 argv_buf_len = 0, env_buf_len = 0;
|
||||
uint32 argv_buf_offset = 0, env_buf_offset = 0;
|
||||
struct fd_table *curfds;
|
||||
struct fd_prestats *prestats;
|
||||
struct argv_environ_values *argv_environ;
|
||||
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;
|
||||
__wasi_fd_t wasm_fd = 3;
|
||||
int32 raw_fd;
|
||||
char *path, resolved_path[PATH_MAX];
|
||||
uint64 total_size;
|
||||
uint32 i;
|
||||
|
||||
if (!module_inst->default_memory) {
|
||||
argv_environ = module_inst->wasi_ctx.argv_environ = NULL;
|
||||
prestats = module_inst->wasi_ctx.prestats = NULL;
|
||||
curfds = module_inst->wasi_ctx.curfds = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* process argv[0], trip the path and suffix, only keep the program name */
|
||||
for (i = 0; i < argc; i++)
|
||||
argv_buf_len += strlen(argv[i]) + 1;
|
||||
|
||||
total_size = sizeof(size_t) * (uint64)argc;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(offset_argv_offsets = wasm_runtime_module_malloc
|
||||
(module_inst, (uint32)total_size))
|
||||
|| argv_buf_len >= UINT32_MAX
|
||||
|| !(offset_argv_buf = wasm_runtime_module_malloc
|
||||
(module_inst, (uint32)argv_buf_len))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: allocate memory failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
argv_offsets = (size_t*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_argv_offsets);
|
||||
argv_buf = (char*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_argv_buf);
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv_offsets[i] = argv_buf_offset;
|
||||
bh_strcpy_s(argv_buf + argv_buf_offset,
|
||||
(uint32)argv_buf_len - argv_buf_offset, argv[i]);
|
||||
argv_buf_offset += (uint32)(strlen(argv[i]) + 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < env_count; i++)
|
||||
env_buf_len += strlen(env[i]) + 1;
|
||||
|
||||
total_size = sizeof(size_t) * (uint64)argc;
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(offset_env_offsets = wasm_runtime_module_malloc
|
||||
(module_inst, (uint32)total_size))
|
||||
|| env_buf_len >= UINT32_MAX
|
||||
|| !(offset_env_buf = wasm_runtime_module_malloc
|
||||
(module_inst, (uint32)env_buf_len))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: allocate memory failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
env_offsets = (size_t*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_env_offsets);
|
||||
env_buf = (char*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_env_buf);
|
||||
|
||||
for (i = 0; i < env_count; i++) {
|
||||
env_offsets[i] = env_buf_offset;
|
||||
bh_strcpy_s(env_buf + env_buf_offset,
|
||||
(uint32)env_buf_len - env_buf_offset, env[i]);
|
||||
env_buf_offset += (uint32)(strlen(env[i]) + 1);
|
||||
}
|
||||
|
||||
if (!(offset_curfds = wasm_runtime_module_malloc
|
||||
(module_inst, sizeof(struct fd_table)))
|
||||
|| !(offset_prestats = wasm_runtime_module_malloc
|
||||
(module_inst, sizeof(struct fd_prestats)))
|
||||
|| !(offset_argv_environ = wasm_runtime_module_malloc
|
||||
(module_inst, sizeof(struct argv_environ_values)))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: allocate memory failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
curfds = module_inst->wasi_ctx.curfds = (struct fd_table*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_curfds);
|
||||
prestats = module_inst->wasi_ctx.prestats = (struct fd_prestats*)
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset_prestats);
|
||||
argv_environ = module_inst->wasi_ctx.argv_environ =
|
||||
(struct argv_environ_values*)wasm_runtime_addr_app_to_native
|
||||
(module_inst, offset_argv_environ);
|
||||
|
||||
fd_table_init(curfds);
|
||||
fd_prestats_init(prestats);
|
||||
|
||||
if (!argv_environ_init(argv_environ,
|
||||
argv_offsets, argc,
|
||||
argv_buf, argv_buf_len,
|
||||
env_offsets, env_count,
|
||||
env_buf, env_buf_len)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: "
|
||||
"init argument environment failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Prepopulate curfds with stdin, stdout, and stderr file descriptors. */
|
||||
if (!fd_table_insert_existing(curfds, 0, 0)
|
||||
|| !fd_table_insert_existing(curfds, 1, 1)
|
||||
|| !fd_table_insert_existing(curfds, 2, 2)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: init fd table failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
wasm_fd = 3;
|
||||
for (i = 0; i < dir_count; i++, wasm_fd++) {
|
||||
path = realpath(dir_list[i], resolved_path);
|
||||
if (!path) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error while pre-opening directory %s: %d\n",
|
||||
dir_list[i], errno);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
raw_fd = open(path, O_RDONLY | O_DIRECTORY, 0);
|
||||
if (raw_fd == -1) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error while pre-opening directory %s: %d\n",
|
||||
dir_list[i], errno);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fd_table_insert_existing(curfds, wasm_fd, raw_fd);
|
||||
fd_prestats_insert(prestats, dir_list[i], wasm_fd);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
if (offset_curfds != 0)
|
||||
wasm_runtime_module_free(module_inst, offset_curfds);
|
||||
if (offset_prestats != 0)
|
||||
wasm_runtime_module_free(module_inst, offset_prestats);
|
||||
if (offset_argv_environ != 0)
|
||||
wasm_runtime_module_free(module_inst, offset_argv_environ);
|
||||
if (offset_argv_buf)
|
||||
wasm_runtime_module_free(module_inst, offset_argv_buf);
|
||||
if (offset_argv_offsets)
|
||||
wasm_runtime_module_free(module_inst, offset_argv_offsets);
|
||||
if (offset_env_buf)
|
||||
wasm_runtime_module_free(module_inst, offset_env_buf);
|
||||
if (offset_env_offsets)
|
||||
wasm_runtime_module_free(module_inst, offset_env_offsets);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
wasm_runtime_destroy_wasi(WASMModuleInstance *module_inst)
|
||||
{
|
||||
WASIContext *wasi_ctx = &module_inst->wasi_ctx;
|
||||
|
||||
if (wasi_ctx->argv_environ)
|
||||
argv_environ_destroy(wasi_ctx->argv_environ);
|
||||
if (wasi_ctx->curfds)
|
||||
fd_table_destroy(wasi_ctx->curfds);
|
||||
if (wasi_ctx->prestats)
|
||||
fd_prestats_destroy(wasi_ctx->prestats);
|
||||
}
|
||||
|
||||
WASIContext *
|
||||
wasm_runtime_get_wasi_ctx(WASMModuleInstance *module_inst)
|
||||
{
|
||||
return &module_inst->wasi_ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Instantiate module
|
||||
*/
|
||||
@ -754,14 +975,14 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
return NULL;
|
||||
|
||||
/* Allocate the memory */
|
||||
if (!(module_inst = wasm_malloc(sizeof(WASMModuleInstance)))) {
|
||||
if (!(module_inst = wasm_malloc((uint32)sizeof(WASMModuleInstance)))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate module failed: allocate memory failed.");
|
||||
globals_deinstantiate(globals);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(module_inst, 0, sizeof(WASMModuleInstance));
|
||||
memset(module_inst, 0, (uint32)sizeof(WASMModuleInstance));
|
||||
module_inst->global_count = global_count;
|
||||
module_inst->globals = globals;
|
||||
|
||||
@ -818,7 +1039,7 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
else {
|
||||
*(int32*)addr_data = global->initial_value.i32;
|
||||
/* Store the offset to memory data for global of addr */
|
||||
*(int32*)global_data = addr_data - memory_data;
|
||||
*(int32*)global_data = (int32)(addr_data - memory_data);
|
||||
addr_data += sizeof(int32);
|
||||
}
|
||||
global_data += sizeof(int32);
|
||||
@ -826,7 +1047,8 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
case VALUE_TYPE_I64:
|
||||
case VALUE_TYPE_F64:
|
||||
wasm_assert(!global->is_addr);
|
||||
memcpy(global_data, &global->initial_value.i64, sizeof(int64));
|
||||
bh_memcpy_s(global_data, (uint32)(global_data_end - global_data),
|
||||
&global->initial_value.i64, sizeof(int64));
|
||||
global_data += sizeof(int64);
|
||||
break;
|
||||
default:
|
||||
@ -880,7 +1102,8 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(memory_data + base_offset, data_seg->data, length);
|
||||
bh_memcpy_s(memory_data + base_offset, memory_size - base_offset,
|
||||
data_seg->data, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -909,10 +1132,10 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
if ((uint32)table_seg->base_offset.u.i32 <
|
||||
module_inst->default_table->cur_size) {
|
||||
length = table_seg->function_count;
|
||||
if (table_seg->base_offset.u.i32 + length >
|
||||
if ((uint32)table_seg->base_offset.u.i32 + length >
|
||||
module_inst->default_table->cur_size)
|
||||
length = module_inst->default_table->cur_size
|
||||
- table_seg->base_offset.u.i32;
|
||||
- (uint32)table_seg->base_offset.u.i32;
|
||||
/* Check function index */
|
||||
for (j = 0; j < length; j++) {
|
||||
if (table_seg->func_indexes[j] >= module_inst->function_count) {
|
||||
@ -922,12 +1145,31 @@ wasm_runtime_instantiate(WASMModule *module,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
memcpy(table_data + table_seg->base_offset.u.i32,
|
||||
table_seg->func_indexes, length * sizeof(uint32));
|
||||
bh_memcpy_s(table_data + table_seg->base_offset.u.i32,
|
||||
(uint32)((module_inst->default_table->cur_size
|
||||
- (uint32)table_seg->base_offset.u.i32)
|
||||
* sizeof(uint32)),
|
||||
table_seg->func_indexes, (uint32)(length * sizeof(uint32)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
if (!wasm_runtime_init_wasi(module_inst,
|
||||
module->wasi_args.dir_list,
|
||||
module->wasi_args.dir_count,
|
||||
module->wasi_args.map_dir_list,
|
||||
module->wasi_args.map_dir_count,
|
||||
module->wasi_args.env,
|
||||
module->wasi_args.env_count,
|
||||
module->wasi_args.argv,
|
||||
module->wasi_args.argc,
|
||||
error_buf, error_buf_size)) {
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (module->start_function != (uint32)-1) {
|
||||
wasm_assert(module->start_function >= module->import_function_count);
|
||||
module_inst->start_function =
|
||||
@ -968,6 +1210,10 @@ wasm_runtime_deinstantiate(WASMModuleInstance *module_inst)
|
||||
if (!module_inst)
|
||||
return;
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
wasm_runtime_destroy_wasi(module_inst);
|
||||
#endif
|
||||
|
||||
if (module_inst->memory_count > 0)
|
||||
memories_deinstantiate(module_inst->memories, module_inst->memory_count);
|
||||
else if (module_inst->memories != NULL && module_inst->global_count > 0)
|
||||
@ -1018,15 +1264,15 @@ wasm_runtime_set_ext_memory(WASMModuleInstance *module_inst,
|
||||
#endif
|
||||
|
||||
bool
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstance *module, int inc_page_count)
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
{
|
||||
#if WASM_ENABLE_MEMORY_GROW != 0
|
||||
WASMMemoryInstance *memory = module->default_memory;
|
||||
WASMMemoryInstance *new_memory;
|
||||
uint32 total_page_count = inc_page_count + memory->cur_page_count;
|
||||
uint32 total_size = offsetof(WASMMemoryInstance, base_addr) +
|
||||
uint64 total_size = offsetof(WASMMemoryInstance, base_addr) +
|
||||
memory->addr_data_size +
|
||||
NumBytesPerPage * total_page_count +
|
||||
NumBytesPerPage * (uint64)total_page_count +
|
||||
memory->global_data_size;
|
||||
|
||||
if (inc_page_count <= 0)
|
||||
@ -1039,7 +1285,8 @@ wasm_runtime_enlarge_memory(WASMModuleInstance *module, int inc_page_count)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(new_memory = wasm_malloc(total_size))) {
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(new_memory = wasm_malloc((uint32)total_size))) {
|
||||
wasm_runtime_set_exception(module, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
@ -1059,11 +1306,13 @@ wasm_runtime_enlarge_memory(WASMModuleInstance *module, int inc_page_count)
|
||||
new_memory->end_addr = new_memory->global_data + memory->global_data_size;
|
||||
|
||||
/* Copy addr data and memory data */
|
||||
memcpy(new_memory->addr_data, memory->addr_data,
|
||||
memory->global_data - memory->addr_data);
|
||||
bh_memcpy_s(new_memory->addr_data,
|
||||
(uint32)(memory->global_data - memory->addr_data),
|
||||
memory->addr_data,
|
||||
(uint32)(memory->global_data - memory->addr_data));
|
||||
/* Copy global data */
|
||||
memcpy(new_memory->global_data, memory->global_data,
|
||||
memory->global_data_size);
|
||||
bh_memcpy_s(new_memory->global_data, new_memory->global_data_size,
|
||||
memory->global_data, memory->global_data_size);
|
||||
/* Init free space of new memory */
|
||||
memset(new_memory->memory_data + NumBytesPerPage * memory->cur_page_count,
|
||||
0, NumBytesPerPage * (total_page_count - memory->cur_page_count));
|
||||
@ -1097,7 +1346,7 @@ get_package_type(const uint8 *buf, uint32 size)
|
||||
WASMExecEnv*
|
||||
wasm_runtime_create_exec_env(uint32 stack_size)
|
||||
{
|
||||
WASMExecEnv *exec_env = wasm_malloc(sizeof(WASMExecEnv));
|
||||
WASMExecEnv *exec_env = wasm_malloc((uint32)sizeof(WASMExecEnv));
|
||||
if (exec_env) {
|
||||
if (!(exec_env->stack = wasm_malloc(stack_size))) {
|
||||
wasm_free(exec_env);
|
||||
@ -1139,7 +1388,7 @@ wasm_runtime_module_malloc(WASMModuleInstance *module_inst, uint32 size)
|
||||
wasm_runtime_set_exception(module_inst, "out of memory");
|
||||
return 0;
|
||||
}
|
||||
return memory->heap_base_offset + (addr - memory->heap_data);
|
||||
return memory->heap_base_offset + (int32)(addr - memory->heap_data);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1161,7 +1410,7 @@ wasm_runtime_module_dup_data(WASMModuleInstance *module_inst,
|
||||
if (buffer_offset != 0) {
|
||||
char *buffer;
|
||||
buffer = wasm_runtime_addr_app_to_native(module_inst, buffer_offset);
|
||||
memcpy(buffer, src, size);
|
||||
bh_memcpy_s(buffer, size, src, size);
|
||||
}
|
||||
return buffer_offset;
|
||||
}
|
||||
@ -1174,7 +1423,7 @@ wasm_runtime_validate_app_addr(WASMModuleInstance *module_inst,
|
||||
uint8 *addr;
|
||||
|
||||
/* integer overflow check */
|
||||
if(app_offset + size < app_offset) {
|
||||
if(app_offset + (int32)size < app_offset) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1294,11 +1543,11 @@ wasm_runtime_addr_native_to_app(WASMModuleInstance *module_inst,
|
||||
WASMMemoryInstance *memory = module_inst->default_memory;
|
||||
if (memory->base_addr <= (uint8*)native_ptr
|
||||
&& (uint8*)native_ptr < memory->end_addr)
|
||||
return (uint8*)native_ptr - memory->memory_data;
|
||||
return (int32)((uint8*)native_ptr - memory->memory_data);
|
||||
else if (memory->heap_data <= (uint8*)native_ptr
|
||||
&& (uint8*)native_ptr < memory->heap_data_end)
|
||||
return memory->heap_base_offset
|
||||
+ ((uint8*)native_ptr - memory->heap_data);
|
||||
+ (int32)((uint8*)native_ptr - memory->heap_data);
|
||||
#if WASM_ENABLE_EXT_MEMORY_SPACE != 0
|
||||
else if (module_inst->ext_mem_data
|
||||
&& module_inst->ext_mem_data <= (uint8*)native_ptr
|
||||
@ -1321,14 +1570,14 @@ wasm_runtime_get_app_addr_range(WASMModuleInstance *module_inst,
|
||||
|
||||
if (0 <= app_offset && app_offset < memory->heap_base_offset) {
|
||||
app_start_offset = 0;
|
||||
app_end_offset = NumBytesPerPage * memory->cur_page_count;
|
||||
app_end_offset = (int32)(NumBytesPerPage * memory->cur_page_count);
|
||||
}
|
||||
else if (memory->heap_base_offset < app_offset
|
||||
&& app_offset < memory->heap_base_offset
|
||||
+ (memory->heap_data_end - memory->heap_data)) {
|
||||
app_start_offset = memory->heap_base_offset;
|
||||
app_end_offset = memory->heap_base_offset
|
||||
+ (memory->heap_data_end - memory->heap_data);
|
||||
+ (int32)(memory->heap_data_end - memory->heap_data);
|
||||
}
|
||||
#if WASM_ENABLE_EXT_MEMORY_SPACE != 0
|
||||
else if (module_inst->ext_mem_data
|
||||
@ -1479,7 +1728,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
|
||||
#endif
|
||||
|
||||
if (argc1 > sizeof(argv_buf) / sizeof(uint32)) {
|
||||
size = ((uint64)sizeof(uint32)) * argc1;
|
||||
size = sizeof(uint32) * (uint64)argc1;
|
||||
if (size >= UINT_MAX
|
||||
|| !(argv1 = wasm_malloc((uint32)size))) {
|
||||
wasm_runtime_set_exception(module_inst, "allocate memory failed.");
|
||||
@ -1524,7 +1773,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
|
||||
else {
|
||||
switch (func_type->types[func_type->param_count]) {
|
||||
case VALUE_TYPE_I32:
|
||||
ret[0] = invokeNative_Int32(func_ptr, argv1, argc1);
|
||||
ret[0] = (uint32)invokeNative_Int32(func_ptr, argv1, argc1);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
PUT_I64_TO_ADDR(ret, invokeNative_Int64(func_ptr, argv1, argc1));
|
||||
@ -1587,9 +1836,9 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
|
||||
|
||||
argc1 = 1 + MAX_REG_FLOATS + func_type->param_count + 2;
|
||||
if (argc1 > sizeof(argv_buf) / sizeof(uint64)) {
|
||||
size = sizeof(uint64) * argc1;
|
||||
size = sizeof(uint64) * (uint64)argc1;
|
||||
if (size >= UINT32_MAX
|
||||
|| !(argv1 = wasm_malloc(size))) {
|
||||
|| !(argv1 = wasm_malloc((uint32)size))) {
|
||||
wasm_runtime_set_exception(module_inst, "allocate memory failed.");
|
||||
return false;
|
||||
}
|
||||
@ -1641,7 +1890,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
|
||||
else {
|
||||
switch (func_type->types[func_type->param_count]) {
|
||||
case VALUE_TYPE_I32:
|
||||
ret[0] = invokeNative_Int32(func_ptr, argv1, n_stacks);
|
||||
ret[0] = (uint32)invokeNative_Int32(func_ptr, argv1, n_stacks);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
PUT_I64_TO_ADDR(ret, invokeNative_Int64(func_ptr, argv1, n_stacks));
|
||||
|
||||
@ -9,6 +9,10 @@
|
||||
#include "wasm.h"
|
||||
#include "wasm_thread.h"
|
||||
#include "wasm_hashmap.h"
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
#include "wasmtime_ssp.h"
|
||||
#include "posix.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -81,6 +85,10 @@ typedef struct WASMGlobalInstance {
|
||||
typedef struct WASMFunctionInstance {
|
||||
/* whether it is import function or WASM function */
|
||||
bool is_import_func;
|
||||
/* parameter count */
|
||||
uint16 param_count;
|
||||
/* local variable count, 0 for import function */
|
||||
uint16 local_count;
|
||||
/* cell num of parameters */
|
||||
uint16 param_cell_num;
|
||||
/* cell num of return type */
|
||||
@ -88,6 +96,10 @@ typedef struct WASMFunctionInstance {
|
||||
/* cell num of local variables, 0 for import function */
|
||||
uint16 local_cell_num;
|
||||
uint16 *local_offsets;
|
||||
/* parameter types */
|
||||
uint8 *param_types;
|
||||
/* local types, NULL for import function */
|
||||
uint8 *local_types;
|
||||
union {
|
||||
WASMFunctionImport *func_import;
|
||||
WASMFunction *func;
|
||||
@ -106,6 +118,14 @@ typedef enum {
|
||||
Package_Type_Unknown = 0xFFFF
|
||||
} PackageType;
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
typedef struct WASIContext {
|
||||
struct fd_table *curfds;
|
||||
struct fd_prestats *prestats;
|
||||
struct argv_environ_values *argv_environ;
|
||||
} WASIContext;
|
||||
#endif
|
||||
|
||||
typedef struct WASMModuleInstance {
|
||||
/* Module instance type, for module instance loaded from
|
||||
WASM bytecode binary, this field is Wasm_Module_Bytecode;
|
||||
@ -133,6 +153,10 @@ typedef struct WASMModuleInstance {
|
||||
|
||||
WASMModule *module;
|
||||
|
||||
#if WASM_ENABLE_WASI != 0
|
||||
WASIContext wasi_ctx;
|
||||
#endif
|
||||
|
||||
uint32 DYNAMICTOP_PTR_offset;
|
||||
uint32 temp_ret;
|
||||
uint32 llvm_stack;
|
||||
@ -271,7 +295,7 @@ wasm_runtime_get_exception(WASMModuleInstance *module);
|
||||
* @return return true if enlarge successfully, false otherwise
|
||||
*/
|
||||
bool
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstance *module, int inc_page_count);
|
||||
wasm_runtime_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASMModuleInstance *
|
||||
|
||||
220
core/iwasm/runtime/wasmtime-wasi-c/LICENSE
Normal file
220
core/iwasm/runtime/wasmtime-wasi-c/LICENSE
Normal file
@ -0,0 +1,220 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
--- LLVM Exceptions to the Apache 2.0 License ----
|
||||
|
||||
As an exception, if, as a result of your compiling your source code, portions
|
||||
of this Software are embedded into an Object form of such source code, you
|
||||
may redistribute such embedded portions in such Object form without complying
|
||||
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||
|
||||
In addition, if you combine or link compiled forms of this Software with
|
||||
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||
court of competent jurisdiction determines that the patent provision (Section
|
||||
3), the indemnity provision (Section 9) or other Section of the License
|
||||
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||
the License, but only in their entirety and only with respect to the Combined
|
||||
Software.
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
Please see the LICENSE file in each top-level directory for the terms applicable to that directory and its relative sub-directories.
|
||||
|
||||
The relevant directories and licenses are:
|
||||
|
||||
src/ - BSD-2-Clause; see src/LICENSE for details
|
||||
include/ - CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
polyfill/clang/ - MIT; see the header of polyfill/clang/stdatomic.h for details
|
||||
@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
@ -0,0 +1,866 @@
|
||||
/*
|
||||
* Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
*
|
||||
* This file declares an interface similar to WASI, but augmented to expose
|
||||
* some implementation details such as the curfds arguments that we pass
|
||||
* around to avoid storing them in TLS.
|
||||
*/
|
||||
|
||||
#ifndef WASMTIME_SSP_H
|
||||
#define WASMTIME_SSP_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint8_t __wasi_advice_t;
|
||||
#define __WASI_ADVICE_NORMAL (0)
|
||||
#define __WASI_ADVICE_SEQUENTIAL (1)
|
||||
#define __WASI_ADVICE_RANDOM (2)
|
||||
#define __WASI_ADVICE_WILLNEED (3)
|
||||
#define __WASI_ADVICE_DONTNEED (4)
|
||||
#define __WASI_ADVICE_NOREUSE (5)
|
||||
|
||||
typedef uint32_t __wasi_clockid_t;
|
||||
#define __WASI_CLOCK_REALTIME (0)
|
||||
#define __WASI_CLOCK_MONOTONIC (1)
|
||||
#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2)
|
||||
#define __WASI_CLOCK_THREAD_CPUTIME_ID (3)
|
||||
|
||||
typedef uint64_t __wasi_device_t;
|
||||
|
||||
typedef uint64_t __wasi_dircookie_t;
|
||||
#define __WASI_DIRCOOKIE_START (0)
|
||||
|
||||
typedef uint16_t __wasi_errno_t;
|
||||
#define __WASI_ESUCCESS (0)
|
||||
#define __WASI_E2BIG (1)
|
||||
#define __WASI_EACCES (2)
|
||||
#define __WASI_EADDRINUSE (3)
|
||||
#define __WASI_EADDRNOTAVAIL (4)
|
||||
#define __WASI_EAFNOSUPPORT (5)
|
||||
#define __WASI_EAGAIN (6)
|
||||
#define __WASI_EALREADY (7)
|
||||
#define __WASI_EBADF (8)
|
||||
#define __WASI_EBADMSG (9)
|
||||
#define __WASI_EBUSY (10)
|
||||
#define __WASI_ECANCELED (11)
|
||||
#define __WASI_ECHILD (12)
|
||||
#define __WASI_ECONNABORTED (13)
|
||||
#define __WASI_ECONNREFUSED (14)
|
||||
#define __WASI_ECONNRESET (15)
|
||||
#define __WASI_EDEADLK (16)
|
||||
#define __WASI_EDESTADDRREQ (17)
|
||||
#define __WASI_EDOM (18)
|
||||
#define __WASI_EDQUOT (19)
|
||||
#define __WASI_EEXIST (20)
|
||||
#define __WASI_EFAULT (21)
|
||||
#define __WASI_EFBIG (22)
|
||||
#define __WASI_EHOSTUNREACH (23)
|
||||
#define __WASI_EIDRM (24)
|
||||
#define __WASI_EILSEQ (25)
|
||||
#define __WASI_EINPROGRESS (26)
|
||||
#define __WASI_EINTR (27)
|
||||
#define __WASI_EINVAL (28)
|
||||
#define __WASI_EIO (29)
|
||||
#define __WASI_EISCONN (30)
|
||||
#define __WASI_EISDIR (31)
|
||||
#define __WASI_ELOOP (32)
|
||||
#define __WASI_EMFILE (33)
|
||||
#define __WASI_EMLINK (34)
|
||||
#define __WASI_EMSGSIZE (35)
|
||||
#define __WASI_EMULTIHOP (36)
|
||||
#define __WASI_ENAMETOOLONG (37)
|
||||
#define __WASI_ENETDOWN (38)
|
||||
#define __WASI_ENETRESET (39)
|
||||
#define __WASI_ENETUNREACH (40)
|
||||
#define __WASI_ENFILE (41)
|
||||
#define __WASI_ENOBUFS (42)
|
||||
#define __WASI_ENODEV (43)
|
||||
#define __WASI_ENOENT (44)
|
||||
#define __WASI_ENOEXEC (45)
|
||||
#define __WASI_ENOLCK (46)
|
||||
#define __WASI_ENOLINK (47)
|
||||
#define __WASI_ENOMEM (48)
|
||||
#define __WASI_ENOMSG (49)
|
||||
#define __WASI_ENOPROTOOPT (50)
|
||||
#define __WASI_ENOSPC (51)
|
||||
#define __WASI_ENOSYS (52)
|
||||
#define __WASI_ENOTCONN (53)
|
||||
#define __WASI_ENOTDIR (54)
|
||||
#define __WASI_ENOTEMPTY (55)
|
||||
#define __WASI_ENOTRECOVERABLE (56)
|
||||
#define __WASI_ENOTSOCK (57)
|
||||
#define __WASI_ENOTSUP (58)
|
||||
#define __WASI_ENOTTY (59)
|
||||
#define __WASI_ENXIO (60)
|
||||
#define __WASI_EOVERFLOW (61)
|
||||
#define __WASI_EOWNERDEAD (62)
|
||||
#define __WASI_EPERM (63)
|
||||
#define __WASI_EPIPE (64)
|
||||
#define __WASI_EPROTO (65)
|
||||
#define __WASI_EPROTONOSUPPORT (66)
|
||||
#define __WASI_EPROTOTYPE (67)
|
||||
#define __WASI_ERANGE (68)
|
||||
#define __WASI_EROFS (69)
|
||||
#define __WASI_ESPIPE (70)
|
||||
#define __WASI_ESRCH (71)
|
||||
#define __WASI_ESTALE (72)
|
||||
#define __WASI_ETIMEDOUT (73)
|
||||
#define __WASI_ETXTBSY (74)
|
||||
#define __WASI_EXDEV (75)
|
||||
#define __WASI_ENOTCAPABLE (76)
|
||||
|
||||
typedef uint16_t __wasi_eventrwflags_t;
|
||||
#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001)
|
||||
|
||||
typedef uint8_t __wasi_eventtype_t;
|
||||
#define __WASI_EVENTTYPE_CLOCK (0)
|
||||
#define __WASI_EVENTTYPE_FD_READ (1)
|
||||
#define __WASI_EVENTTYPE_FD_WRITE (2)
|
||||
|
||||
typedef uint32_t __wasi_exitcode_t;
|
||||
|
||||
typedef uint32_t __wasi_fd_t;
|
||||
|
||||
typedef uint16_t __wasi_fdflags_t;
|
||||
#define __WASI_FDFLAG_APPEND (0x0001)
|
||||
#define __WASI_FDFLAG_DSYNC (0x0002)
|
||||
#define __WASI_FDFLAG_NONBLOCK (0x0004)
|
||||
#define __WASI_FDFLAG_RSYNC (0x0008)
|
||||
#define __WASI_FDFLAG_SYNC (0x0010)
|
||||
|
||||
typedef int64_t __wasi_filedelta_t;
|
||||
|
||||
typedef uint64_t __wasi_filesize_t;
|
||||
|
||||
typedef uint8_t __wasi_filetype_t;
|
||||
#define __WASI_FILETYPE_UNKNOWN (0)
|
||||
#define __WASI_FILETYPE_BLOCK_DEVICE (1)
|
||||
#define __WASI_FILETYPE_CHARACTER_DEVICE (2)
|
||||
#define __WASI_FILETYPE_DIRECTORY (3)
|
||||
#define __WASI_FILETYPE_REGULAR_FILE (4)
|
||||
#define __WASI_FILETYPE_SOCKET_DGRAM (5)
|
||||
#define __WASI_FILETYPE_SOCKET_STREAM (6)
|
||||
#define __WASI_FILETYPE_SYMBOLIC_LINK (7)
|
||||
|
||||
typedef uint16_t __wasi_fstflags_t;
|
||||
#define __WASI_FILESTAT_SET_ATIM (0x0001)
|
||||
#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002)
|
||||
#define __WASI_FILESTAT_SET_MTIM (0x0004)
|
||||
#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008)
|
||||
|
||||
typedef uint64_t __wasi_inode_t;
|
||||
|
||||
typedef uint32_t __wasi_linkcount_t;
|
||||
|
||||
typedef uint32_t __wasi_lookupflags_t;
|
||||
#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001)
|
||||
|
||||
typedef uint16_t __wasi_oflags_t;
|
||||
#define __WASI_O_CREAT (0x0001)
|
||||
#define __WASI_O_DIRECTORY (0x0002)
|
||||
#define __WASI_O_EXCL (0x0004)
|
||||
#define __WASI_O_TRUNC (0x0008)
|
||||
|
||||
typedef uint16_t __wasi_riflags_t;
|
||||
#define __WASI_SOCK_RECV_PEEK (0x0001)
|
||||
#define __WASI_SOCK_RECV_WAITALL (0x0002)
|
||||
|
||||
typedef uint64_t __wasi_rights_t;
|
||||
#define __WASI_RIGHT_FD_DATASYNC (0x0000000000000001)
|
||||
#define __WASI_RIGHT_FD_READ (0x0000000000000002)
|
||||
#define __WASI_RIGHT_FD_SEEK (0x0000000000000004)
|
||||
#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS (0x0000000000000008)
|
||||
#define __WASI_RIGHT_FD_SYNC (0x0000000000000010)
|
||||
#define __WASI_RIGHT_FD_TELL (0x0000000000000020)
|
||||
#define __WASI_RIGHT_FD_WRITE (0x0000000000000040)
|
||||
#define __WASI_RIGHT_FD_ADVISE (0x0000000000000080)
|
||||
#define __WASI_RIGHT_FD_ALLOCATE (0x0000000000000100)
|
||||
#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (0x0000000000000200)
|
||||
#define __WASI_RIGHT_PATH_CREATE_FILE (0x0000000000000400)
|
||||
#define __WASI_RIGHT_PATH_LINK_SOURCE (0x0000000000000800)
|
||||
#define __WASI_RIGHT_PATH_LINK_TARGET (0x0000000000001000)
|
||||
#define __WASI_RIGHT_PATH_OPEN (0x0000000000002000)
|
||||
#define __WASI_RIGHT_FD_READDIR (0x0000000000004000)
|
||||
#define __WASI_RIGHT_PATH_READLINK (0x0000000000008000)
|
||||
#define __WASI_RIGHT_PATH_RENAME_SOURCE (0x0000000000010000)
|
||||
#define __WASI_RIGHT_PATH_RENAME_TARGET (0x0000000000020000)
|
||||
#define __WASI_RIGHT_PATH_FILESTAT_GET (0x0000000000040000)
|
||||
#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE (0x0000000000080000)
|
||||
#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (0x0000000000100000)
|
||||
#define __WASI_RIGHT_FD_FILESTAT_GET (0x0000000000200000)
|
||||
#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE (0x0000000000400000)
|
||||
#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES (0x0000000000800000)
|
||||
#define __WASI_RIGHT_PATH_SYMLINK (0x0000000001000000)
|
||||
#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (0x0000000002000000)
|
||||
#define __WASI_RIGHT_PATH_UNLINK_FILE (0x0000000004000000)
|
||||
#define __WASI_RIGHT_POLL_FD_READWRITE (0x0000000008000000)
|
||||
#define __WASI_RIGHT_SOCK_SHUTDOWN (0x0000000010000000)
|
||||
|
||||
typedef uint16_t __wasi_roflags_t;
|
||||
#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001)
|
||||
|
||||
typedef uint8_t __wasi_sdflags_t;
|
||||
#define __WASI_SHUT_RD (0x01)
|
||||
#define __WASI_SHUT_WR (0x02)
|
||||
|
||||
typedef uint16_t __wasi_siflags_t;
|
||||
|
||||
typedef uint8_t __wasi_signal_t;
|
||||
// 0 is reserved; POSIX has special semantics for kill(pid, 0).
|
||||
#define __WASI_SIGHUP (1)
|
||||
#define __WASI_SIGINT (2)
|
||||
#define __WASI_SIGQUIT (3)
|
||||
#define __WASI_SIGILL (4)
|
||||
#define __WASI_SIGTRAP (5)
|
||||
#define __WASI_SIGABRT (6)
|
||||
#define __WASI_SIGBUS (7)
|
||||
#define __WASI_SIGFPE (8)
|
||||
#define __WASI_SIGKILL (9)
|
||||
#define __WASI_SIGUSR1 (10)
|
||||
#define __WASI_SIGSEGV (11)
|
||||
#define __WASI_SIGUSR2 (12)
|
||||
#define __WASI_SIGPIPE (13)
|
||||
#define __WASI_SIGALRM (14)
|
||||
#define __WASI_SIGTERM (15)
|
||||
#define __WASI_SIGCHLD (16)
|
||||
#define __WASI_SIGCONT (17)
|
||||
#define __WASI_SIGSTOP (18)
|
||||
#define __WASI_SIGTSTP (19)
|
||||
#define __WASI_SIGTTIN (20)
|
||||
#define __WASI_SIGTTOU (21)
|
||||
#define __WASI_SIGURG (22)
|
||||
#define __WASI_SIGXCPU (23)
|
||||
#define __WASI_SIGXFSZ (24)
|
||||
#define __WASI_SIGVTALRM (25)
|
||||
#define __WASI_SIGPROF (26)
|
||||
#define __WASI_SIGWINCH (27)
|
||||
#define __WASI_SIGPOLL (28)
|
||||
#define __WASI_SIGPWR (29)
|
||||
#define __WASI_SIGSYS (30)
|
||||
|
||||
typedef uint16_t __wasi_subclockflags_t;
|
||||
#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001)
|
||||
|
||||
typedef uint64_t __wasi_timestamp_t;
|
||||
|
||||
typedef uint64_t __wasi_userdata_t;
|
||||
|
||||
typedef uint8_t __wasi_whence_t;
|
||||
#define __WASI_WHENCE_CUR (0)
|
||||
#define __WASI_WHENCE_END (1)
|
||||
#define __WASI_WHENCE_SET (2)
|
||||
|
||||
typedef uint8_t __wasi_preopentype_t;
|
||||
#define __WASI_PREOPENTYPE_DIR (0)
|
||||
|
||||
struct fd_table;
|
||||
struct fd_prestats;
|
||||
struct argv_environ_values;
|
||||
|
||||
typedef struct __wasi_dirent_t {
|
||||
__wasi_dircookie_t d_next;
|
||||
__wasi_inode_t d_ino;
|
||||
uint32_t d_namlen;
|
||||
__wasi_filetype_t d_type;
|
||||
} __wasi_dirent_t;
|
||||
_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout");
|
||||
_Static_assert(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_event_t {
|
||||
__wasi_userdata_t userdata;
|
||||
__wasi_errno_t error;
|
||||
__wasi_eventtype_t type;
|
||||
union __wasi_event_u {
|
||||
struct __wasi_event_u_fd_readwrite_t {
|
||||
__wasi_filesize_t nbytes;
|
||||
__wasi_eventrwflags_t flags;
|
||||
} fd_readwrite;
|
||||
} u;
|
||||
} __wasi_event_t;
|
||||
_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout");
|
||||
_Static_assert(sizeof(__wasi_event_t) == 32, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(__wasi_event_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_prestat_t {
|
||||
__wasi_preopentype_t pr_type;
|
||||
union __wasi_prestat_u {
|
||||
struct __wasi_prestat_u_dir_t {
|
||||
size_t pr_name_len;
|
||||
} dir;
|
||||
} u;
|
||||
} __wasi_prestat_t;
|
||||
_Static_assert(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
sizeof(__wasi_prestat_t) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
sizeof(__wasi_prestat_t) == 16, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
_Alignof(__wasi_prestat_t) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
_Alignof(__wasi_prestat_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_fdstat_t {
|
||||
__wasi_filetype_t fs_filetype;
|
||||
__wasi_fdflags_t fs_flags;
|
||||
__wasi_rights_t fs_rights_base;
|
||||
__wasi_rights_t fs_rights_inheriting;
|
||||
} __wasi_fdstat_t;
|
||||
_Static_assert(
|
||||
offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16,
|
||||
"non-wasi data layout");
|
||||
_Static_assert(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_filestat_t {
|
||||
__wasi_device_t st_dev;
|
||||
__wasi_inode_t st_ino;
|
||||
__wasi_filetype_t st_filetype;
|
||||
__wasi_linkcount_t st_nlink;
|
||||
__wasi_filesize_t st_size;
|
||||
__wasi_timestamp_t st_atim;
|
||||
__wasi_timestamp_t st_mtim;
|
||||
__wasi_timestamp_t st_ctim;
|
||||
} __wasi_filestat_t;
|
||||
_Static_assert(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout");
|
||||
_Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_nlink) == 20, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_size) == 24, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_atim) == 32, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_mtim) == 40, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_filestat_t, st_ctim) == 48, "non-wasi data layout");
|
||||
_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_ciovec_t {
|
||||
const void *buf;
|
||||
size_t buf_len;
|
||||
} __wasi_ciovec_t;
|
||||
_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
_Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
_Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_iovec_t {
|
||||
void *buf;
|
||||
size_t buf_len;
|
||||
} __wasi_iovec_t;
|
||||
_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
sizeof(__wasi_iovec_t) == 8, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
sizeof(__wasi_iovec_t) == 16, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 4 ||
|
||||
_Alignof(__wasi_iovec_t) == 4, "non-wasi data layout");
|
||||
_Static_assert(sizeof(void *) != 8 ||
|
||||
_Alignof(__wasi_iovec_t) == 8, "non-wasi data layout");
|
||||
|
||||
typedef struct __wasi_subscription_t {
|
||||
__wasi_userdata_t userdata;
|
||||
__wasi_eventtype_t type;
|
||||
union __wasi_subscription_u {
|
||||
struct __wasi_subscription_u_clock_t {
|
||||
__wasi_userdata_t identifier;
|
||||
__wasi_clockid_t clock_id;
|
||||
__wasi_timestamp_t timeout;
|
||||
__wasi_timestamp_t precision;
|
||||
__wasi_subclockflags_t flags;
|
||||
} clock;
|
||||
struct __wasi_subscription_u_fd_readwrite_t {
|
||||
__wasi_fd_t fd;
|
||||
} fd_readwrite;
|
||||
} u;
|
||||
} __wasi_subscription_t;
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, userdata) == 0, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, type) == 8, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.clock.identifier) == 16,
|
||||
"non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.clock.clock_id) == 24,
|
||||
"non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.clock.timeout) == 32, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.clock.precision) == 40,
|
||||
"non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.clock.flags) == 48, "non-wasi data layout");
|
||||
_Static_assert(
|
||||
offsetof(__wasi_subscription_t, u.fd_readwrite.fd) == 16,
|
||||
"non-wasi data layout");
|
||||
_Static_assert(sizeof(__wasi_subscription_t) == 56, "non-wasi data layout");
|
||||
_Static_assert(_Alignof(__wasi_subscription_t) == 8, "non-wasi data layout");
|
||||
|
||||
#if defined(WASMTIME_SSP_WASI_API)
|
||||
#define WASMTIME_SSP_SYSCALL_NAME(name) \
|
||||
asm("__wasi_" #name)
|
||||
#else
|
||||
#define WASMTIME_SSP_SYSCALL_NAME(name)
|
||||
#endif
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_args_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct argv_environ_values *arg_environ,
|
||||
#endif
|
||||
char **argv,
|
||||
char *argv_buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(args_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_args_sizes_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct argv_environ_values *arg_environ,
|
||||
#endif
|
||||
size_t *argc,
|
||||
size_t *argv_buf_size
|
||||
) WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_clock_res_get(
|
||||
__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t *resolution
|
||||
) WASMTIME_SSP_SYSCALL_NAME(clock_res_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_clock_time_get(
|
||||
__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t precision,
|
||||
__wasi_timestamp_t *time
|
||||
) WASMTIME_SSP_SYSCALL_NAME(clock_time_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_environ_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct argv_environ_values *arg_environ,
|
||||
#endif
|
||||
char **environ,
|
||||
char *environ_buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(environ_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_environ_sizes_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct argv_environ_values *arg_environ,
|
||||
#endif
|
||||
size_t *environ_count,
|
||||
size_t *environ_buf_size
|
||||
) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_prestat_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_prestats *prestats,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_prestat_t *buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_prestats *prestats,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
char *path,
|
||||
size_t path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_close(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
struct fd_prestats *prestats,
|
||||
#endif
|
||||
__wasi_fd_t fd
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_datasync(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_pread(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const __wasi_iovec_t *iovs,
|
||||
size_t iovs_len,
|
||||
__wasi_filesize_t offset,
|
||||
size_t *nread
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_pwrite(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const __wasi_ciovec_t *iovs,
|
||||
size_t iovs_len,
|
||||
__wasi_filesize_t offset,
|
||||
size_t *nwritten
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_read(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const __wasi_iovec_t *iovs,
|
||||
size_t iovs_len,
|
||||
size_t *nread
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_renumber(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
struct fd_prestats *prestats,
|
||||
#endif
|
||||
__wasi_fd_t from,
|
||||
__wasi_fd_t to
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_seek(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filedelta_t offset,
|
||||
__wasi_whence_t whence,
|
||||
__wasi_filesize_t *newoffset
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_tell(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filesize_t *newoffset
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_fdstat_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_fdstat_t *buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_fdflags_t flags
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_rights_t fs_rights_base,
|
||||
__wasi_rights_t fs_rights_inheriting
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_sync(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_write(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const __wasi_ciovec_t *iovs,
|
||||
size_t iovs_len,
|
||||
size_t *nwritten
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_advise(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filesize_t offset,
|
||||
__wasi_filesize_t len,
|
||||
__wasi_advice_t advice
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_allocate(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filesize_t offset,
|
||||
__wasi_filesize_t len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_create_directory(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const char *path,
|
||||
size_t path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_link(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t old_fd,
|
||||
__wasi_lookupflags_t old_flags,
|
||||
const char *old_path,
|
||||
size_t old_path_len,
|
||||
__wasi_fd_t new_fd,
|
||||
const char *new_path,
|
||||
size_t new_path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_open(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t dirfd,
|
||||
__wasi_lookupflags_t dirflags,
|
||||
const char *path,
|
||||
size_t path_len,
|
||||
__wasi_oflags_t oflags,
|
||||
__wasi_rights_t fs_rights_base,
|
||||
__wasi_rights_t fs_rights_inheriting,
|
||||
__wasi_fdflags_t fs_flags,
|
||||
__wasi_fd_t *fd
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_readdir(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
void *buf,
|
||||
size_t buf_len,
|
||||
__wasi_dircookie_t cookie,
|
||||
size_t *bufused
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_readlink(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const char *path,
|
||||
size_t path_len,
|
||||
char *buf,
|
||||
size_t buf_len,
|
||||
size_t *bufused
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_rename(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t old_fd,
|
||||
const char *old_path,
|
||||
size_t old_path_len,
|
||||
__wasi_fd_t new_fd,
|
||||
const char *new_path,
|
||||
size_t new_path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_filestat_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filestat_t *buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_filestat_set_times(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_timestamp_t st_atim,
|
||||
__wasi_timestamp_t st_mtim,
|
||||
__wasi_fstflags_t fstflags
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_fd_filestat_set_size(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_filesize_t st_size
|
||||
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_filestat_get(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_lookupflags_t flags,
|
||||
const char *path,
|
||||
size_t path_len,
|
||||
__wasi_filestat_t *buf
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_filestat_set_times(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
__wasi_lookupflags_t flags,
|
||||
const char *path,
|
||||
size_t path_len,
|
||||
__wasi_timestamp_t st_atim,
|
||||
__wasi_timestamp_t st_mtim,
|
||||
__wasi_fstflags_t fstflags
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_symlink(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
const char *old_path,
|
||||
size_t old_path_len,
|
||||
__wasi_fd_t fd,
|
||||
const char *new_path,
|
||||
size_t new_path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_unlink_file(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const char *path,
|
||||
size_t path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_path_remove_directory(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t fd,
|
||||
const char *path,
|
||||
size_t path_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_poll_oneoff(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
const __wasi_subscription_t *in,
|
||||
__wasi_event_t *out,
|
||||
size_t nsubscriptions,
|
||||
size_t *nevents
|
||||
) WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) __attribute__((__warn_unused_result__));
|
||||
|
||||
_Noreturn void wasmtime_ssp_proc_exit(
|
||||
__wasi_exitcode_t rval
|
||||
) WASMTIME_SSP_SYSCALL_NAME(proc_exit);
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_proc_raise(
|
||||
__wasi_signal_t sig
|
||||
) WASMTIME_SSP_SYSCALL_NAME(proc_raise) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_random_get(
|
||||
void *buf,
|
||||
size_t buf_len
|
||||
) WASMTIME_SSP_SYSCALL_NAME(random_get) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_sock_recv(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t sock,
|
||||
const __wasi_iovec_t *ri_data,
|
||||
size_t ri_data_len,
|
||||
__wasi_riflags_t ri_flags,
|
||||
size_t *ro_datalen,
|
||||
__wasi_roflags_t *ro_flags
|
||||
) WASMTIME_SSP_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_sock_send(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t sock,
|
||||
const __wasi_ciovec_t *si_data,
|
||||
size_t si_data_len,
|
||||
__wasi_siflags_t si_flags,
|
||||
size_t *so_datalen
|
||||
) WASMTIME_SSP_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_sock_shutdown(
|
||||
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
|
||||
struct fd_table *curfds,
|
||||
#endif
|
||||
__wasi_fd_t sock,
|
||||
__wasi_sdflags_t how
|
||||
) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__));
|
||||
|
||||
__wasi_errno_t wasmtime_ssp_sched_yield(void)
|
||||
WASMTIME_SSP_SYSCALL_NAME(sched_yield) __attribute__((__warn_unused_result__));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef WASMTIME_SSP_SYSCALL_NAME
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,24 @@
|
||||
All code is distributed under the following license:
|
||||
|
||||
Copyright (c) 2015 Nuxi, https://nuxi.nl/
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
@ -0,0 +1,14 @@
|
||||
This directory consists of selected files copied from the [libemulator]
|
||||
directory in the [cloudabi-utils] repository, with minor modifications,
|
||||
along with the accompanying LICENSE file from that repository.
|
||||
|
||||
The modifications are marked with `WASMTIME_*` preprocessor macros.
|
||||
|
||||
The files were copied at git revision
|
||||
223dadc53248552db43e012c67ed08cf416a2b12
|
||||
which is dated
|
||||
Tue Jun 25 17:22:07 2019 -0700
|
||||
.
|
||||
|
||||
[libemulator]: https://github.com/NuxiNL/cloudabi-utils/tree/master/src/libemulator
|
||||
[cloudabi-utils]: https://github.com/NuxiNL/cloudabi-utils
|
||||
@ -0,0 +1,100 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__)
|
||||
#define CONFIG_HAS_ARC4RANDOM_BUF 1
|
||||
#else
|
||||
#define CONFIG_HAS_ARC4RANDOM_BUF 0
|
||||
#endif
|
||||
|
||||
// On Linux, prefer to use getrandom, though it isn't available in
|
||||
// GLIBC before 2.25.
|
||||
#if defined(__linux__) && \
|
||||
(!defined(__GLIBC__) || \
|
||||
__GLIBC__ > 2 || \
|
||||
(__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
|
||||
#define CONFIG_HAS_GETRANDOM 1
|
||||
#else
|
||||
#define CONFIG_HAS_GETRANDOM 0
|
||||
#endif
|
||||
|
||||
#if defined(__CloudABI__)
|
||||
#define CONFIG_HAS_CAP_ENTER 1
|
||||
#else
|
||||
#define CONFIG_HAS_CAP_ENTER 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__EMSCRIPTEN__)
|
||||
#define CONFIG_HAS_CLOCK_NANOSLEEP 1
|
||||
#else
|
||||
#define CONFIG_HAS_CLOCK_NANOSLEEP 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__FreeBSD__)
|
||||
#define CONFIG_HAS_FDATASYNC 1
|
||||
#else
|
||||
#define CONFIG_HAS_FDATASYNC 0
|
||||
#endif
|
||||
|
||||
#ifndef __CloudABI__
|
||||
#define CONFIG_HAS_ISATTY 1
|
||||
#else
|
||||
#define CONFIG_HAS_ISATTY 0
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 1
|
||||
#else
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 0
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define CONFIG_HAS_PREADV 1
|
||||
#else
|
||||
#define CONFIG_HAS_PREADV 0
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(__CloudABI__)
|
||||
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1
|
||||
#else
|
||||
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
|
||||
#else
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define CONFIG_HAS_PWRITEV 1
|
||||
#else
|
||||
#define CONFIG_HAS_PWRITEV 0
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define st_atimespec st_atim
|
||||
#define st_mtimespec st_mtim
|
||||
#define st_ctimespec st_ctim
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define CONFIG_TLS_USE_GSBASE 1
|
||||
#else
|
||||
#define CONFIG_TLS_USE_GSBASE 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,215 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef LOCKING_H
|
||||
#define LOCKING_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef __has_extension
|
||||
#define __has_extension(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_extension(c_thread_safety_attributes)
|
||||
#define LOCK_ANNOTATE(x) __attribute__((x))
|
||||
#else
|
||||
#define LOCK_ANNOTATE(x)
|
||||
#endif
|
||||
|
||||
// Lock annotation macros.
|
||||
|
||||
#define LOCKABLE LOCK_ANNOTATE(lockable)
|
||||
|
||||
#define LOCKS_EXCLUSIVE(...) LOCK_ANNOTATE(exclusive_lock_function(__VA_ARGS__))
|
||||
#define LOCKS_SHARED(...) LOCK_ANNOTATE(shared_lock_function(__VA_ARGS__))
|
||||
|
||||
#define TRYLOCKS_EXCLUSIVE(...) \
|
||||
LOCK_ANNOTATE(exclusive_trylock_function(__VA_ARGS__))
|
||||
#define TRYLOCKS_SHARED(...) LOCK_ANNOTATE(shared_trylock_function(__VA_ARGS__))
|
||||
|
||||
#define UNLOCKS(...) LOCK_ANNOTATE(unlock_function(__VA_ARGS__))
|
||||
|
||||
#define REQUIRES_EXCLUSIVE(...) \
|
||||
LOCK_ANNOTATE(exclusive_locks_required(__VA_ARGS__))
|
||||
#define REQUIRES_SHARED(...) LOCK_ANNOTATE(shared_locks_required(__VA_ARGS__))
|
||||
#define REQUIRES_UNLOCKED(...) LOCK_ANNOTATE(locks_excluded(__VA_ARGS__))
|
||||
|
||||
#define NO_LOCK_ANALYSIS LOCK_ANNOTATE(no_thread_safety_analysis)
|
||||
|
||||
// Mutex that uses the lock annotations.
|
||||
|
||||
struct LOCKABLE mutex {
|
||||
pthread_mutex_t object;
|
||||
};
|
||||
|
||||
#define MUTEX_INITIALIZER \
|
||||
{ PTHREAD_MUTEX_INITIALIZER }
|
||||
|
||||
static inline void mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock) {
|
||||
pthread_mutex_init(&lock->object, NULL);
|
||||
}
|
||||
|
||||
static inline void mutex_destroy(struct mutex *lock) REQUIRES_UNLOCKED(*lock) {
|
||||
pthread_mutex_destroy(&lock->object);
|
||||
}
|
||||
|
||||
static inline void mutex_lock(struct mutex *lock)
|
||||
LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_mutex_lock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void mutex_unlock(struct mutex *lock)
|
||||
UNLOCKS(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_mutex_unlock(&lock->object);
|
||||
}
|
||||
|
||||
// Read-write lock that uses the lock annotations.
|
||||
|
||||
struct LOCKABLE rwlock {
|
||||
pthread_rwlock_t object;
|
||||
};
|
||||
|
||||
static inline void rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock) {
|
||||
pthread_rwlock_init(&lock->object, NULL);
|
||||
}
|
||||
|
||||
static inline void rwlock_rdlock(struct rwlock *lock)
|
||||
LOCKS_SHARED(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_rwlock_rdlock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void rwlock_wrlock(struct rwlock *lock)
|
||||
LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_rwlock_wrlock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void rwlock_unlock(struct rwlock *lock)
|
||||
UNLOCKS(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_rwlock_unlock(&lock->object);
|
||||
}
|
||||
|
||||
// Condition variable that uses the lock annotations.
|
||||
|
||||
struct LOCKABLE cond {
|
||||
pthread_cond_t object;
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
clockid_t clock;
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline void cond_init_monotonic(struct cond *cond) {
|
||||
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
|
||||
pthread_condattr_t attr;
|
||||
pthread_condattr_init(&attr);
|
||||
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
|
||||
pthread_cond_init(&cond->object, &attr);
|
||||
pthread_condattr_destroy(&attr);
|
||||
#else
|
||||
pthread_cond_init(&cond->object, NULL);
|
||||
#endif
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
cond->clock = CLOCK_MONOTONIC;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void cond_init_realtime(struct cond *cond) {
|
||||
pthread_cond_init(&cond->object, NULL);
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
cond->clock = CLOCK_REALTIME;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void cond_destroy(struct cond *cond) {
|
||||
pthread_cond_destroy(&cond->object);
|
||||
}
|
||||
|
||||
static inline void cond_signal(struct cond *cond) {
|
||||
pthread_cond_signal(&cond->object);
|
||||
}
|
||||
|
||||
static inline bool cond_timedwait(struct cond *cond, struct mutex *lock,
|
||||
uint64_t timeout, bool abstime)
|
||||
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
|
||||
struct timespec ts = {
|
||||
.tv_sec = (time_t)(timeout / 1000000000),
|
||||
.tv_nsec = (long)(timeout % 1000000000),
|
||||
};
|
||||
|
||||
if (abstime) {
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
|
||||
// No native support for sleeping on monotonic clocks. Convert the
|
||||
// timeout to a relative value and then to an absolute value for the
|
||||
// realtime clock.
|
||||
if (cond->clock != CLOCK_REALTIME) {
|
||||
struct timespec ts_monotonic;
|
||||
clock_gettime(cond->clock, &ts_monotonic);
|
||||
ts.tv_sec -= ts_monotonic.tv_sec;
|
||||
ts.tv_nsec -= ts_monotonic.tv_nsec;
|
||||
if (ts.tv_nsec < 0) {
|
||||
ts.tv_nsec += 1000000000;
|
||||
--ts.tv_sec;
|
||||
}
|
||||
|
||||
struct timespec ts_realtime;
|
||||
clock_gettime(CLOCK_REALTIME, &ts_realtime);
|
||||
ts.tv_sec += ts_realtime.tv_sec;
|
||||
ts.tv_nsec += ts_realtime.tv_nsec;
|
||||
if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_nsec -= 1000000000;
|
||||
++ts.tv_sec;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
// Implementation supports relative timeouts.
|
||||
int ret =
|
||||
pthread_cond_timedwait_relative_np(&cond->object, &lock->object, &ts);
|
||||
assert((ret == 0 || ret == ETIMEDOUT) &&
|
||||
"pthread_cond_timedwait_relative_np() failed");
|
||||
return ret == ETIMEDOUT;
|
||||
#else
|
||||
// Convert to absolute timeout.
|
||||
struct timespec ts_now;
|
||||
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
|
||||
clock_gettime(cond->clock, &ts_now);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &ts_now);
|
||||
#endif
|
||||
ts.tv_sec += ts_now.tv_sec;
|
||||
ts.tv_nsec += ts_now.tv_nsec;
|
||||
if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_nsec -= 1000000000;
|
||||
++ts.tv_sec;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int ret = pthread_cond_timedwait(&cond->object, &lock->object, &ts);
|
||||
assert((ret == 0 || ret == ETIMEDOUT) && "pthread_cond_timedwait() failed");
|
||||
return ret == ETIMEDOUT;
|
||||
}
|
||||
|
||||
static inline void cond_wait(struct cond *cond, struct mutex *lock)
|
||||
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
|
||||
pthread_cond_wait(&cond->object, &lock->object);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,42 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2015 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef COMMON_LIMITS_H
|
||||
#define COMMON_LIMITS_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define NUMERIC_MIN(t) \
|
||||
_Generic((t)0, char \
|
||||
: CHAR_MIN, signed char \
|
||||
: SCHAR_MIN, unsigned char : 0, short \
|
||||
: SHRT_MIN, unsigned short : 0, int \
|
||||
: INT_MIN, unsigned int : 0, long \
|
||||
: LONG_MIN, unsigned long : 0, long long \
|
||||
: LLONG_MIN, unsigned long long : 0, default \
|
||||
: (void)0)
|
||||
|
||||
#define NUMERIC_MAX(t) \
|
||||
_Generic((t)0, char \
|
||||
: CHAR_MAX, signed char \
|
||||
: SCHAR_MAX, unsigned char \
|
||||
: UCHAR_MAX, short \
|
||||
: SHRT_MAX, unsigned short \
|
||||
: USHRT_MAX, int \
|
||||
: INT_MAX, unsigned int \
|
||||
: UINT_MAX, long \
|
||||
: LONG_MAX, unsigned long \
|
||||
: ULONG_MAX, long long \
|
||||
: LLONG_MAX, unsigned long long \
|
||||
: ULLONG_MAX, default \
|
||||
: (void)0)
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,62 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016-2018 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef POSIX_H
|
||||
#define POSIX_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "locking.h"
|
||||
|
||||
struct fd_entry;
|
||||
struct fd_prestat;
|
||||
struct syscalls;
|
||||
|
||||
struct fd_table {
|
||||
struct rwlock lock;
|
||||
struct fd_entry *entries;
|
||||
size_t size;
|
||||
size_t used;
|
||||
};
|
||||
|
||||
struct fd_prestats {
|
||||
struct rwlock lock;
|
||||
struct fd_prestat *prestats;
|
||||
size_t size;
|
||||
size_t used;
|
||||
};
|
||||
|
||||
struct argv_environ_values {
|
||||
size_t argc;
|
||||
size_t argv_buf_size;
|
||||
char **argv;
|
||||
char *argv_buf;
|
||||
size_t environ_count;
|
||||
size_t environ_buf_size;
|
||||
char **environ;
|
||||
char *environ_buf;
|
||||
};
|
||||
|
||||
void fd_table_init(struct fd_table *);
|
||||
bool fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
|
||||
void fd_prestats_init(struct fd_prestats *);
|
||||
bool fd_prestats_insert(struct fd_prestats *, const char *, __wasi_fd_t);
|
||||
bool argv_environ_init(struct argv_environ_values *,
|
||||
const size_t *argv_offsets, size_t argv_offsets_len,
|
||||
const char *argv_buf, size_t argv_buf_len,
|
||||
const size_t *environ_offsets, size_t environ_offsets_len,
|
||||
const char *environ_buf, size_t environ_buf_len);
|
||||
void argv_environ_destroy(struct argv_environ_values *argv_environ);
|
||||
void fd_table_destroy(struct fd_table *ft);
|
||||
void fd_prestats_destroy(struct fd_prestats *pt);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,92 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef QUEUE_H
|
||||
#define QUEUE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// LIST: Double-linked list.
|
||||
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *l_first; \
|
||||
}
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *l_next; \
|
||||
struct type **l_prev; \
|
||||
}
|
||||
|
||||
#define LIST_FOREACH(var, head, field) \
|
||||
for ((var) = (head)->l_first; (var) != NULL; (var) = (var)->field.l_next)
|
||||
#define LIST_INIT(head) \
|
||||
do { \
|
||||
(head)->l_first = NULL; \
|
||||
} while (0)
|
||||
#define LIST_INSERT_HEAD(head, element, field) \
|
||||
do { \
|
||||
(element)->field.l_next = (head)->l_first; \
|
||||
if ((head)->l_first != NULL) \
|
||||
(head)->l_first->field.l_prev = &(element)->field.l_next; \
|
||||
(head)->l_first = (element); \
|
||||
(element)->field.l_prev = &(head)->l_first; \
|
||||
} while (0)
|
||||
#define LIST_REMOVE(element, field) \
|
||||
do { \
|
||||
if ((element)->field.l_next != NULL) \
|
||||
(element)->field.l_next->field.l_prev = (element)->field.l_prev; \
|
||||
*(element)->field.l_prev = (element)->field.l_next; \
|
||||
} while (0)
|
||||
|
||||
// TAILQ: Double-linked list with tail pointer.
|
||||
|
||||
#define TAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *t_first; \
|
||||
struct type **t_last; \
|
||||
}
|
||||
|
||||
#define TAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *t_next; \
|
||||
struct type **t_prev; \
|
||||
}
|
||||
|
||||
#define TAILQ_EMPTY(head) ((head)->t_first == NULL)
|
||||
#define TAILQ_FIRST(head) ((head)->t_first)
|
||||
#define TAILQ_FOREACH(var, head, field) \
|
||||
for ((var) = (head)->t_first; (var) != NULL; (var) = (var)->field.t_next)
|
||||
#define TAILQ_INIT(head) \
|
||||
do { \
|
||||
(head)->t_first = NULL; \
|
||||
(head)->t_last = &(head)->t_first; \
|
||||
} while (0)
|
||||
#define TAILQ_INSERT_TAIL(head, elm, field) \
|
||||
do { \
|
||||
(elm)->field.t_next = NULL; \
|
||||
(elm)->field.t_prev = (head)->t_last; \
|
||||
*(head)->t_last = (elm); \
|
||||
(head)->t_last = &(elm)->field.t_next; \
|
||||
} while (0)
|
||||
#define TAILQ_REMOVE(head, element, field) \
|
||||
do { \
|
||||
if ((element)->field.t_next != NULL) \
|
||||
(element)->field.t_next->field.t_prev = (element)->field.t_prev; \
|
||||
else \
|
||||
(head)->t_last = (element)->field.t_prev; \
|
||||
*(element)->field.t_prev = (element)->field.t_next; \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,92 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "random.h"
|
||||
|
||||
#if CONFIG_HAS_ARC4RANDOM_BUF
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
arc4random_buf(buf, len);
|
||||
}
|
||||
|
||||
#elif CONFIG_HAS_GETRANDOM
|
||||
|
||||
#include <sys/random.h>
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
for (;;) {
|
||||
ssize_t x = getrandom(buf, len, 0);
|
||||
if (x < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
fprintf(stderr, "getrandom failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
if (x == len)
|
||||
return;
|
||||
buf = (void *)((unsigned char *)buf + x);
|
||||
len -= x;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int urandom;
|
||||
|
||||
static void open_urandom(void) {
|
||||
urandom = open("/dev/urandom", O_RDONLY);
|
||||
if (urandom < 0) {
|
||||
fputs("Failed to open /dev/urandom\n", stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
|
||||
pthread_once(&open_once, open_urandom);
|
||||
|
||||
if ((size_t)read(urandom, buf, len) != len) {
|
||||
fputs("Short read on /dev/urandom\n", stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Calculates a random number within the range [0, upper - 1] without
|
||||
// any modulo bias.
|
||||
//
|
||||
// The function below repeatedly obtains a random number from
|
||||
// arc4random() until it lies within the range [2^k % upper, 2^k). As
|
||||
// this range has length k * upper, we can safely obtain a number
|
||||
// without any modulo bias.
|
||||
uintmax_t random_uniform(uintmax_t upper) {
|
||||
// Compute 2^k % upper
|
||||
// == (2^k - upper) % upper
|
||||
// == -upper % upper.
|
||||
uintmax_t lower = -upper % upper;
|
||||
for (;;) {
|
||||
uintmax_t value;
|
||||
random_buf(&value, sizeof(value));
|
||||
if (value >= lower)
|
||||
return value % upper;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void random_buf(void *, size_t);
|
||||
uintmax_t random_uniform(uintmax_t);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,47 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef REFCOUNT_H
|
||||
#define REFCOUNT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "locking.h"
|
||||
|
||||
// Simple reference counter.
|
||||
struct LOCKABLE refcount {
|
||||
atomic_uint count;
|
||||
};
|
||||
|
||||
#define PRODUCES(...) LOCKS_SHARED(__VA_ARGS__) NO_LOCK_ANALYSIS
|
||||
#define CONSUMES(...) UNLOCKS(__VA_ARGS__) NO_LOCK_ANALYSIS
|
||||
|
||||
// Initialize the reference counter.
|
||||
static void refcount_init(struct refcount *r, unsigned int count) PRODUCES(*r) {
|
||||
atomic_init(&r->count, count);
|
||||
}
|
||||
|
||||
// Increment the reference counter.
|
||||
static inline void refcount_acquire(struct refcount *r) PRODUCES(*r) {
|
||||
atomic_fetch_add_explicit(&r->count, 1, memory_order_acquire);
|
||||
}
|
||||
|
||||
// Decrement the reference counter, returning whether the reference
|
||||
// dropped to zero.
|
||||
static inline bool refcount_release(struct refcount *r) CONSUMES(*r) {
|
||||
int old = (int)atomic_fetch_sub_explicit(&r->count, 1, memory_order_release);
|
||||
assert(old != 0 && "Reference count becoming negative");
|
||||
return old == 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,83 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef RIGHTS_H
|
||||
#define RIGHTS_H
|
||||
|
||||
#define RIGHTS_ALL \
|
||||
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
|
||||
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
|
||||
__WASI_RIGHT_FD_SYNC | __WASI_RIGHT_FD_TELL | __WASI_RIGHT_FD_WRITE | \
|
||||
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_ALLOCATE | \
|
||||
__WASI_RIGHT_PATH_CREATE_DIRECTORY | __WASI_RIGHT_PATH_CREATE_FILE | \
|
||||
__WASI_RIGHT_PATH_LINK_SOURCE | __WASI_RIGHT_PATH_LINK_TARGET | \
|
||||
__WASI_RIGHT_PATH_OPEN | __WASI_RIGHT_FD_READDIR | \
|
||||
__WASI_RIGHT_PATH_READLINK | __WASI_RIGHT_PATH_RENAME_SOURCE | \
|
||||
__WASI_RIGHT_PATH_RENAME_TARGET | __WASI_RIGHT_PATH_FILESTAT_GET | \
|
||||
__WASI_RIGHT_PATH_FILESTAT_SET_SIZE | \
|
||||
__WASI_RIGHT_PATH_FILESTAT_SET_TIMES | \
|
||||
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_TIMES | \
|
||||
__WASI_RIGHT_FD_FILESTAT_SET_SIZE | \
|
||||
__WASI_RIGHT_PATH_SYMLINK | __WASI_RIGHT_PATH_UNLINK_FILE | \
|
||||
__WASI_RIGHT_PATH_REMOVE_DIRECTORY | \
|
||||
__WASI_RIGHT_POLL_FD_READWRITE | __WASI_RIGHT_SOCK_SHUTDOWN)
|
||||
|
||||
// Block and character device interaction is outside the scope of
|
||||
// CloudABI. Simply allow everything.
|
||||
#define RIGHTS_BLOCK_DEVICE_BASE RIGHTS_ALL
|
||||
#define RIGHTS_BLOCK_DEVICE_INHERITING RIGHTS_ALL
|
||||
#define RIGHTS_CHARACTER_DEVICE_BASE RIGHTS_ALL
|
||||
#define RIGHTS_CHARACTER_DEVICE_INHERITING RIGHTS_ALL
|
||||
|
||||
// Only allow directory operations on directories. Directories can only
|
||||
// yield file descriptors to other directories and files.
|
||||
#define RIGHTS_DIRECTORY_BASE \
|
||||
(__WASI_RIGHT_FD_FDSTAT_SET_FLAGS | __WASI_RIGHT_FD_SYNC | \
|
||||
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_PATH_CREATE_DIRECTORY | \
|
||||
__WASI_RIGHT_PATH_CREATE_FILE | __WASI_RIGHT_PATH_LINK_SOURCE | \
|
||||
__WASI_RIGHT_PATH_LINK_TARGET | __WASI_RIGHT_PATH_OPEN | \
|
||||
__WASI_RIGHT_FD_READDIR | __WASI_RIGHT_PATH_READLINK | \
|
||||
__WASI_RIGHT_PATH_RENAME_SOURCE | __WASI_RIGHT_PATH_RENAME_TARGET | \
|
||||
__WASI_RIGHT_PATH_FILESTAT_GET | \
|
||||
__WASI_RIGHT_PATH_FILESTAT_SET_SIZE | \
|
||||
__WASI_RIGHT_PATH_FILESTAT_SET_TIMES | \
|
||||
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_TIMES | \
|
||||
__WASI_RIGHT_PATH_SYMLINK | __WASI_RIGHT_PATH_UNLINK_FILE | \
|
||||
__WASI_RIGHT_PATH_REMOVE_DIRECTORY | \
|
||||
__WASI_RIGHT_POLL_FD_READWRITE)
|
||||
#define RIGHTS_DIRECTORY_INHERITING \
|
||||
(RIGHTS_DIRECTORY_BASE | RIGHTS_REGULAR_FILE_BASE)
|
||||
|
||||
// Operations that apply to regular files.
|
||||
#define RIGHTS_REGULAR_FILE_BASE \
|
||||
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
|
||||
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
|
||||
__WASI_RIGHT_FD_SYNC | __WASI_RIGHT_FD_TELL | __WASI_RIGHT_FD_WRITE | \
|
||||
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_ALLOCATE | \
|
||||
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_SIZE | \
|
||||
__WASI_RIGHT_FD_FILESTAT_SET_TIMES | __WASI_RIGHT_POLL_FD_READWRITE)
|
||||
#define RIGHTS_REGULAR_FILE_INHERITING 0
|
||||
|
||||
// Operations that apply to sockets and socket pairs.
|
||||
#define RIGHTS_SOCKET_BASE \
|
||||
(__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
|
||||
__WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_FILESTAT_GET | \
|
||||
__WASI_RIGHT_POLL_FD_READWRITE | __WASI_RIGHT_SOCK_SHUTDOWN)
|
||||
#define RIGHTS_SOCKET_INHERITING RIGHTS_ALL
|
||||
|
||||
// Operations that apply to TTYs.
|
||||
#define RIGHTS_TTY_BASE \
|
||||
(__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
|
||||
__WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_FILESTAT_GET | \
|
||||
__WASI_RIGHT_POLL_FD_READWRITE)
|
||||
#define RIGHTS_TTY_INHERITING 0
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,17 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef SIGNALS_H
|
||||
#define SIGNALS_H
|
||||
|
||||
void signals_init(void);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,33 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "str.h"
|
||||
|
||||
char *str_nullterminate(const char *s, size_t len) {
|
||||
// Copy string.
|
||||
char *ret = strndup(s, len);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
// Ensure that it contains no null bytes within.
|
||||
if (strlen(ret) != len) {
|
||||
free(ret);
|
||||
errno = EILSEQ;
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
// for license information.
|
||||
//
|
||||
// The upstream file contains the following copyright notice:
|
||||
//
|
||||
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
|
||||
|
||||
#ifndef STR_H
|
||||
#define STR_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
char *str_nullterminate(const char *, size_t);
|
||||
|
||||
#endif
|
||||
12
core/iwasm/runtime/wasmtime-wasi-c/wasi.cmake
Normal file
12
core/iwasm/runtime/wasmtime-wasi-c/wasi.cmake
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASI_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
if (WASM_ENABLE_WASI EQUAL 1)
|
||||
include_directories(${WASI_LIB_DIR}/sandboxed-system-primitives/include
|
||||
${WASI_LIB_DIR}/sandboxed-system-primitives/src
|
||||
)
|
||||
file (GLOB_RECURSE source_all ${WASI_LIB_DIR}/sandboxed-system-primitives/*.c )
|
||||
set (WASI_LIB_SOURCE ${source_all})
|
||||
endif ()
|
||||
Reference in New Issue
Block a user