summaryrefslogtreecommitdiffstats
path: root/vendor/hermit-abi
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/hermit-abi')
-rw-r--r--vendor/hermit-abi/.cargo-checksum.json2
-rw-r--r--vendor/hermit-abi/Cargo.toml31
-rw-r--r--vendor/hermit-abi/src/errno.rs397
-rw-r--r--vendor/hermit-abi/src/lib.rs74
4 files changed, 487 insertions, 17 deletions
diff --git a/vendor/hermit-abi/.cargo-checksum.json b/vendor/hermit-abi/.cargo-checksum.json
index 5b4a93900..53188c450 100644
--- a/vendor/hermit-abi/.cargo-checksum.json
+++ b/vendor/hermit-abi/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"9bd554080e32ce81c4741c85e81e70c4009ce5adbf5e8ffe9bda02b964b3208b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"322fadd63e558e5a10caf980cbedf83ac1546ba40fd992f54492e21ce54205af","src/lib.rs":"31fa39172e2e5310a2b2179456cfe3cadcd45443852a01b4a73a601a60bcf211","src/tcplistener.rs":"c6e2db06d4265fa0956851e1c965336d60c53ab21573729aae76ecfe0ccc84c3","src/tcpstream.rs":"38a17de54213faf9de217f6146ff86ee75b67d4404a532b1419903269200936b"},"package":"1ab7905ea95c6d9af62940f9d7dd9596d54c334ae2c15300c482051292d5637f"} \ No newline at end of file
+{"files":{"Cargo.toml":"1b4c80e131e223ca0213e4efe1eda533cd665213aa94ec8920e9b65139cd2122","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"322fadd63e558e5a10caf980cbedf83ac1546ba40fd992f54492e21ce54205af","src/errno.rs":"1c0680ead2ddf26b12d34bd7fa3e1dab386df761d6ac1901889ece26682dc465","src/lib.rs":"f444c2cf2b93506719841cc46605dcded34d0a4b50ff7d5da8d56044610ca463","src/tcplistener.rs":"c6e2db06d4265fa0956851e1c965336d60c53ab21573729aae76ecfe0ccc84c3","src/tcpstream.rs":"38a17de54213faf9de217f6146ff86ee75b67d4404a532b1419903269200936b"},"package":"ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"} \ No newline at end of file
diff --git a/vendor/hermit-abi/Cargo.toml b/vendor/hermit-abi/Cargo.toml
index 81b32c9bf..314aa6ad4 100644
--- a/vendor/hermit-abi/Cargo.toml
+++ b/vendor/hermit-abi/Cargo.toml
@@ -12,18 +12,32 @@
[package]
edition = "2021"
name = "hermit-abi"
-version = "0.2.0"
+version = "0.2.6"
authors = ["Stefan Lankes"]
-description = "hermit-abi is small interface to call functions from the unikernel RustyHermit.\nIt is used to build the target `x86_64-unknown-hermit`.\n"
+description = """
+hermit-abi is small interface to call functions from the unikernel RustyHermit.
+It is used to build the target `x86_64-unknown-hermit`.
+"""
documentation = "https://hermitcore.github.io/rusty-hermit/hermit_abi"
readme = "README.md"
-keywords = ["unikernel", "libos"]
+keywords = [
+ "unikernel",
+ "libos",
+]
categories = ["os"]
license = "MIT/Apache-2.0"
repository = "https://github.com/hermitcore/rusty-hermit"
+resolver = "1"
+
[package.metadata.docs.rs]
-default-target = "x86_64-unknown-hermit"
features = ["docs"]
+default-target = "x86_64-unknown-hermit"
+
+[dependencies.alloc]
+version = "1.0.0"
+optional = true
+package = "rustc-std-workspace-alloc"
+
[dependencies.compiler_builtins]
version = "0.1"
optional = true
@@ -34,10 +48,15 @@ optional = true
package = "rustc-std-workspace-core"
[dependencies.libc]
-version = "0.2.51"
+version = "0.2"
default-features = false
[features]
default = []
docs = []
-rustc-dep-of-std = ["core", "compiler_builtins/rustc-dep-of-std", "libc/rustc-dep-of-std"]
+rustc-dep-of-std = [
+ "core",
+ "alloc",
+ "compiler_builtins/rustc-dep-of-std",
+ "libc/rustc-dep-of-std",
+]
diff --git a/vendor/hermit-abi/src/errno.rs b/vendor/hermit-abi/src/errno.rs
new file mode 100644
index 000000000..dc22dc8ce
--- /dev/null
+++ b/vendor/hermit-abi/src/errno.rs
@@ -0,0 +1,397 @@
+/// Operation not permitted
+pub const EPERM: i32 = 1;
+
+/// No such file or directory
+pub const ENOENT: i32 = 2;
+
+/// No such process
+pub const ESRCH: i32 = 3;
+
+/// Interrupted system call
+pub const EINTR: i32 = 4;
+
+/// I/O error
+pub const EIO: i32 = 5;
+
+/// No such device or address
+pub const ENXIO: i32 = 6;
+
+/// Argument list too long
+pub const E2BIG: i32 = 7;
+
+/// Exec format error
+pub const ENOEXEC: i32 = 8;
+
+/// Bad file number
+pub const EBADF: i32 = 9;
+
+/// No child processes
+pub const ECHILD: i32 = 10;
+
+/// Try again
+pub const EAGAIN: i32 = 11;
+
+/// Out of memory
+pub const ENOMEM: i32 = 12;
+
+/// Permission denied
+pub const EACCES: i32 = 13;
+
+/// Bad address
+pub const EFAULT: i32 = 14;
+
+/// Block device required
+pub const ENOTBLK: i32 = 15;
+
+/// Device or resource busy
+pub const EBUSY: i32 = 16;
+
+/// File exists
+pub const EEXIST: i32 = 17;
+
+/// Cross-device link
+pub const EXDEV: i32 = 18;
+
+/// No such device
+pub const ENODEV: i32 = 19;
+
+/// Not a directory
+pub const ENOTDIR: i32 = 20;
+
+/// Is a directory
+pub const EISDIR: i32 = 21;
+
+/// Invalid argument
+pub const EINVAL: i32 = 22;
+
+/// File table overflow
+pub const ENFILE: i32 = 23;
+
+/// Too many open files
+pub const EMFILE: i32 = 24;
+
+/// Not a typewriter
+pub const ENOTTY: i32 = 25;
+
+/// Text file busy
+pub const ETXTBSY: i32 = 26;
+
+/// File too large
+pub const EFBIG: i32 = 27;
+
+/// No space left on device
+pub const ENOSPC: i32 = 28;
+
+/// Illegal seek
+pub const ESPIPE: i32 = 29;
+
+/// Read-only file system
+pub const EROFS: i32 = 30;
+
+/// Too many links
+pub const EMLINK: i32 = 31;
+
+/// Broken pipe
+pub const EPIPE: i32 = 32;
+
+/// Math argument out of domain of func
+pub const EDOM: i32 = 33;
+
+/// Math result not representable
+pub const ERANGE: i32 = 34;
+
+/// Resource deadlock would occur
+pub const EDEADLK: i32 = 35;
+
+/// File name too long
+pub const ENAMETOOLONG: i32 = 36;
+
+/// No record locks available
+pub const ENOLCK: i32 = 37;
+
+/// Function not implemented
+pub const ENOSYS: i32 = 38;
+
+/// Directory not empty
+pub const ENOTEMPTY: i32 = 39;
+
+/// Too many symbolic links encountered
+pub const ELOOP: i32 = 40;
+
+/// Operation would block
+pub const EWOULDBLOCK: i32 = EAGAIN;
+
+/// No message of desired type
+pub const ENOMSG: i32 = 42;
+
+/// Identifier removed
+pub const EIDRM: i32 = 43;
+
+/// Channel number out of range
+pub const ECHRNG: i32 = 44;
+
+/// Level 2 not synchronized
+pub const EL2NSYNC: i32 = 45;
+
+/// Level 3 halted
+pub const EL3HLT: i32 = 46;
+
+/// Level 3 reset
+pub const EL3RST: i32 = 47;
+
+/// Link number out of range
+pub const ELNRNG: i32 = 48;
+
+/// Protocol driver not attached
+pub const EUNATCH: i32 = 49;
+
+/// No CSI structure available
+pub const ENOCSI: i32 = 50;
+
+/// Level 2 halted
+pub const EL2HLT: i32 = 51;
+
+/// Invalid exchange
+pub const EBADE: i32 = 52;
+
+/// Invalid request descriptor
+pub const EBADR: i32 = 53;
+
+/// Exchange full
+pub const EXFULL: i32 = 54;
+
+/// No anode
+pub const ENOANO: i32 = 55;
+
+/// Invalid request code
+pub const EBADRQC: i32 = 56;
+
+/// Invalid slot
+pub const EBADSLT: i32 = 57;
+
+pub const EDEADLOCK: i32 = EDEADLK;
+
+/// Bad font file format
+pub const EBFONT: i32 = 59;
+
+/// Device not a stream
+pub const ENOSTR: i32 = 60;
+
+/// No data available
+pub const ENODATA: i32 = 61;
+
+/// Timer expired
+pub const ETIME: i32 = 62;
+
+/// Out of streams resources
+pub const ENOSR: i32 = 63;
+
+/// Machine is not on the network
+pub const ENONET: i32 = 64;
+
+/// Package not installed
+pub const ENOPKG: i32 = 65;
+
+/// Object is remote
+pub const EREMOTE: i32 = 66;
+
+/// Link has been severed
+pub const ENOLINK: i32 = 67;
+
+/// Advertise error
+pub const EADV: i32 = 68;
+
+/// Srmount error
+pub const ESRMNT: i32 = 69;
+
+/// Communication error on send
+pub const ECOMM: i32 = 70;
+
+/// Protocol error
+pub const EPROTO: i32 = 71;
+
+/// Multihop attempted
+pub const EMULTIHOP: i32 = 72;
+
+/// RFS specific error
+pub const EDOTDOT: i32 = 73;
+
+/// Not a data message
+pub const EBADMSG: i32 = 74;
+
+/// Value too large for defined data type
+pub const EOVERFLOW: i32 = 75;
+
+/// Name not unique on network
+pub const ENOTUNIQ: i32 = 76;
+
+/// File descriptor in bad state
+pub const EBADFD: i32 = 77;
+
+/// Remote address changed
+pub const EREMCHG: i32 = 78;
+
+/// Can not access a needed shared library
+pub const ELIBACC: i32 = 79;
+
+/// Accessing a corrupted shared library
+pub const ELIBBAD: i32 = 80;
+
+/// .lib section in a.out corrupted
+pub const ELIBSCN: i32 = 81;
+
+/// Attempting to link in too many shared libraries
+pub const ELIBMAX: i32 = 82;
+
+/// Cannot exec a shared library directly
+pub const ELIBEXEC: i32 = 83;
+
+/// Illegal byte sequence
+pub const EILSEQ: i32 = 84;
+
+/// Interrupted system call should be restarted
+pub const ERESTART: i32 = 85;
+
+/// Streams pipe error
+pub const ESTRPIPE: i32 = 86;
+
+/// Too many users
+pub const EUSERS: i32 = 87;
+
+/// Socket operation on non-socket
+pub const ENOTSOCK: i32 = 88;
+
+/// Destination address required
+pub const EDESTADDRREQ: i32 = 89;
+
+/// Message too long
+pub const EMSGSIZE: i32 = 90;
+
+/// Protocol wrong type for socket
+pub const EPROTOTYPE: i32 = 91;
+
+/// Protocol not available
+pub const ENOPROTOOPT: i32 = 92;
+
+/// Protocol not supported
+pub const EPROTONOSUPPORT: i32 = 93;
+
+/// Socket type not supported
+pub const ESOCKTNOSUPPORT: i32 = 94;
+
+/// Operation not supported on transport endpoint
+pub const EOPNOTSUPP: i32 = 95;
+
+/// Protocol family not supported
+pub const EPFNOSUPPORT: i32 = 96;
+
+/// Address family not supported by protocol
+pub const EAFNOSUPPORT: i32 = 97;
+
+/// Address already in use
+pub const EADDRINUSE: i32 = 98;
+
+/// Cannot assign requested address
+pub const EADDRNOTAVAIL: i32 = 99;
+
+/// Network is down
+pub const ENETDOWN: i32 = 100;
+
+/// Network is unreachable
+pub const ENETUNREACH: i32 = 101;
+
+/// Network dropped connection because of reset
+pub const ENETRESET: i32 = 102;
+
+/// Software caused connection abort
+pub const ECONNABORTED: i32 = 103;
+
+/// Connection reset by peer
+pub const ECONNRESET: i32 = 104;
+
+/// No buffer space available
+pub const ENOBUFS: i32 = 105;
+
+/// Transport endpoint is already connected
+pub const EISCONN: i32 = 106;
+
+/// Transport endpoint is not connected
+pub const ENOTCONN: i32 = 107;
+
+/// Cannot send after transport endpoint shutdown
+pub const ESHUTDOWN: i32 = 108;
+
+/// Too many references: cannot splice
+pub const ETOOMANYREFS: i32 = 109;
+
+/// Connection timed out
+pub const ETIMEDOUT: i32 = 110;
+
+/// Connection refused
+pub const ECONNREFUSED: i32 = 111;
+
+/// Host is down
+pub const EHOSTDOWN: i32 = 112;
+
+/// No route to host
+pub const EHOSTUNREACH: i32 = 113;
+
+/// Operation already in progress
+pub const EALREADY: i32 = 114;
+
+/// Operation now in progress
+pub const EINPROGRESS: i32 = 115;
+
+/// Stale file handle
+pub const ESTALE: i32 = 116;
+
+/// Structure needs cleaning
+pub const EUCLEAN: i32 = 117;
+
+/// Not a XENIX named type file
+pub const ENOTNAM: i32 = 118;
+
+/// No XENIX semaphores available
+pub const ENAVAIL: i32 = 119;
+
+/// Is a named type file
+pub const EISNAM: i32 = 120;
+
+/// Remote I/O error
+pub const EREMOTEIO: i32 = 121;
+
+/// Quota exceeded
+pub const EDQUOT: i32 = 122;
+
+/// No medium found
+pub const ENOMEDIUM: i32 = 123;
+
+/// Wrong medium type
+pub const EMEDIUMTYPE: i32 = 124;
+
+/// Operation Canceled
+pub const ECANCELED: i32 = 125;
+
+/// Required key not available
+pub const ENOKEY: i32 = 126;
+
+/// Key has expired
+pub const EKEYEXPIRED: i32 = 127;
+
+/// Key has been revoked
+pub const EKEYREVOKED: i32 = 128;
+
+/// Key was rejected by service
+pub const EKEYREJECTED: i32 = 129;
+
+/// Robust mutexes: Owner died
+pub const EOWNERDEAD: i32 = 130;
+
+/// Robust mutexes: State not recoverable
+pub const ENOTRECOVERABLE: i32 = 131;
+
+/// Robust mutexes: Operation not possible due to RF-kill
+pub const ERFKILL: i32 = 132;
+
+/// Robust mutexes: Memory page has hardware error
+pub const EHWPOISON: i32 = 133;
diff --git a/vendor/hermit-abi/src/lib.rs b/vendor/hermit-abi/src/lib.rs
index 7bb4a4cb0..2a8a2e2dc 100644
--- a/vendor/hermit-abi/src/lib.rs
+++ b/vendor/hermit-abi/src/lib.rs
@@ -5,23 +5,21 @@
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::result_unit_err)]
-extern crate libc;
-
+pub mod errno;
pub mod tcplistener;
pub mod tcpstream;
+use core::mem::MaybeUninit;
+
use libc::c_void;
// sysmbols, which are part of the library operating system
-extern "Rust" {
- fn sys_secure_rand64() -> Option<u64>;
- fn sys_secure_rand32() -> Option<u32>;
-}
-
extern "C" {
fn sys_rand() -> u32;
fn sys_srand(seed: u32);
+ fn sys_secure_rand32(value: *mut u32) -> i32;
+ fn sys_secure_rand64(value: *mut u64) -> i32;
fn sys_get_processor_count() -> usize;
fn sys_malloc(size: usize, align: usize) -> *mut u8;
fn sys_realloc(ptr: *mut u8, size: usize, align: usize, new_size: usize) -> *mut u8;
@@ -34,6 +32,13 @@ extern "C" {
fn sys_read(fd: i32, buf: *mut u8, len: usize) -> isize;
fn sys_write(fd: i32, buf: *const u8, len: usize) -> isize;
fn sys_close(fd: i32) -> i32;
+ fn sys_futex_wait(
+ address: *mut u32,
+ expected: u32,
+ timeout: *const timespec,
+ flags: u32,
+ ) -> i32;
+ fn sys_futex_wake(address: *mut u32, count: i32) -> i32;
fn sys_sem_init(sem: *mut *const c_void, value: u32) -> i32;
fn sys_sem_destroy(sem: *const c_void) -> i32;
fn sys_sem_post(sem: *const c_void) -> i32;
@@ -68,8 +73,10 @@ extern "C" {
fn sys_unlink(name: *const i8) -> i32;
fn sys_network_init() -> i32;
fn sys_block_current_task();
+ fn sys_block_current_task_with_timeout(timeout: u64);
fn sys_wakeup_task(tid: Tid);
fn sys_get_priority() -> u8;
+ fn sys_set_priority(tid: Tid, prio: u8);
}
/// A thread handle type
@@ -101,6 +108,7 @@ pub const LOW_PRIO: Priority = Priority::from(1);
pub struct Handle(usize);
pub const NSEC_PER_SEC: u64 = 1_000_000_000;
+pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1;
pub const CLOCK_REALTIME: u64 = 1;
pub const CLOCK_MONOTONIC: u64 = 4;
pub const STDIN_FILENO: libc::c_int = 0;
@@ -245,6 +253,33 @@ pub unsafe fn close(fd: i32) -> i32 {
sys_close(fd)
}
+/// If the value at address matches the expected value, park the current thread until it is either
+/// woken up with [`futex_wake`] (returns 0) or an optional timeout elapses (returns -ETIMEDOUT).
+///
+/// Setting `timeout` to null means the function will only return if [`futex_wake`] is called.
+/// Otherwise, `timeout` is interpreted as an absolute time measured with [`CLOCK_MONOTONIC`].
+/// If [`FUTEX_RELATIVE_TIMEOUT`] is set in `flags` the timeout is understood to be relative
+/// to the current time.
+///
+/// Returns -EINVAL if `address` is null, the timeout is negative or `flags` contains unknown values.
+#[inline(always)]
+pub unsafe fn futex_wait(
+ address: *mut u32,
+ expected: u32,
+ timeout: *const timespec,
+ flags: u32,
+) -> i32 {
+ sys_futex_wait(address, expected, timeout, flags)
+}
+
+/// Wake `count` threads waiting on the futex at `address`. Returns the number of threads
+/// woken up (saturates to `i32::MAX`). If `count` is `i32::MAX`, wake up all matching
+/// waiting threads. If `count` is negative or `address` is null, returns -EINVAL.
+#[inline(always)]
+pub unsafe fn futex_wake(address: *mut u32, count: i32) -> i32 {
+ sys_futex_wake(address, count)
+}
+
/// sem_init() initializes the unnamed semaphore at the address
/// pointed to by `sem`. The `value` argument specifies the
/// initial value for the semaphore.
@@ -459,7 +494,9 @@ pub unsafe fn srand(seed: u32) {
/// the function returns `None`.
#[inline(always)]
pub unsafe fn secure_rand32() -> Option<u32> {
- sys_secure_rand32()
+ let mut rand = MaybeUninit::uninit();
+ let res = sys_secure_rand32(rand.as_mut_ptr());
+ (res == 0).then(|| rand.assume_init())
}
/// Create a cryptographicly secure 64bit random number with the support of
@@ -467,16 +504,27 @@ pub unsafe fn secure_rand32() -> Option<u32> {
/// the function returns `None`.
#[inline(always)]
pub unsafe fn secure_rand64() -> Option<u64> {
- sys_secure_rand64()
+ let mut rand = MaybeUninit::uninit();
+ let res = sys_secure_rand64(rand.as_mut_ptr());
+ (res == 0).then(|| rand.assume_init())
}
-/// Add current task to the queue of blocked tasl. After calling `block_current_task`,
+/// Add current task to the queue of blocked tasks. After calling `block_current_task`,
/// call `yield_now` to switch to another task.
#[inline(always)]
pub unsafe fn block_current_task() {
sys_block_current_task();
}
+/// Add current task to the queue of blocked tasks, but wake it when `timeout` milliseconds
+/// have elapsed.
+///
+/// After calling `block_current_task`, call `yield_now` to switch to another task.
+#[inline(always)]
+pub unsafe fn block_current_task_with_timeout(timeout: u64) {
+ sys_block_current_task_with_timeout(timeout);
+}
+
/// Wakeup task with the thread id `tid`
#[inline(always)]
pub unsafe fn wakeup_task(tid: Tid) {
@@ -488,3 +536,9 @@ pub unsafe fn wakeup_task(tid: Tid) {
pub unsafe fn get_priority() -> Priority {
Priority::from(sys_get_priority())
}
+
+/// Determine the priority of the current thread
+#[inline(always)]
+pub unsafe fn set_priority(tid: Tid, prio: Priority) {
+ sys_set_priority(tid, prio.into());
+}