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);
|
||||
|
||||
Reference in New Issue
Block a user