From 7904ecd245d2e00f2dc4ade2b64ca51a702df0d9 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 15 Mar 2020 09:46:17 -0400 Subject: [PATCH] deps: update to uvwasi 0.0.6 PR-URL: https://github.com/nodejs/node/pull/32309 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- deps/uvwasi/include/fd_table.h | 4 +- deps/uvwasi/include/uvwasi.h | 5 +- deps/uvwasi/src/clocks.c | 1 + deps/uvwasi/src/fd_table.c | 105 +++++++++++++++++++-------------- deps/uvwasi/src/uvwasi.c | 7 ++- src/node_wasi.cc | 3 + 6 files changed, 78 insertions(+), 47 deletions(-) diff --git a/deps/uvwasi/include/fd_table.h b/deps/uvwasi/include/fd_table.h index fa8a44e7468d41..f29b1adf88d6f0 100644 --- a/deps/uvwasi/include/fd_table.h +++ b/deps/uvwasi/include/fd_table.h @@ -6,6 +6,7 @@ #include "wasi_types.h" struct uvwasi_s; +struct uvwasi_options_s; struct uvwasi_fd_wrap_t { uvwasi_fd_t id; @@ -27,8 +28,7 @@ struct uvwasi_fd_table_t { }; uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi, - struct uvwasi_fd_table_t* table, - uint32_t init_size); + struct uvwasi_options_s* options); void uvwasi_fd_table_free(struct uvwasi_s* uvwasi, struct uvwasi_fd_table_t* table); uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi, diff --git a/deps/uvwasi/include/uvwasi.h b/deps/uvwasi/include/uvwasi.h index 9ca30459e23a73..39ee2f0ceb6609 100644 --- a/deps/uvwasi/include/uvwasi.h +++ b/deps/uvwasi/include/uvwasi.h @@ -11,7 +11,7 @@ extern "C" { #define UVWASI_VERSION_MAJOR 0 #define UVWASI_VERSION_MINOR 0 -#define UVWASI_VERSION_PATCH 5 +#define UVWASI_VERSION_PATCH 6 #define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \ (UVWASI_VERSION_MINOR << 8) | \ (UVWASI_VERSION_PATCH)) @@ -60,6 +60,9 @@ typedef struct uvwasi_options_s { size_t argc; char** argv; char** envp; + uvwasi_fd_t in; + uvwasi_fd_t out; + uvwasi_fd_t err; const uvwasi_mem_t* allocator; } uvwasi_options_t; diff --git a/deps/uvwasi/src/clocks.c b/deps/uvwasi/src/clocks.c index e1fbc696b62f05..fd42b9e50e4d8e 100644 --- a/deps/uvwasi/src/clocks.c +++ b/deps/uvwasi/src/clocks.c @@ -6,6 +6,7 @@ #endif /* _WIN32 */ #include "uv.h" +#include "clocks.h" #include "wasi_types.h" #include "uv_mapping.h" diff --git a/deps/uvwasi/src/fd_table.c b/deps/uvwasi/src/fd_table.c index bc32f4dd28bbce..f6e530d9591df2 100644 --- a/deps/uvwasi/src/fd_table.c +++ b/deps/uvwasi/src/fd_table.c @@ -14,6 +14,46 @@ #include "uvwasi_alloc.h" +static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi, + struct uvwasi_fd_table_t* table, + const uvwasi_fd_t fd, + const uvwasi_fd_t expected, + const char* name) { + struct uvwasi_fd_wrap_t* wrap; + uvwasi_filetype_t type; + uvwasi_rights_t base; + uvwasi_rights_t inheriting; + uvwasi_errno_t err; + + err = uvwasi__get_filetype_by_fd(fd, &type); + if (err != UVWASI_ESUCCESS) + return err; + + err = uvwasi__get_rights(fd, UV_FS_O_RDWR, type, &base, &inheriting); + if (err != UVWASI_ESUCCESS) + return err; + + err = uvwasi_fd_table_insert(uvwasi, + table, + fd, + name, + name, + type, + base, + inheriting, + 0, + &wrap); + if (err != UVWASI_ESUCCESS) + return err; + + if (wrap->id != expected) + err = UVWASI_EBADF; + + uv_mutex_unlock(&wrap->mutex); + return err; +} + + uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, struct uvwasi_fd_table_t* table, uv_file fd, @@ -28,7 +68,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, struct uvwasi_fd_wrap_t** new_fds; uvwasi_errno_t err; uint32_t new_size; - int index; + uint32_t index; uint32_t i; int r; size_t mp_len; @@ -69,16 +109,17 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, table->size = new_size; } else { /* The table is big enough, so find an empty slot for the new data. */ - index = -1; + int valid_slot = 0; for (i = 0; i < table->size; ++i) { if (table->fds[i] == NULL) { + valid_slot = 1; index = i; break; } } - /* index should never be -1. */ - if (index == -1) { + /* This should never happen. */ + if (valid_slot == 0) { uvwasi__free(uvwasi, entry); err = UVWASI_ENOSPC; goto exit; @@ -116,25 +157,21 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, - struct uvwasi_fd_table_t* table, - uint32_t init_size) { - struct uvwasi_fd_wrap_t* wrap; - uvwasi_filetype_t type; - uvwasi_rights_t base; - uvwasi_rights_t inheriting; + uvwasi_options_t* options) { + struct uvwasi_fd_table_t* table; uvwasi_errno_t err; - uvwasi_fd_t i; int r; /* Require an initial size of at least three to store the stdio FDs. */ - if (table == NULL || init_size < 3) + if (uvwasi == NULL || options == NULL || options->fd_table_size < 3) return UVWASI_EINVAL; + table = &uvwasi->fds; table->fds = NULL; table->used = 0; - table->size = init_size; + table->size = options->fd_table_size; table->fds = uvwasi__calloc(uvwasi, - init_size, + options->fd_table_size, sizeof(struct uvwasi_fd_wrap_t*)); if (table->fds == NULL) @@ -153,35 +190,17 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, } /* Create the stdio FDs. */ - for (i = 0; i < 3; ++i) { - err = uvwasi__get_filetype_by_fd(i, &type); - if (err != UVWASI_ESUCCESS) - goto error_exit; - - err = uvwasi__get_rights(i, UV_FS_O_RDWR, type, &base, &inheriting); - if (err != UVWASI_ESUCCESS) - goto error_exit; - - err = uvwasi_fd_table_insert(uvwasi, - table, - i, - "", - "", - type, - base, - inheriting, - 0, - &wrap); - if (err != UVWASI_ESUCCESS) - goto error_exit; - - r = wrap->id != i || wrap->id != (uvwasi_fd_t) wrap->fd; - uv_mutex_unlock(&wrap->mutex); - if (r) { - err = UVWASI_EBADF; - goto error_exit; - } - } + err = uvwasi__insert_stdio(uvwasi, table, options->in, 0, ""); + if (err != UVWASI_ESUCCESS) + goto error_exit; + + err = uvwasi__insert_stdio(uvwasi, table, options->out, 1, ""); + if (err != UVWASI_ESUCCESS) + goto error_exit; + + err = uvwasi__insert_stdio(uvwasi, table, options->err, 2, ""); + if (err != UVWASI_ESUCCESS) + goto error_exit; return UVWASI_ESUCCESS; error_exit: diff --git a/deps/uvwasi/src/uvwasi.c b/deps/uvwasi/src/uvwasi.c index 53b7699f590e53..c80fc7715c1dc0 100644 --- a/deps/uvwasi/src/uvwasi.c +++ b/deps/uvwasi/src/uvwasi.c @@ -34,6 +34,11 @@ # define PATH_MAX_BYTES (PATH_MAX) #endif +/* IBMi PASE does not support posix_fadvise() */ +#ifdef __PASE__ +# undef POSIX_FADV_NORMAL +#endif + static void* default_malloc(size_t size, void* mem_user_data) { return malloc(size); } @@ -569,7 +574,7 @@ uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options) { } } - err = uvwasi_fd_table_init(uvwasi, &uvwasi->fds, options->fd_table_size); + err = uvwasi_fd_table_init(uvwasi, options); if (err != UVWASI_ESUCCESS) goto exit; diff --git a/src/node_wasi.cc b/src/node_wasi.cc index ed8f6c4fa4cb67..f4670ea36f6525 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -170,6 +170,9 @@ void WASI::New(const FunctionCallbackInfo& args) { const uint32_t argc = argv->Length(); uvwasi_options_t options; + options.in = 0; + options.out = 1; + options.err = 2; options.fd_table_size = 3; options.argc = argc; options.argv = argc == 0 ? nullptr : new char*[argc];