-
Notifications
You must be signed in to change notification settings - Fork 5
/
cloudabi.rs
3030 lines (2918 loc) · 98 KB
/
cloudabi.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2016-2019 Nuxi (https://nuxi.nl/) and contributors.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// This file is automatically generated. Do not edit.
//
// Source: https://github.com/NuxiNL/cloudabi
// Appease Rust's tidy.
// ignore-license
// ignore-tidy-linelength
//! **PLEASE NOTE: This entire crate including this
//! documentation is automatically generated from
//! [`cloudabi.txt`](https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt)**
//!
//! # Nuxi CloudABI
//!
//! CloudABI is what you get if you take POSIX, add capability-based
//! security, and remove everything that's incompatible with that. The
//! result is a minimal ABI consisting of only 49 syscalls.
//!
//! CloudABI doesn't have its own kernel, but instead is implemented in existing
//! kernels: FreeBSD has CloudABI support for x86-64 and arm64, and [a patch-set
//! for NetBSD](https://github.com/NuxiNL/netbsd) and [a patch-set for
//! Linux](https://github.com/NuxiNL/linux) are available as well. This means that
//! CloudABI binaries can be executed on different operating systems, without any
//! modification.
//!
//! ## Capability-Based Security
//!
//! Capability-based security means that processes can only perform
//! actions that have no global impact. Processes cannot open files by
//! their absolute path, cannot open network connections, and cannot
//! observe global system state such as the process table.
//!
//! The capabilities of a process are fully determined by its set of open
//! file descriptors (fds). For example, files can only be opened if the
//! process already has a file descriptor to a directory the file is in.
//!
//! Unlike in POSIX, where processes are normally started with file
//! descriptors 0, 1, and 2 reserved for standard input, output, and
//! error, CloudABI does not reserve any file descriptor numbers for
//! specific purposes.
//!
//! In CloudABI, a process depends on its parent process to launch it with
//! the right set of resources, since the process will not be able to open
//! any new resources. For example, a simple static web server would need
//! to be started with a file descriptor to a [TCP
//! listener](https://github.com/NuxiNL/flower), and a file descriptor to
//! the directory for which to serve files. The web server will then be
//! unable to do anything other than reading files in that directory, and
//! process incoming network connections.
//!
//! So, unknown CloudABI binaries can safely be executed without the need
//! for containers, virtual machines, or other sandboxing technologies.
//!
//! Watch [Ed Schouten's Talk at
//! 32C3](https://www.youtube.com/watch?v=3N29vrPoDv8) for more
//! information about what capability-based security for UNIX means.
//!
//! ## Cloudlibc
//!
//! [Cloudlibc](https://github.com/NuxiNL/cloudlibc) is an implementation
//! of the C standard library, without all CloudABI-incompatible
//! functions. For example, Cloudlibc does not have `printf`, but does
//! have `fprintf`. It does not have `open`, but does have `openat`.
//!
//! ## CloudABI-Ports
//!
//! [CloudABI-Ports](https://github.com/NuxiNL/cloudabi-ports) is a
//! collection of ports of commonly used libraries and applications to
//! CloudABI. It contains software such as `zlib`, `libpng`, `boost`,
//! `memcached`, and much more. The software is patched to not depend on
//! any global state, such as files in `/etc` or `/dev`, using `open()`,
//! etc.
//!
//! ## Using CloudABI
//!
//! Instructions for using CloudABI (including kernel modules/patches,
//! toolchain, and ports) are available for several operating systems:
//!
//! - [FreeBSD](https://cloudabi.org/run/freebsd/)
//! - [Linux](https://cloudabi.org/run/linux/)
//! - [macOS](https://cloudabi.org/run/macos/)
//!
//! ## Specification of the ABI
//!
//! The entire ABI is specified in a file called
//! [`cloudabi.txt`](https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt),
//! from which all
//! [headers](https://github.com/NuxiNL/cloudabi/tree/master/headers)
//! and documentation (including the one you're reading now) is generated.
#![no_std]
#![allow(non_camel_case_types)]
#[cfg(feature = "bitflags")]
use bitflags::bitflags;
// Minimal implementation of bitflags! in case we can't depend on the bitflags
// crate. Only implements `bits()` and a `from_bits_unchecked()`.
#[cfg(not(feature = "bitflags"))]
macro_rules! bitflags {
(
$(#[$attr:meta])*
pub struct $name:ident: $type:ty {
$($(#[$const_attr:meta])* const $const:ident = $val:expr;)*
}
) => {
$(#[$attr])*
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct $name { bits: $type }
impl $name {
$($(#[$const_attr])* pub const $const: $name = $name{ bits: $val };)*
pub const fn bits(&self) -> $type { self.bits }
pub const unsafe fn from_bits_unchecked(bits: $type) -> Self { $name{ bits } }
}
}
}
/// File or memory access pattern advisory information.
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum advice {
/// The application expects that it will not access the
/// specified data in the near future.
DONTNEED = 1,
/// The application expects to access the specified data
/// once and then not reuse it thereafter.
NOREUSE = 2,
/// The application has no advice to give on its behavior
/// with respect to the specified data.
NORMAL = 3,
/// The application expects to access the specified data
/// in a random order.
RANDOM = 4,
/// The application expects to access the specified data
/// sequentially from lower offsets to higher offsets.
SEQUENTIAL = 5,
/// The application expects to access the specified data
/// in the near future.
WILLNEED = 6,
}
/// Enumeration describing the kind of value stored in [`auxv`](struct.auxv.html).
#[repr(u32)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum auxtype {
/// Base address of the binary argument data provided to
/// [`proc_exec()`](fn.proc_exec.html).
ARGDATA = 256,
/// Length of the binary argument data provided to
/// [`proc_exec()`](fn.proc_exec.html).
ARGDATALEN = 257,
/// Base address at which the executable is placed in
/// memory.
BASE = 7,
/// Base address of a buffer of random data that may be
/// used for non-cryptographic purposes, for example as a
/// canary for stack smashing protection.
CANARY = 258,
/// Length of a buffer of random data that may be used
/// for non-cryptographic purposes, for example as a
/// canary for stack smashing protection.
CANARYLEN = 259,
/// Number of CPUs that the system this process is running
/// on has.
NCPUS = 260,
/// Terminator of the auxiliary vector.
NULL = 0,
/// Smallest memory object size for which individual
/// memory protection controls can be configured.
PAGESZ = 6,
/// Address of the first ELF program header of the
/// executable.
PHDR = 3,
/// Number of ELF program headers of the executable.
PHNUM = 4,
/// Identifier of the process.
///
/// This environment does not provide any simple numerical
/// process identifiers, for the reason that these are not
/// useful in distributed contexts. Instead, processes are
/// identified by a UUID.
///
/// This record should point to sixteen bytes of binary
/// data, containing a version 4 UUID (fully random).
PID = 263,
/// Address of the ELF header of the vDSO.
///
/// The vDSO is a shared library that is mapped in the
/// address space of the process. It provides entry points
/// for every system call supported by the environment,
/// all having a corresponding symbol that is prefixed
/// with `cloudabi_sys_`. System calls should be invoked
/// through these entry points.
///
/// The first advantage of letting processes call into a
/// vDSO to perform system calls instead of raising
/// hardware traps is that it allows for easy emulation of
/// executables on top of existing operating systems. The
/// second advantage is that in cases where an operating
/// system provides native support for CloudABI executables,
/// it may still implement partial userspace
/// implementations of these system calls to improve
/// performance (e.g., [`clock_time_get()`](fn.clock_time_get.html)). It also provides
/// a more dynamic way of adding, removing or replacing
/// system calls.
SYSINFO_EHDR = 262,
/// Thread ID of the initial thread of the process.
TID = 261,
}
/// Identifiers for clocks.
#[repr(u32)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum clockid {
/// The system-wide monotonic clock, which is defined as a
/// clock measuring real time, whose value cannot be
/// adjusted and which cannot have negative clock jumps.
///
/// The epoch of this clock is undefined. The absolute
/// time value of this clock therefore has no meaning.
MONOTONIC = 1,
/// The CPU-time clock associated with the current
/// process.
PROCESS_CPUTIME_ID = 2,
/// The system-wide clock measuring real time. Time value
/// zero corresponds with 1970-01-01T00:00:00Z.
REALTIME = 3,
/// The CPU-time clock associated with the current thread.
THREAD_CPUTIME_ID = 4,
}
/// A userspace condition variable.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct condvar(pub u32);
/// The condition variable is in its initial state. There
/// are no threads waiting to be woken up. If the
/// condition variable has any other value, the kernel
/// must be called to wake up any sleeping threads.
pub const CONDVAR_HAS_NO_WAITERS: condvar = condvar(0);
/// Identifier for a device containing a file system. Can be used
/// in combination with [`inode`](struct.inode.html) to uniquely identify a file on the
/// local system.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct device(pub u64);
/// A reference to the offset of a directory entry.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct dircookie(pub u64);
/// Permanent reference to the first directory entry
/// within a directory.
pub const DIRCOOKIE_START: dircookie = dircookie(0);
/// Error codes returned by system calls.
///
/// Not all of these error codes are returned by the system calls
/// provided by this environment, but are either used in userspace
/// exclusively or merely provided for alignment with POSIX.
#[repr(u16)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum errno {
/// No error occurred. System call completed successfully.
SUCCESS = 0,
/// Argument list too long.
TOOBIG = 1,
/// Permission denied.
ACCES = 2,
/// Address in use.
ADDRINUSE = 3,
/// Address not available.
ADDRNOTAVAIL = 4,
/// Address family not supported.
AFNOSUPPORT = 5,
/// Resource unavailable, or operation would block.
AGAIN = 6,
/// Connection already in progress.
ALREADY = 7,
/// Bad file descriptor.
BADF = 8,
/// Bad message.
BADMSG = 9,
/// Device or resource busy.
BUSY = 10,
/// Operation canceled.
CANCELED = 11,
/// No child processes.
CHILD = 12,
/// Connection aborted.
CONNABORTED = 13,
/// Connection refused.
CONNREFUSED = 14,
/// Connection reset.
CONNRESET = 15,
/// Resource deadlock would occur.
DEADLK = 16,
/// Destination address required.
DESTADDRREQ = 17,
/// Mathematics argument out of domain of function.
DOM = 18,
/// Reserved.
DQUOT = 19,
/// File exists.
EXIST = 20,
/// Bad address.
FAULT = 21,
/// File too large.
FBIG = 22,
/// Host is unreachable.
HOSTUNREACH = 23,
/// Identifier removed.
IDRM = 24,
/// Illegal byte sequence.
ILSEQ = 25,
/// Operation in progress.
INPROGRESS = 26,
/// Interrupted function.
INTR = 27,
/// Invalid argument.
INVAL = 28,
/// I/O error.
IO = 29,
/// Socket is connected.
ISCONN = 30,
/// Is a directory.
ISDIR = 31,
/// Too many levels of symbolic links.
LOOP = 32,
/// File descriptor value too large.
MFILE = 33,
/// Too many links.
MLINK = 34,
/// Message too large.
MSGSIZE = 35,
/// Reserved.
MULTIHOP = 36,
/// Filename too long.
NAMETOOLONG = 37,
/// Network is down.
NETDOWN = 38,
/// Connection aborted by network.
NETRESET = 39,
/// Network unreachable.
NETUNREACH = 40,
/// Too many files open in system.
NFILE = 41,
/// No buffer space available.
NOBUFS = 42,
/// No such device.
NODEV = 43,
/// No such file or directory.
NOENT = 44,
/// Executable file format error.
NOEXEC = 45,
/// No locks available.
NOLCK = 46,
/// Reserved.
NOLINK = 47,
/// Not enough space.
NOMEM = 48,
/// No message of the desired type.
NOMSG = 49,
/// Protocol not available.
NOPROTOOPT = 50,
/// No space left on device.
NOSPC = 51,
/// Function not supported.
NOSYS = 52,
/// The socket is not connected.
NOTCONN = 53,
/// Not a directory or a symbolic link to a directory.
NOTDIR = 54,
/// Directory not empty.
NOTEMPTY = 55,
/// State not recoverable.
NOTRECOVERABLE = 56,
/// Not a socket.
NOTSOCK = 57,
/// Not supported, or operation not supported on socket.
NOTSUP = 58,
/// Inappropriate I/O control operation.
NOTTY = 59,
/// No such device or address.
NXIO = 60,
/// Value too large to be stored in data type.
OVERFLOW = 61,
/// Previous owner died.
OWNERDEAD = 62,
/// Operation not permitted.
PERM = 63,
/// Broken pipe.
PIPE = 64,
/// Protocol error.
PROTO = 65,
/// Protocol not supported.
PROTONOSUPPORT = 66,
/// Protocol wrong type for socket.
PROTOTYPE = 67,
/// Result too large.
RANGE = 68,
/// Read-only file system.
ROFS = 69,
/// Invalid seek.
SPIPE = 70,
/// No such process.
SRCH = 71,
/// Reserved.
STALE = 72,
/// Connection timed out.
TIMEDOUT = 73,
/// Text file busy.
TXTBSY = 74,
/// Cross-device link.
XDEV = 75,
/// Extension: Capabilities insufficient.
NOTCAPABLE = 76,
}
bitflags! {
/// The state of the file descriptor subscribed to with
/// [`FD_READ`](enum.eventtype.html#variant.FD_READ) or [`FD_WRITE`](enum.eventtype.html#variant.FD_WRITE).
#[repr(C)]
pub struct eventrwflags: u16 {
/// The peer of this socket has closed or disconnected.
const HANGUP = 0x0001;
}
}
/// Type of a subscription to an event or its occurrence.
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum eventtype {
/// The time value of clock [`subscription.union.clock.clock_id`](struct.subscription_clock.html#structfield.clock_id)
/// has reached timestamp [`subscription.union.clock.timeout`](struct.subscription_clock.html#structfield.timeout).
CLOCK = 1,
/// Condition variable [`subscription.union.condvar.condvar`](struct.subscription_condvar.html#structfield.condvar) has
/// been woken up and [`subscription.union.condvar.lock`](struct.subscription_condvar.html#structfield.lock) has been
/// acquired for writing.
CONDVAR = 2,
/// File descriptor [`subscription.union.fd_readwrite.fd`](struct.subscription_fd_readwrite.html#structfield.fd) has
/// data available for reading. This event always triggers
/// for regular files.
FD_READ = 3,
/// File descriptor [`subscription.union.fd_readwrite.fd`](struct.subscription_fd_readwrite.html#structfield.fd) has
/// capacity available for writing. This event always
/// triggers for regular files.
FD_WRITE = 4,
/// Lock [`subscription.union.lock.lock`](struct.subscription_lock.html#structfield.lock) has been acquired for
/// reading.
LOCK_RDLOCK = 5,
/// Lock [`subscription.union.lock.lock`](struct.subscription_lock.html#structfield.lock) has been acquired for
/// writing.
LOCK_WRLOCK = 6,
/// The process associated with process descriptor
/// [`subscription.union.proc_terminate.fd`](struct.subscription_proc_terminate.html#structfield.fd) has terminated.
PROC_TERMINATE = 7,
}
/// Exit code generated by a process when exiting.
pub type exitcode = u32;
/// A file descriptor number.
///
/// Unlike on POSIX-compliant systems, none of the file descriptor
/// numbers are reserved for a purpose (e.g., stdin, stdout,
/// stderr). Operating systems are not required to allocate new
/// file descriptors in ascending order.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct fd(pub u32);
/// Returned to the child process by [`proc_fork()`](fn.proc_fork.html).
pub const PROCESS_CHILD: fd = fd(0xffffffff);
/// Passed to [`mem_map()`](fn.mem_map.html) when creating a mapping to
/// anonymous memory.
pub const MAP_ANON_FD : fd = fd(0xffffffff);
bitflags! {
/// File descriptor flags.
#[repr(C)]
pub struct fdflags: u16 {
/// Append mode: Data written to the file is always
/// appended to the file's end.
const APPEND = 0x0001;
/// Write according to synchronized I/O data integrity
/// completion. Only the data stored in the file is
/// synchronized.
const DSYNC = 0x0002;
/// Non-blocking mode.
const NONBLOCK = 0x0004;
/// Synchronized read I/O operations.
const RSYNC = 0x0008;
/// Write according to synchronized I/O file integrity
/// completion. In addition to synchronizing the data
/// stored in the file, the system may also synchronously
/// update the file's metadata.
const SYNC = 0x0010;
}
}
bitflags! {
/// Which file descriptor attributes to adjust.
#[repr(C)]
pub struct fdsflags: u16 {
/// Adjust the file descriptor flags stored in
/// [`fdstat.fs_flags`](struct.fdstat.html#structfield.fs_flags).
const FLAGS = 0x0001;
/// Restrict the rights of the file descriptor to the
/// rights stored in [`fdstat.fs_rights_base`](struct.fdstat.html#structfield.fs_rights_base) and
/// [`fdstat.fs_rights_inheriting`](struct.fdstat.html#structfield.fs_rights_inheriting).
const RIGHTS = 0x0002;
}
}
/// Relative offset within a file.
pub type filedelta = i64;
/// Non-negative file size or length of a region within a file.
pub type filesize = u64;
/// The type of a file descriptor or file.
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum filetype {
/// The type of the file descriptor or file is unknown or
/// is different from any of the other types specified.
UNKNOWN = 0,
/// The file descriptor or file refers to a block device
/// inode.
BLOCK_DEVICE = 16,
/// The file descriptor or file refers to a character
/// device inode.
CHARACTER_DEVICE = 17,
/// The file descriptor or file refers to a directory
/// inode.
DIRECTORY = 32,
/// The file descriptor refers to a process handle.
PROCESS = 80,
/// The file descriptor or file refers to a regular file
/// inode.
REGULAR_FILE = 96,
/// The file descriptor refers to a shared memory object.
SHARED_MEMORY = 112,
/// The file descriptor or file refers to a datagram
/// socket.
SOCKET_DGRAM = 128,
/// The file descriptor or file refers to a byte-stream
/// socket.
SOCKET_STREAM = 130,
/// The file refers to a symbolic link inode.
SYMBOLIC_LINK = 144,
}
bitflags! {
/// Which file attributes to adjust.
#[repr(C)]
pub struct fsflags: u16 {
/// Adjust the last data access timestamp to the value
/// stored in [`filestat.st_atim`](struct.filestat.html#structfield.st_atim).
const ATIM = 0x0001;
/// Adjust the last data access timestamp to the time
/// of clock [`REALTIME`](enum.clockid.html#variant.REALTIME).
const ATIM_NOW = 0x0002;
/// Adjust the last data modification timestamp to the
/// value stored in [`filestat.st_mtim`](struct.filestat.html#structfield.st_mtim).
const MTIM = 0x0004;
/// Adjust the last data modification timestamp to the
/// time of clock [`REALTIME`](enum.clockid.html#variant.REALTIME).
const MTIM_NOW = 0x0008;
/// Truncate or extend the file to the size stored in
/// [`filestat.st_size`](struct.filestat.html#structfield.st_size).
const SIZE = 0x0010;
}
}
/// File serial number that is unique within its file system.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct inode(pub u64);
/// Number of hard links to an inode.
pub type linkcount = u32;
/// A userspace read-recursive readers-writer lock, similar to a
/// Linux futex or a FreeBSD umtx.
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct lock(pub u32);
/// Value indicating that the lock is in its initial
/// unlocked state.
pub const LOCK_UNLOCKED : lock = lock(0x00000000);
/// Bitmask indicating that the lock is write-locked. If
/// set, the lower 30 bits of the lock contain the
/// identifier of the thread that owns the write lock.
/// Otherwise, the lower 30 bits of the lock contain the
/// number of acquired read locks.
pub const LOCK_WRLOCKED : lock = lock(0x40000000);
/// Bitmask indicating that the lock is either read locked
/// or write locked, and that one or more threads have
/// their execution suspended, waiting to acquire the
/// lock. The last owner of the lock must call the
/// kernel to unlock.
///
/// When the lock is acquired for reading and this bit is
/// set, it means that one or more threads are attempting
/// to acquire this lock for writing. In that case, other
/// threads should only acquire additional read locks if
/// suspending execution would cause a deadlock. It is
/// preferred to suspend execution, as this prevents
/// starvation of writers.
pub const LOCK_KERNEL_MANAGED: lock = lock(0x80000000);
/// Value indicating that the lock is in an incorrect
/// state. A lock cannot be in its initial unlocked state,
/// while also managed by the kernel.
pub const LOCK_BOGUS : lock = lock(0x80000000);
bitflags! {
/// Flags determining the method of how paths are resolved.
#[repr(C)]
pub struct lookupflags: u32 {
/// As long as the resolved path corresponds to a symbolic
/// link, it is expanded.
const SYMLINK_FOLLOW = 0x00000001;
}
}
bitflags! {
/// Memory mapping flags.
#[repr(C)]
pub struct mflags: u8 {
/// Instead of mapping the contents of the file provided,
/// create a mapping to anonymous memory. The file
/// descriptor argument must be set to [`MAP_ANON_FD`](constant.MAP_ANON_FD.html),
/// and the offset must be set to zero.
const ANON = 0x01;
/// Require that the mapping is performed at the base
/// address provided.
const FIXED = 0x02;
/// Changes are private.
const PRIVATE = 0x04;
/// Changes are shared.
const SHARED = 0x08;
}
}
bitflags! {
/// Memory page protection options.
///
/// This implementation enforces the `W^X` property: Pages cannot be
/// mapped for execution while also mapped for writing.
#[repr(C)]
pub struct mprot: u8 {
/// Page can be executed.
const EXEC = 0x01;
/// Page can be written.
const WRITE = 0x02;
/// Page can be read.
const READ = 0x04;
}
}
bitflags! {
/// Methods of synchronizing memory with physical storage.
#[repr(C)]
pub struct msflags: u8 {
/// Perform asynchronous writes.
const ASYNC = 0x01;
/// Invalidate cached data.
const INVALIDATE = 0x02;
/// Perform synchronous writes.
const SYNC = 0x04;
}
}
/// Specifies the number of threads sleeping on a condition
/// variable that should be woken up.
pub type nthreads = u32;
bitflags! {
/// Open flags used by [`file_open()`](fn.file_open.html).
#[repr(C)]
pub struct oflags: u16 {
/// Create file if it does not exist.
const CREAT = 0x0001;
/// Fail if not a directory.
const DIRECTORY = 0x0002;
/// Fail if file already exists.
const EXCL = 0x0004;
/// Truncate file to size 0.
const TRUNC = 0x0008;
}
}
bitflags! {
/// Flags provided to [`sock_recv()`](fn.sock_recv.html).
#[repr(C)]
pub struct riflags: u16 {
/// Returns the message without removing it from the
/// socket's receive queue.
const PEEK = 0x0004;
/// On byte-stream sockets, block until the full amount
/// of data can be returned.
const WAITALL = 0x0010;
}
}
bitflags! {
/// File descriptor rights, determining which actions may be
/// performed.
#[repr(C)]
pub struct rights: u64 {
/// The right to invoke [`fd_datasync()`](fn.fd_datasync.html).
///
/// If [`FILE_OPEN`](struct.rights.html#associatedconstant.FILE_OPEN) is set, includes the right to
/// invoke [`file_open()`](fn.file_open.html) with [`DSYNC`](struct.fdflags.html#associatedconstant.DSYNC).
const FD_DATASYNC = 0x0000000000000001;
/// The right to invoke [`fd_read()`](fn.fd_read.html) and [`sock_recv()`](fn.sock_recv.html).
///
/// If [`MEM_MAP`](struct.rights.html#associatedconstant.MEM_MAP) is set, includes the right to
/// invoke [`mem_map()`](fn.mem_map.html) with memory protection option
/// [`READ`](struct.mprot.html#associatedconstant.READ).
///
/// If [`FD_SEEK`](struct.rights.html#associatedconstant.FD_SEEK) is set, includes the right to invoke
/// [`fd_pread()`](fn.fd_pread.html).
const FD_READ = 0x0000000000000002;
/// The right to invoke [`fd_seek()`](fn.fd_seek.html). This flag implies
/// [`FD_TELL`](struct.rights.html#associatedconstant.FD_TELL).
const FD_SEEK = 0x0000000000000004;
/// The right to invoke [`fd_stat_put()`](fn.fd_stat_put.html) with
/// [`FLAGS`](struct.fdsflags.html#associatedconstant.FLAGS).
const FD_STAT_PUT_FLAGS = 0x0000000000000008;
/// The right to invoke [`fd_sync()`](fn.fd_sync.html).
///
/// If [`FILE_OPEN`](struct.rights.html#associatedconstant.FILE_OPEN) is set, includes the right to
/// invoke [`file_open()`](fn.file_open.html) with [`RSYNC`](struct.fdflags.html#associatedconstant.RSYNC) and
/// [`DSYNC`](struct.fdflags.html#associatedconstant.DSYNC).
const FD_SYNC = 0x0000000000000010;
/// The right to invoke [`fd_seek()`](fn.fd_seek.html) in such a way that the
/// file offset remains unaltered (i.e., [`CUR`](enum.whence.html#variant.CUR) with
/// offset zero).
const FD_TELL = 0x0000000000000020;
/// The right to invoke [`fd_write()`](fn.fd_write.html) and [`sock_send()`](fn.sock_send.html).
///
/// If [`MEM_MAP`](struct.rights.html#associatedconstant.MEM_MAP) is set, includes the right to
/// invoke [`mem_map()`](fn.mem_map.html) with memory protection option
/// [`WRITE`](struct.mprot.html#associatedconstant.WRITE).
///
/// If [`FD_SEEK`](struct.rights.html#associatedconstant.FD_SEEK) is set, includes the right to
/// invoke [`fd_pwrite()`](fn.fd_pwrite.html).
const FD_WRITE = 0x0000000000000040;
/// The right to invoke [`file_advise()`](fn.file_advise.html).
const FILE_ADVISE = 0x0000000000000080;
/// The right to invoke [`file_allocate()`](fn.file_allocate.html).
const FILE_ALLOCATE = 0x0000000000000100;
/// The right to invoke [`file_create()`](fn.file_create.html) with
/// [`DIRECTORY`](enum.filetype.html#variant.DIRECTORY).
const FILE_CREATE_DIRECTORY = 0x0000000000000200;
/// If [`FILE_OPEN`](struct.rights.html#associatedconstant.FILE_OPEN) is set, the right to invoke
/// [`file_open()`](fn.file_open.html) with [`CREAT`](struct.oflags.html#associatedconstant.CREAT).
const FILE_CREATE_FILE = 0x0000000000000400;
/// The right to invoke [`file_link()`](fn.file_link.html) with the file
/// descriptor as the source directory.
const FILE_LINK_SOURCE = 0x0000000000001000;
/// The right to invoke [`file_link()`](fn.file_link.html) with the file
/// descriptor as the target directory.
const FILE_LINK_TARGET = 0x0000000000002000;
/// The right to invoke [`file_open()`](fn.file_open.html).
const FILE_OPEN = 0x0000000000004000;
/// The right to invoke [`file_readdir()`](fn.file_readdir.html).
const FILE_READDIR = 0x0000000000008000;
/// The right to invoke [`file_readlink()`](fn.file_readlink.html).
const FILE_READLINK = 0x0000000000010000;
/// The right to invoke [`file_rename()`](fn.file_rename.html) with the file
/// descriptor as the source directory.
const FILE_RENAME_SOURCE = 0x0000000000020000;
/// The right to invoke [`file_rename()`](fn.file_rename.html) with the file
/// descriptor as the target directory.
const FILE_RENAME_TARGET = 0x0000000000040000;
/// The right to invoke [`file_stat_fget()`](fn.file_stat_fget.html).
const FILE_STAT_FGET = 0x0000000000080000;
/// The right to invoke [`file_stat_fput()`](fn.file_stat_fput.html) with
/// [`SIZE`](struct.fsflags.html#associatedconstant.SIZE).
///
/// If [`FILE_OPEN`](struct.rights.html#associatedconstant.FILE_OPEN) is set, includes the right to
/// invoke [`file_open()`](fn.file_open.html) with [`TRUNC`](struct.oflags.html#associatedconstant.TRUNC).
const FILE_STAT_FPUT_SIZE = 0x0000000000100000;
/// The right to invoke [`file_stat_fput()`](fn.file_stat_fput.html) with
/// [`ATIM`](struct.fsflags.html#associatedconstant.ATIM), [`ATIM_NOW`](struct.fsflags.html#associatedconstant.ATIM_NOW), [`MTIM`](struct.fsflags.html#associatedconstant.MTIM),
/// and [`MTIM_NOW`](struct.fsflags.html#associatedconstant.MTIM_NOW).
const FILE_STAT_FPUT_TIMES = 0x0000000000200000;
/// The right to invoke [`file_stat_get()`](fn.file_stat_get.html).
const FILE_STAT_GET = 0x0000000000400000;
/// The right to invoke [`file_stat_put()`](fn.file_stat_put.html) with
/// [`ATIM`](struct.fsflags.html#associatedconstant.ATIM), [`ATIM_NOW`](struct.fsflags.html#associatedconstant.ATIM_NOW), [`MTIM`](struct.fsflags.html#associatedconstant.MTIM),
/// and [`MTIM_NOW`](struct.fsflags.html#associatedconstant.MTIM_NOW).
const FILE_STAT_PUT_TIMES = 0x0000000000800000;
/// The right to invoke [`file_symlink()`](fn.file_symlink.html).
const FILE_SYMLINK = 0x0000000001000000;
/// The right to invoke [`file_unlink()`](fn.file_unlink.html).
const FILE_UNLINK = 0x0000000002000000;
/// The right to invoke [`mem_map()`](fn.mem_map.html) with [`mprot`](struct.mprot.html) set to
/// zero.
const MEM_MAP = 0x0000000004000000;
/// If [`MEM_MAP`](struct.rights.html#associatedconstant.MEM_MAP) is set, the right to invoke
/// [`mem_map()`](fn.mem_map.html) with [`EXEC`](struct.mprot.html#associatedconstant.EXEC).
const MEM_MAP_EXEC = 0x0000000008000000;
/// If [`FD_READ`](struct.rights.html#associatedconstant.FD_READ) is set, includes the right to
/// invoke [`poll()`](fn.poll.html) to subscribe to [`FD_READ`](enum.eventtype.html#variant.FD_READ).
///
/// If [`FD_WRITE`](struct.rights.html#associatedconstant.FD_WRITE) is set, includes the right to
/// invoke [`poll()`](fn.poll.html) to subscribe to [`FD_WRITE`](enum.eventtype.html#variant.FD_WRITE).
const POLL_FD_READWRITE = 0x0000000010000000;
/// The right to invoke [`poll()`](fn.poll.html) to subscribe to
/// [`PROC_TERMINATE`](enum.eventtype.html#variant.PROC_TERMINATE).
const POLL_PROC_TERMINATE = 0x0000000040000000;
/// The right to invoke [`proc_exec()`](fn.proc_exec.html).
const PROC_EXEC = 0x0000000100000000;
/// The right to invoke [`sock_shutdown()`](fn.sock_shutdown.html).
const SOCK_SHUTDOWN = 0x0000008000000000;
}
}
bitflags! {
/// Flags returned by [`sock_recv()`](fn.sock_recv.html).
#[repr(C)]
pub struct roflags: u16 {
/// Returned by [`sock_recv()`](fn.sock_recv.html): List of file descriptors
/// has been truncated.
const FDS_TRUNCATED = 0x0001;
/// Returned by [`sock_recv()`](fn.sock_recv.html): Message data has been
/// truncated.
const DATA_TRUNCATED = 0x0008;
}
}
/// Indicates whether an object is stored in private or shared
/// memory.
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum scope {
/// The object is stored in private memory.
PRIVATE = 4,
/// The object is stored in shared memory.
SHARED = 8,
}
bitflags! {
/// Which channels on a socket need to be shut down.
#[repr(C)]
pub struct sdflags: u8 {
/// Disables further receive operations.
const RD = 0x01;
/// Disables further send operations.
const WR = 0x02;
}
}
bitflags! {
/// Flags provided to [`sock_send()`](fn.sock_send.html). As there are currently no flags
/// defined, it must be set to zero.
#[repr(C)]
pub struct siflags: u16 {
const DEFAULT = 0;
}
}
/// Signal condition.
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
pub enum signal {
/// Process abort signal.
///
/// Action: Terminates the process.
ABRT = 1,
/// Alarm clock.
///
/// Action: Terminates the process.
ALRM = 2,
/// Access to an undefined portion of a memory object.
///
/// Action: Terminates the process.
BUS = 3,
/// Child process terminated, stopped, or continued.
///
/// Action: Ignored.
CHLD = 4,
/// Continue executing, if stopped.
///
/// Action: Continues executing, if stopped.
CONT = 5,
/// Erroneous arithmetic operation.
///
/// Action: Terminates the process.
FPE = 6,
/// Hangup.
///
/// Action: Terminates the process.
HUP = 7,
/// Illegal instruction.
///
/// Action: Terminates the process.
ILL = 8,
/// Terminate interrupt signal.
///
/// Action: Terminates the process.
INT = 9,
/// Kill.
///
/// Action: Terminates the process.
KILL = 10,
/// Write on a pipe with no one to read it.
///
/// Action: Ignored.
PIPE = 11,
/// Terminal quit signal.
///
/// Action: Terminates the process.
QUIT = 12,
/// Invalid memory reference.
///
/// Action: Terminates the process.
SEGV = 13,
/// Stop executing.
///
/// Action: Stops executing.
STOP = 14,
/// Bad system call.
///
/// Action: Terminates the process.
SYS = 15,
/// Termination signal.
///
/// Action: Terminates the process.
TERM = 16,
/// Trace/breakpoint trap.
///
/// Action: Terminates the process.
TRAP = 17,
/// Terminal stop signal.
///
/// Action: Stops executing.
TSTP = 18,
/// Background process attempting read.
///
/// Action: Stops executing.
TTIN = 19,
/// Background process attempting write.
///
/// Action: Stops executing.
TTOU = 20,
/// High bandwidth data is available at a socket.
///
/// Action: Ignored.
URG = 21,
/// User-defined signal 1.
///
/// Action: Terminates the process.
USR1 = 22,
/// User-defined signal 2.
///
/// Action: Terminates the process.
USR2 = 23,
/// Virtual timer expired.
///
/// Action: Terminates the process.
VTALRM = 24,
/// CPU time limit exceeded.
///