Merge pull request #2740 from bytecodealliance/dev/wasi-libc-windows
The implementation is already in a stage where it's possible to compile WAMR with wasi libc enabled and run wasi modules without errors.
This commit is contained in:
@ -388,6 +388,18 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
|
||||
{
|
||||
float32 f32 = strtof(argv[i], &endptr);
|
||||
if (isnan(f32)) {
|
||||
#ifdef _MSC_VER
|
||||
/*
|
||||
* Spec tests require the binary representation of NaN to be
|
||||
* 0x7fc00000 for float and 0x7ff8000000000000 for float;
|
||||
* however, in MSVC compiler, strtof doesn't return this
|
||||
* exact value, causing some of the spec test failures. We
|
||||
* use the value returned by nan/nanf as it is the one
|
||||
* expected by spec tests.
|
||||
*
|
||||
*/
|
||||
f32 = nanf("");
|
||||
#endif
|
||||
if (argv[i][0] == '-') {
|
||||
union ieee754_float u;
|
||||
u.f = f32;
|
||||
@ -422,6 +434,9 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
|
||||
} u;
|
||||
u.val = strtod(argv[i], &endptr);
|
||||
if (isnan(u.val)) {
|
||||
#ifdef _MSC_VER
|
||||
u.val = nan("");
|
||||
#endif
|
||||
if (argv[i][0] == '-') {
|
||||
union ieee754_double ud;
|
||||
ud.d = u.val;
|
||||
@ -585,7 +600,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
|
||||
{
|
||||
#if UINTPTR_MAX == UINT32_MAX
|
||||
if (argv1[k] != 0 && argv1[k] != (uint32)-1)
|
||||
os_printf("%p:ref.extern", (void *)argv1[k]);
|
||||
os_printf("0x%" PRIxPTR ":ref.extern", (void *)argv1[k]);
|
||||
else
|
||||
os_printf("extern:ref.null");
|
||||
k++;
|
||||
@ -598,7 +613,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
|
||||
u.parts[1] = argv1[k + 1];
|
||||
k += 2;
|
||||
if (u.val && u.val != (uintptr_t)-1LL)
|
||||
os_printf("%p:ref.extern", (void *)u.val);
|
||||
os_printf("0x%" PRIxPTR ":ref.extern", (void *)u.val);
|
||||
else
|
||||
os_printf("extern:ref.null");
|
||||
#endif
|
||||
|
||||
@ -2778,7 +2778,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
|
||||
uint32 dir_count, const char *map_dir_list[],
|
||||
uint32 map_dir_count, const char *env_list[],
|
||||
uint32 env_count, char *argv[], int argc,
|
||||
int stdinfd, int stdoutfd, int stderrfd)
|
||||
int64 stdinfd, int64 stdoutfd, int64 stderrfd)
|
||||
{
|
||||
WASIArguments *wasi_args = get_wasi_args_from_module(module);
|
||||
|
||||
@ -2792,9 +2792,9 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
|
||||
wasi_args->env_count = env_count;
|
||||
wasi_args->argv = argv;
|
||||
wasi_args->argc = (uint32)argc;
|
||||
wasi_args->stdio[0] = stdinfd;
|
||||
wasi_args->stdio[1] = stdoutfd;
|
||||
wasi_args->stdio[2] = stderrfd;
|
||||
wasi_args->stdio[0] = (os_raw_file_handle)stdinfd;
|
||||
wasi_args->stdio[1] = (os_raw_file_handle)stdoutfd;
|
||||
wasi_args->stdio[2] = (os_raw_file_handle)stderrfd;
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
@ -2889,8 +2889,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *addr_pool[], uint32 addr_pool_size,
|
||||
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
|
||||
char *argv[], uint32 argc, int stdinfd, int stdoutfd,
|
||||
int stderrfd, char *error_buf, uint32 error_buf_size)
|
||||
char *argv[], uint32 argc, os_raw_file_handle stdinfd,
|
||||
os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
WASIContext *wasi_ctx;
|
||||
char *argv_buf = NULL;
|
||||
@ -2908,7 +2909,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
bool argv_environ_inited = false;
|
||||
bool addr_pool_inited = false;
|
||||
__wasi_fd_t wasm_fd = 3;
|
||||
int32 raw_fd;
|
||||
os_file_handle file_handle;
|
||||
char *path, resolved_path[PATH_MAX];
|
||||
uint32 i;
|
||||
|
||||
@ -2978,15 +2979,19 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
}
|
||||
addr_pool_inited = true;
|
||||
|
||||
/* Prepopulate curfds with stdin, stdout, and stderr file descriptors.
|
||||
*
|
||||
* If -1 is given, use STDIN_FILENO (0), STDOUT_FILENO (1),
|
||||
* STDERR_FILENO (2) respectively.
|
||||
*/
|
||||
if (!fd_table_insert_existing(curfds, 0, (stdinfd != -1) ? stdinfd : 0)
|
||||
|| !fd_table_insert_existing(curfds, 1, (stdoutfd != -1) ? stdoutfd : 1)
|
||||
|| !fd_table_insert_existing(curfds, 2,
|
||||
(stderrfd != -1) ? stderrfd : 2)) {
|
||||
os_file_handle stdin_file_handle = os_convert_stdin_handle(stdinfd);
|
||||
os_file_handle stdout_file_handle = os_convert_stdout_handle(stdoutfd);
|
||||
os_file_handle stderr_file_handle = os_convert_stderr_handle(stderrfd);
|
||||
|
||||
if (!os_is_handle_valid(&stdin_file_handle)
|
||||
|| !os_is_handle_valid(&stdout_file_handle)
|
||||
|| !os_is_handle_valid(&stderr_file_handle))
|
||||
goto fail;
|
||||
|
||||
/* Prepopulate curfds with stdin, stdout, and stderr file descriptors. */
|
||||
if (!fd_table_insert_existing(curfds, 0, stdin_file_handle, true)
|
||||
|| !fd_table_insert_existing(curfds, 1, stdout_file_handle, true)
|
||||
|| !fd_table_insert_existing(curfds, 2, stderr_file_handle, true)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Init wasi environment failed: init fd table failed");
|
||||
goto fail;
|
||||
@ -2994,7 +2999,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
|
||||
wasm_fd = 3;
|
||||
for (i = 0; i < dir_count; i++, wasm_fd++) {
|
||||
path = realpath(dir_list[i], resolved_path);
|
||||
path = os_realpath(dir_list[i], resolved_path);
|
||||
if (!path) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
@ -3003,22 +3008,31 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
raw_fd = open(path, O_RDONLY | O_DIRECTORY, 0);
|
||||
if (raw_fd == -1) {
|
||||
__wasi_errno_t error = os_open_preopendir(path, &file_handle);
|
||||
|
||||
if (error != __WASI_ESUCCESS) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error while pre-opening directory %s: %d\n",
|
||||
dir_list[i], errno);
|
||||
dir_list[i], error);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!fd_table_insert_existing(curfds, wasm_fd, raw_fd)
|
||||
|| !fd_prestats_insert(prestats, dir_list[i], wasm_fd)) {
|
||||
if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false)) {
|
||||
if (error_buf)
|
||||
snprintf(
|
||||
error_buf, error_buf_size,
|
||||
"error while pre-opening directory %s: insertion failed\n",
|
||||
dir_list[i]);
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error inserting preopen fd %u (directory %s) into fd "
|
||||
"table",
|
||||
(unsigned int)wasm_fd, dir_list[i]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!fd_prestats_insert(prestats, dir_list[i], wasm_fd)) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error inserting preopen fd %u (directory %s) into "
|
||||
"prestats table",
|
||||
(unsigned int)wasm_fd, dir_list[i]);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@ -3053,7 +3067,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
path = realpath(map_host, resolved_path);
|
||||
path = os_realpath(map_host, resolved_path);
|
||||
if (!path) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
@ -3064,8 +3078,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
raw_fd = open(path, O_RDONLY | O_DIRECTORY, 0);
|
||||
if (raw_fd == -1) {
|
||||
__wasi_errno_t error = os_open_preopendir(path, &file_handle);
|
||||
if (error != __WASI_ESUCCESS) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"error while pre-opening mapped directory %s: %d\n",
|
||||
@ -3075,7 +3089,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!fd_table_insert_existing(curfds, wasm_fd, raw_fd)
|
||||
if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false)
|
||||
|| !fd_prestats_insert(prestats, map_mapped, wasm_fd)) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
@ -3216,8 +3230,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *addr_pool[], uint32 addr_pool_size,
|
||||
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
|
||||
char *argv[], uint32 argc, int stdinfd, int stdoutfd,
|
||||
int stderrfd, char *error_buf, uint32 error_buf_size)
|
||||
char *argv[], uint32 argc, os_raw_file_handle stdinfd,
|
||||
os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
WASIContext *ctx;
|
||||
uvwasi_t *uvwasi;
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
#if WASM_ENABLE_UVWASI == 0
|
||||
#include "wasmtime_ssp.h"
|
||||
#include "posix.h"
|
||||
#else
|
||||
#include "uvwasi.h"
|
||||
@ -863,7 +862,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
|
||||
uint32 dir_count, const char *map_dir_list[],
|
||||
uint32 map_dir_count, const char *env_list[],
|
||||
uint32 env_count, char *argv[], int argc,
|
||||
int stdinfd, int stdoutfd, int stderrfd);
|
||||
int64 stdinfd, int64 stdoutfd, int64 stderrfd);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
@ -891,8 +890,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *addr_pool[], uint32 addr_pool_size,
|
||||
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
|
||||
char *argv[], uint32 argc, int stdinfd, int stdoutfd,
|
||||
int stderrfd, char *error_buf, uint32 error_buf_size);
|
||||
char *argv[], uint32 argc, os_raw_file_handle stdinfd,
|
||||
os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
|
||||
void
|
||||
wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst);
|
||||
|
||||
@ -432,26 +432,31 @@ wasm_runtime_get_module_hash(wasm_module_t module);
|
||||
* @param env_count The number of elements in env.
|
||||
* @param argv The list of command line arguments.
|
||||
* @param argc The number of elements in argv.
|
||||
* @param stdinfd The host file descriptor to back WASI STDIN_FILENO.
|
||||
* If -1 is specified, STDIN_FILENO is used.
|
||||
* @param stdoutfd The host file descriptor to back WASI STDOUT_FILENO.
|
||||
* If -1 is specified, STDOUT_FILENO is used.
|
||||
* @param stderrfd The host file descriptor to back WASI STDERR_FILENO.
|
||||
* If -1 is specified, STDERR_FILENO is used.
|
||||
* @param stdin_handle The raw host handle to back WASI STDIN_FILENO.
|
||||
* If an invalid handle is specified (e.g. -1 on POSIX,
|
||||
* INVALID_HANDLE_VALUE on Windows), the platform default
|
||||
* for STDIN is used.
|
||||
* @param stdoutfd The raw host handle to back WASI STDOUT_FILENO.
|
||||
* If an invalid handle is specified (e.g. -1 on POSIX,
|
||||
* INVALID_HANDLE_VALUE on Windows), the platform default
|
||||
* for STDOUT is used.
|
||||
* @param stderrfd The raw host handle to back WASI STDERR_FILENO.
|
||||
* If an invalid handle is specified (e.g. -1 on POSIX,
|
||||
* INVALID_HANDLE_VALUE on Windows), the platform default
|
||||
* for STDERR is used.
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_set_wasi_args_ex(wasm_module_t module,
|
||||
const char *dir_list[], uint32_t dir_count,
|
||||
const char *map_dir_list[], uint32_t map_dir_count,
|
||||
const char *env[], uint32_t env_count,
|
||||
char *argv[], int argc,
|
||||
int stdinfd, int stdoutfd, int stderrfd);
|
||||
char *argv[], int argc, int64_t stdinfd,
|
||||
int64_t stdoutfd, int64_t stderrfd);
|
||||
|
||||
/**
|
||||
* Set WASI parameters.
|
||||
*
|
||||
* Same as wasm_runtime_set_wasi_args_ex with stdinfd = -1, stdoutfd = -1,
|
||||
* stderrfd = -1.
|
||||
* Same as wasm_runtime_set_wasi_args_ex but with default stdio handles
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_set_wasi_args(wasm_module_t module,
|
||||
|
||||
@ -350,7 +350,7 @@ typedef struct WASIArguments {
|
||||
uint32 ns_lookup_count;
|
||||
char **argv;
|
||||
uint32 argc;
|
||||
int stdio[3];
|
||||
os_raw_file_handle stdio[3];
|
||||
} WASIArguments;
|
||||
#endif
|
||||
|
||||
|
||||
@ -330,8 +330,9 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
|
||||
}
|
||||
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
if (!os_mem_commit(mapped_mem, memory_data_size,
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
|
||||
if (memory_data_size > 0
|
||||
&& !os_mem_commit(mapped_mem, memory_data_size,
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
|
||||
set_error_buf(error_buf, error_buf_size, "commit memory failed");
|
||||
os_munmap(mapped_mem, map_size);
|
||||
goto fail1;
|
||||
|
||||
3
core/iwasm/libraries/lib-socket/test/manifest.json
Normal file
3
core/iwasm/libraries/lib-socket/test/manifest.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "WAMR lib-socket tests"
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
#include "wasm_runtime_common.h"
|
||||
#include "wasmtime_ssp.h"
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
#include "../../../thread-mgr/thread_manager.h"
|
||||
@ -192,7 +193,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_clock_res_get(clock_id, resolution);
|
||||
return os_clock_res_get(clock_id, resolution);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
@ -206,7 +207,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_clock_time_get(clock_id, precision, time);
|
||||
return os_clock_time_get(clock_id, precision, time);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#ifndef _LIBC_WASI_WRAPPER_H
|
||||
#define _LIBC_WASI_WRAPPER_H
|
||||
|
||||
#include "wasmtime_ssp.h"
|
||||
#include "posix.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -8,99 +8,68 @@
|
||||
#include "ssp_config.h"
|
||||
#include "blocking_op.h"
|
||||
|
||||
int
|
||||
blocking_op_close(wasm_exec_env_t exec_env, int fd)
|
||||
__wasi_errno_t
|
||||
blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
bool is_stdio)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
int ret = close(fd);
|
||||
__wasi_errno_t error = os_close(handle, is_stdio);
|
||||
wasm_runtime_end_blocking_op(exec_env);
|
||||
return error;
|
||||
}
|
||||
|
||||
__wasi_errno_t
|
||||
blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
__wasi_errno_t error = os_readv(handle, iov, iovcnt, nread);
|
||||
wasm_runtime_end_blocking_op(exec_env);
|
||||
return error;
|
||||
}
|
||||
|
||||
__wasi_errno_t
|
||||
blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_iovec_t *iov, int iovcnt,
|
||||
__wasi_filesize_t offset, size_t *nread)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
__wasi_errno_t ret = os_preadv(handle, iov, iovcnt, offset, nread);
|
||||
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)
|
||||
__wasi_errno_t
|
||||
blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_ciovec_t *iov, int iovcnt,
|
||||
size_t *nwritten)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
ssize_t ret = readv(fd, iov, iovcnt);
|
||||
__wasi_errno_t error = os_writev(handle, iov, iovcnt, nwritten);
|
||||
wasm_runtime_end_blocking_op(exec_env);
|
||||
return ret;
|
||||
return error;
|
||||
}
|
||||
|
||||
#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)
|
||||
__wasi_errno_t
|
||||
blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_ciovec_t *iov, int iovcnt,
|
||||
__wasi_filesize_t offset, size_t *nwritten)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
ssize_t ret = preadv(fd, iov, iovcnt, offset);
|
||||
__wasi_errno_t error = os_pwritev(handle, iov, iovcnt, offset, nwritten);
|
||||
wasm_runtime_end_blocking_op(exec_env);
|
||||
return ret;
|
||||
return error;
|
||||
}
|
||||
#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 */
|
||||
|
||||
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_PWRITEV */
|
||||
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_PWRITEV */
|
||||
|
||||
int
|
||||
blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
|
||||
@ -187,15 +156,17 @@ blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
blocking_op_openat(wasm_exec_env_t exec_env, int fd, const char *path,
|
||||
int oflags, mode_t mode)
|
||||
__wasi_errno_t
|
||||
blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const char *path, __wasi_oflags_t oflags,
|
||||
__wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
|
||||
wasi_libc_file_access_mode access_mode, os_file_handle *out)
|
||||
{
|
||||
if (!wasm_runtime_begin_blocking_op(exec_env)) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
return __WASI_EINTR;
|
||||
}
|
||||
int ret = openat(fd, path, oflags, mode);
|
||||
__wasi_errno_t error = os_openat(handle, path, oflags, fd_flags,
|
||||
lookup_flags, access_mode, out);
|
||||
wasm_runtime_end_blocking_op(exec_env);
|
||||
return ret;
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -6,26 +6,24 @@
|
||||
#include "bh_platform.h"
|
||||
#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);
|
||||
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);
|
||||
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);
|
||||
__wasi_errno_t
|
||||
blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
bool is_stdio);
|
||||
__wasi_errno_t
|
||||
blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread);
|
||||
__wasi_errno_t
|
||||
blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_iovec_t *iov, int iovcnt,
|
||||
__wasi_filesize_t offset, size_t *nread);
|
||||
__wasi_errno_t
|
||||
blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_ciovec_t *iov, int iovcnt,
|
||||
size_t *nwritten);
|
||||
__wasi_errno_t
|
||||
blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const struct __wasi_ciovec_t *iov, int iovcnt,
|
||||
__wasi_filesize_t offset, size_t *nwritten);
|
||||
int
|
||||
blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
|
||||
bh_socket_t *sockp, void *addr,
|
||||
@ -47,6 +45,9 @@ 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);
|
||||
|
||||
__wasi_errno_t
|
||||
blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
|
||||
const char *path, __wasi_oflags_t oflags,
|
||||
__wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
|
||||
wasi_libc_file_access_mode access_mode, os_file_handle *out);
|
||||
@ -49,7 +49,7 @@
|
||||
/* Mutex that uses the lock annotations. */
|
||||
|
||||
struct LOCKABLE mutex {
|
||||
pthread_mutex_t object;
|
||||
korp_mutex object;
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
@ -60,69 +60,71 @@ struct LOCKABLE mutex {
|
||||
static inline bool
|
||||
mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
|
||||
{
|
||||
return pthread_mutex_init(&lock->object, NULL) == 0 ? true : false;
|
||||
return os_mutex_init(&lock->object) == BHT_OK ? true : false;
|
||||
}
|
||||
|
||||
static inline void
|
||||
mutex_destroy(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
|
||||
{
|
||||
pthread_mutex_destroy(&lock->object);
|
||||
os_mutex_destroy(&lock->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
mutex_lock(struct mutex *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_mutex_lock(&lock->object);
|
||||
os_mutex_lock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
mutex_unlock(struct mutex *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_mutex_unlock(&lock->object);
|
||||
os_mutex_unlock(&lock->object);
|
||||
}
|
||||
|
||||
/* Read-write lock that uses the lock annotations. */
|
||||
|
||||
struct LOCKABLE rwlock {
|
||||
pthread_rwlock_t object;
|
||||
korp_rwlock object;
|
||||
};
|
||||
|
||||
static inline bool
|
||||
rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock)
|
||||
{
|
||||
return pthread_rwlock_init(&lock->object, NULL) == 0 ? true : false;
|
||||
return os_rwlock_init(&lock->object) == 0 ? true : false;
|
||||
}
|
||||
|
||||
static inline void
|
||||
rwlock_rdlock(struct rwlock *lock) LOCKS_SHARED(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_rwlock_rdlock(&lock->object);
|
||||
os_rwlock_rdlock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
rwlock_wrlock(struct rwlock *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_rwlock_wrlock(&lock->object);
|
||||
os_rwlock_wrlock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
rwlock_unlock(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_rwlock_unlock(&lock->object);
|
||||
os_rwlock_unlock(&lock->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
rwlock_destroy(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_rwlock_destroy(&lock->object);
|
||||
os_rwlock_destroy(&lock->object);
|
||||
}
|
||||
|
||||
/* Condition variable that uses the lock annotations. */
|
||||
|
||||
struct LOCKABLE cond {
|
||||
pthread_cond_t object;
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
korp_cond object;
|
||||
|
||||
#if !CONFIG_HAS_CLOCK_NANOSLEEP \
|
||||
&& (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
|
||||
clockid_t clock;
|
||||
#endif
|
||||
};
|
||||
@ -147,43 +149,49 @@ cond_init_monotonic(struct cond *cond)
|
||||
fail:
|
||||
pthread_condattr_destroy(&attr);
|
||||
#else
|
||||
if (pthread_cond_init(&cond->object, NULL) != 0)
|
||||
if (os_cond_init(&cond->object) != 0)
|
||||
return false;
|
||||
ret = true;
|
||||
#endif
|
||||
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
#if !CONFIG_HAS_CLOCK_NANOSLEEP \
|
||||
&& (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
|
||||
cond->clock = CLOCK_MONOTONIC;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
cond_init_realtime(struct cond *cond)
|
||||
{
|
||||
if (pthread_cond_init(&cond->object, NULL) != 0)
|
||||
if (os_cond_init(&cond->object) != 0)
|
||||
return false;
|
||||
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
|
||||
#if !CONFIG_HAS_CLOCK_NANOSLEEP \
|
||||
&& (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|
||||
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
|
||||
cond->clock = CLOCK_REALTIME;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void
|
||||
cond_destroy(struct cond *cond)
|
||||
{
|
||||
pthread_cond_destroy(&cond->object);
|
||||
os_cond_destroy(&cond->object);
|
||||
}
|
||||
|
||||
static inline void
|
||||
cond_signal(struct cond *cond)
|
||||
{
|
||||
pthread_cond_signal(&cond->object);
|
||||
os_cond_signal(&cond->object);
|
||||
}
|
||||
|
||||
#if !CONFIG_HAS_CLOCK_NANOSLEEP
|
||||
|
||||
static inline bool
|
||||
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
||||
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
@ -259,7 +267,7 @@ static inline void
|
||||
cond_wait(struct cond *cond, struct mutex *lock)
|
||||
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
pthread_cond_wait(&cond->object, &lock->object);
|
||||
os_cond_wait(&cond->object, &lock->object);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -60,7 +60,8 @@ struct addr_pool {
|
||||
bool
|
||||
fd_table_init(struct fd_table *);
|
||||
bool
|
||||
fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
|
||||
fd_table_insert_existing(struct fd_table *, __wasi_fd_t, os_file_handle,
|
||||
bool is_stdio);
|
||||
bool
|
||||
fd_prestats_init(struct fd_prestats *);
|
||||
bool
|
||||
|
||||
@ -47,6 +47,23 @@ random_buf(void *buf, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(BH_PLATFORM_WINDOWS)
|
||||
|
||||
#include <wincrypt.h>
|
||||
|
||||
void
|
||||
random_buf(void *buf, size_t len)
|
||||
{
|
||||
static int crypt_initialized = 0;
|
||||
static HCRYPTPROV provider;
|
||||
if (!crypt_initialized) {
|
||||
CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT);
|
||||
crypt_initialized = 1;
|
||||
}
|
||||
CryptGenRandom(provider, len, buf);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int urandom;
|
||||
|
||||
@ -47,75 +47,19 @@
|
||||
#define CONFIG_HAS_CLOCK_NANOSLEEP 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(ESP_PLATFORM)
|
||||
#define CONFIG_HAS_FDATASYNC 1
|
||||
#else
|
||||
#define CONFIG_HAS_FDATASYNC 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For NuttX, CONFIG_HAS_ISATTY is provided by its platform header.
|
||||
* (platform_internal.h)
|
||||
*/
|
||||
#ifndef __NuttX__
|
||||
#ifndef __CloudABI__
|
||||
#define CONFIG_HAS_ISATTY 1
|
||||
#else
|
||||
#define CONFIG_HAS_ISATTY 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(__COSMOPOLITAN__)
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 1
|
||||
#else
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
|
||||
#define CONFIG_HAS_PREADV 1
|
||||
#else
|
||||
#define CONFIG_HAS_PREADV 0
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(__CloudABI__)
|
||||
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1
|
||||
#else
|
||||
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) \
|
||||
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32) \
|
||||
&& !defined(__COSMOPOLITAN__)
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
|
||||
#else
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
|
||||
#define CONFIG_HAS_PWRITEV 1
|
||||
#else
|
||||
#define CONFIG_HAS_PWRITEV 0
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define st_atim st_atimespec
|
||||
#define st_ctim st_ctimespec
|
||||
#define st_mtim st_mtimespec
|
||||
#endif
|
||||
|
||||
#if defined(O_DSYNC)
|
||||
#define CONFIG_HAS_O_DSYNC
|
||||
#endif
|
||||
|
||||
// POSIX requires O_RSYNC to be defined, but Linux explicitly doesn't support
|
||||
// it.
|
||||
#if defined(O_RSYNC) && !defined(__linux__)
|
||||
#define CONFIG_HAS_O_RSYNC
|
||||
#endif
|
||||
|
||||
#if defined(O_SYNC)
|
||||
#define CONFIG_HAS_O_SYNC
|
||||
#endif
|
||||
|
||||
#if !defined(BH_PLATFORM_LINUX_SGX)
|
||||
/* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
|
||||
so we have to handle this case specially */
|
||||
@ -143,10 +87,4 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
|
||||
#define CONFIG_HAS_STD_ATOMIC 0
|
||||
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
|
||||
|
||||
#if !defined(__NuttX__)
|
||||
#define CONFIG_HAS_D_INO 1
|
||||
#else
|
||||
#define CONFIG_HAS_D_INO 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user