Skip to content

Commit b6ce736

Browse files
cjihrigtargos
authored andcommitted
wasi: introduce initial WASI support
Co-authored-by: Gus Caplan <[email protected]> Co-authored-by: Daniel Bevenius <[email protected]> Co-authored-by: Jiawen Geng <[email protected]> Co-authored-by: Tobias Nießen <[email protected]> Co-authored-by: Chengzhong Wu <[email protected]> PR-URL: #30258 Refs: #27850 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Wyatt Preul <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent 4de6097 commit b6ce736

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+12753
-4
lines changed

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -1526,3 +1526,28 @@ The externally maintained libraries used by Node.js are:
15261526
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15271527
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15281528
"""
1529+
1530+
- uvwasi, located at deps/uvwasi, is licensed as follows:
1531+
"""
1532+
MIT License
1533+
1534+
Copyright (c) 2019 Colin Ihrig and Contributors
1535+
1536+
Permission is hereby granted, free of charge, to any person obtaining a copy
1537+
of this software and associated documentation files (the "Software"), to deal
1538+
in the Software without restriction, including without limitation the rights
1539+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1540+
copies of the Software, and to permit persons to whom the Software is
1541+
furnished to do so, subject to the following conditions:
1542+
1543+
The above copyright notice and this permission notice shall be included in all
1544+
copies or substantial portions of the Software.
1545+
1546+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1547+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1548+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1549+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1550+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1551+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1552+
SOFTWARE.
1553+
"""

deps/uvwasi/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Colin Ihrig and Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

deps/uvwasi/include/clocks.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef __UVWASI_CLOCKS_H__
2+
#define __UVWASI_CLOCKS_H__
3+
4+
#include "wasi_types.h"
5+
6+
uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time);
7+
uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time);
8+
uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time);
9+
10+
uvwasi_errno_t uvwasi__clock_getres_process_cputime(uvwasi_timestamp_t* time);
11+
uvwasi_errno_t uvwasi__clock_getres_thread_cputime(uvwasi_timestamp_t* time);
12+
13+
#endif /* __UVWASI_CLOCKS_H__ */

deps/uvwasi/include/fd_table.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef __UVWASI_FD_TABLE_H__
2+
#define __UVWASI_FD_TABLE_H__
3+
4+
#include <stdint.h>
5+
#include "uv.h"
6+
#include "wasi_types.h"
7+
#include "uv_mapping.h"
8+
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+
19+
20+
struct uvwasi_fd_wrap_t {
21+
uvwasi_fd_t id;
22+
uv_file fd;
23+
char path[PATH_MAX_BYTES];
24+
char real_path[PATH_MAX_BYTES];
25+
uvwasi_filetype_t type;
26+
uvwasi_rights_t rights_base;
27+
uvwasi_rights_t rights_inheriting;
28+
int preopen;
29+
int valid;
30+
};
31+
32+
struct uvwasi_fd_table_t {
33+
struct uvwasi_fd_wrap_t* fds;
34+
uint32_t size;
35+
uint32_t used;
36+
};
37+
38+
uvwasi_errno_t uvwasi_fd_table_init(struct uvwasi_fd_table_t* table,
39+
uint32_t init_size);
40+
void uvwasi_fd_table_free(struct uvwasi_fd_table_t* table);
41+
uvwasi_errno_t uvwasi_fd_table_insert_preopen(struct uvwasi_fd_table_t* table,
42+
const uv_file fd,
43+
const char* path,
44+
const char* real_path);
45+
uvwasi_errno_t uvwasi_fd_table_insert_fd(struct uvwasi_fd_table_t* table,
46+
const uv_file fd,
47+
const int flags,
48+
const char* path,
49+
uvwasi_rights_t rights_base,
50+
uvwasi_rights_t rights_inheriting,
51+
struct uvwasi_fd_wrap_t* wrap);
52+
uvwasi_errno_t uvwasi_fd_table_get(const struct uvwasi_fd_table_t* table,
53+
const uvwasi_fd_t id,
54+
struct uvwasi_fd_wrap_t** wrap,
55+
uvwasi_rights_t rights_base,
56+
uvwasi_rights_t rights_inheriting);
57+
uvwasi_errno_t uvwasi_fd_table_remove(struct uvwasi_fd_table_t* table,
58+
const uvwasi_fd_t id);
59+
60+
#endif /* __UVWASI_FD_TABLE_H__ */

deps/uvwasi/include/uv_mapping.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef __UVWASI_UV_MAPPING_H__
2+
#define __UVWASI_UV_MAPPING_H__
3+
4+
#include "uv.h"
5+
#include "wasi_types.h"
6+
7+
#define NANOS_PER_SEC 1000000000
8+
9+
uvwasi_errno_t uvwasi__translate_uv_error(int err);
10+
int uvwasi__translate_to_uv_signal(uvwasi_signal_t sig);
11+
uvwasi_timestamp_t uvwasi__timespec_to_timestamp(const uv_timespec_t* ts);
12+
uvwasi_filetype_t uvwasi__stat_to_filetype(const uv_stat_t* stat);
13+
void uvwasi__stat_to_filestat(const uv_stat_t* stat, uvwasi_filestat_t* fs);
14+
15+
#endif /* __UVWASI_UV_MAPPING_H__ */

deps/uvwasi/include/uvwasi.h

+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
#ifndef __UVWASI_H__
2+
#define __UVWASI_H__
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include "wasi_types.h"
9+
#include "uv_mapping.h"
10+
#include "fd_table.h"
11+
12+
#define UVWASI_VERSION_MAJOR 0
13+
#define UVWASI_VERSION_MINOR 0
14+
#define UVWASI_VERSION_PATCH 1
15+
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
16+
(UVWASI_VERSION_MINOR << 8) | \
17+
(UVWASI_VERSION_PATCH))
18+
#define UVWASI_STRINGIFY(v) UVWASI_STRINGIFY_HELPER(v)
19+
#define UVWASI_STRINGIFY_HELPER(v) #v
20+
#define UVWASI_VERSION_STRING UVWASI_STRINGIFY(UVWASI_VERSION_MAJOR) "." \
21+
UVWASI_STRINGIFY(UVWASI_VERSION_MINOR) "." \
22+
UVWASI_STRINGIFY(UVWASI_VERSION_PATCH)
23+
24+
25+
typedef struct uvwasi_s {
26+
struct uvwasi_fd_table_t fds;
27+
size_t argc;
28+
char** argv;
29+
char* argv_buf;
30+
size_t argv_buf_size;
31+
size_t envc;
32+
char** env;
33+
char* env_buf;
34+
size_t env_buf_size;
35+
} uvwasi_t;
36+
37+
typedef struct uvwasi_preopen_s {
38+
char* mapped_path;
39+
char* real_path;
40+
} uvwasi_preopen_t;
41+
42+
typedef struct uvwasi_options_s {
43+
size_t fd_table_size;
44+
size_t preopenc;
45+
uvwasi_preopen_t* preopens;
46+
size_t argc;
47+
char** argv;
48+
char** envp;
49+
} uvwasi_options_t;
50+
51+
52+
// Embedder API.
53+
uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options);
54+
void uvwasi_destroy(uvwasi_t* uvwasi);
55+
uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
56+
const uvwasi_fd_t fd,
57+
uv_file new_host_fd);
58+
59+
60+
// WASI system call API.
61+
uvwasi_errno_t uvwasi_args_get(uvwasi_t* uvwasi, char** argv, char* argv_buf);
62+
uvwasi_errno_t uvwasi_args_sizes_get(uvwasi_t* uvwasi,
63+
size_t* argc,
64+
size_t* argv_buf_size);
65+
uvwasi_errno_t uvwasi_clock_res_get(uvwasi_t* uvwasi,
66+
uvwasi_clockid_t clock_id,
67+
uvwasi_timestamp_t* resolution);
68+
uvwasi_errno_t uvwasi_clock_time_get(uvwasi_t* uvwasi,
69+
uvwasi_clockid_t clock_id,
70+
uvwasi_timestamp_t precision,
71+
uvwasi_timestamp_t* time);
72+
uvwasi_errno_t uvwasi_environ_get(uvwasi_t* uvwasi,
73+
char** environment,
74+
char* environ_buf);
75+
uvwasi_errno_t uvwasi_environ_sizes_get(uvwasi_t* uvwasi,
76+
size_t* environ_count,
77+
size_t* environ_buf_size);
78+
uvwasi_errno_t uvwasi_fd_advise(uvwasi_t* uvwasi,
79+
uvwasi_fd_t fd,
80+
uvwasi_filesize_t offset,
81+
uvwasi_filesize_t len,
82+
uvwasi_advice_t advice);
83+
uvwasi_errno_t uvwasi_fd_allocate(uvwasi_t* uvwasi,
84+
uvwasi_fd_t fd,
85+
uvwasi_filesize_t offset,
86+
uvwasi_filesize_t len);
87+
uvwasi_errno_t uvwasi_fd_close(uvwasi_t* uvwasi, uvwasi_fd_t fd);
88+
uvwasi_errno_t uvwasi_fd_datasync(uvwasi_t* uvwasi, uvwasi_fd_t fd);
89+
uvwasi_errno_t uvwasi_fd_fdstat_get(uvwasi_t* uvwasi,
90+
uvwasi_fd_t fd,
91+
uvwasi_fdstat_t* buf);
92+
uvwasi_errno_t uvwasi_fd_fdstat_set_flags(uvwasi_t* uvwasi,
93+
uvwasi_fd_t fd,
94+
uvwasi_fdflags_t flags);
95+
uvwasi_errno_t uvwasi_fd_fdstat_set_rights(uvwasi_t* uvwasi,
96+
uvwasi_fd_t fd,
97+
uvwasi_rights_t fs_rights_base,
98+
uvwasi_rights_t fs_rights_inheriting
99+
);
100+
uvwasi_errno_t uvwasi_fd_filestat_get(uvwasi_t* uvwasi,
101+
uvwasi_fd_t fd,
102+
uvwasi_filestat_t* buf);
103+
uvwasi_errno_t uvwasi_fd_filestat_set_size(uvwasi_t* uvwasi,
104+
uvwasi_fd_t fd,
105+
uvwasi_filesize_t st_size);
106+
uvwasi_errno_t uvwasi_fd_filestat_set_times(uvwasi_t* uvwasi,
107+
uvwasi_fd_t fd,
108+
uvwasi_timestamp_t st_atim,
109+
uvwasi_timestamp_t st_mtim,
110+
uvwasi_fstflags_t fst_flags);
111+
uvwasi_errno_t uvwasi_fd_pread(uvwasi_t* uvwasi,
112+
uvwasi_fd_t fd,
113+
const uvwasi_iovec_t* iovs,
114+
size_t iovs_len,
115+
uvwasi_filesize_t offset,
116+
size_t* nread);
117+
uvwasi_errno_t uvwasi_fd_prestat_get(uvwasi_t* uvwasi,
118+
uvwasi_fd_t fd,
119+
uvwasi_prestat_t* buf);
120+
uvwasi_errno_t uvwasi_fd_prestat_dir_name(uvwasi_t* uvwasi,
121+
uvwasi_fd_t fd,
122+
char* path,
123+
size_t path_len);
124+
uvwasi_errno_t uvwasi_fd_pwrite(uvwasi_t* uvwasi,
125+
uvwasi_fd_t fd,
126+
const uvwasi_ciovec_t* iovs,
127+
size_t iovs_len,
128+
uvwasi_filesize_t offset,
129+
size_t* nwritten);
130+
uvwasi_errno_t uvwasi_fd_read(uvwasi_t* uvwasi,
131+
uvwasi_fd_t fd,
132+
const uvwasi_iovec_t* iovs,
133+
size_t iovs_len,
134+
size_t* nread);
135+
uvwasi_errno_t uvwasi_fd_readdir(uvwasi_t* uvwasi,
136+
uvwasi_fd_t fd,
137+
void* buf,
138+
size_t buf_len,
139+
uvwasi_dircookie_t cookie,
140+
size_t* bufused);
141+
uvwasi_errno_t uvwasi_fd_renumber(uvwasi_t* uvwasi,
142+
uvwasi_fd_t from,
143+
uvwasi_fd_t to);
144+
uvwasi_errno_t uvwasi_fd_seek(uvwasi_t* uvwasi,
145+
uvwasi_fd_t fd,
146+
uvwasi_filedelta_t offset,
147+
uvwasi_whence_t whence,
148+
uvwasi_filesize_t* newoffset);
149+
uvwasi_errno_t uvwasi_fd_sync(uvwasi_t* uvwasi, uvwasi_fd_t fd);
150+
uvwasi_errno_t uvwasi_fd_tell(uvwasi_t* uvwasi,
151+
uvwasi_fd_t fd,
152+
uvwasi_filesize_t* offset);
153+
uvwasi_errno_t uvwasi_fd_write(uvwasi_t* uvwasi,
154+
uvwasi_fd_t fd,
155+
const uvwasi_ciovec_t* iovs,
156+
size_t iovs_len,
157+
size_t* nwritten);
158+
uvwasi_errno_t uvwasi_path_create_directory(uvwasi_t* uvwasi,
159+
uvwasi_fd_t fd,
160+
const char* path,
161+
size_t path_len);
162+
uvwasi_errno_t uvwasi_path_filestat_get(uvwasi_t* uvwasi,
163+
uvwasi_fd_t fd,
164+
uvwasi_lookupflags_t flags,
165+
const char* path,
166+
size_t path_len,
167+
uvwasi_filestat_t* buf);
168+
uvwasi_errno_t uvwasi_path_filestat_set_times(uvwasi_t* uvwasi,
169+
uvwasi_fd_t fd,
170+
uvwasi_lookupflags_t flags,
171+
const char* path,
172+
size_t path_len,
173+
uvwasi_timestamp_t st_atim,
174+
uvwasi_timestamp_t st_mtim,
175+
uvwasi_fstflags_t fst_flags);
176+
uvwasi_errno_t uvwasi_path_link(uvwasi_t* uvwasi,
177+
uvwasi_fd_t old_fd,
178+
uvwasi_lookupflags_t old_flags,
179+
const char* old_path,
180+
size_t old_path_len,
181+
uvwasi_fd_t new_fd,
182+
const char* new_path,
183+
size_t new_path_len);
184+
uvwasi_errno_t uvwasi_path_open(uvwasi_t* uvwasi,
185+
uvwasi_fd_t dirfd,
186+
uvwasi_lookupflags_t dirflags,
187+
const char* path,
188+
size_t path_len,
189+
uvwasi_oflags_t o_flags,
190+
uvwasi_rights_t fs_rights_base,
191+
uvwasi_rights_t fs_rights_inheriting,
192+
uvwasi_fdflags_t fs_flags,
193+
uvwasi_fd_t* fd);
194+
uvwasi_errno_t uvwasi_path_readlink(uvwasi_t* uvwasi,
195+
uvwasi_fd_t fd,
196+
const char* path,
197+
size_t path_len,
198+
char* buf,
199+
size_t buf_len,
200+
size_t* bufused);
201+
uvwasi_errno_t uvwasi_path_remove_directory(uvwasi_t* uvwasi,
202+
uvwasi_fd_t fd,
203+
const char* path,
204+
size_t path_len);
205+
uvwasi_errno_t uvwasi_path_rename(uvwasi_t* uvwasi,
206+
uvwasi_fd_t old_fd,
207+
const char* old_path,
208+
size_t old_path_len,
209+
uvwasi_fd_t new_fd,
210+
const char* new_path,
211+
size_t new_path_len);
212+
uvwasi_errno_t uvwasi_path_symlink(uvwasi_t* uvwasi,
213+
const char* old_path,
214+
size_t old_path_len,
215+
uvwasi_fd_t fd,
216+
const char* new_path,
217+
size_t new_path_len);
218+
uvwasi_errno_t uvwasi_path_unlink_file(uvwasi_t* uvwasi,
219+
uvwasi_fd_t fd,
220+
const char* path,
221+
size_t path_len);
222+
uvwasi_errno_t uvwasi_poll_oneoff(uvwasi_t* uvwasi,
223+
const uvwasi_subscription_t* in,
224+
uvwasi_event_t* out,
225+
size_t nsubscriptions,
226+
size_t* nevents);
227+
uvwasi_errno_t uvwasi_proc_exit(uvwasi_t* uvwasi, uvwasi_exitcode_t rval);
228+
uvwasi_errno_t uvwasi_proc_raise(uvwasi_t* uvwasi, uvwasi_signal_t sig);
229+
uvwasi_errno_t uvwasi_random_get(uvwasi_t* uvwasi, void* buf, size_t buf_len);
230+
uvwasi_errno_t uvwasi_sched_yield(uvwasi_t* uvwasi);
231+
uvwasi_errno_t uvwasi_sock_recv(uvwasi_t* uvwasi,
232+
uvwasi_fd_t sock,
233+
const uvwasi_iovec_t* ri_data,
234+
size_t ri_data_len,
235+
uvwasi_riflags_t ri_flags,
236+
size_t* ro_datalen,
237+
uvwasi_roflags_t* ro_flags);
238+
uvwasi_errno_t uvwasi_sock_send(uvwasi_t* uvwasi,
239+
uvwasi_fd_t sock,
240+
const uvwasi_ciovec_t* si_data,
241+
size_t si_data_len,
242+
uvwasi_siflags_t si_flags,
243+
size_t* so_datalen);
244+
uvwasi_errno_t uvwasi_sock_shutdown(uvwasi_t* uvwasi,
245+
uvwasi_fd_t sock,
246+
uvwasi_sdflags_t how);
247+
248+
#ifdef __cplusplus
249+
}
250+
#endif
251+
252+
#endif /* __UVWASI_H__ */

0 commit comments

Comments
 (0)