1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
|
;; WASI Preview. This is an evolution of the API that WASI initially
;; launched with.
;;
;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi).
;;
;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md)
;; for an explanation of what that means.
(use "typenames.witx")
(module $wasi_snapshot_preview1
;;; Linear memory to be accessed by WASI functions that need it.
(import "memory" (memory))
;;; Read command-line argument data.
;;; The size of the array should match that returned by `args_sizes_get`
(@interface func (export "args_get")
(param $argv (@witx pointer (@witx pointer u8)))
(param $argv_buf (@witx pointer u8))
(result $error (expected (error $errno)))
)
;;; Return command-line argument data sizes.
(@interface func (export "args_sizes_get")
;;; Returns the number of arguments and the size of the argument string
;;; data, or an error.
(result $error (expected (tuple $size $size) (error $errno)))
)
;;; Read environment variable data.
;;; The sizes of the buffers should match that returned by `environ_sizes_get`.
(@interface func (export "environ_get")
(param $environ (@witx pointer (@witx pointer u8)))
(param $environ_buf (@witx pointer u8))
(result $error (expected (error $errno)))
)
;;; Return environment variable data sizes.
(@interface func (export "environ_sizes_get")
;;; Returns the number of environment variable arguments and the size of the
;;; environment variable data.
(result $error (expected (tuple $size $size) (error $errno)))
)
;;; Return the resolution of a clock.
;;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
;;; return `errno::inval`.
;;; Note: This is similar to `clock_getres` in POSIX.
(@interface func (export "clock_res_get")
;;; The clock for which to return the resolution.
(param $id $clockid)
;;; The resolution of the clock, or an error if one happened.
(result $error (expected $timestamp (error $errno)))
)
;;; Return the time value of a clock.
;;; Note: This is similar to `clock_gettime` in POSIX.
(@interface func (export "clock_time_get")
;;; The clock for which to return the time.
(param $id $clockid)
;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
(param $precision $timestamp)
;;; The time value of the clock.
(result $error (expected $timestamp (error $errno)))
)
;;; Provide file advisory information on a file descriptor.
;;; Note: This is similar to `posix_fadvise` in POSIX.
(@interface func (export "fd_advise")
(param $fd $fd)
;;; The offset within the file to which the advisory applies.
(param $offset $filesize)
;;; The length of the region to which the advisory applies.
(param $len $filesize)
;;; The advice.
(param $advice $advice)
(result $error (expected (error $errno)))
)
;;; Force the allocation of space in a file.
;;; Note: This is similar to `posix_fallocate` in POSIX.
(@interface func (export "fd_allocate")
(param $fd $fd)
;;; The offset at which to start the allocation.
(param $offset $filesize)
;;; The length of the area that is allocated.
(param $len $filesize)
(result $error (expected (error $errno)))
)
;;; Close a file descriptor.
;;; Note: This is similar to `close` in POSIX.
(@interface func (export "fd_close")
(param $fd $fd)
(result $error (expected (error $errno)))
)
;;; Synchronize the data of a file to disk.
;;; Note: This is similar to `fdatasync` in POSIX.
(@interface func (export "fd_datasync")
(param $fd $fd)
(result $error (expected (error $errno)))
)
;;; Get the attributes of a file descriptor.
;;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
(@interface func (export "fd_fdstat_get")
(param $fd $fd)
;;; The buffer where the file descriptor's attributes are stored.
(result $error (expected $fdstat (error $errno)))
)
;;; Adjust the flags associated with a file descriptor.
;;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
(@interface func (export "fd_fdstat_set_flags")
(param $fd $fd)
;;; The desired values of the file descriptor flags.
(param $flags $fdflags)
(result $error (expected (error $errno)))
)
;;; Adjust the rights associated with a file descriptor.
;;; This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
(@interface func (export "fd_fdstat_set_rights")
(param $fd $fd)
;;; The desired rights of the file descriptor.
(param $fs_rights_base $rights)
(param $fs_rights_inheriting $rights)
(result $error (expected (error $errno)))
)
;;; Return the attributes of an open file.
(@interface func (export "fd_filestat_get")
(param $fd $fd)
;;; The buffer where the file's attributes are stored.
(result $error (expected $filestat (error $errno)))
)
;;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
;;; Note: This is similar to `ftruncate` in POSIX.
(@interface func (export "fd_filestat_set_size")
(param $fd $fd)
;;; The desired file size.
(param $size $filesize)
(result $error (expected (error $errno)))
)
;;; Adjust the timestamps of an open file or directory.
;;; Note: This is similar to `futimens` in POSIX.
(@interface func (export "fd_filestat_set_times")
(param $fd $fd)
;;; The desired values of the data access timestamp.
(param $atim $timestamp)
;;; The desired values of the data modification timestamp.
(param $mtim $timestamp)
;;; A bitmask indicating which timestamps to adjust.
(param $fst_flags $fstflags)
(result $error (expected (error $errno)))
)
;;; Read from a file descriptor, without using and updating the file descriptor's offset.
;;; Note: This is similar to `preadv` in POSIX.
(@interface func (export "fd_pread")
(param $fd $fd)
;;; List of scatter/gather vectors in which to store data.
(param $iovs $iovec_array)
;;; The offset within the file at which to read.
(param $offset $filesize)
;;; The number of bytes read.
(result $error (expected $size (error $errno)))
)
;;; Return a description of the given preopened file descriptor.
(@interface func (export "fd_prestat_get")
(param $fd $fd)
;;; The buffer where the description is stored.
(result $error (expected $prestat (error $errno)))
)
;;; Return a description of the given preopened file descriptor.
(@interface func (export "fd_prestat_dir_name")
(param $fd $fd)
;;; A buffer into which to write the preopened directory name.
(param $path (@witx pointer u8))
(param $path_len $size)
(result $error (expected (error $errno)))
)
;;; Write to a file descriptor, without using and updating the file descriptor's offset.
;;; Note: This is similar to `pwritev` in POSIX.
(@interface func (export "fd_pwrite")
(param $fd $fd)
;;; List of scatter/gather vectors from which to retrieve data.
(param $iovs $ciovec_array)
;;; The offset within the file at which to write.
(param $offset $filesize)
;;; The number of bytes written.
(result $error (expected $size (error $errno)))
)
;;; Read from a file descriptor.
;;; Note: This is similar to `readv` in POSIX.
(@interface func (export "fd_read")
(param $fd $fd)
;;; List of scatter/gather vectors to which to store data.
(param $iovs $iovec_array)
;;; The number of bytes read.
(result $error (expected $size (error $errno)))
)
;;; Read directory entries from a directory.
;;; When successful, the contents of the output buffer consist of a sequence of
;;; directory entries. Each directory entry consists of a `dirent` object,
;;; followed by `dirent::d_namlen` bytes holding the name of the directory
;;; entry.
;;
;;; This function fills the output buffer as much as possible, potentially
;;; truncating the last directory entry. This allows the caller to grow its
;;; read buffer size in case it's too small to fit a single large directory
;;; entry, or skip the oversized directory entry.
(@interface func (export "fd_readdir")
(param $fd $fd)
;;; The buffer where directory entries are stored
(param $buf (@witx pointer u8))
(param $buf_len $size)
;;; The location within the directory to start reading
(param $cookie $dircookie)
;;; 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.
(result $error (expected $size (error $errno)))
)
;;; Atomically replace a file descriptor by renumbering another file descriptor.
;;
;;; Due to the strong focus on thread safety, this environment does not provide
;;; a mechanism to duplicate or renumber a file descriptor to an arbitrary
;;; number, like `dup2()`. This would be prone to race conditions, as an actual
;;; file descriptor with the same number could be allocated by a different
;;; thread at the same time.
;;
;;; This function provides a way to atomically renumber file descriptors, which
;;; would disappear if `dup2()` were to be removed entirely.
(@interface func (export "fd_renumber")
(param $fd $fd)
;;; The file descriptor to overwrite.
(param $to $fd)
(result $error (expected (error $errno)))
)
;;; Move the offset of a file descriptor.
;;; Note: This is similar to `lseek` in POSIX.
(@interface func (export "fd_seek")
(param $fd $fd)
;;; The number of bytes to move.
(param $offset $filedelta)
;;; The base from which the offset is relative.
(param $whence $whence)
;;; The new offset of the file descriptor, relative to the start of the file.
(result $error (expected $filesize (error $errno)))
)
;;; Synchronize the data and metadata of a file to disk.
;;; Note: This is similar to `fsync` in POSIX.
(@interface func (export "fd_sync")
(param $fd $fd)
(result $error (expected (error $errno)))
)
;;; Return the current offset of a file descriptor.
;;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
(@interface func (export "fd_tell")
(param $fd $fd)
;;; The current offset of the file descriptor, relative to the start of the file.
(result $error (expected $filesize (error $errno)))
)
;;; Write to a file descriptor.
;;; Note: This is similar to `writev` in POSIX.
(@interface func (export "fd_write")
(param $fd $fd)
;;; List of scatter/gather vectors from which to retrieve data.
(param $iovs $ciovec_array)
(result $error (expected $size (error $errno)))
)
;;; Create a directory.
;;; Note: This is similar to `mkdirat` in POSIX.
(@interface func (export "path_create_directory")
(param $fd $fd)
;;; The path at which to create the directory.
(param $path string)
(result $error (expected (error $errno)))
)
;;; Return the attributes of a file or directory.
;;; Note: This is similar to `stat` in POSIX.
(@interface func (export "path_filestat_get")
(param $fd $fd)
;;; Flags determining the method of how the path is resolved.
(param $flags $lookupflags)
;;; The path of the file or directory to inspect.
(param $path string)
;;; The buffer where the file's attributes are stored.
(result $error (expected $filestat (error $errno)))
)
;;; Adjust the timestamps of a file or directory.
;;; Note: This is similar to `utimensat` in POSIX.
(@interface func (export "path_filestat_set_times")
(param $fd $fd)
;;; Flags determining the method of how the path is resolved.
(param $flags $lookupflags)
;;; The path of the file or directory to operate on.
(param $path string)
;;; The desired values of the data access timestamp.
(param $atim $timestamp)
;;; The desired values of the data modification timestamp.
(param $mtim $timestamp)
;;; A bitmask indicating which timestamps to adjust.
(param $fst_flags $fstflags)
(result $error (expected (error $errno)))
)
;;; Create a hard link.
;;; Note: This is similar to `linkat` in POSIX.
(@interface func (export "path_link")
(param $old_fd $fd)
;;; Flags determining the method of how the path is resolved.
(param $old_flags $lookupflags)
;;; The source path from which to link.
(param $old_path string)
;;; The working directory at which the resolution of the new path starts.
(param $new_fd $fd)
;;; The destination path at which to create the hard link.
(param $new_path string)
(result $error (expected (error $errno)))
)
;;; Open a file or directory.
;;
;;; The returned file descriptor is not guaranteed to be the lowest-numbered
;;; file descriptor not currently open; it is randomized to prevent
;;; applications from depending on making assumptions about indexes, since this
;;; is error-prone in multi-threaded contexts. The returned file descriptor is
;;; guaranteed to be less than 2**31.
;;
;;; Note: This is similar to `openat` in POSIX.
(@interface func (export "path_open")
(param $fd $fd)
;;; Flags determining the method of how the path is resolved.
(param $dirflags $lookupflags)
;;; The relative path of the file or directory to open, relative to the
;;; `path_open::fd` directory.
(param $path string)
;;; The method by which to open the file.
(param $oflags $oflags)
;;; The initial rights of the newly created file descriptor. The
;;; implementation is allowed to return a file descriptor with fewer rights
;;; than specified, if and only if those rights do not apply to the type of
;;; file being opened.
;;
;;; The *base* rights are rights that will apply to operations using the file
;;; descriptor itself, while the *inheriting* rights are rights that apply to
;;; file descriptors derived from it.
(param $fs_rights_base $rights)
(param $fs_rights_inheriting $rights)
(param $fdflags $fdflags)
;;; The file descriptor of the file that has been opened.
(result $error (expected $fd (error $errno)))
)
;;; Read the contents of a symbolic link.
;;; Note: This is similar to `readlinkat` in POSIX.
(@interface func (export "path_readlink")
(param $fd $fd)
;;; The path of the symbolic link from which to read.
(param $path string)
;;; The buffer to which to write the contents of the symbolic link.
(param $buf (@witx pointer u8))
(param $buf_len $size)
;;; The number of bytes placed in the buffer.
(result $error (expected $size (error $errno)))
)
;;; Remove a directory.
;;; Return `errno::notempty` if the directory is not empty.
;;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
(@interface func (export "path_remove_directory")
(param $fd $fd)
;;; The path to a directory to remove.
(param $path string)
(result $error (expected (error $errno)))
)
;;; Rename a file or directory.
;;; Note: This is similar to `renameat` in POSIX.
(@interface func (export "path_rename")
(param $fd $fd)
;;; The source path of the file or directory to rename.
(param $old_path string)
;;; The working directory at which the resolution of the new path starts.
(param $new_fd $fd)
;;; The destination path to which to rename the file or directory.
(param $new_path string)
(result $error (expected (error $errno)))
)
;;; Create a symbolic link.
;;; Note: This is similar to `symlinkat` in POSIX.
(@interface func (export "path_symlink")
;;; The contents of the symbolic link.
(param $old_path string)
(param $fd $fd)
;;; The destination path at which to create the symbolic link.
(param $new_path string)
(result $error (expected (error $errno)))
)
;;; Unlink a file.
;;; Return `errno::isdir` if the path refers to a directory.
;;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
(@interface func (export "path_unlink_file")
(param $fd $fd)
;;; The path to a file to unlink.
(param $path string)
(result $error (expected (error $errno)))
)
;;; Concurrently poll for the occurrence of a set of events.
(@interface func (export "poll_oneoff")
;;; The events to which to subscribe.
(param $in (@witx const_pointer $subscription))
;;; The events that have occurred.
(param $out (@witx pointer $event))
;;; Both the number of subscriptions and events.
(param $nsubscriptions $size)
;;; The number of events stored.
(result $error (expected $size (error $errno)))
)
;;; Terminate the process normally. An exit code of 0 indicates successful
;;; termination of the program. The meanings of other values is dependent on
;;; the environment.
(@interface func (export "proc_exit")
;;; The exit code returned by the process.
(param $rval $exitcode)
(@witx noreturn)
)
;;; Send a signal to the process of the calling thread.
;;; Note: This is similar to `raise` in POSIX.
(@interface func (export "proc_raise")
;;; The signal condition to trigger.
(param $sig $signal)
(result $error (expected (error $errno)))
)
;;; Temporarily yield execution of the calling thread.
;;; Note: This is similar to `sched_yield` in POSIX.
(@interface func (export "sched_yield")
(result $error (expected (error $errno)))
)
;;; Write high-quality random data into a buffer.
;;; This function blocks when the implementation is unable to immediately
;;; provide sufficient high-quality random data.
;;; This function may execute slowly, so when large mounts of random data are
;;; required, it's advisable to use this function to seed a pseudo-random
;;; number generator, rather than to provide the random data directly.
(@interface func (export "random_get")
;;; The buffer to fill with random data.
(param $buf (@witx pointer u8))
(param $buf_len $size)
(result $error (expected (error $errno)))
)
;;; Receive a message from a socket.
;;; Note: This is similar to `recv` in POSIX, though it also supports reading
;;; the data into multiple buffers in the manner of `readv`.
(@interface func (export "sock_recv")
(param $fd $fd)
;;; List of scatter/gather vectors to which to store data.
(param $ri_data $iovec_array)
;;; Message flags.
(param $ri_flags $riflags)
;;; Number of bytes stored in ri_data and message flags.
(result $error (expected (tuple $size $roflags) (error $errno)))
)
;;; Send a message on a socket.
;;; Note: This is similar to `send` in POSIX, though it also supports writing
;;; the data from multiple buffers in the manner of `writev`.
(@interface func (export "sock_send")
(param $fd $fd)
;;; List of scatter/gather vectors to which to retrieve data
(param $si_data $ciovec_array)
;;; Message flags.
(param $si_flags $siflags)
;;; Number of bytes transmitted.
(result $error (expected $size (error $errno)))
)
;;; Shut down socket send and receive channels.
;;; Note: This is similar to `shutdown` in POSIX.
(@interface func (export "sock_shutdown")
(param $fd $fd)
;;; Which channels on the socket to shut down.
(param $how $sdflags)
(result $error (expected (error $errno)))
)
)
|