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