GeezerVison is showing github.com — deps: update uvwasi to 0.0.19 · nodejs/node@21453ae
File treeExpand file treeCollapse file tree Open diff view settings doc/contributing/maintaining
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/uvwasi/include/uvwasi.h +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | extern "C" { | 6 | 6 | #endif | 7 | 7 |
| | 8 | +#include "uv.h" | 8 | 9 | #include "wasi_serdes.h" | 9 | 10 | #include "wasi_types.h" | 10 | 11 |
| 11 | 12 | #define UVWASI_VERSION_MAJOR 0 | 12 | 13 | #define UVWASI_VERSION_MINOR 0 | 13 | | -#define UVWASI_VERSION_PATCH 18 | | 14 | +#define UVWASI_VERSION_PATCH 19 | 14 | 15 | #define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \ | 15 | 16 | (UVWASI_VERSION_MINOR << 8) | \ | 16 | 17 | (UVWASI_VERSION_PATCH)) | @@ -47,17 +48,25 @@ typedef struct uvwasi_s { | 47 | 48 | char* env_buf; | 48 | 49 | uvwasi_size_t env_buf_size; | 49 | 50 | const uvwasi_mem_t* allocator; | | 51 | + uv_loop_t* loop; | 50 | 52 | } uvwasi_t; | 51 | 53 |
| 52 | 54 | typedef struct uvwasi_preopen_s { | 53 | 55 | const char* mapped_path; | 54 | 56 | const char* real_path; | 55 | 57 | } uvwasi_preopen_t; | 56 | 58 |
| | 59 | +typedef struct uvwasi_preopen_socket_s { | | 60 | + const char* address; | | 61 | + int port; | | 62 | +} uvwasi_preopen_socket_t; | | 63 | + | 57 | 64 | typedef struct uvwasi_options_s { | 58 | 65 | uvwasi_size_t fd_table_size; | 59 | 66 | uvwasi_size_t preopenc; | 60 | 67 | uvwasi_preopen_t* preopens; | | 68 | + uvwasi_size_t preopen_socketc; | | 69 | + uvwasi_preopen_socket_t* preopen_sockets; | 61 | 70 | uvwasi_size_t argc; | 62 | 71 | const char** argv; | 63 | 72 | const char** envp; | |
Collapse file Copy file name to clipboardExpand all lines: deps/uvwasi/src/fd_table.c +52-17Lines changed: 52 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi, | 37 | 37 | err = uvwasi_fd_table_insert(uvwasi, | 38 | 38 | table, | 39 | 39 | fd, | | 40 | + NULL, | 40 | 41 | name, | 41 | 42 | name, | 42 | 43 | type, | @@ -58,6 +59,7 @@ static uvwasi_errno_t uvwasi__insert_stdio(uvwasi_t* uvwasi, | 58 | 59 | uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | 59 | 60 | struct uvwasi_fd_table_t* table, | 60 | 61 | uv_file fd, | | 62 | + uv_tcp_t* sock, | 61 | 63 | const char* mapped_path, | 62 | 64 | const char* real_path, | 63 | 65 | uvwasi_filetype_t type, | @@ -78,29 +80,40 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | 78 | 80 | char* rp_copy; | 79 | 81 | char* np_copy; | 80 | 82 |
| 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 | + | 83 | 94 | /* Reserve room for the mapped path, real path, and normalized mapped path. */ | 84 | 95 | entry = (struct uvwasi_fd_wrap_t*) | 85 | 96 | uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + mp_len + rp_len + 3); | 86 | 97 | if (entry == NULL) | 87 | 98 | return UVWASI_ENOMEM; | 88 | 99 |
| 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 | + } | 104 | 117 | } | 105 | 118 |
| 106 | 119 | uv_rwlock_wrlock(&table->rwlock); | @@ -150,6 +163,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi, | 150 | 163 |
| 151 | 164 | entry->id = index; | 152 | 165 | entry->fd = fd; | | 166 | + entry->sock = sock; | 153 | 167 | entry->path = mp_copy; | 154 | 168 | entry->real_path = rp_copy; | 155 | 169 | entry->normalized_path = np_copy; | @@ -280,6 +294,7 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi, | 280 | 294 | return uvwasi_fd_table_insert(uvwasi, | 281 | 295 | table, | 282 | 296 | fd, | | 297 | + NULL, | 283 | 298 | path, | 284 | 299 | real_path, | 285 | 300 | UVWASI_FILETYPE_DIRECTORY, | @@ -290,6 +305,26 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(uvwasi_t* uvwasi, | 290 | 305 | } | 291 | 306 |
| 292 | 307 |
| | 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 | + | 293 | 328 | uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table, | 294 | 329 | const uvwasi_fd_t id, | 295 | 330 | struct uvwasi_fd_wrap_t** wrap, | |
Collapse file Copy file name to clipboardExpand all lines: deps/uvwasi/src/fd_table.h +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ struct uvwasi_options_s; | 11 | 11 | struct uvwasi_fd_wrap_t { | 12 | 12 | uvwasi_fd_t id; | 13 | 13 | uv_file fd; | | 14 | + uv_tcp_t* sock; | 14 | 15 | char* path; | 15 | 16 | char* real_path; | 16 | 17 | char* normalized_path; | @@ -35,6 +36,7 @@ void uvwasi_fd_table_free(struct uvwasi_s* uvwasi, | 35 | 36 | uvwasi_errno_t uvwasi_fd_table_insert(struct uvwasi_s* uvwasi, | 36 | 37 | struct uvwasi_fd_table_t* table, | 37 | 38 | uv_file fd, | | 39 | + uv_tcp_t* sock, | 38 | 40 | const char* mapped_path, | 39 | 41 | const char* real_path, | 40 | 42 | uvwasi_filetype_t type, | @@ -47,6 +49,9 @@ uvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_s* uvwasi, | 47 | 49 | const uv_file fd, | 48 | 50 | const char* path, | 49 | 51 | 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); | 50 | 55 | uvwasi_errno_t uvwasi_fd_table_get(struct uvwasi_fd_table_t* table, | 51 | 56 | const uvwasi_fd_t id, | 52 | 57 | struct uvwasi_fd_wrap_t** wrap, | |
Collapse file Copy file name to clipboard +95Lines changed: 95 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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__ */ |
|