Skip to content

Commit b6ce736

Browse files
cjihrigtargos
authored andcommitted
wasi: introduce initial WASI support
Co-authored-by: Gus Caplan <me@gus.host> Co-authored-by: Daniel Bevenius <daniel.bevenius@gmail.com> Co-authored-by: Jiawen Geng <technicalcute@gmail.com> Co-authored-by: Tobias Nießen <tniessen@tnie.de> Co-authored-by: Chengzhong Wu <legendecas@gmail.com> PR-URL: #30258 Refs: #27850 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 4de6097 commit b6ce736

84 files changed

Lines changed: 12753 additions & 4 deletions

Some content is hidden

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

‎LICENSE‎

Lines changed: 25 additions & 0 deletions
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‎

Lines changed: 21 additions & 0 deletions
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‎

Lines changed: 13 additions & 0 deletions
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_tuvwasi__clock_gettime_realtime(uvwasi_timestamp_t*time);
7+
uvwasi_errno_tuvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t*time);
8+
uvwasi_errno_tuvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t*time);
9+
10+
uvwasi_errno_tuvwasi__clock_getres_process_cputime(uvwasi_timestamp_t*time);
11+
uvwasi_errno_tuvwasi__clock_getres_thread_cputime(uvwasi_timestamp_t*time);
12+
13+
#endif/* __UVWASI_CLOCKS_H__ */

‎deps/uvwasi/include/fd_table.h‎

Lines changed: 60 additions & 0 deletions
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+
# definePATH_MAX_BYTES (MAX_PATH * 4)
14+
#else
15+
# include<limits.h>
16+
# definePATH_MAX_BYTES (PATH_MAX)
17+
#endif
18+
19+
20+
structuvwasi_fd_wrap_t {
21+
uvwasi_fd_tid;
22+
uv_filefd;
23+
charpath[PATH_MAX_BYTES];
24+
charreal_path[PATH_MAX_BYTES];
25+
uvwasi_filetype_ttype;
26+
uvwasi_rights_trights_base;
27+
uvwasi_rights_trights_inheriting;
28+
intpreopen;
29+
intvalid;
30+
};
31+
32+
structuvwasi_fd_table_t {
33+
structuvwasi_fd_wrap_t*fds;
34+
uint32_tsize;
35+
uint32_tused;
36+
};
37+
38+
uvwasi_errno_tuvwasi_fd_table_init(structuvwasi_fd_table_t*table,
39+
uint32_tinit_size);
40+
voiduvwasi_fd_table_free(structuvwasi_fd_table_t*table);
41+
uvwasi_errno_tuvwasi_fd_table_insert_preopen(structuvwasi_fd_table_t*table,
42+
constuv_filefd,
43+
constchar*path,
44+
constchar*real_path);
45+
uvwasi_errno_tuvwasi_fd_table_insert_fd(structuvwasi_fd_table_t*table,
46+
constuv_filefd,
47+
constintflags,
48+
constchar*path,
49+
uvwasi_rights_trights_base,
50+
uvwasi_rights_trights_inheriting,
51+
structuvwasi_fd_wrap_t*wrap);
52+
uvwasi_errno_tuvwasi_fd_table_get(conststructuvwasi_fd_table_t*table,
53+
constuvwasi_fd_tid,
54+
structuvwasi_fd_wrap_t**wrap,
55+
uvwasi_rights_trights_base,
56+
uvwasi_rights_trights_inheriting);
57+
uvwasi_errno_tuvwasi_fd_table_remove(structuvwasi_fd_table_t*table,
58+
constuvwasi_fd_tid);
59+
60+
#endif/* __UVWASI_FD_TABLE_H__ */

‎deps/uvwasi/include/uv_mapping.h‎

Lines changed: 15 additions & 0 deletions
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+
#defineNANOS_PER_SEC 1000000000
8+
9+
uvwasi_errno_tuvwasi__translate_uv_error(interr);
10+
intuvwasi__translate_to_uv_signal(uvwasi_signal_tsig);
11+
uvwasi_timestamp_tuvwasi__timespec_to_timestamp(constuv_timespec_t*ts);
12+
uvwasi_filetype_tuvwasi__stat_to_filetype(constuv_stat_t*stat);
13+
voiduvwasi__stat_to_filestat(constuv_stat_t*stat, uvwasi_filestat_t*fs);
14+
15+
#endif/* __UVWASI_UV_MAPPING_H__ */

‎deps/uvwasi/include/uvwasi.h‎

Lines changed: 252 additions & 0 deletions
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+
#defineUVWASI_VERSION_MAJOR 0
13+
#defineUVWASI_VERSION_MINOR 0
14+
#defineUVWASI_VERSION_PATCH 1
15+
#defineUVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
16+
(UVWASI_VERSION_MINOR << 8) | \
17+
(UVWASI_VERSION_PATCH))
18+
#defineUVWASI_STRINGIFY(v) UVWASI_STRINGIFY_HELPER(v)
19+
#defineUVWASI_STRINGIFY_HELPER(v) #v
20+
#defineUVWASI_VERSION_STRING UVWASI_STRINGIFY(UVWASI_VERSION_MAJOR) "." \
21+
UVWASI_STRINGIFY(UVWASI_VERSION_MINOR) "." \
22+
UVWASI_STRINGIFY(UVWASI_VERSION_PATCH)
23+
24+
25+
typedefstructuvwasi_s {
26+
structuvwasi_fd_table_tfds;
27+
size_targc;
28+
char**argv;
29+
char*argv_buf;
30+
size_targv_buf_size;
31+
size_tenvc;
32+
char**env;
33+
char*env_buf;
34+
size_tenv_buf_size;
35+
} uvwasi_t;
36+
37+
typedefstructuvwasi_preopen_s {
38+
char*mapped_path;
39+
char*real_path;
40+
} uvwasi_preopen_t;
41+
42+
typedefstructuvwasi_options_s {
43+
size_tfd_table_size;
44+
size_tpreopenc;
45+
uvwasi_preopen_t*preopens;
46+
size_targc;
47+
char**argv;
48+
char**envp;
49+
} uvwasi_options_t;
50+
51+
52+
// Embedder API.
53+
uvwasi_errno_tuvwasi_init(uvwasi_t*uvwasi, uvwasi_options_t*options);
54+
voiduvwasi_destroy(uvwasi_t*uvwasi);
55+
uvwasi_errno_tuvwasi_embedder_remap_fd(uvwasi_t*uvwasi,
56+
constuvwasi_fd_tfd,
57+
uv_filenew_host_fd);
58+
59+
60+
// WASI system call API.
61+
uvwasi_errno_tuvwasi_args_get(uvwasi_t*uvwasi, char**argv, char*argv_buf);
62+
uvwasi_errno_tuvwasi_args_sizes_get(uvwasi_t*uvwasi,
63+
size_t*argc,
64+
size_t*argv_buf_size);
65+
uvwasi_errno_tuvwasi_clock_res_get(uvwasi_t*uvwasi,
66+
uvwasi_clockid_tclock_id,
67+
uvwasi_timestamp_t*resolution);
68+
uvwasi_errno_tuvwasi_clock_time_get(uvwasi_t*uvwasi,
69+
uvwasi_clockid_tclock_id,
70+
uvwasi_timestamp_tprecision,
71+
uvwasi_timestamp_t*time);
72+
uvwasi_errno_tuvwasi_environ_get(uvwasi_t*uvwasi,
73+
char**environment,
74+
char*environ_buf);
75+
uvwasi_errno_tuvwasi_environ_sizes_get(uvwasi_t*uvwasi,
76+
size_t*environ_count,
77+
size_t*environ_buf_size);
78+
uvwasi_errno_tuvwasi_fd_advise(uvwasi_t*uvwasi,
79+
uvwasi_fd_tfd,
80+
uvwasi_filesize_toffset,
81+
uvwasi_filesize_tlen,
82+
uvwasi_advice_tadvice);
83+
uvwasi_errno_tuvwasi_fd_allocate(uvwasi_t*uvwasi,
84+
uvwasi_fd_tfd,
85+
uvwasi_filesize_toffset,
86+
uvwasi_filesize_tlen);
87+
uvwasi_errno_tuvwasi_fd_close(uvwasi_t*uvwasi, uvwasi_fd_tfd);
88+
uvwasi_errno_tuvwasi_fd_datasync(uvwasi_t*uvwasi, uvwasi_fd_tfd);
89+
uvwasi_errno_tuvwasi_fd_fdstat_get(uvwasi_t*uvwasi,
90+
uvwasi_fd_tfd,
91+
uvwasi_fdstat_t*buf);
92+
uvwasi_errno_tuvwasi_fd_fdstat_set_flags(uvwasi_t*uvwasi,
93+
uvwasi_fd_tfd,
94+
uvwasi_fdflags_tflags);
95+
uvwasi_errno_tuvwasi_fd_fdstat_set_rights(uvwasi_t*uvwasi,
96+
uvwasi_fd_tfd,
97+
uvwasi_rights_tfs_rights_base,
98+
uvwasi_rights_tfs_rights_inheriting
99+
);
100+
uvwasi_errno_tuvwasi_fd_filestat_get(uvwasi_t*uvwasi,
101+
uvwasi_fd_tfd,
102+
uvwasi_filestat_t*buf);
103+
uvwasi_errno_tuvwasi_fd_filestat_set_size(uvwasi_t*uvwasi,
104+
uvwasi_fd_tfd,
105+
uvwasi_filesize_tst_size);
106+
uvwasi_errno_tuvwasi_fd_filestat_set_times(uvwasi_t*uvwasi,
107+
uvwasi_fd_tfd,
108+
uvwasi_timestamp_tst_atim,
109+
uvwasi_timestamp_tst_mtim,
110+
uvwasi_fstflags_tfst_flags);
111+
uvwasi_errno_tuvwasi_fd_pread(uvwasi_t*uvwasi,
112+
uvwasi_fd_tfd,
113+
constuvwasi_iovec_t*iovs,
114+
size_tiovs_len,
115+
uvwasi_filesize_toffset,
116+
size_t*nread);
117+
uvwasi_errno_tuvwasi_fd_prestat_get(uvwasi_t*uvwasi,
118+
uvwasi_fd_tfd,
119+
uvwasi_prestat_t*buf);
120+
uvwasi_errno_tuvwasi_fd_prestat_dir_name(uvwasi_t*uvwasi,
121+
uvwasi_fd_tfd,
122+
char*path,
123+
size_tpath_len);
124+
uvwasi_errno_tuvwasi_fd_pwrite(uvwasi_t*uvwasi,
125+
uvwasi_fd_tfd,
126+
constuvwasi_ciovec_t*iovs,
127+
size_tiovs_len,
128+
uvwasi_filesize_toffset,
129+
size_t*nwritten);
130+
uvwasi_errno_tuvwasi_fd_read(uvwasi_t*uvwasi,
131+
uvwasi_fd_tfd,
132+
constuvwasi_iovec_t*iovs,
133+
size_tiovs_len,
134+
size_t*nread);
135+
uvwasi_errno_tuvwasi_fd_readdir(uvwasi_t*uvwasi,
136+
uvwasi_fd_tfd,
137+
void*buf,
138+
size_tbuf_len,
139+
uvwasi_dircookie_tcookie,
140+
size_t*bufused);
141+
uvwasi_errno_tuvwasi_fd_renumber(uvwasi_t*uvwasi,
142+
uvwasi_fd_tfrom,
143+
uvwasi_fd_tto);
144+
uvwasi_errno_tuvwasi_fd_seek(uvwasi_t*uvwasi,
145+
uvwasi_fd_tfd,
146+
uvwasi_filedelta_toffset,
147+
uvwasi_whence_twhence,
148+
uvwasi_filesize_t*newoffset);
149+
uvwasi_errno_tuvwasi_fd_sync(uvwasi_t*uvwasi, uvwasi_fd_tfd);
150+
uvwasi_errno_tuvwasi_fd_tell(uvwasi_t*uvwasi,
151+
uvwasi_fd_tfd,
152+
uvwasi_filesize_t*offset);
153+
uvwasi_errno_tuvwasi_fd_write(uvwasi_t*uvwasi,
154+
uvwasi_fd_tfd,
155+
constuvwasi_ciovec_t*iovs,
156+
size_tiovs_len,
157+
size_t*nwritten);
158+
uvwasi_errno_tuvwasi_path_create_directory(uvwasi_t*uvwasi,
159+
uvwasi_fd_tfd,
160+
constchar*path,
161+
size_tpath_len);
162+
uvwasi_errno_tuvwasi_path_filestat_get(uvwasi_t*uvwasi,
163+
uvwasi_fd_tfd,
164+
uvwasi_lookupflags_tflags,
165+
constchar*path,
166+
size_tpath_len,
167+
uvwasi_filestat_t*buf);
168+
uvwasi_errno_tuvwasi_path_filestat_set_times(uvwasi_t*uvwasi,
169+
uvwasi_fd_tfd,
170+
uvwasi_lookupflags_tflags,
171+
constchar*path,
172+
size_tpath_len,
173+
uvwasi_timestamp_tst_atim,
174+
uvwasi_timestamp_tst_mtim,
175+
uvwasi_fstflags_tfst_flags);
176+
uvwasi_errno_tuvwasi_path_link(uvwasi_t*uvwasi,
177+
uvwasi_fd_told_fd,
178+
uvwasi_lookupflags_told_flags,
179+
constchar*old_path,
180+
size_told_path_len,
181+
uvwasi_fd_tnew_fd,
182+
constchar*new_path,
183+
size_tnew_path_len);
184+
uvwasi_errno_tuvwasi_path_open(uvwasi_t*uvwasi,
185+
uvwasi_fd_tdirfd,
186+
uvwasi_lookupflags_tdirflags,
187+
constchar*path,
188+
size_tpath_len,
189+
uvwasi_oflags_to_flags,
190+
uvwasi_rights_tfs_rights_base,
191+
uvwasi_rights_tfs_rights_inheriting,
192+
uvwasi_fdflags_tfs_flags,
193+
uvwasi_fd_t*fd);
194+
uvwasi_errno_tuvwasi_path_readlink(uvwasi_t*uvwasi,
195+
uvwasi_fd_tfd,
196+
constchar*path,
197+
size_tpath_len,
198+
char*buf,
199+
size_tbuf_len,
200+
size_t*bufused);
201+
uvwasi_errno_tuvwasi_path_remove_directory(uvwasi_t*uvwasi,
202+
uvwasi_fd_tfd,
203+
constchar*path,
204+
size_tpath_len);
205+
uvwasi_errno_tuvwasi_path_rename(uvwasi_t*uvwasi,
206+
uvwasi_fd_told_fd,
207+
constchar*old_path,
208+
size_told_path_len,
209+
uvwasi_fd_tnew_fd,
210+
constchar*new_path,
211+
size_tnew_path_len);
212+
uvwasi_errno_tuvwasi_path_symlink(uvwasi_t*uvwasi,
213+
constchar*old_path,
214+
size_told_path_len,
215+
uvwasi_fd_tfd,
216+
constchar*new_path,
217+
size_tnew_path_len);
218+
uvwasi_errno_tuvwasi_path_unlink_file(uvwasi_t*uvwasi,
219+
uvwasi_fd_tfd,
220+
constchar*path,
221+
size_tpath_len);
222+
uvwasi_errno_tuvwasi_poll_oneoff(uvwasi_t*uvwasi,
223+
constuvwasi_subscription_t*in,
224+
uvwasi_event_t*out,
225+
size_tnsubscriptions,
226+
size_t*nevents);
227+
uvwasi_errno_tuvwasi_proc_exit(uvwasi_t*uvwasi, uvwasi_exitcode_trval);
228+
uvwasi_errno_tuvwasi_proc_raise(uvwasi_t*uvwasi, uvwasi_signal_tsig);
229+
uvwasi_errno_tuvwasi_random_get(uvwasi_t*uvwasi, void*buf, size_tbuf_len);
230+
uvwasi_errno_tuvwasi_sched_yield(uvwasi_t*uvwasi);
231+
uvwasi_errno_tuvwasi_sock_recv(uvwasi_t*uvwasi,
232+
uvwasi_fd_tsock,
233+
constuvwasi_iovec_t*ri_data,
234+
size_tri_data_len,
235+
uvwasi_riflags_tri_flags,
236+
size_t*ro_datalen,
237+
uvwasi_roflags_t*ro_flags);
238+
uvwasi_errno_tuvwasi_sock_send(uvwasi_t*uvwasi,
239+
uvwasi_fd_tsock,
240+
constuvwasi_ciovec_t*si_data,
241+
size_tsi_data_len,
242+
uvwasi_siflags_tsi_flags,
243+
size_t*so_datalen);
244+
uvwasi_errno_tuvwasi_sock_shutdown(uvwasi_t*uvwasi,
245+
uvwasi_fd_tsock,
246+
uvwasi_sdflags_thow);
247+
248+
#ifdef__cplusplus
249+
}
250+
#endif
251+
252+
#endif/* __UVWASI_H__ */

0 commit comments

Comments
 (0)