Apply clang-format for core/iwasm compilation and libraries (#784)
Apply clang-format for core/iwasm/compilation and core/iwasm/libraries files. Add wasm-c-api empty_imports sample to workflow test. And enable triggering workflow when core/config.h changes.
This commit is contained in:
@ -59,14 +59,13 @@ control_thread_routine(void *arg)
|
||||
control_thread->debug_engine = g_debug_engine;
|
||||
control_thread->debug_instance = debug_inst;
|
||||
strcpy(control_thread->ip_addr, g_debug_engine->ip_addr);
|
||||
control_thread->port =
|
||||
g_debug_engine->process_base_port + debug_inst->id;
|
||||
control_thread->port = g_debug_engine->process_base_port + debug_inst->id;
|
||||
|
||||
LOG_WARNING("control thread of debug object %p start at %s:%d\n",
|
||||
debug_inst, control_thread->ip_addr, control_thread->port);
|
||||
|
||||
control_thread->server =
|
||||
wasm_launch_gdbserver(control_thread->ip_addr, control_thread->port);
|
||||
wasm_launch_gdbserver(control_thread->ip_addr, control_thread->port);
|
||||
if (!control_thread->server) {
|
||||
LOG_ERROR("Failed to create debug server\n");
|
||||
os_cond_signal(&exec_env->wait_cond);
|
||||
@ -110,7 +109,7 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance)
|
||||
bh_assert(exec_env);
|
||||
|
||||
if (!(control_thread =
|
||||
wasm_runtime_malloc(sizeof(WASMDebugControlThread)))) {
|
||||
wasm_runtime_malloc(sizeof(WASMDebugControlThread)))) {
|
||||
LOG_ERROR("WASM Debug Engine error: failed to allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
@ -123,8 +122,9 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance)
|
||||
|
||||
os_mutex_lock(&exec_env->wait_lock);
|
||||
|
||||
if (0 != os_thread_create(&control_thread->tid, control_thread_routine,
|
||||
debug_instance, APP_THREAD_STACK_SIZE_MAX)) {
|
||||
if (0
|
||||
!= os_thread_create(&control_thread->tid, control_thread_routine,
|
||||
debug_instance, APP_THREAD_STACK_SIZE_MAX)) {
|
||||
os_mutex_unlock(&control_thread->wait_lock);
|
||||
goto fail1;
|
||||
}
|
||||
@ -153,8 +153,7 @@ wasm_debug_control_thread_destroy(WASMDebugInstance *debug_instance)
|
||||
{
|
||||
WASMDebugControlThread *control_thread = debug_instance->control_thread;
|
||||
LOG_VERBOSE("control thread of debug object %p stop at %s:%d\n",
|
||||
debug_instance, control_thread->ip_addr,
|
||||
control_thread->port);
|
||||
debug_instance, control_thread->ip_addr, control_thread->port);
|
||||
control_thread->status = STOPPED;
|
||||
os_mutex_lock(&control_thread->wait_lock);
|
||||
wasm_close_gdbserver(control_thread->server);
|
||||
@ -200,9 +199,9 @@ wasm_debug_engine_init(char *ip_addr, int platform_port, int process_port)
|
||||
if (g_debug_engine) {
|
||||
process_port -= 1;
|
||||
g_debug_engine->platform_port =
|
||||
platform_port > 0 ? platform_port : 1234;
|
||||
platform_port > 0 ? platform_port : 1234;
|
||||
g_debug_engine->process_base_port =
|
||||
process_port > 0 ? process_port : 6169;
|
||||
process_port > 0 ? process_port : 6169;
|
||||
if (ip_addr)
|
||||
sprintf(g_debug_engine->ip_addr, "%s", ip_addr);
|
||||
else
|
||||
@ -277,7 +276,7 @@ static WASMDebugInstance *
|
||||
wasm_cluster_get_debug_instance(WASMDebugEngine *engine, WASMCluster *cluster)
|
||||
{
|
||||
WASMDebugInstance *instance =
|
||||
bh_list_first_elem(&engine->debug_instance_list);
|
||||
bh_list_first_elem(&engine->debug_instance_list);
|
||||
while (instance) {
|
||||
if (instance->cluster == cluster)
|
||||
return instance;
|
||||
@ -343,8 +342,7 @@ wasm_debug_instance_get_current_env(WASMDebugInstance *instance)
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
bool
|
||||
wasm_debug_instance_get_current_object_name(WASMDebugInstance *instance,
|
||||
char name_buffer[],
|
||||
int len)
|
||||
char name_buffer[], int len)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASIArguments *wasi_args;
|
||||
@ -392,8 +390,8 @@ wasm_debug_instance_get_tid(WASMDebugInstance *instance)
|
||||
}
|
||||
|
||||
int
|
||||
wasm_debug_instance_get_tids(WASMDebugInstance *instance,
|
||||
uint64 tids[], int len)
|
||||
wasm_debug_instance_get_tids(WASMDebugInstance *instance, uint64 tids[],
|
||||
int len)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
int i = 0;
|
||||
@ -411,8 +409,8 @@ wasm_debug_instance_get_tids(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
uint64
|
||||
wasm_debug_instance_wait_thread(WASMDebugInstance *instance,
|
||||
uint64 tid, uint32 *status)
|
||||
wasm_debug_instance_wait_thread(WASMDebugInstance *instance, uint64 tid,
|
||||
uint32 *status)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMExecEnv *last_exec_env = NULL;
|
||||
@ -454,13 +452,12 @@ wasm_debug_instance_get_pc(WASMDebugInstance *instance)
|
||||
return 0;
|
||||
|
||||
exec_env = wasm_debug_instance_get_current_env(instance);
|
||||
if ((exec_env->cur_frame != NULL)
|
||||
&& (exec_env->cur_frame->ip != NULL)) {
|
||||
if ((exec_env->cur_frame != NULL) && (exec_env->cur_frame->ip != NULL)) {
|
||||
WASMModuleInstance *module_inst =
|
||||
(WASMModuleInstance *)exec_env->module_inst;
|
||||
(WASMModuleInstance *)exec_env->module_inst;
|
||||
return WASM_ADDR(
|
||||
WasmObj, instance->id,
|
||||
(exec_env->cur_frame->ip - module_inst->module->load_addr));
|
||||
WasmObj, instance->id,
|
||||
(exec_env->cur_frame->ip - module_inst->module->load_addr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -519,7 +516,8 @@ wasm_debug_instance_get_memregion(WASMDebugInstance *instance, uint64 addr)
|
||||
sprintf(mem_info->permisson, "%s", "rx");
|
||||
}
|
||||
break;
|
||||
case WasmMemory: {
|
||||
case WasmMemory:
|
||||
{
|
||||
memory = module_inst->default_memory;
|
||||
|
||||
if (memory) {
|
||||
@ -549,8 +547,8 @@ wasm_debug_instance_destroy_memregion(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
|
||||
uint64 offset, char *buf, uint64 *size)
|
||||
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance, uint64 offset,
|
||||
char *buf, uint64 *size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
@ -567,14 +565,14 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
|
||||
if (offset + *size > module_inst->module->load_size) {
|
||||
LOG_VERBOSE("wasm_debug_instance_get_data_mem size over flow!\n");
|
||||
*size = module_inst->module->load_size >= offset
|
||||
? module_inst->module->load_size - offset
|
||||
: 0;
|
||||
? module_inst->module->load_size - offset
|
||||
: 0;
|
||||
}
|
||||
|
||||
bh_memcpy_s(buf, *size, module_inst->module->load_addr + offset, *size);
|
||||
|
||||
WASMDebugBreakPoint *breakpoint =
|
||||
bh_list_first_elem(&instance->break_point_list);
|
||||
bh_list_first_elem(&instance->break_point_list);
|
||||
|
||||
while (breakpoint) {
|
||||
if (offset <= breakpoint->addr && breakpoint->addr < offset + *size) {
|
||||
@ -585,12 +583,12 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
WASMFastOPCodeNode *fast_opcode =
|
||||
bh_list_first_elem(&module_inst->module->fast_opcode_list);
|
||||
bh_list_first_elem(&module_inst->module->fast_opcode_list);
|
||||
while (fast_opcode) {
|
||||
if (offset <= fast_opcode->offset
|
||||
&& fast_opcode->offset < offset + *size) {
|
||||
*(uint8 *)(buf + (fast_opcode->offset - offset)) =
|
||||
fast_opcode->orig_op;
|
||||
fast_opcode->orig_op;
|
||||
}
|
||||
fast_opcode = bh_list_elem_next(fast_opcode);
|
||||
}
|
||||
@ -599,8 +597,8 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
|
||||
uint64 offset, char *buf, uint64 *size)
|
||||
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance, uint64 offset,
|
||||
char *buf, uint64 *size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
@ -621,8 +619,7 @@ wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
|
||||
num_bytes_per_page = memory->num_bytes_per_page;
|
||||
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
|
||||
if (offset + *size > linear_mem_size) {
|
||||
LOG_VERBOSE(
|
||||
"wasm_debug_instance_get_linear_mem size over flow!\n");
|
||||
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
|
||||
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
|
||||
}
|
||||
bh_memcpy_s(buf, *size, memory->memory_data + offset, *size);
|
||||
@ -632,8 +629,8 @@ wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
|
||||
uint64 offset, char *buf, uint64 *size)
|
||||
wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance, uint64 offset,
|
||||
char *buf, uint64 *size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
@ -654,8 +651,7 @@ wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
|
||||
num_bytes_per_page = memory->num_bytes_per_page;
|
||||
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
|
||||
if (offset + *size > linear_mem_size) {
|
||||
LOG_VERBOSE(
|
||||
"wasm_debug_instance_get_linear_mem size over flow!\n");
|
||||
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
|
||||
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
|
||||
}
|
||||
bh_memcpy_s(memory->memory_data + offset, *size, buf, *size);
|
||||
@ -665,17 +661,17 @@ wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size)
|
||||
wasm_debug_instance_get_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
|
||||
uint64 *size)
|
||||
{
|
||||
switch (WASM_ADDR_TYPE(addr)) {
|
||||
case WasmMemory:
|
||||
return wasm_debug_instance_get_linear_mem(
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
break;
|
||||
case WasmObj:
|
||||
return wasm_debug_instance_get_obj_mem(
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -683,13 +679,13 @@ wasm_debug_instance_get_mem(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_set_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size)
|
||||
wasm_debug_instance_set_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
|
||||
uint64 *size)
|
||||
{
|
||||
switch (WASM_ADDR_TYPE(addr)) {
|
||||
case WasmMemory:
|
||||
return wasm_debug_instance_set_linear_mem(
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
instance, WASM_ADDR_OFFSET(addr), buf, size);
|
||||
break;
|
||||
case WasmObj:
|
||||
default:
|
||||
@ -713,8 +709,8 @@ wasm_exec_env_get_instance(WASMExecEnv *exec_env)
|
||||
}
|
||||
|
||||
int
|
||||
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
|
||||
uint64 tid, uint64 buf[], uint64 size)
|
||||
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance, uint64 tid,
|
||||
uint64 buf[], uint64 size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
struct WASMInterpFrame *frame;
|
||||
@ -727,13 +723,13 @@ wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
|
||||
while (exec_env) {
|
||||
if (exec_env->handle == tid) {
|
||||
WASMModuleInstance *module_inst =
|
||||
(WASMModuleInstance *)exec_env->module_inst;
|
||||
(WASMModuleInstance *)exec_env->module_inst;
|
||||
frame = exec_env->cur_frame;
|
||||
while (frame && i < size) {
|
||||
if (frame->ip != NULL) {
|
||||
buf[i++] =
|
||||
WASM_ADDR(WasmObj, instance->id,
|
||||
(frame->ip - module_inst->module->load_addr));
|
||||
WASM_ADDR(WasmObj, instance->id,
|
||||
(frame->ip - module_inst->module->load_addr));
|
||||
}
|
||||
frame = frame->prev_frame;
|
||||
}
|
||||
@ -745,8 +741,8 @@ wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
|
||||
uint64 addr, uint64 length)
|
||||
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance, uint64 addr,
|
||||
uint64 length)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
@ -769,23 +765,20 @@ wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
|
||||
if (offset + sizeof(break_instr) <= module_inst->module->load_size) {
|
||||
WASMDebugBreakPoint *breakpoint;
|
||||
if (!(breakpoint =
|
||||
wasm_runtime_malloc(sizeof(WASMDebugBreakPoint)))) {
|
||||
LOG_ERROR(
|
||||
"WASM Debug Engine error: failed to allocate memory");
|
||||
wasm_runtime_malloc(sizeof(WASMDebugBreakPoint)))) {
|
||||
LOG_ERROR("WASM Debug Engine error: failed to allocate memory");
|
||||
return false;
|
||||
}
|
||||
memset(breakpoint, 0, sizeof(WASMDebugBreakPoint));
|
||||
breakpoint->addr = offset;
|
||||
/* TODO: how to if more than one breakpoints are set
|
||||
at the same addr? */
|
||||
bh_memcpy_s(&breakpoint->orignal_data,
|
||||
(uint32)sizeof(break_instr),
|
||||
bh_memcpy_s(&breakpoint->orignal_data, (uint32)sizeof(break_instr),
|
||||
module_inst->module->load_addr + offset,
|
||||
(uint32)sizeof(break_instr));
|
||||
|
||||
bh_memcpy_s(module_inst->module->load_addr + offset,
|
||||
(uint32)sizeof(break_instr),
|
||||
break_instr,
|
||||
(uint32)sizeof(break_instr), break_instr,
|
||||
(uint32)sizeof(break_instr));
|
||||
|
||||
bh_list_insert(&instance->break_point_list, breakpoint);
|
||||
@ -796,8 +789,8 @@ wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
|
||||
uint64 addr, uint64 length)
|
||||
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance, uint64 addr,
|
||||
uint64 length)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
@ -819,10 +812,9 @@ wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
|
||||
if (length >= sizeof(break_instr)) {
|
||||
if (offset + sizeof(break_instr) <= module_inst->module->load_size) {
|
||||
WASMDebugBreakPoint *breakpoint =
|
||||
bh_list_first_elem(&instance->break_point_list);
|
||||
bh_list_first_elem(&instance->break_point_list);
|
||||
while (breakpoint) {
|
||||
WASMDebugBreakPoint *next_break =
|
||||
bh_list_elem_next(breakpoint);
|
||||
WASMDebugBreakPoint *next_break = bh_list_elem_next(breakpoint);
|
||||
if (breakpoint->addr == offset) {
|
||||
/* TODO: how to if more than one breakpoints are set
|
||||
at the same addr? */
|
||||
@ -901,9 +893,8 @@ wasm_debug_instance_singlestep(WASMDebugInstance *instance, uint64 tid)
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_local(WASMDebugInstance *instance,
|
||||
int frame_index, int local_index,
|
||||
char buf[], int *size)
|
||||
wasm_debug_instance_get_local(WASMDebugInstance *instance, int frame_index,
|
||||
int local_index, char buf[], int *size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
struct WASMInterpFrame *frame;
|
||||
@ -961,9 +952,8 @@ wasm_debug_instance_get_local(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_global(WASMDebugInstance *instance,
|
||||
int frame_index, int global_index,
|
||||
char buf[], int *size)
|
||||
wasm_debug_instance_get_global(WASMDebugInstance *instance, int frame_index,
|
||||
int global_index, char buf[], int *size)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
struct WASMInterpFrame *frame;
|
||||
@ -1003,9 +993,9 @@ wasm_debug_instance_get_global(WASMDebugInstance *instance,
|
||||
global_addr = global_data + global->data_offset;
|
||||
#else
|
||||
global_addr = global->import_global_inst
|
||||
? global->import_module_inst->global_data
|
||||
+ global->import_global_inst->data_offset
|
||||
: global_data + global->data_offset;
|
||||
? global->import_module_inst->global_data
|
||||
+ global->import_global_inst->data_offset
|
||||
: global_data + global->data_offset;
|
||||
#endif
|
||||
global_type = global->type;
|
||||
|
||||
@ -1028,8 +1018,7 @@ wasm_debug_instance_get_global(WASMDebugInstance *instance,
|
||||
}
|
||||
|
||||
uint64
|
||||
wasm_debug_instance_mmap(WASMDebugInstance *instance,
|
||||
uint32 size, int map_port)
|
||||
wasm_debug_instance_mmap(WASMDebugInstance *instance, uint32 size, int map_port)
|
||||
{
|
||||
WASMExecEnv *exec_env;
|
||||
WASMModuleInstance *module_inst;
|
||||
|
||||
@ -67,10 +67,10 @@ typedef enum WasmAddressType {
|
||||
WasmInvalid = 0x03
|
||||
} WasmAddressType;
|
||||
|
||||
#define WASM_ADDR(type, id, offset) \
|
||||
#define WASM_ADDR(type, id, offset) \
|
||||
(((uint64)type << 62) | ((uint64)0 << 32) | ((uint64)offset << 0))
|
||||
|
||||
#define WASM_ADDR_TYPE(addr) (((addr)&0xC000000000000000) >> 62)
|
||||
#define WASM_ADDR_TYPE(addr) (((addr)&0xC000000000000000) >> 62)
|
||||
#define WASM_ADDR_OFFSET(addr) (((addr)&0x00000000FFFFFFFF))
|
||||
|
||||
#define INVALIED_ADDR (0xFFFFFFFFFFFFFFFF)
|
||||
@ -96,7 +96,6 @@ wasm_debug_set_engine_active(bool active);
|
||||
bool
|
||||
wasm_debug_get_engine_active(void);
|
||||
|
||||
|
||||
uint64
|
||||
wasm_debug_instance_get_pid(WASMDebugInstance *instance);
|
||||
|
||||
@ -104,8 +103,8 @@ uint64
|
||||
wasm_debug_instance_get_tid(WASMDebugInstance *instance);
|
||||
|
||||
int
|
||||
wasm_debug_instance_get_tids(WASMDebugInstance *instance,
|
||||
uint64 tids[], int len);
|
||||
wasm_debug_instance_get_tids(WASMDebugInstance *instance, uint64 tids[],
|
||||
int len);
|
||||
|
||||
void
|
||||
wasm_debug_instance_set_cur_thread(WASMDebugInstance *instance, uint64 tid);
|
||||
@ -124,32 +123,32 @@ wasm_debug_instance_destroy_memregion(WASMDebugInstance *instance,
|
||||
WASMDebugMemoryInfo *mem_info);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size);
|
||||
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance, uint64 addr,
|
||||
char *buf, uint64 *size);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size);
|
||||
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance, uint64 addr,
|
||||
char *buf, uint64 *size);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size);
|
||||
wasm_debug_instance_get_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
|
||||
uint64 *size);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_set_mem(WASMDebugInstance *instance,
|
||||
uint64 addr, char *buf, uint64 *size);
|
||||
wasm_debug_instance_set_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
|
||||
uint64 *size);
|
||||
|
||||
int
|
||||
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
|
||||
uint64 tid, uint64 buf[], uint64 size);
|
||||
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance, uint64 tid,
|
||||
uint64 buf[], uint64 size);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
|
||||
uint64 addr, uint64 length);
|
||||
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance, uint64 addr,
|
||||
uint64 length);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
|
||||
uint64 addr, uint64 length);
|
||||
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance, uint64 addr,
|
||||
uint64 length);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_continue(WASMDebugInstance *instance);
|
||||
@ -158,21 +157,19 @@ bool
|
||||
wasm_debug_instance_kill(WASMDebugInstance *instance);
|
||||
|
||||
uint64
|
||||
wasm_debug_instance_wait_thread(WASMDebugInstance *instance,
|
||||
uint64 tid, uint32 *status);
|
||||
wasm_debug_instance_wait_thread(WASMDebugInstance *instance, uint64 tid,
|
||||
uint32 *status);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_singlestep(WASMDebugInstance *instance, uint64 tid);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_local(WASMDebugInstance *instance,
|
||||
int frame_index, int local_index,
|
||||
char buf[], int *size);
|
||||
wasm_debug_instance_get_local(WASMDebugInstance *instance, int frame_index,
|
||||
int local_index, char buf[], int *size);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_get_global(WASMDebugInstance *instance,
|
||||
int frame_index, int global_index,
|
||||
char buf[], int *size);
|
||||
wasm_debug_instance_get_global(WASMDebugInstance *instance, int frame_index,
|
||||
int global_index, char buf[], int *size);
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
bool
|
||||
@ -181,8 +178,8 @@ wasm_debug_instance_get_current_object_name(WASMDebugInstance *instance,
|
||||
#endif
|
||||
|
||||
uint64
|
||||
wasm_debug_instance_mmap(WASMDebugInstance *instance,
|
||||
uint32 size, int map_port);
|
||||
wasm_debug_instance_mmap(WASMDebugInstance *instance, uint32 size,
|
||||
int map_port);
|
||||
|
||||
bool
|
||||
wasm_debug_instance_ummap(WASMDebugInstance *instance, uint64 addr);
|
||||
|
||||
@ -75,8 +75,9 @@ wasm_launch_gdbserver(char *host, int port)
|
||||
}
|
||||
|
||||
ret = fcntl(listen_fd, F_SETFD, FD_CLOEXEC);
|
||||
if(ret < 0) {
|
||||
LOG_ERROR("wasm gdb server error: fcntl() failed on setting FD_CLOEXEC");
|
||||
if (ret < 0) {
|
||||
LOG_ERROR(
|
||||
"wasm gdb server error: fcntl() failed on setting FD_CLOEXEC");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
@ -55,13 +55,13 @@ process_xfer(WASMGDBServer *server, const char *name, char *args)
|
||||
*args++ = '\0';
|
||||
|
||||
if (!strcmp(name, "libraries") && !strcmp(mode, "read")) {
|
||||
//TODO: how to get current wasm file name?
|
||||
// TODO: how to get current wasm file name?
|
||||
uint64_t addr = wasm_debug_instance_get_load_addr(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
char objname[128];
|
||||
wasm_debug_instance_get_current_object_name(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, objname, 128);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, objname, 128);
|
||||
sprintf(tmpbuf,
|
||||
"l<library-list><library name=\"%s\"><section "
|
||||
"address=\"0x%lx\"/></library></library-list>",
|
||||
@ -88,8 +88,8 @@ porcess_wasm_local(WASMGDBServer *server, char *args)
|
||||
sprintf(tmpbuf, "E01");
|
||||
if (sscanf(args, "%d;%d", &frame_index, &local_index) == 2) {
|
||||
ret = wasm_debug_instance_get_local(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
|
||||
local_index, buf, &size);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
|
||||
local_index, buf, &size);
|
||||
if (ret && size > 0) {
|
||||
mem2hex(buf, tmpbuf, size);
|
||||
}
|
||||
@ -109,8 +109,8 @@ porcess_wasm_global(WASMGDBServer *server, char *args)
|
||||
sprintf(tmpbuf, "E01");
|
||||
if (sscanf(args, "%d;%d", &frame_index, &global_index) == 2) {
|
||||
ret = wasm_debug_instance_get_global(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
|
||||
global_index, buf, &size);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
|
||||
global_index, buf, &size);
|
||||
if (ret && size > 0) {
|
||||
mem2hex(buf, tmpbuf, size);
|
||||
}
|
||||
@ -133,14 +133,15 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
if (!strcmp(name, "C")) {
|
||||
uint64_t pid, tid;
|
||||
pid = wasm_debug_instance_get_pid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
tid = wasm_debug_instance_get_tid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
snprintf(tmpbuf, sizeof(tmpbuf), "QCp%lx.%lx", pid, tid);
|
||||
write_packet(server, tmpbuf);
|
||||
}
|
||||
if (!strcmp(name, "Supported")) {
|
||||
sprintf(tmpbuf, "qXfer:libraries:read+;PacketSize=%x;", MAX_PACKET_SIZE);
|
||||
sprintf(tmpbuf, "qXfer:libraries:read+;PacketSize=%x;",
|
||||
MAX_PACKET_SIZE);
|
||||
write_packet(server, tmpbuf);
|
||||
}
|
||||
|
||||
@ -161,10 +162,9 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
}
|
||||
|
||||
if (!strcmp(name, "HostInfo")) {
|
||||
//Todo: change vendor to Intel for outside tree?
|
||||
// Todo: change vendor to Intel for outside tree?
|
||||
char triple[256];
|
||||
mem2hex("wasm32-Ant-wasi-wasm", triple,
|
||||
strlen("wasm32-Ant-wasi-wasm"));
|
||||
mem2hex("wasm32-Ant-wasi-wasm", triple, strlen("wasm32-Ant-wasi-wasm"));
|
||||
sprintf(tmpbuf,
|
||||
"vendor:Ant;ostype:wasi;arch:wasm32;"
|
||||
"triple:%s;endian:little;ptrsize:4;",
|
||||
@ -183,14 +183,13 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
write_packet(server, "");
|
||||
}
|
||||
if (!strcmp(name, "ProcessInfo")) {
|
||||
//Todo: process id parent-pid
|
||||
// Todo: process id parent-pid
|
||||
uint64_t pid;
|
||||
pid = wasm_debug_instance_get_pid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
char triple[256];
|
||||
//arch-vendor-os-env(format)
|
||||
mem2hex("wasm32-Ant-wasi-wasm", triple,
|
||||
strlen("wasm32-Ant-wasi-wasm"));
|
||||
// arch-vendor-os-env(format)
|
||||
mem2hex("wasm32-Ant-wasi-wasm", triple, strlen("wasm32-Ant-wasi-wasm"));
|
||||
sprintf(tmpbuf,
|
||||
"pid:%lx;parent-pid:%lx;vendor:Ant;ostype:wasi;arch:wasm32;"
|
||||
"triple:%s;endian:little;ptrsize:4;",
|
||||
@ -200,9 +199,9 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
}
|
||||
if (!strcmp(name, "RegisterInfo0")) {
|
||||
sprintf(
|
||||
tmpbuf,
|
||||
"name:pc;alt-name:pc;bitsize:64;offset:0;encoding:uint;format:hex;"
|
||||
"set:General Purpose Registers;gcc:16;dwarf:16;generic:pc;");
|
||||
tmpbuf,
|
||||
"name:pc;alt-name:pc;bitsize:64;offset:0;encoding:uint;format:hex;"
|
||||
"set:General Purpose Registers;gcc:16;dwarf:16;generic:pc;");
|
||||
write_packet(server, tmpbuf);
|
||||
}
|
||||
else if (!strncmp(name, "RegisterInfo", strlen("RegisterInfo"))) {
|
||||
@ -215,24 +214,23 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
if (args && (!strcmp(name, "MemoryRegionInfo"))) {
|
||||
uint64_t addr = strtol(args, NULL, 16);
|
||||
WASMDebugMemoryInfo *mem_info = wasm_debug_instance_get_memregion(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr);
|
||||
if (mem_info) {
|
||||
char name[256];
|
||||
mem2hex(mem_info->name, name, strlen(mem_info->name));
|
||||
sprintf(tmpbuf, "start:%lx;size:%lx;permissions:%s;name:%s;",
|
||||
(uint64)mem_info->start, mem_info->size, mem_info->permisson, name);
|
||||
(uint64)mem_info->start, mem_info->size,
|
||||
mem_info->permisson, name);
|
||||
write_packet(server, tmpbuf);
|
||||
wasm_debug_instance_destroy_memregion(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, mem_info);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, mem_info);
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(name, "WasmData")) {
|
||||
|
||||
}
|
||||
|
||||
if (!strcmp(name, "WasmMem")) {
|
||||
|
||||
}
|
||||
|
||||
if (!strcmp(name, "Symbol")) {
|
||||
@ -243,8 +241,8 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
||||
uint64_t tid = strtol(args, NULL, 16);
|
||||
uint64_t buf[1024 / sizeof(uint64_t)];
|
||||
uint64_t count = wasm_debug_instance_get_call_stack_pcs(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, buf,
|
||||
1024 / sizeof(uint64_t));
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, buf,
|
||||
1024 / sizeof(uint64_t));
|
||||
if (count > 0) {
|
||||
mem2hex((char *)buf, tmpbuf, count * sizeof(uint64_t));
|
||||
write_packet(server, tmpbuf);
|
||||
@ -276,16 +274,17 @@ send_thread_stop_status(WASMGDBServer *server, uint32_t status, uint64_t tid)
|
||||
return;
|
||||
}
|
||||
tids_number = wasm_debug_instance_get_tids(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tids, 20);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tids, 20);
|
||||
uint64_t pc = wasm_debug_instance_get_pc(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
|
||||
if (status == WAMR_SIG_SINGSTEP) {
|
||||
gdb_status = WAMR_SIG_TRAP;
|
||||
}
|
||||
|
||||
//TODO: how name a wasm thread?
|
||||
len += sprintf(tmpbuf, "T%02xthread:%lx;name:%s;", gdb_status, tid, "nobody");
|
||||
// TODO: how name a wasm thread?
|
||||
len +=
|
||||
sprintf(tmpbuf, "T%02xthread:%lx;name:%s;", gdb_status, tid, "nobody");
|
||||
if (tids_number > 0) {
|
||||
len += sprintf(tmpbuf + len, "threads:");
|
||||
while (i < tids_number) {
|
||||
@ -336,12 +335,12 @@ handle_v_packet(WASMGDBServer *server, char *payload)
|
||||
*numstring++ = '\0';
|
||||
uint64_t tid = strtol(numstring, NULL, 16);
|
||||
wasm_debug_instance_set_cur_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
wasm_debug_instance_singlestep(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
tid = wasm_debug_instance_wait_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid,
|
||||
&status);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid,
|
||||
&status);
|
||||
send_thread_stop_status(server, status, tid);
|
||||
}
|
||||
}
|
||||
@ -352,11 +351,11 @@ void
|
||||
handle_threadstop_request(WASMGDBServer *server, char *payload)
|
||||
{
|
||||
uint64_t tid = wasm_debug_instance_get_tid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
uint32_t status;
|
||||
|
||||
tid = wasm_debug_instance_wait_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
|
||||
send_thread_stop_status(server, status, tid);
|
||||
}
|
||||
@ -370,7 +369,7 @@ handle_set_current_thread(WASMGDBServer *server, char *payload)
|
||||
tid = strtol(payload, NULL, 16);
|
||||
if (tid > 0)
|
||||
wasm_debug_instance_set_cur_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid);
|
||||
}
|
||||
write_packet(server, "OK");
|
||||
}
|
||||
@ -385,7 +384,7 @@ handle_get_register(WASMGDBServer *server, char *payload)
|
||||
return;
|
||||
}
|
||||
uint64_t regdata = wasm_debug_instance_get_pc(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
mem2hex((void *)®data, tmpbuf, 8);
|
||||
tmpbuf[8 * 2] = '\0';
|
||||
write_packet(server, tmpbuf);
|
||||
@ -423,8 +422,8 @@ handle_get_read_memory(WASMGDBServer *server, char *payload)
|
||||
char *buff = wasm_runtime_malloc(mlen);
|
||||
if (buff) {
|
||||
ret = wasm_debug_instance_get_mem(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, maddr, buff,
|
||||
&mlen);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, maddr,
|
||||
buff, &mlen);
|
||||
if (ret) {
|
||||
mem2hex(buff, tmpbuf, mlen);
|
||||
}
|
||||
@ -451,8 +450,8 @@ handle_get_write_memory(WASMGDBServer *server, char *payload)
|
||||
if (buff) {
|
||||
hex2mem(payload, buff, act_len);
|
||||
ret = wasm_debug_instance_set_mem(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, maddr, buff,
|
||||
&mlen);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, maddr,
|
||||
buff, &mlen);
|
||||
if (ret) {
|
||||
sprintf(tmpbuf, "%s", "OK");
|
||||
}
|
||||
@ -470,8 +469,8 @@ handle_add_break(WASMGDBServer *server, char *payload)
|
||||
if (sscanf(payload, "%zx,%zx,%zx", &type, &addr, &length) == 3) {
|
||||
if (type == eBreakpointSoftware) {
|
||||
bool ret = wasm_debug_instance_add_breakpoint(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr,
|
||||
length);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr,
|
||||
length);
|
||||
if (ret)
|
||||
write_packet(server, "OK");
|
||||
else
|
||||
@ -490,8 +489,8 @@ handle_remove_break(WASMGDBServer *server, char *payload)
|
||||
if (sscanf(payload, "%zx,%zx,%zx", &type, &addr, &length) == 3) {
|
||||
if (type == eBreakpointSoftware) {
|
||||
bool ret = wasm_debug_instance_remove_breakpoint(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr,
|
||||
length);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr,
|
||||
length);
|
||||
if (ret)
|
||||
write_packet(server, "OK");
|
||||
else
|
||||
@ -509,13 +508,13 @@ handle_continue_request(WASMGDBServer *server, char *payload)
|
||||
uint32_t status;
|
||||
|
||||
wasm_debug_instance_continue(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
|
||||
tid = wasm_debug_instance_get_tid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
|
||||
tid = wasm_debug_instance_wait_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
|
||||
send_thread_stop_status(server, status, tid);
|
||||
}
|
||||
@ -527,13 +526,13 @@ handle_kill_request(WASMGDBServer *server, char *payload)
|
||||
uint32_t status;
|
||||
|
||||
wasm_debug_instance_kill(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
|
||||
tid = wasm_debug_instance_get_tid(
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
(WASMDebugInstance *)server->thread->debug_instance);
|
||||
|
||||
tid = wasm_debug_instance_wait_thread(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
|
||||
|
||||
send_thread_stop_status(server, status, tid);
|
||||
}
|
||||
@ -572,7 +571,8 @@ handle_malloc(WASMGDBServer *server, char *payload)
|
||||
args++;
|
||||
}
|
||||
addr = wasm_debug_instance_mmap(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, size, map_port);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, size,
|
||||
map_port);
|
||||
if (addr) {
|
||||
sprintf(tmpbuf, "%lx", addr);
|
||||
}
|
||||
@ -590,7 +590,7 @@ handle_free(WASMGDBServer *server, char *payload)
|
||||
addr = strtol(payload, NULL, 16);
|
||||
|
||||
ret = wasm_debug_instance_ummap(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr);
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr);
|
||||
if (ret) {
|
||||
sprintf(tmpbuf, "%s", "OK");
|
||||
}
|
||||
|
||||
@ -83,8 +83,7 @@ write_hex(WASMGDBServer *gdbserver, unsigned long hex)
|
||||
}
|
||||
|
||||
void
|
||||
write_packet_bytes(WASMGDBServer *gdbserver,
|
||||
const uint8_t *data,
|
||||
write_packet_bytes(WASMGDBServer *gdbserver, const uint8_t *data,
|
||||
size_t num_bytes)
|
||||
{
|
||||
uint8_t checksum;
|
||||
@ -106,10 +105,8 @@ write_packet(WASMGDBServer *gdbserver, const char *data)
|
||||
}
|
||||
|
||||
void
|
||||
write_binary_packet(WASMGDBServer *gdbserver,
|
||||
const char *pfx,
|
||||
const uint8_t *data,
|
||||
ssize_t num_bytes)
|
||||
write_binary_packet(WASMGDBServer *gdbserver, const char *pfx,
|
||||
const uint8_t *data, ssize_t num_bytes)
|
||||
{
|
||||
uint8_t *buf;
|
||||
ssize_t pfx_num_chars = strlen(pfx);
|
||||
|
||||
@ -12,13 +12,14 @@
|
||||
|
||||
#define WAMR_PTHREAD_KEYS_MAX 32
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module(exec_env) \
|
||||
wasm_exec_env_get_module(exec_env)
|
||||
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
#define get_thread_arg(exec_env) \
|
||||
#define get_thread_arg(exec_env) \
|
||||
wasm_exec_env_get_thread_arg(exec_env)
|
||||
|
||||
#define get_wasi_ctx(module_inst) \
|
||||
@ -35,10 +36,10 @@
|
||||
|
||||
#define addr_native_to_app(ptr) \
|
||||
wasm_runtime_addr_native_to_app(module_inst, ptr)
|
||||
/* clang-format on */
|
||||
|
||||
extern bool
|
||||
wasm_runtime_call_indirect(wasm_exec_env_t exec_env,
|
||||
uint32 element_indices,
|
||||
wasm_runtime_call_indirect(wasm_exec_env_t exec_env, uint32 element_indices,
|
||||
uint32 argc, uint32 argv[]);
|
||||
|
||||
enum {
|
||||
@ -95,7 +96,7 @@ typedef struct ThreadInfoNode {
|
||||
/* type can be [THREAD | MUTEX | CONDITION] */
|
||||
uint32 type;
|
||||
/* Thread status, this variable should be volatile
|
||||
as its value may be changed in different threads */
|
||||
as its value may be changed in different threads */
|
||||
volatile uint32 status;
|
||||
bool joinable;
|
||||
union {
|
||||
@ -161,8 +162,7 @@ lib_pthread_init()
|
||||
if (0 != os_mutex_init(&thread_global_lock))
|
||||
return false;
|
||||
bh_list_init(&cluster_info_list);
|
||||
if (!wasm_cluster_register_destroy_callback(
|
||||
lib_pthread_destroy_callback)) {
|
||||
if (!wasm_cluster_register_destroy_callback(lib_pthread_destroy_callback)) {
|
||||
os_mutex_destroy(&thread_global_lock);
|
||||
return false;
|
||||
}
|
||||
@ -175,7 +175,7 @@ lib_pthread_destroy()
|
||||
os_mutex_destroy(&thread_global_lock);
|
||||
}
|
||||
|
||||
static ClusterInfoNode*
|
||||
static ClusterInfoNode *
|
||||
get_cluster_info(WASMCluster *cluster)
|
||||
{
|
||||
ClusterInfoNode *node;
|
||||
@ -195,30 +195,30 @@ get_cluster_info(WASMCluster *cluster)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static KeyData*
|
||||
static KeyData *
|
||||
key_data_list_lookup(wasm_exec_env_t exec_env, int32 key)
|
||||
{
|
||||
ClusterInfoNode *node;
|
||||
WASMCluster *cluster =
|
||||
wasm_exec_env_get_cluster(exec_env);
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
|
||||
if ((node = get_cluster_info(cluster))) {
|
||||
return (key >= 0 && key < WAMR_PTHREAD_KEYS_MAX
|
||||
&& node->key_data_list[key].is_created)
|
||||
? &(node->key_data_list[key]) : NULL;
|
||||
? &(node->key_data_list[key])
|
||||
: NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Lookup the thread key value node for a thread,
|
||||
create a new one if failed
|
||||
This design will reduce the memory usage. If the thread doesn't use
|
||||
the local storage, it will not occupy memory space
|
||||
*/
|
||||
static int32*
|
||||
key_value_list_lookup_or_create(wasm_exec_env_t exec_env,
|
||||
ClusterInfoNode *info, int32 key)
|
||||
/**
|
||||
* Lookup the thread key value node for a thread, create a new one if failed
|
||||
* This design will reduce the memory usage. If the thread doesn't use the
|
||||
* local storage, it will not occupy memory space.
|
||||
*/
|
||||
static int32 *
|
||||
key_value_list_lookup_or_create(wasm_exec_env_t exec_env, ClusterInfoNode *info,
|
||||
int32 key)
|
||||
{
|
||||
KeyData *key_node;
|
||||
ThreadKeyValueNode *data;
|
||||
@ -296,9 +296,7 @@ call_key_destructor(wasm_exec_env_t exec_env)
|
||||
uint32 argv[1];
|
||||
|
||||
argv[0] = value;
|
||||
wasm_runtime_call_indirect(exec_env,
|
||||
destructor_index,
|
||||
1, argv);
|
||||
wasm_runtime_call_indirect(exec_env, destructor_index, 1, argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -325,7 +323,7 @@ destroy_thread_key_value_list(bh_list *list)
|
||||
}
|
||||
}
|
||||
|
||||
static ClusterInfoNode*
|
||||
static ClusterInfoNode *
|
||||
create_cluster_info(WASMCluster *cluster)
|
||||
{
|
||||
ClusterInfoNode *node;
|
||||
@ -346,12 +344,9 @@ create_cluster_info(WASMCluster *cluster)
|
||||
}
|
||||
|
||||
node->cluster = cluster;
|
||||
if (!(node->thread_info_map =
|
||||
bh_hash_map_create(32, true,
|
||||
(HashFunc)thread_handle_hash,
|
||||
(KeyEqualFunc)thread_handle_equal,
|
||||
NULL,
|
||||
thread_info_destroy))) {
|
||||
if (!(node->thread_info_map = bh_hash_map_create(
|
||||
32, true, (HashFunc)thread_handle_hash,
|
||||
(KeyEqualFunc)thread_handle_equal, NULL, thread_info_destroy))) {
|
||||
os_mutex_destroy(&node->key_data_list_lock);
|
||||
wasm_runtime_free(node);
|
||||
return NULL;
|
||||
@ -395,13 +390,12 @@ delete_thread_info_node(ThreadInfoNode *thread_info)
|
||||
{
|
||||
ClusterInfoNode *node;
|
||||
bool ret;
|
||||
WASMCluster *cluster =
|
||||
wasm_exec_env_get_cluster(thread_info->exec_env);
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(thread_info->exec_env);
|
||||
|
||||
if ((node = get_cluster_info(cluster))) {
|
||||
ret = bh_hash_map_remove(node->thread_info_map,
|
||||
(void *)(uintptr_t)thread_info->handle,
|
||||
NULL, NULL);
|
||||
(void *)(uintptr_t)thread_info->handle, NULL,
|
||||
NULL);
|
||||
(void)ret;
|
||||
}
|
||||
|
||||
@ -412,8 +406,7 @@ static bool
|
||||
append_thread_info_node(ThreadInfoNode *thread_info)
|
||||
{
|
||||
ClusterInfoNode *node;
|
||||
WASMCluster *cluster =
|
||||
wasm_exec_env_get_cluster(thread_info->exec_env);
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(thread_info->exec_env);
|
||||
|
||||
if (!(node = get_cluster_info(cluster))) {
|
||||
if (!(node = create_cluster_info(cluster))) {
|
||||
@ -430,7 +423,7 @@ append_thread_info_node(ThreadInfoNode *thread_info)
|
||||
return true;
|
||||
}
|
||||
|
||||
static ThreadInfoNode*
|
||||
static ThreadInfoNode *
|
||||
get_thread_info(wasm_exec_env_t exec_env, uint32 handle)
|
||||
{
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
@ -453,7 +446,7 @@ allocate_handle()
|
||||
return id;
|
||||
}
|
||||
|
||||
static void*
|
||||
static void *
|
||||
pthread_start_routine(void *arg)
|
||||
{
|
||||
wasm_exec_env_t exec_env = (wasm_exec_env_t)arg;
|
||||
@ -482,9 +475,8 @@ pthread_start_routine(void *arg)
|
||||
wasm_exec_env_set_thread_info(exec_env);
|
||||
argv[0] = routine_args->arg;
|
||||
|
||||
if(!wasm_runtime_call_indirect(exec_env,
|
||||
routine_args->elem_index,
|
||||
1, argv)) {
|
||||
if (!wasm_runtime_call_indirect(exec_env, routine_args->elem_index, 1,
|
||||
argv)) {
|
||||
if (wasm_runtime_get_exception(module_inst))
|
||||
wasm_cluster_spread_exception(exec_env);
|
||||
}
|
||||
@ -498,8 +490,8 @@ pthread_start_routine(void *arg)
|
||||
wasm_runtime_free(routine_args);
|
||||
|
||||
/* if the thread is joinable, store the result in its info node,
|
||||
if the other threads join this thread after exited, then we
|
||||
can return the stored result */
|
||||
if the other threads join this thread after exited, then we
|
||||
can return the stored result */
|
||||
if (!info_node->joinable) {
|
||||
delete_thread_info_node(info_node);
|
||||
}
|
||||
@ -520,10 +512,10 @@ pthread_start_routine(void *arg)
|
||||
|
||||
static int
|
||||
pthread_create_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 *thread, /* thread_handle */
|
||||
const void *attr, /* not supported */
|
||||
uint32 elem_index, /* entry function */
|
||||
uint32 arg) /* arguments buffer */
|
||||
uint32 *thread, /* thread_handle */
|
||||
const void *attr, /* not supported */
|
||||
uint32 elem_index, /* entry function */
|
||||
uint32 arg) /* arguments buffer */
|
||||
{
|
||||
wasm_module_t module = get_module(exec_env);
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -539,15 +531,13 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
|
||||
bh_assert(module);
|
||||
bh_assert(module_inst);
|
||||
|
||||
if (!(new_module_inst =
|
||||
wasm_runtime_instantiate_internal(module, true, 8192, 0,
|
||||
NULL, 0)))
|
||||
if (!(new_module_inst = wasm_runtime_instantiate_internal(
|
||||
module, true, 8192, 0, NULL, 0)))
|
||||
return -1;
|
||||
|
||||
/* Set custom_data to new module instance */
|
||||
wasm_runtime_set_custom_data_internal(
|
||||
new_module_inst,
|
||||
wasm_runtime_get_custom_data(module_inst));
|
||||
new_module_inst, wasm_runtime_get_custom_data(module_inst));
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -575,17 +565,16 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
|
||||
routine_args->module_inst = new_module_inst;
|
||||
|
||||
os_mutex_lock(&exec_env->wait_lock);
|
||||
ret = wasm_cluster_create_thread(exec_env, new_module_inst,
|
||||
pthread_start_routine,
|
||||
(void *)routine_args);
|
||||
ret = wasm_cluster_create_thread(
|
||||
exec_env, new_module_inst, pthread_start_routine, (void *)routine_args);
|
||||
if (ret != 0) {
|
||||
os_mutex_unlock(&exec_env->wait_lock);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Wait for the thread routine to assign the exec_env to
|
||||
thread_info_node, otherwise the exec_env in the thread
|
||||
info node may be NULL in the next pthread API call */
|
||||
thread_info_node, otherwise the exec_env in the thread
|
||||
info node may be NULL in the next pthread API call */
|
||||
os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock);
|
||||
os_mutex_unlock(&exec_env->wait_lock);
|
||||
|
||||
@ -618,10 +607,10 @@ pthread_join_wrapper(wasm_exec_env_t exec_env, uint32 thread,
|
||||
module_inst = get_module_inst(exec_env);
|
||||
|
||||
/* validate addr, we can use current thread's
|
||||
module instance here as the memory is shared */
|
||||
module instance here as the memory is shared */
|
||||
if (!validate_app_addr(retval_offset, sizeof(int32))) {
|
||||
/* Join failed, but we don't want to terminate all threads,
|
||||
do not spread exception here */
|
||||
do not spread exception here */
|
||||
wasm_runtime_set_exception(module_inst, NULL);
|
||||
return -1;
|
||||
}
|
||||
@ -645,14 +634,14 @@ pthread_join_wrapper(wasm_exec_env_t exec_env, uint32 thread,
|
||||
/* if the thread has exited, return stored results */
|
||||
|
||||
/* this thread must be joinable, otherwise the
|
||||
info_node should be destroyed once exit */
|
||||
info_node should be destroyed once exit */
|
||||
bh_assert(node->joinable);
|
||||
join_ret = 0;
|
||||
ret = node->u.ret;
|
||||
}
|
||||
|
||||
if (retval_offset != 0)
|
||||
*(uint32*)retval = (uint32)(uintptr_t)ret;
|
||||
*(uint32 *)retval = (uint32)(uintptr_t)ret;
|
||||
|
||||
return join_ret;
|
||||
}
|
||||
@ -699,7 +688,7 @@ pthread_self_wrapper(wasm_exec_env_t exec_env)
|
||||
{
|
||||
ThreadRoutineArgs *args = get_thread_arg(exec_env);
|
||||
/* If thread_arg is NULL, it's the exec_env of the main thread,
|
||||
return id 0 to app */
|
||||
return id 0 to app */
|
||||
if (!args)
|
||||
return 0;
|
||||
|
||||
@ -717,8 +706,8 @@ pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset)
|
||||
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && !defined(BH_PLATFORM_WINDOWS)
|
||||
/* If hardware bound check enabled, don't deinstantiate module inst
|
||||
and thread info node here for AoT module, as they will be freed
|
||||
in pthread_start_routine */
|
||||
and thread info node here for AoT module, as they will be freed
|
||||
in pthread_start_routine */
|
||||
if (exec_env->jmpbuf_stack_top) {
|
||||
wasm_cluster_exit_thread(exec_env, (void *)(uintptr_t)retval_offset);
|
||||
}
|
||||
@ -773,7 +762,7 @@ pthread_mutex_init_wrapper(wasm_exec_env_t exec_env, uint32 *mutex, void *attr)
|
||||
|
||||
/* Return the mutex handle to app */
|
||||
if (mutex)
|
||||
*(uint32*)mutex = info_node->handle;
|
||||
*(uint32 *)mutex = info_node->handle;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -790,7 +779,7 @@ fail1:
|
||||
static int32
|
||||
pthread_mutex_lock_wrapper(wasm_exec_env_t exec_env, uint32 *mutex)
|
||||
{
|
||||
ThreadInfoNode* info_node = get_thread_info(exec_env, *mutex);
|
||||
ThreadInfoNode *info_node = get_thread_info(exec_env, *mutex);
|
||||
if (!info_node || info_node->type != T_MUTEX)
|
||||
return -1;
|
||||
|
||||
@ -800,7 +789,7 @@ pthread_mutex_lock_wrapper(wasm_exec_env_t exec_env, uint32 *mutex)
|
||||
static int32
|
||||
pthread_mutex_unlock_wrapper(wasm_exec_env_t exec_env, uint32 *mutex)
|
||||
{
|
||||
ThreadInfoNode* info_node = get_thread_info(exec_env, *mutex);
|
||||
ThreadInfoNode *info_node = get_thread_info(exec_env, *mutex);
|
||||
if (!info_node || info_node->type != T_MUTEX)
|
||||
return -1;
|
||||
|
||||
@ -811,7 +800,7 @@ static int32
|
||||
pthread_mutex_destroy_wrapper(wasm_exec_env_t exec_env, uint32 *mutex)
|
||||
{
|
||||
int32 ret_val;
|
||||
ThreadInfoNode* info_node = get_thread_info(exec_env, *mutex);
|
||||
ThreadInfoNode *info_node = get_thread_info(exec_env, *mutex);
|
||||
if (!info_node || info_node->type != T_MUTEX)
|
||||
return -1;
|
||||
|
||||
@ -852,7 +841,7 @@ pthread_cond_init_wrapper(wasm_exec_env_t exec_env, uint32 *cond, void *attr)
|
||||
|
||||
/* Return the cond handle to app */
|
||||
if (cond)
|
||||
*(uint32*)cond = info_node->handle;
|
||||
*(uint32 *)cond = info_node->handle;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -882,9 +871,10 @@ pthread_cond_wait_wrapper(wasm_exec_env_t exec_env, uint32 *cond, uint32 *mutex)
|
||||
return os_cond_wait(cond_info_node->u.cond, mutex_info_node->u.mutex);
|
||||
}
|
||||
|
||||
/* Currently we don't support struct timespec in built-in libc,
|
||||
so the pthread_cond_timedwait use useconds instead
|
||||
*/
|
||||
/**
|
||||
* Currently we don't support struct timespec in built-in libc,
|
||||
* so the pthread_cond_timedwait use useconds instead
|
||||
*/
|
||||
static int32
|
||||
pthread_cond_timedwait_wrapper(wasm_exec_env_t exec_env, uint32 *cond,
|
||||
uint32 *mutex, uint64 useconds)
|
||||
@ -906,7 +896,7 @@ pthread_cond_timedwait_wrapper(wasm_exec_env_t exec_env, uint32 *cond,
|
||||
static int32
|
||||
pthread_cond_signal_wrapper(wasm_exec_env_t exec_env, uint32 *cond)
|
||||
{
|
||||
ThreadInfoNode* info_node = get_thread_info(exec_env, *cond);
|
||||
ThreadInfoNode *info_node = get_thread_info(exec_env, *cond);
|
||||
if (!info_node || info_node->type != T_COND)
|
||||
return -1;
|
||||
|
||||
@ -917,7 +907,7 @@ static int32
|
||||
pthread_cond_destroy_wrapper(wasm_exec_env_t exec_env, uint32 *cond)
|
||||
{
|
||||
int32 ret_val;
|
||||
ThreadInfoNode* info_node = get_thread_info(exec_env, *cond);
|
||||
ThreadInfoNode *info_node = get_thread_info(exec_env, *cond);
|
||||
if (!info_node || info_node->type != T_COND)
|
||||
return -1;
|
||||
|
||||
@ -939,7 +929,7 @@ pthread_key_create_wrapper(wasm_exec_env_t exec_env, int32 *key,
|
||||
|
||||
if (!info) {
|
||||
/* The user may call pthread_key_create in main thread,
|
||||
in this case the cluster info hasn't been created */
|
||||
in this case the cluster info hasn't been created */
|
||||
if (!(info = create_cluster_info(cluster))) {
|
||||
return -1;
|
||||
}
|
||||
@ -1037,46 +1027,50 @@ pthread_key_delete_wrapper(wasm_exec_env_t exec_env, int32 key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Currently the memory allocator doesn't support alloc specific aligned
|
||||
space, we wrap posix_memalign to simply malloc memory */
|
||||
/**
|
||||
* Currently the memory allocator doesn't support alloc specific aligned
|
||||
* space, we wrap posix_memalign to simply malloc memory
|
||||
*/
|
||||
static int32
|
||||
posix_memalign_wrapper(wasm_exec_env_t exec_env,
|
||||
void **memptr, int32 align, int32 size)
|
||||
posix_memalign_wrapper(wasm_exec_env_t exec_env, void **memptr, int32 align,
|
||||
int32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
void *p = NULL;
|
||||
|
||||
*((int32 *)memptr) = module_malloc(size, (void**)&p);
|
||||
*((int32 *)memptr) = module_malloc(size, (void **)&p);
|
||||
if (!p)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
/* clang-format on */
|
||||
|
||||
static NativeSymbol native_symbols_lib_pthread[] = {
|
||||
REG_NATIVE_FUNC(pthread_create, "(**ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_join, "(ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_detach, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_cancel, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_self, "()i"),
|
||||
REG_NATIVE_FUNC(pthread_exit, "(i)"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_init, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_lock, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_unlock, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_destroy, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_init, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_wait, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_create, "(**ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_join, "(ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_detach, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_cancel, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_self, "()i"),
|
||||
REG_NATIVE_FUNC(pthread_exit, "(i)"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_init, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_lock, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_unlock, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_mutex_destroy, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_init, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_wait, "(**)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_timedwait, "(**I)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_signal, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_destroy, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_key_create, "(*i)i"),
|
||||
REG_NATIVE_FUNC(pthread_setspecific, "(ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_getspecific, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_key_delete, "(i)i"),
|
||||
REG_NATIVE_FUNC(posix_memalign, "(*ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_signal, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_cond_destroy, "(*)i"),
|
||||
REG_NATIVE_FUNC(pthread_key_create, "(*i)i"),
|
||||
REG_NATIVE_FUNC(pthread_setspecific, "(ii)i"),
|
||||
REG_NATIVE_FUNC(pthread_getspecific, "(i)i"),
|
||||
REG_NATIVE_FUNC(pthread_key_delete, "(i)i"),
|
||||
REG_NATIVE_FUNC(posix_memalign, "(*ii)i"),
|
||||
};
|
||||
|
||||
uint32
|
||||
|
||||
@ -29,9 +29,10 @@ void
|
||||
wasm_runtime_set_llvm_stack(wasm_module_inst_t module, uint32 llvm_stack);
|
||||
|
||||
uint32
|
||||
wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr,
|
||||
uint32 size, void **p_native_addr);
|
||||
wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
@ -55,6 +56,7 @@ wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr,
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
/* clang-format on */
|
||||
|
||||
typedef int (*out_func_t)(int c, void *ctx);
|
||||
|
||||
@ -66,15 +68,14 @@ enum pad_type {
|
||||
};
|
||||
|
||||
typedef char *_va_list;
|
||||
#define _INTSIZEOF(n) \
|
||||
(((uint32)sizeof(n) + 3) & (uint32)~3)
|
||||
#define _va_arg(ap, t) \
|
||||
(*(t*)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
|
||||
#define _INTSIZEOF(n) (((uint32)sizeof(n) + 3) & (uint32)~3)
|
||||
#define _va_arg(ap, t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
|
||||
|
||||
#define CHECK_VA_ARG(ap, t) do { \
|
||||
if ((uint8*)ap + _INTSIZEOF(t) > native_end_addr) \
|
||||
goto fail; \
|
||||
} while (0)
|
||||
#define CHECK_VA_ARG(ap, t) \
|
||||
do { \
|
||||
if ((uint8 *)ap + _INTSIZEOF(t) > native_end_addr) \
|
||||
goto fail; \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief Output an unsigned int in hex format
|
||||
@ -86,10 +87,8 @@ typedef char *_va_list;
|
||||
* @return N/A
|
||||
*/
|
||||
static void
|
||||
_printf_hex_uint(out_func_t out, void *ctx,
|
||||
const uint64 num, bool is_u64,
|
||||
enum pad_type padding,
|
||||
int min_width)
|
||||
_printf_hex_uint(out_func_t out, void *ctx, const uint64 num, bool is_u64,
|
||||
enum pad_type padding, int min_width)
|
||||
{
|
||||
int shift = sizeof(num) * 8;
|
||||
int found_largest_digit = 0;
|
||||
@ -97,14 +96,14 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
int digits = 0;
|
||||
char nibble;
|
||||
|
||||
while (shift >= 4) {
|
||||
shift -= 4;
|
||||
nibble = (num >> shift) & 0xf;
|
||||
while (shift >= 4) {
|
||||
shift -= 4;
|
||||
nibble = (num >> shift) & 0xf;
|
||||
|
||||
if (nibble || found_largest_digit || shift == 0) {
|
||||
found_largest_digit = 1;
|
||||
nibble = (char)(nibble + (nibble > 9 ? 87 : 48));
|
||||
out((int) nibble, ctx);
|
||||
out((int)nibble, ctx);
|
||||
digits++;
|
||||
continue;
|
||||
}
|
||||
@ -112,7 +111,8 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
if (remaining-- <= min_width) {
|
||||
if (padding == PAD_ZERO_BEFORE) {
|
||||
out('0', ctx);
|
||||
} else if (padding == PAD_SPACE_BEFORE) {
|
||||
}
|
||||
else if (padding == PAD_SPACE_BEFORE) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
}
|
||||
@ -136,10 +136,8 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
* @return N/A
|
||||
*/
|
||||
static void
|
||||
_printf_dec_uint(out_func_t out, void *ctx,
|
||||
const uint32 num,
|
||||
enum pad_type padding,
|
||||
int min_width)
|
||||
_printf_dec_uint(out_func_t out, void *ctx, const uint32 num,
|
||||
enum pad_type padding, int min_width)
|
||||
{
|
||||
uint32 pos = 999999999;
|
||||
uint32 remainder = num;
|
||||
@ -155,17 +153,18 @@ _printf_dec_uint(out_func_t out, void *ctx,
|
||||
while (pos >= 9) {
|
||||
if (found_largest_digit || remainder > pos) {
|
||||
found_largest_digit = 1;
|
||||
out((int) ((remainder / (pos + 1)) + 48), ctx);
|
||||
out((int)((remainder / (pos + 1)) + 48), ctx);
|
||||
digits++;
|
||||
} else if (remaining <= min_width && padding < PAD_SPACE_AFTER) {
|
||||
out((int) (padding == PAD_ZERO_BEFORE ? '0' : ' '), ctx);
|
||||
}
|
||||
else if (remaining <= min_width && padding < PAD_SPACE_AFTER) {
|
||||
out((int)(padding == PAD_ZERO_BEFORE ? '0' : ' '), ctx);
|
||||
digits++;
|
||||
}
|
||||
remaining--;
|
||||
remainder %= (pos + 1);
|
||||
pos /= 10;
|
||||
}
|
||||
out((int) (remainder + 48), ctx);
|
||||
out((int)(remainder + 48), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
remaining = min_width - digits;
|
||||
@ -193,8 +192,8 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
int long_ctr = 0;
|
||||
uint8 *native_end_addr;
|
||||
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8*)ap,
|
||||
NULL, &native_end_addr))
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8 *)ap, NULL,
|
||||
&native_end_addr))
|
||||
goto fail;
|
||||
|
||||
/* fmt has already been adjusted if needed */
|
||||
@ -202,7 +201,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
while (*fmt) {
|
||||
if (!might_format) {
|
||||
if (*fmt != '%') {
|
||||
out((int) *fmt, ctx);
|
||||
out((int)*fmt, ctx);
|
||||
}
|
||||
else {
|
||||
might_format = 1;
|
||||
@ -213,179 +212,188 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
}
|
||||
else {
|
||||
switch (*fmt) {
|
||||
case '-':
|
||||
padding = PAD_SPACE_AFTER;
|
||||
goto still_might_format;
|
||||
|
||||
case '0':
|
||||
if (min_width < 0 && padding == PAD_NONE) {
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
case '-':
|
||||
padding = PAD_SPACE_AFTER;
|
||||
goto still_might_format;
|
||||
|
||||
case '0':
|
||||
if (min_width < 0 && padding == PAD_NONE) {
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
goto still_might_format;
|
||||
}
|
||||
goto handle_1_to_9;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
handle_1_to_9:
|
||||
if (min_width < 0) {
|
||||
min_width = *fmt - '0';
|
||||
}
|
||||
else {
|
||||
min_width = 10 * min_width + *fmt - '0';
|
||||
}
|
||||
|
||||
if (padding == PAD_NONE) {
|
||||
padding = PAD_SPACE_BEFORE;
|
||||
}
|
||||
goto still_might_format;
|
||||
|
||||
case 'l':
|
||||
long_ctr++;
|
||||
/* Fall through */
|
||||
case 'z':
|
||||
case 'h':
|
||||
/* FIXME: do nothing for these modifiers */
|
||||
goto still_might_format;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
{
|
||||
int32 d;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
d = _va_arg(ap, int32);
|
||||
}
|
||||
else {
|
||||
int64 lld;
|
||||
CHECK_VA_ARG(ap, int64);
|
||||
lld = _va_arg(ap, int64);
|
||||
if (lld > INT32_MAX || lld < INT32_MIN) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
}
|
||||
d = (int32)lld;
|
||||
}
|
||||
|
||||
if (d < 0) {
|
||||
out((int)'-', ctx);
|
||||
d = -d;
|
||||
min_width--;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, (uint32)d, padding, min_width);
|
||||
break;
|
||||
}
|
||||
goto handle_1_to_9;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
handle_1_to_9:
|
||||
if (min_width < 0) {
|
||||
min_width = *fmt - '0';
|
||||
} else {
|
||||
min_width = 10 * min_width + *fmt - '0';
|
||||
case 'u':
|
||||
{
|
||||
uint32 u;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
u = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
uint64 llu;
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
llu = _va_arg(ap, uint64);
|
||||
if (llu > INT32_MAX) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
}
|
||||
u = (uint32)llu;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, u, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
out('0', ctx);
|
||||
out('x', ctx);
|
||||
/* left-pad pointers with zeros */
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
min_width = 8;
|
||||
/* Fall through */
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
uint64 x;
|
||||
bool is_ptr = (*fmt == 'p') ? true : false;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
x = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
x = _va_arg(ap, uint64);
|
||||
}
|
||||
_printf_hex_uint(out, ctx, x, !is_ptr, padding, min_width);
|
||||
break;
|
||||
}
|
||||
|
||||
if (padding == PAD_NONE) {
|
||||
padding = PAD_SPACE_BEFORE;
|
||||
}
|
||||
goto still_might_format;
|
||||
case 's':
|
||||
{
|
||||
char *s;
|
||||
char *start;
|
||||
uint32 s_offset;
|
||||
|
||||
case 'l':
|
||||
long_ctr++;
|
||||
/* Fall through */
|
||||
case 'z':
|
||||
case 'h':
|
||||
/* FIXME: do nothing for these modifiers */
|
||||
goto still_might_format;
|
||||
|
||||
case 'd':
|
||||
case 'i': {
|
||||
int32 d;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
d = _va_arg(ap, int32);
|
||||
}
|
||||
else {
|
||||
int64 lld;
|
||||
CHECK_VA_ARG(ap, int64);
|
||||
lld = _va_arg(ap, int64);
|
||||
if (lld > INT32_MAX || lld < INT32_MIN) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
}
|
||||
d = (int32)lld;
|
||||
}
|
||||
|
||||
if (d < 0) {
|
||||
out((int)'-', ctx);
|
||||
d = -d;
|
||||
min_width--;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, (uint32)d, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
uint32 u;
|
||||
s = start = addr_app_to_native(s_offset);
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
u = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
uint64 llu;
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
llu = _va_arg(ap, uint64);
|
||||
if (llu > INT32_MAX) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
while (*s)
|
||||
out((int)(*s++), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
int remaining = min_width - (int32)(s - start);
|
||||
while (remaining-- > 0) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
}
|
||||
u = (uint32)llu;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, u, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
out('0', ctx);
|
||||
out('x', ctx);
|
||||
/* left-pad pointers with zeros */
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
min_width = 8;
|
||||
/* Fall through */
|
||||
case 'x':
|
||||
case 'X': {
|
||||
uint64 x;
|
||||
bool is_ptr = (*fmt == 'p') ? true : false;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
x = _va_arg(ap, uint32);
|
||||
} else {
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
x = _va_arg(ap, uint64);
|
||||
}
|
||||
_printf_hex_uint(out, ctx, x, !is_ptr, padding, min_width);
|
||||
break;
|
||||
}
|
||||
|
||||
case 's': {
|
||||
char *s;
|
||||
char *start;
|
||||
uint32 s_offset;
|
||||
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
s = start = addr_app_to_native(s_offset);
|
||||
|
||||
while (*s)
|
||||
out((int) (*s++), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
int remaining = min_width - (int32)(s - start);
|
||||
while (remaining-- > 0) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
int c;
|
||||
CHECK_VA_ARG(ap, int);
|
||||
c = _va_arg(ap, int);
|
||||
out(c, ctx);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c': {
|
||||
int c;
|
||||
CHECK_VA_ARG(ap, int);
|
||||
c = _va_arg(ap, int);
|
||||
out(c, ctx);
|
||||
break;
|
||||
}
|
||||
case '%':
|
||||
{
|
||||
out((int)'%', ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
case '%': {
|
||||
out((int) '%', ctx);
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
float64 f64;
|
||||
char buf[16], *s;
|
||||
|
||||
case 'f': {
|
||||
float64 f64;
|
||||
char buf[16], *s;
|
||||
/* Make 8-byte aligned */
|
||||
ap = (_va_list)(((uintptr_t)ap + 7) & ~(uintptr_t)7);
|
||||
CHECK_VA_ARG(ap, float64);
|
||||
f64 = _va_arg(ap, float64);
|
||||
snprintf(buf, sizeof(buf), "%f", f64);
|
||||
s = buf;
|
||||
while (*s)
|
||||
out((int)(*s++), ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make 8-byte aligned */
|
||||
ap = (_va_list)(((uintptr_t)ap + 7) & ~(uintptr_t)7);
|
||||
CHECK_VA_ARG(ap, float64);
|
||||
f64 = _va_arg(ap, float64);
|
||||
snprintf(buf, sizeof(buf), "%f", f64);
|
||||
s = buf;
|
||||
while (*s)
|
||||
out((int) (*s++), ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
out((int) '%', ctx);
|
||||
out((int) *fmt, ctx);
|
||||
break;
|
||||
default:
|
||||
out((int)'%', ctx);
|
||||
out((int)*fmt, ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
might_format = 0;
|
||||
}
|
||||
|
||||
still_might_format:
|
||||
still_might_format:
|
||||
++fmt;
|
||||
}
|
||||
return true;
|
||||
@ -411,7 +419,8 @@ sprintf_out(int c, struct str_context *ctx)
|
||||
|
||||
if (ctx->count == ctx->max - 1) {
|
||||
ctx->str[ctx->count++] = '\0';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ctx->str[ctx->count++] = (char)c;
|
||||
}
|
||||
|
||||
@ -453,8 +462,7 @@ printf_out(int c, struct str_context *ctx)
|
||||
#endif
|
||||
|
||||
static int
|
||||
printf_wrapper(wasm_exec_env_t exec_env,
|
||||
const char * format, _va_list va_args)
|
||||
printf_wrapper(wasm_exec_env_t exec_env, const char *format, _va_list va_args)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
struct str_context ctx = { NULL, 0, 0 };
|
||||
@ -463,15 +471,16 @@ printf_wrapper(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(va_args, sizeof(int32)))
|
||||
return 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)printf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)printf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
return (int)ctx.count;
|
||||
}
|
||||
|
||||
static int
|
||||
sprintf_wrapper(wasm_exec_env_t exec_env,
|
||||
char *str, const char *format, _va_list va_args)
|
||||
sprintf_wrapper(wasm_exec_env_t exec_env, char *str, const char *format,
|
||||
_va_list va_args)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint8 *native_end_offset;
|
||||
@ -481,17 +490,18 @@ sprintf_wrapper(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(va_args, sizeof(uint32)))
|
||||
return 0;
|
||||
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8*)str,
|
||||
NULL, &native_end_offset)) {
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8 *)str, NULL,
|
||||
&native_end_offset)) {
|
||||
wasm_runtime_set_exception(module_inst, "out of bounds memory access");
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx.str = str;
|
||||
ctx.max = (uint32)(native_end_offset - (uint8*)str);
|
||||
ctx.max = (uint32)(native_end_offset - (uint8 *)str);
|
||||
ctx.count = 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
if (ctx.count < ctx.max) {
|
||||
@ -516,7 +526,8 @@ snprintf_wrapper(wasm_exec_env_t exec_env, char *str, uint32 size,
|
||||
ctx.max = size;
|
||||
ctx.count = 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
if (ctx.count < ctx.max) {
|
||||
@ -551,7 +562,7 @@ strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
if (str) {
|
||||
len = (uint32)strlen(str) + 1;
|
||||
|
||||
str_ret_offset = module_malloc(len, (void**)&str_ret);
|
||||
str_ret_offset = module_malloc(len, (void **)&str_ret);
|
||||
if (str_ret_offset) {
|
||||
bh_memcpy_s(str_ret, len, str, len);
|
||||
}
|
||||
@ -567,21 +578,21 @@ _strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
}
|
||||
|
||||
static int32
|
||||
memcmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *s1, const void *s2, uint32 size)
|
||||
memcmp_wrapper(wasm_exec_env_t exec_env, const void *s1, const void *s2,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
/* s2 has been checked by runtime */
|
||||
if (!validate_native_addr((void*)s1, size))
|
||||
if (!validate_native_addr((void *)s1, size))
|
||||
return 0;
|
||||
|
||||
return memcmp(s1, s2, size);
|
||||
}
|
||||
|
||||
static uint32
|
||||
memcpy_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
memcpy_wrapper(wasm_exec_env_t exec_env, void *dst, const void *src,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -598,8 +609,7 @@ memcpy_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memmove_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, void *src, uint32 size)
|
||||
memmove_wrapper(wasm_exec_env_t exec_env, void *dst, void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -616,8 +626,7 @@ memmove_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memset_wrapper(wasm_exec_env_t exec_env,
|
||||
void *s, int32 c, uint32 size)
|
||||
memset_wrapper(wasm_exec_env_t exec_env, void *s, int32 c, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 s_offset = addr_native_to_app(s);
|
||||
@ -630,8 +639,7 @@ memset_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
strchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, int32 c)
|
||||
strchr_wrapper(wasm_exec_env_t exec_env, const char *s, int32 c)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *ret;
|
||||
@ -642,21 +650,20 @@ strchr_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int32
|
||||
strcmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2)
|
||||
strcmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2)
|
||||
{
|
||||
/* s1 and s2 have been checked by runtime */
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
|
||||
static int32
|
||||
strncmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2, uint32 size)
|
||||
strncmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
/* s2 has been checked by runtime */
|
||||
if (!validate_native_addr((void*)s1, size))
|
||||
if (!validate_native_addr((void *)s1, size))
|
||||
return 0;
|
||||
|
||||
return strncmp(s1, s2, size);
|
||||
@ -681,8 +688,8 @@ strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
|
||||
}
|
||||
|
||||
static uint32
|
||||
strncpy_wrapper(wasm_exec_env_t exec_env,
|
||||
char *dst, const char *src, uint32 size)
|
||||
strncpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
@ -716,14 +723,14 @@ static uint32
|
||||
calloc_wrapper(wasm_exec_env_t exec_env, uint32 nmemb, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint64 total_size = (uint64) nmemb * (uint64) size;
|
||||
uint64 total_size = (uint64)nmemb * (uint64)size;
|
||||
uint32 ret_offset = 0;
|
||||
uint8 *ret_ptr;
|
||||
|
||||
if (total_size >= UINT32_MAX)
|
||||
return 0;
|
||||
|
||||
ret_offset = module_malloc((uint32)total_size, (void**)&ret_ptr);
|
||||
ret_offset = module_malloc((uint32)total_size, (void **)&ret_ptr);
|
||||
if (ret_offset) {
|
||||
memset(ret_ptr, 0, (uint32)total_size);
|
||||
}
|
||||
@ -767,8 +774,8 @@ exit_wrapper(wasm_exec_env_t exec_env, int32 status)
|
||||
}
|
||||
|
||||
static int32
|
||||
strtol_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *nptr, char **endptr, int32 base)
|
||||
strtol_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
|
||||
int32 base)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 num = 0;
|
||||
@ -778,14 +785,14 @@ strtol_wrapper(wasm_exec_env_t exec_env,
|
||||
return 0;
|
||||
|
||||
num = (int32)strtol(nptr, endptr, base);
|
||||
*(uint32*)endptr = addr_native_to_app(*endptr);
|
||||
*(uint32 *)endptr = addr_native_to_app(*endptr);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
static uint32
|
||||
strtoul_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *nptr, char **endptr, int32 base)
|
||||
strtoul_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
|
||||
int32 base)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 num = 0;
|
||||
@ -801,13 +808,12 @@ strtoul_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *s, int32 c, uint32 n)
|
||||
memchr_wrapper(wasm_exec_env_t exec_env, const void *s, int32 c, uint32 n)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
void *res;
|
||||
|
||||
if (!validate_native_addr((void*)s, n))
|
||||
if (!validate_native_addr((void *)s, n))
|
||||
return 0;
|
||||
|
||||
res = memchr(s, c, n);
|
||||
@ -815,32 +821,29 @@ memchr_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int32
|
||||
strncasecmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2, uint32 n)
|
||||
strncasecmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
|
||||
uint32 n)
|
||||
{
|
||||
/* s1 and s2 have been checked by runtime */
|
||||
return strncasecmp(s1, s2, n);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strspn_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *accept)
|
||||
strspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *accept)
|
||||
{
|
||||
/* s and accept have been checked by runtime */
|
||||
return (uint32)strspn(s, accept);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strcspn_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *reject)
|
||||
strcspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *reject)
|
||||
{
|
||||
/* s and reject have been checked by runtime */
|
||||
return (uint32)strcspn(s, reject);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strstr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *find)
|
||||
strstr_wrapper(wasm_exec_env_t exec_env, const char *s, const char *find)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
/* s and find have been checked by runtime */
|
||||
@ -925,24 +928,19 @@ getTempRet0_wrapper(wasm_exec_env_t exec_env)
|
||||
static uint32
|
||||
llvm_bswap_i16_wrapper(wasm_exec_env_t exec_env, uint32 data)
|
||||
{
|
||||
return (data & 0xFFFF0000)
|
||||
| ((data & 0xFF) << 8)
|
||||
| ((data & 0xFF00) >> 8);
|
||||
return (data & 0xFFFF0000) | ((data & 0xFF) << 8) | ((data & 0xFF00) >> 8);
|
||||
}
|
||||
|
||||
static uint32
|
||||
llvm_bswap_i32_wrapper(wasm_exec_env_t exec_env, uint32 data)
|
||||
{
|
||||
return ((data & 0xFF) << 24)
|
||||
| ((data & 0xFF00) << 8)
|
||||
| ((data & 0xFF0000) >> 8)
|
||||
| ((data & 0xFF000000) >> 24);
|
||||
return ((data & 0xFF) << 24) | ((data & 0xFF00) << 8)
|
||||
| ((data & 0xFF0000) >> 8) | ((data & 0xFF000000) >> 24);
|
||||
}
|
||||
|
||||
static uint32
|
||||
bitshift64Lshr_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 uint64_part0, uint32 uint64_part1,
|
||||
uint32 bits)
|
||||
bitshift64Lshr_wrapper(wasm_exec_env_t exec_env, uint32 uint64_part0,
|
||||
uint32 uint64_part1, uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
union {
|
||||
@ -955,14 +953,13 @@ bitshift64Lshr_wrapper(wasm_exec_env_t exec_env,
|
||||
|
||||
u.value >>= bits;
|
||||
/* return low 32bit and save high 32bit to temp ret */
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32) (u.value >> 32));
|
||||
return (uint32) u.value;
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32)(u.value >> 32));
|
||||
return (uint32)u.value;
|
||||
}
|
||||
|
||||
static uint32
|
||||
bitshift64Shl_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 int64_part0, uint32 int64_part1,
|
||||
uint32 bits)
|
||||
bitshift64Shl_wrapper(wasm_exec_env_t exec_env, uint32 int64_part0,
|
||||
uint32 int64_part1, uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
union {
|
||||
@ -975,8 +972,8 @@ bitshift64Shl_wrapper(wasm_exec_env_t exec_env,
|
||||
|
||||
u.value <<= bits;
|
||||
/* return low 32bit and save high 32bit to temp ret */
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32) (u.value >> 32));
|
||||
return (uint32) u.value;
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32)(u.value >> 32));
|
||||
return (uint32)u.value;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -996,8 +993,8 @@ llvm_stacksave_wrapper(wasm_exec_env_t exec_env)
|
||||
}
|
||||
|
||||
static uint32
|
||||
emscripten_memcpy_big_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
emscripten_memcpy_big_wrapper(wasm_exec_env_t exec_env, void *dst,
|
||||
const void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -1038,8 +1035,7 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
|
||||
}
|
||||
|
||||
static uint32
|
||||
__cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 thrown_size)
|
||||
__cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env, uint32 thrown_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 exception = module_malloc(thrown_size, NULL);
|
||||
@ -1050,16 +1046,12 @@ __cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static void
|
||||
__cxa_begin_catch_wrapper(wasm_exec_env_t exec_env,
|
||||
void *exception_object)
|
||||
{
|
||||
}
|
||||
__cxa_begin_catch_wrapper(wasm_exec_env_t exec_env, void *exception_object)
|
||||
{}
|
||||
|
||||
static void
|
||||
__cxa_throw_wrapper(wasm_exec_env_t exec_env,
|
||||
void *thrown_exception,
|
||||
void *tinfo,
|
||||
uint32 table_elem_idx)
|
||||
__cxa_throw_wrapper(wasm_exec_env_t exec_env, void *thrown_exception,
|
||||
void *tinfo, uint32 table_elem_idx)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char buf[32];
|
||||
@ -1074,8 +1066,8 @@ struct timespec_app {
|
||||
};
|
||||
|
||||
static uint32
|
||||
clock_gettime_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 clk_id, struct timespec_app *ts_app)
|
||||
clock_gettime_wrapper(wasm_exec_env_t exec_env, uint32 clk_id,
|
||||
struct timespec_app *ts_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint64 time;
|
||||
@ -1103,7 +1095,6 @@ static void
|
||||
print_wrapper(wasm_exec_env_t exec_env)
|
||||
{
|
||||
os_printf("in specttest.print()\n");
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1137,8 +1128,10 @@ print_f64_wrapper(wasm_exec_env_t exec_env, double f64)
|
||||
}
|
||||
#endif /* WASM_ENABLE_SPEC_TEST */
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ \
|
||||
#func_name, func_name##_wrapper, signature, NULL \
|
||||
}
|
||||
|
||||
static NativeSymbol native_symbols_libc_builtin[] = {
|
||||
REG_NATIVE_FUNC(printf, "($*)i"),
|
||||
@ -1281,4 +1274,3 @@ wasm_native_lookup_libc_builtin_global(const char *module_name,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "sys/syscall.h"
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
@ -34,15 +35,15 @@
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
/* clang-format on */
|
||||
|
||||
extern bool
|
||||
wasm_runtime_call_indirect(wasm_exec_env_t exec_env,
|
||||
uint32 element_idx,
|
||||
wasm_runtime_call_indirect(wasm_exec_env_t exec_env, uint32 element_idx,
|
||||
uint32 argc, uint32 argv[]);
|
||||
|
||||
static void
|
||||
invoke_viiii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx,
|
||||
int arg0, int arg1, int arg2, int arg3)
|
||||
invoke_viiii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0,
|
||||
int arg1, int arg2, int arg3)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -56,8 +57,8 @@ invoke_viiii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx,
|
||||
}
|
||||
|
||||
static void
|
||||
invoke_viii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx,
|
||||
int arg0, int arg1, int arg2)
|
||||
invoke_viii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0,
|
||||
int arg1, int arg2)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -70,8 +71,8 @@ invoke_viii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx,
|
||||
}
|
||||
|
||||
static void
|
||||
invoke_vii_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 elem_idx, int arg0, int arg1)
|
||||
invoke_vii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0,
|
||||
int arg1)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -83,8 +84,7 @@ invoke_vii_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static void
|
||||
invoke_vi_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 elem_idx, int arg0)
|
||||
invoke_vi_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -95,8 +95,8 @@ invoke_vi_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int
|
||||
invoke_iii_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 elem_idx, int arg0, int arg1)
|
||||
invoke_iii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0,
|
||||
int arg1)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -108,8 +108,7 @@ invoke_iii_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int
|
||||
invoke_ii_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 elem_idx, int arg0)
|
||||
invoke_ii_wrapper(wasm_exec_env_t exec_env, uint32 elem_idx, int arg0)
|
||||
{
|
||||
uint32 argv[4];
|
||||
bool ret;
|
||||
@ -144,8 +143,8 @@ struct stat_emcc {
|
||||
};
|
||||
|
||||
static int
|
||||
open_wrapper(wasm_exec_env_t exec_env, const char *pathname,
|
||||
int flags, int mode)
|
||||
open_wrapper(wasm_exec_env_t exec_env, const char *pathname, int flags,
|
||||
int mode)
|
||||
{
|
||||
if (pathname == NULL)
|
||||
return -1;
|
||||
@ -153,8 +152,7 @@ open_wrapper(wasm_exec_env_t exec_env, const char *pathname,
|
||||
}
|
||||
|
||||
static int
|
||||
__sys_read_wrapper(wasm_exec_env_t exec_env,
|
||||
int fd, void *buf, uint32 count)
|
||||
__sys_read_wrapper(wasm_exec_env_t exec_env, int fd, void *buf, uint32 count)
|
||||
{
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
@ -183,15 +181,14 @@ statbuf_native2app(const struct stat *statbuf_native,
|
||||
}
|
||||
|
||||
static int
|
||||
__sys_stat64_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *pathname,
|
||||
__sys_stat64_wrapper(wasm_exec_env_t exec_env, const char *pathname,
|
||||
struct stat_emcc *statbuf_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int ret;
|
||||
struct stat statbuf;
|
||||
|
||||
if (!validate_native_addr((void*)statbuf_app, sizeof(struct stat_emcc)))
|
||||
if (!validate_native_addr((void *)statbuf_app, sizeof(struct stat_emcc)))
|
||||
return -1;
|
||||
|
||||
if (pathname == NULL)
|
||||
@ -204,14 +201,14 @@ __sys_stat64_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int
|
||||
__sys_fstat64_wrapper(wasm_exec_env_t exec_env,
|
||||
int fd, struct stat_emcc *statbuf_app)
|
||||
__sys_fstat64_wrapper(wasm_exec_env_t exec_env, int fd,
|
||||
struct stat_emcc *statbuf_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int ret;
|
||||
struct stat statbuf;
|
||||
|
||||
if (!validate_native_addr((void*)statbuf_app, sizeof(struct stat_emcc)))
|
||||
if (!validate_native_addr((void *)statbuf_app, sizeof(struct stat_emcc)))
|
||||
return -1;
|
||||
|
||||
if (fd <= 0)
|
||||
@ -224,16 +221,15 @@ __sys_fstat64_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_wrapper(wasm_exec_env_t exec_env,
|
||||
void *addr, int length, int prot, int flags,
|
||||
int fd, int64 offset)
|
||||
mmap_wrapper(wasm_exec_env_t exec_env, void *addr, int length, int prot,
|
||||
int flags, int fd, int64 offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 buf_offset;
|
||||
char *buf;
|
||||
int size_read;
|
||||
|
||||
buf_offset = module_malloc(length, (void**)&buf);
|
||||
buf_offset = module_malloc(length, (void **)&buf);
|
||||
if (buf_offset == 0)
|
||||
return -1;
|
||||
|
||||
@ -275,16 +271,14 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length)
|
||||
}
|
||||
|
||||
static int
|
||||
setjmp_wrapper(wasm_exec_env_t exec_env,
|
||||
void *jmp_buf)
|
||||
setjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf)
|
||||
{
|
||||
os_printf("setjmp() called\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
longjmp_wrapper(wasm_exec_env_t exec_env,
|
||||
void *jmp_buf, int val)
|
||||
longjmp_wrapper(wasm_exec_env_t exec_env, void *jmp_buf, int val)
|
||||
{
|
||||
os_printf("longjmp() called\n");
|
||||
}
|
||||
@ -305,9 +299,7 @@ get_free_file_slot()
|
||||
}
|
||||
|
||||
static int
|
||||
fopen_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *pathname,
|
||||
const char *mode)
|
||||
fopen_wrapper(wasm_exec_env_t exec_env, const char *pathname, const char *mode)
|
||||
{
|
||||
FILE *file;
|
||||
int file_id;
|
||||
@ -327,8 +319,8 @@ fopen_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
fread_wrapper(wasm_exec_env_t exec_env,
|
||||
void *ptr, uint32 size, uint32 nmemb, int file_id)
|
||||
fread_wrapper(wasm_exec_env_t exec_env, void *ptr, uint32 size, uint32 nmemb,
|
||||
int file_id)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
@ -343,8 +335,7 @@ fread_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int
|
||||
fseeko_wrapper(wasm_exec_env_t exec_env,
|
||||
int file_id, int64 offset, int whence)
|
||||
fseeko_wrapper(wasm_exec_env_t exec_env, int file_id, int64 offset, int whence)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
@ -359,9 +350,8 @@ fseeko_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
emcc_fwrite_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *ptr, uint32 size, uint32 nmemb,
|
||||
int file_id)
|
||||
emcc_fwrite_wrapper(wasm_exec_env_t exec_env, const void *ptr, uint32 size,
|
||||
uint32 nmemb, int file_id)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
@ -403,8 +393,7 @@ fclose_wrapper(wasm_exec_env_t exec_env, int file_id)
|
||||
}
|
||||
|
||||
static int
|
||||
__sys_mkdir_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *pathname, int mode)
|
||||
__sys_mkdir_wrapper(wasm_exec_env_t exec_env, const char *pathname, int mode)
|
||||
{
|
||||
if (!pathname)
|
||||
return -1;
|
||||
@ -522,8 +511,10 @@ emscripten_thread_sleep_wrapper(wasm_exec_env_t exec_env, double timeout_ms)
|
||||
|
||||
#endif /* end of BH_PLATFORM_LINUX_SGX */
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
/* clang-format off */
|
||||
|
||||
static NativeSymbol native_symbols_libc_emcc[] = {
|
||||
REG_NATIVE_FUNC(invoke_viiii, "(iiiii)"),
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
@ -30,6 +31,7 @@
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
/* clang-format on */
|
||||
|
||||
#define wasi_errno_t uvwasi_errno_t
|
||||
#define wasi_fd_t uvwasi_fd_t
|
||||
@ -117,8 +119,8 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_args_sizes_get(wasm_exec_env_t exec_env,
|
||||
uint32 *argc_app, uint32 *argv_buf_size_app)
|
||||
wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
|
||||
uint32 *argv_buf_size_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -132,7 +134,6 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env,
|
||||
|| !validate_native_addr(argv_buf_size_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
|
||||
err = uvwasi_args_sizes_get(uvwasi, &argc, &argv_buf_size);
|
||||
if (err)
|
||||
return err;
|
||||
@ -143,8 +144,7 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_clock_res_get(wasm_exec_env_t exec_env,
|
||||
wasi_clockid_t clock_id,
|
||||
wasi_clock_res_get(wasm_exec_env_t exec_env, wasi_clockid_t clock_id,
|
||||
wasi_timestamp_t *resolution)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -157,10 +157,8 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
wasi_clockid_t clock_id,
|
||||
wasi_timestamp_t precision,
|
||||
wasi_timestamp_t *time)
|
||||
wasi_clock_time_get(wasm_exec_env_t exec_env, wasi_clockid_t clock_id,
|
||||
wasi_timestamp_t precision, wasi_timestamp_t *time)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -172,8 +170,8 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
uint32 *environ_offsets, char *environ_buf)
|
||||
wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
|
||||
char *environ_buf)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -217,8 +215,8 @@ wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|
||||
uint32 *environ_count_app, uint32 *environ_buf_size_app)
|
||||
wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
|
||||
uint32 *environ_buf_size_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -242,8 +240,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_prestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_prestat_app_t *prestat_app)
|
||||
wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_prestat_app_t *prestat_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -266,8 +264,8 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, char *path, uint32 path_len)
|
||||
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env, wasi_fd_t fd, char *path,
|
||||
uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -303,9 +301,8 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_pread(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_filesize_t offset, uint32 *nread_app)
|
||||
wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
|
||||
uint32 iovs_len, wasi_filesize_t offset, uint32 *nread_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -335,12 +332,11 @@ wasi_fd_pread(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = uvwasi_fd_pread(uvwasi, fd, iovec_begin,
|
||||
iovs_len, offset, &nread);
|
||||
err = uvwasi_fd_pread(uvwasi, fd, iovec_begin, iovs_len, offset, &nread);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -355,8 +351,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_filesize_t offset, uint32 *nwritten_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -373,7 +369,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
|
||||
@ -387,12 +383,12 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = uvwasi_fd_pwrite(uvwasi, fd, ciovec_begin,
|
||||
iovs_len, offset, &nwritten);
|
||||
err =
|
||||
uvwasi_fd_pwrite(uvwasi, fd, ciovec_begin, iovs_len, offset, &nwritten);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -407,9 +403,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
uint32 *nread_app)
|
||||
wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const iovec_app_t *iovec_app, uint32 iovs_len, uint32 *nread_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -425,7 +420,7 @@ wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
|
||||
@ -439,12 +434,11 @@ wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = uvwasi_fd_read(uvwasi, fd,
|
||||
iovec_begin, iovs_len, &nread);
|
||||
err = uvwasi_fd_read(uvwasi, fd, iovec_begin, iovs_len, &nread);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -471,9 +465,8 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_seek(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filedelta_t offset, wasi_whence_t whence,
|
||||
wasi_filesize_t *newoffset)
|
||||
wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
|
||||
wasi_whence_t whence, wasi_filesize_t *newoffset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -488,8 +481,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_tell(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filesize_t *newoffset)
|
||||
wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -504,8 +496,8 @@ wasi_fd_tell(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_fdstat_t *fdstat_app)
|
||||
wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_fdstat_t *fdstat_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -527,8 +519,8 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_fdflags_t flags)
|
||||
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_fdflags_t flags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -540,8 +532,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_rights_t fs_rights_base,
|
||||
wasi_rights_t fs_rights_inheriting)
|
||||
{
|
||||
@ -551,8 +542,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_fd_fdstat_set_rights(uvwasi, fd,
|
||||
fs_rights_base, fs_rights_inheriting);
|
||||
return uvwasi_fd_fdstat_set_rights(uvwasi, fd, fs_rights_base,
|
||||
fs_rights_inheriting);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
@ -586,7 +577,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
|
||||
@ -600,7 +591,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
@ -643,11 +634,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_advise(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_filesize_t offset,
|
||||
wasi_filesize_t len,
|
||||
wasi_advice_t advice)
|
||||
wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
|
||||
wasi_filesize_t len, wasi_advice_t advice)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -659,9 +647,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_allocate(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_filesize_t offset,
|
||||
wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
|
||||
wasi_filesize_t len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -674,8 +660,8 @@ wasi_fd_allocate(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_create_directory(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const char *path, uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -687,12 +673,10 @@ wasi_path_create_directory(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_link(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t old_fd,
|
||||
wasi_lookupflags_t old_flags,
|
||||
const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t new_fd,
|
||||
const char *new_path, uint32 new_path_len)
|
||||
wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
|
||||
wasi_lookupflags_t old_flags, const char *old_path,
|
||||
uint32 old_path_len, wasi_fd_t new_fd, const char *new_path,
|
||||
uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -700,20 +684,15 @@ wasi_path_link(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_path_link(uvwasi,
|
||||
old_fd, old_flags, old_path, old_path_len,
|
||||
return uvwasi_path_link(uvwasi, old_fd, old_flags, old_path, old_path_len,
|
||||
new_fd, new_path, new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_open(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t dirfd,
|
||||
wasi_lookupflags_t dirflags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_oflags_t oflags,
|
||||
wasi_rights_t fs_rights_base,
|
||||
wasi_rights_t fs_rights_inheriting,
|
||||
wasi_fdflags_t fs_flags,
|
||||
wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
|
||||
wasi_lookupflags_t dirflags, const char *path, uint32 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_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -727,25 +706,16 @@ wasi_path_open(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = uvwasi_path_open(uvwasi,
|
||||
dirfd, dirflags,
|
||||
path, path_len,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
&fd);
|
||||
err = uvwasi_path_open(uvwasi, dirfd, dirflags, path, path_len, oflags,
|
||||
fs_rights_base, fs_rights_inheriting, fs_flags, &fd);
|
||||
|
||||
*fd_app = fd;
|
||||
return err;
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
void *buf, uint32 buf_len,
|
||||
wasi_dircookie_t cookie,
|
||||
uint32 *bufused_app)
|
||||
wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
|
||||
uint32 buf_len, wasi_dircookie_t cookie, uint32 *bufused_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -758,8 +728,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(bufused_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = uvwasi_fd_readdir(uvwasi, fd,
|
||||
buf, buf_len, cookie, &bufused);
|
||||
err = uvwasi_fd_readdir(uvwasi, fd, buf, buf_len, cookie, &bufused);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -768,10 +737,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
const char *path, uint32 path_len,
|
||||
char *buf, uint32 buf_len,
|
||||
wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
|
||||
uint32 path_len, char *buf, uint32 buf_len,
|
||||
uint32 *bufused_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -785,9 +752,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(bufused_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = uvwasi_path_readlink(uvwasi, fd,
|
||||
path, path_len,
|
||||
buf, buf_len, &bufused);
|
||||
err = uvwasi_path_readlink(uvwasi, fd, path, path_len, buf, buf_len,
|
||||
&bufused);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -796,9 +762,9 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_rename(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t old_fd, const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t new_fd, const char *new_path, uint32 new_path_len)
|
||||
wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
|
||||
const char *old_path, uint32 old_path_len, wasi_fd_t new_fd,
|
||||
const char *new_path, uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -806,14 +772,13 @@ wasi_path_rename(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_path_rename(uvwasi,
|
||||
old_fd, old_path, old_path_len,
|
||||
new_fd, new_path, new_path_len);
|
||||
return uvwasi_path_rename(uvwasi, old_fd, old_path, old_path_len, new_fd,
|
||||
new_path, new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filestat_t *filestat)
|
||||
wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_filestat_t *filestat)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -828,10 +793,8 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim,
|
||||
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_timestamp_t st_atim, wasi_timestamp_t st_mtim,
|
||||
wasi_fstflags_t fstflags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -840,13 +803,11 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_fd_filestat_set_times(uvwasi, fd,
|
||||
st_atim, st_mtim, fstflags);
|
||||
return uvwasi_fd_filestat_set_times(uvwasi, fd, st_atim, st_mtim, fstflags);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_filesize_t st_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -859,11 +820,9 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_filestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_filestat_t *filestat)
|
||||
wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags, const char *path,
|
||||
uint32 path_len, wasi_filestat_t *filestat)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -874,18 +833,15 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_path_filestat_get(uvwasi, fd,
|
||||
flags, path, path_len, filestat);
|
||||
return uvwasi_path_filestat_get(uvwasi, fd, flags, path, path_len,
|
||||
filestat);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim,
|
||||
wasi_fstflags_t fstflags)
|
||||
wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags, const char *path,
|
||||
uint32 path_len, wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim, wasi_fstflags_t fstflags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -893,15 +849,14 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_path_filestat_set_times(uvwasi, fd,
|
||||
flags, path, path_len,
|
||||
return uvwasi_path_filestat_set_times(uvwasi, fd, flags, path, path_len,
|
||||
st_atim, st_mtim, fstflags);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_symlink(wasm_exec_env_t exec_env,
|
||||
const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t fd, const char *new_path, uint32 new_path_len)
|
||||
wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
|
||||
uint32 old_path_len, wasi_fd_t fd, const char *new_path,
|
||||
uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -909,14 +864,13 @@ wasi_path_symlink(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return uvwasi_path_symlink(uvwasi,
|
||||
old_path, old_path_len, fd,
|
||||
new_path, new_path_len);
|
||||
return uvwasi_path_symlink(uvwasi, old_path, old_path_len, fd, new_path,
|
||||
new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_unlink_file(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
|
||||
uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -928,8 +882,8 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_remove_directory(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const char *path, uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -941,9 +895,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_poll_oneoff(wasm_exec_env_t exec_env,
|
||||
const wasi_subscription_t *in, wasi_event_t *out,
|
||||
uint32 nsubscriptions, uint32 *nevents_app)
|
||||
wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
|
||||
wasi_event_t *out, uint32 nsubscriptions, uint32 *nevents_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -953,13 +906,12 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env,
|
||||
if (!uvwasi)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
if (!validate_native_addr((void*)in, sizeof(wasi_subscription_t))
|
||||
if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
|
||||
|| !validate_native_addr(out, sizeof(wasi_event_t))
|
||||
|| !validate_native_addr(nevents_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = uvwasi_poll_oneoff(uvwasi, in, out,
|
||||
nsubscriptions, &nevents);
|
||||
err = uvwasi_poll_oneoff(uvwasi, in, out, nsubscriptions, &nevents);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -997,12 +949,9 @@ wasi_random_get(wasm_exec_env_t exec_env, void *buf, uint32 buf_len)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_recv(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock,
|
||||
iovec_app_t *ri_data, uint32 ri_data_len,
|
||||
wasi_riflags_t ri_flags,
|
||||
uint32 *ro_datalen_app,
|
||||
wasi_roflags_t *ro_flags)
|
||||
wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
|
||||
uint32 ri_data_len, wasi_riflags_t ri_flags,
|
||||
uint32 *ro_datalen_app, wasi_roflags_t *ro_flags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -1033,18 +982,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(ri_data->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(ri_data->buf_offset);
|
||||
iovec->buf_len = ri_data->buf_len;
|
||||
}
|
||||
|
||||
err = uvwasi_sock_recv(uvwasi, sock,
|
||||
iovec_begin, ri_data_len,
|
||||
ri_flags, &ro_datalen,
|
||||
ro_flags);
|
||||
err = uvwasi_sock_recv(uvwasi, sock, iovec_begin, ri_data_len, ri_flags,
|
||||
&ro_datalen, ro_flags);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
*(uint32*)ro_datalen_app = (uint32)ro_datalen;
|
||||
*(uint32 *)ro_datalen_app = (uint32)ro_datalen;
|
||||
|
||||
/* success */
|
||||
err = 0;
|
||||
@ -1055,11 +1002,9 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock,
|
||||
wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
|
||||
const iovec_app_t *si_data, uint32 si_data_len,
|
||||
wasi_siflags_t si_flags,
|
||||
uint32 *so_datalen_app)
|
||||
wasi_siflags_t si_flags, uint32 *so_datalen_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -1075,7 +1020,7 @@ wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)si_data_len;
|
||||
if (!validate_native_addr(so_datalen_app, sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)si_data, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)si_data, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)si_data_len;
|
||||
@ -1089,13 +1034,12 @@ wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(si_data->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(si_data->buf_offset);
|
||||
ciovec->buf_len = si_data->buf_len;
|
||||
}
|
||||
|
||||
err = uvwasi_sock_send(uvwasi, sock,
|
||||
ciovec_begin, si_data_len,
|
||||
si_flags, &so_datalen);
|
||||
err = uvwasi_sock_send(uvwasi, sock, ciovec_begin, si_data_len, si_flags,
|
||||
&so_datalen);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -1110,8 +1054,7 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_shutdown(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock, wasi_sdflags_t how)
|
||||
wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uvwasi_t *uvwasi = get_wasi_ctx(module_inst);
|
||||
@ -1131,8 +1074,10 @@ wasi_sched_yield(wasm_exec_env_t exec_env)
|
||||
return uvwasi_sched_yield(uvwasi);
|
||||
}
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, wasi_##func_name, signature, NULL }
|
||||
/* clang-format on */
|
||||
|
||||
static NativeSymbol native_symbols_libc_wasi[] = {
|
||||
REG_NATIVE_FUNC(args_get, "(**)i"),
|
||||
@ -1188,4 +1133,3 @@ get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis)
|
||||
*p_libc_wasi_apis = native_symbols_libc_wasi;
|
||||
return sizeof(native_symbols_libc_wasi) / sizeof(NativeSymbol);
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
void
|
||||
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
@ -33,6 +34,7 @@ wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct wasi_prestat_app {
|
||||
wasi_preopentype_t pr_type;
|
||||
@ -52,14 +54,13 @@ typedef struct WASIContext {
|
||||
char **argv_list;
|
||||
char *env_buf;
|
||||
char **env_list;
|
||||
} *wasi_ctx_t;
|
||||
} * wasi_ctx_t;
|
||||
|
||||
wasi_ctx_t
|
||||
wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst);
|
||||
|
||||
static inline struct fd_table *
|
||||
wasi_ctx_get_curfds(wasm_module_inst_t module_inst,
|
||||
wasi_ctx_t wasi_ctx)
|
||||
wasi_ctx_get_curfds(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
|
||||
{
|
||||
if (!wasi_ctx)
|
||||
return NULL;
|
||||
@ -67,8 +68,7 @@ wasi_ctx_get_curfds(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
static inline struct argv_environ_values *
|
||||
wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst,
|
||||
wasi_ctx_t wasi_ctx)
|
||||
wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
|
||||
{
|
||||
if (!wasi_ctx)
|
||||
return NULL;
|
||||
@ -76,8 +76,7 @@ wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
static inline struct fd_prestats *
|
||||
wasi_ctx_get_prestats(wasm_module_inst_t module_inst,
|
||||
wasi_ctx_t wasi_ctx)
|
||||
wasi_ctx_get_prestats(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
|
||||
{
|
||||
if (!wasi_ctx)
|
||||
return NULL;
|
||||
@ -90,7 +89,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
struct argv_environ_values *argv_environ =
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
size_t argc, argv_buf_size, i;
|
||||
char **argv;
|
||||
uint64 total_size;
|
||||
@ -110,7 +109,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|
||||
|| !validate_native_addr(argv_buf, (uint32)argv_buf_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(char*) * ((uint64)argc + 1);
|
||||
total_size = sizeof(char *) * ((uint64)argc + 1);
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(argv = wasm_runtime_malloc((uint32)total_size)))
|
||||
return (wasi_errno_t)-1;
|
||||
@ -130,8 +129,8 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_args_sizes_get(wasm_exec_env_t exec_env,
|
||||
uint32 *argc_app, uint32 *argv_buf_size_app)
|
||||
wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
|
||||
uint32 *argv_buf_size_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -148,8 +147,7 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env,
|
||||
|
||||
argv_environ = wasi_ctx->argv_environ;
|
||||
|
||||
err = wasmtime_ssp_args_sizes_get(argv_environ,
|
||||
&argc, &argv_buf_size);
|
||||
err = wasmtime_ssp_args_sizes_get(argv_environ, &argc, &argv_buf_size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -173,7 +171,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
wasi_clockid_t clock_id, /* uint32 clock_id */
|
||||
wasi_clockid_t clock_id, /* uint32 clock_id */
|
||||
wasi_timestamp_t precision, /* uint64 precision */
|
||||
wasi_timestamp_t *time /* uint64 *time */)
|
||||
{
|
||||
@ -186,13 +184,13 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
uint32 *environ_offsets, char *environ_buf)
|
||||
wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
|
||||
char *environ_buf)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
struct argv_environ_values *argv_environ =
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
size_t environ_count, environ_buf_size, i;
|
||||
uint64 total_size;
|
||||
char **environs;
|
||||
@ -201,8 +199,8 @@ wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_environ_sizes_get(argv_environ,
|
||||
&environ_count, &environ_buf_size);
|
||||
err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
|
||||
&environ_buf_size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -213,7 +211,7 @@ wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
|| !validate_native_addr(environ_buf, (uint32)environ_buf_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(char*) * (((uint64)environ_count + 1));
|
||||
total_size = sizeof(char *) * (((uint64)environ_count + 1));
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(environs = wasm_runtime_malloc((uint32)total_size)))
|
||||
@ -234,13 +232,13 @@ wasi_environ_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|
||||
uint32 *environ_count_app, uint32 *environ_buf_size_app)
|
||||
wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
|
||||
uint32 *environ_buf_size_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
struct argv_environ_values *argv_environ =
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
|
||||
size_t environ_count, environ_buf_size;
|
||||
wasi_errno_t err;
|
||||
|
||||
@ -251,8 +249,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|
||||
|| !validate_native_addr(environ_buf_size_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_environ_sizes_get(argv_environ,
|
||||
&environ_count, &environ_buf_size);
|
||||
err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
|
||||
&environ_buf_size);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -263,8 +261,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_prestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_prestat_app_t *prestat_app)
|
||||
wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_prestat_app_t *prestat_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -288,8 +286,8 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, char *path, uint32 path_len)
|
||||
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env, wasi_fd_t fd, char *path,
|
||||
uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -298,8 +296,7 @@ wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_fd_prestat_dir_name(prestats,
|
||||
fd, path, path_len);
|
||||
return wasmtime_ssp_fd_prestat_dir_name(prestats, fd, path, path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
@ -330,9 +327,8 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_pread(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_filesize_t offset, uint32 *nread_app)
|
||||
wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
|
||||
uint32 iovs_len, wasi_filesize_t offset, uint32 *nread_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -364,12 +360,12 @@ wasi_fd_pread(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin,
|
||||
iovs_len, offset, &nread);
|
||||
err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset,
|
||||
&nread);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -384,8 +380,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
wasi_filesize_t offset, uint32 *nwritten_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -403,7 +399,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
|
||||
@ -418,12 +414,12 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin,
|
||||
iovs_len, offset, &nwritten);
|
||||
err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset,
|
||||
&nwritten);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -438,9 +434,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
|
||||
uint32 *nread_app)
|
||||
wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const iovec_app_t *iovec_app, uint32 iovs_len, uint32 *nread_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -457,7 +452,7 @@ wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
|
||||
@ -472,12 +467,11 @@ wasi_fd_read(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
|
||||
iovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_fd_read(curfds, fd,
|
||||
iovec_begin, iovs_len, &nread);
|
||||
err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -506,9 +500,8 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_seek(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filedelta_t offset, wasi_whence_t whence,
|
||||
wasi_filesize_t *newoffset)
|
||||
wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
|
||||
wasi_whence_t whence, wasi_filesize_t *newoffset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -524,8 +517,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_tell(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filesize_t *newoffset)
|
||||
wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -541,8 +533,8 @@ wasi_fd_tell(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_fdstat_t *fdstat_app)
|
||||
wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_fdstat_t *fdstat_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -565,8 +557,8 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_fdflags_t flags)
|
||||
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_fdflags_t flags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -579,8 +571,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_rights_t fs_rights_base,
|
||||
wasi_rights_t fs_rights_inheriting)
|
||||
{
|
||||
@ -591,8 +582,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd,
|
||||
fs_rights_base, fs_rights_inheriting);
|
||||
return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base,
|
||||
fs_rights_inheriting);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
@ -628,7 +619,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
|
||||
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
|
||||
@ -643,12 +634,11 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
|
||||
ciovec->buf_len = iovec_app->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_fd_write(curfds, fd,
|
||||
ciovec_begin, iovs_len, &nwritten);
|
||||
err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
@ -663,11 +653,8 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_advise(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_filesize_t offset,
|
||||
wasi_filesize_t len,
|
||||
wasi_advice_t advice)
|
||||
wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
|
||||
wasi_filesize_t len, wasi_advice_t advice)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -680,9 +667,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_allocate(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_filesize_t offset,
|
||||
wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
|
||||
wasi_filesize_t len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -696,8 +681,8 @@ wasi_fd_allocate(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_create_directory(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const char *path, uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -706,17 +691,14 @@ wasi_path_create_directory(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_create_directory(curfds, fd,
|
||||
path, path_len);
|
||||
return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_link(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t old_fd,
|
||||
wasi_lookupflags_t old_flags,
|
||||
const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t new_fd,
|
||||
const char *new_path, uint32 new_path_len)
|
||||
wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
|
||||
wasi_lookupflags_t old_flags, const char *old_path,
|
||||
uint32 old_path_len, wasi_fd_t new_fd, const char *new_path,
|
||||
uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -726,20 +708,15 @@ wasi_path_link(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_link(curfds, prestats,
|
||||
old_fd, old_flags, old_path, old_path_len,
|
||||
new_fd, new_path, new_path_len);
|
||||
return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path,
|
||||
old_path_len, new_fd, new_path, new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_open(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t dirfd,
|
||||
wasi_lookupflags_t dirflags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_oflags_t oflags,
|
||||
wasi_rights_t fs_rights_base,
|
||||
wasi_rights_t fs_rights_inheriting,
|
||||
wasi_fdflags_t fs_flags,
|
||||
wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
|
||||
wasi_lookupflags_t dirflags, const char *path, uint32 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_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -754,25 +731,17 @@ wasi_path_open(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_path_open(curfds,
|
||||
dirfd, dirflags,
|
||||
path, path_len,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
&fd);
|
||||
err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len,
|
||||
oflags, fs_rights_base, fs_rights_inheriting,
|
||||
fs_flags, &fd);
|
||||
|
||||
*fd_app = fd;
|
||||
return err;
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
void *buf, uint32 buf_len,
|
||||
wasi_dircookie_t cookie,
|
||||
uint32 *bufused_app)
|
||||
wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
|
||||
uint32 buf_len, wasi_dircookie_t cookie, uint32 *bufused_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -786,8 +755,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(bufused_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_fd_readdir(curfds, fd,
|
||||
buf, buf_len, cookie, &bufused);
|
||||
err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -796,10 +764,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
const char *path, uint32 path_len,
|
||||
char *buf, uint32 buf_len,
|
||||
wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
|
||||
uint32 path_len, char *buf, uint32 buf_len,
|
||||
uint32 *bufused_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -814,9 +780,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(bufused_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_path_readlink(curfds, fd,
|
||||
path, path_len,
|
||||
buf, buf_len, &bufused);
|
||||
err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len,
|
||||
&bufused);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -825,9 +790,9 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_rename(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t old_fd, const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t new_fd, const char *new_path, uint32 new_path_len)
|
||||
wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
|
||||
const char *old_path, uint32 old_path_len, wasi_fd_t new_fd,
|
||||
const char *new_path, uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -836,14 +801,13 @@ wasi_path_rename(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_rename(curfds,
|
||||
old_fd, old_path, old_path_len,
|
||||
return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len,
|
||||
new_fd, new_path, new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, wasi_filestat_t *filestat)
|
||||
wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_filestat_t *filestat)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -859,10 +823,8 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim,
|
||||
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_timestamp_t st_atim, wasi_timestamp_t st_mtim,
|
||||
wasi_fstflags_t fstflags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -872,13 +834,12 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_fd_filestat_set_times(curfds, fd,
|
||||
st_atim, st_mtim, fstflags);
|
||||
return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim,
|
||||
fstflags);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_filesize_t st_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
@ -892,11 +853,9 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_filestat_get(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_filestat_t *filestat)
|
||||
wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags, const char *path,
|
||||
uint32 path_len, wasi_filestat_t *filestat)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -908,18 +867,15 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_filestat_get(curfds, fd,
|
||||
flags, path, path_len, filestat);
|
||||
return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len,
|
||||
filestat);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags,
|
||||
const char *path, uint32 path_len,
|
||||
wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim,
|
||||
wasi_fstflags_t fstflags)
|
||||
wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
wasi_lookupflags_t flags, const char *path,
|
||||
uint32 path_len, wasi_timestamp_t st_atim,
|
||||
wasi_timestamp_t st_mtim, wasi_fstflags_t fstflags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -928,15 +884,14 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_filestat_set_times(curfds, fd,
|
||||
flags, path, path_len,
|
||||
st_atim, st_mtim, fstflags);
|
||||
return wasmtime_ssp_path_filestat_set_times(
|
||||
curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_symlink(wasm_exec_env_t exec_env,
|
||||
const char *old_path, uint32 old_path_len,
|
||||
wasi_fd_t fd, const char *new_path, uint32 new_path_len)
|
||||
wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
|
||||
uint32 old_path_len, wasi_fd_t fd, const char *new_path,
|
||||
uint32 new_path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -946,14 +901,13 @@ wasi_path_symlink(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_path_symlink(curfds, prestats,
|
||||
old_path, old_path_len, fd,
|
||||
new_path, new_path_len);
|
||||
return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len,
|
||||
fd, new_path, new_path_len);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_unlink_file(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
|
||||
uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -966,8 +920,8 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_path_remove_directory(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t fd, const char *path, uint32 path_len)
|
||||
wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
|
||||
const char *path, uint32 path_len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -980,9 +934,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_poll_oneoff(wasm_exec_env_t exec_env,
|
||||
const wasi_subscription_t *in, wasi_event_t *out,
|
||||
uint32 nsubscriptions, uint32 *nevents_app)
|
||||
wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
|
||||
wasi_event_t *out, uint32 nsubscriptions, uint32 *nevents_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -993,13 +946,12 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env,
|
||||
if (!wasi_ctx)
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
if (!validate_native_addr((void*)in, sizeof(wasi_subscription_t))
|
||||
if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
|
||||
|| !validate_native_addr(out, sizeof(wasi_event_t))
|
||||
|| !validate_native_addr(nevents_app, sizeof(uint32)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
err = wasmtime_ssp_poll_oneoff(curfds, in, out,
|
||||
nsubscriptions, &nevents);
|
||||
err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -1035,12 +987,9 @@ wasi_random_get(wasm_exec_env_t exec_env, void *buf, uint32 buf_len)
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_recv(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock,
|
||||
iovec_app_t *ri_data, uint32 ri_data_len,
|
||||
wasi_riflags_t ri_flags,
|
||||
uint32 *ro_datalen_app,
|
||||
wasi_roflags_t *ro_flags)
|
||||
wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
|
||||
uint32 ri_data_len, wasi_riflags_t ri_flags,
|
||||
uint32 *ro_datalen_app, wasi_roflags_t *ro_flags)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -1073,18 +1022,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
iovec->buf = (void*)addr_app_to_native(ri_data->buf_offset);
|
||||
iovec->buf = (void *)addr_app_to_native(ri_data->buf_offset);
|
||||
iovec->buf_len = ri_data->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_sock_recv(curfds, sock,
|
||||
iovec_begin, ri_data_len,
|
||||
ri_flags, &ro_datalen,
|
||||
ro_flags);
|
||||
err = wasmtime_ssp_sock_recv(curfds, sock, iovec_begin, ri_data_len,
|
||||
ri_flags, &ro_datalen, ro_flags);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
*(uint32*)ro_datalen_app = (uint32)ro_datalen;
|
||||
*(uint32 *)ro_datalen_app = (uint32)ro_datalen;
|
||||
|
||||
/* success */
|
||||
err = 0;
|
||||
@ -1095,11 +1042,9 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock,
|
||||
wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
|
||||
const iovec_app_t *si_data, uint32 si_data_len,
|
||||
wasi_siflags_t si_flags,
|
||||
uint32 *so_datalen_app)
|
||||
wasi_siflags_t si_flags, uint32 *so_datalen_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -1116,7 +1061,7 @@ wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
total_size = sizeof(iovec_app_t) * (uint64)si_data_len;
|
||||
if (!validate_native_addr(so_datalen_app, sizeof(uint32))
|
||||
|| total_size >= UINT32_MAX
|
||||
|| !validate_native_addr((void*)si_data, (uint32)total_size))
|
||||
|| !validate_native_addr((void *)si_data, (uint32)total_size))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
total_size = sizeof(wasi_ciovec_t) * (uint64)si_data_len;
|
||||
@ -1131,12 +1076,11 @@ wasi_sock_send(wasm_exec_env_t exec_env,
|
||||
err = (wasi_errno_t)-1;
|
||||
goto fail;
|
||||
}
|
||||
ciovec->buf = (char*)addr_app_to_native(si_data->buf_offset);
|
||||
ciovec->buf = (char *)addr_app_to_native(si_data->buf_offset);
|
||||
ciovec->buf_len = si_data->buf_len;
|
||||
}
|
||||
|
||||
err = wasmtime_ssp_sock_send(curfds, sock,
|
||||
ciovec_begin, si_data_len,
|
||||
err = wasmtime_ssp_sock_send(curfds, sock, ciovec_begin, si_data_len,
|
||||
si_flags, &so_datalen);
|
||||
if (err)
|
||||
goto fail;
|
||||
@ -1152,8 +1096,7 @@ fail:
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
wasi_sock_shutdown(wasm_exec_env_t exec_env,
|
||||
wasi_fd_t sock, wasi_sdflags_t how)
|
||||
wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
|
||||
@ -1171,8 +1114,10 @@ wasi_sched_yield(wasm_exec_env_t exec_env)
|
||||
return wasmtime_ssp_sched_yield();
|
||||
}
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, wasi_##func_name, signature, NULL }
|
||||
/* clang-format on */
|
||||
|
||||
static NativeSymbol native_symbols_libc_wasi[] = {
|
||||
REG_NATIVE_FUNC(args_get, "(**)i"),
|
||||
@ -1228,4 +1173,3 @@ get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis)
|
||||
*p_libc_wasi_apis = native_symbols_libc_wasi;
|
||||
return sizeof(native_symbols_libc_wasi) / sizeof(NativeSymbol);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
* Part of the Wasmtime Project, under the Apache License v2.0 with
|
||||
* LLVM Exceptions. See
|
||||
* https://github.com/bytecodealliance/wasmtime/blob/main/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
|
||||
@ -13,6 +15,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifndef _Static_assert
|
||||
#define _Static_assert static_assert
|
||||
@ -28,7 +32,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
_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");
|
||||
@ -891,5 +894,6 @@ __wasi_errno_t wasmtime_ssp_sched_yield(void)
|
||||
|
||||
#undef WASMTIME_SSP_SYSCALL_NAME
|
||||
|
||||
#endif
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* end of WASMTIME_SSP_H */
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -32,13 +34,13 @@
|
||||
#define LOCKS_SHARED(...) LOCK_ANNOTATE(shared_lock_function(__VA_ARGS__))
|
||||
|
||||
#define TRYLOCKS_EXCLUSIVE(...) \
|
||||
LOCK_ANNOTATE(exclusive_trylock_function(__VA_ARGS__))
|
||||
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__))
|
||||
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__))
|
||||
|
||||
@ -50,8 +52,10 @@ struct LOCKABLE mutex {
|
||||
pthread_mutex_t object;
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
#define MUTEX_INITIALIZER \
|
||||
{ PTHREAD_MUTEX_INITIALIZER }
|
||||
{ PTHREAD_MUTEX_INITIALIZER }
|
||||
/* clang-format on */
|
||||
|
||||
static inline bool
|
||||
mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
|
||||
@ -117,14 +121,15 @@ rwlock_destroy(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
|
||||
|
||||
struct LOCKABLE cond {
|
||||
pthread_cond_t object;
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
clockid_t clock;
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline bool
|
||||
cond_init_monotonic(struct cond *cond) {
|
||||
cond_init_monotonic(struct cond *cond)
|
||||
{
|
||||
bool ret = false;
|
||||
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
|
||||
pthread_condattr_t attr;
|
||||
@ -147,8 +152,8 @@ fail:
|
||||
ret = true;
|
||||
#endif
|
||||
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
cond->clock = CLOCK_MONOTONIC;
|
||||
#endif
|
||||
return ret;
|
||||
@ -159,28 +164,29 @@ cond_init_realtime(struct cond *cond)
|
||||
{
|
||||
if (pthread_cond_init(&cond->object, NULL) != 0)
|
||||
return false;
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
|
||||
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
cond->clock = CLOCK_REALTIME;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void
|
||||
cond_destroy(struct cond *cond) {
|
||||
cond_destroy(struct cond *cond)
|
||||
{
|
||||
pthread_cond_destroy(&cond->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
cond_signal(struct cond *cond) {
|
||||
cond_signal(struct cond *cond)
|
||||
{
|
||||
pthread_cond_signal(&cond->object);
|
||||
}
|
||||
|
||||
#if !CONFIG_HAS_CLOCK_NANOSLEEP
|
||||
static inline bool
|
||||
cond_timedwait(struct cond *cond, struct mutex *lock,
|
||||
uint64_t timeout, bool abstime)
|
||||
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
||||
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {
|
||||
@ -220,8 +226,8 @@ cond_timedwait(struct cond *cond, struct mutex *lock,
|
||||
else {
|
||||
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
/* Implementation supports relative timeouts. */
|
||||
ret = pthread_cond_timedwait_relative_np(&cond->object,
|
||||
&lock->object, &ts);
|
||||
ret = pthread_cond_timedwait_relative_np(&cond->object, &lock->object,
|
||||
&ts);
|
||||
bh_assert((ret == 0 || ret == ETIMEDOUT)
|
||||
&& "pthread_cond_timedwait_relative_np() failed");
|
||||
return ret == ETIMEDOUT;
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -12,29 +14,29 @@
|
||||
#ifndef COMMON_LIMITS_H
|
||||
#define COMMON_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_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)
|
||||
#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
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -20,41 +22,48 @@ struct fd_prestat;
|
||||
struct syscalls;
|
||||
|
||||
struct fd_table {
|
||||
struct rwlock lock;
|
||||
struct fd_entry *entries;
|
||||
size_t size;
|
||||
size_t used;
|
||||
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 rwlock lock;
|
||||
struct fd_prestat *prestats;
|
||||
size_t size;
|
||||
size_t used;
|
||||
};
|
||||
|
||||
struct argv_environ_values {
|
||||
const char *argv_buf;
|
||||
size_t argv_buf_size;
|
||||
char **argv_list;
|
||||
size_t argc;
|
||||
char *environ_buf;
|
||||
size_t environ_buf_size;
|
||||
char **environ_list;
|
||||
size_t environ_count;
|
||||
const char *argv_buf;
|
||||
size_t argv_buf_size;
|
||||
char **argv_list;
|
||||
size_t argc;
|
||||
char *environ_buf;
|
||||
size_t environ_buf_size;
|
||||
char **environ_list;
|
||||
size_t environ_count;
|
||||
};
|
||||
|
||||
bool fd_table_init(struct fd_table *);
|
||||
bool fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
|
||||
bool 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 *argv_environ,
|
||||
char *argv_buf, size_t argv_buf_size,
|
||||
char **argv_list, size_t argc,
|
||||
char *environ_buf, size_t environ_buf_size,
|
||||
char **environ_list, size_t environ_count);
|
||||
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);
|
||||
bool
|
||||
fd_table_init(struct fd_table *);
|
||||
bool
|
||||
fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
|
||||
bool
|
||||
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 *argv_environ, char *argv_buf,
|
||||
size_t argv_buf_size, char **argv_list, size_t argc,
|
||||
char *environ_buf, size_t environ_buf_size,
|
||||
char **environ_list, size_t environ_count);
|
||||
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
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -15,76 +17,82 @@
|
||||
// LIST: Double-linked list.
|
||||
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *l_first; \
|
||||
}
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
struct name { \
|
||||
struct type *l_first; \
|
||||
}
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *l_next; \
|
||||
struct type **l_prev; \
|
||||
}
|
||||
/* clang-format off */
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
/* clang-format on */
|
||||
|
||||
#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)
|
||||
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; \
|
||||
}
|
||||
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_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)
|
||||
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
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -15,8 +17,10 @@
|
||||
|
||||
#if CONFIG_HAS_ARC4RANDOM_BUF
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
arc4random_buf(buf, len);
|
||||
void
|
||||
random_buf(void *buf, size_t len)
|
||||
{
|
||||
arc4random_buf(buf, len);
|
||||
}
|
||||
|
||||
#elif CONFIG_HAS_GETRANDOM
|
||||
@ -25,42 +29,48 @@ void random_buf(void *buf, size_t len) {
|
||||
#include <sys/random.h>
|
||||
#endif
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
for (;;) {
|
||||
ssize_t x = getrandom(buf, len, 0);
|
||||
if (x < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
os_printf("getrandom failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
if ((size_t)x == len)
|
||||
return;
|
||||
buf = (void *)((unsigned char *)buf + x);
|
||||
len -= (size_t)x;
|
||||
}
|
||||
void
|
||||
random_buf(void *buf, size_t len)
|
||||
{
|
||||
for (;;) {
|
||||
ssize_t x = getrandom(buf, len, 0);
|
||||
if (x < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
os_printf("getrandom failed: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
if ((size_t)x == len)
|
||||
return;
|
||||
buf = (void *)((unsigned char *)buf + x);
|
||||
len -= (size_t)x;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int urandom;
|
||||
|
||||
static void open_urandom(void) {
|
||||
urandom = open("/dev/urandom", O_RDONLY);
|
||||
if (urandom < 0) {
|
||||
os_printf("Failed to open /dev/urandom\n");
|
||||
abort();
|
||||
}
|
||||
static void
|
||||
open_urandom(void)
|
||||
{
|
||||
urandom = open("/dev/urandom", O_RDONLY);
|
||||
if (urandom < 0) {
|
||||
os_printf("Failed to open /dev/urandom\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void random_buf(void *buf, size_t len) {
|
||||
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
|
||||
pthread_once(&open_once, open_urandom);
|
||||
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) {
|
||||
os_printf("Short read on /dev/urandom\n");
|
||||
abort();
|
||||
}
|
||||
if ((size_t)read(urandom, buf, len) != len) {
|
||||
os_printf("Short read on /dev/urandom\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -72,15 +82,17 @@ void random_buf(void *buf, size_t len) {
|
||||
// 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -12,7 +14,8 @@
|
||||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
void random_buf(void *, size_t);
|
||||
void
|
||||
random_buf(void *, size_t);
|
||||
uintmax_t random_uniform(uintmax_t);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -46,8 +48,8 @@ refcount_acquire(struct refcount *r) PRODUCES(*r)
|
||||
static inline bool
|
||||
refcount_release(struct refcount *r) CONSUMES(*r)
|
||||
{
|
||||
int old = (int)atomic_fetch_sub_explicit(&r->count, 1,
|
||||
memory_order_release);
|
||||
int old =
|
||||
(int)atomic_fetch_sub_explicit(&r->count, 1, memory_order_release);
|
||||
bh_assert(old != 0 && "Reference count becoming negative");
|
||||
return old == 1;
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -12,6 +14,8 @@
|
||||
#ifndef RIGHTS_H
|
||||
#define RIGHTS_H
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#define RIGHTS_ALL \
|
||||
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
|
||||
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
|
||||
@ -80,4 +84,6 @@
|
||||
__WASI_RIGHT_POLL_FD_READWRITE)
|
||||
#define RIGHTS_TTY_INHERITING 0
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -12,6 +14,7 @@
|
||||
#ifndef SIGNALS_H
|
||||
#define SIGNALS_H
|
||||
|
||||
void signals_init(void);
|
||||
void
|
||||
signals_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -14,7 +16,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__) || (defined(ANDROID) && __ANDROID_API__ < 28)
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__) \
|
||||
|| (defined(ANDROID) && __ANDROID_API__ < 28)
|
||||
#define CONFIG_HAS_ARC4RANDOM_BUF 1
|
||||
#else
|
||||
#define CONFIG_HAS_ARC4RANDOM_BUF 0
|
||||
@ -22,10 +25,9 @@
|
||||
|
||||
// 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))
|
||||
#if defined(__linux__) \
|
||||
&& (!defined(__GLIBC__) || __GLIBC__ > 2 \
|
||||
|| (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
|
||||
#define CONFIG_HAS_GETRANDOM 1
|
||||
#else
|
||||
#define CONFIG_HAS_GETRANDOM 0
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -27,7 +29,8 @@ bh_strndup(const char *s, size_t n)
|
||||
}
|
||||
|
||||
char *
|
||||
str_nullterminate(const char *s, size_t len) {
|
||||
str_nullterminate(const char *s, size_t len)
|
||||
{
|
||||
/* Copy string */
|
||||
char *ret = bh_strndup(s, len);
|
||||
|
||||
@ -40,5 +43,5 @@ str_nullterminate(const char *s, size_t len) {
|
||||
errno = EILSEQ;
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
|
||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
||||
// information.
|
||||
//
|
||||
// Significant parts of this file are derived from cloudabi-utils. See
|
||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
||||
@ -14,6 +16,7 @@
|
||||
|
||||
#include "ssp_config.h"
|
||||
|
||||
char *str_nullterminate(const char *, size_t);
|
||||
char *
|
||||
str_nullterminate(const char *, size_t);
|
||||
|
||||
#endif
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
|
||||
typedef struct {
|
||||
bh_list_link l;
|
||||
|
||||
void (*destroy_cb)(WASMCluster *);
|
||||
} DestroyCallBackNode;
|
||||
|
||||
@ -133,8 +132,7 @@ wasm_cluster_create(WASMExecEnv *exec_env)
|
||||
}
|
||||
|
||||
/* Prepare the aux stack top and size for every thread */
|
||||
if (!wasm_exec_env_get_aux_stack(exec_env,
|
||||
&aux_stack_start,
|
||||
if (!wasm_exec_env_get_aux_stack(exec_env, &aux_stack_start,
|
||||
&aux_stack_size)) {
|
||||
LOG_VERBOSE("No aux stack info for this module, can't create thread");
|
||||
|
||||
@ -167,13 +165,13 @@ wasm_cluster_create(WASMExecEnv *exec_env)
|
||||
total_size = cluster_max_thread_num * sizeof(uint32);
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(cluster->stack_tops =
|
||||
wasm_runtime_malloc((uint32)total_size))) {
|
||||
wasm_runtime_malloc((uint32)total_size))) {
|
||||
goto fail;
|
||||
}
|
||||
memset(cluster->stack_tops, 0, (uint32)total_size);
|
||||
|
||||
if (!(cluster->stack_segment_occupied =
|
||||
wasm_runtime_malloc(cluster_max_thread_num * sizeof(bool)))) {
|
||||
wasm_runtime_malloc(cluster_max_thread_num * sizeof(bool)))) {
|
||||
goto fail;
|
||||
}
|
||||
memset(cluster->stack_segment_occupied, 0,
|
||||
@ -215,8 +213,8 @@ destroy_cluster_visitor(void *node, void *user_data)
|
||||
void
|
||||
wasm_cluster_destroy(WASMCluster *cluster)
|
||||
{
|
||||
traverse_list(destroy_callback_list,
|
||||
destroy_cluster_visitor, (void *)cluster);
|
||||
traverse_list(destroy_callback_list, destroy_cluster_visitor,
|
||||
(void *)cluster);
|
||||
|
||||
/* Remove the cluster from the cluster list */
|
||||
os_mutex_lock(&cluster_list_lock);
|
||||
@ -302,7 +300,7 @@ wasm_cluster_search_exec_env(WASMCluster *cluster,
|
||||
}
|
||||
|
||||
/* search the global cluster list to find if the given
|
||||
module instance have a corresponding exec_env */
|
||||
module instance have a corresponding exec_env */
|
||||
WASMExecEnv *
|
||||
wasm_clusters_search_exec_env(WASMModuleInstanceCommon *module_inst)
|
||||
{
|
||||
@ -338,21 +336,19 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(new_module_inst =
|
||||
wasm_runtime_instantiate_internal(module, true, 8192,
|
||||
0, NULL, 0))) {
|
||||
if (!(new_module_inst = wasm_runtime_instantiate_internal(
|
||||
module, true, 8192, 0, NULL, 0))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (module_inst) {
|
||||
/* Set custom_data to new module instance */
|
||||
wasm_runtime_set_custom_data_internal(
|
||||
new_module_inst,
|
||||
wasm_runtime_get_custom_data(module_inst));
|
||||
new_module_inst, wasm_runtime_get_custom_data(module_inst));
|
||||
}
|
||||
|
||||
new_exec_env = wasm_exec_env_create_internal(
|
||||
new_module_inst, exec_env->wasm_stack_size);
|
||||
new_exec_env = wasm_exec_env_create_internal(new_module_inst,
|
||||
exec_env->wasm_stack_size);
|
||||
if (!new_exec_env)
|
||||
goto fail1;
|
||||
|
||||
@ -400,7 +396,7 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
|
||||
}
|
||||
|
||||
/* start routine of thread manager */
|
||||
static void*
|
||||
static void *
|
||||
thread_manager_start_routine(void *arg)
|
||||
{
|
||||
void *ret;
|
||||
@ -432,8 +428,7 @@ thread_manager_start_routine(void *arg)
|
||||
int32
|
||||
wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||
wasm_module_inst_t module_inst,
|
||||
void* (*thread_routine)(void *),
|
||||
void *arg)
|
||||
void *(*thread_routine)(void *), void *arg)
|
||||
{
|
||||
WASMCluster *cluster;
|
||||
WASMExecEnv *new_exec_env;
|
||||
@ -443,8 +438,8 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||
cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
bh_assert(cluster);
|
||||
|
||||
new_exec_env = wasm_exec_env_create_internal(
|
||||
module_inst, exec_env->wasm_stack_size);
|
||||
new_exec_env =
|
||||
wasm_exec_env_create_internal(module_inst, exec_env->wasm_stack_size);
|
||||
if (!new_exec_env)
|
||||
return -1;
|
||||
|
||||
@ -466,9 +461,10 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||
new_exec_env->thread_start_routine = thread_routine;
|
||||
new_exec_env->thread_arg = arg;
|
||||
|
||||
if (0 != os_thread_create(&tid, thread_manager_start_routine,
|
||||
(void *)new_exec_env,
|
||||
APP_THREAD_STACK_SIZE_DEFAULT)) {
|
||||
if (0
|
||||
!= os_thread_create(&tid, thread_manager_start_routine,
|
||||
(void *)new_exec_env,
|
||||
APP_THREAD_STACK_SIZE_DEFAULT)) {
|
||||
goto fail3;
|
||||
}
|
||||
|
||||
@ -520,9 +516,10 @@ wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status)
|
||||
}
|
||||
|
||||
inline static bool
|
||||
wasm_cluster_thread_is_running(WASMExecEnv *exec_env) {
|
||||
return exec_env->current_status->running_status == STATUS_RUNNING
|
||||
|| exec_env->current_status->running_status == STATUS_STEP;
|
||||
wasm_cluster_thread_is_running(WASMExecEnv *exec_env)
|
||||
{
|
||||
return exec_env->current_status->running_status == STATUS_RUNNING
|
||||
|| exec_env->current_status->running_status == STATUS_STEP;
|
||||
}
|
||||
|
||||
void
|
||||
@ -532,7 +529,7 @@ wasm_cluster_clear_thread_signal(WASMExecEnv *exec_env)
|
||||
}
|
||||
|
||||
void
|
||||
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 * status)
|
||||
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status)
|
||||
{
|
||||
os_mutex_lock(&exec_env->current_status->wait_lock);
|
||||
while (wasm_cluster_thread_is_running(exec_env)) {
|
||||
@ -576,21 +573,23 @@ wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo)
|
||||
}
|
||||
}
|
||||
|
||||
void wasm_cluster_thread_exited(WASMExecEnv *exec_env)
|
||||
void
|
||||
wasm_cluster_thread_exited(WASMExecEnv *exec_env)
|
||||
{
|
||||
exec_env->current_status->running_status = STATUS_EXIT;
|
||||
os_cond_signal(&exec_env->current_status->wait_cond);
|
||||
|
||||
}
|
||||
|
||||
void wasm_cluster_thread_continue(WASMExecEnv *exec_env)
|
||||
void
|
||||
wasm_cluster_thread_continue(WASMExecEnv *exec_env)
|
||||
{
|
||||
wasm_cluster_clear_thread_signal(exec_env);
|
||||
exec_env->current_status->running_status = STATUS_RUNNING;
|
||||
os_cond_signal(&exec_env->wait_cond);
|
||||
}
|
||||
|
||||
void wasm_cluster_thread_step(WASMExecEnv *exec_env)
|
||||
void
|
||||
wasm_cluster_thread_step(WASMExecEnv *exec_env)
|
||||
{
|
||||
exec_env->current_status->running_status = STATUS_STEP;
|
||||
os_cond_signal(&exec_env->wait_cond);
|
||||
@ -654,12 +653,12 @@ wasm_cluster_cancel_thread(WASMExecEnv *exec_env)
|
||||
{
|
||||
/* Set the termination flag */
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TERM);
|
||||
wasm_cluster_thread_exited(exec_env);
|
||||
wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TERM);
|
||||
wasm_cluster_thread_exited(exec_env);
|
||||
#else
|
||||
exec_env->suspend_flags.flags |= 0x01;
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -678,16 +677,15 @@ terminate_thread_visitor(void *node, void *user_data)
|
||||
void
|
||||
wasm_cluster_terminate_all(WASMCluster *cluster)
|
||||
{
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
terminate_thread_visitor, NULL);
|
||||
traverse_list(&cluster->exec_env_list, terminate_thread_visitor, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_cluster_terminate_all_except_self(WASMCluster *cluster,
|
||||
WASMExecEnv *exec_env)
|
||||
{
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
terminate_thread_visitor, (void *)exec_env);
|
||||
traverse_list(&cluster->exec_env_list, terminate_thread_visitor,
|
||||
(void *)exec_env);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -726,16 +724,15 @@ suspend_thread_visitor(void *node, void *user_data)
|
||||
void
|
||||
wasm_cluster_suspend_all(WASMCluster *cluster)
|
||||
{
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
suspend_thread_visitor, NULL);
|
||||
traverse_list(&cluster->exec_env_list, suspend_thread_visitor, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_cluster_suspend_all_except_self(WASMCluster *cluster,
|
||||
WASMExecEnv *exec_env)
|
||||
{
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
suspend_thread_visitor, (void *)exec_env);
|
||||
traverse_list(&cluster->exec_env_list, suspend_thread_visitor,
|
||||
(void *)exec_env);
|
||||
}
|
||||
|
||||
void
|
||||
@ -765,8 +762,7 @@ set_exception_visitor(void *node, void *user_data)
|
||||
WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
|
||||
WASMExecEnv *exec_env = (WASMExecEnv *)user_data;
|
||||
WASMModuleInstanceCommon *module_inst = get_module_inst(exec_env);
|
||||
WASMModuleInstanceCommon *curr_module_inst =
|
||||
get_module_inst(curr_exec_env);
|
||||
WASMModuleInstanceCommon *curr_module_inst = get_module_inst(curr_exec_env);
|
||||
const char *exception = wasm_runtime_get_exception(module_inst);
|
||||
/* skip "Exception: " */
|
||||
exception += 11;
|
||||
@ -806,7 +802,6 @@ wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
|
||||
cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
bh_assert(cluster);
|
||||
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
set_custom_data_visitor,
|
||||
traverse_list(&cluster->exec_env_list, set_custom_data_visitor,
|
||||
custom_data);
|
||||
}
|
||||
|
||||
@ -16,30 +16,28 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
#define WAMR_SIG_TRAP (5)
|
||||
#define WAMR_SIG_STOP (19)
|
||||
#define WAMR_SIG_TERM (15)
|
||||
#define WAMR_SIG_SINGSTEP (0x1ff)
|
||||
#define WAMR_SIG_TRAP (5)
|
||||
#define WAMR_SIG_STOP (19)
|
||||
#define WAMR_SIG_TERM (15)
|
||||
#define WAMR_SIG_SINGSTEP (0x1ff)
|
||||
|
||||
#define STATUS_RUNNING (0)
|
||||
#define STATUS_STOP (1)
|
||||
#define STATUS_EXIT (2)
|
||||
#define STATUS_STEP (3)
|
||||
#define STATUS_STOP (1)
|
||||
#define STATUS_EXIT (2)
|
||||
#define STATUS_STEP (3)
|
||||
|
||||
#define IS_WAMR_TERM_SIG(signo) \
|
||||
((signo) == WAMR_SIG_TERM)
|
||||
#define IS_WAMR_TERM_SIG(signo) ((signo) == WAMR_SIG_TERM)
|
||||
|
||||
#define IS_WAMR_STOP_SIG(signo) \
|
||||
((signo) == WAMR_SIG_STOP || (signo) == WAMR_SIG_TRAP)
|
||||
|
||||
typedef struct WASMCurrentEnvStatus
|
||||
{
|
||||
uint64 signal_flag:32;
|
||||
uint64 step_count:16;
|
||||
uint64 running_status:16;
|
||||
typedef struct WASMCurrentEnvStatus {
|
||||
uint64 signal_flag : 32;
|
||||
uint64 step_count : 16;
|
||||
uint64 running_status : 16;
|
||||
korp_mutex wait_lock;
|
||||
korp_cond wait_cond;
|
||||
}WASMCurrentEnvStatus;
|
||||
} WASMCurrentEnvStatus;
|
||||
|
||||
WASMCurrentEnvStatus *
|
||||
wasm_cluster_create_exenv_status();
|
||||
@ -57,7 +55,7 @@ void
|
||||
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
|
||||
|
||||
void
|
||||
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 * status);
|
||||
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status);
|
||||
|
||||
void
|
||||
wasm_cluster_thread_exited(WASMExecEnv *exec_env);
|
||||
@ -72,8 +70,7 @@ void
|
||||
wasm_cluster_thread_step(WASMExecEnv *exec_env);
|
||||
|
||||
#endif
|
||||
typedef struct WASMCluster
|
||||
{
|
||||
typedef struct WASMCluster {
|
||||
struct WASMCluster *next;
|
||||
|
||||
korp_mutex lock;
|
||||
@ -89,7 +86,8 @@ typedef struct WASMCluster
|
||||
bool *stack_segment_occupied;
|
||||
} WASMCluster;
|
||||
|
||||
void wasm_cluster_set_max_thread_num(uint32 num);
|
||||
void
|
||||
wasm_cluster_set_max_thread_num(uint32 num);
|
||||
|
||||
bool
|
||||
thread_manager_init();
|
||||
@ -106,14 +104,13 @@ void
|
||||
wasm_cluster_destroy(WASMCluster *cluster);
|
||||
|
||||
/* Get the cluster of the current exec_env */
|
||||
WASMCluster*
|
||||
WASMCluster *
|
||||
wasm_exec_env_get_cluster(WASMExecEnv *exec_env);
|
||||
|
||||
int32
|
||||
wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||
wasm_module_inst_t module_inst,
|
||||
void* (*thread_routine)(void *),
|
||||
void *arg);
|
||||
void *(*thread_routine)(void *), void *arg);
|
||||
|
||||
int32
|
||||
wasm_cluster_join_thread(WASMExecEnv *exec_env, void **ret_val);
|
||||
|
||||
Reference in New Issue
Block a user