wasi: introduce initial WASI support · nodejs/node@9ec53cf · GitHub
Skip to content

Commit 9ec53cf

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 b91d22c commit 9ec53cf

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

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_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

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+
# 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

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+
#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

Lines changed: 252 additions & 0 deletions

0 commit comments

Comments
 (0)