1 #ifndef __UVWASI_WASI_TYPES_H__
2 #define __UVWASI_WASI_TYPES_H__
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 
7 /* API: https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md */
8 
9 typedef uint32_t uvwasi_size_t;
10 
11 typedef uint8_t uvwasi_advice_t;
12 #define UVWASI_ADVICE_NORMAL     0
13 #define UVWASI_ADVICE_SEQUENTIAL 1
14 #define UVWASI_ADVICE_RANDOM     2
15 #define UVWASI_ADVICE_WILLNEED   3
16 #define UVWASI_ADVICE_DONTNEED   4
17 #define UVWASI_ADVICE_NOREUSE    5
18 
19 typedef struct uvwasi_ciovec_s {
20   const void* buf;
21   uvwasi_size_t buf_len;
22 } uvwasi_ciovec_t;
23 
24 typedef uint32_t uvwasi_clockid_t;
25 #define UVWASI_CLOCK_REALTIME           0
26 #define UVWASI_CLOCK_MONOTONIC          1
27 #define UVWASI_CLOCK_PROCESS_CPUTIME_ID 2
28 #define UVWASI_CLOCK_THREAD_CPUTIME_ID  3
29 
30 typedef uint64_t uvwasi_device_t;
31 
32 typedef uint64_t uvwasi_dircookie_t;
33 #define UVWASI_DIRCOOKIE_START 0
34 
35 typedef uint16_t uvwasi_errno_t;
36 #define UVWASI_ESUCCESS         0
37 #define UVWASI_E2BIG            1
38 #define UVWASI_EACCES           2
39 #define UVWASI_EADDRINUSE       3
40 #define UVWASI_EADDRNOTAVAIL    4
41 #define UVWASI_EAFNOSUPPORT     5
42 #define UVWASI_EAGAIN           6
43 #define UVWASI_EALREADY         7
44 #define UVWASI_EBADF            8
45 #define UVWASI_EBADMSG          9
46 #define UVWASI_EBUSY           10
47 #define UVWASI_ECANCELED       11
48 #define UVWASI_ECHILD          12
49 #define UVWASI_ECONNABORTED    13
50 #define UVWASI_ECONNREFUSED    14
51 #define UVWASI_ECONNRESET      15
52 #define UVWASI_EDEADLK         16
53 #define UVWASI_EDESTADDRREQ    17
54 #define UVWASI_EDOM            18
55 #define UVWASI_EDQUOT          19
56 #define UVWASI_EEXIST          20
57 #define UVWASI_EFAULT          21
58 #define UVWASI_EFBIG           22
59 #define UVWASI_EHOSTUNREACH    23
60 #define UVWASI_EIDRM           24
61 #define UVWASI_EILSEQ          25
62 #define UVWASI_EINPROGRESS     26
63 #define UVWASI_EINTR           27
64 #define UVWASI_EINVAL          28
65 #define UVWASI_EIO             29
66 #define UVWASI_EISCONN         30
67 #define UVWASI_EISDIR          31
68 #define UVWASI_ELOOP           32
69 #define UVWASI_EMFILE          33
70 #define UVWASI_EMLINK          34
71 #define UVWASI_EMSGSIZE        35
72 #define UVWASI_EMULTIHOP       36
73 #define UVWASI_ENAMETOOLONG    37
74 #define UVWASI_ENETDOWN        38
75 #define UVWASI_ENETRESET       39
76 #define UVWASI_ENETUNREACH     40
77 #define UVWASI_ENFILE          41
78 #define UVWASI_ENOBUFS         42
79 #define UVWASI_ENODEV          43
80 #define UVWASI_ENOENT          44
81 #define UVWASI_ENOEXEC         45
82 #define UVWASI_ENOLCK          46
83 #define UVWASI_ENOLINK         47
84 #define UVWASI_ENOMEM          48
85 #define UVWASI_ENOMSG          49
86 #define UVWASI_ENOPROTOOPT     50
87 #define UVWASI_ENOSPC          51
88 #define UVWASI_ENOSYS          52
89 #define UVWASI_ENOTCONN        53
90 #define UVWASI_ENOTDIR         54
91 #define UVWASI_ENOTEMPTY       55
92 #define UVWASI_ENOTRECOVERABLE 56
93 #define UVWASI_ENOTSOCK        57
94 #define UVWASI_ENOTSUP         58
95 #define UVWASI_ENOTTY          59
96 #define UVWASI_ENXIO           60
97 #define UVWASI_EOVERFLOW       61
98 #define UVWASI_EOWNERDEAD      62
99 #define UVWASI_EPERM           63
100 #define UVWASI_EPIPE           64
101 #define UVWASI_EPROTO          65
102 #define UVWASI_EPROTONOSUPPORT 66
103 #define UVWASI_EPROTOTYPE      67
104 #define UVWASI_ERANGE          68
105 #define UVWASI_EROFS           69
106 #define UVWASI_ESPIPE          70
107 #define UVWASI_ESRCH           71
108 #define UVWASI_ESTALE          72
109 #define UVWASI_ETIMEDOUT       73
110 #define UVWASI_ETXTBSY         74
111 #define UVWASI_EXDEV           75
112 #define UVWASI_ENOTCAPABLE     76
113 
114 typedef uint16_t uvwasi_eventrwflags_t;          /* Bitfield */
115 #define UVWASI_EVENT_FD_READWRITE_HANGUP (1 << 0)
116 
117 typedef uint8_t uvwasi_eventtype_t;
118 #define UVWASI_EVENTTYPE_CLOCK    0
119 #define UVWASI_EVENTTYPE_FD_READ  1
120 #define UVWASI_EVENTTYPE_FD_WRITE 2
121 
122 typedef uint32_t uvwasi_exitcode_t;
123 
124 typedef uint32_t uvwasi_fd_t;
125 
126 typedef uint16_t uvwasi_fdflags_t;               /* Bitfield */
127 #define UVWASI_FDFLAG_APPEND   (1 << 0)
128 #define UVWASI_FDFLAG_DSYNC    (1 << 1)
129 #define UVWASI_FDFLAG_NONBLOCK (1 << 2)
130 #define UVWASI_FDFLAG_RSYNC    (1 << 3)
131 #define UVWASI_FDFLAG_SYNC     (1 << 4)
132 
133 typedef int64_t uvwasi_filedelta_t;
134 
135 typedef uint64_t uvwasi_filesize_t;
136 
137 typedef uint8_t uvwasi_filetype_t;
138 #define UVWASI_FILETYPE_UNKNOWN          0
139 #define UVWASI_FILETYPE_BLOCK_DEVICE     1
140 #define UVWASI_FILETYPE_CHARACTER_DEVICE 2
141 #define UVWASI_FILETYPE_DIRECTORY        3
142 #define UVWASI_FILETYPE_REGULAR_FILE     4
143 #define UVWASI_FILETYPE_SOCKET_DGRAM     5
144 #define UVWASI_FILETYPE_SOCKET_STREAM    6
145 #define UVWASI_FILETYPE_SYMBOLIC_LINK    7
146 
147 typedef uint16_t uvwasi_fstflags_t;              /* Bitfield */
148 #define UVWASI_FILESTAT_SET_ATIM      (1 << 0)
149 #define UVWASI_FILESTAT_SET_ATIM_NOW  (1 << 1)
150 #define UVWASI_FILESTAT_SET_MTIM      (1 << 2)
151 #define UVWASI_FILESTAT_SET_MTIM_NOW  (1 << 3)
152 
153 typedef uint64_t uvwasi_inode_t;
154 
155 typedef struct uvwasi_iovec_s {
156   void* buf;
157   uvwasi_size_t buf_len;
158 } uvwasi_iovec_t;
159 
160 typedef uint64_t uvwasi_linkcount_t;
161 
162 typedef uint32_t uvwasi_lookupflags_t;           /* Bitfield */
163 #define UVWASI_LOOKUP_SYMLINK_FOLLOW (1 << 0)
164 
165 typedef uint16_t uvwasi_oflags_t;                /* Bitfield */
166 #define UVWASI_O_CREAT     (1 << 0)
167 #define UVWASI_O_DIRECTORY (1 << 1)
168 #define UVWASI_O_EXCL      (1 << 2)
169 #define UVWASI_O_TRUNC     (1 << 3)
170 
171 typedef uint8_t uvwasi_preopentype_t;
172 #define UVWASI_PREOPENTYPE_DIR 0
173 
174 typedef struct uvwasi_prestat_s {
175   uvwasi_preopentype_t pr_type;
176   union uvwasi_prestat_u {
177     struct uvwasi_prestat_dir_t {
178       uvwasi_size_t pr_name_len;
179     } dir;
180   } u;
181 } uvwasi_prestat_t;
182 
183 typedef uint16_t uvwasi_riflags_t;               /* Bitfield */
184 #define UVWASI_SOCK_RECV_PEEK    (1 << 0)
185 #define UVWASI_SOCK_RECV_WAITALL (1 << 1)
186 
187 typedef uint64_t uvwasi_rights_t;                /* Bitfield */
188 #define UVWASI_RIGHT_FD_DATASYNC             (1 << 0)
189 #define UVWASI_RIGHT_FD_READ                 (1 << 1)
190 #define UVWASI_RIGHT_FD_SEEK                 (1 << 2)
191 #define UVWASI_RIGHT_FD_FDSTAT_SET_FLAGS     (1 << 3)
192 #define UVWASI_RIGHT_FD_SYNC                 (1 << 4)
193 #define UVWASI_RIGHT_FD_TELL                 (1 << 5)
194 #define UVWASI_RIGHT_FD_WRITE                (1 << 6)
195 #define UVWASI_RIGHT_FD_ADVISE               (1 << 7)
196 #define UVWASI_RIGHT_FD_ALLOCATE             (1 << 8)
197 #define UVWASI_RIGHT_PATH_CREATE_DIRECTORY   (1 << 9)
198 #define UVWASI_RIGHT_PATH_CREATE_FILE        (1 << 10)
199 #define UVWASI_RIGHT_PATH_LINK_SOURCE        (1 << 11)
200 #define UVWASI_RIGHT_PATH_LINK_TARGET        (1 << 12)
201 #define UVWASI_RIGHT_PATH_OPEN               (1 << 13)
202 #define UVWASI_RIGHT_FD_READDIR              (1 << 14)
203 #define UVWASI_RIGHT_PATH_READLINK           (1 << 15)
204 #define UVWASI_RIGHT_PATH_RENAME_SOURCE      (1 << 16)
205 #define UVWASI_RIGHT_PATH_RENAME_TARGET      (1 << 17)
206 #define UVWASI_RIGHT_PATH_FILESTAT_GET       (1 << 18)
207 #define UVWASI_RIGHT_PATH_FILESTAT_SET_SIZE  (1 << 19)
208 #define UVWASI_RIGHT_PATH_FILESTAT_SET_TIMES (1 << 20)
209 #define UVWASI_RIGHT_FD_FILESTAT_GET         (1 << 21)
210 #define UVWASI_RIGHT_FD_FILESTAT_SET_SIZE    (1 << 22)
211 #define UVWASI_RIGHT_FD_FILESTAT_SET_TIMES   (1 << 23)
212 #define UVWASI_RIGHT_PATH_SYMLINK            (1 << 24)
213 #define UVWASI_RIGHT_PATH_REMOVE_DIRECTORY   (1 << 25)
214 #define UVWASI_RIGHT_PATH_UNLINK_FILE        (1 << 26)
215 #define UVWASI_RIGHT_POLL_FD_READWRITE       (1 << 27)
216 #define UVWASI_RIGHT_SOCK_SHUTDOWN           (1 << 28)
217 
218 typedef uint16_t uvwasi_roflags_t;               /* Bitfield */
219 #define UVWASI_SOCK_RECV_DATA_TRUNCATED (1 << 0)
220 
221 typedef uint8_t uvwasi_sdflags_t;                /* Bitfield */
222 #define UVWASI_SHUT_RD (1 << 0)
223 #define UVWASI_SHUT_WR (1 << 1)
224 
225 typedef uint16_t uvwasi_siflags_t;               /* Bitfield */
226 
227 typedef uint8_t uvwasi_signal_t;
228 #define UVWASI_SIGHUP     1
229 #define UVWASI_SIGINT     2
230 #define UVWASI_SIGQUIT    3
231 #define UVWASI_SIGILL     4
232 #define UVWASI_SIGTRAP    5
233 #define UVWASI_SIGABRT    6
234 #define UVWASI_SIGBUS     7
235 #define UVWASI_SIGFPE     8
236 #define UVWASI_SIGKILL    9
237 #define UVWASI_SIGUSR1   10
238 #define UVWASI_SIGSEGV   11
239 #define UVWASI_SIGUSR2   12
240 #define UVWASI_SIGPIPE   13
241 #define UVWASI_SIGALRM   14
242 #define UVWASI_SIGTERM   15
243 #define UVWASI_SIGCHLD   16
244 #define UVWASI_SIGCONT   17
245 #define UVWASI_SIGSTOP   18
246 #define UVWASI_SIGTSTP   19
247 #define UVWASI_SIGTTIN   20
248 #define UVWASI_SIGTTOU   21
249 #define UVWASI_SIGURG    22
250 #define UVWASI_SIGXCPU   23
251 #define UVWASI_SIGXFSZ   24
252 #define UVWASI_SIGVTALRM 25
253 #define UVWASI_SIGPROF   26
254 #define UVWASI_SIGWINCH  27
255 #define UVWASI_SIGPOLL   28
256 #define UVWASI_SIGPWR    29
257 #define UVWASI_SIGSYS    30
258 
259 typedef uint16_t uvwasi_subclockflags_t;         /* Bitfield */
260 #define UVWASI_SUBSCRIPTION_CLOCK_ABSTIME (1 << 0)
261 
262 typedef uint64_t uvwasi_timestamp_t;
263 
264 typedef uint64_t uvwasi_userdata_t;
265 
266 typedef struct uvwasi_subscription_s {
267   uvwasi_userdata_t userdata;
268   uvwasi_eventtype_t type;
269   union {
270     struct {
271       uvwasi_clockid_t clock_id;
272       uvwasi_timestamp_t timeout;
273       uvwasi_timestamp_t precision;
274       uvwasi_subclockflags_t flags;
275     } clock;
276     struct {
277       uvwasi_fd_t fd;
278     } fd_readwrite;
279   } u;
280 } uvwasi_subscription_t;
281 
282 typedef struct uvwasi_dirent_s {
283   uvwasi_dircookie_t d_next;
284   uvwasi_inode_t d_ino;
285   uint32_t d_namlen;
286   uvwasi_filetype_t d_type;
287 } uvwasi_dirent_t;
288 
289 typedef struct uvwasi_fdstat_s {
290   uvwasi_filetype_t fs_filetype;
291   uvwasi_fdflags_t fs_flags;
292   uvwasi_rights_t fs_rights_base;
293   uvwasi_rights_t fs_rights_inheriting;
294 } uvwasi_fdstat_t;
295 
296 typedef struct uvwasi_filestat_s {
297   uvwasi_device_t st_dev;
298   uvwasi_inode_t st_ino;
299   uvwasi_filetype_t st_filetype;
300   uvwasi_linkcount_t st_nlink;
301   uvwasi_filesize_t st_size;
302   uvwasi_timestamp_t st_atim;
303   uvwasi_timestamp_t st_mtim;
304   uvwasi_timestamp_t st_ctim;
305 } uvwasi_filestat_t;
306 
307 typedef struct uvwasi_event_s {
308   uvwasi_userdata_t userdata;
309   uvwasi_errno_t error;
310   uvwasi_eventtype_t type;
311   union {
312     struct {
313       uvwasi_filesize_t nbytes;
314       uvwasi_eventrwflags_t flags;
315     } fd_readwrite;
316   } u;
317 } uvwasi_event_t;
318 
319 typedef uint8_t uvwasi_whence_t;
320 #define UVWASI_WHENCE_SET 0
321 #define UVWASI_WHENCE_CUR 1
322 #define UVWASI_WHENCE_END 2
323 
324 #endif /* __UVWASI_WASI_TYPES_H__ */
325