summaryrefslogtreecommitdiff
path: root/deps/uvwasi/src
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2020-03-15 09:46:17 -0400
committercjihrig <cjihrig@gmail.com>2020-03-18 20:47:28 -0400
commit543c046feb015c8290e2408d210916976126b24f (patch)
tree0f78124a098c2ee080feb7ecfca8e85514cb8688 /deps/uvwasi/src
parent6a349019da7ea79cd394101faad119db56b76bfa (diff)
downloadnode-new-543c046feb015c8290e2408d210916976126b24f.tar.gz
deps: update to uvwasi 0.0.6
PR-URL: https://github.com/nodejs/node/pull/32309 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/uvwasi/src')
-rw-r--r--deps/uvwasi/src/clocks.c1
-rw-r--r--deps/uvwasi/src/fd_table.c105
-rw-r--r--deps/uvwasi/src/uvwasi.c7
3 files changed, 69 insertions, 44 deletions
diff --git a/deps/uvwasi/src/clocks.c b/deps/uvwasi/src/clocks.c
index e1fbc696b6..fd42b9e50e 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 bc32f4dd28..f6e530d959 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 @@ exit:
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, "<stdin>");
+ if (err != UVWASI_ESUCCESS)
+ goto error_exit;
+
+ err = uvwasi__insert_stdio(uvwasi, table, options->out, 1, "<stdout>");
+ if (err != UVWASI_ESUCCESS)
+ goto error_exit;
+
+ err = uvwasi__insert_stdio(uvwasi, table, options->err, 2, "<stderr>");
+ 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 53b7699f59..c80fc7715c 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;