mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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>
This commit is contained in:
1 parent
dedd219622
commit
7904ecd245
6 files changed
+76
-45
No files matched your search
Vendored
+2
-2
@@ -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,
|
||||
|
||||
Vendored
+4
-1
@@ -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;
|
||||
|
||||
|
||||
Vendored
+1
@@ -6,6 +6,7 @@
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "uv.h"
|
||||
#include "clocks.h"
|
||||
#include "wasi_types.h"
|
||||
#include "uv_mapping.h"
|
||||
|
||||
|
||||
Vendored
+60
-41
@@ -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__insert_stdio(uvwasi, table, options->in, 0, "<stdin>");
|
||||
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__insert_stdio(uvwasi, table, options->out, 1, "<stdout>");
|
||||
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->err, 2, "<stderr>");
|
||||
if (err != UVWASI_ESUCCESS)
|
||||
goto error_exit;
|
||||
|
||||
return UVWASI_ESUCCESS;
|
||||
error_exit:
|
||||
|
||||
Vendored
+6
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -170,6 +170,9 @@ void WASI::New(const FunctionCallbackInfo<Value>& 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];
|
||||
|
||||
Reference in new issue
Block a user