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