Skip to content

Commit fe0e1db

Browse files
cjihrigtargos
authored andcommitted
deps: update to uvwasi 0.0.6
PR-URL: #32309 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent baf56f8 commit fe0e1db

File tree

6 files changed

+78
-47
lines changed

6 files changed

+78
-47
lines changed

deps/uvwasi/include/fd_table.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "wasi_types.h"
77

88
struct uvwasi_s;
9+
struct uvwasi_options_s;
910

1011
struct uvwasi_fd_wrap_t {
1112
uvwasi_fd_t id;
@@ -27,8 +28,7 @@ struct uvwasi_fd_table_t {
2728
};
2829

2930
uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_s* uvwasi,
30-
struct uvwasi_fd_table_t* table,
31-
uint32_t init_size);
31+
struct uvwasi_options_s* options);
3232
void uvwasi_fd_table_free(struct uvwasi_s* uvwasi,
3333
struct uvwasi_fd_table_t* table);
3434
uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi,

deps/uvwasi/include/uvwasi.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111

1212
#define UVWASI_VERSION_MAJOR 0
1313
#define UVWASI_VERSION_MINOR 0
14-
#define UVWASI_VERSION_PATCH 5
14+
#define UVWASI_VERSION_PATCH 6
1515
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
1616
(UVWASI_VERSION_MINOR << 8) | \
1717
(UVWASI_VERSION_PATCH))
@@ -60,6 +60,9 @@ typedef struct uvwasi_options_s {
6060
size_t argc;
6161
char** argv;
6262
char** envp;
63+
uvwasi_fd_t in;
64+
uvwasi_fd_t out;
65+
uvwasi_fd_t err;
6366
const uvwasi_mem_t* allocator;
6467
} uvwasi_options_t;
6568

deps/uvwasi/src/clocks.c

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#endif /* _WIN32 */
77

88
#include "uv.h"
9+
#include "clocks.h"
910
#include "wasi_types.h"
1011
#include "uv_mapping.h"
1112

deps/uvwasi/src/fd_table.c

+62-43
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,46 @@
1414
#include "uvwasi_alloc.h"
1515

1616

17+
static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
18+
struct uvwasi_fd_table_t* table,
19+
const uvwasi_fd_t fd,
20+
const uvwasi_fd_t expected,
21+
const char* name) {
22+
struct uvwasi_fd_wrap_t* wrap;
23+
uvwasi_filetype_t type;
24+
uvwasi_rights_t base;
25+
uvwasi_rights_t inheriting;
26+
uvwasi_errno_t err;
27+
28+
err = uvwasi__get_filetype_by_fd(fd, &type);
29+
if (err != UVWASI_ESUCCESS)
30+
return err;
31+
32+
err = uvwasi__get_rights(fd, UV_FS_O_RDWR, type, &base, &inheriting);
33+
if (err != UVWASI_ESUCCESS)
34+
return err;
35+
36+
err = uvwasi_fd_table_insert(uvwasi,
37+
table,
38+
fd,
39+
name,
40+
name,
41+
type,
42+
base,
43+
inheriting,
44+
0,
45+
&wrap);
46+
if (err != UVWASI_ESUCCESS)
47+
return err;
48+
49+
if (wrap->id != expected)
50+
err = UVWASI_EBADF;
51+
52+
uv_mutex_unlock(&wrap->mutex);
53+
return err;
54+
}
55+
56+
1757
uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
1858
struct uvwasi_fd_table_t* table,
1959
uv_file fd,
@@ -28,7 +68,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
2868
struct uvwasi_fd_wrap_t** new_fds;
2969
uvwasi_errno_t err;
3070
uint32_t new_size;
31-
int index;
71+
uint32_t index;
3272
uint32_t i;
3373
int r;
3474
size_t mp_len;
@@ -69,16 +109,17 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
69109
table->size = new_size;
70110
} else {
71111
/* The table is big enough, so find an empty slot for the new data. */
72-
index = -1;
112+
int valid_slot = 0;
73113
for (i = 0; i < table->size; ++i) {
74114
if (table->fds[i] == NULL) {
115+
valid_slot = 1;
75116
index = i;
76117
break;
77118
}
78119
}
79120

80-
/* index should never be -1. */
81-
if (index == -1) {
121+
/* This should never happen. */
122+
if (valid_slot == 0) {
82123
uvwasi__free(uvwasi, entry);
83124
err = UVWASI_ENOSPC;
84125
goto exit;
@@ -116,25 +157,21 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
116157

117158

118159
uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi,
119-
struct uvwasi_fd_table_t* table,
120-
uint32_t init_size) {
121-
struct uvwasi_fd_wrap_t* wrap;
122-
uvwasi_filetype_t type;
123-
uvwasi_rights_t base;
124-
uvwasi_rights_t inheriting;
160+
uvwasi_options_t* options) {
161+
struct uvwasi_fd_table_t* table;
125162
uvwasi_errno_t err;
126-
uvwasi_fd_t i;
127163
int r;
128164

129165
/* Require an initial size of at least three to store the stdio FDs. */
130-
if (table == NULL || init_size < 3)
166+
if (uvwasi == NULL || options == NULL || options->fd_table_size < 3)
131167
return UVWASI_EINVAL;
132168

169+
table = &uvwasi->fds;
133170
table->fds = NULL;
134171
table->used = 0;
135-
table->size = init_size;
172+
table->size = options->fd_table_size;
136173
table->fds = uvwasi__calloc(uvwasi,
137-
init_size,
174+
options->fd_table_size,
138175
sizeof(struct uvwasi_fd_wrap_t*));
139176

140177
if (table->fds == NULL)
@@ -153,35 +190,17 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi,
153190
}
154191

155192
/* Create the stdio FDs. */
156-
for (i = 0; i < 3; ++i) {
157-
err = uvwasi__get_filetype_by_fd(i, &type);
158-
if (err != UVWASI_ESUCCESS)
159-
goto error_exit;
160-
161-
err = uvwasi__get_rights(i, UV_FS_O_RDWR, type, &base, &inheriting);
162-
if (err != UVWASI_ESUCCESS)
163-
goto error_exit;
164-
165-
err = uvwasi_fd_table_insert(uvwasi,
166-
table,
167-
i,
168-
"",
169-
"",
170-
type,
171-
base,
172-
inheriting,
173-
0,
174-
&wrap);
175-
if (err != UVWASI_ESUCCESS)
176-
goto error_exit;
177-
178-
r = wrap->id != i || wrap->id != (uvwasi_fd_t) wrap->fd;
179-
uv_mutex_unlock(&wrap->mutex);
180-
if (r) {
181-
err = UVWASI_EBADF;
182-
goto error_exit;
183-
}
184-
}
193+
err = uvwasi__insert_stdio(uvwasi, table, options->in, 0, "<stdin>");
194+
if (err != UVWASI_ESUCCESS)
195+
goto error_exit;
196+
197+
err = uvwasi__insert_stdio(uvwasi, table, options->out, 1, "<stdout>");
198+
if (err != UVWASI_ESUCCESS)
199+
goto error_exit;
200+
201+
err = uvwasi__insert_stdio(uvwasi, table, options->err, 2, "<stderr>");
202+
if (err != UVWASI_ESUCCESS)
203+
goto error_exit;
185204

186205
return UVWASI_ESUCCESS;
187206
error_exit:

deps/uvwasi/src/uvwasi.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
# define PATH_MAX_BYTES (PATH_MAX)
3535
#endif
3636

37+
/* IBMi PASE does not support posix_fadvise() */
38+
#ifdef __PASE__
39+
# undef POSIX_FADV_NORMAL
40+
#endif
41+
3742
static void* default_malloc(size_t size, void* mem_user_data) {
3843
return malloc(size);
3944
}
@@ -569,7 +574,7 @@ uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options) {
569574
}
570575
}
571576

572-
err = uvwasi_fd_table_init(uvwasi, &uvwasi->fds, options->fd_table_size);
577+
err = uvwasi_fd_table_init(uvwasi, options);
573578
if (err != UVWASI_ESUCCESS)
574579
goto exit;
575580

src/node_wasi.cc

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ void WASI::New(const FunctionCallbackInfo<Value>& args) {
169169
const uint32_t argc = argv->Length();
170170
uvwasi_options_t options;
171171

172+
options.in = 0;
173+
options.out = 1;
174+
options.err = 2;
172175
options.fd_table_size = 3;
173176
options.argc = argc;
174177
options.argv = argc == 0 ? nullptr : new char*[argc];

0 commit comments

Comments
 (0)