From 53f1655a3b886cb590d2b7ac22aa9f25c39c93b5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 28 Aug 2023 16:23:50 +0900 Subject: [PATCH 01/40] some logic to terminate blocking op basically a port from https://github.com/yamt/garbage/blob/master/c/sig2/test.c this ported version has not been tested yet though. --- core/iwasm/common/wasm_blocking_op.c | 73 +++++++++++++++++++ core/iwasm/common/wasm_runtime_common.h | 9 +++ core/iwasm/common/wasm_suspend_flags.h | 2 + .../platform/common/posix/posix_thread.c | 57 +++++++++++++++ .../platform/include/platform_api_extension.h | 8 ++ 5 files changed, 149 insertions(+) create mode 100644 core/iwasm/common/wasm_blocking_op.c diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c new file mode 100644 index 0000000000..69123097d0 --- /dev/null +++ b/core/iwasm/common/wasm_blocking_op.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_exec_env.h" + +#include "bh_platform.h" +#include "bh_common.h" +#include "bh_assert.h" + +typedef WASMExecEnv *wasm_exec_env_t; + +#define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock) +#define UNLOCK(env) WASM_SUSPEND_FLAGS_UNLOCK((env)->wait_lock) + +#define ISSET(env, bit) \ + ((WASM_SUSPEND_FLAGS_GET((env)->suspend_flags) & WASM_SUSPEND_FLAG_##bit) \ + != 0) +#define SET(env, bit) \ + WASM_SUSPEND_FLAGS_FETCH_OR((env)->suspend_flags, WASM_SUSPEND_FLAG_##bit) +#define CLR(env, bit) \ + WASM_SUSPEND_FLAGS_FETCH_AND((env)->suspend_flags, ~WASM_SUSPEND_FLAG_##bit) + +bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t env) +{ + LOCK(env); + bh_assert(!ISSET(env, BLOCKING)); + SET(env, BLOCKING); + if (ISSET(env, TERMINATE)) { + CLR(env, BLOCKING); + UNLOCK(env); + return false; + } + UNLOCK(env); + os_begin_blocking_op(); + return true; +} + +void +wasm_runtime_end_blocking_op(wasm_exec_env_t env) +{ + LOCK(env); + bh_assert(ISSET(env, BLOCKING)); + CLR(env, BLOCKING); + UNLOCK(env); + os_end_blocking_op(); +} + +void +wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) +{ + /* + * ISSET(BLOCKING) here means that the target thread + * is in somewhere between wasm_begin_blocking_op and + * wasm_end_blocking_op. + * keep waking it up until it reaches wasm_end_blocking_op, + * which clears the BLOCKING bit. + * + * this dumb loop is necessary because posix doesn't provide + * a way to unmask signal and block atomically. + */ + + LOCK(env); + SET(env, TERMINATE); + while (ISSET(env, BLOCKING)) { + os_wakeup_blocking_op(env->handle); + + /* relax a bit */ + os_usleep(50 * 1000); + } +} diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index 4e3bc80af7..19d0af117e 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -1040,6 +1040,15 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, const char *global_name); +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_end_blocking_op(WASMExecEnv *exec_env); + +void +wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env); + #ifdef __cplusplus } #endif diff --git a/core/iwasm/common/wasm_suspend_flags.h b/core/iwasm/common/wasm_suspend_flags.h index b7ecbb0b23..b182b2b5f0 100644 --- a/core/iwasm/common/wasm_suspend_flags.h +++ b/core/iwasm/common/wasm_suspend_flags.h @@ -20,6 +20,8 @@ extern "C" { #define WASM_SUSPEND_FLAG_BREAKPOINT 0x4 /* Return from pthread_exit */ #define WASM_SUSPEND_FLAG_EXIT 0x8 +/* The thread might be blocking */ +#define WASM_SUSPEND_FLAG_BLOCKING 0x10 typedef union WASMSuspendFlags { bh_atomic_32_t flags; diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index b1460f6b53..648d242978 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -17,6 +17,9 @@ typedef struct { #endif } thread_wrapper_arg; +static int +os_blocking_op_init(); + #ifdef OS_ENABLE_HW_BOUND_CHECK /* The signal handler passed to os_thread_signal_init() */ static os_thread_local_attribute os_signal_handler signal_handler; @@ -425,6 +428,7 @@ os_thread_get_stack_boundary() * the stack guard pages are set and signal alternate stack are set. */ static os_thread_local_attribute bool thread_signal_inited = false; +static bool g_proc_signal_inited = false; #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 /* The signal alternate stack base addr */ @@ -582,6 +586,13 @@ os_thread_signal_init(os_signal_handler handler) if (thread_signal_inited) return 0; + if (g_proc_signal_inited) { + if (os_blocking_op_init() != BHT_OK) { + return -1; + } + g_proc_signal_inited = true; + } + #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 if (!init_stack_guard_pages()) { os_printf("Failed to init stack guard pages\n"); @@ -627,6 +638,7 @@ os_thread_signal_init(os_signal_handler handler) #endif signal_handler = handler; thread_signal_inited = true; + os_end_blocking_op(); return 0; fail3: @@ -695,3 +707,48 @@ os_sigreturn() #endif } #endif /* end of OS_ENABLE_HW_BOUND_CHECK */ + +int g_blocking_op_signo; +sigset_t g_blocking_op_sigmask; + +static void +blocking_op_sighandler(int signo) +{ + /* nothing */ +} + +static int +os_blocking_op_init() +{ + g_blocking_op_signo = SIGUSR1; /* XXX make this configurable */ + sigemptyset(&g_blocking_op_sigmask); + sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo); + + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = blocking_op_sighandler; + return sigaction(g_blocking_op_signo, &sa, NULL) ? BHT_ERROR : BHT_OK; +} + +void +os_begin_blocking_op() +{ + sigprocmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); +} + +void +os_end_blocking_op() +{ + sigprocmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); +} + +int +os_wakeup_blocking_op(korp_tid tid) +{ + int ret = pthread_kill(tid, g_blocking_op_signo); + if (ret != 0) { + return BHT_ERROR; + } + return BHT_OK; +} diff --git a/core/shared/platform/include/platform_api_extension.h b/core/shared/platform/include/platform_api_extension.h index 5b7b556e09..3d19c90cd4 100644 --- a/core/shared/platform/include/platform_api_extension.h +++ b/core/shared/platform/include/platform_api_extension.h @@ -323,6 +323,14 @@ os_sem_getvalue(korp_sem *sem, int *sval); int os_sem_unlink(const char *name); +/* */ +void +os_begin_blocking_op(); +void +os_end_blocking_op(); +int +os_wakeup_blocking_op(korp_tid tid); + /**************************************************** * Section 2 * * Socket support * From 5ea4c0372e117d2e6d5b605931de901e1e1f4435 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 28 Aug 2023 16:32:31 +0900 Subject: [PATCH 02/40] avoid sleeping with a mutex held --- core/iwasm/common/wasm_blocking_op.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index 69123097d0..cc913612b2 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -65,9 +65,11 @@ wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) LOCK(env); SET(env, TERMINATE); while (ISSET(env, BLOCKING)) { + UNLOCK(env); os_wakeup_blocking_op(env->handle); /* relax a bit */ os_usleep(50 * 1000); + LOCK(env); } } From 6fbe85c098dd1345b2a30b88bb5d33b70bd2ad87 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 16:12:50 +0900 Subject: [PATCH 03/40] comment --- core/shared/platform/common/posix/posix_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index 648d242978..7b94a1396b 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -428,7 +428,7 @@ os_thread_get_stack_boundary() * the stack guard pages are set and signal alternate stack are set. */ static os_thread_local_attribute bool thread_signal_inited = false; -static bool g_proc_signal_inited = false; +static bool g_proc_signal_inited = false; /* process-wide initialization */ #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 /* The signal alternate stack base addr */ From 63bdb2145ec42d71798e7b2b4550c853da0e7313 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 16:13:01 +0900 Subject: [PATCH 04/40] fix an inverted condition --- core/shared/platform/common/posix/posix_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index 7b94a1396b..cdeaa20dad 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -586,7 +586,7 @@ os_thread_signal_init(os_signal_handler handler) if (thread_signal_inited) return 0; - if (g_proc_signal_inited) { + if (!g_proc_signal_inited) { if (os_blocking_op_init() != BHT_OK) { return -1; } From 1bfc73784fb621f6f9ab06f41be63b94062b89c1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 16:13:51 +0900 Subject: [PATCH 05/40] wasm_export.h: add wasm_runtime_{begin|end}_blocking_op --- core/iwasm/include/wasm_export.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 34206db290..5f5a0ce850 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1546,6 +1546,12 @@ wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_context(wasm_module_inst_t inst, void *key); +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_end_blocking_op(wasm_exec_env_t exec_env); + /* clang-format on */ #ifdef __cplusplus From ec28fa2803f71fcf4607a906b866e6320174c692 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 16:16:11 +0900 Subject: [PATCH 06/40] make set_thread_cancel_flags interrupt blocking op --- core/iwasm/libraries/thread-mgr/thread_manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.c b/core/iwasm/libraries/thread-mgr/thread_manager.c index 06be3bc89d..fa8d972201 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -1059,6 +1059,8 @@ set_thread_cancel_flags(WASMExecEnv *exec_env) WASM_SUSPEND_FLAG_TERMINATE); os_mutex_unlock(&exec_env->wait_lock); + + wasm_runtime_interrupt_blocking_op(exec_env); } static void From acfd426a18ead3c26500626318f8ecc93b375dba Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 16:18:32 +0900 Subject: [PATCH 07/40] wasi: mark blocking ops explicitly for now, only update fd_read. it should be easy to apply to other methods as the necessary change is mostly mechanical. --- core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c | 3 ++- .../sandboxed-system-primitives/include/wasmtime_ssp.h | 3 +++ .../libc-wasi/sandboxed-system-primitives/src/posix.c | 10 ++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index 70ac4dc54f..8401c56117 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -496,7 +496,8 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread); + err = wasmtime_ssp_fd_read(exec_env, curfds, fd, iovec_begin, iovs_len, + &nread); if (err) goto fail; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index a531535520..7fe0ab4754 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -22,6 +22,8 @@ #include #include +#include "wasm_export.h" + /* clang-format off */ #ifdef __cplusplus @@ -675,6 +677,7 @@ __wasi_errno_t wasmtime_ssp_fd_pwrite( ) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_read( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_iovec_t *iovs, diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index a9831d770b..db22fa7a21 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -1036,8 +1036,9 @@ wasmtime_ssp_fd_pwrite(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_read(struct fd_table *curfds, __wasi_fd_t fd, - const __wasi_iovec_t *iov, size_t iovcnt, size_t *nread) +wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, + size_t *nread) { struct fd_object *fo; __wasi_errno_t error = @@ -1045,7 +1046,12 @@ wasmtime_ssp_fd_read(struct fd_table *curfds, __wasi_fd_t fd, if (error != 0) return error; + if (!wasm_runtime_begin_blocking_op(exec_env)) { + fd_object_release(fo); + return __WASI_EINTR; + } ssize_t len = readv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); + wasm_runtime_end_blocking_op(exec_env); fd_object_release(fo); if (len < 0) return convert_errno(errno); From 3114f909b2138bebf4cb9fb55015f9b70eee31b5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 18:27:53 +0900 Subject: [PATCH 08/40] separate blocking op initialization from thread signal init --- core/iwasm/common/wasm_runtime_common.c | 8 +++ .../platform/common/posix/posix_blocking_op.c | 60 +++++++++++++++++++ .../platform/common/posix/posix_thread.c | 57 ------------------ .../platform/include/platform_api_extension.h | 2 + 4 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 core/shared/platform/common/posix/posix_blocking_op.c diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 3a2f44c5f0..3357a76f18 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -457,9 +457,16 @@ wasm_runtime_env_init() } #endif + if (os_blocking_op_init() != BHT_OK) { + goto fail11; + } + os_end_blocking_op(); + return true; +fail11: #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 + aot_compiler_destroy(); fail10: #if WASM_ENABLE_FAST_JIT != 0 jit_compiler_destroy(); @@ -1421,6 +1428,7 @@ wasm_runtime_thread_env_inited(void) return false; #endif #endif + os_end_blocking_op(); return true; } diff --git a/core/shared/platform/common/posix/posix_blocking_op.c b/core/shared/platform/common/posix/posix_blocking_op.c new file mode 100644 index 0000000000..34375e0f8b --- /dev/null +++ b/core/shared/platform/common/posix/posix_blocking_op.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_extension.h" + +static bool g_blocking_op_inited = false; +static int g_blocking_op_signo; +static sigset_t g_blocking_op_sigmask; + +static void +blocking_op_sighandler(int signo) +{ + /* nothing */ +} + +int +os_blocking_op_init() +{ + if (g_blocking_op_inited) { + return BHT_OK; + } + + g_blocking_op_signo = SIGUSR1; /* XXX make this configurable */ + sigemptyset(&g_blocking_op_sigmask); + sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo); + + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = blocking_op_sighandler; + if (sigaction(g_blocking_op_signo, &sa, NULL)) { + return BHT_ERROR; + } + g_blocking_op_inited = true; + return BHT_OK; +} + +void +os_begin_blocking_op() +{ + sigprocmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); +} + +void +os_end_blocking_op() +{ + sigprocmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); +} + +int +os_wakeup_blocking_op(korp_tid tid) +{ + int ret = pthread_kill(tid, g_blocking_op_signo); + if (ret != 0) { + return BHT_ERROR; + } + return BHT_OK; +} diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index cdeaa20dad..b1460f6b53 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -17,9 +17,6 @@ typedef struct { #endif } thread_wrapper_arg; -static int -os_blocking_op_init(); - #ifdef OS_ENABLE_HW_BOUND_CHECK /* The signal handler passed to os_thread_signal_init() */ static os_thread_local_attribute os_signal_handler signal_handler; @@ -428,7 +425,6 @@ os_thread_get_stack_boundary() * the stack guard pages are set and signal alternate stack are set. */ static os_thread_local_attribute bool thread_signal_inited = false; -static bool g_proc_signal_inited = false; /* process-wide initialization */ #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 /* The signal alternate stack base addr */ @@ -586,13 +582,6 @@ os_thread_signal_init(os_signal_handler handler) if (thread_signal_inited) return 0; - if (!g_proc_signal_inited) { - if (os_blocking_op_init() != BHT_OK) { - return -1; - } - g_proc_signal_inited = true; - } - #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 if (!init_stack_guard_pages()) { os_printf("Failed to init stack guard pages\n"); @@ -638,7 +627,6 @@ os_thread_signal_init(os_signal_handler handler) #endif signal_handler = handler; thread_signal_inited = true; - os_end_blocking_op(); return 0; fail3: @@ -707,48 +695,3 @@ os_sigreturn() #endif } #endif /* end of OS_ENABLE_HW_BOUND_CHECK */ - -int g_blocking_op_signo; -sigset_t g_blocking_op_sigmask; - -static void -blocking_op_sighandler(int signo) -{ - /* nothing */ -} - -static int -os_blocking_op_init() -{ - g_blocking_op_signo = SIGUSR1; /* XXX make this configurable */ - sigemptyset(&g_blocking_op_sigmask); - sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo); - - struct sigaction sa; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = blocking_op_sighandler; - return sigaction(g_blocking_op_signo, &sa, NULL) ? BHT_ERROR : BHT_OK; -} - -void -os_begin_blocking_op() -{ - sigprocmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); -} - -void -os_end_blocking_op() -{ - sigprocmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); -} - -int -os_wakeup_blocking_op(korp_tid tid) -{ - int ret = pthread_kill(tid, g_blocking_op_signo); - if (ret != 0) { - return BHT_ERROR; - } - return BHT_OK; -} diff --git a/core/shared/platform/include/platform_api_extension.h b/core/shared/platform/include/platform_api_extension.h index 3d19c90cd4..2e54bdb0fe 100644 --- a/core/shared/platform/include/platform_api_extension.h +++ b/core/shared/platform/include/platform_api_extension.h @@ -324,6 +324,8 @@ int os_sem_unlink(const char *name); /* */ +int +os_blocking_op_init(); void os_begin_blocking_op(); void From 0dbcee3ae6ac0eccfeae9c648e0ef0f47cc89262 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 18:40:14 +0900 Subject: [PATCH 09/40] nuttx: update the file list --- product-mini/platforms/nuttx/wamr.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/product-mini/platforms/nuttx/wamr.mk b/product-mini/platforms/nuttx/wamr.mk index e5af62cc86..33c485a4bc 100644 --- a/product-mini/platforms/nuttx/wamr.mk +++ b/product-mini/platforms/nuttx/wamr.mk @@ -354,8 +354,10 @@ CFLAGS += -I$(IWASM_ROOT)/interpreter endif CSRCS += nuttx_platform.c \ + posix_blocking_op.c \ posix_thread.c \ posix_time.c \ + posix_sleep.c \ mem_alloc.c \ ems_kfc.c \ ems_alloc.c \ @@ -370,6 +372,7 @@ CSRCS += nuttx_platform.c \ bh_read_file.c \ runtime_timer.c \ wasm_application.c \ + wasm_blocking_op.c \ wasm_runtime_common.c \ wasm_native.c \ wasm_exec_env.c \ From f8c80707a7f4911919d453fd8b8954f5397b8fe9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 20:55:44 +0900 Subject: [PATCH 10/40] wasm_blocking_op.c: this stuff doesn't make sense w/o threads --- core/iwasm/common/wasm_blocking_op.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index cc913612b2..b2e869f1ac 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -9,6 +9,8 @@ #include "bh_common.h" #include "bh_assert.h" +#if WASM_ENABLE_THREAD_MGR != 0 + typedef WASMExecEnv *wasm_exec_env_t; #define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock) @@ -73,3 +75,5 @@ wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) LOCK(env); } } + +#endif /* WASM_ENABLE_THREAD_MGR != 0 */ From dee874bddf55a43d993aceecd83a7f4fe735f794 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 23:00:42 +0900 Subject: [PATCH 11/40] add dummy wasm_runtime_begin_blocking_op and wasm_runtime_end_blocking_op --- core/iwasm/common/wasm_blocking_op.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index b2e869f1ac..4148e3b158 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -76,4 +76,16 @@ wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) } } -#endif /* WASM_ENABLE_THREAD_MGR != 0 */ +#else /* WASM_ENABLE_THREAD_MGR */ + +bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t env) +{ + return true; +} + +void +wasm_runtime_end_blocking_op(wasm_exec_env_t env) +{} + +#endif /* WASM_ENABLE_THREAD_MGR */ From a5c3fe0285cff258a8430c963c4d3ceaa0fcc833 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 30 Aug 2023 23:27:20 +0900 Subject: [PATCH 12/40] fix build --- core/iwasm/common/wasm_blocking_op.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index 4148e3b158..22f98d9537 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include "wasm_exec_env.h" +#include "wasm_runtime_common.h" #include "bh_platform.h" #include "bh_common.h" @@ -11,8 +11,6 @@ #if WASM_ENABLE_THREAD_MGR != 0 -typedef WASMExecEnv *wasm_exec_env_t; - #define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock) #define UNLOCK(env) WASM_SUSPEND_FLAGS_UNLOCK((env)->wait_lock) From 926ad8829956f2c3855d7e0d41f2211ba18c1df3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 31 Aug 2023 13:47:39 +0900 Subject: [PATCH 13/40] OS_ENABLE_WAKEUP_BLOCKING_OP --- core/iwasm/common/wasm_blocking_op.c | 6 +++--- core/iwasm/common/wasm_runtime_common.c | 6 ++++++ core/shared/platform/common/posix/posix_blocking_op.c | 4 ++++ core/shared/platform/darwin/platform_internal.h | 2 ++ core/shared/platform/freebsd/platform_internal.h | 2 ++ core/shared/platform/linux/platform_internal.h | 2 ++ core/shared/platform/nuttx/platform_internal.h | 2 ++ 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index 22f98d9537..f299a4ddad 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -9,7 +9,7 @@ #include "bh_common.h" #include "bh_assert.h" -#if WASM_ENABLE_THREAD_MGR != 0 +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) #define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock) #define UNLOCK(env) WASM_SUSPEND_FLAGS_UNLOCK((env)->wait_lock) @@ -74,7 +74,7 @@ wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) } } -#else /* WASM_ENABLE_THREAD_MGR */ +#else /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */ bool wasm_runtime_begin_blocking_op(wasm_exec_env_t env) @@ -86,4 +86,4 @@ void wasm_runtime_end_blocking_op(wasm_exec_env_t env) {} -#endif /* WASM_ENABLE_THREAD_MGR */ +#endif /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */ diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 3357a76f18..7325d4ae68 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -457,16 +457,22 @@ wasm_runtime_env_init() } #endif +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) if (os_blocking_op_init() != BHT_OK) { goto fail11; } os_end_blocking_op(); +#endif return true; +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) fail11: #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 aot_compiler_destroy(); +#endif +#endif +#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 fail10: #if WASM_ENABLE_FAST_JIT != 0 jit_compiler_destroy(); diff --git a/core/shared/platform/common/posix/posix_blocking_op.c b/core/shared/platform/common/posix/posix_blocking_op.c index 34375e0f8b..81cdd5764e 100644 --- a/core/shared/platform/common/posix/posix_blocking_op.c +++ b/core/shared/platform/common/posix/posix_blocking_op.c @@ -5,6 +5,8 @@ #include "platform_api_extension.h" +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP + static bool g_blocking_op_inited = false; static int g_blocking_op_signo; static sigset_t g_blocking_op_sigmask; @@ -58,3 +60,5 @@ os_wakeup_blocking_op(korp_tid tid) } return BHT_OK; } + +#endif /* OS_ENABLE_WAKEUP_BLOCKING_OP */ diff --git a/core/shared/platform/darwin/platform_internal.h b/core/shared/platform/darwin/platform_internal.h index 3fd1c258e2..67e0edf3fb 100644 --- a/core/shared/platform/darwin/platform_internal.h +++ b/core/shared/platform/darwin/platform_internal.h @@ -102,6 +102,8 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#define OS_ENABLE_WAKEUP_BLOCKING_OP + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/freebsd/platform_internal.h b/core/shared/platform/freebsd/platform_internal.h index 7b4789c992..64b5a03af9 100644 --- a/core/shared/platform/freebsd/platform_internal.h +++ b/core/shared/platform/freebsd/platform_internal.h @@ -101,6 +101,8 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#define OS_ENABLE_WAKEUP_BLOCKING_OP + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/linux/platform_internal.h b/core/shared/platform/linux/platform_internal.h index 8439f8723d..4e5098876e 100644 --- a/core/shared/platform/linux/platform_internal.h +++ b/core/shared/platform/linux/platform_internal.h @@ -115,6 +115,8 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#define OS_ENABLE_WAKEUP_BLOCKING_OP + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index b5bbdacd04..0878eec8d0 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -123,6 +123,8 @@ utimensat(int fd, const char *path, const struct timespec ts[2], int flag); DIR * fdopendir(int fd); +#define OS_ENABLE_WAKEUP_BLOCKING_OP + #ifdef __cplusplus } #endif From 4d9668e1cc4a97385fa69252202fe3957baa4464 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 31 Aug 2023 14:11:26 +0900 Subject: [PATCH 14/40] OS_ENABLE_WAKEUP_BLOCKING_OP --- core/iwasm/libraries/thread-mgr/thread_manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.c b/core/iwasm/libraries/thread-mgr/thread_manager.c index fa8d972201..49545de727 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -1060,7 +1060,9 @@ set_thread_cancel_flags(WASMExecEnv *exec_env) os_mutex_unlock(&exec_env->wait_lock); +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP wasm_runtime_interrupt_blocking_op(exec_env); +#endif } static void From 71f390d40b334c79efc9f94e873d14e13cd900d6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 31 Aug 2023 14:24:04 +0900 Subject: [PATCH 15/40] call os_end_blocking_op in the intended function --- core/iwasm/common/wasm_runtime_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 7325d4ae68..353985b137 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -1405,6 +1405,10 @@ wasm_runtime_init_thread_env(void) } #endif +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) + os_end_blocking_op(); +#endif + return true; } @@ -1434,7 +1438,6 @@ wasm_runtime_thread_env_inited(void) return false; #endif #endif - os_end_blocking_op(); return true; } From 0e856d2e6b17353a2c5275a7b139b241e6a32d51 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 31 Aug 2023 14:28:53 +0900 Subject: [PATCH 16/40] add a missing os_end_blocking_op --- core/shared/platform/common/posix/posix_thread.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index b1460f6b53..a0b1844057 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -39,6 +39,9 @@ os_thread_wrapper(void *arg) #ifdef OS_ENABLE_HW_BOUND_CHECK if (os_thread_signal_init(handler) != 0) return NULL; +#endif +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP + os_end_blocking_op(); #endif start_func(thread_arg); #ifdef OS_ENABLE_HW_BOUND_CHECK From 3ee082dfefa72f4640710eea4af9eb2bdf1e508f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 10:43:42 +0900 Subject: [PATCH 17/40] move blocking op wrapper into a separate file also adapt fd_pread --- .../libraries/libc-wasi/libc_wasi_wrapper.c | 4 +- .../include/wasmtime_ssp.h | 1 + .../src/blocking_op.c | 50 +++++++++++++++++++ .../src/blocking_op.h | 21 ++++++++ .../sandboxed-system-primitives/src/posix.c | 24 ++++----- 5 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c create mode 100644 core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index 8401c56117..d46eedb778 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -389,8 +389,8 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app, 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(exec_env, curfds, fd, iovec_begin, iovs_len, + offset, &nread); if (err) goto fail; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index 7fe0ab4754..c9a0f499fe 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -659,6 +659,7 @@ __wasi_errno_t wasmtime_ssp_fd_datasync( ) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_pread( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_iovec_t *iovs, diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c new file mode 100644 index 0000000000..0aa409aa20 --- /dev/null +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "ssp_config.h" +#include "blocking_op.h" + +ssize_t +blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = readv(fd, iov, iovcnt); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +#if CONFIG_HAS_PREADV +ssize_t +blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt, off_t offset) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = preadv(fd, iov, iovcnt, offset); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} +#else /* CONFIG_HAS_PREADV */ +ssize_t +blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, + off_t offset) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = pread(fd, p, nb, offset); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} +#endif /* CONFIG_HAS_PREADV */ diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h new file mode 100644 index 0000000000..4d67fdfbe1 --- /dev/null +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include + +#include + +#include "wasm_export.h" + +ssize_t +blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt); +ssize_t +blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt, off_t offset); +ssize_t +blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, + off_t offset); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index db22fa7a21..364b6b281f 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -13,6 +13,7 @@ #include "ssp_config.h" #include "bh_platform.h" +#include "blocking_op.h" #include "wasmtime_ssp.h" #include "locking.h" #include "posix.h" @@ -914,8 +915,8 @@ wasmtime_ssp_fd_datasync(struct fd_table *curfds, __wasi_fd_t fd) } __wasi_errno_t -wasmtime_ssp_fd_pread(struct fd_table *curfds, __wasi_fd_t fd, - const __wasi_iovec_t *iov, size_t iovcnt, +wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, __wasi_filesize_t offset, size_t *nread) { if (iovcnt == 0) @@ -928,8 +929,9 @@ wasmtime_ssp_fd_pread(struct fd_table *curfds, __wasi_fd_t fd, return error; #if CONFIG_HAS_PREADV - ssize_t len = preadv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt, - (off_t)offset); + ssize_t len = + blocking_op_preadv(env, fd_number(fo), (const struct iovec *)iov, + (int)iovcnt, (off_t)offset); fd_object_release(fo); if (len < 0) return convert_errno(errno); @@ -937,7 +939,8 @@ wasmtime_ssp_fd_pread(struct fd_table *curfds, __wasi_fd_t fd, return 0; #else if (iovcnt == 1) { - ssize_t len = pread(fd_number(fo), iov->buf, iov->buf_len, offset); + ssize_t len = blocking_op_pread(exec_env, fd_number(fo), iov->buf, + iov->buf_len, offset); fd_object_release(fo); if (len < 0) return convert_errno(errno); @@ -956,7 +959,8 @@ wasmtime_ssp_fd_pread(struct fd_table *curfds, __wasi_fd_t fd, } // Perform a single read operation. - ssize_t len = pread(fd_number(fo), buf, totalsize, offset); + ssize_t len = + blocking_op_pread(exec_env, fd_number(fo), buf, totalsize, offset); fd_object_release(fo); if (len < 0) { wasm_runtime_free(buf); @@ -1046,12 +1050,8 @@ wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, if (error != 0) return error; - if (!wasm_runtime_begin_blocking_op(exec_env)) { - fd_object_release(fo); - return __WASI_EINTR; - } - ssize_t len = readv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); - wasm_runtime_end_blocking_op(exec_env); + ssize_t len = blocking_op_readv(exec_env, fd_number(fo), + (const struct iovec *)iov, (int)iovcnt); fd_object_release(fo); if (len < 0) return convert_errno(errno); From 62a5e2319675ccc212edee49f22f277fcc7767fa Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 12:07:02 +0900 Subject: [PATCH 18/40] wasi: WIP adapt more ops --- .../libraries/libc-wasi/libc_wasi_wrapper.c | 158 +++++------ .../include/wasmtime_ssp.h | 87 ++++++ .../src/blocking_op.c | 53 ++++ .../src/blocking_op.h | 12 + .../sandboxed-system-primitives/src/posix.c | 264 +++++++++--------- 5 files changed, 367 insertions(+), 207 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index d46eedb778..2bde369c33 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -335,7 +335,7 @@ wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_close(curfds, prestats, fd); + return wasmtime_ssp_fd_close(exec_env, curfds, prestats, fd); } static wasi_errno_t @@ -348,7 +348,7 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_datasync(curfds, fd); + return wasmtime_ssp_fd_datasync(exec_env, curfds, fd); } static wasi_errno_t @@ -443,7 +443,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset, + err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len, offset, &nwritten); if (err) goto fail; @@ -522,7 +522,7 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_renumber(curfds, prestats, from, to); + return wasmtime_ssp_fd_renumber(exec_env, curfds, prestats, from, to); } static wasi_errno_t @@ -539,7 +539,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset, if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_seek(curfds, fd, offset, whence, newoffset); + return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence, newoffset); } static wasi_errno_t @@ -555,7 +555,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset) if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_tell(curfds, fd, newoffset); + return wasmtime_ssp_fd_tell(exec_env, curfds, fd, newoffset); } static wasi_errno_t @@ -574,7 +574,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t))) return (wasi_errno_t)-1; - err = wasmtime_ssp_fd_fdstat_get(curfds, fd, &fdstat); + err = wasmtime_ssp_fd_fdstat_get(exec_env, curfds, fd, &fdstat); if (err) return err; @@ -593,7 +593,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_fdstat_set_flags(curfds, fd, flags); + return wasmtime_ssp_fd_fdstat_set_flags(exec_env, curfds, fd, flags); } static wasi_errno_t @@ -608,7 +608,7 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base, + return wasmtime_ssp_fd_fdstat_set_rights(exec_env, curfds, fd, fs_rights_base, fs_rights_inheriting); } @@ -622,7 +622,7 @@ wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_sync(curfds, fd); + return wasmtime_ssp_fd_sync(exec_env, curfds, fd); } static wasi_errno_t @@ -664,7 +664,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten); + err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len, &nwritten); if (err) goto fail; @@ -689,7 +689,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_advise(curfds, fd, offset, len, advice); + return wasmtime_ssp_fd_advise(exec_env, curfds, fd, offset, len, advice); } static wasi_errno_t @@ -703,7 +703,7 @@ wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_allocate(curfds, fd, offset, len); + return wasmtime_ssp_fd_allocate(exec_env, curfds, fd, offset, len); } static wasi_errno_t @@ -717,7 +717,7 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, 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(exec_env, curfds, fd, path, path_len); } static wasi_errno_t @@ -734,7 +734,7 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path, + return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags, old_path, old_path_len, new_fd, new_path, new_path_len); } @@ -757,7 +757,7 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd, 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, + err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path, path_len, oflags, fs_rights_base, fs_rights_inheriting, fs_flags, &fd); @@ -781,7 +781,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf, 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(exec_env, curfds, fd, buf, buf_len, cookie, &bufused); if (err) return err; @@ -806,7 +806,7 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path, 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, + err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf, buf_len, &bufused); if (err) return err; @@ -827,7 +827,7 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd, 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(exec_env, curfds, old_fd, old_path, old_path_len, new_fd, new_path, new_path_len); } @@ -845,7 +845,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(filestat, sizeof(wasi_filestat_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_get(curfds, fd, filestat); + return wasmtime_ssp_fd_filestat_get(exec_env, curfds, fd, filestat); } static wasi_errno_t @@ -860,7 +860,7 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim, + return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim, st_mtim, fstflags); } @@ -875,7 +875,7 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_set_size(curfds, fd, st_size); + return wasmtime_ssp_fd_filestat_set_size(exec_env, curfds, fd, st_size); } static wasi_errno_t @@ -893,7 +893,7 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, 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, + return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path, path_len, filestat); } @@ -910,7 +910,7 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_filestat_set_times( + return wasmtime_ssp_path_filestat_set_times(exec_env, curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags); } @@ -927,7 +927,7 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len, + return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path, old_path_len, fd, new_path, new_path_len); } @@ -942,7 +942,7 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_unlink_file(curfds, fd, path, path_len); + return wasmtime_ssp_path_unlink_file(exec_env, curfds, fd, path, path_len); } static wasi_errno_t @@ -956,7 +956,7 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_remove_directory(curfds, fd, path, path_len); + return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path, path_len); } #if WASM_ENABLE_THREAD_MGR != 0 @@ -1027,7 +1027,7 @@ execute_interruptible_poll_oneoff( /* update timeout for clock subscription events */ update_clock_subscription_data( in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); - err = wasmtime_ssp_poll_oneoff(curfds, in_copy, out, nsubscriptions, + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, nsubscriptions, nevents); elapsed += time_quant; @@ -1080,7 +1080,7 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in, return (wasi_errno_t)-1; #if WASM_ENABLE_THREAD_MGR == 0 - err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents); + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions, &nevents); #else err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions, &nevents, exec_env); @@ -1134,7 +1134,7 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_accept(curfds, fd, flags, fd_new); + return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new); } static wasi_errno_t @@ -1153,7 +1153,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_addr_local(curfds, fd, addr); + return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr); } static wasi_errno_t @@ -1172,7 +1172,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_addr_remote(curfds, fd, addr); + return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr); } static wasi_errno_t @@ -1193,7 +1193,7 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx); - return wasi_ssp_sock_addr_resolve(curfds, ns_lookup_list, host, service, + return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host, service, hints, addr_info, addr_info_size, max_info_size); } @@ -1212,7 +1212,7 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx); - return wasi_ssp_sock_bind(curfds, addr_pool, fd, addr); + return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr); } static wasi_errno_t @@ -1235,7 +1235,7 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx); - return wasi_ssp_sock_connect(curfds, addr_pool, fd, addr); + return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr); } static wasi_errno_t @@ -1254,7 +1254,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_broadcast(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1273,7 +1273,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_keep_alive(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1293,7 +1293,7 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_linger(curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled, linger_s); } static wasi_errno_t @@ -1312,7 +1312,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_recv_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1331,7 +1331,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_recv_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1350,7 +1350,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_reuse_addr(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1369,7 +1369,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_reuse_port(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1388,7 +1388,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_send_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1407,7 +1407,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_send_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1426,7 +1426,7 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_fastopen_connect(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1445,7 +1445,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_no_delay(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1464,7 +1464,7 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_quick_ack(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1483,7 +1483,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_keep_idle(curfds, fd, time_s); + return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1502,7 +1502,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_keep_intvl(curfds, fd, time_s); + return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1521,7 +1521,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_multicast_loop(curfds, fd, ipv6, + return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6, is_enabled); } @@ -1540,7 +1540,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1559,7 +1559,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_multicast_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1578,7 +1578,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ipv6_only(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1593,7 +1593,7 @@ wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_listen(curfds, fd, backlog); + return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog); } static wasi_errno_t @@ -1610,7 +1610,7 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_open(curfds, poolfd, af, socktype, sockfd); + return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd); } static wasi_errno_t @@ -1625,7 +1625,7 @@ wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_broadcast(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1641,7 +1641,7 @@ wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_keep_alive(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1657,7 +1657,7 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_linger(curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled, linger_s); } static wasi_errno_t @@ -1672,7 +1672,7 @@ wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_recv_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1688,7 +1688,7 @@ wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_recv_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1704,7 +1704,7 @@ wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_reuse_addr(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1720,7 +1720,7 @@ wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_reuse_port(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1735,7 +1735,7 @@ wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_send_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1751,7 +1751,7 @@ wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_send_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1767,7 +1767,7 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_fastopen_connect(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1783,7 +1783,7 @@ wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_no_delay(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1799,7 +1799,7 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_quick_ack(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1815,7 +1815,7 @@ wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_keep_idle(curfds, fd, time_s); + return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1831,7 +1831,7 @@ wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_keep_intvl(curfds, fd, time_s); + return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1847,7 +1847,7 @@ wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_multicast_loop(curfds, fd, ipv6, + return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6, is_enabled); } @@ -1868,7 +1868,7 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_add_membership(curfds, fd, imr_multiaddr, + return wasmtime_ssp_sock_set_ip_add_membership(exec_env, curfds, fd, imr_multiaddr, imr_interface); } @@ -1889,7 +1889,7 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_drop_membership(curfds, fd, imr_multiaddr, + return wasmtime_ssp_sock_set_ip_drop_membership(exec_env, curfds, fd, imr_multiaddr, imr_interface); } @@ -1905,7 +1905,7 @@ wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1921,7 +1921,7 @@ wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_multicast_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1936,7 +1936,7 @@ wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ipv6_only(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -2054,7 +2054,7 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock, memset(buf_begin, 0, total_size); *ro_data_len = 0; - err = wasmtime_ssp_sock_recv_from(curfds, sock, buf_begin, total_size, + err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin, total_size, ri_flags, src_addr, &recv_bytes); if (err != __WASI_ESUCCESS) { goto fail; @@ -2154,7 +2154,7 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send(curfds, sock, buf, buf_size, &send_bytes); + err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size, &send_bytes); *so_data_len = (uint32)send_bytes; wasm_runtime_free(buf); @@ -2194,7 +2194,7 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send_to(curfds, addr_pool, sock, buf, buf_size, + err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf, buf_size, si_flags, dest_addr, &send_bytes); *so_data_len = (uint32)send_bytes; @@ -2213,7 +2213,7 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how) if (!wasi_ctx) return __WASI_EINVAL; - return wasmtime_ssp_sock_shutdown(curfds, sock); + return wasmtime_ssp_sock_shutdown(exec_env, curfds, sock); } static wasi_errno_t diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index c9a0f499fe..efe7c8e3a4 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -648,12 +648,14 @@ __wasi_errno_t wasmtime_ssp_fd_prestat_dir_name( ) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_close( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t fd ) WASMTIME_SSP_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_datasync( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd ) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__)); @@ -669,6 +671,7 @@ __wasi_errno_t wasmtime_ssp_fd_pread( ) WASMTIME_SSP_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_pwrite( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_ciovec_t *iovs, @@ -687,6 +690,7 @@ __wasi_errno_t wasmtime_ssp_fd_read( ) WASMTIME_SSP_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_renumber( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t from, @@ -694,6 +698,7 @@ __wasi_errno_t wasmtime_ssp_fd_renumber( ) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_seek( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filedelta_t offset, @@ -702,24 +707,28 @@ __wasi_errno_t wasmtime_ssp_fd_seek( ) WASMTIME_SSP_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_tell( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t *newoffset ) WASMTIME_SSP_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_fdstat_get( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdstat_t *buf ) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdflags_t flags ) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_rights_t fs_rights_base, @@ -727,11 +736,13 @@ __wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights( ) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_sync( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd ) WASMTIME_SSP_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_write( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_ciovec_t *iovs, @@ -740,6 +751,7 @@ __wasi_errno_t wasmtime_ssp_fd_write( ) WASMTIME_SSP_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_advise( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t offset, @@ -748,6 +760,7 @@ __wasi_errno_t wasmtime_ssp_fd_advise( ) WASMTIME_SSP_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_allocate( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t offset, @@ -755,6 +768,7 @@ __wasi_errno_t wasmtime_ssp_fd_allocate( ) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_create_directory( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, @@ -762,6 +776,7 @@ __wasi_errno_t wasmtime_ssp_path_create_directory( ) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_link( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t old_fd, @@ -774,6 +789,7 @@ __wasi_errno_t wasmtime_ssp_path_link( ) WASMTIME_SSP_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_open( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, @@ -787,6 +803,7 @@ __wasi_errno_t wasmtime_ssp_path_open( ) WASMTIME_SSP_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_readdir( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, void *buf, @@ -796,6 +813,7 @@ __wasi_errno_t wasmtime_ssp_fd_readdir( ) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_readlink( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, @@ -806,6 +824,7 @@ __wasi_errno_t wasmtime_ssp_path_readlink( ) WASMTIME_SSP_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_rename( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t old_fd, const char *old_path, @@ -816,12 +835,14 @@ __wasi_errno_t wasmtime_ssp_path_rename( ) WASMTIME_SSP_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_filestat_get( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filestat_t *buf ) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_filestat_set_times( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_timestamp_t st_atim, @@ -830,12 +851,14 @@ __wasi_errno_t wasmtime_ssp_fd_filestat_set_times( ) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_fd_filestat_set_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t st_size ) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_filestat_get( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, @@ -845,6 +868,7 @@ __wasi_errno_t wasmtime_ssp_path_filestat_get( ) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_filestat_set_times( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, @@ -856,6 +880,7 @@ __wasi_errno_t wasmtime_ssp_path_filestat_set_times( ) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_symlink( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, const char *old_path, @@ -866,6 +891,7 @@ __wasi_errno_t wasmtime_ssp_path_symlink( ) WASMTIME_SSP_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_unlink_file( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, @@ -873,6 +899,7 @@ __wasi_errno_t wasmtime_ssp_path_unlink_file( ) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_path_remove_directory( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, @@ -880,6 +907,7 @@ __wasi_errno_t wasmtime_ssp_path_remove_directory( ) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_poll_oneoff( + wasm_exec_env_t exec_env, struct fd_table *curfds, const __wasi_subscription_t *in, __wasi_event_t *out, @@ -894,24 +922,28 @@ __wasi_errno_t wasmtime_ssp_random_get( __wasi_errno_t wasi_ssp_sock_accept( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_addr_local( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_addr_t *addr ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_addr_remote( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_addr_t *addr ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_open( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype, __wasi_fd_t *sockfd @@ -919,12 +951,14 @@ wasi_ssp_sock_open( __wasi_errno_t wasi_ssp_sock_bind( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t fd, __wasi_addr_t *addr ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_addr_resolve( + wasm_exec_env_t exec_env, struct fd_table *curfds, char **ns_lookup_list, const char *host, const char* service, __wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info, @@ -933,65 +967,76 @@ wasi_ssp_sock_addr_resolve( __wasi_errno_t wasi_ssp_sock_connect( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t fd, __wasi_addr_t *addr ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_get_recv_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_get_reuse_addr( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t *reuse ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_get_reuse_port( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t *reuse ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_get_send_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_set_recv_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_set_reuse_addr( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t reuse ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_set_reuse_port( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t reuse ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_set_send_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasi_ssp_sock_listen( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t backlog ) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_recv( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, void *buf, @@ -1000,6 +1045,7 @@ __wasi_errno_t wasmtime_ssp_sock_recv( ) WASMTIME_SSP_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_recv_from( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, void *buf, @@ -1010,6 +1056,7 @@ __wasi_errno_t wasmtime_ssp_sock_recv_from( ) WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_send( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, const void *buf, @@ -1018,6 +1065,7 @@ __wasi_errno_t wasmtime_ssp_sock_send( ) WASMTIME_SSP_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_send_to( + wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t sock, const void *buf, @@ -1028,53 +1076,62 @@ __wasi_errno_t wasmtime_ssp_sock_send_to( ) WASMTIME_SSP_SYSCALL_NAME(sock_send_to) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_shutdown( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock ) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_recv_timeout( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint64_t timeout_us ) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_recv_timeout( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint64_t *timeout_us ) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_send_timeout( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint64_t timeout_us ) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_send_timeout( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint64_t *timeout_us ) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_send_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, size_t bufsiz ) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_send_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, size_t *bufsiz ) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_recv_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, size_t bufsiz ) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_recv_buf_size( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, size_t *bufsiz @@ -1082,42 +1139,49 @@ __wasi_errno_t wasmtime_ssp_sock_get_recv_buf_size( __wasi_errno_t wasmtime_ssp_sock_set_keep_alive( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_keep_alive( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_reuse_addr( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_reuse_addr( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_reuse_port( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_reuse_port( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_linger( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled, @@ -1125,83 +1189,97 @@ __wasi_errno_t wasmtime_ssp_sock_set_linger( ) WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_linger( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled, int *linger_s ) WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_broadcast( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_broadcast( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_tcp_no_delay( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_tcp_no_delay( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_tcp_quick_ack( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_tcp_quick_ack( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_idle( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint32_t time_s ) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_idle( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint32_t *time_s ) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_intvl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint32_t time_s ) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_intvl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint32_t *time_s ) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_tcp_fastopen_connect( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_tcp_fastopen_connect( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_loop( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, @@ -1209,6 +1287,7 @@ __wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_loop( ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_loop( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, @@ -1216,6 +1295,7 @@ __wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_loop( ) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ip_add_membership( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, @@ -1223,6 +1303,7 @@ __wasi_errno_t wasmtime_ssp_sock_set_ip_add_membership( ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ip_drop_membership( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, @@ -1230,36 +1311,42 @@ __wasi_errno_t wasmtime_ssp_sock_set_ip_drop_membership( ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ip_ttl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint8_t ttl_s ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_ip_ttl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint8_t *ttl_s ) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_ttl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint8_t ttl_s ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_ttl( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, uint8_t *ttl_s ) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_set_ipv6_only( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled ) WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) __attribute__((__warn_unused_result__)); __wasi_errno_t wasmtime_ssp_sock_get_ipv6_only( + wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index 0aa409aa20..0dd60a3375 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -8,6 +8,18 @@ #include "ssp_config.h" #include "blocking_op.h" +int +blocking_op_close(wasm_exec_env_t exec_env, int fd) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = close(fd); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + ssize_t blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, int iovcnt) @@ -48,3 +60,44 @@ blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, return ret; } #endif /* CONFIG_HAS_PREADV */ + +ssize_t +blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = writev(fd, iov, iovcnt); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +#if CONFIG_HAS_PWRITEV +ssize_t +blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt, off_t offset) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = pwritev(fd, iov, iovcnt, offset); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} +#else /* CONFIG_HAS_PREADV */ +ssize_t +blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, + off_t offset) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + ssize_t ret = pwrite(fd, p, nb, offset); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} +#endif /* CONFIG_HAS_PREADV */ diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index 4d67fdfbe1..b005b8fc62 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -10,6 +10,8 @@ #include "wasm_export.h" +int +blocking_op_close(wasm_exec_env_t exec_env, int fd); ssize_t blocking_op_readv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, int iovcnt); @@ -19,3 +21,13 @@ blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, ssize_t blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, off_t offset); + +ssize_t +blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt); +ssize_t +blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, + int iovcnt, off_t offset); +ssize_t +blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, + off_t offset); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 364b6b281f..5dceb56acd 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -631,16 +631,23 @@ fd_number(const struct fd_object *fo) return number; } -#define CLOSE_NON_STD_FD(fd) \ +// The env == NULL case is for +// fd_table_destroy, path_get, path_put, fd_table_insert_existing +#define CLOSE_NON_STD_FD(env, fd) \ do { \ - if (fd > 2) \ + if (fd > 2) { \ + if (env == NULL) { \ close(fd); \ + } else { \ + blocking_op_close(env, fd); \ + } \ + } \ } while (0) // Lowers the reference count on a file descriptor object. When the // reference count reaches zero, its resources are cleaned up. static void -fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount) +fd_object_release(wasm_exec_env_t env, struct fd_object *fo) UNLOCKS(fo->refcount) { if (refcount_release(&fo->refcount)) { int saved_errno = errno; @@ -650,14 +657,14 @@ fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount) // closedir() on it also closes the underlying file descriptor. mutex_destroy(&fo->directory.lock); if (fo->directory.handle == NULL) { - CLOSE_NON_STD_FD(fd_number(fo)); + CLOSE_NON_STD_FD(env, fd_number(fo)); } else { closedir(fo->directory.handle); } break; default: - CLOSE_NON_STD_FD(fd_number(fo)); + CLOSE_NON_STD_FD(env, fd_number(fo)); break; } wasm_runtime_free(fo); @@ -696,7 +703,7 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) fo->number = out; if (type == __WASI_FILETYPE_DIRECTORY) { if (!mutex_init(&fo->directory.lock)) { - fd_object_release(fo); + fd_object_release(NULL, fo); return false; } fo->directory.handle = NULL; @@ -706,7 +713,7 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) rwlock_wrlock(&ft->lock); if (!fd_table_grow(ft, in, 1)) { rwlock_unlock(&ft->lock); - fd_object_release(fo); + fd_object_release(NULL, fo); return false; } @@ -730,7 +737,7 @@ fd_table_unused(struct fd_table *ft) REQUIRES_SHARED(ft->lock) // Inserts a file descriptor object into an unused slot of the file // descriptor table. static __wasi_errno_t -fd_table_insert(struct fd_table *ft, struct fd_object *fo, +fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft, struct fd_object *fo, __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) UNLOCKS(fo->refcount) @@ -739,7 +746,7 @@ fd_table_insert(struct fd_table *ft, struct fd_object *fo, rwlock_wrlock(&ft->lock); if (!fd_table_grow(ft, 0, 1)) { rwlock_unlock(&ft->lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return convert_errno(errno); } @@ -751,7 +758,7 @@ fd_table_insert(struct fd_table *ft, struct fd_object *fo, // Inserts a numerical file descriptor into the file descriptor table. static __wasi_errno_t -fd_table_insert_fd(struct fd_table *ft, int in, __wasi_filetype_t type, +fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft, int in, __wasi_filetype_t type, __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) @@ -767,12 +774,12 @@ fd_table_insert_fd(struct fd_table *ft, int in, __wasi_filetype_t type, fo->number = in; if (type == __WASI_FILETYPE_DIRECTORY) { if (!mutex_init(&fo->directory.lock)) { - fd_object_release(fo); + fd_object_release(exec_env, fo); return (__wasi_errno_t)-1; } fo->directory.handle = NULL; } - return fd_table_insert(ft, fo, rights_base, rights_inheriting, out); + return fd_table_insert(exec_env, ft, fo, rights_base, rights_inheriting, out); } __wasi_errno_t @@ -822,7 +829,7 @@ wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_close(struct fd_table *curfds, struct fd_prestats *prestats, +wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t fd) { // Don't allow closing a pre-opened resource. @@ -852,7 +859,7 @@ wasmtime_ssp_fd_close(struct fd_table *curfds, struct fd_prestats *prestats, struct fd_object *fo; fd_table_detach(ft, fd, &fo); rwlock_unlock(&ft->lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return 0; } @@ -895,7 +902,7 @@ fd_object_get(struct fd_table *curfds, struct fd_object **fo, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_datasync(struct fd_table *curfds, __wasi_fd_t fd) +wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = @@ -908,7 +915,7 @@ wasmtime_ssp_fd_datasync(struct fd_table *curfds, __wasi_fd_t fd) #else int ret = fsync(fd_number(fo)); #endif - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; @@ -930,9 +937,9 @@ wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, #if CONFIG_HAS_PREADV ssize_t len = - blocking_op_preadv(env, fd_number(fo), (const struct iovec *)iov, + blocking_op_preadv(exec_env, fd_number(fo), (const struct iovec *)iov, (int)iovcnt, (off_t)offset); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) return convert_errno(errno); *nread = (size_t)len; @@ -941,7 +948,7 @@ wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, if (iovcnt == 1) { ssize_t len = blocking_op_pread(exec_env, fd_number(fo), iov->buf, iov->buf_len, offset); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) return convert_errno(errno); *nread = len; @@ -954,14 +961,14 @@ wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, totalsize += iov[i].buf_len; char *buf = wasm_runtime_malloc(totalsize); if (buf == NULL) { - fd_object_release(fo); + fd_object_release(exec_env, fo); return __WASI_ENOMEM; } // Perform a single read operation. ssize_t len = blocking_op_pread(exec_env, fd_number(fo), buf, totalsize, offset); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) { wasm_runtime_free(buf); return convert_errno(errno); @@ -989,7 +996,7 @@ wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_fd_pwrite(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, __wasi_filesize_t offset, size_t *nwritten) { @@ -1004,11 +1011,11 @@ wasmtime_ssp_fd_pwrite(struct fd_table *curfds, __wasi_fd_t fd, ssize_t len; #if CONFIG_HAS_PWRITEV - len = pwritev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt, + len = blocking_op_pwritev(exec_env, fd_number(fo), (const struct iovec *)iov, (int)iovcnt, (off_t)offset); #else if (iovcnt == 1) { - len = pwrite(fd_number(fo), iov->buf, iov->buf_len, offset); + len = blocking_op_pwrite(exec_env, fd_number(fo), iov->buf, iov->buf_len, offset); } else { // Allocate a single buffer to fit all data. @@ -1017,7 +1024,7 @@ wasmtime_ssp_fd_pwrite(struct fd_table *curfds, __wasi_fd_t fd, totalsize += iov[i].buf_len; char *buf = wasm_runtime_malloc(totalsize); if (buf == NULL) { - fd_object_release(fo); + fd_object_release(exec_env, fo); return __WASI_ENOMEM; } size_t bufoff = 0; @@ -1028,11 +1035,11 @@ wasmtime_ssp_fd_pwrite(struct fd_table *curfds, __wasi_fd_t fd, } // Perform a single write operation. - len = pwrite(fd_number(fo), buf, totalsize, offset); + len = blocking_op_pwrite(exec_env, fd_number(fo), buf, totalsize, offset); wasm_runtime_free(buf); } #endif - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) return convert_errno(errno); *nwritten = (size_t)len; @@ -1052,7 +1059,7 @@ wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, ssize_t len = blocking_op_readv(exec_env, fd_number(fo), (const struct iovec *)iov, (int)iovcnt); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) return convert_errno(errno); *nread = (size_t)len; @@ -1060,7 +1067,7 @@ wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_fd_renumber(struct fd_table *curfds, struct fd_prestats *prestats, +wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t from, __wasi_fd_t to) { // Don't allow renumbering over a pre-opened resource. @@ -1099,11 +1106,11 @@ wasmtime_ssp_fd_renumber(struct fd_table *curfds, struct fd_prestats *prestats, refcount_acquire(&fe_from->object->refcount); fd_table_attach(ft, to, fe_from->object, fe_from->rights_base, fe_from->rights_inheriting); - fd_object_release(fo); + fd_object_release(exec_env, fo); // Remove the old fd from the file descriptor table. fd_table_detach(ft, from, &fo); - fd_object_release(fo); + fd_object_release(exec_env, fo); --ft->used; rwlock_unlock(&ft->lock); @@ -1111,7 +1118,7 @@ wasmtime_ssp_fd_renumber(struct fd_table *curfds, struct fd_prestats *prestats, } __wasi_errno_t -wasmtime_ssp_fd_seek(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filedelta_t offset, __wasi_whence_t whence, __wasi_filesize_t *newoffset) { @@ -1141,7 +1148,7 @@ wasmtime_ssp_fd_seek(struct fd_table *curfds, __wasi_fd_t fd, return error; off_t ret = lseek(fd_number(fo), offset, nwhence); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); *newoffset = (__wasi_filesize_t)ret; @@ -1149,7 +1156,7 @@ wasmtime_ssp_fd_seek(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_tell(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t *newoffset) { struct fd_object *fo; @@ -1159,7 +1166,7 @@ wasmtime_ssp_fd_tell(struct fd_table *curfds, __wasi_fd_t fd, return error; off_t ret = lseek(fd_number(fo), 0, SEEK_CUR); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); *newoffset = (__wasi_filesize_t)ret; @@ -1167,7 +1174,7 @@ wasmtime_ssp_fd_tell(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_fdstat_get(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdstat_t *buf) { struct fd_table *ft = curfds; @@ -1216,7 +1223,7 @@ wasmtime_ssp_fd_fdstat_get(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_flags(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdflags_t fs_flags) { int noflags = 0; @@ -1246,14 +1253,14 @@ wasmtime_ssp_fd_fdstat_set_flags(struct fd_table *curfds, __wasi_fd_t fd, return error; int ret = fcntl(fd_number(fo), F_SETFL, noflags); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_rights(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_rights_t fs_rights_base, __wasi_rights_t fs_rights_inheriting) { @@ -1275,7 +1282,7 @@ wasmtime_ssp_fd_fdstat_set_rights(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_sync(struct fd_table *curfds, __wasi_fd_t fd) +wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = @@ -1284,14 +1291,14 @@ wasmtime_ssp_fd_sync(struct fd_table *curfds, __wasi_fd_t fd) return error; int ret = fsync(fd_number(fo)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; } __wasi_errno_t -wasmtime_ssp_fd_write(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, size_t *nwritten) { @@ -1324,7 +1331,7 @@ wasmtime_ssp_fd_write(struct fd_table *curfds, __wasi_fd_t fd, len = writev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); } #endif /* end of BH_VPRINTF */ - fd_object_release(fo); + fd_object_release(exec_env, fo); if (len < 0) return convert_errno(errno); *nwritten = (size_t)len; @@ -1332,7 +1339,7 @@ wasmtime_ssp_fd_write(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_advise(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len, __wasi_advice_t advice) { @@ -1368,7 +1375,7 @@ wasmtime_ssp_fd_advise(struct fd_table *curfds, __wasi_fd_t fd, return error; int ret = posix_fadvise(fd_number(fo), (off_t)offset, (off_t)len, nadvice); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret != 0) return convert_errno(ret); return 0; @@ -1398,7 +1405,7 @@ wasmtime_ssp_fd_advise(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_allocate(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len) { struct fd_object *fo; @@ -1420,7 +1427,7 @@ wasmtime_ssp_fd_allocate(struct fd_table *curfds, __wasi_fd_t fd, ret = ftruncate(fd_number(fo), newsize); #endif - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret != 0) return convert_errno(ret); return 0; @@ -1708,7 +1715,7 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, close(fds[i]); for (size_t i = 0; i <= curpath; ++i) wasm_runtime_free(paths_start[i]); - fd_object_release(fo); + fd_object_release(NULL, fo); return error; #endif } @@ -1732,11 +1739,11 @@ path_put(struct path_access *pa) UNLOCKS(pa->fd_object->refcount) wasm_runtime_free(pa->path_start); if (fd_number(pa->fd_object) != pa->fd) close(pa->fd); - fd_object_release(pa->fd_object); + fd_object_release(NULL, pa->fd_object); } __wasi_errno_t -wasmtime_ssp_path_create_directory(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; @@ -1781,7 +1788,7 @@ validate_path(const char *path, struct fd_prestats *pt) } __wasi_errno_t -wasmtime_ssp_path_link(struct fd_table *curfds, struct fd_prestats *prestats, +wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, __wasi_fd_t old_fd, __wasi_lookupflags_t old_flags, const char *old_path, size_t old_path_len, __wasi_fd_t new_fd, const char *new_path, @@ -1838,7 +1845,7 @@ wasmtime_ssp_path_link(struct fd_table *curfds, struct fd_prestats *prestats, } __wasi_errno_t -wasmtime_ssp_path_open(struct fd_table *curfds, __wasi_fd_t dirfd, +wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, const char *path, size_t pathlen, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, @@ -1971,7 +1978,7 @@ wasmtime_ssp_path_open(struct fd_table *curfds, __wasi_fd_t dirfd, rights_base |= (__wasi_rights_t)RIGHTS_REGULAR_FILE_BASE; } - return fd_table_insert_fd(curfds, nfd, type, rights_base & max_base, + return fd_table_insert_fd(exec_env, curfds, nfd, type, rights_base & max_base, rights_inheriting & max_inheriting, fd); } @@ -1990,7 +1997,7 @@ fd_readdir_put(void *buf, size_t bufsize, size_t *bufused, const void *elem, } __wasi_errno_t -wasmtime_ssp_fd_readdir(struct fd_table *curfds, __wasi_fd_t fd, void *buf, +wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, void *buf, size_t nbyte, __wasi_dircookie_t cookie, size_t *bufused) { @@ -2008,7 +2015,7 @@ wasmtime_ssp_fd_readdir(struct fd_table *curfds, __wasi_fd_t fd, void *buf, dp = fdopendir(fd_number(fo)); if (dp == NULL) { mutex_unlock(&fo->directory.lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return convert_errno(errno); } fo->directory.handle = dp; @@ -2032,7 +2039,7 @@ wasmtime_ssp_fd_readdir(struct fd_table *curfds, __wasi_fd_t fd, void *buf, struct dirent *de = readdir(dp); if (de == NULL) { mutex_unlock(&fo->directory.lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return errno == 0 || *bufused > 0 ? 0 : convert_errno(errno); } fo->directory.offset = (__wasi_dircookie_t)telldir(dp); @@ -2081,12 +2088,12 @@ wasmtime_ssp_fd_readdir(struct fd_table *curfds, __wasi_fd_t fd, void *buf, fd_readdir_put(buf, nbyte, bufused, de->d_name, namlen); } mutex_unlock(&fo->directory.lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return 0; } __wasi_errno_t -wasmtime_ssp_path_readlink(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen, char *buf, size_t bufsize, size_t *bufused) { @@ -2109,7 +2116,7 @@ wasmtime_ssp_path_readlink(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_path_rename(struct fd_table *curfds, __wasi_fd_t old_fd, +wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t old_fd, const char *old_path, size_t old_path_len, __wasi_fd_t new_fd, const char *new_path, size_t new_path_len) @@ -2154,7 +2161,7 @@ convert_stat(const struct stat *in, __wasi_filestat_t *out) } __wasi_errno_t -wasmtime_ssp_fd_filestat_get(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filestat_t *buf) { struct fd_object *fo; @@ -2174,7 +2181,7 @@ wasmtime_ssp_fd_filestat_get(struct fd_table *curfds, __wasi_fd_t fd, } } buf->st_filetype = fo->type; - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; @@ -2224,7 +2231,7 @@ convert_utimens_arguments(__wasi_timestamp_t st_atim, } __wasi_errno_t -wasmtime_ssp_fd_filestat_set_size(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t st_size) { struct fd_object *fo; @@ -2234,14 +2241,14 @@ wasmtime_ssp_fd_filestat_set_size(struct fd_table *curfds, __wasi_fd_t fd, return error; int ret = ftruncate(fd_number(fo), (off_t)st_size); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; } __wasi_errno_t -wasmtime_ssp_fd_filestat_set_times(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim, __wasi_fstflags_t fstflags) @@ -2262,14 +2269,14 @@ wasmtime_ssp_fd_filestat_set_times(struct fd_table *curfds, __wasi_fd_t fd, convert_utimens_arguments(st_atim, st_mtim, fstflags, ts); int ret = futimens(fd_number(fo), ts); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret < 0) return convert_errno(errno); return 0; } __wasi_errno_t -wasmtime_ssp_path_filestat_get(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, size_t pathlen, __wasi_filestat_t *buf) { @@ -2306,7 +2313,7 @@ wasmtime_ssp_path_filestat_get(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_path_filestat_set_times(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, size_t pathlen, __wasi_timestamp_t st_atim, @@ -2344,7 +2351,7 @@ wasmtime_ssp_path_filestat_set_times(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_path_symlink(struct fd_table *curfds, struct fd_prestats *prestats, +wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, const char *old_path, size_t old_path_len, __wasi_fd_t fd, const char *new_path, size_t new_path_len) @@ -2379,7 +2386,7 @@ wasmtime_ssp_path_symlink(struct fd_table *curfds, struct fd_prestats *prestats, } __wasi_errno_t -wasmtime_ssp_path_unlink_file(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; @@ -2413,7 +2420,7 @@ wasmtime_ssp_path_unlink_file(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_path_remove_directory(struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; @@ -2439,7 +2446,7 @@ wasmtime_ssp_path_remove_directory(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_poll_oneoff(struct fd_table *curfds, +wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds, const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions, size_t *nevents) NO_LOCK_ANALYSIS @@ -2687,7 +2694,7 @@ wasmtime_ssp_poll_oneoff(struct fd_table *curfds, for (size_t i = 0; i < nsubscriptions; ++i) if (fos[i] != NULL) - fd_object_release(fos[i]); + fd_object_release(exec_env, fos[i]); wasm_runtime_free(fos); wasm_runtime_free(pfds); return error; @@ -2701,7 +2708,7 @@ wasmtime_ssp_random_get(void *buf, size_t nbyte) } __wasi_errno_t -wasi_ssp_sock_accept(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new) { __wasi_filetype_t wasi_type; @@ -2716,7 +2723,7 @@ wasi_ssp_sock_accept(struct fd_table *curfds, __wasi_fd_t fd, } ret = os_socket_accept(fd_number(fo), &new_sock, NULL, NULL); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { error = convert_errno(errno); goto fail; @@ -2728,7 +2735,7 @@ wasi_ssp_sock_accept(struct fd_table *curfds, __wasi_fd_t fd, goto fail; } - error = fd_table_insert_fd(curfds, new_sock, wasi_type, max_base, + error = fd_table_insert_fd(exec_env, curfds, new_sock, wasi_type, max_base, max_inheriting, fd_new); if (error != __WASI_ESUCCESS) { /* released in fd_table_insert_fd() */ @@ -2746,7 +2753,7 @@ wasi_ssp_sock_accept(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_addr_local(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; @@ -2759,7 +2766,7 @@ wasi_ssp_sock_addr_local(struct fd_table *curfds, __wasi_fd_t fd, return error; ret = os_socket_addr_local(fd_number(fo), &bh_addr); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret != BHT_OK) { return convert_errno(errno); } @@ -2770,7 +2777,7 @@ wasi_ssp_sock_addr_local(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_addr_remote(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; @@ -2783,7 +2790,7 @@ wasi_ssp_sock_addr_remote(struct fd_table *curfds, __wasi_fd_t fd, return error; ret = os_socket_addr_remote(fd_number(fo), &bh_addr); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (ret != BHT_OK) { return convert_errno(errno); } @@ -2823,7 +2830,7 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen) } __wasi_errno_t -wasi_ssp_sock_bind(struct fd_table *curfds, struct addr_pool *addr_pool, +wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t fd, __wasi_addr_t *addr) { char buf[48] = { 0 }; @@ -2845,7 +2852,7 @@ wasi_ssp_sock_bind(struct fd_table *curfds, struct addr_pool *addr_pool, return error; ret = os_socket_bind(fd_number(fo), buf, &port); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -2854,7 +2861,7 @@ wasi_ssp_sock_bind(struct fd_table *curfds, struct addr_pool *addr_pool, } __wasi_errno_t -wasi_ssp_sock_addr_resolve(struct fd_table *curfds, char **ns_lookup_list, +wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, char **ns_lookup_list, const char *host, const char *service, __wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info, @@ -2906,7 +2913,7 @@ wasi_ssp_sock_addr_resolve(struct fd_table *curfds, char **ns_lookup_list, } __wasi_errno_t -wasi_ssp_sock_connect(struct fd_table *curfds, struct addr_pool *addr_pool, +wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t fd, __wasi_addr_t *addr) { char buf[48] = { 0 }; @@ -2929,7 +2936,7 @@ wasi_ssp_sock_connect(struct fd_table *curfds, struct addr_pool *addr_pool, ret = os_socket_connect(fd_number(fo), buf, addr->kind == IPv4 ? addr->addr.ip4.port : addr->addr.ip6.port); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -2938,7 +2945,7 @@ wasi_ssp_sock_connect(struct fd_table *curfds, struct addr_pool *addr_pool, } __wasi_errno_t -wasi_ssp_sock_get_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size) { struct fd_object *fo; @@ -2951,7 +2958,7 @@ wasi_ssp_sock_get_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, socklen_t optlen = sizeof(optval); ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval, &optlen); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -2962,7 +2969,7 @@ wasi_ssp_sock_get_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_get_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t *reuse) { @@ -2976,7 +2983,7 @@ wasi_ssp_sock_get_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, socklen_t optlen = sizeof(optval); ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval, &optlen); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -2987,7 +2994,7 @@ wasi_ssp_sock_get_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_get_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t *reuse) { struct fd_object *fo; @@ -3007,7 +3014,7 @@ wasi_ssp_sock_get_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, optval = 0; #endif /* defined(SO_REUSEPORT) */ - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3018,7 +3025,7 @@ wasi_ssp_sock_get_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_get_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size) { struct fd_object *fo; @@ -3031,7 +3038,7 @@ wasi_ssp_sock_get_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, socklen_t optlen = sizeof(optval); ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval, &optlen); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3042,7 +3049,7 @@ wasi_ssp_sock_get_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_listen(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t backlog) { struct fd_object *fo; @@ -3053,7 +3060,7 @@ wasi_ssp_sock_listen(struct fd_table *curfds, __wasi_fd_t fd, return error; ret = os_socket_listen(fd_number(fo), backlog); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3062,7 +3069,7 @@ wasi_ssp_sock_listen(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_open(struct fd_table *curfds, __wasi_fd_t poolfd, +wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype, __wasi_fd_t *sockfd) { @@ -3096,7 +3103,7 @@ wasi_ssp_sock_open(struct fd_table *curfds, __wasi_fd_t poolfd, } // TODO: base rights and inheriting rights ? - error = fd_table_insert_fd(curfds, sock, wasi_type, max_base, + error = fd_table_insert_fd(exec_env, curfds, sock, wasi_type, max_base, max_inheriting, sockfd); if (error != __WASI_ESUCCESS) { return error; @@ -3106,7 +3113,7 @@ wasi_ssp_sock_open(struct fd_table *curfds, __wasi_fd_t poolfd, } __wasi_errno_t -wasi_ssp_sock_set_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size) { struct fd_object *fo; @@ -3119,7 +3126,7 @@ wasi_ssp_sock_set_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3128,7 +3135,7 @@ wasi_ssp_sock_set_recv_buf_size(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_set_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; @@ -3141,7 +3148,7 @@ wasi_ssp_sock_set_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3150,7 +3157,7 @@ wasi_ssp_sock_set_reuse_addr(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_set_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; @@ -3169,7 +3176,7 @@ wasi_ssp_sock_set_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, ret = BHT_ERROR; #endif /* defined(SO_REUSEPORT) */ - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3178,7 +3185,7 @@ wasi_ssp_sock_set_reuse_port(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasi_ssp_sock_set_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size) { struct fd_object *fo; @@ -3192,7 +3199,7 @@ wasi_ssp_sock_set_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval, sizeof(optval)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3201,17 +3208,17 @@ wasi_ssp_sock_set_send_buf_size(struct fd_table *curfds, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_sock_recv(struct fd_table *curfds, __wasi_fd_t sock, void *buf, +wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, void *buf, size_t buf_len, size_t *recv_len) { __wasi_addr_t src_addr; - return wasmtime_ssp_sock_recv_from(curfds, sock, buf, buf_len, 0, &src_addr, + return wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf, buf_len, 0, &src_addr, recv_len); } __wasi_errno_t -wasmtime_ssp_sock_recv_from(struct fd_table *curfds, __wasi_fd_t sock, +wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, void *buf, size_t buf_len, __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr, size_t *recv_len) @@ -3227,7 +3234,7 @@ wasmtime_ssp_sock_recv_from(struct fd_table *curfds, __wasi_fd_t sock, } ret = os_socket_recv_from(fd_number(fo), buf, buf_len, 0, &sockaddr); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3239,7 +3246,7 @@ wasmtime_ssp_sock_recv_from(struct fd_table *curfds, __wasi_fd_t sock, } __wasi_errno_t -wasmtime_ssp_sock_send(struct fd_table *curfds, __wasi_fd_t sock, +wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, const void *buf, size_t buf_len, size_t *sent_len) { struct fd_object *fo; @@ -3252,7 +3259,7 @@ wasmtime_ssp_sock_send(struct fd_table *curfds, __wasi_fd_t sock, } ret = os_socket_send(fd_number(fo), buf, buf_len); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3262,7 +3269,7 @@ wasmtime_ssp_sock_send(struct fd_table *curfds, __wasi_fd_t sock, } __wasi_errno_t -wasmtime_ssp_sock_send_to(struct fd_table *curfds, struct addr_pool *addr_pool, +wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, __wasi_fd_t sock, const void *buf, size_t buf_len, __wasi_siflags_t si_flags, const __wasi_addr_t *dest_addr, size_t *sent_len) @@ -3289,7 +3296,7 @@ wasmtime_ssp_sock_send_to(struct fd_table *curfds, struct addr_pool *addr_pool, wasi_addr_to_bh_sockaddr(dest_addr, &sockaddr); ret = os_socket_send_to(fd_number(fo), buf, buf_len, 0, &sockaddr); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3299,7 +3306,7 @@ wasmtime_ssp_sock_send_to(struct fd_table *curfds, struct addr_pool *addr_pool, } __wasi_errno_t -wasmtime_ssp_sock_shutdown(struct fd_table *curfds, __wasi_fd_t sock) +wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock) { struct fd_object *fo; __wasi_errno_t error; @@ -3310,7 +3317,7 @@ wasmtime_ssp_sock_shutdown(struct fd_table *curfds, __wasi_fd_t sock) return error; ret = os_socket_shutdown(fd_number(fo)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); @@ -3402,7 +3409,7 @@ fd_table_destroy(struct fd_table *ft) if (ft->entries) { for (uint32 i = 0; i < ft->size; i++) { if (ft->entries[i].object != NULL) { - fd_object_release(ft->entries[i].object); + fd_object_release(NULL, ft->entries[i].object); } } rwlock_destroy(&ft->lock); @@ -3597,6 +3604,7 @@ addr_pool_destroy(struct addr_pool *addr_pool) // implementation #define WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(FUNC_NAME, OPTION_TYPE) \ __wasi_errno_t wasmtime_ssp_sock_##FUNC_NAME( \ + wasm_exec_env_t exec_env, \ WASMTIME_SSP_PASSTHROUGH_FD_TABLE __wasi_fd_t sock, \ OPTION_TYPE option) \ { \ @@ -3607,7 +3615,7 @@ addr_pool_destroy(struct addr_pool *addr_pool) if (error != 0) \ return error; \ ret = os_socket_##FUNC_NAME(fd_number(fo), option); \ - fd_object_release(fo); \ + fd_object_release(exec_env, fo); \ if (BHT_OK != ret) \ return convert_errno(errno); \ return __WASI_ESUCCESS; \ @@ -3650,7 +3658,7 @@ WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(get_ipv6_only, bool *) #undef WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION __wasi_errno_t -wasmtime_ssp_sock_set_linger(struct fd_table *curfds, __wasi_fd_t sock, +wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool is_enabled, int linger_s) { struct fd_object *fo; @@ -3661,14 +3669,14 @@ wasmtime_ssp_sock_set_linger(struct fd_table *curfds, __wasi_fd_t sock, return error; ret = os_socket_set_linger(fd_number(fo), is_enabled, linger_s); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_get_linger(struct fd_table *curfds, __wasi_fd_t sock, +wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool *is_enabled, int *linger_s) { struct fd_object *fo; @@ -3679,7 +3687,7 @@ wasmtime_ssp_sock_get_linger(struct fd_table *curfds, __wasi_fd_t sock, return error; ret = os_socket_get_linger(fd_number(fo), is_enabled, linger_s); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); @@ -3687,7 +3695,7 @@ wasmtime_ssp_sock_get_linger(struct fd_table *curfds, __wasi_fd_t sock, } __wasi_errno_t -wasmtime_ssp_sock_set_ip_add_membership(struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) @@ -3705,14 +3713,14 @@ wasmtime_ssp_sock_set_ip_add_membership(struct fd_table *curfds, is_ipv6 = imr_multiaddr->kind == IPv6; ret = os_socket_set_ip_add_membership(fd_number(fo), &addr_info, imr_interface, is_ipv6); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_set_ip_drop_membership(struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) @@ -3730,14 +3738,14 @@ wasmtime_ssp_sock_set_ip_drop_membership(struct fd_table *curfds, is_ipv6 = imr_multiaddr->kind == IPv6; ret = os_socket_set_ip_drop_membership(fd_number(fo), &addr_info, imr_interface, is_ipv6); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_set_ip_multicast_loop(struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, bool is_enabled) { @@ -3749,14 +3757,14 @@ wasmtime_ssp_sock_set_ip_multicast_loop(struct fd_table *curfds, return error; ret = os_socket_set_ip_multicast_loop(fd_number(fo), ipv6, is_enabled); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_get_ip_multicast_loop(struct fd_table *curfds, +wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, bool *is_enabled) { @@ -3768,7 +3776,7 @@ wasmtime_ssp_sock_get_ip_multicast_loop(struct fd_table *curfds, return error; ret = os_socket_get_ip_multicast_loop(fd_number(fo), ipv6, is_enabled); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); From e41f4e36b2e388b6d3008fd647394e2a6d0de4ca Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 13:40:00 +0900 Subject: [PATCH 19/40] wasi: adapt connect, accept --- .../src/blocking_op.c | 24 +++++++++++++++++++ .../src/blocking_op.h | 6 ++++- .../sandboxed-system-primitives/src/posix.c | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index 0dd60a3375..f532131e47 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -101,3 +101,27 @@ blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, return ret; } #endif /* CONFIG_HAS_PREADV */ + +int +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, bh_socket_t *sockp, void *addr, unsigned int *addrlenp) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_accept(server_sock, sockp, addr, addrlenp); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, const char *addr, int port) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_connect(sock, addr, port); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index b005b8fc62..b3c8d392e8 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -8,6 +8,7 @@ #include +#include "bh_platform.h" #include "wasm_export.h" int @@ -21,7 +22,6 @@ blocking_op_preadv(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, ssize_t blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, off_t offset); - ssize_t blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, int iovcnt); @@ -31,3 +31,7 @@ blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, ssize_t blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, off_t offset); +int +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, bh_socket_t *sockp, void *addr, unsigned int *addrlenp); +int +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, const char *addr, int port); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 5dceb56acd..8925ef30d2 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -2722,7 +2722,7 @@ wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f goto fail; } - ret = os_socket_accept(fd_number(fo), &new_sock, NULL, NULL); + ret = blocking_op_socket_accept(exec_env, fd_number(fo), &new_sock, NULL, NULL); fd_object_release(exec_env, fo); if (BHT_OK != ret) { error = convert_errno(errno); @@ -2933,7 +2933,7 @@ wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, struct if (error != __WASI_ESUCCESS) return error; - ret = os_socket_connect(fd_number(fo), buf, + ret = blocking_op_socket_connect(exec_env, fd_number(fo), buf, addr->kind == IPv4 ? addr->addr.ip4.port : addr->addr.ip6.port); fd_object_release(exec_env, fo); From 798a2feb22c3e7e88e0af093c09b5a72c5f5d46d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 13:42:21 +0900 Subject: [PATCH 20/40] wasm_runtime_end_blocking_op: preserve errno --- core/iwasm/common/wasm_blocking_op.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index f299a4ddad..f45110a355 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -41,11 +41,13 @@ wasm_runtime_begin_blocking_op(wasm_exec_env_t env) void wasm_runtime_end_blocking_op(wasm_exec_env_t env) { + int saved_errno = errno; LOCK(env); bh_assert(ISSET(env, BLOCKING)); CLR(env, BLOCKING); UNLOCK(env); os_end_blocking_op(); + errno = saved_errno; } void From ed8851e96865871ffcf652ec5d467a3928173a1a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 15:25:29 +0900 Subject: [PATCH 21/40] apply clang-format --- .../libraries/libc-wasi/libc_wasi_wrapper.c | 109 ++++--- .../src/blocking_op.c | 13 +- .../src/blocking_op.h | 13 +- .../sandboxed-system-primitives/src/posix.c | 300 ++++++++++-------- 4 files changed, 247 insertions(+), 188 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index 2bde369c33..292bd83795 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -443,8 +443,8 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len, offset, - &nwritten); + err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len, + offset, &nwritten); if (err) goto fail; @@ -539,7 +539,8 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset, if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence, newoffset); + return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence, + newoffset); } static wasi_errno_t @@ -608,8 +609,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_fdstat_set_rights(exec_env, curfds, fd, fs_rights_base, - fs_rights_inheriting); + return wasmtime_ssp_fd_fdstat_set_rights( + exec_env, curfds, fd, fs_rights_base, fs_rights_inheriting); } static wasi_errno_t @@ -664,7 +665,8 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len, &nwritten); + err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len, + &nwritten); if (err) goto fail; @@ -717,7 +719,8 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_create_directory(exec_env, curfds, fd, path, path_len); + return wasmtime_ssp_path_create_directory(exec_env, curfds, fd, path, + path_len); } static wasi_errno_t @@ -734,8 +737,9 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags, old_path, - old_path_len, new_fd, new_path, new_path_len); + return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags, + old_path, old_path_len, new_fd, new_path, + new_path_len); } static wasi_errno_t @@ -757,9 +761,9 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd, if (!validate_native_addr(fd_app, sizeof(wasi_fd_t))) return (wasi_errno_t)-1; - err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path, path_len, - oflags, fs_rights_base, fs_rights_inheriting, - fs_flags, &fd); + err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path, + path_len, oflags, fs_rights_base, + fs_rights_inheriting, fs_flags, &fd); *fd_app = fd; return err; @@ -781,7 +785,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf, if (!validate_native_addr(bufused_app, sizeof(uint32))) return (wasi_errno_t)-1; - err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie, &bufused); + err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie, + &bufused); if (err) return err; @@ -806,8 +811,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path, if (!validate_native_addr(bufused_app, sizeof(uint32))) return (wasi_errno_t)-1; - err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf, buf_len, - &bufused); + err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf, + buf_len, &bufused); if (err) return err; @@ -827,8 +832,9 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_rename(exec_env, curfds, old_fd, old_path, old_path_len, - new_fd, new_path, new_path_len); + return wasmtime_ssp_path_rename(exec_env, curfds, old_fd, old_path, + old_path_len, new_fd, new_path, + new_path_len); } static wasi_errno_t @@ -860,8 +866,8 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim, st_mtim, - fstflags); + return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim, + st_mtim, fstflags); } static wasi_errno_t @@ -893,8 +899,8 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(filestat, sizeof(wasi_filestat_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path, path_len, - filestat); + return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path, + path_len, filestat); } static wasi_errno_t @@ -910,8 +916,9 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_filestat_set_times(exec_env, - curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags); + return wasmtime_ssp_path_filestat_set_times(exec_env, curfds, fd, flags, + path, path_len, st_atim, + st_mtim, fstflags); } static wasi_errno_t @@ -927,8 +934,8 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path, old_path_len, - fd, new_path, new_path_len); + return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path, + old_path_len, fd, new_path, new_path_len); } static wasi_errno_t @@ -956,7 +963,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path, path_len); + return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path, + path_len); } #if WASM_ENABLE_THREAD_MGR != 0 @@ -1027,8 +1035,8 @@ execute_interruptible_poll_oneoff( /* update timeout for clock subscription events */ update_clock_subscription_data( in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); - err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, nsubscriptions, - nevents); + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, + nsubscriptions, nevents); elapsed += time_quant; if (err) { @@ -1080,7 +1088,8 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in, return (wasi_errno_t)-1; #if WASM_ENABLE_THREAD_MGR == 0 - err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions, &nevents); + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions, + &nevents); #else err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions, &nevents, exec_env); @@ -1193,8 +1202,8 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx); - return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host, service, - hints, addr_info, addr_info_size, + return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host, + service, hints, addr_info, addr_info_size, max_info_size); } @@ -1293,7 +1302,8 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled, + linger_s); } static wasi_errno_t @@ -1426,7 +1436,8 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1464,7 +1475,8 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1657,7 +1669,8 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled, + linger_s); } static wasi_errno_t @@ -1767,7 +1780,8 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1799,7 +1813,8 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1868,8 +1883,8 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_add_membership(exec_env, curfds, fd, imr_multiaddr, - imr_interface); + return wasmtime_ssp_sock_set_ip_add_membership( + exec_env, curfds, fd, imr_multiaddr, imr_interface); } static wasi_errno_t @@ -1889,8 +1904,8 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_drop_membership(exec_env, curfds, fd, imr_multiaddr, - imr_interface); + return wasmtime_ssp_sock_set_ip_drop_membership( + exec_env, curfds, fd, imr_multiaddr, imr_interface); } static wasi_errno_t @@ -2054,8 +2069,9 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock, memset(buf_begin, 0, total_size); *ro_data_len = 0; - err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin, total_size, - ri_flags, src_addr, &recv_bytes); + err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin, + total_size, ri_flags, src_addr, + &recv_bytes); if (err != __WASI_ESUCCESS) { goto fail; } @@ -2154,7 +2170,8 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size, &send_bytes); + err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size, + &send_bytes); *so_data_len = (uint32)send_bytes; wasm_runtime_free(buf); @@ -2194,8 +2211,8 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf, buf_size, - si_flags, dest_addr, &send_bytes); + err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf, + buf_size, si_flags, dest_addr, &send_bytes); *so_data_len = (uint32)send_bytes; wasm_runtime_free(buf); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index f532131e47..bfacdd9c6a 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -63,7 +63,7 @@ blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, ssize_t blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, - int iovcnt) + int iovcnt) { if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; @@ -77,7 +77,7 @@ blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, #if CONFIG_HAS_PWRITEV ssize_t blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, - int iovcnt, off_t offset) + int iovcnt, off_t offset) { if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; @@ -90,7 +90,7 @@ blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, #else /* CONFIG_HAS_PREADV */ ssize_t blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, - off_t offset) + off_t offset) { if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; @@ -103,7 +103,9 @@ blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, #endif /* CONFIG_HAS_PREADV */ int -blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, bh_socket_t *sockp, void *addr, unsigned int *addrlenp) +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, + bh_socket_t *sockp, void *addr, + unsigned int *addrlenp) { if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; @@ -115,7 +117,8 @@ blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, bh_ } int -blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, const char *addr, int port) +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, + const char *addr, int port) { if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index b3c8d392e8..8321230bbf 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -24,14 +24,17 @@ blocking_op_pread(wasm_exec_env_t exec_env, int fd, void *p, size_t nb, off_t offset); ssize_t blocking_op_writev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, - int iovcnt); + int iovcnt); ssize_t blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, - int iovcnt, off_t offset); + int iovcnt, off_t offset); ssize_t blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, - off_t offset); + off_t offset); int -blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, bh_socket_t *sockp, void *addr, unsigned int *addrlenp); +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, + bh_socket_t *sockp, void *addr, + unsigned int *addrlenp); int -blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, const char *addr, int port); +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, + const char *addr, int port); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 8925ef30d2..4553ae2007 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -633,21 +633,23 @@ fd_number(const struct fd_object *fo) // The env == NULL case is for // fd_table_destroy, path_get, path_put, fd_table_insert_existing -#define CLOSE_NON_STD_FD(env, fd) \ - do { \ - if (fd > 2) { \ - if (env == NULL) { \ - close(fd); \ - } else { \ - blocking_op_close(env, fd); \ - } \ - } \ +#define CLOSE_NON_STD_FD(env, fd) \ + do { \ + if (fd > 2) { \ + if (env == NULL) { \ + close(fd); \ + } \ + else { \ + blocking_op_close(env, fd); \ + } \ + } \ } while (0) // Lowers the reference count on a file descriptor object. When the // reference count reaches zero, its resources are cleaned up. static void -fd_object_release(wasm_exec_env_t env, struct fd_object *fo) UNLOCKS(fo->refcount) +fd_object_release(wasm_exec_env_t env, struct fd_object *fo) + UNLOCKS(fo->refcount) { if (refcount_release(&fo->refcount)) { int saved_errno = errno; @@ -737,10 +739,10 @@ fd_table_unused(struct fd_table *ft) REQUIRES_SHARED(ft->lock) // Inserts a file descriptor object into an unused slot of the file // descriptor table. static __wasi_errno_t -fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft, struct fd_object *fo, - __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, - __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) - UNLOCKS(fo->refcount) +fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft, + struct fd_object *fo, __wasi_rights_t rights_base, + __wasi_rights_t rights_inheriting, __wasi_fd_t *out) + REQUIRES_UNLOCKED(ft->lock) UNLOCKS(fo->refcount) { // Grow the file descriptor table if needed. rwlock_wrlock(&ft->lock); @@ -758,8 +760,8 @@ fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft, struct fd_object // Inserts a numerical file descriptor into the file descriptor table. static __wasi_errno_t -fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft, int in, __wasi_filetype_t type, - __wasi_rights_t rights_base, +fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft, int in, + __wasi_filetype_t type, __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) { @@ -779,7 +781,8 @@ fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft, int in, __wasi } fo->directory.handle = NULL; } - return fd_table_insert(exec_env, ft, fo, rights_base, rights_inheriting, out); + return fd_table_insert(exec_env, ft, fo, rights_base, rights_inheriting, + out); } __wasi_errno_t @@ -829,8 +832,8 @@ wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, - __wasi_fd_t fd) +wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t fd) { // Don't allow closing a pre-opened resource. // TODO: Eventually, we do want to permit this, once libpreopen in @@ -902,7 +905,8 @@ fd_object_get(struct fd_table *curfds, struct fd_object **fo, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd) +wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = @@ -996,9 +1000,10 @@ wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - const __wasi_ciovec_t *iov, size_t iovcnt, - __wasi_filesize_t offset, size_t *nwritten) +wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iov, + size_t iovcnt, __wasi_filesize_t offset, + size_t *nwritten) { if (iovcnt == 0) return __WASI_EINVAL; @@ -1011,11 +1016,13 @@ wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi ssize_t len; #if CONFIG_HAS_PWRITEV - len = blocking_op_pwritev(exec_env, fd_number(fo), (const struct iovec *)iov, (int)iovcnt, - (off_t)offset); + len = + blocking_op_pwritev(exec_env, fd_number(fo), (const struct iovec *)iov, + (int)iovcnt, (off_t)offset); #else if (iovcnt == 1) { - len = blocking_op_pwrite(exec_env, fd_number(fo), iov->buf, iov->buf_len, offset); + len = blocking_op_pwrite(exec_env, fd_number(fo), iov->buf, + iov->buf_len, offset); } else { // Allocate a single buffer to fit all data. @@ -1035,7 +1042,8 @@ wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi } // Perform a single write operation. - len = blocking_op_pwrite(exec_env, fd_number(fo), buf, totalsize, offset); + len = + blocking_op_pwrite(exec_env, fd_number(fo), buf, totalsize, offset); wasm_runtime_free(buf); } #endif @@ -1067,8 +1075,9 @@ wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, - __wasi_fd_t from, __wasi_fd_t to) +wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t from, + __wasi_fd_t to) { // Don't allow renumbering over a pre-opened resource. // TODO: Eventually, we do want to permit this, once libpreopen in @@ -1118,9 +1127,9 @@ wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, stru } __wasi_errno_t -wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_filedelta_t offset, __wasi_whence_t whence, - __wasi_filesize_t *newoffset) +wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *newoffset) { int nwhence; switch (whence) { @@ -1156,8 +1165,8 @@ wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f } __wasi_errno_t -wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_filesize_t *newoffset) +wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t *newoffset) { struct fd_object *fo; __wasi_errno_t error = @@ -1174,8 +1183,8 @@ wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f } __wasi_errno_t -wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_fdstat_t *buf) +wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdstat_t *buf) { struct fd_table *ft = curfds; rwlock_rdlock(&ft->lock); @@ -1223,7 +1232,8 @@ wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __ } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_fdflags_t fs_flags) { int noflags = 0; @@ -1260,7 +1270,8 @@ wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, struct fd_table *curf } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_rights_t fs_rights_base, __wasi_rights_t fs_rights_inheriting) { @@ -1282,7 +1293,8 @@ wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, struct fd_table *cur } __wasi_errno_t -wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd) +wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = @@ -1298,8 +1310,8 @@ wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f } __wasi_errno_t -wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - const __wasi_ciovec_t *iov, size_t iovcnt, +wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, size_t *nwritten) { struct fd_object *fo; @@ -1339,9 +1351,9 @@ wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_ } __wasi_errno_t -wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_filesize_t offset, __wasi_filesize_t len, - __wasi_advice_t advice) +wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len, __wasi_advice_t advice) { #ifdef POSIX_FADV_NORMAL int nadvice; @@ -1405,8 +1417,9 @@ wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi } __wasi_errno_t -wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_filesize_t offset, __wasi_filesize_t len) +wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len) { struct fd_object *fo; __wasi_errno_t error = @@ -1743,7 +1756,8 @@ path_put(struct path_access *pa) UNLOCKS(pa->fd_object->refcount) } __wasi_errno_t -wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; @@ -1788,11 +1802,11 @@ validate_path(const char *path, struct fd_prestats *pt) } __wasi_errno_t -wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, - __wasi_fd_t old_fd, __wasi_lookupflags_t old_flags, - const char *old_path, size_t old_path_len, - __wasi_fd_t new_fd, const char *new_path, - size_t new_path_len) +wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t old_fd, + __wasi_lookupflags_t old_flags, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) { struct path_access old_pa; __wasi_errno_t error = @@ -1845,9 +1859,9 @@ wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, struct } __wasi_errno_t -wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t dirfd, - __wasi_lookupflags_t dirflags, const char *path, - size_t pathlen, __wasi_oflags_t oflags, +wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, + const char *path, size_t pathlen, __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) @@ -1978,7 +1992,8 @@ wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi rights_base |= (__wasi_rights_t)RIGHTS_REGULAR_FILE_BASE; } - return fd_table_insert_fd(exec_env, curfds, nfd, type, rights_base & max_base, + return fd_table_insert_fd(exec_env, curfds, nfd, type, + rights_base & max_base, rights_inheriting & max_inheriting, fd); } @@ -1997,9 +2012,9 @@ fd_readdir_put(void *buf, size_t bufsize, size_t *bufused, const void *elem, } __wasi_errno_t -wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, void *buf, - size_t nbyte, __wasi_dircookie_t cookie, - size_t *bufused) +wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, void *buf, size_t nbyte, + __wasi_dircookie_t cookie, size_t *bufused) { struct fd_object *fo; __wasi_errno_t error = @@ -2093,9 +2108,9 @@ wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, __was } __wasi_errno_t -wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - const char *path, size_t pathlen, char *buf, - size_t bufsize, size_t *bufused) +wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t pathlen, + char *buf, size_t bufsize, size_t *bufused) { struct path_access pa; __wasi_errno_t error = path_get_nofollow( @@ -2116,10 +2131,10 @@ wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, __ } __wasi_errno_t -wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t old_fd, - const char *old_path, size_t old_path_len, - __wasi_fd_t new_fd, const char *new_path, - size_t new_path_len) +wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t old_fd, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) { struct path_access old_pa; __wasi_errno_t error = @@ -2161,8 +2176,8 @@ convert_stat(const struct stat *in, __wasi_filestat_t *out) } __wasi_errno_t -wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_filestat_t *buf) +wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filestat_t *buf) { struct fd_object *fo; __wasi_errno_t error = @@ -2231,7 +2246,8 @@ convert_utimens_arguments(__wasi_timestamp_t st_atim, } __wasi_errno_t -wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_filesize_t st_size) { struct fd_object *fo; @@ -2248,7 +2264,8 @@ wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, struct fd_table *cur } __wasi_errno_t -wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim, __wasi_fstflags_t fstflags) @@ -2276,7 +2293,8 @@ wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table *cu } __wasi_errno_t -wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, size_t pathlen, __wasi_filestat_t *buf) { @@ -2313,7 +2331,8 @@ wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds } __wasi_errno_t -wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, size_t pathlen, __wasi_timestamp_t st_atim, @@ -2351,10 +2370,10 @@ wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, struct fd_table * } __wasi_errno_t -wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, struct fd_prestats *prestats, - const char *old_path, size_t old_path_len, - __wasi_fd_t fd, const char *new_path, - size_t new_path_len) +wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, const char *old_path, + size_t old_path_len, __wasi_fd_t fd, + const char *new_path, size_t new_path_len) { char *target = str_nullterminate(old_path, old_path_len); if (target == NULL) @@ -2386,8 +2405,8 @@ wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, str } __wasi_errno_t -wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - const char *path, size_t pathlen) +wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; __wasi_errno_t error = path_get_nofollow( @@ -2420,7 +2439,8 @@ wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; @@ -2708,8 +2728,9 @@ wasmtime_ssp_random_get(void *buf, size_t nbyte) } __wasi_errno_t -wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_fdflags_t flags, __wasi_fd_t *fd_new) +wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdflags_t flags, + __wasi_fd_t *fd_new) { __wasi_filetype_t wasi_type; __wasi_rights_t max_base, max_inheriting; @@ -2722,7 +2743,8 @@ wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f goto fail; } - ret = blocking_op_socket_accept(exec_env, fd_number(fo), &new_sock, NULL, NULL); + ret = blocking_op_socket_accept(exec_env, fd_number(fo), &new_sock, NULL, + NULL); fd_object_release(exec_env, fo); if (BHT_OK != ret) { error = convert_errno(errno); @@ -2753,8 +2775,8 @@ wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f } __wasi_errno_t -wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_addr_t *addr) +wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; bh_sockaddr_t bh_addr; @@ -2777,8 +2799,8 @@ wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, __wa } __wasi_errno_t -wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_addr_t *addr) +wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; bh_sockaddr_t bh_addr; @@ -2830,8 +2852,9 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen) } __wasi_errno_t -wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) { char buf[48] = { 0 }; struct fd_object *fo; @@ -2861,9 +2884,9 @@ wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, struct add } __wasi_errno_t -wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, char **ns_lookup_list, - const char *host, const char *service, - __wasi_addr_info_hints_t *hints, +wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, + char **ns_lookup_list, const char *host, + const char *service, __wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info, __wasi_size_t addr_info_size, __wasi_size_t *max_info_size) @@ -2913,8 +2936,9 @@ wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, ch } __wasi_errno_t -wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) { char buf[48] = { 0 }; struct fd_object *fo; @@ -2934,8 +2958,8 @@ wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, struct return error; ret = blocking_op_socket_connect(exec_env, fd_number(fo), buf, - addr->kind == IPv4 ? addr->addr.ip4.port - : addr->addr.ip6.port); + addr->kind == IPv4 ? addr->addr.ip4.port + : addr->addr.ip6.port); fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); @@ -2945,7 +2969,8 @@ wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, struct } __wasi_errno_t -wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size) { struct fd_object *fo; @@ -2969,8 +2994,8 @@ wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfd } __wasi_errno_t -wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - uint8_t *reuse) +wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) { struct fd_object *fo; @@ -2994,8 +3019,8 @@ wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - uint8_t *reuse) +wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) { struct fd_object *fo; int ret; @@ -3025,7 +3050,8 @@ wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t *size) { struct fd_object *fo; @@ -3049,8 +3075,8 @@ wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfd } __wasi_errno_t -wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - __wasi_size_t backlog) +wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_size_t backlog) { struct fd_object *fo; int ret; @@ -3069,9 +3095,9 @@ wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_f } __wasi_errno_t -wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t poolfd, - __wasi_address_family_t af, __wasi_sock_type_t socktype, - __wasi_fd_t *sockfd) +wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t poolfd, __wasi_address_family_t af, + __wasi_sock_type_t socktype, __wasi_fd_t *sockfd) { bh_socket_t sock; bool is_tcp = SOCKET_DGRAM == socktype ? false : true; @@ -3113,7 +3139,8 @@ wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_ } __wasi_errno_t -wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size) { struct fd_object *fo; @@ -3135,8 +3162,8 @@ wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfd } __wasi_errno_t -wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - uint8_t reuse) +wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; int ret; @@ -3157,8 +3184,8 @@ wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, - uint8_t reuse) +wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; int ret; @@ -3185,7 +3212,8 @@ wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t fd, +wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, __wasi_size_t size) { struct fd_object *fo; @@ -3208,18 +3236,19 @@ wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, struct fd_table *curfd } __wasi_errno_t -wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, void *buf, - size_t buf_len, size_t *recv_len) +wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, + size_t *recv_len) { __wasi_addr_t src_addr; - return wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf, buf_len, 0, &src_addr, - recv_len); + return wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf, buf_len, 0, + &src_addr, recv_len); } __wasi_errno_t -wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, - void *buf, size_t buf_len, +wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr, size_t *recv_len) { @@ -3246,8 +3275,9 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, _ } __wasi_errno_t -wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, - const void *buf, size_t buf_len, size_t *sent_len) +wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, const void *buf, size_t buf_len, + size_t *sent_len) { struct fd_object *fo; __wasi_errno_t error; @@ -3269,8 +3299,9 @@ wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi } __wasi_errno_t -wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, struct addr_pool *addr_pool, - __wasi_fd_t sock, const void *buf, size_t buf_len, +wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t sock, + const void *buf, size_t buf_len, __wasi_siflags_t si_flags, const __wasi_addr_t *dest_addr, size_t *sent_len) { @@ -3306,7 +3337,8 @@ wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, str } __wasi_errno_t -wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock) +wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock) { struct fd_object *fo; __wasi_errno_t error; @@ -3615,7 +3647,7 @@ addr_pool_destroy(struct addr_pool *addr_pool) if (error != 0) \ return error; \ ret = os_socket_##FUNC_NAME(fd_number(fo), option); \ - fd_object_release(exec_env, fo); \ + fd_object_release(exec_env, fo); \ if (BHT_OK != ret) \ return convert_errno(errno); \ return __WASI_ESUCCESS; \ @@ -3658,8 +3690,8 @@ WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(get_ipv6_only, bool *) #undef WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION __wasi_errno_t -wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, - bool is_enabled, int linger_s) +wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool is_enabled, int linger_s) { struct fd_object *fo; __wasi_errno_t error; @@ -3676,8 +3708,8 @@ wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, __wasi_fd_t sock, - bool *is_enabled, int *linger_s) +wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool *is_enabled, int *linger_s) { struct fd_object *fo; __wasi_errno_t error; @@ -3695,7 +3727,8 @@ wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, } __wasi_errno_t -wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) @@ -3720,7 +3753,8 @@ wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, struct fd_tabl } __wasi_errno_t -wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) @@ -3745,7 +3779,8 @@ wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, struct fd_tab } __wasi_errno_t -wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, struct fd_table *curfds, +wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, bool is_enabled) { @@ -3764,7 +3799,8 @@ wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, struct fd_tabl } __wasi_errno_t -wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, struct fd_table *curfds, +wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, bool ipv6, bool *is_enabled) { From a3fc491995e60af4bddfcec8a90dc9dbdd8fe3b2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 15:31:30 +0900 Subject: [PATCH 22/40] nuttx/wamr.mk: add blocking_op.c --- product-mini/platforms/nuttx/wamr.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/product-mini/platforms/nuttx/wamr.mk b/product-mini/platforms/nuttx/wamr.mk index 33c485a4bc..02cf81581e 100644 --- a/product-mini/platforms/nuttx/wamr.mk +++ b/product-mini/platforms/nuttx/wamr.mk @@ -246,6 +246,7 @@ ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI),y) CFLAGS += -DWASM_ENABLE_LIBC_WASI=1 CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/src CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/include +CSRCS += blocking_op.c CSRCS += posix_socket.c CSRCS += libc_wasi_wrapper.c VPATH += $(IWASM_ROOT)/libraries/libc-wasi From e1379c54d9f6f37bfdef33d22e5c19ab9387406a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 15:33:30 +0900 Subject: [PATCH 23/40] some platforms doesn't seem to have sys/uio.h --- .../libc-wasi/sandboxed-system-primitives/src/blocking_op.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index 8321230bbf..9337576aeb 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -3,11 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include -#include - -#include - #include "bh_platform.h" #include "wasm_export.h" From 29422d2b3b348aeffe41f0fa87c3acb6eae5179d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 17:54:09 +0900 Subject: [PATCH 24/40] wasi: adapt send_to/recv_from --- .../src/blocking_op.c | 28 +++++++++++++++++++ .../src/blocking_op.h | 8 ++++++ .../sandboxed-system-primitives/src/posix.c | 6 ++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index bfacdd9c6a..dd70041c2e 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -128,3 +128,31 @@ blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, wasm_runtime_end_blocking_op(exec_env); return ret; } + +int +blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock, + void *buf, unsigned int len, int flags, + bh_sockaddr_t *src_addr) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_recv_from(sock, buf, len, flags, src_addr); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, + const void *buf, unsigned int len, int flags, + const bh_sockaddr_t *dest_addr) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_send_to(sock, buf, len, flags, dest_addr); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index 9337576aeb..5940868406 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -33,3 +33,11 @@ blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, int blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, const char *addr, int port); +int +blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock, + void *buf, unsigned int len, int flags, + bh_sockaddr_t *src_addr); +int +blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, + const void *buf, unsigned int len, int flags, + const bh_sockaddr_t *dest_addr); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 4553ae2007..f28803b23f 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -3262,7 +3262,8 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, return error; } - ret = os_socket_recv_from(fd_number(fo), buf, buf_len, 0, &sockaddr); + ret = blocking_op_socket_recv_from(exec_env, fd_number(fo), buf, buf_len, 0, + &sockaddr); fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); @@ -3326,7 +3327,8 @@ wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, wasi_addr_to_bh_sockaddr(dest_addr, &sockaddr); - ret = os_socket_send_to(fd_number(fo), buf, buf_len, 0, &sockaddr); + ret = blocking_op_socket_send_to(exec_env, fd_number(fo), buf, buf_len, 0, + &sockaddr); fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); From 1a04b486934e62fbbd26744de4d7677193186a57 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 18:44:22 +0900 Subject: [PATCH 25/40] wasi: adapt socket_addr_resolve --- .../src/blocking_op.c | 17 +++++++++++++++++ .../src/blocking_op.h | 6 ++++++ .../sandboxed-system-primitives/src/posix.c | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index dd70041c2e..3a81387688 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -156,3 +156,20 @@ blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, wasm_runtime_end_blocking_op(exec_env); return ret; } + +int +blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, + const char *service, uint8_t *hint_is_tcp, + uint8_t *hint_is_ipv4, + bh_addr_info_t *addr_info, + size_t addr_info_size, size_t *max_info_size) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_addr_resolve(host, service, hint_is_tcp, hint_is_ipv4, + addr_info, addr_info_size, max_info_size); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index 5940868406..7fd358779b 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -41,3 +41,9 @@ int blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, const void *buf, unsigned int len, int flags, const bh_sockaddr_t *dest_addr); +int +blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, + const char *service, uint8_t *hint_is_tcp, + uint8_t *hint_is_ipv4, + bh_addr_info_t *addr_info, + size_t addr_info_size, size_t *max_info_size); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index f28803b23f..cf09561d89 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -2907,8 +2907,8 @@ wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, return __WASI_EACCES; } - int ret = os_socket_addr_resolve( - host, service, + int ret = blocking_op_socket_addr_resolve( + exec_env, host, service, hints->hints_enabled && hints->type != SOCKET_ANY ? &hints_is_tcp : NULL, hints->hints_enabled && hints->family != INET_UNSPEC ? &hints_is_ipv4 From 0fe0f1ca37062d792f87b08efcbc555c9b271826 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 18:50:13 +0900 Subject: [PATCH 26/40] wasi: fix comments --- .../libc-wasi/sandboxed-system-primitives/src/blocking_op.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index 3a81387688..357165cbad 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -87,7 +87,7 @@ blocking_op_pwritev(wasm_exec_env_t exec_env, int fd, const struct iovec *iov, wasm_runtime_end_blocking_op(exec_env); return ret; } -#else /* CONFIG_HAS_PREADV */ +#else /* CONFIG_HAS_PWRITEV */ ssize_t blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, off_t offset) @@ -100,7 +100,7 @@ blocking_op_pwrite(wasm_exec_env_t exec_env, int fd, const void *p, size_t nb, wasm_runtime_end_blocking_op(exec_env); return ret; } -#endif /* CONFIG_HAS_PREADV */ +#endif /* CONFIG_HAS_PWRITEV */ int blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, From 896cfeb2046b362c86a07fee75726c9eb7f39026 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 18:59:03 +0900 Subject: [PATCH 27/40] add a comment --- core/iwasm/include/wasm_export.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 5f5a0ce850..abc77d1aa9 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1546,6 +1546,24 @@ wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_context(wasm_module_inst_t inst, void *key); +/* + * wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op + * + * wrap an operation which possibly blocks for long to prepare + * for async termination. + * + * eg. + * + * if (!wasm_runtime_begin_blocking_op) { + * return EINTR; + * } + * ret = possibly_blocking_op(); + * wasm_runtime_end_blocking_op(env); + * return ret; + * + * If the underlying platform has a support, (OS_ENABLE_WAKEUP_BLOCKING_OP) + * it's used to unblock the thread for async termination. + */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env); From 8775b9a1561150b941a05fbd4c5b22f9bdd5d4e5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 7 Sep 2023 19:54:26 +0900 Subject: [PATCH 28/40] comment --- core/iwasm/include/wasm_export.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index abc77d1aa9..5490ad5254 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1549,8 +1549,9 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key); /* * wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op * - * wrap an operation which possibly blocks for long to prepare - * for async termination. + * These APIs are intended to be used by the implementations of + * host functions. It wraps an operation which possibly blocks for long + * to prepare for async termination. * * eg. * From 0454842f8783b9cd6cdf1e411dd663c5e0d84b11 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 8 Sep 2023 09:13:22 +0900 Subject: [PATCH 29/40] wasi: adapt openat note: openat with O_DIRECTORY should not block --- .../sandboxed-system-primitives/src/blocking_op.c | 13 +++++++++++++ .../sandboxed-system-primitives/src/blocking_op.h | 3 +++ .../sandboxed-system-primitives/src/posix.c | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index 357165cbad..fab329ee01 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -173,3 +173,16 @@ blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, wasm_runtime_end_blocking_op(exec_env); return ret; } + +int +blocking_op_openat(wasm_exec_env_t exec_env, int fd, const char *path, + int oflags, mode_t mode) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = openat(fd, path, oflags, mode); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h index 7fd358779b..44a16d3386 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -47,3 +47,6 @@ blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, uint8_t *hint_is_ipv4, bh_addr_info_t *addr_info, size_t addr_info_size, size_t *max_info_size); +int +blocking_op_openat(wasm_exec_env_t exec_env, int fd, const char *path, + int oflags, mode_t mode); diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index cf09561d89..c096511c95 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -1595,6 +1595,9 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // components. In other words, a pathname component that must be a // directory. First attempt to obtain a directory file descriptor // for it. + // + // Note: we don't bother to use blocking_op_openat here + // because openat with O_DIRECTORY should not block. int newdir = #ifdef O_SEARCH openat(fds[curfd], file, O_SEARCH | O_DIRECTORY | O_NOFOLLOW); @@ -1935,7 +1938,7 @@ wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, if (!pa.follow) noflags |= O_NOFOLLOW; - int nfd = openat(pa.fd, pa.path, noflags, 0666); + int nfd = blocking_op_openat(exec_env, pa.fd, pa.path, noflags, 0666); if (nfd < 0) { int openat_errno = errno; // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket. From a770e37e4cc12ee1b9bf6d2e7476965ba16069c1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 8 Sep 2023 09:35:20 +0900 Subject: [PATCH 30/40] comment --- .../platform/include/platform_api_extension.h | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/shared/platform/include/platform_api_extension.h b/core/shared/platform/include/platform_api_extension.h index 2e54bdb0fe..06bd9ee899 100644 --- a/core/shared/platform/include/platform_api_extension.h +++ b/core/shared/platform/include/platform_api_extension.h @@ -323,13 +323,31 @@ os_sem_getvalue(korp_sem *sem, int *sval); int os_sem_unlink(const char *name); -/* */ +/** + * Initialize process-global state for os_wakeup_blocking_op. + */ int os_blocking_op_init(); + +/** + * Start accepting os_wakeup_blocking_op requests for the calling thread. + */ void os_begin_blocking_op(); + +/** + * Stop accepting os_wakeup_blocking_op requests for the calling thread. + */ void os_end_blocking_op(); + +/** + * Wake up the specified thread. + * + * For example, on posix-like platforms, this can be implemented by + * sending a signal (w/o SA_RESTART) which interrupts a blocking + * system call. + */ int os_wakeup_blocking_op(korp_tid tid); From 66438228c678f1db58022bfd888f397e22617784 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 13 Sep 2023 16:06:48 +0900 Subject: [PATCH 31/40] add os_set_signal_number_for_blocking_op --- core/shared/platform/common/posix/posix_blocking_op.c | 9 +++++++-- core/shared/platform/darwin/platform_internal.h | 2 ++ core/shared/platform/freebsd/platform_internal.h | 2 ++ core/shared/platform/linux/platform_internal.h | 2 ++ core/shared/platform/nuttx/platform_internal.h | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/shared/platform/common/posix/posix_blocking_op.c b/core/shared/platform/common/posix/posix_blocking_op.c index 81cdd5764e..9e293645a4 100644 --- a/core/shared/platform/common/posix/posix_blocking_op.c +++ b/core/shared/platform/common/posix/posix_blocking_op.c @@ -8,7 +8,7 @@ #ifdef OS_ENABLE_WAKEUP_BLOCKING_OP static bool g_blocking_op_inited = false; -static int g_blocking_op_signo; +static int g_blocking_op_signo = SIGUSR1; static sigset_t g_blocking_op_sigmask; static void @@ -17,6 +17,12 @@ blocking_op_sighandler(int signo) /* nothing */ } +void +os_set_signal_number_for_blocking_op(int signo) +{ + g_blocking_op_signo = signo; +} + int os_blocking_op_init() { @@ -24,7 +30,6 @@ os_blocking_op_init() return BHT_OK; } - g_blocking_op_signo = SIGUSR1; /* XXX make this configurable */ sigemptyset(&g_blocking_op_sigmask); sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo); diff --git a/core/shared/platform/darwin/platform_internal.h b/core/shared/platform/darwin/platform_internal.h index 67e0edf3fb..1055ba9711 100644 --- a/core/shared/platform/darwin/platform_internal.h +++ b/core/shared/platform/darwin/platform_internal.h @@ -103,6 +103,8 @@ os_sigreturn(); #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ #define OS_ENABLE_WAKEUP_BLOCKING_OP +void +os_set_signal_number_for_blocking_op(int signo); #ifdef __cplusplus } diff --git a/core/shared/platform/freebsd/platform_internal.h b/core/shared/platform/freebsd/platform_internal.h index 64b5a03af9..8bdb98942c 100644 --- a/core/shared/platform/freebsd/platform_internal.h +++ b/core/shared/platform/freebsd/platform_internal.h @@ -102,6 +102,8 @@ os_sigreturn(); #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ #define OS_ENABLE_WAKEUP_BLOCKING_OP +void +os_set_signal_number_for_blocking_op(int signo); #ifdef __cplusplus } diff --git a/core/shared/platform/linux/platform_internal.h b/core/shared/platform/linux/platform_internal.h index 4e5098876e..08cdb01073 100644 --- a/core/shared/platform/linux/platform_internal.h +++ b/core/shared/platform/linux/platform_internal.h @@ -116,6 +116,8 @@ os_sigreturn(); #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ #define OS_ENABLE_WAKEUP_BLOCKING_OP +void +os_set_signal_number_for_blocking_op(int signo); #ifdef __cplusplus } diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index 0878eec8d0..5ae620955b 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -124,6 +124,8 @@ DIR * fdopendir(int fd); #define OS_ENABLE_WAKEUP_BLOCKING_OP +void +os_set_signal_number_for_blocking_op(int signo); #ifdef __cplusplus } From 33d23f0b40969a74c01c600bdad5a67933c2c56a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 13 Sep 2023 16:13:23 +0900 Subject: [PATCH 32/40] comment --- core/iwasm/include/wasm_export.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 5490ad5254..9a67aca422 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1562,8 +1562,24 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key); * wasm_runtime_end_blocking_op(env); * return ret; * - * If the underlying platform has a support, (OS_ENABLE_WAKEUP_BLOCKING_OP) - * it's used to unblock the thread for async termination. + * If the underlying platform support (OS_ENABLE_WAKEUP_BLOCKING_OP) is + * not available, these functions are no-op. In that case, the runtime + * might not terminate a blocking thread in a timely manner. + * + * If the underlying platform support is available, it's used to wake up + * the thread for async termination. The expectation here is that a + * `os_wakeup_blocking_op` call makes the blocking operation + * (`possibly_blocking_op` in the above example) return in a timely manner. + * + * The actual wake up mechanism used by `os_wakeup_blocking_op` is + * platform-dependent. It might impose some platform-dependent restrictions + * on the implementation of the blocking opearation. + * + * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is + * used. The signal delivery configurations (eg. signal handler, signal mask, + * etc) for the signal is set up by the runtime. You can change the signal + * to use for this purpose by calling os_set_signal_number_for_blocking_op + * before the runtime initialization. */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env); From 143a7d64db87e9ddb33bd15b66ea0d54793b9c7e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 14 Sep 2023 17:48:58 +0900 Subject: [PATCH 33/40] posix_blocking_op.c: use pthread_sigmask instead of sigprocmask I was assuming pthread_sigmask was an alias of sigprocmask. It's true for platforms I'm familiar with. However, after reading the descriptions in the relevant standards, I changed my mind. --- core/shared/platform/common/posix/posix_blocking_op.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/shared/platform/common/posix/posix_blocking_op.c b/core/shared/platform/common/posix/posix_blocking_op.c index 9e293645a4..560828a06e 100644 --- a/core/shared/platform/common/posix/posix_blocking_op.c +++ b/core/shared/platform/common/posix/posix_blocking_op.c @@ -47,13 +47,13 @@ os_blocking_op_init() void os_begin_blocking_op() { - sigprocmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); + pthread_sigmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); } void os_end_blocking_op() { - sigprocmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); + pthread_sigmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); } int From fd13caf62e971d062b1660757df3f827be4b3369 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 14 Sep 2023 18:02:36 +0900 Subject: [PATCH 34/40] add a comment about getaddrinfo --- .../sandboxed-system-primitives/src/blocking_op.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index fab329ee01..684be3efb1 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -164,6 +164,14 @@ blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, bh_addr_info_t *addr_info, size_t addr_info_size, size_t *max_info_size) { + /* + * Note: Unlike others, os_socket_addr_resolve() is not a simple system + * call. It's likely backed by a complex libc function, getaddrinfo(). + * Depending on the implementation of getaddrinfo(), it might or + * might not be possible to make it return with os_wakeup_blocking_op(). + * Unfortunately, macOS getaddrinfo() doesn't seem return on + * interrupted system calls. + */ if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; return -1; From 5ac3cb578a4aeda835c59de66eef9d5544164d59 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 15 Sep 2023 12:00:09 +0900 Subject: [PATCH 35/40] comment --- .../sandboxed-system-primitives/src/blocking_op.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c index 684be3efb1..9d01f2bfeb 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -167,10 +167,15 @@ blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, /* * Note: Unlike others, os_socket_addr_resolve() is not a simple system * call. It's likely backed by a complex libc function, getaddrinfo(). - * Depending on the implementation of getaddrinfo(), it might or - * might not be possible to make it return with os_wakeup_blocking_op(). - * Unfortunately, macOS getaddrinfo() doesn't seem return on - * interrupted system calls. + * Depending on the implementation of getaddrinfo() and underlying + * DNS resolver, it might or might not be possible to make it return + * with os_wakeup_blocking_op(). + * + * Unfortunately, many of ISC/bind based resolvers just keep going on + * interrupted system calls. It includes macOS and glibc. + * + * On the other hand, NuttX as of writing this returns EAI_AGAIN + * on EINTR. */ if (!wasm_runtime_begin_blocking_op(exec_env)) { errno = EINTR; From 0daf3d7f3d0d063a4245133c3dc0c12ae2d8ae89 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Sep 2023 11:37:27 +0900 Subject: [PATCH 36/40] comments --- core/iwasm/include/wasm_export.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 9a67aca422..a0eff541b2 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1555,13 +1555,16 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key); * * eg. * - * if (!wasm_runtime_begin_blocking_op) { + * if (!wasm_runtime_begin_blocking_op(exec_env)) { * return EINTR; * } * ret = possibly_blocking_op(); - * wasm_runtime_end_blocking_op(env); + * wasm_runtime_end_blocking_op(exec_env); * return ret; * + * If threading support (WASM_ENABLE_THREAD_MGR) is not enabled, + * these functions are no-op. + * * If the underlying platform support (OS_ENABLE_WAKEUP_BLOCKING_OP) is * not available, these functions are no-op. In that case, the runtime * might not terminate a blocking thread in a timely manner. From b5399cd7dd17aaece5ffd8e8cd6201580e3c81b2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Sep 2023 11:38:28 +0900 Subject: [PATCH 37/40] comment --- core/iwasm/include/wasm_export.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index a0eff541b2..48ed55933c 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1580,7 +1580,7 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key); * * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is * used. The signal delivery configurations (eg. signal handler, signal mask, - * etc) for the signal is set up by the runtime. You can change the signal + * etc) for the signal are set up by the runtime. You can change the signal * to use for this purpose by calling os_set_signal_number_for_blocking_op * before the runtime initialization. */ From ecf798a2df59afeefadfe93ab842b0afee193af8 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Sep 2023 18:47:24 +0900 Subject: [PATCH 38/40] add a build-time config WAMR_DISABLE_WAKEUP_BLOCKING_OP --- build-scripts/config_common.cmake | 5 +++++ core/shared/platform/darwin/platform_internal.h | 2 ++ core/shared/platform/freebsd/platform_internal.h | 2 ++ core/shared/platform/linux/platform_internal.h | 2 ++ core/shared/platform/nuttx/platform_internal.h | 2 ++ doc/build_wamr.md | 4 ++++ product-mini/platforms/nuttx/wamr.mk | 3 +++ 7 files changed, 20 insertions(+) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 0e27e0c097..2054e154ec 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -273,6 +273,11 @@ else () add_definitions (-DWASM_DISABLE_STACK_HW_BOUND_CHECK=0) endif () endif () +if (WAMR_DISABLE_WAKEUP_BLOCKING_OP EQUAL 1) + add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=1) +else () + add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=0) +endif () if (WAMR_BUILD_SIMD EQUAL 1) if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*") add_definitions (-DWASM_ENABLE_SIMD=1) diff --git a/core/shared/platform/darwin/platform_internal.h b/core/shared/platform/darwin/platform_internal.h index 1055ba9711..5cd037a207 100644 --- a/core/shared/platform/darwin/platform_internal.h +++ b/core/shared/platform/darwin/platform_internal.h @@ -102,7 +102,9 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#if WASM_DISABLE_WAKEUP_BLOCKING_OP != 0 #define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif void os_set_signal_number_for_blocking_op(int signo); diff --git a/core/shared/platform/freebsd/platform_internal.h b/core/shared/platform/freebsd/platform_internal.h index 8bdb98942c..ed1d4efa4d 100644 --- a/core/shared/platform/freebsd/platform_internal.h +++ b/core/shared/platform/freebsd/platform_internal.h @@ -101,7 +101,9 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#if WASM_DISABLE_WAKEUP_BLOCKING_OP != 0 #define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif void os_set_signal_number_for_blocking_op(int signo); diff --git a/core/shared/platform/linux/platform_internal.h b/core/shared/platform/linux/platform_internal.h index 08cdb01073..222a6fc57f 100644 --- a/core/shared/platform/linux/platform_internal.h +++ b/core/shared/platform/linux/platform_internal.h @@ -115,7 +115,9 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#if WASM_DISABLE_WAKEUP_BLOCKING_OP != 0 #define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif void os_set_signal_number_for_blocking_op(int signo); diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index 5ae620955b..c53857e0f9 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -123,7 +123,9 @@ utimensat(int fd, const char *path, const struct timespec ts[2], int flag); DIR * fdopendir(int fd); +#if WASM_DISABLE_WAKEUP_BLOCKING_OP != 0 #define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif void os_set_signal_number_for_blocking_op(int signo); diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 81b4f6211b..9938eadcbe 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -109,6 +109,10 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM - **WAMR_DISABLE_STACK_HW_BOUND_CHECK**=1/0, default to enable if not set and supported by platform, same as `WAMR_DISABLE_HW_BOUND_CHECK`. > Note: When boundary check with hardware trap is disabled, or `WAMR_DISABLE_HW_BOUND_CHECK` is set to 1, the native stack boundary check with hardware trap will be disabled too, no matter what value is set to `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. And when boundary check with hardware trap is enabled, the status of this feature is set according to the value of `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. +#### **Disable async wakeup of blocking operation** +- **WAMR_DISABLE_WAKEUP_BLOCKING_OP**=1/0, default to enable if supported by the platform +> Note: The feature helps async termination of blocking threads. If you disable it, the runtime can wait for termination of blocking threads possibly forever. + #### **Enable tail call feature** - **WAMR_BUILD_TAIL_CALL**=1/0, default to disable if not set diff --git a/product-mini/platforms/nuttx/wamr.mk b/product-mini/platforms/nuttx/wamr.mk index 02cf81581e..04a6db91fd 100644 --- a/product-mini/platforms/nuttx/wamr.mk +++ b/product-mini/platforms/nuttx/wamr.mk @@ -310,6 +310,9 @@ CFLAGS += -DWASM_DISABLE_HW_BOUND_CHECK=0 CFLAGS += -DWASM_DISABLE_STACK_HW_BOUND_CHECK=0 endif +# REVISIT: is this worth to have a Kconfig? +CFLAGS += -DWASM_DISABLE_WAKEUP_BLOCKING_OP=0 + ifeq ($(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS),y) CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=1 else From 3be54a0e3994c221562f12ce8b3cefa7eaeab8a8 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Sep 2023 18:50:13 +0900 Subject: [PATCH 39/40] add messages --- build-scripts/config_common.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 2054e154ec..210f2d7887 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -275,8 +275,10 @@ else () endif () if (WAMR_DISABLE_WAKEUP_BLOCKING_OP EQUAL 1) add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=1) + message (" Wakeup of blocking operations disabled") else () add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=0) + message (" Wakeup of blocking operations enabled") endif () if (WAMR_BUILD_SIMD EQUAL 1) if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*") From 778d2b2982a12b010aa707f2cd503ff6cc0e0061 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 19 Sep 2023 21:09:29 +0900 Subject: [PATCH 40/40] add a missing unlock --- core/iwasm/common/wasm_blocking_op.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/iwasm/common/wasm_blocking_op.c b/core/iwasm/common/wasm_blocking_op.c index f45110a355..25777c8d74 100644 --- a/core/iwasm/common/wasm_blocking_op.c +++ b/core/iwasm/common/wasm_blocking_op.c @@ -74,6 +74,7 @@ wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) os_usleep(50 * 1000); LOCK(env); } + UNLOCK(env); } #else /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */