]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/headers/public/wasi/api.h
c header generation updated for reorganized witx ast (#139)
[wasi-libc.git] / libc-bottom-half / headers / public / wasi / api.h
CommitLineData
446cb3f1 1/**
cd74e1d9
DG
2 * THIS FILE IS AUTO-GENERATED from the following files:
3 * typenames.witx, wasi_snapshot_preview1.witx
446cb3f1
DG
4 *
5 * @file
cd74e1d9 6 * This file describes the [WASI] interface, consisting of functions, types,
446cb3f1
DG
7 * and defined values (macros).
8 *
9 * The interface described here is greatly inspired by [CloudABI]'s clean,
10 * thoughtfully-designed, cabability-oriented, POSIX-style API.
11 *
12 * [CloudABI]: https://github.com/NuxiNL/cloudlibc
cd74e1d9 13 * [WASI]: https://github.com/WebAssembly/WASI/
446cb3f1
DG
14 */
15
16#ifndef __wasi_api_h
17#define __wasi_api_h
18
19#ifndef __wasi__
20#error <wasi/api.h> is only supported on WASI platforms.
21#endif
22
23#include <stddef.h>
24#include <stdint.h>
25
26_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
27_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
28_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
29_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
30_Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
31_Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
32_Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
33_Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39// TODO: Encoding this in witx.
40#define __WASI_DIRCOOKIE_START (UINT64_C(0))
41typedef __SIZE_TYPE__ __wasi_size_t;
42
43/**
44 * Non-negative file size or length of a region within a file.
45 */
46typedef uint64_t __wasi_filesize_t;
47
48/**
49 * Timestamp in nanoseconds.
50 */
51typedef uint64_t __wasi_timestamp_t;
52
53/**
54 * Identifiers for clocks.
55 */
56typedef uint32_t __wasi_clockid_t;
57
58/**
59 * The clock measuring real time. Time value zero corresponds with
60 * 1970-01-01T00:00:00Z.
61 */
62#define __WASI_CLOCKID_REALTIME ((__wasi_clockid_t)0)
63
64/**
65 * The store-wide monotonic clock, which is defined as a clock measuring
66 * real time, whose value cannot be adjusted and which cannot have negative
67 * clock jumps. The epoch of this clock is undefined. The absolute time
68 * value of this clock therefore has no meaning.
69 */
70#define __WASI_CLOCKID_MONOTONIC ((__wasi_clockid_t)1)
71
72/**
73 * The CPU-time clock associated with the current process.
74 */
75#define __WASI_CLOCKID_PROCESS_CPUTIME_ID ((__wasi_clockid_t)2)
76
77/**
78 * The CPU-time clock associated with the current thread.
79 */
80#define __WASI_CLOCKID_THREAD_CPUTIME_ID ((__wasi_clockid_t)3)
81
82/**
83 * Error codes returned by functions.
84 * Not all of these error codes are returned by the functions provided by this
85 * API; some are used in higher-level library layers, and others are provided
86 * merely for alignment with POSIX.
87 */
88typedef uint16_t __wasi_errno_t;
89
90/**
91 * No error occurred. System call completed successfully.
92 */
93#define __WASI_ERRNO_SUCCESS ((__wasi_errno_t)0)
94
95/**
96 * Argument list too long.
97 */
98#define __WASI_ERRNO_2BIG ((__wasi_errno_t)1)
99
100/**
101 * Permission denied.
102 */
103#define __WASI_ERRNO_ACCES ((__wasi_errno_t)2)
104
105/**
106 * Address in use.
107 */
108#define __WASI_ERRNO_ADDRINUSE ((__wasi_errno_t)3)
109
110/**
111 * Address not available.
112 */
113#define __WASI_ERRNO_ADDRNOTAVAIL ((__wasi_errno_t)4)
114
115/**
116 * Address family not supported.
117 */
118#define __WASI_ERRNO_AFNOSUPPORT ((__wasi_errno_t)5)
119
120/**
121 * Resource unavailable, or operation would block.
122 */
123#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
124
125/**
126 * Connection already in progress.
127 */
128#define __WASI_ERRNO_ALREADY ((__wasi_errno_t)7)
129
130/**
131 * Bad file descriptor.
132 */
133#define __WASI_ERRNO_BADF ((__wasi_errno_t)8)
134
135/**
136 * Bad message.
137 */
138#define __WASI_ERRNO_BADMSG ((__wasi_errno_t)9)
139
140/**
141 * Device or resource busy.
142 */
143#define __WASI_ERRNO_BUSY ((__wasi_errno_t)10)
144
145/**
146 * Operation canceled.
147 */
148#define __WASI_ERRNO_CANCELED ((__wasi_errno_t)11)
149
150/**
151 * No child processes.
152 */
153#define __WASI_ERRNO_CHILD ((__wasi_errno_t)12)
154
155/**
156 * Connection aborted.
157 */
158#define __WASI_ERRNO_CONNABORTED ((__wasi_errno_t)13)
159
160/**
161 * Connection refused.
162 */
163#define __WASI_ERRNO_CONNREFUSED ((__wasi_errno_t)14)
164
165/**
166 * Connection reset.
167 */
168#define __WASI_ERRNO_CONNRESET ((__wasi_errno_t)15)
169
170/**
171 * Resource deadlock would occur.
172 */
173#define __WASI_ERRNO_DEADLK ((__wasi_errno_t)16)
174
175/**
176 * Destination address required.
177 */
178#define __WASI_ERRNO_DESTADDRREQ ((__wasi_errno_t)17)
179
180/**
181 * Mathematics argument out of domain of function.
182 */
183#define __WASI_ERRNO_DOM ((__wasi_errno_t)18)
184
185/**
186 * Reserved.
187 */
188#define __WASI_ERRNO_DQUOT ((__wasi_errno_t)19)
189
190/**
191 * File exists.
192 */
193#define __WASI_ERRNO_EXIST ((__wasi_errno_t)20)
194
195/**
196 * Bad address.
197 */
198#define __WASI_ERRNO_FAULT ((__wasi_errno_t)21)
199
200/**
201 * File too large.
202 */
203#define __WASI_ERRNO_FBIG ((__wasi_errno_t)22)
204
205/**
206 * Host is unreachable.
207 */
208#define __WASI_ERRNO_HOSTUNREACH ((__wasi_errno_t)23)
209
210/**
211 * Identifier removed.
212 */
213#define __WASI_ERRNO_IDRM ((__wasi_errno_t)24)
214
215/**
216 * Illegal byte sequence.
217 */
218#define __WASI_ERRNO_ILSEQ ((__wasi_errno_t)25)
219
220/**
221 * Operation in progress.
222 */
223#define __WASI_ERRNO_INPROGRESS ((__wasi_errno_t)26)
224
225/**
226 * Interrupted function.
227 */
228#define __WASI_ERRNO_INTR ((__wasi_errno_t)27)
229
230/**
231 * Invalid argument.
232 */
233#define __WASI_ERRNO_INVAL ((__wasi_errno_t)28)
234
235/**
236 * I/O error.
237 */
238#define __WASI_ERRNO_IO ((__wasi_errno_t)29)
239
240/**
241 * Socket is connected.
242 */
243#define __WASI_ERRNO_ISCONN ((__wasi_errno_t)30)
244
245/**
246 * Is a directory.
247 */
248#define __WASI_ERRNO_ISDIR ((__wasi_errno_t)31)
249
250/**
251 * Too many levels of symbolic links.
252 */
253#define __WASI_ERRNO_LOOP ((__wasi_errno_t)32)
254
255/**
256 * File descriptor value too large.
257 */
258#define __WASI_ERRNO_MFILE ((__wasi_errno_t)33)
259
260/**
261 * Too many links.
262 */
263#define __WASI_ERRNO_MLINK ((__wasi_errno_t)34)
264
265/**
266 * Message too large.
267 */
268#define __WASI_ERRNO_MSGSIZE ((__wasi_errno_t)35)
269
270/**
271 * Reserved.
272 */
273#define __WASI_ERRNO_MULTIHOP ((__wasi_errno_t)36)
274
275/**
276 * Filename too long.
277 */
278#define __WASI_ERRNO_NAMETOOLONG ((__wasi_errno_t)37)
279
280/**
281 * Network is down.
282 */
283#define __WASI_ERRNO_NETDOWN ((__wasi_errno_t)38)
284
285/**
286 * Connection aborted by network.
287 */
288#define __WASI_ERRNO_NETRESET ((__wasi_errno_t)39)
289
290/**
291 * Network unreachable.
292 */
293#define __WASI_ERRNO_NETUNREACH ((__wasi_errno_t)40)
294
295/**
296 * Too many files open in system.
297 */
298#define __WASI_ERRNO_NFILE ((__wasi_errno_t)41)
299
300/**
301 * No buffer space available.
302 */
303#define __WASI_ERRNO_NOBUFS ((__wasi_errno_t)42)
304
305/**
306 * No such device.
307 */
308#define __WASI_ERRNO_NODEV ((__wasi_errno_t)43)
309
310/**
311 * No such file or directory.
312 */
313#define __WASI_ERRNO_NOENT ((__wasi_errno_t)44)
314
315/**
316 * Executable file format error.
317 */
318#define __WASI_ERRNO_NOEXEC ((__wasi_errno_t)45)
319
320/**
321 * No locks available.
322 */
323#define __WASI_ERRNO_NOLCK ((__wasi_errno_t)46)
324
325/**
326 * Reserved.
327 */
328#define __WASI_ERRNO_NOLINK ((__wasi_errno_t)47)
329
330/**
331 * Not enough space.
332 */
333#define __WASI_ERRNO_NOMEM ((__wasi_errno_t)48)
334
335/**
336 * No message of the desired type.
337 */
338#define __WASI_ERRNO_NOMSG ((__wasi_errno_t)49)
339
340/**
341 * Protocol not available.
342 */
343#define __WASI_ERRNO_NOPROTOOPT ((__wasi_errno_t)50)
344
345/**
346 * No space left on device.
347 */
348#define __WASI_ERRNO_NOSPC ((__wasi_errno_t)51)
349
350/**
351 * Function not supported.
352 */
353#define __WASI_ERRNO_NOSYS ((__wasi_errno_t)52)
354
355/**
356 * The socket is not connected.
357 */
358#define __WASI_ERRNO_NOTCONN ((__wasi_errno_t)53)
359
360/**
361 * Not a directory or a symbolic link to a directory.
362 */
363#define __WASI_ERRNO_NOTDIR ((__wasi_errno_t)54)
364
365/**
366 * Directory not empty.
367 */
368#define __WASI_ERRNO_NOTEMPTY ((__wasi_errno_t)55)
369
370/**
371 * State not recoverable.
372 */
373#define __WASI_ERRNO_NOTRECOVERABLE ((__wasi_errno_t)56)
374
375/**
376 * Not a socket.
377 */
378#define __WASI_ERRNO_NOTSOCK ((__wasi_errno_t)57)
379
380/**
381 * Not supported, or operation not supported on socket.
382 */
383#define __WASI_ERRNO_NOTSUP ((__wasi_errno_t)58)
384
385/**
386 * Inappropriate I/O control operation.
387 */
388#define __WASI_ERRNO_NOTTY ((__wasi_errno_t)59)
389
390/**
391 * No such device or address.
392 */
393#define __WASI_ERRNO_NXIO ((__wasi_errno_t)60)
394
395/**
396 * Value too large to be stored in data type.
397 */
398#define __WASI_ERRNO_OVERFLOW ((__wasi_errno_t)61)
399
400/**
401 * Previous owner died.
402 */
403#define __WASI_ERRNO_OWNERDEAD ((__wasi_errno_t)62)
404
405/**
406 * Operation not permitted.
407 */
408#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
409
410/**
411 * Broken pipe.
412 */
413#define __WASI_ERRNO_PIPE ((__wasi_errno_t)64)
414
415/**
416 * Protocol error.
417 */
418#define __WASI_ERRNO_PROTO ((__wasi_errno_t)65)
419
420/**
421 * Protocol not supported.
422 */
423#define __WASI_ERRNO_PROTONOSUPPORT ((__wasi_errno_t)66)
424
425/**
426 * Protocol wrong type for socket.
427 */
428#define __WASI_ERRNO_PROTOTYPE ((__wasi_errno_t)67)
429
430/**
431 * Result too large.
432 */
433#define __WASI_ERRNO_RANGE ((__wasi_errno_t)68)
434
435/**
436 * Read-only file system.
437 */
438#define __WASI_ERRNO_ROFS ((__wasi_errno_t)69)
439
440/**
441 * Invalid seek.
442 */
443#define __WASI_ERRNO_SPIPE ((__wasi_errno_t)70)
444
445/**
446 * No such process.
447 */
448#define __WASI_ERRNO_SRCH ((__wasi_errno_t)71)
449
450/**
451 * Reserved.
452 */
453#define __WASI_ERRNO_STALE ((__wasi_errno_t)72)
454
455/**
456 * Connection timed out.
457 */
458#define __WASI_ERRNO_TIMEDOUT ((__wasi_errno_t)73)
459
460/**
461 * Text file busy.
462 */
463#define __WASI_ERRNO_TXTBSY ((__wasi_errno_t)74)
464
465/**
466 * Cross-device link.
467 */
468#define __WASI_ERRNO_XDEV ((__wasi_errno_t)75)
469
470/**
471 * Extension: Capabilities insufficient.
472 */
473#define __WASI_ERRNO_NOTCAPABLE ((__wasi_errno_t)76)
474
475/**
476 * File descriptor rights, determining which actions may be performed.
477 */
478typedef uint64_t __wasi_rights_t;
479
480/**
481 * The right to invoke `fd_datasync`.
482 * If `path_open` is set, includes the right to invoke
483 * `path_open` with `fdflag::dsync`.
484 */
485#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)1)
486
487/**
488 * The right to invoke `fd_read` and `sock_recv`.
489 * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
490 */
491#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)2)
492
493/**
494 * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
495 */
496#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)4)
497
498/**
499 * The right to invoke `fd_fdstat_set_flags`.
500 */
501#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)8)
502
503/**
504 * The right to invoke `fd_sync`.
505 * If `path_open` is set, includes the right to invoke
506 * `path_open` with `fdflag::rsync` and `fdflag::dsync`.
507 */
508#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)16)
509
510/**
511 * The right to invoke `fd_seek` in such a way that the file offset
512 * remains unaltered (i.e., `WHENCE_CUR` with offset zero), or to
513 * invoke `fd_tell`.
514 */
515#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)32)
516
517/**
518 * The right to invoke `fd_write` and `sock_send`.
519 * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
520 */
521#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)64)
522
523/**
524 * The right to invoke `fd_advise`.
525 */
526#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)128)
527
528/**
529 * The right to invoke `fd_allocate`.
530 */
531#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)256)
532
533/**
534 * The right to invoke `path_create_directory`.
535 */
536#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)512)
537
538/**
539 * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
540 */
541#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)1024)
542
543/**
544 * The right to invoke `path_link` with the file descriptor as the
545 * source directory.
546 */
547#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)2048)
548
549/**
550 * The right to invoke `path_link` with the file descriptor as the
551 * target directory.
552 */
553#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)4096)
554
555/**
556 * The right to invoke `path_open`.
557 */
558#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)8192)
559
560/**
561 * The right to invoke `fd_readdir`.
562 */
563#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)16384)
564
565/**
566 * The right to invoke `path_readlink`.
567 */
568#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)32768)
569
570/**
571 * The right to invoke `path_rename` with the file descriptor as the source directory.
572 */
573#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)65536)
574
575/**
576 * The right to invoke `path_rename` with the file descriptor as the target directory.
577 */
578#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)131072)
579
580/**
581 * The right to invoke `path_filestat_get`.
582 */
583#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)262144)
584
585/**
586 * The right to change a file's size (there is no `path_filestat_set_size`).
587 * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
588 */
589#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)524288)
590
591/**
592 * The right to invoke `path_filestat_set_times`.
593 */
594#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)1048576)
595
596/**
597 * The right to invoke `fd_filestat_get`.
598 */
599#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)2097152)
600
601/**
602 * The right to invoke `fd_filestat_set_size`.
603 */
604#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)4194304)
605
606/**
607 * The right to invoke `fd_filestat_set_times`.
608 */
609#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)8388608)
610
611/**
612 * The right to invoke `path_symlink`.
613 */
614#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)16777216)
615
616/**
617 * The right to invoke `path_remove_directory`.
618 */
619#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)33554432)
620
621/**
622 * The right to invoke `path_unlink_file`.
623 */
624#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)67108864)
625
626/**
627 * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
628 * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
629 */
630#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)134217728)
631
632/**
633 * The right to invoke `sock_shutdown`.
634 */
635#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)268435456)
636
637/**
638 * A file descriptor index.
639 */
640typedef uint32_t __wasi_fd_t;
641
642/**
643 * A region of memory for scatter/gather reads.
644 */
645typedef struct __wasi_iovec_t {
646 /**
647 * The address of the buffer to be filled.
648 */
649 uint8_t * buf;
650
651 /**
652 * The length of the buffer to be filled.
653 */
654 __wasi_size_t buf_len;
655
656} __wasi_iovec_t;
657
658/**
659 * A region of memory for scatter/gather writes.
660 */
661typedef struct __wasi_ciovec_t {
662 /**
663 * The address of the buffer to be written.
664 */
665 const uint8_t * buf;
666
667 /**
668 * The length of the buffer to be written.
669 */
670 __wasi_size_t buf_len;
671
672} __wasi_ciovec_t;
673
674/**
675 * Relative offset within a file.
676 */
677typedef int64_t __wasi_filedelta_t;
678
679/**
680 * The position relative to which to set the offset of the file descriptor.
681 */
682typedef uint8_t __wasi_whence_t;
683
684/**
685 * Seek relative to start-of-file.
686 */
687#define __WASI_WHENCE_SET ((__wasi_whence_t)0)
688
689/**
690 * Seek relative to current position.
691 */
692#define __WASI_WHENCE_CUR ((__wasi_whence_t)1)
693
694/**
695 * Seek relative to end-of-file.
696 */
697#define __WASI_WHENCE_END ((__wasi_whence_t)2)
698
699/**
700 * A reference to the offset of a directory entry.
701 *
702 * The value 0 signifies the start of the directory.
703 */
704typedef uint64_t __wasi_dircookie_t;
705
706/**
707 * The type for the $d_namlen field of $dirent.
708 */
709typedef uint32_t __wasi_dirnamlen_t;
710
711/**
712 * File serial number that is unique within its file system.
713 */
714typedef uint64_t __wasi_inode_t;
715
716/**
717 * The type of a file descriptor or file.
718 */
719typedef uint8_t __wasi_filetype_t;
720
721/**
722 * The type of the file descriptor or file is unknown or is different from any of the other types specified.
723 */
724#define __WASI_FILETYPE_UNKNOWN ((__wasi_filetype_t)0)
725
726/**
727 * The file descriptor or file refers to a block device inode.
728 */
729#define __WASI_FILETYPE_BLOCK_DEVICE ((__wasi_filetype_t)1)
730
731/**
732 * The file descriptor or file refers to a character device inode.
733 */
734#define __WASI_FILETYPE_CHARACTER_DEVICE ((__wasi_filetype_t)2)
735
736/**
737 * The file descriptor or file refers to a directory inode.
738 */
739#define __WASI_FILETYPE_DIRECTORY ((__wasi_filetype_t)3)
740
741/**
742 * The file descriptor or file refers to a regular file inode.
743 */
744#define __WASI_FILETYPE_REGULAR_FILE ((__wasi_filetype_t)4)
745
746/**
747 * The file descriptor or file refers to a datagram socket.
748 */
749#define __WASI_FILETYPE_SOCKET_DGRAM ((__wasi_filetype_t)5)
750
751/**
752 * The file descriptor or file refers to a byte-stream socket.
753 */
754#define __WASI_FILETYPE_SOCKET_STREAM ((__wasi_filetype_t)6)
755
756/**
757 * The file refers to a symbolic link inode.
758 */
759#define __WASI_FILETYPE_SYMBOLIC_LINK ((__wasi_filetype_t)7)
760
761/**
762 * A directory entry.
763 */
764typedef struct __wasi_dirent_t {
765 /**
766 * The offset of the next directory entry stored in this directory.
767 */
768 __wasi_dircookie_t d_next;
769
770 /**
771 * The serial number of the file referred to by this directory entry.
772 */
773 __wasi_inode_t d_ino;
774
775 /**
776 * The length of the name of the directory entry.
777 */
778 __wasi_dirnamlen_t d_namlen;
779
780 /**
781 * The type of the file referred to by this directory entry.
782 */
783 __wasi_filetype_t d_type;
784
785} __wasi_dirent_t;
786
787/**
788 * File or memory access pattern advisory information.
789 */
790typedef uint8_t __wasi_advice_t;
791
792/**
793 * The application has no advice to give on its behavior with respect to the specified data.
794 */
795#define __WASI_ADVICE_NORMAL ((__wasi_advice_t)0)
796
797/**
798 * The application expects to access the specified data sequentially from lower offsets to higher offsets.
799 */
800#define __WASI_ADVICE_SEQUENTIAL ((__wasi_advice_t)1)
801
802/**
803 * The application expects to access the specified data in a random order.
804 */
805#define __WASI_ADVICE_RANDOM ((__wasi_advice_t)2)
806
807/**
808 * The application expects to access the specified data in the near future.
809 */
810#define __WASI_ADVICE_WILLNEED ((__wasi_advice_t)3)
811
812/**
813 * The application expects that it will not access the specified data in the near future.
814 */
815#define __WASI_ADVICE_DONTNEED ((__wasi_advice_t)4)
816
817/**
818 * The application expects to access the specified data once and then not reuse it thereafter.
819 */
820#define __WASI_ADVICE_NOREUSE ((__wasi_advice_t)5)
821
822/**
823 * File descriptor flags.
824 */
825typedef uint16_t __wasi_fdflags_t;
826
827/**
828 * Append mode: Data written to the file is always appended to the file's end.
829 */
830#define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)1)
831
832/**
833 * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
834 */
835#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)2)
836
837/**
838 * Non-blocking mode.
839 */
840#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)4)
841
842/**
843 * Synchronized read I/O operations.
844 */
845#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)8)
846
847/**
848 * Write according to synchronized I/O file integrity completion. In
849 * addition to synchronizing the data stored in the file, the implementation
850 * may also synchronously update the file's metadata.
851 */
852#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)16)
853
854/**
855 * File descriptor attributes.
856 */
857typedef struct __wasi_fdstat_t {
858 /**
859 * File type.
860 */
861 __wasi_filetype_t fs_filetype;
862
863 /**
864 * File descriptor flags.
865 */
866 __wasi_fdflags_t fs_flags;
867
868 /**
869 * Rights that apply to this file descriptor.
870 */
871 __wasi_rights_t fs_rights_base;
872
873 /**
874 * Maximum set of rights that may be installed on new file descriptors that
875 * are created through this file descriptor, e.g., through `path_open`.
876 */
877 __wasi_rights_t fs_rights_inheriting;
878
879} __wasi_fdstat_t;
880
881/**
882 * Identifier for a device containing a file system. Can be used in combination
883 * with `inode` to uniquely identify a file or directory in the filesystem.
884 */
885typedef uint64_t __wasi_device_t;
886
887/**
888 * Which file time attributes to adjust.
889 */
890typedef uint16_t __wasi_fstflags_t;
891
892/**
893 * Adjust the last data access timestamp to the value stored in `filestat::st_atim`.
894 */
895#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)1)
896
897/**
898 * Adjust the last data access timestamp to the time of clock `clock::realtime`.
899 */
900#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)2)
901
902/**
903 * Adjust the last data modification timestamp to the value stored in `filestat::st_mtim`.
904 */
905#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)4)
906
907/**
908 * Adjust the last data modification timestamp to the time of clock `clock::realtime`.
909 */
910#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)8)
911
912/**
913 * Flags determining the method of how paths are resolved.
914 */
915typedef uint32_t __wasi_lookupflags_t;
916
917/**
918 * As long as the resolved path corresponds to a symbolic link, it is expanded.
919 */
920#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)1)
921
922/**
923 * Open flags used by `path_open`.
924 */
925typedef uint16_t __wasi_oflags_t;
926
927/**
928 * Create file if it does not exist.
929 */
930#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)1)
931
932/**
933 * Fail if not a directory.
934 */
935#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)2)
936
937/**
938 * Fail if file already exists.
939 */
940#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)4)
941
942/**
943 * Truncate file to size 0.
944 */
945#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)8)
946
947/**
948 * Number of hard links to an inode.
949 */
950typedef uint64_t __wasi_linkcount_t;
951
952/**
953 * File attributes.
954 */
955typedef struct __wasi_filestat_t {
956 /**
957 * Device ID of device containing the file.
958 */
959 __wasi_device_t dev;
960
961 /**
962 * File serial number.
963 */
964 __wasi_inode_t ino;
965
966 /**
967 * File type.
968 */
969 __wasi_filetype_t filetype;
970
971 /**
972 * Number of hard links to the file.
973 */
974 __wasi_linkcount_t nlink;
975
976 /**
977 * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
978 */
979 __wasi_filesize_t size;
980
981 /**
982 * Last data access timestamp.
983 */
984 __wasi_timestamp_t atim;
985
986 /**
987 * Last data modification timestamp.
988 */
989 __wasi_timestamp_t mtim;
990
991 /**
992 * Last file status change timestamp.
993 */
994 __wasi_timestamp_t ctim;
995
996} __wasi_filestat_t;
997
998/**
999 * User-provided value that may be attached to objects that is retained when
1000 * extracted from the implementation.
1001 */
1002typedef uint64_t __wasi_userdata_t;
1003
1004/**
1005 * Type of a subscription to an event or its occurrence.
1006 */
1007typedef uint8_t __wasi_eventtype_t;
1008
1009/**
1010 * The time value of clock `subscription::u.clock.clock_id` has
1011 * reached timestamp `subscription::u.clock.timeout`.
1012 */
1013#define __WASI_EVENTTYPE_CLOCK ((__wasi_eventtype_t)0)
1014
1015/**
1016 * File descriptor `subscription::u.fd_readwrite.fd` has data
1017 * available for reading. This event always triggers for regular files.
1018 */
1019#define __WASI_EVENTTYPE_FD_READ ((__wasi_eventtype_t)1)
1020
1021/**
1022 * File descriptor `subscription::u.fd_readwrite.fd` has capacity
1023 * available for writing. This event always triggers for regular files.
1024 */
1025#define __WASI_EVENTTYPE_FD_WRITE ((__wasi_eventtype_t)2)
1026
1027/**
1028 * The state of the file descriptor subscribed to with
1029 * `eventtype::fd_read` or `eventtype::fd_write`.
1030 */
1031typedef uint16_t __wasi_eventrwflags_t;
1032
1033/**
1034 * The peer of this socket has closed or disconnected.
1035 */
1036#define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)1)
1037
1038/**
1039 * The contents of an $event when type is `eventtype::fd_read` or
1040 * `eventtype::fd_write`.
1041 */
1042typedef struct __wasi_event_fd_readwrite_t {
1043 /**
1044 * The number of bytes available for reading or writing.
1045 */
1046 __wasi_filesize_t nbytes;
1047
1048 /**
1049 * The state of the file descriptor.
1050 */
1051 __wasi_eventrwflags_t flags;
1052
1053} __wasi_event_fd_readwrite_t;
1054
1055/**
1056 * The contents of an $event.
1057 */
1058typedef union __wasi_event_u_t {
1059 /**
1060 * When type is `eventtype::fd_read` or `eventtype::fd_write`:
1061 */
1062 __wasi_event_fd_readwrite_t fd_readwrite;
1063
1064} __wasi_event_u_t;
1065
1066/**
1067 * An event that occurred.
1068 */
1069typedef struct __wasi_event_t {
1070 /**
1071 * User-provided value that got attached to `subscription::userdata`.
1072 */
1073 __wasi_userdata_t userdata;
1074
1075 /**
1076 * If non-zero, an error that occurred while processing the subscription request.
1077 */
1078 __wasi_errno_t error;
1079
1080 /**
1081 * The type of the event that occurred.
1082 */
1083 __wasi_eventtype_t type;
1084
1085 /**
1086 * The contents of the event.
1087 */
1088 __wasi_event_u_t u;
1089
1090} __wasi_event_t;
1091
1092/**
1093 * Flags determining how to interpret the timestamp provided in
1094 * `subscription::u.clock.timeout.`
1095 */
1096typedef uint16_t __wasi_subclockflags_t;
1097
1098/**
1099 * If set, treat the timestamp provided in
1100 * `subscription::u.clock.timeout` as an absolute timestamp of clock
1101 * `subscription::u.clock.clock_id.` If clear, treat the timestamp
1102 * provided in `subscription::u.clock.timeout` relative to the
1103 * current time value of clock `subscription::u.clock.clock_id.`
1104 */
1105#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)1)
1106
1107/**
1108 * The contents of a $subscription when type is `eventtype::clock`.
1109 */
1110typedef struct __wasi_subscription_clock_t {
1111 /**
1112 * The clock against which to compare the timestamp.
1113 */
1114 __wasi_clockid_t id;
1115
1116 /**
1117 * The absolute or relative timestamp.
1118 */
1119 __wasi_timestamp_t timeout;
1120
1121 /**
1122 * The amount of time that the implementation may wait additionally
1123 * to coalesce with other events.
1124 */
1125 __wasi_timestamp_t precision;
1126
1127 /**
1128 * Flags specifying whether the timeout is absolute or relative
1129 */
1130 __wasi_subclockflags_t flags;
1131
1132} __wasi_subscription_clock_t;
1133
1134/**
1135 * The contents of a $subscription when type is type is
1136 * `eventtype::fd_read` or `eventtype::fd_write`.
1137 */
1138typedef struct __wasi_subscription_fd_readwrite_t {
1139 /**
1140 * The file descriptor on which to wait for it to become ready for reading or writing.
1141 */
1142 __wasi_fd_t file_descriptor;
1143
1144} __wasi_subscription_fd_readwrite_t;
1145
1146/**
1147 * The contents of a $subscription.
1148 */
1149typedef union __wasi_subscription_u_t {
1150 /**
1151 * When type is `eventtype::clock`:
1152 */
1153 __wasi_subscription_clock_t clock;
1154
1155 /**
1156 * When type is `eventtype::fd_read` or `eventtype::fd_write`:
1157 */
1158 __wasi_subscription_fd_readwrite_t fd_readwrite;
1159
1160} __wasi_subscription_u_t;
1161
1162/**
1163 * Subscription to an event.
1164 */
1165typedef struct __wasi_subscription_t {
1166 /**
1167 * User-provided value that is attached to the subscription in the
1168 * implementation and returned through `event::userdata`.
1169 */
1170 __wasi_userdata_t userdata;
1171
1172 /**
1173 * The type of the event to which to subscribe.
1174 */
1175 __wasi_eventtype_t type;
1176
1177 /**
1178 * The contents of the subscription.
1179 */
1180 __wasi_subscription_u_t u;
1181
1182} __wasi_subscription_t;
1183
1184/**
1185 * Exit code generated by a process when exiting.
1186 */
1187typedef uint32_t __wasi_exitcode_t;
1188
1189/**
1190 * Signal condition.
1191 */
1192typedef uint8_t __wasi_signal_t;
1193
1194/**
1195 * No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
1196 * so this value is reserved.
1197 */
1198#define __WASI_SIGNAL_NONE ((__wasi_signal_t)0)
1199
1200/**
1201 * Hangup.
1202 * Action: Terminates the process.
1203 */
1204#define __WASI_SIGNAL_HUP ((__wasi_signal_t)1)
1205
1206/**
1207 * Terminate interrupt signal.
1208 * Action: Terminates the process.
1209 */
1210#define __WASI_SIGNAL_INT ((__wasi_signal_t)2)
1211
1212/**
1213 * Terminal quit signal.
1214 * Action: Terminates the process.
1215 */
1216#define __WASI_SIGNAL_QUIT ((__wasi_signal_t)3)
1217
1218/**
1219 * Illegal instruction.
1220 * Action: Terminates the process.
1221 */
1222#define __WASI_SIGNAL_ILL ((__wasi_signal_t)4)
1223
1224/**
1225 * Trace/breakpoint trap.
1226 * Action: Terminates the process.
1227 */
1228#define __WASI_SIGNAL_TRAP ((__wasi_signal_t)5)
1229
1230/**
1231 * Process abort signal.
1232 * Action: Terminates the process.
1233 */
1234#define __WASI_SIGNAL_ABRT ((__wasi_signal_t)6)
1235
1236/**
1237 * Access to an undefined portion of a memory object.
1238 * Action: Terminates the process.
1239 */
1240#define __WASI_SIGNAL_BUS ((__wasi_signal_t)7)
1241
1242/**
1243 * Erroneous arithmetic operation.
1244 * Action: Terminates the process.
1245 */
1246#define __WASI_SIGNAL_FPE ((__wasi_signal_t)8)
1247
1248/**
1249 * Kill.
1250 * Action: Terminates the process.
1251 */
1252#define __WASI_SIGNAL_KILL ((__wasi_signal_t)9)
1253
1254/**
1255 * User-defined signal 1.
1256 * Action: Terminates the process.
1257 */
1258#define __WASI_SIGNAL_USR1 ((__wasi_signal_t)10)
1259
1260/**
1261 * Invalid memory reference.
1262 * Action: Terminates the process.
1263 */
1264#define __WASI_SIGNAL_SEGV ((__wasi_signal_t)11)
1265
1266/**
1267 * User-defined signal 2.
1268 * Action: Terminates the process.
1269 */
1270#define __WASI_SIGNAL_USR2 ((__wasi_signal_t)12)
1271
1272/**
1273 * Write on a pipe with no one to read it.
1274 * Action: Ignored.
1275 */
1276#define __WASI_SIGNAL_PIPE ((__wasi_signal_t)13)
1277
1278/**
1279 * Alarm clock.
1280 * Action: Terminates the process.
1281 */
1282#define __WASI_SIGNAL_ALRM ((__wasi_signal_t)14)
1283
1284/**
1285 * Termination signal.
1286 * Action: Terminates the process.
1287 */
1288#define __WASI_SIGNAL_TERM ((__wasi_signal_t)15)
1289
1290/**
1291 * Child process terminated, stopped, or continued.
1292 * Action: Ignored.
1293 */
1294#define __WASI_SIGNAL_CHLD ((__wasi_signal_t)16)
1295
1296/**
1297 * Continue executing, if stopped.
1298 * Action: Continues executing, if stopped.
1299 */
1300#define __WASI_SIGNAL_CONT ((__wasi_signal_t)17)
1301
1302/**
1303 * Stop executing.
1304 * Action: Stops executing.
1305 */
1306#define __WASI_SIGNAL_STOP ((__wasi_signal_t)18)
1307
1308/**
1309 * Terminal stop signal.
1310 * Action: Stops executing.
1311 */
1312#define __WASI_SIGNAL_TSTP ((__wasi_signal_t)19)
1313
1314/**
1315 * Background process attempting read.
1316 * Action: Stops executing.
1317 */
1318#define __WASI_SIGNAL_TTIN ((__wasi_signal_t)20)
1319
1320/**
1321 * Background process attempting write.
1322 * Action: Stops executing.
1323 */
1324#define __WASI_SIGNAL_TTOU ((__wasi_signal_t)21)
1325
1326/**
1327 * High bandwidth data is available at a socket.
1328 * Action: Ignored.
1329 */
1330#define __WASI_SIGNAL_URG ((__wasi_signal_t)22)
1331
1332/**
1333 * CPU time limit exceeded.
1334 * Action: Terminates the process.
1335 */
1336#define __WASI_SIGNAL_XCPU ((__wasi_signal_t)23)
1337
1338/**
1339 * File size limit exceeded.
1340 * Action: Terminates the process.
1341 */
1342#define __WASI_SIGNAL_XFSZ ((__wasi_signal_t)24)
1343
1344/**
1345 * Virtual timer expired.
1346 * Action: Terminates the process.
1347 */
1348#define __WASI_SIGNAL_VTALRM ((__wasi_signal_t)25)
1349
1350/**
1351 * Profiling timer expired.
1352 * Action: Terminates the process.
1353 */
1354#define __WASI_SIGNAL_PROF ((__wasi_signal_t)26)
1355
1356/**
1357 * Window changed.
1358 * Action: Ignored.
1359 */
1360#define __WASI_SIGNAL_WINCH ((__wasi_signal_t)27)
1361
1362/**
1363 * I/O possible.
1364 * Action: Terminates the process.
1365 */
1366#define __WASI_SIGNAL_POLL ((__wasi_signal_t)28)
1367
1368/**
1369 * Power failure.
1370 * Action: Terminates the process.
1371 */
1372#define __WASI_SIGNAL_PWR ((__wasi_signal_t)29)
1373
1374/**
1375 * Bad system call.
1376 * Action: Terminates the process.
1377 */
1378#define __WASI_SIGNAL_SYS ((__wasi_signal_t)30)
1379
1380/**
1381 * Flags provided to `sock_recv`.
1382 */
1383typedef uint16_t __wasi_riflags_t;
1384
1385/**
1386 * Returns the message without removing it from the socket's receive queue.
1387 */
1388#define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)1)
1389
1390/**
1391 * On byte-stream sockets, block until the full amount of data can be returned.
1392 */
1393#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)2)
1394
1395/**
1396 * Flags returned by `sock_recv`.
1397 */
1398typedef uint16_t __wasi_roflags_t;
1399
1400/**
1401 * Returned by `sock_recv`: Message data has been truncated.
1402 */
1403#define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)1)
1404
1405/**
1406 * Flags provided to `sock_send`. As there are currently no flags
1407 * defined, it must be set to zero.
1408 */
1409typedef uint16_t __wasi_siflags_t;
1410
1411/**
1412 * Which channels on a socket to shut down.
1413 */
1414typedef uint8_t __wasi_sdflags_t;
1415
1416/**
1417 * Disables further receive operations.
1418 */
1419#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)1)
1420
1421/**
1422 * Disables further send operations.
1423 */
1424#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)2)
1425
1426/**
1427 * Identifiers for preopened capabilities.
1428 */
1429typedef uint8_t __wasi_preopentype_t;
1430
1431/**
1432 * A pre-opened directory.
1433 */
1434#define __WASI_PREOPENTYPE_DIR ((__wasi_preopentype_t)0)
1435
1436/**
1437 * The contents of a $prestat when type is `preopentype::dir`.
1438 */
1439typedef struct __wasi_prestat_dir_t {
1440 /**
1441 * The length of the directory name for use with `fd_prestat_dir_name`.
1442 */
1443 __wasi_size_t pr_name_len;
1444
1445} __wasi_prestat_dir_t;
1446
1447/**
1448 * The contents of an $prestat.
1449 */
1450typedef union __wasi_prestat_u_t {
1451 /**
1452 * When type is `preopentype::dir`:
1453 */
1454 __wasi_prestat_dir_t dir;
1455
1456} __wasi_prestat_u_t;
1457
1458/**
1459 * Information about a pre-opened capability.
1460 */
1461typedef struct __wasi_prestat_t {
1462 /**
1463 * The type of the pre-opened capability.
1464 */
1465 __wasi_preopentype_t pr_type;
1466
1467 /**
1468 * The contents of the information.
1469 */
1470 __wasi_prestat_u_t u;
1471
1472} __wasi_prestat_t;
1473
1474/**
1475 * @defgroup wasi_snapshot_preview1
1476 * @{
1477 */
1478
1479/**
1480 * Read command-line argument data.
1481 * The size of the array should match that returned by `wasi_args_sizes_get()`
1482 */
1483__wasi_errno_t __wasi_args_get(
1484 uint8_t * * argv,
1485
1486 uint8_t * argv_buf
1487) __attribute__((
1488 __import_module__("wasi_snapshot_preview1"),
1489 __import_name__("args_get"),
1490 __warn_unused_result__
1491));
1492
1493/**
1494 * Return command-line argument data sizes.
1495 */
1496__wasi_errno_t __wasi_args_sizes_get(
1497 /**
1498 * The number of arguments.
1499 */
1500 __wasi_size_t *argc,
1501 /**
1502 * The size of the argument string data.
1503 */
1504 __wasi_size_t *argv_buf_size
1505) __attribute__((
1506 __import_module__("wasi_snapshot_preview1"),
1507 __import_name__("args_sizes_get"),
1508 __warn_unused_result__
1509));
1510
1511/**
1512 * Read environment variable data.
1513 * The sizes of the buffers should match that returned by `environ.sizes_get()`.
1514 */
1515__wasi_errno_t __wasi_environ_get(
1516 uint8_t * * environ,
1517
1518 uint8_t * environ_buf
1519) __attribute__((
1520 __import_module__("wasi_snapshot_preview1"),
1521 __import_name__("environ_get"),
1522 __warn_unused_result__
1523));
1524
1525/**
1526 * Return command-line argument data sizes.
1527 */
1528__wasi_errno_t __wasi_environ_sizes_get(
1529 /**
1530 * The number of arguments.
1531 */
1532 __wasi_size_t *argc,
1533 /**
1534 * The size of the argument string data.
1535 */
1536 __wasi_size_t *argv_buf_size
1537) __attribute__((
1538 __import_module__("wasi_snapshot_preview1"),
1539 __import_name__("environ_sizes_get"),
1540 __warn_unused_result__
1541));
1542
1543/**
1544 * Return the resolution of a clock.
1545 * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL`
1546 * Note: This is similar to `clock_getres` in POSIX.
1547 */
1548__wasi_errno_t __wasi_clock_res_get(
1549 /**
1550 * The clock for which to return the resolution.
1551 */
1552 __wasi_clockid_t id,
1553
1554 /**
1555 * The resolution of the clock.
1556 */
1557 __wasi_timestamp_t *resolution
1558) __attribute__((
1559 __import_module__("wasi_snapshot_preview1"),
1560 __import_name__("clock_res_get"),
1561 __warn_unused_result__
1562));
1563
1564/**
1565 * Return the time value of a clock.
1566 * Note: This is similar to `clock_gettime` in POSIX.
1567 */
1568__wasi_errno_t __wasi_clock_time_get(
1569 /**
1570 * The clock for which to return the time.
1571 */
1572 __wasi_clockid_t id,
1573
1574 /**
1575 * The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
1576 */
fe130532 1577 __wasi_timestamp_t precision,
446cb3f1
DG
1578
1579 /**
1580 * The time value of the clock.
1581 */
1582 __wasi_timestamp_t *time
1583) __attribute__((
1584 __import_module__("wasi_snapshot_preview1"),
1585 __import_name__("clock_time_get"),
1586 __warn_unused_result__
1587));
1588
1589/**
1590 * Provide file advisory information on a file descriptor.
1591 * Note: This is similar to `posix_fadvise` in POSIX.
1592 */
1593__wasi_errno_t __wasi_fd_advise(
fe130532 1594 __wasi_fd_t fd,
446cb3f1
DG
1595
1596 /**
1597 * The offset within the file to which the advisory applies.
1598 */
fe130532 1599 __wasi_filesize_t offset,
446cb3f1
DG
1600
1601 /**
1602 * The length of the region to which the advisory applies.
1603 */
fe130532 1604 __wasi_filesize_t len,
446cb3f1
DG
1605
1606 /**
1607 * The advice.
1608 */
1609 __wasi_advice_t advice
1610) __attribute__((
1611 __import_module__("wasi_snapshot_preview1"),
1612 __import_name__("fd_advise"),
1613 __warn_unused_result__
1614));
1615
1616/**
1617 * Force the allocation of space in a file.
1618 * Note: This is similar to `posix_fallocate` in POSIX.
1619 */
1620__wasi_errno_t __wasi_fd_allocate(
fe130532 1621 __wasi_fd_t fd,
446cb3f1
DG
1622
1623 /**
1624 * The offset at which to start the allocation.
1625 */
fe130532 1626 __wasi_filesize_t offset,
446cb3f1
DG
1627
1628 /**
1629 * The length of the area that is allocated.
1630 */
fe130532 1631 __wasi_filesize_t len
446cb3f1
DG
1632) __attribute__((
1633 __import_module__("wasi_snapshot_preview1"),
1634 __import_name__("fd_allocate"),
1635 __warn_unused_result__
1636));
1637
1638/**
1639 * Close a file descriptor.
1640 * Note: This is similar to `close` in POSIX.
1641 */
1642__wasi_errno_t __wasi_fd_close(
fe130532 1643 __wasi_fd_t fd
446cb3f1
DG
1644) __attribute__((
1645 __import_module__("wasi_snapshot_preview1"),
1646 __import_name__("fd_close"),
1647 __warn_unused_result__
1648));
1649
1650/**
1651 * Synchronize the data of a file to disk.
1652 * Note: This is similar to `fdatasync` in POSIX.
1653 */
1654__wasi_errno_t __wasi_fd_datasync(
fe130532 1655 __wasi_fd_t fd
446cb3f1
DG
1656) __attribute__((
1657 __import_module__("wasi_snapshot_preview1"),
1658 __import_name__("fd_datasync"),
1659 __warn_unused_result__
1660));
1661
1662/**
1663 * Get the attributes of a file descriptor.
1664 * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
1665 */
1666__wasi_errno_t __wasi_fd_fdstat_get(
fe130532 1667 __wasi_fd_t fd,
446cb3f1
DG
1668
1669 /**
1670 * The buffer where the file descriptor's attributes are stored.
1671 */
1672 __wasi_fdstat_t *stat
1673) __attribute__((
1674 __import_module__("wasi_snapshot_preview1"),
1675 __import_name__("fd_fdstat_get"),
1676 __warn_unused_result__
1677));
1678
1679/**
1680 * Adjust the flags associated with a file descriptor.
1681 * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
1682 */
1683__wasi_errno_t __wasi_fd_fdstat_set_flags(
fe130532 1684 __wasi_fd_t fd,
446cb3f1
DG
1685
1686 /**
1687 * The desired values of the file descriptor flags.
1688 */
1689 __wasi_fdflags_t flags
1690) __attribute__((
1691 __import_module__("wasi_snapshot_preview1"),
1692 __import_name__("fd_fdstat_set_flags"),
1693 __warn_unused_result__
1694));
1695
1696/**
1697 * Adjust the rights associated with a file descriptor.
1698 * This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights
1699 */
1700__wasi_errno_t __wasi_fd_fdstat_set_rights(
fe130532 1701 __wasi_fd_t fd,
446cb3f1
DG
1702
1703 /**
1704 * The desired rights of the file descriptor.
1705 */
1706 __wasi_rights_t fs_rights_base,
1707
1708 __wasi_rights_t fs_rights_inheriting
1709) __attribute__((
1710 __import_module__("wasi_snapshot_preview1"),
1711 __import_name__("fd_fdstat_set_rights"),
1712 __warn_unused_result__
1713));
1714
1715/**
1716 * Return the attributes of an open file.
1717 */
1718__wasi_errno_t __wasi_fd_filestat_get(
fe130532 1719 __wasi_fd_t fd,
446cb3f1
DG
1720
1721 /**
1722 * The buffer where the file's attributes are stored.
1723 */
1724 __wasi_filestat_t *buf
1725) __attribute__((
1726 __import_module__("wasi_snapshot_preview1"),
1727 __import_name__("fd_filestat_get"),
1728 __warn_unused_result__
1729));
1730
1731/**
1732 * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
1733 * Note: This is similar to `ftruncate` in POSIX.
1734 */
1735__wasi_errno_t __wasi_fd_filestat_set_size(
fe130532 1736 __wasi_fd_t fd,
446cb3f1
DG
1737
1738 /**
1739 * The desired file size.
1740 */
fe130532 1741 __wasi_filesize_t size
446cb3f1
DG
1742) __attribute__((
1743 __import_module__("wasi_snapshot_preview1"),
1744 __import_name__("fd_filestat_set_size"),
1745 __warn_unused_result__
1746));
1747
1748/**
1749 * Adjust the timestamps of an open file or directory.
1750 * Note: This is similar to `futimens` in POSIX.
1751 */
1752__wasi_errno_t __wasi_fd_filestat_set_times(
fe130532 1753 __wasi_fd_t fd,
446cb3f1
DG
1754
1755 /**
1756 * The desired values of the data access timestamp.
1757 */
fe130532 1758 __wasi_timestamp_t atim,
446cb3f1
DG
1759
1760 /**
1761 * The desired values of the data modification timestamp.
1762 */
fe130532 1763 __wasi_timestamp_t mtim,
446cb3f1
DG
1764
1765 /**
1766 * A bitmask indicating which timestamps to adjust.
1767 */
1768 __wasi_fstflags_t fst_flags
1769) __attribute__((
1770 __import_module__("wasi_snapshot_preview1"),
1771 __import_name__("fd_filestat_set_times"),
1772 __warn_unused_result__
1773));
1774
1775/**
1776 * Read from a file descriptor, without using and updating the file descriptor's offset.
1777 * Note: This is similar to `preadv` in POSIX.
1778 */
1779__wasi_errno_t __wasi_fd_pread(
fe130532 1780 __wasi_fd_t fd,
446cb3f1
DG
1781
1782 /**
1783 * List of scatter/gather vectors in which to store data.
1784 */
1785 const __wasi_iovec_t *iovs,
1786
1787 /**
1788 * The length of the array pointed to by `iovs`.
1789 */
1790 size_t iovs_len,
1791
1792 /**
1793 * The offset within the file at which to read.
1794 */
fe130532 1795 __wasi_filesize_t offset,
446cb3f1
DG
1796
1797 /**
1798 * The number of bytes read.
1799 */
1800 __wasi_size_t *nread
1801) __attribute__((
1802 __import_module__("wasi_snapshot_preview1"),
1803 __import_name__("fd_pread"),
1804 __warn_unused_result__
1805));
1806
1807/**
1808 * Return a description of the given preopened file descriptor.
1809 */
1810__wasi_errno_t __wasi_fd_prestat_get(
fe130532 1811 __wasi_fd_t fd,
446cb3f1
DG
1812
1813 /**
1814 * The buffer where the description is stored.
1815 */
1816 __wasi_prestat_t *buf
1817) __attribute__((
1818 __import_module__("wasi_snapshot_preview1"),
1819 __import_name__("fd_prestat_get"),
1820 __warn_unused_result__
1821));
1822
1823/**
1824 * Return a description of the given preopened file descriptor.
1825 */
1826__wasi_errno_t __wasi_fd_prestat_dir_name(
fe130532 1827 __wasi_fd_t fd,
446cb3f1
DG
1828
1829 /**
1830 * A buffer into which to write the preopened directory name.
1831 */
1832 uint8_t * path,
1833
fe130532 1834 __wasi_size_t path_len
446cb3f1
DG
1835) __attribute__((
1836 __import_module__("wasi_snapshot_preview1"),
1837 __import_name__("fd_prestat_dir_name"),
1838 __warn_unused_result__
1839));
1840
1841/**
1842 * Write to a file descriptor, without using and updating the file descriptor's offset.
1843 * Note: This is similar to `pwritev` in POSIX.
1844 */
1845__wasi_errno_t __wasi_fd_pwrite(
fe130532 1846 __wasi_fd_t fd,
446cb3f1
DG
1847
1848 /**
1849 * List of scatter/gather vectors from which to retrieve data.
1850 */
1851 const __wasi_ciovec_t *iovs,
1852
1853 /**
1854 * The length of the array pointed to by `iovs`.
1855 */
1856 size_t iovs_len,
1857
1858 /**
1859 * The offset within the file at which to write.
1860 */
fe130532 1861 __wasi_filesize_t offset,
446cb3f1
DG
1862
1863 /**
1864 * The number of bytes written.
1865 */
1866 __wasi_size_t *nwritten
1867) __attribute__((
1868 __import_module__("wasi_snapshot_preview1"),
1869 __import_name__("fd_pwrite"),
1870 __warn_unused_result__
1871));
1872
1873/**
1874 * Read from a file descriptor.
1875 * Note: This is similar to `readv` in POSIX.
1876 */
1877__wasi_errno_t __wasi_fd_read(
fe130532 1878 __wasi_fd_t fd,
446cb3f1
DG
1879
1880 /**
1881 * List of scatter/gather vectors to which to store data.
1882 */
1883 const __wasi_iovec_t *iovs,
1884
1885 /**
1886 * The length of the array pointed to by `iovs`.
1887 */
1888 size_t iovs_len,
1889
1890 /**
1891 * The number of bytes read.
1892 */
1893 __wasi_size_t *nread
1894) __attribute__((
1895 __import_module__("wasi_snapshot_preview1"),
1896 __import_name__("fd_read"),
1897 __warn_unused_result__
1898));
1899
1900/**
1901 * Read directory entries from a directory.
1902 * When successful, the contents of the output buffer consist of a sequence of
1903 * directory entries. Each directory entry consists of a dirent_t object,
1904 * followed by dirent_t::d_namlen bytes holding the name of the directory
1905 * entry.
1906 * This function fills the output buffer as much as possible, potentially
1907 * truncating the last directory entry. This allows the caller to grow its
1908 * read buffer size in case it's too small to fit a single large directory
1909 * entry, or skip the oversized directory entry.
1910 */
1911__wasi_errno_t __wasi_fd_readdir(
fe130532 1912 __wasi_fd_t fd,
446cb3f1
DG
1913
1914 /**
1915 * The buffer where directory entries are stored
1916 */
1917 uint8_t * buf,
1918
fe130532 1919 __wasi_size_t buf_len,
446cb3f1
DG
1920
1921 /**
1922 * The location within the directory to start reading
1923 */
fe130532 1924 __wasi_dircookie_t cookie,
446cb3f1
DG
1925
1926 /**
1927 * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
1928 */
1929 __wasi_size_t *bufused
1930) __attribute__((
1931 __import_module__("wasi_snapshot_preview1"),
1932 __import_name__("fd_readdir"),
1933 __warn_unused_result__
1934));
1935
1936/**
1937 * Atomically replace a file descriptor by renumbering another file descriptor.
1938 * Due to the strong focus on thread safety, this environment does not provide
1939 * a mechanism to duplicate or renumber a file descriptor to an arbitrary
1940 * number, like `dup2()`. This would be prone to race conditions, as an actual
1941 * file descriptor with the same number could be allocated by a different
1942 * thread at the same time.
1943 * This function provides a way to atomically renumber file descriptors, which
1944 * would disappear if `dup2()` were to be removed entirely.
1945 */
1946__wasi_errno_t __wasi_fd_renumber(
fe130532 1947 __wasi_fd_t fd,
446cb3f1
DG
1948
1949 /**
1950 * The file descriptor to overwrite.
1951 */
fe130532 1952 __wasi_fd_t to
446cb3f1
DG
1953) __attribute__((
1954 __import_module__("wasi_snapshot_preview1"),
1955 __import_name__("fd_renumber"),
1956 __warn_unused_result__
1957));
1958
1959/**
1960 * Move the offset of a file descriptor.
1961 * Note: This is similar to `lseek` in POSIX.
1962 */
1963__wasi_errno_t __wasi_fd_seek(
fe130532 1964 __wasi_fd_t fd,
446cb3f1
DG
1965
1966 /**
1967 * The number of bytes to move.
1968 */
fe130532 1969 __wasi_filedelta_t offset,
446cb3f1
DG
1970
1971 /**
1972 * The base from which the offset is relative.
1973 */
1974 __wasi_whence_t whence,
1975
1976 /**
1977 * The new offset of the file descriptor, relative to the start of the file.
1978 */
1979 __wasi_filesize_t *newoffset
1980) __attribute__((
1981 __import_module__("wasi_snapshot_preview1"),
1982 __import_name__("fd_seek"),
1983 __warn_unused_result__
1984));
1985
1986/**
1987 * Synchronize the data and metadata of a file to disk.
1988 * Note: This is similar to `fsync` in POSIX.
1989 */
1990__wasi_errno_t __wasi_fd_sync(
fe130532 1991 __wasi_fd_t fd
446cb3f1
DG
1992) __attribute__((
1993 __import_module__("wasi_snapshot_preview1"),
1994 __import_name__("fd_sync"),
1995 __warn_unused_result__
1996));
1997
1998/**
1999 * Return the current offset of a file descriptor.
2000 * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
2001 */
2002__wasi_errno_t __wasi_fd_tell(
fe130532 2003 __wasi_fd_t fd,
446cb3f1
DG
2004
2005 /**
2006 * The current offset of the file descriptor, relative to the start of the file.
2007 */
2008 __wasi_filesize_t *offset
2009) __attribute__((
2010 __import_module__("wasi_snapshot_preview1"),
2011 __import_name__("fd_tell"),
2012 __warn_unused_result__
2013));
2014
2015/**
2016 * Write to a file descriptor.
2017 * Note: This is similar to `writev` in POSIX.
2018 */
2019__wasi_errno_t __wasi_fd_write(
fe130532 2020 __wasi_fd_t fd,
446cb3f1
DG
2021
2022 /**
2023 * List of scatter/gather vectors from which to retrieve data.
2024 */
2025 const __wasi_ciovec_t *iovs,
2026
2027 /**
2028 * The length of the array pointed to by `iovs`.
2029 */
2030 size_t iovs_len,
2031
2032 /**
2033 * The number of bytes written.
2034 */
2035 __wasi_size_t *nwritten
2036) __attribute__((
2037 __import_module__("wasi_snapshot_preview1"),
2038 __import_name__("fd_write"),
2039 __warn_unused_result__
2040));
2041
2042/**
2043 * Create a directory.
2044 * Note: This is similar to `mkdirat` in POSIX.
2045 */
2046__wasi_errno_t __wasi_path_create_directory(
fe130532 2047 __wasi_fd_t fd,
446cb3f1
DG
2048
2049 /**
2050 * The path at which to create the directory.
2051 */
2052 const char *path,
2053
2054 /**
2055 * The length of the buffer pointed to by `path`.
2056 */
2057 size_t path_len
2058) __attribute__((
2059 __import_module__("wasi_snapshot_preview1"),
2060 __import_name__("path_create_directory"),
2061 __warn_unused_result__
2062));
2063
2064/**
2065 * Return the attributes of a file or directory.
2066 * Note: This is similar to `stat` in POSIX.
2067 */
2068__wasi_errno_t __wasi_path_filestat_get(
fe130532 2069 __wasi_fd_t fd,
446cb3f1
DG
2070
2071 /**
2072 * Flags determining the method of how the path is resolved.
2073 */
2074 __wasi_lookupflags_t flags,
2075
2076 /**
2077 * The path of the file or directory to inspect.
2078 */
2079 const char *path,
2080
2081 /**
2082 * The length of the buffer pointed to by `path`.
2083 */
2084 size_t path_len,
2085
2086 /**
2087 * The buffer where the file's attributes are stored.
2088 */
2089 __wasi_filestat_t *buf
2090) __attribute__((
2091 __import_module__("wasi_snapshot_preview1"),
2092 __import_name__("path_filestat_get"),
2093 __warn_unused_result__
2094));
2095
2096/**
2097 * Adjust the timestamps of a file or directory.
2098 * Note: This is similar to `utimensat` in POSIX.
2099 */
2100__wasi_errno_t __wasi_path_filestat_set_times(
fe130532 2101 __wasi_fd_t fd,
446cb3f1
DG
2102
2103 /**
2104 * Flags determining the method of how the path is resolved.
2105 */
2106 __wasi_lookupflags_t flags,
2107
2108 /**
2109 * The path of the file or directory to operate on.
2110 */
2111 const char *path,
2112
2113 /**
2114 * The length of the buffer pointed to by `path`.
2115 */
2116 size_t path_len,
2117
2118 /**
2119 * The desired values of the data access timestamp.
2120 */
fe130532 2121 __wasi_timestamp_t atim,
446cb3f1
DG
2122
2123 /**
2124 * The desired values of the data modification timestamp.
2125 */
fe130532 2126 __wasi_timestamp_t mtim,
446cb3f1
DG
2127
2128 /**
2129 * A bitmask indicating which timestamps to adjust.
2130 */
2131 __wasi_fstflags_t fst_flags
2132) __attribute__((
2133 __import_module__("wasi_snapshot_preview1"),
2134 __import_name__("path_filestat_set_times"),
2135 __warn_unused_result__
2136));
2137
2138/**
2139 * Create a hard link.
2140 * Note: This is similar to `linkat` in POSIX.
2141 */
2142__wasi_errno_t __wasi_path_link(
fe130532 2143 __wasi_fd_t old_fd,
446cb3f1
DG
2144
2145 /**
2146 * Flags determining the method of how the path is resolved.
2147 */
2148 __wasi_lookupflags_t old_flags,
2149
2150 /**
2151 * The source path from which to link.
2152 */
2153 const char *old_path,
2154
2155 /**
2156 * The length of the buffer pointed to by `old_path`.
2157 */
2158 size_t old_path_len,
2159
2160 /**
2161 * The working directory at which the resolution of the new path starts.
2162 */
fe130532 2163 __wasi_fd_t new_fd,
446cb3f1
DG
2164
2165 /**
2166 * The destination path at which to create the hard link.
2167 */
2168 const char *new_path,
2169
2170 /**
2171 * The length of the buffer pointed to by `new_path`.
2172 */
2173 size_t new_path_len
2174) __attribute__((
2175 __import_module__("wasi_snapshot_preview1"),
2176 __import_name__("path_link"),
2177 __warn_unused_result__
2178));
2179
2180/**
2181 * Open a file or directory.
2182 * The returned file descriptor is not guaranteed to be the lowest-numbered
2183 * file descriptor not currently open; it is randomized to prevent
2184 * applications from depending on making assumptions about indexes, since this
2185 * is error-prone in multi-threaded contexts. The returned file descriptor is
2186 * guaranteed to be less than 2**31.
2187 * Note: This is similar to `openat` in POSIX.
2188 */
2189__wasi_errno_t __wasi_path_open(
fe130532 2190 __wasi_fd_t fd,
446cb3f1
DG
2191
2192 /**
2193 * Flags determining the method of how the path is resolved.
2194 */
2195 __wasi_lookupflags_t dirflags,
2196
2197 /**
2198 * The relative path of the file or directory to open, relative to the
2199 * `dirfd` directory.
2200 */
2201 const char *path,
2202
2203 /**
2204 * The length of the buffer pointed to by `path`.
2205 */
2206 size_t path_len,
2207
2208 /**
2209 * The method by which to open the file.
2210 */
2211 __wasi_oflags_t oflags,
2212
2213 /**
2214 * The initial rights of the newly created file descriptor. The
2215 * implementation is allowed to return a file descriptor with fewer rights
2216 * than specified, if and only if those rights do not apply to the type of
2217 * file being opened.
2218 * The *base* rights are rights that will apply to operations using the file
2219 * descriptor itself, while the *inheriting* rights are rights that apply to
2220 * file descriptors derived from it.
2221 */
2222 __wasi_rights_t fs_rights_base,
2223
2224 __wasi_rights_t fs_rights_inherting,
2225
2226 __wasi_fdflags_t fdflags,
2227
2228 /**
2229 * The file descriptor of the file that has been opened.
2230 */
2231 __wasi_fd_t *opened_fd
2232) __attribute__((
2233 __import_module__("wasi_snapshot_preview1"),
2234 __import_name__("path_open"),
2235 __warn_unused_result__
2236));
2237
2238/**
2239 * Read the contents of a symbolic link.
2240 * Note: This is similar to `readlinkat` in POSIX.
2241 */
2242__wasi_errno_t __wasi_path_readlink(
fe130532 2243 __wasi_fd_t fd,
446cb3f1
DG
2244
2245 /**
2246 * The path of the symbolic link from which to read.
2247 */
2248 const char *path,
2249
2250 /**
2251 * The length of the buffer pointed to by `path`.
2252 */
2253 size_t path_len,
2254
2255 /**
2256 * The buffer to which to write the contents of the symbolic link.
2257 */
2258 uint8_t * buf,
2259
fe130532 2260 __wasi_size_t buf_len,
446cb3f1
DG
2261
2262 /**
2263 * The number of bytes placed in the buffer.
2264 */
2265 __wasi_size_t *bufused
2266) __attribute__((
2267 __import_module__("wasi_snapshot_preview1"),
2268 __import_name__("path_readlink"),
2269 __warn_unused_result__
2270));
2271
2272/**
2273 * Remove a directory.
2274 * Return `ENOTEMPTY` if the directory is not empty.
2275 * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
2276 */
2277__wasi_errno_t __wasi_path_remove_directory(
fe130532 2278 __wasi_fd_t fd,
446cb3f1
DG
2279
2280 /**
2281 * The path to a directory to remove.
2282 */
2283 const char *path,
2284
2285 /**
2286 * The length of the buffer pointed to by `path`.
2287 */
2288 size_t path_len
2289) __attribute__((
2290 __import_module__("wasi_snapshot_preview1"),
2291 __import_name__("path_remove_directory"),
2292 __warn_unused_result__
2293));
2294
2295/**
2296 * Rename a file or directory.
2297 * Note: This is similar to `renameat` in POSIX.
2298 */
2299__wasi_errno_t __wasi_path_rename(
fe130532 2300 __wasi_fd_t fd,
446cb3f1
DG
2301
2302 /**
2303 * The source path of the file or directory to rename.
2304 */
2305 const char *old_path,
2306
2307 /**
2308 * The length of the buffer pointed to by `old_path`.
2309 */
2310 size_t old_path_len,
2311
2312 /**
2313 * The working directory at which the resolution of the new path starts.
2314 */
fe130532 2315 __wasi_fd_t new_fd,
446cb3f1
DG
2316
2317 /**
2318 * The destination path to which to rename the file or directory.
2319 */
2320 const char *new_path,
2321
2322 /**
2323 * The length of the buffer pointed to by `new_path`.
2324 */
2325 size_t new_path_len
2326) __attribute__((
2327 __import_module__("wasi_snapshot_preview1"),
2328 __import_name__("path_rename"),
2329 __warn_unused_result__
2330));
2331
2332/**
2333 * Create a symbolic link.
2334 * Note: This is similar to `symlinkat` in POSIX.
2335 */
2336__wasi_errno_t __wasi_path_symlink(
2337 /**
2338 * The contents of the symbolic link.
2339 */
2340 const char *old_path,
2341
2342 /**
2343 * The length of the buffer pointed to by `old_path`.
2344 */
2345 size_t old_path_len,
2346
fe130532 2347 __wasi_fd_t fd,
446cb3f1
DG
2348
2349 /**
2350 * The destination path at which to create the symbolic link.
2351 */
2352 const char *new_path,
2353
2354 /**
2355 * The length of the buffer pointed to by `new_path`.
2356 */
2357 size_t new_path_len
2358) __attribute__((
2359 __import_module__("wasi_snapshot_preview1"),
2360 __import_name__("path_symlink"),
2361 __warn_unused_result__
2362));
2363
2364/**
2365 * Unlink a file.
2366 * Return `EISDIR` if the path refers to a directory.
2367 * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
2368 */
2369__wasi_errno_t __wasi_path_unlink_file(
fe130532 2370 __wasi_fd_t fd,
446cb3f1
DG
2371
2372 /**
2373 * The path to a file to unlink.
2374 */
2375 const char *path,
2376
2377 /**
2378 * The length of the buffer pointed to by `path`.
2379 */
2380 size_t path_len
2381) __attribute__((
2382 __import_module__("wasi_snapshot_preview1"),
2383 __import_name__("path_unlink_file"),
2384 __warn_unused_result__
2385));
2386
2387/**
2388 * Concurrently poll for the occurrence of a set of events.
2389 */
2390__wasi_errno_t __wasi_poll_oneoff(
2391 /**
2392 * The events to which to subscribe.
2393 */
2394 const __wasi_subscription_t * in,
2395
2396 /**
2397 * The events that have occurred.
2398 */
2399 __wasi_event_t * out,
2400
2401 /**
2402 * Both the number of subscriptions and events.
2403 */
fe130532 2404 __wasi_size_t nsubscriptions,
446cb3f1
DG
2405
2406 /**
2407 * The number of events stored.
2408 */
2409 __wasi_size_t *nevents
2410) __attribute__((
2411 __import_module__("wasi_snapshot_preview1"),
2412 __import_name__("poll_oneoff"),
2413 __warn_unused_result__
2414));
2415
2416/**
2417 * Terminate the process normally. An exit code of 0 indicates successful
2418 * termination of the program. The meanings of other values is dependent on
2419 * the environment.
2420 */
2421_Noreturn void __wasi_proc_exit(
2422 /**
2423 * The exit code returned by the process.
2424 */
fe130532 2425 __wasi_exitcode_t rval
446cb3f1
DG
2426) __attribute__((
2427 __import_module__("wasi_snapshot_preview1"),
2428 __import_name__("proc_exit")));
2429
2430/**
2431 * Send a signal to the process of the calling thread.
2432 * Note: This is similar to `raise` in POSIX.
2433 */
2434__wasi_errno_t __wasi_proc_raise(
2435 /**
2436 * The signal condition to trigger.
2437 */
2438 __wasi_signal_t sig
2439) __attribute__((
2440 __import_module__("wasi_snapshot_preview1"),
2441 __import_name__("proc_raise"),
2442 __warn_unused_result__
2443));
2444
2445/**
2446 * Temporarily yield execution of the calling thread.
2447 * Note: This is similar to `sched_yield` in POSIX.
2448 */
2449__wasi_errno_t __wasi_sched_yield(
2450 void
2451) __attribute__((
2452 __import_module__("wasi_snapshot_preview1"),
2453 __import_name__("sched_yield"),
2454 __warn_unused_result__
2455));
2456
2457/**
2458 * Write high-quality random data into a buffer.
2459 * This function blocks when the implementation is unable to immediately
2460 * provide sufficient high-quality random data.
2461 * This function may execute slowly, so when large mounts of random data are
2462 * required, it's advisable to use this function to seed a pseudo-random
2463 * number generator, rather than to provide the random data directly.
2464 */
2465__wasi_errno_t __wasi_random_get(
2466 /**
2467 * The buffer to fill with random data.
2468 */
2469 uint8_t * buf,
2470
fe130532 2471 __wasi_size_t buf_len
446cb3f1
DG
2472) __attribute__((
2473 __import_module__("wasi_snapshot_preview1"),
2474 __import_name__("random_get"),
2475 __warn_unused_result__
2476));
2477
2478/**
2479 * Receive a message from a socket.
2480 * Note: This is similar to `recv` in POSIX, though it also supports reading
2481 * the data into multiple buffers in the manner of `readv`.
2482 */
2483__wasi_errno_t __wasi_sock_recv(
fe130532 2484 __wasi_fd_t fd,
446cb3f1
DG
2485
2486 /**
2487 * List of scatter/gather vectors to which to store data.
2488 */
2489 const __wasi_iovec_t *ri_data,
2490
2491 /**
2492 * The length of the array pointed to by `ri_data`.
2493 */
2494 size_t ri_data_len,
2495
2496 /**
2497 * Message flags.
2498 */
2499 __wasi_riflags_t ri_flags,
2500
2501 /**
2502 * Number of bytes stored in ri_data.
2503 */
2504 __wasi_size_t *ro_datalen,
2505 /**
2506 * Message flags.
2507 */
2508 __wasi_roflags_t *ro_flags
2509) __attribute__((
2510 __import_module__("wasi_snapshot_preview1"),
2511 __import_name__("sock_recv"),
2512 __warn_unused_result__
2513));
2514
2515/**
2516 * Send a message on a socket.
2517 * Note: This is similar to `send` in POSIX, though it also supports writing
2518 * the data from multiple buffers in the manner of `writev`.
2519 */
2520__wasi_errno_t __wasi_sock_send(
fe130532 2521 __wasi_fd_t fd,
446cb3f1
DG
2522
2523 /**
2524 * List of scatter/gather vectors to which to retrieve data
2525 */
2526 const __wasi_ciovec_t *si_data,
2527
2528 /**
2529 * The length of the array pointed to by `si_data`.
2530 */
2531 size_t si_data_len,
2532
2533 /**
2534 * Message flags.
2535 */
fe130532 2536 __wasi_siflags_t si_flags,
446cb3f1
DG
2537
2538 /**
2539 * Number of bytes transmitted.
2540 */
2541 __wasi_size_t *so_datalen
2542) __attribute__((
2543 __import_module__("wasi_snapshot_preview1"),
2544 __import_name__("sock_send"),
2545 __warn_unused_result__
2546));
2547
2548/**
2549 * Shut down socket send and receive channels.
2550 * Note: This is similar to `shutdown` in POSIX.
2551 */
2552__wasi_errno_t __wasi_sock_shutdown(
fe130532 2553 __wasi_fd_t fd,
446cb3f1
DG
2554
2555 /**
2556 * Which channels on the socket to shut down.
2557 */
2558 __wasi_sdflags_t how
2559) __attribute__((
2560 __import_module__("wasi_snapshot_preview1"),
2561 __import_name__("sock_shutdown"),
2562 __warn_unused_result__
2563));
2564
2565/** @} */
2566
2567#ifdef __cplusplus
2568}
2569#endif
2570
2571#endif