1use core::fmt;
6use core::mem::MaybeUninit;
7pub type Size = usize;
8pub type Filesize = u64;
9pub type Timestamp = u64;
10#[repr(transparent)]
11#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
12pub struct Clockid(u32);
13pub const CLOCKID_REALTIME: Clockid = Clockid(0);
16pub const CLOCKID_MONOTONIC: Clockid = Clockid(1);
21pub const CLOCKID_PROCESS_CPUTIME_ID: Clockid = Clockid(2);
23pub const CLOCKID_THREAD_CPUTIME_ID: Clockid = Clockid(3);
25impl Clockid {
26 pub const fn raw(&self) -> u32 {
27 self.0
28 }
29
30 pub fn name(&self) -> &'static str {
31 match self.0 {
32 0 => "REALTIME",
33 1 => "MONOTONIC",
34 2 => "PROCESS_CPUTIME_ID",
35 3 => "THREAD_CPUTIME_ID",
36 _ => unsafe { core::hint::unreachable_unchecked() },
37 }
38 }
39 pub fn message(&self) -> &'static str {
40 match self.0 {
41 0 => {
42 "The clock measuring real time. Time value zero corresponds with
431970-01-01T00:00:00Z."
44 }
45 1 => {
46 "The store-wide monotonic clock, which is defined as a clock measuring
47real time, whose value cannot be adjusted and which cannot have negative
48clock jumps. The epoch of this clock is undefined. The absolute time
49value of this clock therefore has no meaning."
50 }
51 2 => "The CPU-time clock associated with the current process.",
52 3 => "The CPU-time clock associated with the current thread.",
53 _ => unsafe { core::hint::unreachable_unchecked() },
54 }
55 }
56}
57impl fmt::Debug for Clockid {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.debug_struct("Clockid")
60 .field("code", &self.0)
61 .field("name", &self.name())
62 .field("message", &self.message())
63 .finish()
64 }
65}
66
67#[repr(transparent)]
68#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
69pub struct Errno(u16);
70pub const ERRNO_SUCCESS: Errno = Errno(0);
72pub const ERRNO_2BIG: Errno = Errno(1);
74pub const ERRNO_ACCES: Errno = Errno(2);
76pub const ERRNO_ADDRINUSE: Errno = Errno(3);
78pub const ERRNO_ADDRNOTAVAIL: Errno = Errno(4);
80pub const ERRNO_AFNOSUPPORT: Errno = Errno(5);
82pub const ERRNO_AGAIN: Errno = Errno(6);
84pub const ERRNO_ALREADY: Errno = Errno(7);
86pub const ERRNO_BADF: Errno = Errno(8);
88pub const ERRNO_BADMSG: Errno = Errno(9);
90pub const ERRNO_BUSY: Errno = Errno(10);
92pub const ERRNO_CANCELED: Errno = Errno(11);
94pub const ERRNO_CHILD: Errno = Errno(12);
96pub const ERRNO_CONNABORTED: Errno = Errno(13);
98pub const ERRNO_CONNREFUSED: Errno = Errno(14);
100pub const ERRNO_CONNRESET: Errno = Errno(15);
102pub const ERRNO_DEADLK: Errno = Errno(16);
104pub const ERRNO_DESTADDRREQ: Errno = Errno(17);
106pub const ERRNO_DOM: Errno = Errno(18);
108pub const ERRNO_DQUOT: Errno = Errno(19);
110pub const ERRNO_EXIST: Errno = Errno(20);
112pub const ERRNO_FAULT: Errno = Errno(21);
114pub const ERRNO_FBIG: Errno = Errno(22);
116pub const ERRNO_HOSTUNREACH: Errno = Errno(23);
118pub const ERRNO_IDRM: Errno = Errno(24);
120pub const ERRNO_ILSEQ: Errno = Errno(25);
122pub const ERRNO_INPROGRESS: Errno = Errno(26);
124pub const ERRNO_INTR: Errno = Errno(27);
126pub const ERRNO_INVAL: Errno = Errno(28);
128pub const ERRNO_IO: Errno = Errno(29);
130pub const ERRNO_ISCONN: Errno = Errno(30);
132pub const ERRNO_ISDIR: Errno = Errno(31);
134pub const ERRNO_LOOP: Errno = Errno(32);
136pub const ERRNO_MFILE: Errno = Errno(33);
138pub const ERRNO_MLINK: Errno = Errno(34);
140pub const ERRNO_MSGSIZE: Errno = Errno(35);
142pub const ERRNO_MULTIHOP: Errno = Errno(36);
144pub const ERRNO_NAMETOOLONG: Errno = Errno(37);
146pub const ERRNO_NETDOWN: Errno = Errno(38);
148pub const ERRNO_NETRESET: Errno = Errno(39);
150pub const ERRNO_NETUNREACH: Errno = Errno(40);
152pub const ERRNO_NFILE: Errno = Errno(41);
154pub const ERRNO_NOBUFS: Errno = Errno(42);
156pub const ERRNO_NODEV: Errno = Errno(43);
158pub const ERRNO_NOENT: Errno = Errno(44);
160pub const ERRNO_NOEXEC: Errno = Errno(45);
162pub const ERRNO_NOLCK: Errno = Errno(46);
164pub const ERRNO_NOLINK: Errno = Errno(47);
166pub const ERRNO_NOMEM: Errno = Errno(48);
168pub const ERRNO_NOMSG: Errno = Errno(49);
170pub const ERRNO_NOPROTOOPT: Errno = Errno(50);
172pub const ERRNO_NOSPC: Errno = Errno(51);
174pub const ERRNO_NOSYS: Errno = Errno(52);
176pub const ERRNO_NOTCONN: Errno = Errno(53);
178pub const ERRNO_NOTDIR: Errno = Errno(54);
180pub const ERRNO_NOTEMPTY: Errno = Errno(55);
182pub const ERRNO_NOTRECOVERABLE: Errno = Errno(56);
184pub const ERRNO_NOTSOCK: Errno = Errno(57);
186pub const ERRNO_NOTSUP: Errno = Errno(58);
188pub const ERRNO_NOTTY: Errno = Errno(59);
190pub const ERRNO_NXIO: Errno = Errno(60);
192pub const ERRNO_OVERFLOW: Errno = Errno(61);
194pub const ERRNO_OWNERDEAD: Errno = Errno(62);
196pub const ERRNO_PERM: Errno = Errno(63);
198pub const ERRNO_PIPE: Errno = Errno(64);
200pub const ERRNO_PROTO: Errno = Errno(65);
202pub const ERRNO_PROTONOSUPPORT: Errno = Errno(66);
204pub const ERRNO_PROTOTYPE: Errno = Errno(67);
206pub const ERRNO_RANGE: Errno = Errno(68);
208pub const ERRNO_ROFS: Errno = Errno(69);
210pub const ERRNO_SPIPE: Errno = Errno(70);
212pub const ERRNO_SRCH: Errno = Errno(71);
214pub const ERRNO_STALE: Errno = Errno(72);
216pub const ERRNO_TIMEDOUT: Errno = Errno(73);
218pub const ERRNO_TXTBSY: Errno = Errno(74);
220pub const ERRNO_XDEV: Errno = Errno(75);
222pub const ERRNO_NOTCAPABLE: Errno = Errno(76);
224impl Errno {
225 pub const fn raw(&self) -> u16 {
226 self.0
227 }
228
229 pub fn name(&self) -> &'static str {
230 match self.0 {
231 0 => "SUCCESS",
232 1 => "2BIG",
233 2 => "ACCES",
234 3 => "ADDRINUSE",
235 4 => "ADDRNOTAVAIL",
236 5 => "AFNOSUPPORT",
237 6 => "AGAIN",
238 7 => "ALREADY",
239 8 => "BADF",
240 9 => "BADMSG",
241 10 => "BUSY",
242 11 => "CANCELED",
243 12 => "CHILD",
244 13 => "CONNABORTED",
245 14 => "CONNREFUSED",
246 15 => "CONNRESET",
247 16 => "DEADLK",
248 17 => "DESTADDRREQ",
249 18 => "DOM",
250 19 => "DQUOT",
251 20 => "EXIST",
252 21 => "FAULT",
253 22 => "FBIG",
254 23 => "HOSTUNREACH",
255 24 => "IDRM",
256 25 => "ILSEQ",
257 26 => "INPROGRESS",
258 27 => "INTR",
259 28 => "INVAL",
260 29 => "IO",
261 30 => "ISCONN",
262 31 => "ISDIR",
263 32 => "LOOP",
264 33 => "MFILE",
265 34 => "MLINK",
266 35 => "MSGSIZE",
267 36 => "MULTIHOP",
268 37 => "NAMETOOLONG",
269 38 => "NETDOWN",
270 39 => "NETRESET",
271 40 => "NETUNREACH",
272 41 => "NFILE",
273 42 => "NOBUFS",
274 43 => "NODEV",
275 44 => "NOENT",
276 45 => "NOEXEC",
277 46 => "NOLCK",
278 47 => "NOLINK",
279 48 => "NOMEM",
280 49 => "NOMSG",
281 50 => "NOPROTOOPT",
282 51 => "NOSPC",
283 52 => "NOSYS",
284 53 => "NOTCONN",
285 54 => "NOTDIR",
286 55 => "NOTEMPTY",
287 56 => "NOTRECOVERABLE",
288 57 => "NOTSOCK",
289 58 => "NOTSUP",
290 59 => "NOTTY",
291 60 => "NXIO",
292 61 => "OVERFLOW",
293 62 => "OWNERDEAD",
294 63 => "PERM",
295 64 => "PIPE",
296 65 => "PROTO",
297 66 => "PROTONOSUPPORT",
298 67 => "PROTOTYPE",
299 68 => "RANGE",
300 69 => "ROFS",
301 70 => "SPIPE",
302 71 => "SRCH",
303 72 => "STALE",
304 73 => "TIMEDOUT",
305 74 => "TXTBSY",
306 75 => "XDEV",
307 76 => "NOTCAPABLE",
308 _ => unsafe { core::hint::unreachable_unchecked() },
309 }
310 }
311 pub fn message(&self) -> &'static str {
312 match self.0 {
313 0 => "No error occurred. System call completed successfully.",
314 1 => "Argument list too long.",
315 2 => "Permission denied.",
316 3 => "Address in use.",
317 4 => "Address not available.",
318 5 => "Address family not supported.",
319 6 => "Resource unavailable, or operation would block.",
320 7 => "Connection already in progress.",
321 8 => "Bad file descriptor.",
322 9 => "Bad message.",
323 10 => "Device or resource busy.",
324 11 => "Operation canceled.",
325 12 => "No child processes.",
326 13 => "Connection aborted.",
327 14 => "Connection refused.",
328 15 => "Connection reset.",
329 16 => "Resource deadlock would occur.",
330 17 => "Destination address required.",
331 18 => "Mathematics argument out of domain of function.",
332 19 => "Reserved.",
333 20 => "File exists.",
334 21 => "Bad address.",
335 22 => "File too large.",
336 23 => "Host is unreachable.",
337 24 => "Identifier removed.",
338 25 => "Illegal byte sequence.",
339 26 => "Operation in progress.",
340 27 => "Interrupted function.",
341 28 => "Invalid argument.",
342 29 => "I/O error.",
343 30 => "Socket is connected.",
344 31 => "Is a directory.",
345 32 => "Too many levels of symbolic links.",
346 33 => "File descriptor value too large.",
347 34 => "Too many links.",
348 35 => "Message too large.",
349 36 => "Reserved.",
350 37 => "Filename too long.",
351 38 => "Network is down.",
352 39 => "Connection aborted by network.",
353 40 => "Network unreachable.",
354 41 => "Too many files open in system.",
355 42 => "No buffer space available.",
356 43 => "No such device.",
357 44 => "No such file or directory.",
358 45 => "Executable file format error.",
359 46 => "No locks available.",
360 47 => "Reserved.",
361 48 => "Not enough space.",
362 49 => "No message of the desired type.",
363 50 => "Protocol not available.",
364 51 => "No space left on device.",
365 52 => "Function not supported.",
366 53 => "The socket is not connected.",
367 54 => "Not a directory or a symbolic link to a directory.",
368 55 => "Directory not empty.",
369 56 => "State not recoverable.",
370 57 => "Not a socket.",
371 58 => "Not supported, or operation not supported on socket.",
372 59 => "Inappropriate I/O control operation.",
373 60 => "No such device or address.",
374 61 => "Value too large to be stored in data type.",
375 62 => "Previous owner died.",
376 63 => "Operation not permitted.",
377 64 => "Broken pipe.",
378 65 => "Protocol error.",
379 66 => "Protocol not supported.",
380 67 => "Protocol wrong type for socket.",
381 68 => "Result too large.",
382 69 => "Read-only file system.",
383 70 => "Invalid seek.",
384 71 => "No such process.",
385 72 => "Reserved.",
386 73 => "Connection timed out.",
387 74 => "Text file busy.",
388 75 => "Cross-device link.",
389 76 => "Extension: Capabilities insufficient.",
390 _ => unsafe { core::hint::unreachable_unchecked() },
391 }
392 }
393}
394impl fmt::Debug for Errno {
395 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
396 f.debug_struct("Errno")
397 .field("code", &self.0)
398 .field("name", &self.name())
399 .field("message", &self.message())
400 .finish()
401 }
402}
403impl fmt::Display for Errno {
404 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
405 write!(f, "{} (error {})", self.name(), self.0)
406 }
407}
408
409#[cfg(feature = "std")]
410extern crate std;
411#[cfg(feature = "std")]
412impl std::error::Error for Errno {}
413
414pub type Rights = u64;
415pub const RIGHTS_FD_DATASYNC: Rights = 1 << 0;
419pub const RIGHTS_FD_READ: Rights = 1 << 1;
422pub const RIGHTS_FD_SEEK: Rights = 1 << 2;
424pub const RIGHTS_FD_FDSTAT_SET_FLAGS: Rights = 1 << 3;
426pub const RIGHTS_FD_SYNC: Rights = 1 << 4;
430pub const RIGHTS_FD_TELL: Rights = 1 << 5;
434pub const RIGHTS_FD_WRITE: Rights = 1 << 6;
437pub const RIGHTS_FD_ADVISE: Rights = 1 << 7;
439pub const RIGHTS_FD_ALLOCATE: Rights = 1 << 8;
441pub const RIGHTS_PATH_CREATE_DIRECTORY: Rights = 1 << 9;
443pub const RIGHTS_PATH_CREATE_FILE: Rights = 1 << 10;
445pub const RIGHTS_PATH_LINK_SOURCE: Rights = 1 << 11;
448pub const RIGHTS_PATH_LINK_TARGET: Rights = 1 << 12;
451pub const RIGHTS_PATH_OPEN: Rights = 1 << 13;
453pub const RIGHTS_FD_READDIR: Rights = 1 << 14;
455pub const RIGHTS_PATH_READLINK: Rights = 1 << 15;
457pub const RIGHTS_PATH_RENAME_SOURCE: Rights = 1 << 16;
459pub const RIGHTS_PATH_RENAME_TARGET: Rights = 1 << 17;
461pub const RIGHTS_PATH_FILESTAT_GET: Rights = 1 << 18;
463pub const RIGHTS_PATH_FILESTAT_SET_SIZE: Rights = 1 << 19;
466pub const RIGHTS_PATH_FILESTAT_SET_TIMES: Rights = 1 << 20;
468pub const RIGHTS_FD_FILESTAT_GET: Rights = 1 << 21;
470pub const RIGHTS_FD_FILESTAT_SET_SIZE: Rights = 1 << 22;
472pub const RIGHTS_FD_FILESTAT_SET_TIMES: Rights = 1 << 23;
474pub const RIGHTS_PATH_SYMLINK: Rights = 1 << 24;
476pub const RIGHTS_PATH_REMOVE_DIRECTORY: Rights = 1 << 25;
478pub const RIGHTS_PATH_UNLINK_FILE: Rights = 1 << 26;
480pub const RIGHTS_POLL_FD_READWRITE: Rights = 1 << 27;
483pub const RIGHTS_SOCK_SHUTDOWN: Rights = 1 << 28;
485pub const RIGHTS_SOCK_ACCEPT: Rights = 1 << 29;
487
488pub type Fd = u32;
489#[repr(C)]
490#[derive(Copy, Clone, Debug)]
491pub struct Iovec {
492 pub buf: *mut u8,
494 pub buf_len: Size,
496}
497#[repr(C)]
498#[derive(Copy, Clone, Debug)]
499pub struct Ciovec {
500 pub buf: *const u8,
502 pub buf_len: Size,
504}
505pub type IovecArray<'a> = &'a [Iovec];
506pub type CiovecArray<'a> = &'a [Ciovec];
507pub type Filedelta = i64;
508#[repr(transparent)]
509#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
510pub struct Whence(u8);
511pub const WHENCE_SET: Whence = Whence(0);
513pub const WHENCE_CUR: Whence = Whence(1);
515pub const WHENCE_END: Whence = Whence(2);
517impl Whence {
518 pub const fn raw(&self) -> u8 {
519 self.0
520 }
521
522 pub fn name(&self) -> &'static str {
523 match self.0 {
524 0 => "SET",
525 1 => "CUR",
526 2 => "END",
527 _ => unsafe { core::hint::unreachable_unchecked() },
528 }
529 }
530 pub fn message(&self) -> &'static str {
531 match self.0 {
532 0 => "Seek relative to start-of-file.",
533 1 => "Seek relative to current position.",
534 2 => "Seek relative to end-of-file.",
535 _ => unsafe { core::hint::unreachable_unchecked() },
536 }
537 }
538}
539impl fmt::Debug for Whence {
540 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
541 f.debug_struct("Whence")
542 .field("code", &self.0)
543 .field("name", &self.name())
544 .field("message", &self.message())
545 .finish()
546 }
547}
548
549pub type Dircookie = u64;
550pub type Dirnamlen = u32;
551pub type Inode = u64;
552#[repr(transparent)]
553#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
554pub struct Filetype(u8);
555pub const FILETYPE_UNKNOWN: Filetype = Filetype(0);
557pub const FILETYPE_BLOCK_DEVICE: Filetype = Filetype(1);
559pub const FILETYPE_CHARACTER_DEVICE: Filetype = Filetype(2);
561pub const FILETYPE_DIRECTORY: Filetype = Filetype(3);
563pub const FILETYPE_REGULAR_FILE: Filetype = Filetype(4);
565pub const FILETYPE_SOCKET_DGRAM: Filetype = Filetype(5);
567pub const FILETYPE_SOCKET_STREAM: Filetype = Filetype(6);
569pub const FILETYPE_SYMBOLIC_LINK: Filetype = Filetype(7);
571impl Filetype {
572 pub const fn raw(&self) -> u8 {
573 self.0
574 }
575
576 pub fn name(&self) -> &'static str {
577 match self.0 {
578 0 => "UNKNOWN",
579 1 => "BLOCK_DEVICE",
580 2 => "CHARACTER_DEVICE",
581 3 => "DIRECTORY",
582 4 => "REGULAR_FILE",
583 5 => "SOCKET_DGRAM",
584 6 => "SOCKET_STREAM",
585 7 => "SYMBOLIC_LINK",
586 _ => unsafe { core::hint::unreachable_unchecked() },
587 }
588 }
589 pub fn message(&self) -> &'static str {
590 match self.0 {0 => "The type of the file descriptor or file is unknown or is different from any of the other types specified.",1 => "The file descriptor or file refers to a block device inode.",2 => "The file descriptor or file refers to a character device inode.",3 => "The file descriptor or file refers to a directory inode.",4 => "The file descriptor or file refers to a regular file inode.",5 => "The file descriptor or file refers to a datagram socket.",6 => "The file descriptor or file refers to a byte-stream socket.",7 => "The file refers to a symbolic link inode.",_ => unsafe { core::hint::unreachable_unchecked() },}
591 }
592}
593impl fmt::Debug for Filetype {
594 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
595 f.debug_struct("Filetype")
596 .field("code", &self.0)
597 .field("name", &self.name())
598 .field("message", &self.message())
599 .finish()
600 }
601}
602
603#[repr(C)]
604#[derive(Copy, Clone, Debug)]
605pub struct Dirent {
606 pub d_next: Dircookie,
608 pub d_ino: Inode,
610 pub d_namlen: Dirnamlen,
612 pub d_type: Filetype,
614}
615#[repr(transparent)]
616#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
617pub struct Advice(u8);
618pub const ADVICE_NORMAL: Advice = Advice(0);
620pub const ADVICE_SEQUENTIAL: Advice = Advice(1);
622pub const ADVICE_RANDOM: Advice = Advice(2);
624pub const ADVICE_WILLNEED: Advice = Advice(3);
626pub const ADVICE_DONTNEED: Advice = Advice(4);
628pub const ADVICE_NOREUSE: Advice = Advice(5);
630impl Advice {
631 pub const fn raw(&self) -> u8 {
632 self.0
633 }
634
635 pub fn name(&self) -> &'static str {
636 match self.0 {
637 0 => "NORMAL",
638 1 => "SEQUENTIAL",
639 2 => "RANDOM",
640 3 => "WILLNEED",
641 4 => "DONTNEED",
642 5 => "NOREUSE",
643 _ => unsafe { core::hint::unreachable_unchecked() },
644 }
645 }
646 pub fn message(&self) -> &'static str {
647 match self.0 {0 => "The application has no advice to give on its behavior with respect to the specified data.",1 => "The application expects to access the specified data sequentially from lower offsets to higher offsets.",2 => "The application expects to access the specified data in a random order.",3 => "The application expects to access the specified data in the near future.",4 => "The application expects that it will not access the specified data in the near future.",5 => "The application expects to access the specified data once and then not reuse it thereafter.",_ => unsafe { core::hint::unreachable_unchecked() },}
648 }
649}
650impl fmt::Debug for Advice {
651 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
652 f.debug_struct("Advice")
653 .field("code", &self.0)
654 .field("name", &self.name())
655 .field("message", &self.message())
656 .finish()
657 }
658}
659
660pub type Fdflags = u16;
661pub const FDFLAGS_APPEND: Fdflags = 1 << 0;
663pub const FDFLAGS_DSYNC: Fdflags = 1 << 1;
665pub const FDFLAGS_NONBLOCK: Fdflags = 1 << 2;
667pub const FDFLAGS_RSYNC: Fdflags = 1 << 3;
669pub const FDFLAGS_SYNC: Fdflags = 1 << 4;
673
674#[repr(C)]
675#[derive(Copy, Clone, Debug)]
676pub struct Fdstat {
677 pub fs_filetype: Filetype,
679 pub fs_flags: Fdflags,
681 pub fs_rights_base: Rights,
683 pub fs_rights_inheriting: Rights,
686}
687pub type Device = u64;
688pub type Fstflags = u16;
689pub const FSTFLAGS_ATIM: Fstflags = 1 << 0;
691pub const FSTFLAGS_ATIM_NOW: Fstflags = 1 << 1;
693pub const FSTFLAGS_MTIM: Fstflags = 1 << 2;
695pub const FSTFLAGS_MTIM_NOW: Fstflags = 1 << 3;
697
698pub type Lookupflags = u32;
699pub const LOOKUPFLAGS_SYMLINK_FOLLOW: Lookupflags = 1 << 0;
701
702pub type Oflags = u16;
703pub const OFLAGS_CREAT: Oflags = 1 << 0;
705pub const OFLAGS_DIRECTORY: Oflags = 1 << 1;
707pub const OFLAGS_EXCL: Oflags = 1 << 2;
709pub const OFLAGS_TRUNC: Oflags = 1 << 3;
711
712pub type Linkcount = u64;
713#[repr(C)]
714#[derive(Copy, Clone, Debug)]
715pub struct Filestat {
716 pub dev: Device,
718 pub ino: Inode,
720 pub filetype: Filetype,
722 pub nlink: Linkcount,
724 pub size: Filesize,
726 pub atim: Timestamp,
728 pub mtim: Timestamp,
730 pub ctim: Timestamp,
732}
733pub type Userdata = u64;
734#[repr(transparent)]
735#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
736pub struct Eventtype(u8);
737pub const EVENTTYPE_CLOCK: Eventtype = Eventtype(0);
740pub const EVENTTYPE_FD_READ: Eventtype = Eventtype(1);
743pub const EVENTTYPE_FD_WRITE: Eventtype = Eventtype(2);
746impl Eventtype {
747 pub const fn raw(&self) -> u8 {
748 self.0
749 }
750
751 pub fn name(&self) -> &'static str {
752 match self.0 {
753 0 => "CLOCK",
754 1 => "FD_READ",
755 2 => "FD_WRITE",
756 _ => unsafe { core::hint::unreachable_unchecked() },
757 }
758 }
759 pub fn message(&self) -> &'static str {
760 match self.0 {
761 0 => {
762 "The time value of clock `subscription_clock::id` has
763reached timestamp `subscription_clock::timeout`."
764 }
765 1 => {
766 "File descriptor `subscription_fd_readwrite::file_descriptor` has data
767available for reading. This event always triggers for regular files."
768 }
769 2 => {
770 "File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
771available for writing. This event always triggers for regular files."
772 }
773 _ => unsafe { core::hint::unreachable_unchecked() },
774 }
775 }
776}
777impl fmt::Debug for Eventtype {
778 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
779 f.debug_struct("Eventtype")
780 .field("code", &self.0)
781 .field("name", &self.name())
782 .field("message", &self.message())
783 .finish()
784 }
785}
786
787pub type Eventrwflags = u16;
788pub const EVENTRWFLAGS_FD_READWRITE_HANGUP: Eventrwflags = 1 << 0;
790
791#[repr(C)]
792#[derive(Copy, Clone, Debug)]
793pub struct EventFdReadwrite {
794 pub nbytes: Filesize,
796 pub flags: Eventrwflags,
798}
799#[repr(C)]
800#[derive(Copy, Clone, Debug)]
801pub struct Event {
802 pub userdata: Userdata,
804 pub error: Errno,
806 pub type_: Eventtype,
808 pub fd_readwrite: EventFdReadwrite,
811}
812pub type Subclockflags = u16;
813pub const SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME: Subclockflags = 1 << 0;
819
820#[repr(C)]
821#[derive(Copy, Clone, Debug)]
822pub struct SubscriptionClock {
823 pub id: Clockid,
825 pub timeout: Timestamp,
827 pub precision: Timestamp,
830 pub flags: Subclockflags,
832}
833#[repr(C)]
834#[derive(Copy, Clone, Debug)]
835pub struct SubscriptionFdReadwrite {
836 pub file_descriptor: Fd,
838}
839#[repr(C)]
840#[derive(Copy, Clone)]
841pub union SubscriptionUU {
842 pub clock: SubscriptionClock,
843 pub fd_read: SubscriptionFdReadwrite,
844 pub fd_write: SubscriptionFdReadwrite,
845}
846#[repr(C)]
847#[derive(Copy, Clone)]
848pub struct SubscriptionU {
849 pub tag: u8,
850 pub u: SubscriptionUU,
851}
852
853#[repr(C)]
854#[derive(Copy, Clone)]
855pub struct Subscription {
856 pub userdata: Userdata,
859 pub u: SubscriptionU,
861}
862pub type Exitcode = u32;
863#[repr(transparent)]
864#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
865pub struct Signal(u8);
866pub const SIGNAL_NONE: Signal = Signal(0);
869pub const SIGNAL_HUP: Signal = Signal(1);
872pub const SIGNAL_INT: Signal = Signal(2);
875pub const SIGNAL_QUIT: Signal = Signal(3);
878pub const SIGNAL_ILL: Signal = Signal(4);
881pub const SIGNAL_TRAP: Signal = Signal(5);
884pub const SIGNAL_ABRT: Signal = Signal(6);
887pub const SIGNAL_BUS: Signal = Signal(7);
890pub const SIGNAL_FPE: Signal = Signal(8);
893pub const SIGNAL_KILL: Signal = Signal(9);
896pub const SIGNAL_USR1: Signal = Signal(10);
899pub const SIGNAL_SEGV: Signal = Signal(11);
902pub const SIGNAL_USR2: Signal = Signal(12);
905pub const SIGNAL_PIPE: Signal = Signal(13);
908pub const SIGNAL_ALRM: Signal = Signal(14);
911pub const SIGNAL_TERM: Signal = Signal(15);
914pub const SIGNAL_CHLD: Signal = Signal(16);
917pub const SIGNAL_CONT: Signal = Signal(17);
920pub const SIGNAL_STOP: Signal = Signal(18);
923pub const SIGNAL_TSTP: Signal = Signal(19);
926pub const SIGNAL_TTIN: Signal = Signal(20);
929pub const SIGNAL_TTOU: Signal = Signal(21);
932pub const SIGNAL_URG: Signal = Signal(22);
935pub const SIGNAL_XCPU: Signal = Signal(23);
938pub const SIGNAL_XFSZ: Signal = Signal(24);
941pub const SIGNAL_VTALRM: Signal = Signal(25);
944pub const SIGNAL_PROF: Signal = Signal(26);
947pub const SIGNAL_WINCH: Signal = Signal(27);
950pub const SIGNAL_POLL: Signal = Signal(28);
953pub const SIGNAL_PWR: Signal = Signal(29);
956pub const SIGNAL_SYS: Signal = Signal(30);
959impl Signal {
960 pub const fn raw(&self) -> u8 {
961 self.0
962 }
963
964 pub fn name(&self) -> &'static str {
965 match self.0 {
966 0 => "NONE",
967 1 => "HUP",
968 2 => "INT",
969 3 => "QUIT",
970 4 => "ILL",
971 5 => "TRAP",
972 6 => "ABRT",
973 7 => "BUS",
974 8 => "FPE",
975 9 => "KILL",
976 10 => "USR1",
977 11 => "SEGV",
978 12 => "USR2",
979 13 => "PIPE",
980 14 => "ALRM",
981 15 => "TERM",
982 16 => "CHLD",
983 17 => "CONT",
984 18 => "STOP",
985 19 => "TSTP",
986 20 => "TTIN",
987 21 => "TTOU",
988 22 => "URG",
989 23 => "XCPU",
990 24 => "XFSZ",
991 25 => "VTALRM",
992 26 => "PROF",
993 27 => "WINCH",
994 28 => "POLL",
995 29 => "PWR",
996 30 => "SYS",
997 _ => unsafe { core::hint::unreachable_unchecked() },
998 }
999 }
1000 pub fn message(&self) -> &'static str {
1001 match self.0 {
1002 0 => {
1003 "No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
1004so this value is reserved."
1005 }
1006 1 => {
1007 "Hangup.
1008Action: Terminates the process."
1009 }
1010 2 => {
1011 "Terminate interrupt signal.
1012Action: Terminates the process."
1013 }
1014 3 => {
1015 "Terminal quit signal.
1016Action: Terminates the process."
1017 }
1018 4 => {
1019 "Illegal instruction.
1020Action: Terminates the process."
1021 }
1022 5 => {
1023 "Trace/breakpoint trap.
1024Action: Terminates the process."
1025 }
1026 6 => {
1027 "Process abort signal.
1028Action: Terminates the process."
1029 }
1030 7 => {
1031 "Access to an undefined portion of a memory object.
1032Action: Terminates the process."
1033 }
1034 8 => {
1035 "Erroneous arithmetic operation.
1036Action: Terminates the process."
1037 }
1038 9 => {
1039 "Kill.
1040Action: Terminates the process."
1041 }
1042 10 => {
1043 "User-defined signal 1.
1044Action: Terminates the process."
1045 }
1046 11 => {
1047 "Invalid memory reference.
1048Action: Terminates the process."
1049 }
1050 12 => {
1051 "User-defined signal 2.
1052Action: Terminates the process."
1053 }
1054 13 => {
1055 "Write on a pipe with no one to read it.
1056Action: Ignored."
1057 }
1058 14 => {
1059 "Alarm clock.
1060Action: Terminates the process."
1061 }
1062 15 => {
1063 "Termination signal.
1064Action: Terminates the process."
1065 }
1066 16 => {
1067 "Child process terminated, stopped, or continued.
1068Action: Ignored."
1069 }
1070 17 => {
1071 "Continue executing, if stopped.
1072Action: Continues executing, if stopped."
1073 }
1074 18 => {
1075 "Stop executing.
1076Action: Stops executing."
1077 }
1078 19 => {
1079 "Terminal stop signal.
1080Action: Stops executing."
1081 }
1082 20 => {
1083 "Background process attempting read.
1084Action: Stops executing."
1085 }
1086 21 => {
1087 "Background process attempting write.
1088Action: Stops executing."
1089 }
1090 22 => {
1091 "High bandwidth data is available at a socket.
1092Action: Ignored."
1093 }
1094 23 => {
1095 "CPU time limit exceeded.
1096Action: Terminates the process."
1097 }
1098 24 => {
1099 "File size limit exceeded.
1100Action: Terminates the process."
1101 }
1102 25 => {
1103 "Virtual timer expired.
1104Action: Terminates the process."
1105 }
1106 26 => {
1107 "Profiling timer expired.
1108Action: Terminates the process."
1109 }
1110 27 => {
1111 "Window changed.
1112Action: Ignored."
1113 }
1114 28 => {
1115 "I/O possible.
1116Action: Terminates the process."
1117 }
1118 29 => {
1119 "Power failure.
1120Action: Terminates the process."
1121 }
1122 30 => {
1123 "Bad system call.
1124Action: Terminates the process."
1125 }
1126 _ => unsafe { core::hint::unreachable_unchecked() },
1127 }
1128 }
1129}
1130impl fmt::Debug for Signal {
1131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1132 f.debug_struct("Signal")
1133 .field("code", &self.0)
1134 .field("name", &self.name())
1135 .field("message", &self.message())
1136 .finish()
1137 }
1138}
1139
1140pub type Riflags = u16;
1141pub const RIFLAGS_RECV_PEEK: Riflags = 1 << 0;
1143pub const RIFLAGS_RECV_WAITALL: Riflags = 1 << 1;
1145
1146pub type Roflags = u16;
1147pub const ROFLAGS_RECV_DATA_TRUNCATED: Roflags = 1 << 0;
1149
1150pub type Siflags = u16;
1151pub type Sdflags = u8;
1152pub const SDFLAGS_RD: Sdflags = 1 << 0;
1154pub const SDFLAGS_WR: Sdflags = 1 << 1;
1156
1157#[repr(transparent)]
1158#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
1159pub struct Preopentype(u8);
1160pub const PREOPENTYPE_DIR: Preopentype = Preopentype(0);
1162impl Preopentype {
1163 pub const fn raw(&self) -> u8 {
1164 self.0
1165 }
1166
1167 pub fn name(&self) -> &'static str {
1168 match self.0 {
1169 0 => "DIR",
1170 _ => unsafe { core::hint::unreachable_unchecked() },
1171 }
1172 }
1173 pub fn message(&self) -> &'static str {
1174 match self.0 {
1175 0 => "A pre-opened directory.",
1176 _ => unsafe { core::hint::unreachable_unchecked() },
1177 }
1178 }
1179}
1180impl fmt::Debug for Preopentype {
1181 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1182 f.debug_struct("Preopentype")
1183 .field("code", &self.0)
1184 .field("name", &self.name())
1185 .field("message", &self.message())
1186 .finish()
1187 }
1188}
1189
1190#[repr(C)]
1191#[derive(Copy, Clone, Debug)]
1192pub struct PrestatDir {
1193 pub pr_name_len: Size,
1195}
1196#[repr(C)]
1197#[derive(Copy, Clone)]
1198pub union PrestatU {
1199 pub dir: PrestatDir,
1200}
1201#[repr(C)]
1202#[derive(Copy, Clone)]
1203pub struct Prestat {
1204 pub tag: u8,
1205 pub u: PrestatU,
1206}
1207
1208pub unsafe fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Result<(), Errno> {
1212 let ret = wasi_snapshot_preview1::args_get(argv as i32, argv_buf as i32);
1213 match ret {
1214 0 => Ok(()),
1215 _ => Err(Errno(ret as u16)),
1216 }
1217}
1218
1219pub unsafe fn args_sizes_get() -> Result<(Size, Size), Errno> {
1226 let mut rp0 = MaybeUninit::<Size>::uninit();
1227 let mut rp1 = MaybeUninit::<Size>::uninit();
1228 let ret =
1229 wasi_snapshot_preview1::args_sizes_get(rp0.as_mut_ptr() as i32, rp1.as_mut_ptr() as i32);
1230 match ret {
1231 0 => Ok((
1232 core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
1233 core::ptr::read(rp1.as_mut_ptr() as i32 as *const Size),
1234 )),
1235 _ => Err(Errno(ret as u16)),
1236 }
1237}
1238
1239pub unsafe fn environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Result<(), Errno> {
1243 let ret = wasi_snapshot_preview1::environ_get(environ as i32, environ_buf as i32);
1244 match ret {
1245 0 => Ok(()),
1246 _ => Err(Errno(ret as u16)),
1247 }
1248}
1249
1250pub unsafe fn environ_sizes_get() -> Result<(Size, Size), Errno> {
1257 let mut rp0 = MaybeUninit::<Size>::uninit();
1258 let mut rp1 = MaybeUninit::<Size>::uninit();
1259 let ret =
1260 wasi_snapshot_preview1::environ_sizes_get(rp0.as_mut_ptr() as i32, rp1.as_mut_ptr() as i32);
1261 match ret {
1262 0 => Ok((
1263 core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
1264 core::ptr::read(rp1.as_mut_ptr() as i32 as *const Size),
1265 )),
1266 _ => Err(Errno(ret as u16)),
1267 }
1268}
1269
1270pub unsafe fn clock_res_get(id: Clockid) -> Result<Timestamp, Errno> {
1283 let mut rp0 = MaybeUninit::<Timestamp>::uninit();
1284 let ret = wasi_snapshot_preview1::clock_res_get(id.0 as i32, rp0.as_mut_ptr() as i32);
1285 match ret {
1286 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Timestamp)),
1287 _ => Err(Errno(ret as u16)),
1288 }
1289}
1290
1291pub unsafe fn clock_time_get(id: Clockid, precision: Timestamp) -> Result<Timestamp, Errno> {
1303 let mut rp0 = MaybeUninit::<Timestamp>::uninit();
1304 let ret = wasi_snapshot_preview1::clock_time_get(
1305 id.0 as i32,
1306 precision as i64,
1307 rp0.as_mut_ptr() as i32,
1308 );
1309 match ret {
1310 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Timestamp)),
1311 _ => Err(Errno(ret as u16)),
1312 }
1313}
1314
1315pub unsafe fn fd_advise(
1324 fd: Fd,
1325 offset: Filesize,
1326 len: Filesize,
1327 advice: Advice,
1328) -> Result<(), Errno> {
1329 let ret =
1330 wasi_snapshot_preview1::fd_advise(fd as i32, offset as i64, len as i64, advice.0 as i32);
1331 match ret {
1332 0 => Ok(()),
1333 _ => Err(Errno(ret as u16)),
1334 }
1335}
1336
1337pub unsafe fn fd_allocate(fd: Fd, offset: Filesize, len: Filesize) -> Result<(), Errno> {
1345 let ret = wasi_snapshot_preview1::fd_allocate(fd as i32, offset as i64, len as i64);
1346 match ret {
1347 0 => Ok(()),
1348 _ => Err(Errno(ret as u16)),
1349 }
1350}
1351
1352pub unsafe fn fd_close(fd: Fd) -> Result<(), Errno> {
1355 let ret = wasi_snapshot_preview1::fd_close(fd as i32);
1356 match ret {
1357 0 => Ok(()),
1358 _ => Err(Errno(ret as u16)),
1359 }
1360}
1361
1362pub unsafe fn fd_datasync(fd: Fd) -> Result<(), Errno> {
1365 let ret = wasi_snapshot_preview1::fd_datasync(fd as i32);
1366 match ret {
1367 0 => Ok(()),
1368 _ => Err(Errno(ret as u16)),
1369 }
1370}
1371
1372pub unsafe fn fd_fdstat_get(fd: Fd) -> Result<Fdstat, Errno> {
1379 let mut rp0 = MaybeUninit::<Fdstat>::uninit();
1380 let ret = wasi_snapshot_preview1::fd_fdstat_get(fd as i32, rp0.as_mut_ptr() as i32);
1381 match ret {
1382 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fdstat)),
1383 _ => Err(Errno(ret as u16)),
1384 }
1385}
1386
1387pub unsafe fn fd_fdstat_set_flags(fd: Fd, flags: Fdflags) -> Result<(), Errno> {
1394 let ret = wasi_snapshot_preview1::fd_fdstat_set_flags(fd as i32, flags as i32);
1395 match ret {
1396 0 => Ok(()),
1397 _ => Err(Errno(ret as u16)),
1398 }
1399}
1400
1401pub unsafe fn fd_fdstat_set_rights(
1408 fd: Fd,
1409 fs_rights_base: Rights,
1410 fs_rights_inheriting: Rights,
1411) -> Result<(), Errno> {
1412 let ret = wasi_snapshot_preview1::fd_fdstat_set_rights(
1413 fd as i32,
1414 fs_rights_base as i64,
1415 fs_rights_inheriting as i64,
1416 );
1417 match ret {
1418 0 => Ok(()),
1419 _ => Err(Errno(ret as u16)),
1420 }
1421}
1422
1423pub unsafe fn fd_filestat_get(fd: Fd) -> Result<Filestat, Errno> {
1429 let mut rp0 = MaybeUninit::<Filestat>::uninit();
1430 let ret = wasi_snapshot_preview1::fd_filestat_get(fd as i32, rp0.as_mut_ptr() as i32);
1431 match ret {
1432 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filestat)),
1433 _ => Err(Errno(ret as u16)),
1434 }
1435}
1436
1437pub unsafe fn fd_filestat_set_size(fd: Fd, size: Filesize) -> Result<(), Errno> {
1444 let ret = wasi_snapshot_preview1::fd_filestat_set_size(fd as i32, size as i64);
1445 match ret {
1446 0 => Ok(()),
1447 _ => Err(Errno(ret as u16)),
1448 }
1449}
1450
1451pub unsafe fn fd_filestat_set_times(
1460 fd: Fd,
1461 atim: Timestamp,
1462 mtim: Timestamp,
1463 fst_flags: Fstflags,
1464) -> Result<(), Errno> {
1465 let ret = wasi_snapshot_preview1::fd_filestat_set_times(
1466 fd as i32,
1467 atim as i64,
1468 mtim as i64,
1469 fst_flags as i32,
1470 );
1471 match ret {
1472 0 => Ok(()),
1473 _ => Err(Errno(ret as u16)),
1474 }
1475}
1476
1477pub unsafe fn fd_pread(fd: Fd, iovs: IovecArray<'_>, offset: Filesize) -> Result<Size, Errno> {
1489 let mut rp0 = MaybeUninit::<Size>::uninit();
1490 let ret = wasi_snapshot_preview1::fd_pread(
1491 fd as i32,
1492 iovs.as_ptr() as i32,
1493 iovs.len() as i32,
1494 offset as i64,
1495 rp0.as_mut_ptr() as i32,
1496 );
1497 match ret {
1498 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1499 _ => Err(Errno(ret as u16)),
1500 }
1501}
1502
1503pub unsafe fn fd_prestat_get(fd: Fd) -> Result<Prestat, Errno> {
1509 let mut rp0 = MaybeUninit::<Prestat>::uninit();
1510 let ret = wasi_snapshot_preview1::fd_prestat_get(fd as i32, rp0.as_mut_ptr() as i32);
1511 match ret {
1512 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Prestat)),
1513 _ => Err(Errno(ret as u16)),
1514 }
1515}
1516
1517pub unsafe fn fd_prestat_dir_name(fd: Fd, path: *mut u8, path_len: Size) -> Result<(), Errno> {
1523 let ret = wasi_snapshot_preview1::fd_prestat_dir_name(fd as i32, path as i32, path_len as i32);
1524 match ret {
1525 0 => Ok(()),
1526 _ => Err(Errno(ret as u16)),
1527 }
1528}
1529
1530pub unsafe fn fd_pwrite(fd: Fd, iovs: CiovecArray<'_>, offset: Filesize) -> Result<Size, Errno> {
1542 let mut rp0 = MaybeUninit::<Size>::uninit();
1543 let ret = wasi_snapshot_preview1::fd_pwrite(
1544 fd as i32,
1545 iovs.as_ptr() as i32,
1546 iovs.len() as i32,
1547 offset as i64,
1548 rp0.as_mut_ptr() as i32,
1549 );
1550 match ret {
1551 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1552 _ => Err(Errno(ret as u16)),
1553 }
1554}
1555
1556pub unsafe fn fd_read(fd: Fd, iovs: IovecArray<'_>) -> Result<Size, Errno> {
1567 let mut rp0 = MaybeUninit::<Size>::uninit();
1568 let ret = wasi_snapshot_preview1::fd_read(
1569 fd as i32,
1570 iovs.as_ptr() as i32,
1571 iovs.len() as i32,
1572 rp0.as_mut_ptr() as i32,
1573 );
1574 match ret {
1575 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1576 _ => Err(Errno(ret as u16)),
1577 }
1578}
1579
1580pub unsafe fn fd_readdir(
1599 fd: Fd,
1600 buf: *mut u8,
1601 buf_len: Size,
1602 cookie: Dircookie,
1603) -> Result<Size, Errno> {
1604 let mut rp0 = MaybeUninit::<Size>::uninit();
1605 let ret = wasi_snapshot_preview1::fd_readdir(
1606 fd as i32,
1607 buf as i32,
1608 buf_len as i32,
1609 cookie as i64,
1610 rp0.as_mut_ptr() as i32,
1611 );
1612 match ret {
1613 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1614 _ => Err(Errno(ret as u16)),
1615 }
1616}
1617
1618pub unsafe fn fd_renumber(fd: Fd, to: Fd) -> Result<(), Errno> {
1631 let ret = wasi_snapshot_preview1::fd_renumber(fd as i32, to as i32);
1632 match ret {
1633 0 => Ok(()),
1634 _ => Err(Errno(ret as u16)),
1635 }
1636}
1637
1638pub unsafe fn fd_seek(fd: Fd, offset: Filedelta, whence: Whence) -> Result<Filesize, Errno> {
1650 let mut rp0 = MaybeUninit::<Filesize>::uninit();
1651 let ret = wasi_snapshot_preview1::fd_seek(
1652 fd as i32,
1653 offset,
1654 whence.0 as i32,
1655 rp0.as_mut_ptr() as i32,
1656 );
1657 match ret {
1658 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filesize)),
1659 _ => Err(Errno(ret as u16)),
1660 }
1661}
1662
1663pub unsafe fn fd_sync(fd: Fd) -> Result<(), Errno> {
1666 let ret = wasi_snapshot_preview1::fd_sync(fd as i32);
1667 match ret {
1668 0 => Ok(()),
1669 _ => Err(Errno(ret as u16)),
1670 }
1671}
1672
1673pub unsafe fn fd_tell(fd: Fd) -> Result<Filesize, Errno> {
1680 let mut rp0 = MaybeUninit::<Filesize>::uninit();
1681 let ret = wasi_snapshot_preview1::fd_tell(fd as i32, rp0.as_mut_ptr() as i32);
1682 match ret {
1683 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filesize)),
1684 _ => Err(Errno(ret as u16)),
1685 }
1686}
1687
1688pub unsafe fn fd_write(fd: Fd, iovs: CiovecArray<'_>) -> Result<Size, Errno> {
1695 let mut rp0 = MaybeUninit::<Size>::uninit();
1696 let ret = wasi_snapshot_preview1::fd_write(
1697 fd as i32,
1698 iovs.as_ptr() as i32,
1699 iovs.len() as i32,
1700 rp0.as_mut_ptr() as i32,
1701 );
1702 match ret {
1703 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1704 _ => Err(Errno(ret as u16)),
1705 }
1706}
1707
1708pub unsafe fn path_create_directory(fd: Fd, path: &str) -> Result<(), Errno> {
1715 let ret = wasi_snapshot_preview1::path_create_directory(
1716 fd as i32,
1717 path.as_ptr() as i32,
1718 path.len() as i32,
1719 );
1720 match ret {
1721 0 => Ok(()),
1722 _ => Err(Errno(ret as u16)),
1723 }
1724}
1725
1726pub unsafe fn path_filestat_get(fd: Fd, flags: Lookupflags, path: &str) -> Result<Filestat, Errno> {
1738 let mut rp0 = MaybeUninit::<Filestat>::uninit();
1739 let ret = wasi_snapshot_preview1::path_filestat_get(
1740 fd as i32,
1741 flags as i32,
1742 path.as_ptr() as i32,
1743 path.len() as i32,
1744 rp0.as_mut_ptr() as i32,
1745 );
1746 match ret {
1747 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Filestat)),
1748 _ => Err(Errno(ret as u16)),
1749 }
1750}
1751
1752pub unsafe fn path_filestat_set_times(
1763 fd: Fd,
1764 flags: Lookupflags,
1765 path: &str,
1766 atim: Timestamp,
1767 mtim: Timestamp,
1768 fst_flags: Fstflags,
1769) -> Result<(), Errno> {
1770 let ret = wasi_snapshot_preview1::path_filestat_set_times(
1771 fd as i32,
1772 flags as i32,
1773 path.as_ptr() as i32,
1774 path.len() as i32,
1775 atim as i64,
1776 mtim as i64,
1777 fst_flags as i32,
1778 );
1779 match ret {
1780 0 => Ok(()),
1781 _ => Err(Errno(ret as u16)),
1782 }
1783}
1784
1785pub unsafe fn path_link(
1795 old_fd: Fd,
1796 old_flags: Lookupflags,
1797 old_path: &str,
1798 new_fd: Fd,
1799 new_path: &str,
1800) -> Result<(), Errno> {
1801 let ret = wasi_snapshot_preview1::path_link(
1802 old_fd as i32,
1803 old_flags as i32,
1804 old_path.as_ptr() as i32,
1805 old_path.len() as i32,
1806 new_fd as i32,
1807 new_path.as_ptr() as i32,
1808 new_path.len() as i32,
1809 );
1810 match ret {
1811 0 => Ok(()),
1812 _ => Err(Errno(ret as u16)),
1813 }
1814}
1815
1816pub unsafe fn path_open(
1842 fd: Fd,
1843 dirflags: Lookupflags,
1844 path: &str,
1845 oflags: Oflags,
1846 fs_rights_base: Rights,
1847 fs_rights_inheriting: Rights,
1848 fdflags: Fdflags,
1849) -> Result<Fd, Errno> {
1850 let mut rp0 = MaybeUninit::<Fd>::uninit();
1851 let ret = wasi_snapshot_preview1::path_open(
1852 fd as i32,
1853 dirflags as i32,
1854 path.as_ptr() as i32,
1855 path.len() as i32,
1856 oflags as i32,
1857 fs_rights_base as i64,
1858 fs_rights_inheriting as i64,
1859 fdflags as i32,
1860 rp0.as_mut_ptr() as i32,
1861 );
1862 match ret {
1863 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
1864 _ => Err(Errno(ret as u16)),
1865 }
1866}
1867
1868pub unsafe fn path_readlink(
1880 fd: Fd,
1881 path: &str,
1882 buf: *mut u8,
1883 buf_len: Size,
1884) -> Result<Size, Errno> {
1885 let mut rp0 = MaybeUninit::<Size>::uninit();
1886 let ret = wasi_snapshot_preview1::path_readlink(
1887 fd as i32,
1888 path.as_ptr() as i32,
1889 path.len() as i32,
1890 buf as i32,
1891 buf_len as i32,
1892 rp0.as_mut_ptr() as i32,
1893 );
1894 match ret {
1895 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
1896 _ => Err(Errno(ret as u16)),
1897 }
1898}
1899
1900pub unsafe fn path_remove_directory(fd: Fd, path: &str) -> Result<(), Errno> {
1908 let ret = wasi_snapshot_preview1::path_remove_directory(
1909 fd as i32,
1910 path.as_ptr() as i32,
1911 path.len() as i32,
1912 );
1913 match ret {
1914 0 => Ok(()),
1915 _ => Err(Errno(ret as u16)),
1916 }
1917}
1918
1919pub unsafe fn path_rename(fd: Fd, old_path: &str, new_fd: Fd, new_path: &str) -> Result<(), Errno> {
1928 let ret = wasi_snapshot_preview1::path_rename(
1929 fd as i32,
1930 old_path.as_ptr() as i32,
1931 old_path.len() as i32,
1932 new_fd as i32,
1933 new_path.as_ptr() as i32,
1934 new_path.len() as i32,
1935 );
1936 match ret {
1937 0 => Ok(()),
1938 _ => Err(Errno(ret as u16)),
1939 }
1940}
1941
1942pub unsafe fn path_symlink(old_path: &str, fd: Fd, new_path: &str) -> Result<(), Errno> {
1950 let ret = wasi_snapshot_preview1::path_symlink(
1951 old_path.as_ptr() as i32,
1952 old_path.len() as i32,
1953 fd as i32,
1954 new_path.as_ptr() as i32,
1955 new_path.len() as i32,
1956 );
1957 match ret {
1958 0 => Ok(()),
1959 _ => Err(Errno(ret as u16)),
1960 }
1961}
1962
1963pub unsafe fn path_unlink_file(fd: Fd, path: &str) -> Result<(), Errno> {
1971 let ret = wasi_snapshot_preview1::path_unlink_file(
1972 fd as i32,
1973 path.as_ptr() as i32,
1974 path.len() as i32,
1975 );
1976 match ret {
1977 0 => Ok(()),
1978 _ => Err(Errno(ret as u16)),
1979 }
1980}
1981
1982pub unsafe fn poll_oneoff(
1994 in_: *const Subscription,
1995 out: *mut Event,
1996 nsubscriptions: Size,
1997) -> Result<Size, Errno> {
1998 let mut rp0 = MaybeUninit::<Size>::uninit();
1999 let ret = wasi_snapshot_preview1::poll_oneoff(
2000 in_ as i32,
2001 out as i32,
2002 nsubscriptions as i32,
2003 rp0.as_mut_ptr() as i32,
2004 );
2005 match ret {
2006 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
2007 _ => Err(Errno(ret as u16)),
2008 }
2009}
2010
2011pub unsafe fn proc_exit(rval: Exitcode) {
2019 wasi_snapshot_preview1::proc_exit(rval as i32);
2020}
2021
2022pub unsafe fn proc_raise(sig: Signal) -> Result<(), Errno> {
2029 let ret = wasi_snapshot_preview1::proc_raise(sig.0 as i32);
2030 match ret {
2031 0 => Ok(()),
2032 _ => Err(Errno(ret as u16)),
2033 }
2034}
2035
2036pub unsafe fn sched_yield() -> Result<(), Errno> {
2039 let ret = wasi_snapshot_preview1::sched_yield();
2040 match ret {
2041 0 => Ok(()),
2042 _ => Err(Errno(ret as u16)),
2043 }
2044}
2045
2046pub unsafe fn random_get(buf: *mut u8, buf_len: Size) -> Result<(), Errno> {
2057 let ret = wasi_snapshot_preview1::random_get(buf as i32, buf_len as i32);
2058 match ret {
2059 0 => Ok(()),
2060 _ => Err(Errno(ret as u16)),
2061 }
2062}
2063
2064pub unsafe fn sock_accept(fd: Fd, flags: Fdflags) -> Result<Fd, Errno> {
2076 let mut rp0 = MaybeUninit::<Fd>::uninit();
2077 let ret = wasi_snapshot_preview1::sock_accept(fd as i32, flags as i32, rp0.as_mut_ptr() as i32);
2078 match ret {
2079 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Fd)),
2080 _ => Err(Errno(ret as u16)),
2081 }
2082}
2083
2084pub unsafe fn sock_recv(
2097 fd: Fd,
2098 ri_data: IovecArray<'_>,
2099 ri_flags: Riflags,
2100) -> Result<(Size, Roflags), Errno> {
2101 let mut rp0 = MaybeUninit::<Size>::uninit();
2102 let mut rp1 = MaybeUninit::<Roflags>::uninit();
2103 let ret = wasi_snapshot_preview1::sock_recv(
2104 fd as i32,
2105 ri_data.as_ptr() as i32,
2106 ri_data.len() as i32,
2107 ri_flags as i32,
2108 rp0.as_mut_ptr() as i32,
2109 rp1.as_mut_ptr() as i32,
2110 );
2111 match ret {
2112 0 => Ok((
2113 core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size),
2114 core::ptr::read(rp1.as_mut_ptr() as i32 as *const Roflags),
2115 )),
2116 _ => Err(Errno(ret as u16)),
2117 }
2118}
2119
2120pub unsafe fn sock_send(
2133 fd: Fd,
2134 si_data: CiovecArray<'_>,
2135 si_flags: Siflags,
2136) -> Result<Size, Errno> {
2137 let mut rp0 = MaybeUninit::<Size>::uninit();
2138 let ret = wasi_snapshot_preview1::sock_send(
2139 fd as i32,
2140 si_data.as_ptr() as i32,
2141 si_data.len() as i32,
2142 si_flags as i32,
2143 rp0.as_mut_ptr() as i32,
2144 );
2145 match ret {
2146 0 => Ok(core::ptr::read(rp0.as_mut_ptr() as i32 as *const Size)),
2147 _ => Err(Errno(ret as u16)),
2148 }
2149}
2150
2151pub unsafe fn sock_shutdown(fd: Fd, how: Sdflags) -> Result<(), Errno> {
2158 let ret = wasi_snapshot_preview1::sock_shutdown(fd as i32, how as i32);
2159 match ret {
2160 0 => Ok(()),
2161 _ => Err(Errno(ret as u16)),
2162 }
2163}
2164
2165pub mod wasi_snapshot_preview1 {
2166 #[link(wasm_import_module = "wasi_snapshot_preview1")]
2167 extern "C" {
2168 pub fn args_get(arg0: i32, arg1: i32) -> i32;
2172 pub fn args_sizes_get(arg0: i32, arg1: i32) -> i32;
2174 pub fn environ_get(arg0: i32, arg1: i32) -> i32;
2178 pub fn environ_sizes_get(arg0: i32, arg1: i32) -> i32;
2180 pub fn clock_res_get(arg0: i32, arg1: i32) -> i32;
2185 pub fn clock_time_get(arg0: i32, arg1: i64, arg2: i32) -> i32;
2188 pub fn fd_advise(arg0: i32, arg1: i64, arg2: i64, arg3: i32) -> i32;
2191 pub fn fd_allocate(arg0: i32, arg1: i64, arg2: i64) -> i32;
2194 pub fn fd_close(arg0: i32) -> i32;
2197 pub fn fd_datasync(arg0: i32) -> i32;
2200 pub fn fd_fdstat_get(arg0: i32, arg1: i32) -> i32;
2203 pub fn fd_fdstat_set_flags(arg0: i32, arg1: i32) -> i32;
2206 pub fn fd_fdstat_set_rights(arg0: i32, arg1: i64, arg2: i64) -> i32;
2209 pub fn fd_filestat_get(arg0: i32, arg1: i32) -> i32;
2211 pub fn fd_filestat_set_size(arg0: i32, arg1: i64) -> i32;
2214 pub fn fd_filestat_set_times(arg0: i32, arg1: i64, arg2: i64, arg3: i32) -> i32;
2217 pub fn fd_pread(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
2220 pub fn fd_prestat_get(arg0: i32, arg1: i32) -> i32;
2222 pub fn fd_prestat_dir_name(arg0: i32, arg1: i32, arg2: i32) -> i32;
2224 pub fn fd_pwrite(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
2227 pub fn fd_read(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
2230 pub fn fd_readdir(arg0: i32, arg1: i32, arg2: i32, arg3: i64, arg4: i32) -> i32;
2240 pub fn fd_renumber(arg0: i32, arg1: i32) -> i32;
2249 pub fn fd_seek(arg0: i32, arg1: i64, arg2: i32, arg3: i32) -> i32;
2252 pub fn fd_sync(arg0: i32) -> i32;
2255 pub fn fd_tell(arg0: i32, arg1: i32) -> i32;
2258 pub fn fd_write(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
2261 pub fn path_create_directory(arg0: i32, arg1: i32, arg2: i32) -> i32;
2264 pub fn path_filestat_get(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
2267 pub fn path_filestat_set_times(
2270 arg0: i32,
2271 arg1: i32,
2272 arg2: i32,
2273 arg3: i32,
2274 arg4: i64,
2275 arg5: i64,
2276 arg6: i32,
2277 ) -> i32;
2278 pub fn path_link(
2281 arg0: i32,
2282 arg1: i32,
2283 arg2: i32,
2284 arg3: i32,
2285 arg4: i32,
2286 arg5: i32,
2287 arg6: i32,
2288 ) -> i32;
2289 pub fn path_open(
2297 arg0: i32,
2298 arg1: i32,
2299 arg2: i32,
2300 arg3: i32,
2301 arg4: i32,
2302 arg5: i64,
2303 arg6: i64,
2304 arg7: i32,
2305 arg8: i32,
2306 ) -> i32;
2307 pub fn path_readlink(
2310 arg0: i32,
2311 arg1: i32,
2312 arg2: i32,
2313 arg3: i32,
2314 arg4: i32,
2315 arg5: i32,
2316 ) -> i32;
2317 pub fn path_remove_directory(arg0: i32, arg1: i32, arg2: i32) -> i32;
2321 pub fn path_rename(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32, arg5: i32)
2324 -> i32;
2325 pub fn path_symlink(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
2328 pub fn path_unlink_file(arg0: i32, arg1: i32, arg2: i32) -> i32;
2332 pub fn poll_oneoff(arg0: i32, arg1: i32, arg2: i32, arg3: i32) -> i32;
2334 pub fn proc_exit(arg0: i32) -> !;
2338 pub fn proc_raise(arg0: i32) -> i32;
2341 pub fn sched_yield() -> i32;
2344 pub fn random_get(arg0: i32, arg1: i32) -> i32;
2351 pub fn sock_accept(arg0: i32, arg1: i32, arg2: i32) -> i32;
2354 pub fn sock_recv(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32, arg5: i32) -> i32;
2358 pub fn sock_send(arg0: i32, arg1: i32, arg2: i32, arg3: i32, arg4: i32) -> i32;
2362 pub fn sock_shutdown(arg0: i32, arg1: i32) -> i32;
2365 }
2366}