1;; Type names used by low-level WASI interfaces.
2;;
3;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi).
4;;
5;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md)
6;; for an explanation of what that means.
7
8(typename $size u32)
9
10;;; Non-negative file size or length of a region within a file.
11(typename $filesize u64)
12
13;;; Timestamp in nanoseconds.
14(typename $timestamp u64)
15
16;;; Identifiers for clocks.
17(typename $clockid
18  (enum u32
19    ;;; The clock measuring real time. Time value zero corresponds with
20    ;;; 1970-01-01T00:00:00Z.
21    $realtime
22    ;;; The store-wide monotonic clock, which is defined as a clock measuring
23    ;;; real time, whose value cannot be adjusted and which cannot have negative
24    ;;; clock jumps. The epoch of this clock is undefined. The absolute time
25    ;;; value of this clock therefore has no meaning.
26    $monotonic
27    ;;; The CPU-time clock associated with the current process.
28    $process_cputime_id
29    ;;; The CPU-time clock associated with the current thread.
30    $thread_cputime_id
31  )
32)
33
34;;; Error codes returned by functions.
35;;; Not all of these error codes are returned by the functions provided by this
36;;; API; some are used in higher-level library layers, and others are provided
37;;; merely for alignment with POSIX.
38(typename $errno
39  (enum u16
40    ;;; No error occurred. System call completed successfully.
41    $success
42    ;;; Argument list too long.
43    $2big
44    ;;; Permission denied.
45    $acces
46    ;;; Address in use.
47    $addrinuse
48    ;;; Address not available.
49    $addrnotavail
50    ;;; Address family not supported.
51    $afnosupport
52    ;;; Resource unavailable, or operation would block.
53    $again
54    ;;; Connection already in progress.
55    $already
56    ;;; Bad file descriptor.
57    $badf
58    ;;; Bad message.
59    $badmsg
60    ;;; Device or resource busy.
61    $busy
62    ;;; Operation canceled.
63    $canceled
64    ;;; No child processes.
65    $child
66    ;;; Connection aborted.
67    $connaborted
68    ;;; Connection refused.
69    $connrefused
70    ;;; Connection reset.
71    $connreset
72    ;;; Resource deadlock would occur.
73    $deadlk
74    ;;; Destination address required.
75    $destaddrreq
76    ;;; Mathematics argument out of domain of function.
77    $dom
78    ;;; Reserved.
79    $dquot
80    ;;; File exists.
81    $exist
82    ;;; Bad address.
83    $fault
84    ;;; File too large.
85    $fbig
86    ;;; Host is unreachable.
87    $hostunreach
88    ;;; Identifier removed.
89    $idrm
90    ;;; Illegal byte sequence.
91    $ilseq
92    ;;; Operation in progress.
93    $inprogress
94    ;;; Interrupted function.
95    $intr
96    ;;; Invalid argument.
97    $inval
98    ;;; I/O error.
99    $io
100    ;;; Socket is connected.
101    $isconn
102    ;;; Is a directory.
103    $isdir
104    ;;; Too many levels of symbolic links.
105    $loop
106    ;;; File descriptor value too large.
107    $mfile
108    ;;; Too many links.
109    $mlink
110    ;;; Message too large.
111    $msgsize
112    ;;; Reserved.
113    $multihop
114    ;;; Filename too long.
115    $nametoolong
116    ;;; Network is down.
117    $netdown
118    ;;; Connection aborted by network.
119    $netreset
120    ;;; Network unreachable.
121    $netunreach
122    ;;; Too many files open in system.
123    $nfile
124    ;;; No buffer space available.
125    $nobufs
126    ;;; No such device.
127    $nodev
128    ;;; No such file or directory.
129    $noent
130    ;;; Executable file format error.
131    $noexec
132    ;;; No locks available.
133    $nolck
134    ;;; Reserved.
135    $nolink
136    ;;; Not enough space.
137    $nomem
138    ;;; No message of the desired type.
139    $nomsg
140    ;;; Protocol not available.
141    $noprotoopt
142    ;;; No space left on device.
143    $nospc
144    ;;; Function not supported.
145    $nosys
146    ;;; The socket is not connected.
147    $notconn
148    ;;; Not a directory or a symbolic link to a directory.
149    $notdir
150    ;;; Directory not empty.
151    $notempty
152    ;;; State not recoverable.
153    $notrecoverable
154    ;;; Not a socket.
155    $notsock
156    ;;; Not supported, or operation not supported on socket.
157    $notsup
158    ;;; Inappropriate I/O control operation.
159    $notty
160    ;;; No such device or address.
161    $nxio
162    ;;; Value too large to be stored in data type.
163    $overflow
164    ;;; Previous owner died.
165    $ownerdead
166    ;;; Operation not permitted.
167    $perm
168    ;;; Broken pipe.
169    $pipe
170    ;;; Protocol error.
171    $proto
172    ;;; Protocol not supported.
173    $protonosupport
174    ;;; Protocol wrong type for socket.
175    $prototype
176    ;;; Result too large.
177    $range
178    ;;; Read-only file system.
179    $rofs
180    ;;; Invalid seek.
181    $spipe
182    ;;; No such process.
183    $srch
184    ;;; Reserved.
185    $stale
186    ;;; Connection timed out.
187    $timedout
188    ;;; Text file busy.
189    $txtbsy
190    ;;; Cross-device link.
191    $xdev
192    ;;; Extension: Capabilities insufficient.
193    $notcapable
194  )
195)
196
197;;; File descriptor rights, determining which actions may be performed.
198(typename $rights
199  (flags u64
200    ;;; The right to invoke `fd_datasync`.
201    ;;
202    ;;; If `path_open` is set, includes the right to invoke
203    ;;; `path_open` with `fdflags::dsync`.
204    $fd_datasync
205    ;;; The right to invoke `fd_read` and `sock_recv`.
206    ;;
207    ;;; If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
208    $fd_read
209    ;;; The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
210    $fd_seek
211    ;;; The right to invoke `fd_fdstat_set_flags`.
212    $fd_fdstat_set_flags
213    ;;; The right to invoke `fd_sync`.
214    ;;
215    ;;; If `path_open` is set, includes the right to invoke
216    ;;; `path_open` with `fdflags::rsync` and `fdflags::dsync`.
217    $fd_sync
218    ;;; The right to invoke `fd_seek` in such a way that the file offset
219    ;;; remains unaltered (i.e., `whence::cur` with offset zero), or to
220    ;;; invoke `fd_tell`.
221    $fd_tell
222    ;;; The right to invoke `fd_write` and `sock_send`.
223    ;;; If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
224    $fd_write
225    ;;; The right to invoke `fd_advise`.
226    $fd_advise
227    ;;; The right to invoke `fd_allocate`.
228    $fd_allocate
229    ;;; The right to invoke `path_create_directory`.
230    $path_create_directory
231    ;;; If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
232    $path_create_file
233    ;;; The right to invoke `path_link` with the file descriptor as the
234    ;;; source directory.
235    $path_link_source
236    ;;; The right to invoke `path_link` with the file descriptor as the
237    ;;; target directory.
238    $path_link_target
239    ;;; The right to invoke `path_open`.
240    $path_open
241    ;;; The right to invoke `fd_readdir`.
242    $fd_readdir
243    ;;; The right to invoke `path_readlink`.
244    $path_readlink
245    ;;; The right to invoke `path_rename` with the file descriptor as the source directory.
246    $path_rename_source
247    ;;; The right to invoke `path_rename` with the file descriptor as the target directory.
248    $path_rename_target
249    ;;; The right to invoke `path_filestat_get`.
250    $path_filestat_get
251    ;;; The right to change a file's size (there is no `path_filestat_set_size`).
252    ;;; If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
253    $path_filestat_set_size
254    ;;; The right to invoke `path_filestat_set_times`.
255    $path_filestat_set_times
256    ;;; The right to invoke `fd_filestat_get`.
257    $fd_filestat_get
258    ;;; The right to invoke `fd_filestat_set_size`.
259    $fd_filestat_set_size
260    ;;; The right to invoke `fd_filestat_set_times`.
261    $fd_filestat_set_times
262    ;;; The right to invoke `path_symlink`.
263    $path_symlink
264    ;;; The right to invoke `path_remove_directory`.
265    $path_remove_directory
266    ;;; The right to invoke `path_unlink_file`.
267    $path_unlink_file
268    ;;; If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
269    ;;; If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
270    $poll_fd_readwrite
271    ;;; The right to invoke `sock_shutdown`.
272    $sock_shutdown
273  )
274)
275
276;;; A file descriptor handle.
277(typename $fd (handle))
278
279;;; A region of memory for scatter/gather reads.
280(typename $iovec
281  (struct
282    ;;; The address of the buffer to be filled.
283    (field $buf (@witx pointer u8))
284    ;;; The length of the buffer to be filled.
285    (field $buf_len $size)
286  )
287)
288
289;;; A region of memory for scatter/gather writes.
290(typename $ciovec
291  (struct
292    ;;; The address of the buffer to be written.
293    (field $buf (@witx const_pointer u8))
294    ;;; The length of the buffer to be written.
295    (field $buf_len $size)
296  )
297)
298
299(typename $iovec_array (array $iovec))
300(typename $ciovec_array (array $ciovec))
301
302;;; Relative offset within a file.
303(typename $filedelta s64)
304
305;;; The position relative to which to set the offset of the file descriptor.
306(typename $whence
307  (enum u8
308    ;;; Seek relative to start-of-file.
309    $set
310    ;;; Seek relative to current position.
311    $cur
312    ;;; Seek relative to end-of-file.
313    $end
314  )
315)
316
317;;; A reference to the offset of a directory entry.
318;;;
319;;; The value 0 signifies the start of the directory.
320(typename $dircookie u64)
321
322;;; The type for the $d_namlen field of $dirent.
323(typename $dirnamlen u32)
324
325;;; File serial number that is unique within its file system.
326(typename $inode u64)
327
328;;; The type of a file descriptor or file.
329(typename $filetype
330  (enum u8
331    ;;; The type of the file descriptor or file is unknown or is different from any of the other types specified.
332    $unknown
333    ;;; The file descriptor or file refers to a block device inode.
334    $block_device
335    ;;; The file descriptor or file refers to a character device inode.
336    $character_device
337    ;;; The file descriptor or file refers to a directory inode.
338    $directory
339    ;;; The file descriptor or file refers to a regular file inode.
340    $regular_file
341    ;;; The file descriptor or file refers to a datagram socket.
342    $socket_dgram
343    ;;; The file descriptor or file refers to a byte-stream socket.
344    $socket_stream
345    ;;; The file refers to a symbolic link inode.
346    $symbolic_link
347  )
348)
349
350;;; A directory entry.
351(typename $dirent
352  (struct
353    ;;; The offset of the next directory entry stored in this directory.
354    (field $d_next $dircookie)
355    ;;; The serial number of the file referred to by this directory entry.
356    (field $d_ino $inode)
357    ;;; The length of the name of the directory entry.
358    (field $d_namlen $dirnamlen)
359    ;;; The type of the file referred to by this directory entry.
360    (field $d_type $filetype)
361  )
362)
363
364;;; File or memory access pattern advisory information.
365(typename $advice
366  (enum u8
367    ;;; The application has no advice to give on its behavior with respect to the specified data.
368    $normal
369    ;;; The application expects to access the specified data sequentially from lower offsets to higher offsets.
370    $sequential
371    ;;; The application expects to access the specified data in a random order.
372    $random
373    ;;; The application expects to access the specified data in the near future.
374    $willneed
375    ;;; The application expects that it will not access the specified data in the near future.
376    $dontneed
377    ;;; The application expects to access the specified data once and then not reuse it thereafter.
378    $noreuse
379  )
380)
381
382;;; File descriptor flags.
383(typename $fdflags
384  (flags u16
385    ;;; Append mode: Data written to the file is always appended to the file's end.
386    $append
387    ;;; Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
388    $dsync
389    ;;; Non-blocking mode.
390    $nonblock
391    ;;; Synchronized read I/O operations.
392    $rsync
393    ;;; Write according to synchronized I/O file integrity completion. In
394    ;;; addition to synchronizing the data stored in the file, the implementation
395    ;;; may also synchronously update the file's metadata.
396    $sync
397  )
398)
399
400;;; File descriptor attributes.
401(typename $fdstat
402  (struct
403    ;;; File type.
404    (field $fs_filetype $filetype)
405    ;;; File descriptor flags.
406    (field $fs_flags $fdflags)
407    ;;; Rights that apply to this file descriptor.
408    (field $fs_rights_base $rights)
409    ;;; Maximum set of rights that may be installed on new file descriptors that
410    ;;; are created through this file descriptor, e.g., through `path_open`.
411    (field $fs_rights_inheriting $rights)
412  )
413)
414
415;;; Identifier for a device containing a file system. Can be used in combination
416;;; with `inode` to uniquely identify a file or directory in the filesystem.
417(typename $device u64)
418
419;;; Which file time attributes to adjust.
420(typename $fstflags
421  (flags u16
422    ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`.
423    $atim
424    ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`.
425    $atim_now
426    ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
427    $mtim
428    ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
429    $mtim_now
430  )
431)
432
433;;; Flags determining the method of how paths are resolved.
434(typename $lookupflags
435  (flags u32
436    ;;; As long as the resolved path corresponds to a symbolic link, it is expanded.
437    $symlink_follow
438  )
439)
440
441;;; Open flags used by `path_open`.
442(typename $oflags
443  (flags u16
444    ;;; Create file if it does not exist.
445    $creat
446    ;;; Fail if not a directory.
447    $directory
448    ;;; Fail if file already exists.
449    $excl
450    ;;; Truncate file to size 0.
451    $trunc
452  )
453)
454
455;;; Number of hard links to an inode.
456(typename $linkcount u64)
457
458;;; File attributes.
459(typename $filestat
460  (struct
461    ;;; Device ID of device containing the file.
462    (field $dev $device)
463    ;;; File serial number.
464    (field $ino $inode)
465    ;;; File type.
466    (field $filetype $filetype)
467    ;;; Number of hard links to the file.
468    (field $nlink $linkcount)
469    ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
470    (field $size $filesize)
471    ;;; Last data access timestamp.
472    (field $atim $timestamp)
473    ;;; Last data modification timestamp.
474    (field $mtim $timestamp)
475    ;;; Last file status change timestamp.
476    (field $ctim $timestamp)
477  )
478)
479
480;;; User-provided value that may be attached to objects that is retained when
481;;; extracted from the implementation.
482(typename $userdata u64)
483
484;;; Type of a subscription to an event or its occurrence.
485(typename $eventtype
486  (enum u8
487    ;;; The time value of clock `subscription_clock::id` has
488    ;;; reached timestamp `subscription_clock::timeout`.
489    $clock
490    ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has data
491    ;;; available for reading. This event always triggers for regular files.
492    $fd_read
493    ;;; File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
494    ;;; available for writing. This event always triggers for regular files.
495    $fd_write
496  )
497)
498
499;;; The state of the file descriptor subscribed to with
500;;; `eventtype::fd_read` or `eventtype::fd_write`.
501(typename $eventrwflags
502  (flags u16
503    ;;; The peer of this socket has closed or disconnected.
504    $fd_readwrite_hangup
505  )
506)
507
508;;; The contents of an $event when type is `eventtype::fd_read` or
509;;; `eventtype::fd_write`.
510(typename $event_fd_readwrite
511  (struct
512    ;;; The number of bytes available for reading or writing.
513    (field $nbytes $filesize)
514    ;;; The state of the file descriptor.
515    (field $flags $eventrwflags)
516  )
517)
518
519;;; An event that occurred.
520(typename $event
521  (struct
522    ;;; User-provided value that got attached to `subscription::userdata`.
523    (field $userdata $userdata)
524    ;;; If non-zero, an error that occurred while processing the subscription request.
525    (field $error $errno)
526    ;;; The type of event that occured
527    (field $type $eventtype)
528    ;;; The contents of the event, if it is an `eventtype::fd_read` or
529    ;;; `eventtype::fd_write`. `eventtype::clock` events ignore this field.
530    (field $fd_readwrite $event_fd_readwrite)
531  )
532)
533
534;;; Flags determining how to interpret the timestamp provided in
535;;; `subscription_clock::timeout`.
536(typename $subclockflags
537  (flags u16
538    ;;; If set, treat the timestamp provided in
539    ;;; `subscription_clock::timeout` as an absolute timestamp of clock
540    ;;; `subscription_clock::id`. If clear, treat the timestamp
541    ;;; provided in `subscription_clock::timeout` relative to the
542    ;;; current time value of clock `subscription_clock::id`.
543    $subscription_clock_abstime
544  )
545)
546
547;;; The contents of a `subscription` when type is `eventtype::clock`.
548(typename $subscription_clock
549  (struct
550    ;;; The clock against which to compare the timestamp.
551    (field $id $clockid)
552    ;;; The absolute or relative timestamp.
553    (field $timeout $timestamp)
554    ;;; The amount of time that the implementation may wait additionally
555    ;;; to coalesce with other events.
556    (field $precision $timestamp)
557    ;;; Flags specifying whether the timeout is absolute or relative
558    (field $flags $subclockflags)
559  )
560)
561
562;;; The contents of a `subscription` when type is type is
563;;; `eventtype::fd_read` or `eventtype::fd_write`.
564(typename $subscription_fd_readwrite
565  (struct
566    ;;; The file descriptor on which to wait for it to become ready for reading or writing.
567    (field $file_descriptor $fd)
568  )
569)
570
571;;; The contents of a `subscription`.
572(typename $subscription_u
573  (union $eventtype
574    (field $clock $subscription_clock)
575    (field $fd_read  $subscription_fd_readwrite)
576    (field $fd_write $subscription_fd_readwrite)
577  )
578)
579
580;;; Subscription to an event.
581(typename $subscription
582  (struct
583    ;;; User-provided value that is attached to the subscription in the
584    ;;; implementation and returned through `event::userdata`.
585    (field $userdata $userdata)
586    ;;; The type of the event to which to subscribe, and its contents
587    (field $u $subscription_u)
588  )
589)
590
591;;; Exit code generated by a process when exiting.
592(typename $exitcode u32)
593
594;;; Signal condition.
595(typename $signal
596  (enum u8
597    ;;; No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
598    ;;; so this value is reserved.
599    $none
600    ;;; Hangup.
601    ;;; Action: Terminates the process.
602    $hup
603    ;;; Terminate interrupt signal.
604    ;;; Action: Terminates the process.
605    $int
606    ;;; Terminal quit signal.
607    ;;; Action: Terminates the process.
608    $quit
609    ;;; Illegal instruction.
610    ;;; Action: Terminates the process.
611    $ill
612    ;;; Trace/breakpoint trap.
613    ;;; Action: Terminates the process.
614    $trap
615    ;;; Process abort signal.
616    ;;; Action: Terminates the process.
617    $abrt
618    ;;; Access to an undefined portion of a memory object.
619    ;;; Action: Terminates the process.
620    $bus
621    ;;; Erroneous arithmetic operation.
622    ;;; Action: Terminates the process.
623    $fpe
624    ;;; Kill.
625    ;;; Action: Terminates the process.
626    $kill
627    ;;; User-defined signal 1.
628    ;;; Action: Terminates the process.
629    $usr1
630    ;;; Invalid memory reference.
631    ;;; Action: Terminates the process.
632    $segv
633    ;;; User-defined signal 2.
634    ;;; Action: Terminates the process.
635    $usr2
636    ;;; Write on a pipe with no one to read it.
637    ;;; Action: Ignored.
638    $pipe
639    ;;; Alarm clock.
640    ;;; Action: Terminates the process.
641    $alrm
642    ;;; Termination signal.
643    ;;; Action: Terminates the process.
644    $term
645    ;;; Child process terminated, stopped, or continued.
646    ;;; Action: Ignored.
647    $chld
648    ;;; Continue executing, if stopped.
649    ;;; Action: Continues executing, if stopped.
650    $cont
651    ;;; Stop executing.
652    ;;; Action: Stops executing.
653    $stop
654    ;;; Terminal stop signal.
655    ;;; Action: Stops executing.
656    $tstp
657    ;;; Background process attempting read.
658    ;;; Action: Stops executing.
659    $ttin
660    ;;; Background process attempting write.
661    ;;; Action: Stops executing.
662    $ttou
663    ;;; High bandwidth data is available at a socket.
664    ;;; Action: Ignored.
665    $urg
666    ;;; CPU time limit exceeded.
667    ;;; Action: Terminates the process.
668    $xcpu
669    ;;; File size limit exceeded.
670    ;;; Action: Terminates the process.
671    $xfsz
672    ;;; Virtual timer expired.
673    ;;; Action: Terminates the process.
674    $vtalrm
675    ;;; Profiling timer expired.
676    ;;; Action: Terminates the process.
677    $prof
678    ;;; Window changed.
679    ;;; Action: Ignored.
680    $winch
681    ;;; I/O possible.
682    ;;; Action: Terminates the process.
683    $poll
684    ;;; Power failure.
685    ;;; Action: Terminates the process.
686    $pwr
687    ;;; Bad system call.
688    ;;; Action: Terminates the process.
689    $sys
690  )
691)
692
693;;; Flags provided to `sock_recv`.
694(typename $riflags
695  (flags u16
696    ;;; Returns the message without removing it from the socket's receive queue.
697    $recv_peek
698    ;;; On byte-stream sockets, block until the full amount of data can be returned.
699    $recv_waitall
700  )
701)
702
703;;; Flags returned by `sock_recv`.
704(typename $roflags
705  (flags u16
706    ;;; Returned by `sock_recv`: Message data has been truncated.
707    $recv_data_truncated
708  )
709)
710
711;;; Flags provided to `sock_send`. As there are currently no flags
712;;; defined, it must be set to zero.
713(typename $siflags u16)
714
715;;; Which channels on a socket to shut down.
716(typename $sdflags
717  (flags u8
718    ;;; Disables further receive operations.
719    $rd
720    ;;; Disables further send operations.
721    $wr
722  )
723)
724
725;;; Identifiers for preopened capabilities.
726(typename $preopentype
727  (enum u8
728    ;;; A pre-opened directory.
729    $dir
730  )
731)
732
733;;; The contents of a $prestat when type is `preopentype::dir`.
734(typename $prestat_dir
735  (struct
736    ;;; The length of the directory name for use with `fd_prestat_dir_name`.
737    (field $pr_name_len $size)
738  )
739)
740
741;;; Information about a pre-opened capability.
742(typename $prestat
743  (union $preopentype
744    (field $dir $prestat_dir)
745  )
746)
747
748