Skip to content

Commit 32805a9

Browse files
cjihrigBridgeAR
authored andcommitted
deps,src,test: update to uvwasi 0.0.3
This commit updates to uvwasi 0.0.3, which implements a newer version of the WASI spec, snapshot_1. Since the WASI API has changed, this also requires updating the WebAssembly memory interfacing logic and recompiling the WASI tests with a version of wasi-libc that supports snapshot_1. PR-URL: #30980 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent f8aa365 commit 32805a9

27 files changed

+176
-59
lines changed

deps/uvwasi/include/fd_table.h

+5-15
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,22 @@
66
#include "wasi_types.h"
77
#include "uv_mapping.h"
88

9-
/* TODO(cjihrig): PATH_MAX_BYTES shouldn't be stack allocated. On Windows, paths
10-
can be 32k long, and this PATH_MAX_BYTES is an artificial limitation. */
11-
#ifdef _WIN32
12-
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
13-
# define PATH_MAX_BYTES (MAX_PATH * 4)
14-
#else
15-
# include <limits.h>
16-
# define PATH_MAX_BYTES (PATH_MAX)
17-
#endif
18-
199
struct uvwasi_s;
2010

2111
struct uvwasi_fd_wrap_t {
2212
uvwasi_fd_t id;
2313
uv_file fd;
24-
char path[PATH_MAX_BYTES];
25-
char real_path[PATH_MAX_BYTES];
14+
char* path;
15+
char* real_path;
2616
uvwasi_filetype_t type;
2717
uvwasi_rights_t rights_base;
2818
uvwasi_rights_t rights_inheriting;
2919
int preopen;
30-
int valid;
3120
uv_mutex_t mutex;
3221
};
3322

3423
struct uvwasi_fd_table_t {
35-
struct uvwasi_fd_wrap_t* fds;
24+
struct uvwasi_fd_wrap_t** fds;
3625
uint32_t size;
3726
uint32_t used;
3827
uv_rwlock_t rwlock;
@@ -61,7 +50,8 @@ uvwasi_errno_t uvwasi_fd_table_get(const struct uvwasi_fd_table_t* table,
6150
struct uvwasi_fd_wrap_t** wrap,
6251
uvwasi_rights_t rights_base,
6352
uvwasi_rights_t rights_inheriting);
64-
uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_fd_table_t* table,
53+
uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_s* uvwasi,
54+
struct uvwasi_fd_table_t* table,
6555
const uvwasi_fd_t id);
6656

6757
#endif /* __UVWASI_FD_TABLE_H__ */

deps/uvwasi/include/uvwasi.h

+3-2
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 1
14+
#define UVWASI_VERSION_PATCH 3
1515
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
1616
(UVWASI_VERSION_MINOR << 8) | \
1717
(UVWASI_VERSION_PATCH))
@@ -20,7 +20,7 @@ extern "C" {
2020
#define UVWASI_VERSION_STRING UVWASI_STRINGIFY(UVWASI_VERSION_MAJOR) "." \
2121
UVWASI_STRINGIFY(UVWASI_VERSION_MINOR) "." \
2222
UVWASI_STRINGIFY(UVWASI_VERSION_PATCH)
23-
#define UVWASI_VERSION_WASI "snapshot_0"
23+
#define UVWASI_VERSION_WASI "snapshot_1"
2424

2525
typedef void* (*uvwasi_malloc)(size_t size, void* mem_user_data);
2626
typedef void (*uvwasi_free)(void* ptr, void* mem_user_data);
@@ -69,6 +69,7 @@ void uvwasi_destroy(uvwasi_t* uvwasi);
6969
uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
7070
const uvwasi_fd_t fd,
7171
uv_file new_host_fd);
72+
const char* uvwasi_embedder_err_code_to_string(uvwasi_errno_t code);
7273

7374

7475
// WASI system call API.

deps/uvwasi/include/wasi_types.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ typedef struct uvwasi_iovec_s {
155155
size_t buf_len;
156156
} uvwasi_iovec_t;
157157

158-
typedef uint32_t uvwasi_linkcount_t;
158+
typedef uint64_t uvwasi_linkcount_t;
159159

160160
typedef uint32_t uvwasi_lookupflags_t; /* Bitfield */
161161
#define UVWASI_LOOKUP_SYMLINK_FOLLOW (1 << 0)
@@ -266,7 +266,6 @@ typedef struct uvwasi_subscription_s {
266266
uvwasi_eventtype_t type;
267267
union {
268268
struct {
269-
uvwasi_userdata_t identifier;
270269
uvwasi_clockid_t clock_id;
271270
uvwasi_timestamp_t timeout;
272271
uvwasi_timestamp_t precision;
@@ -316,8 +315,8 @@ typedef struct uvwasi_event_s {
316315
} uvwasi_event_t;
317316

318317
typedef uint8_t uvwasi_whence_t;
319-
#define UVWASI_WHENCE_CUR 0
320-
#define UVWASI_WHENCE_END 1
321-
#define UVWASI_WHENCE_SET 2
318+
#define UVWASI_WHENCE_SET 0
319+
#define UVWASI_WHENCE_CUR 1
320+
#define UVWASI_WHENCE_END 2
322321

323322
#endif /* __UVWASI_WASI_TYPES_H__ */

deps/uvwasi/src/fd_table.c

+45-14
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,29 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi,
187187
int preopen,
188188
struct uvwasi_fd_wrap_t** wrap) {
189189
struct uvwasi_fd_wrap_t* entry;
190-
struct uvwasi_fd_wrap_t* new_fds;
190+
struct uvwasi_fd_wrap_t** new_fds;
191191
uvwasi_errno_t err;
192192
uint32_t new_size;
193193
int index;
194194
uint32_t i;
195195
int r;
196+
size_t mp_len;
197+
char* mp_copy;
198+
size_t rp_len;
199+
char* rp_copy;
200+
201+
mp_len = strlen(mapped_path);
202+
rp_len = strlen(real_path);
203+
entry = (struct uvwasi_fd_wrap_t*)
204+
uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + rp_len + 2);
205+
if (entry == NULL) return UVWASI_ENOMEM;
206+
207+
mp_copy = (char*)(entry + 1);
208+
rp_copy = mp_copy + mp_len + 1;
209+
memcpy(mp_copy, mapped_path, mp_len);
210+
mp_copy[mp_len] = '\0';
211+
memcpy(rp_copy, real_path, rp_len);
212+
rp_copy[rp_len] = '\0';
196213

197214
uv_rwlock_wrlock(&table->rwlock);
198215

@@ -201,12 +218,13 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi,
201218
new_size = table->size * 2;
202219
new_fds = uvwasi__realloc(uvwasi, table->fds, new_size * sizeof(*new_fds));
203220
if (new_fds == NULL) {
221+
uvwasi__free(uvwasi, entry);
204222
err = UVWASI_ENOMEM;
205223
goto exit;
206224
}
207225

208226
for (i = table->size; i < new_size; ++i)
209-
new_fds[i].valid = 0;
227+
new_fds[i] = NULL;
210228

211229
index = table->size;
212230
table->fds = new_fds;
@@ -215,20 +233,21 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi,
215233
/* The table is big enough, so find an empty slot for the new data. */
216234
index = -1;
217235
for (i = 0; i < table->size; ++i) {
218-
if (table->fds[i].valid != 1) {
236+
if (table->fds[i] == NULL) {
219237
index = i;
220238
break;
221239
}
222240
}
223241

224242
/* index should never be -1. */
225243
if (index == -1) {
244+
uvwasi__free(uvwasi, entry);
226245
err = UVWASI_ENOSPC;
227246
goto exit;
228247
}
229248
}
230249

231-
entry = &table->fds[index];
250+
table->fds[index] = entry;
232251

233252
r = uv_mutex_init(&entry->mutex);
234253
if (r != 0) {
@@ -238,13 +257,12 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi,
238257

239258
entry->id = index;
240259
entry->fd = fd;
241-
strcpy(entry->path, mapped_path);
242-
strcpy(entry->real_path, real_path);
260+
entry->path = mp_copy;
261+
entry->real_path = rp_copy;
243262
entry->type = type;
244263
entry->rights_base = rights_base;
245264
entry->rights_inheriting = rights_inheriting;
246265
entry->preopen = preopen;
247-
entry->valid = 1;
248266
table->used++;
249267

250268
if (wrap != NULL)
@@ -281,7 +299,7 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi,
281299
table->size = init_size;
282300
table->fds = uvwasi__calloc(uvwasi,
283301
init_size,
284-
sizeof(struct uvwasi_fd_wrap_t));
302+
sizeof(struct uvwasi_fd_wrap_t*));
285303

286304
if (table->fds == NULL) {
287305
err = UVWASI_ENOMEM;
@@ -325,9 +343,20 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi,
325343

326344

327345
void uvwasi_fd_table_free(uvwasi_t* uvwasi, struct uvwasi_fd_table_t* table) {
346+
struct uvwasi_fd_wrap_t* entry;
347+
uint32_t i;
348+
328349
if (table == NULL)
329350
return;
330351

352+
for (i = 0; i < table->size; i++) {
353+
entry = table->fds[i];
354+
if (entry == NULL) continue;
355+
356+
uv_mutex_destroy(&entry->mutex);
357+
uvwasi__free(uvwasi, entry);
358+
}
359+
331360
uvwasi__free(uvwasi, table->fds);
332361
table->fds = NULL;
333362
table->size = 0;
@@ -430,9 +459,9 @@ uvwasi_errno_t uvwasi_fd_table_get(const struct uvwasi_fd_table_t* table,
430459
goto exit;
431460
}
432461

433-
entry = &table->fds[id];
462+
entry = table->fds[id];
434463

435-
if (entry->valid != 1 || entry->id != id) {
464+
if (entry == NULL || entry->id != id) {
436465
err = UVWASI_EBADF;
437466
goto exit;
438467
}
@@ -453,7 +482,8 @@ uvwasi_errno_t uvwasi_fd_table_get(const struct uvwasi_fd_table_t* table,
453482
}
454483

455484

456-
uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_fd_table_t* table,
485+
uvwasi_errno_t uvwasi_fd_table_remove(uvwasi_t* uvwasi,
486+
struct uvwasi_fd_table_t* table,
457487
const uvwasi_fd_t id) {
458488
struct uvwasi_fd_wrap_t* entry;
459489
uvwasi_errno_t err;
@@ -468,15 +498,16 @@ uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_fd_table_t* table,
468498
goto exit;
469499
}
470500

471-
entry = &table->fds[id];
501+
entry = table->fds[id];
472502

473-
if (entry->valid != 1 || entry->id != id) {
503+
if (entry == NULL || entry->id != id) {
474504
err = UVWASI_EBADF;
475505
goto exit;
476506
}
477507

478508
uv_mutex_destroy(&entry->mutex);
479-
entry->valid = 0;
509+
uvwasi__free(uvwasi, entry);
510+
table->fds[id] = NULL;
480511
table->used--;
481512
err = UVWASI_ESUCCESS;
482513
exit:

deps/uvwasi/src/uvwasi.c

+100-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
#include "fd_table.h"
2626
#include "clocks.h"
2727

28+
/* TODO(cjihrig): PATH_MAX_BYTES shouldn't be stack allocated. On Windows, paths
29+
can be 32k long, and this PATH_MAX_BYTES is an artificial limitation. */
30+
#ifdef _WIN32
31+
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
32+
# define PATH_MAX_BYTES (MAX_PATH * 4)
33+
#else
34+
# include <limits.h>
35+
# define PATH_MAX_BYTES (PATH_MAX)
36+
#endif
37+
2838
static void* default_malloc(size_t size, void* mem_user_data) {
2939
return malloc(size);
3040
}
@@ -688,7 +698,7 @@ uvwasi_errno_t uvwasi_fd_close(uvwasi_t* uvwasi, uvwasi_fd_t fd) {
688698
if (r != 0)
689699
return uvwasi__translate_uv_error(r);
690700

691-
return uvwasi_fd_table_remove(&uvwasi->fds, fd);
701+
return uvwasi_fd_table_remove(uvwasi, &uvwasi->fds, fd);
692702
}
693703

694704

@@ -1319,7 +1329,7 @@ uvwasi_errno_t uvwasi_fd_renumber(uvwasi_t* uvwasi,
13191329
to_wrap->id = to;
13201330
uv_mutex_unlock(&from_wrap->mutex);
13211331
uv_mutex_unlock(&to_wrap->mutex);
1322-
return uvwasi_fd_table_remove(&uvwasi->fds, from);
1332+
return uvwasi_fd_table_remove(uvwasi, &uvwasi->fds, from);
13231333
}
13241334

13251335

@@ -1773,7 +1783,7 @@ uvwasi_errno_t uvwasi_path_open(uvwasi_t* uvwasi,
17731783
if ((o_flags & UVWASI_O_DIRECTORY) != 0 &&
17741784
wrap.type != UVWASI_FILETYPE_DIRECTORY) {
17751785
uv_mutex_unlock(&dirfd_wrap->mutex);
1776-
uvwasi_fd_table_remove(&uvwasi->fds, wrap.id);
1786+
uvwasi_fd_table_remove(uvwasi, &uvwasi->fds, wrap.id);
17771787
err = UVWASI_ENOTDIR;
17781788
goto close_file_and_error_exit;
17791789
}
@@ -2140,3 +2150,90 @@ uvwasi_errno_t uvwasi_sock_shutdown(uvwasi_t* uvwasi,
21402150
https://github.com/WebAssembly/WASI/issues/4 */
21412151
return UVWASI_ENOTSUP;
21422152
}
2153+
2154+
2155+
const char* uvwasi_embedder_err_code_to_string(uvwasi_errno_t code) {
2156+
switch (code) {
2157+
#define V(errcode) case errcode: return #errcode;
2158+
V(UVWASI_E2BIG)
2159+
V(UVWASI_EACCES)
2160+
V(UVWASI_EADDRINUSE)
2161+
V(UVWASI_EADDRNOTAVAIL)
2162+
V(UVWASI_EAFNOSUPPORT)
2163+
V(UVWASI_EAGAIN)
2164+
V(UVWASI_EALREADY)
2165+
V(UVWASI_EBADF)
2166+
V(UVWASI_EBADMSG)
2167+
V(UVWASI_EBUSY)
2168+
V(UVWASI_ECANCELED)
2169+
V(UVWASI_ECHILD)
2170+
V(UVWASI_ECONNABORTED)
2171+
V(UVWASI_ECONNREFUSED)
2172+
V(UVWASI_ECONNRESET)
2173+
V(UVWASI_EDEADLK)
2174+
V(UVWASI_EDESTADDRREQ)
2175+
V(UVWASI_EDOM)
2176+
V(UVWASI_EDQUOT)
2177+
V(UVWASI_EEXIST)
2178+
V(UVWASI_EFAULT)
2179+
V(UVWASI_EFBIG)
2180+
V(UVWASI_EHOSTUNREACH)
2181+
V(UVWASI_EIDRM)
2182+
V(UVWASI_EILSEQ)
2183+
V(UVWASI_EINPROGRESS)
2184+
V(UVWASI_EINTR)
2185+
V(UVWASI_EINVAL)
2186+
V(UVWASI_EIO)
2187+
V(UVWASI_EISCONN)
2188+
V(UVWASI_EISDIR)
2189+
V(UVWASI_ELOOP)
2190+
V(UVWASI_EMFILE)
2191+
V(UVWASI_EMLINK)
2192+
V(UVWASI_EMSGSIZE)
2193+
V(UVWASI_EMULTIHOP)
2194+
V(UVWASI_ENAMETOOLONG)
2195+
V(UVWASI_ENETDOWN)
2196+
V(UVWASI_ENETRESET)
2197+
V(UVWASI_ENETUNREACH)
2198+
V(UVWASI_ENFILE)
2199+
V(UVWASI_ENOBUFS)
2200+
V(UVWASI_ENODEV)
2201+
V(UVWASI_ENOENT)
2202+
V(UVWASI_ENOEXEC)
2203+
V(UVWASI_ENOLCK)
2204+
V(UVWASI_ENOLINK)
2205+
V(UVWASI_ENOMEM)
2206+
V(UVWASI_ENOMSG)
2207+
V(UVWASI_ENOPROTOOPT)
2208+
V(UVWASI_ENOSPC)
2209+
V(UVWASI_ENOSYS)
2210+
V(UVWASI_ENOTCONN)
2211+
V(UVWASI_ENOTDIR)
2212+
V(UVWASI_ENOTEMPTY)
2213+
V(UVWASI_ENOTRECOVERABLE)
2214+
V(UVWASI_ENOTSOCK)
2215+
V(UVWASI_ENOTSUP)
2216+
V(UVWASI_ENOTTY)
2217+
V(UVWASI_ENXIO)
2218+
V(UVWASI_EOVERFLOW)
2219+
V(UVWASI_EOWNERDEAD)
2220+
V(UVWASI_EPERM)
2221+
V(UVWASI_EPIPE)
2222+
V(UVWASI_EPROTO)
2223+
V(UVWASI_EPROTONOSUPPORT)
2224+
V(UVWASI_EPROTOTYPE)
2225+
V(UVWASI_ERANGE)
2226+
V(UVWASI_EROFS)
2227+
V(UVWASI_ESPIPE)
2228+
V(UVWASI_ESRCH)
2229+
V(UVWASI_ESTALE)
2230+
V(UVWASI_ETIMEDOUT)
2231+
V(UVWASI_ETXTBSY)
2232+
V(UVWASI_EXDEV)
2233+
V(UVWASI_ENOTCAPABLE)
2234+
V(UVWASI_ESUCCESS)
2235+
#undef V
2236+
default:
2237+
return "UVWASI_UNKNOWN_ERROR";
2238+
}
2239+
}

0 commit comments

Comments
 (0)