Skip to content

Commit 3227d73

Browse files
nodejs-github-botmhdawson
authored andcommitted
deps: update uvwasi to 0.0.19
PR-URL: #49908 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 6322d4f commit 3227d73

File tree

8 files changed

+491
-47
lines changed

8 files changed

+491
-47
lines changed

deps/uvwasi/include/uvwasi.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
extern "C" {
66
#endif
77

8+
#include "uv.h"
89
#include "wasi_serdes.h"
910
#include "wasi_types.h"
1011

1112
#define UVWASI_VERSION_MAJOR 0
1213
#define UVWASI_VERSION_MINOR 0
13-
#define UVWASI_VERSION_PATCH 18
14+
#define UVWASI_VERSION_PATCH 19
1415
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
1516
(UVWASI_VERSION_MINOR << 8) | \
1617
(UVWASI_VERSION_PATCH))
@@ -47,17 +48,25 @@ typedef struct uvwasi_s {
4748
char* env_buf;
4849
uvwasi_size_t env_buf_size;
4950
const uvwasi_mem_t* allocator;
51+
uv_loop_t* loop;
5052
} uvwasi_t;
5153

5254
typedef struct uvwasi_preopen_s {
5355
const char* mapped_path;
5456
const char* real_path;
5557
} uvwasi_preopen_t;
5658

59+
typedef struct uvwasi_preopen_socket_s {
60+
const char* address;
61+
int port;
62+
} uvwasi_preopen_socket_t;
63+
5764
typedef struct uvwasi_options_s {
5865
uvwasi_size_t fd_table_size;
5966
uvwasi_size_t preopenc;
6067
uvwasi_preopen_t* preopens;
68+
uvwasi_size_t preopen_socketc;
69+
uvwasi_preopen_socket_t* preopen_sockets;
6170
uvwasi_size_t argc;
6271
const char** argv;
6372
const char** envp;

deps/uvwasi/src/fd_table.c

+52-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
3737
err = uvwasi_fd_table_insert(uvwasi,
3838
table,
3939
fd,
40+
NULL,
4041
name,
4142
name,
4243
type,
@@ -58,6 +59,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi,
5859
uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
5960
struct uvwasi_fd_table_t* table,
6061
uv_file fd,
62+
uv_tcp_t* sock,
6163
const char* mapped_path,
6264
const char* real_path,
6365
uvwasi_filetype_t type,
@@ -78,29 +80,40 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
7880
char* rp_copy;
7981
char* np_copy;
8082

81-
mp_len = strlen(mapped_path);
82-
rp_len = strlen(real_path);
83+
if (type != UVWASI_FILETYPE_SOCKET_STREAM) {
84+
mp_len = strlen(mapped_path);
85+
rp_len = strlen(real_path);
86+
} else {
87+
mp_len = 0;
88+
rp_len = 0;
89+
rp_copy = NULL;
90+
mp_copy = NULL;
91+
np_copy = NULL;
92+
}
93+
8394
/* Reserve room for the mapped path, real path, and normalized mapped path. */
8495
entry = (struct uvwasi_fd_wrap_t*)
8596
uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + mp_len + rp_len + 3);
8697
if (entry == NULL)
8798
return UVWASI_ENOMEM;
8899

89-
mp_copy = (char*)(entry + 1);
90-
rp_copy = mp_copy + mp_len + 1;
91-
np_copy = rp_copy + rp_len + 1;
92-
memcpy(mp_copy, mapped_path, mp_len);
93-
mp_copy[mp_len] = '\0';
94-
memcpy(rp_copy, real_path, rp_len);
95-
rp_copy[rp_len] = '\0';
96-
97-
/* Calculate the normalized version of the mapped path, as it will be used for
98-
any path calculations on this fd. Use the length of the mapped path as an
99-
upper bound for the normalized path length. */
100-
err = uvwasi__normalize_path(mp_copy, mp_len, np_copy, mp_len);
101-
if (err) {
102-
uvwasi__free(uvwasi, entry);
103-
goto exit;
100+
if (type != UVWASI_FILETYPE_SOCKET_STREAM) {
101+
mp_copy = (char*)(entry + 1);
102+
rp_copy = mp_copy + mp_len + 1;
103+
np_copy = rp_copy + rp_len + 1;
104+
memcpy(mp_copy, mapped_path, mp_len);
105+
mp_copy[mp_len] = '\0';
106+
memcpy(rp_copy, real_path, rp_len);
107+
rp_copy[rp_len] = '\0';
108+
109+
/* Calculate the normalized version of the mapped path, as it will be used for
110+
any path calculations on this fd. Use the length of the mapped path as an
111+
upper bound for the normalized path length. */
112+
err = uvwasi__normalize_path(mp_copy, mp_len, np_copy, mp_len);
113+
if (err) {
114+
uvwasi__free(uvwasi, entry);
115+
goto exit;
116+
}
104117
}
105118

106119
uv_rwlock_wrlock(&table->rwlock);
@@ -150,6 +163,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
150163

151164
entry->id = index;
152165
entry->fd = fd;
166+
entry->sock = sock;
153167
entry->path = mp_copy;
154168
entry->real_path = rp_copy;
155169
entry->normalized_path = np_copy;
@@ -280,6 +294,7 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
280294
return uvwasi_fd_table_insert(uvwasi,
281295
table,
282296
fd,
297+
NULL,
283298
path,
284299
real_path,
285300
UVWASI_FILETYPE_DIRECTORY,
@@ -290,6 +305,26 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi,
290305
}
291306

292307

308+
uvwasi_errno_t uvwasi_fd_table_insert_preopen_socket(uvwasi_t* uvwasi,
309+
struct uvwasi_fd_table_t* table,
310+
uv_tcp_t* sock) {
311+
if (table == NULL || sock == NULL)
312+
return UVWASI_EINVAL;
313+
314+
return uvwasi_fd_table_insert(uvwasi,
315+
table,
316+
-1,
317+
sock,
318+
NULL,
319+
NULL,
320+
UVWASI_FILETYPE_SOCKET_STREAM,
321+
UVWASI__RIGHTS_SOCKET_BASE,
322+
UVWASI__RIGHTS_SOCKET_INHERITING,
323+
1,
324+
NULL);
325+
}
326+
327+
293328
uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table,
294329
const uvwasi_fd_t id,
295330
struct uvwasi_fd_wrap_t** wrap,

deps/uvwasi/src/fd_table.h

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct uvwasi_options_s;
1111
struct uvwasi_fd_wrap_t {
1212
uvwasi_fd_t id;
1313
uv_file fd;
14+
uv_tcp_t* sock;
1415
char* path;
1516
char* real_path;
1617
char* normalized_path;
@@ -35,6 +36,7 @@ void uvwasi_fd_table_free(struct uvwasi_s* uvwasi,
3536
uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi,
3637
struct uvwasi_fd_table_t* table,
3738
uv_file fd,
39+
uv_tcp_t* sock,
3840
const char* mapped_path,
3941
const char* real_path,
4042
uvwasi_filetype_t type,
@@ -47,6 +49,9 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_s* uvwasi,
4749
const uv_file fd,
4850
const char* path,
4951
const char* real_path);
52+
uvwasi_errno_t uvwasi_fd_table_insert_preopen_socket(struct uvwasi_s* uvwasi,
53+
struct uvwasi_fd_table_t* table,
54+
uv_tcp_t* sock);
5055
uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table,
5156
const uvwasi_fd_t id,
5257
struct uvwasi_fd_wrap_t** wrap,

deps/uvwasi/src/sync_helpers.c

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "uv.h"
2+
#include "sync_helpers.h"
3+
#include "uv_mapping.h"
4+
#include "uvwasi_alloc.h"
5+
6+
typedef struct free_handle_data_s {
7+
uvwasi_t* uvwasi;
8+
int done;
9+
} free_handle_data_t;
10+
11+
static void free_handle_cb(uv_handle_t* handle) {
12+
free_handle_data_t* free_handle_data = uv_handle_get_data((uv_handle_t*) handle);
13+
uvwasi__free(free_handle_data->uvwasi, handle);
14+
free_handle_data->done = 1;
15+
}
16+
17+
int free_handle_sync(struct uvwasi_s* uvwasi, uv_handle_t* handle) {
18+
free_handle_data_t free_handle_data = { uvwasi, 0 };
19+
uv_handle_set_data(handle, (void*) &free_handle_data);
20+
uv_close(handle, free_handle_cb);
21+
uv_loop_t* handle_loop = uv_handle_get_loop(handle);
22+
while(!free_handle_data.done) {
23+
if (uv_run(handle_loop, UV_RUN_ONCE) == 0) {
24+
break;
25+
}
26+
}
27+
return UVWASI_ESUCCESS;
28+
}
29+
30+
static void do_stream_shutdown(uv_shutdown_t* req, int status) {
31+
shutdown_data_t* shutdown_data;
32+
shutdown_data = uv_handle_get_data((uv_handle_t*) req->handle);
33+
shutdown_data->status = status;
34+
shutdown_data->done = 1;
35+
}
36+
37+
int shutdown_stream_sync(struct uvwasi_s* uvwasi,
38+
uv_stream_t* stream,
39+
shutdown_data_t* shutdown_data) {
40+
uv_shutdown_t req;
41+
uv_loop_t* stream_loop;
42+
43+
shutdown_data->done = 0;
44+
shutdown_data->status = 0;
45+
stream_loop = uv_handle_get_loop((uv_handle_t*) stream);
46+
47+
uv_handle_set_data((uv_handle_t*) stream, (void*) shutdown_data);
48+
uv_shutdown(&req, stream, do_stream_shutdown);
49+
while (!shutdown_data->done) {
50+
if (uv_run(stream_loop, UV_RUN_ONCE) == 0) {
51+
return UVWASI_ECANCELED;
52+
}
53+
}
54+
return UVWASI_ESUCCESS;
55+
}
56+
57+
static void recv_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
58+
recv_data_t* recv_data;
59+
recv_data = uv_handle_get_data(handle);
60+
buf->base = recv_data->base;
61+
buf->len = recv_data->len;
62+
}
63+
64+
void do_stream_recv(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
65+
recv_data_t* recv_data;
66+
recv_data = uv_handle_get_data((uv_handle_t*) stream);
67+
uv_read_stop(stream);
68+
recv_data->nread = nread;
69+
recv_data->done = 1;
70+
}
71+
72+
int read_stream_sync(struct uvwasi_s* uvwasi,
73+
uv_stream_t* stream,
74+
recv_data_t* recv_data) {
75+
uv_loop_t* recv_loop;
76+
int r;
77+
78+
recv_data->nread = 0;
79+
recv_data->done = 0;
80+
recv_loop = uv_handle_get_loop((uv_handle_t*) stream);
81+
82+
uv_handle_set_data((uv_handle_t*) stream, (void*) recv_data);
83+
r = uv_read_start(stream, recv_alloc_cb, do_stream_recv);
84+
if (r != 0) {
85+
return uvwasi__translate_uv_error(r);
86+
}
87+
88+
while (!recv_data->done) {
89+
if (uv_run(recv_loop, UV_RUN_ONCE) == 0) {
90+
return UVWASI_ECANCELED;
91+
}
92+
}
93+
94+
return UVWASI_ESUCCESS;
95+
}

deps/uvwasi/src/sync_helpers.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __UVWASI_SYNC_HELPERS_H__
2+
#define __UVWASI_SYNC_HELPERS_H__
3+
4+
struct uvwasi_s;
5+
6+
typedef struct shutdown_data_s {
7+
int status;
8+
int done;
9+
} shutdown_data_t;
10+
11+
typedef struct recv_data_s {
12+
char* base;
13+
size_t len;
14+
ssize_t nread;
15+
int done;
16+
} recv_data_t;
17+
18+
int free_handle_sync(struct uvwasi_s* uvwasi, uv_handle_t* handle);
19+
20+
int shutdown_stream_sync(struct uvwasi_s* uvwasi,
21+
uv_stream_t* stream,
22+
shutdown_data_t* shutdown_data);
23+
24+
int read_stream_sync(struct uvwasi_s* uvwasi,
25+
uv_stream_t* stream,
26+
recv_data_t* recv_data);
27+
#endif /* __UVWASI_SYNC_HELPERS_H__ */

0 commit comments

Comments
 (0)