Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

1
vendor/libredox/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{"Cargo.lock":"c4af84cd84ef63dd83ce49a1c62038a6ff340b0384d8b7039687fd2f23644869","Cargo.toml":"f97902aee37e2edc5a38aac1187895dc735a57c279a3b116576880bf91d2d9f1","LICENSE":"8d073a6a80d1ef2d2fc2bc6c809aa221161bf1906c76d4aeef55fd2b999d9413","src/lib.rs":"8ed861afa04c44c872645b5be6173060b522b72ae56c161d954cc2c32e8d3eb5"},"package":"416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb"}

66
vendor/libredox/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,66 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bitflags"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
[[package]]
name = "ioslice"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e571352c8a3b89074d12e3ee5173ffe162159105352aaaf1fc5764da747e31b"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
[[package]]
name = "libredox"
version = "0.1.10"
dependencies = [
"bitflags",
"ioslice",
"libc",
"redox_syscall",
]
[[package]]
name = "redox_syscall"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [
"bitflags",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

55
vendor/libredox/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,55 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "libredox"
version = "0.1.10"
authors = ["4lDO2 <4lDO2@protonmail.com>"]
build = false
exclude = ["target"]
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Redox stable ABI"
readme = false
license = "MIT"
repository = "https://gitlab.redox-os.org/redox-os/libredox.git"
[features]
call = []
default = [
"call",
"std",
"redox_syscall",
]
mkns = ["ioslice"]
std = []
[lib]
name = "libredox"
path = "src/lib.rs"
[dependencies.bitflags]
version = "2"
[dependencies.ioslice]
version = "0.6"
optional = true
[dependencies.libc]
version = "0.2"
[dependencies.redox_syscall]
version = "0.5.16"
optional = true

21
vendor/libredox/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 4lDO2
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

714
vendor/libredox/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,714 @@
//! Redox-specific system library.
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "call")]
use self::error::{Error, Result};
pub mod error {
use super::*;
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
// TODO: Define as enum?
pub struct Error {
// TODO: NonZeroU16? "success" is not an error.
errno: u16,
}
impl Error {
pub fn new(errno: i32) -> Self {
Self {
errno: errno.try_into().unwrap_or(u16::MAX),
}
}
pub fn errno(self) -> i32 {
self.errno.into()
}
pub fn is_wouldblock(self) -> bool {
matches!(self.errno(), errno::EAGAIN | errno::EWOULDBLOCK)
}
pub fn is_interrupt(self) -> bool {
self.errno() == errno::EINTR
}
pub fn mux(res: Result<usize, Self>) -> usize {
match res {
// TODO: Ensure success cannot overlap with error values.
Ok(success) => success,
Err(error) => usize::wrapping_neg(usize::from(error.errno)),
}
}
pub fn demux(res: usize) -> Result<usize, Self> {
if res > usize::wrapping_neg(4096) {
Err(Self {
errno: res.wrapping_neg().try_into().expect("2^BITS - res < 4096"),
})
} else {
Ok(res)
}
}
#[cfg(feature = "call")]
pub fn description(self, buf: &mut [u8]) -> &str {
call::strerror(self.errno, buf).map_or("unknown error", |(desc, _)| desc)
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
#[cfg(feature = "call")]
{
write!(f, "{}", self.description(&mut [0; 256]))
}
#[cfg(not(feature = "call"))]
{
write!(f, "Error {} (strerror unavailable)", self.errno)
}
}
}
impl core::fmt::Debug for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
#[cfg(feature = "call")]
{
write!(
f,
"Error `{}` {}",
self.description(&mut [0; 256]),
self.errno
)
}
#[cfg(not(feature = "call"))]
{
write!(f, "Error {} (strerror unavailable)", self.errno)
}
}
}
#[cfg(feature = "redox_syscall")]
impl From<syscall::Error> for Error {
fn from(value: syscall::Error) -> Self {
Self {
errno: value.errno.try_into().unwrap_or(u16::MAX),
}
}
}
#[cfg(feature = "redox_syscall")]
impl From<Error> for syscall::Error {
fn from(value: Error) -> Self {
Self::new(value.errno())
}
}
#[cfg(feature = "std")]
impl From<Error> for std::io::Error {
fn from(value: Error) -> Self {
Self::from_raw_os_error(value.errno.into())
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T, E = Error> = core::result::Result<T, E>;
}
pub mod flag {
pub use libc::{
O_ACCMODE, O_APPEND, O_ASYNC, O_CLOEXEC, O_CREAT, O_DIRECTORY, O_EXCL, O_FSYNC, O_NOFOLLOW,
O_NONBLOCK, O_PATH, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,
};
pub use libc::{CLOCK_MONOTONIC, CLOCK_REALTIME};
pub use libc::{SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK};
pub use libc::{
SIGABRT,
SIGALRM,
SIGBUS,
SIGCHLD,
SIGCONT,
SIGFPE,
// TODO: Const rather than use, to convert to u32
SIGHUP,
SIGILL,
SIGINT,
SIGIO,
SIGKILL,
SIGPIPE,
SIGPROF,
SIGPWR,
SIGQUIT,
SIGSEGV,
SIGSTKFLT,
SIGSYS,
SIGTERM,
SIGTRAP,
SIGTSTP,
SIGTTIN,
SIGTTOU,
SIGURG,
SIGUSR1,
SIGUSR2,
SIGVTALRM,
SIGWINCH,
SIGXFSZ,
};
#[cfg(target_os = "redox")]
pub use libc::{O_EXLOCK, O_SHLOCK, O_SYMLINK};
pub const MAP_SHARED: u32 = libc::MAP_SHARED as u32;
pub const MAP_PRIVATE: u32 = libc::MAP_PRIVATE as u32;
pub const PROT_NONE: u32 = libc::PROT_NONE as u32;
pub const PROT_READ: u32 = libc::PROT_READ as u32;
pub const PROT_WRITE: u32 = libc::PROT_WRITE as u32;
pub const PROT_EXEC: u32 = libc::PROT_EXEC as u32;
pub const WNOHANG: u32 = libc::WNOHANG as u32;
pub const WUNTRACED: u32 = libc::WUNTRACED as u32;
pub const WCONTINUED: u32 = libc::WCONTINUED as u32;
}
pub mod errno {
pub use libc::{
E2BIG, EACCES, EADDRINUSE, EADDRNOTAVAIL, EADV, EAFNOSUPPORT, EAGAIN, EALREADY, EBADE,
EBADF, EBADFD, EBADMSG, EBADR, EBADRQC, EBADSLT, EBFONT, EBUSY, ECANCELED, ECHILD, ECHRNG,
ECOMM, ECONNABORTED, ECONNREFUSED, ECONNRESET, EDEADLK, EDEADLOCK, EDESTADDRREQ, EDOM,
EDOTDOT, EDQUOT, EEXIST, EFAULT, EFBIG, EHOSTDOWN, EHOSTUNREACH, EIDRM, EILSEQ,
EINPROGRESS, EINTR, EINVAL, EIO, EISCONN, EISDIR, EISNAM, EKEYEXPIRED, EKEYREJECTED,
EKEYREVOKED, EL2HLT, EL2NSYNC, EL3HLT, EL3RST, ELIBACC, ELIBBAD, ELIBEXEC, ELIBMAX,
ELIBSCN, ELNRNG, ELOOP, EMEDIUMTYPE, EMFILE, EMLINK, EMSGSIZE, EMULTIHOP, ENAMETOOLONG,
ENAVAIL, ENETDOWN, ENETRESET, ENETUNREACH, ENFILE, ENOANO, ENOBUFS, ENOCSI, ENODEV, ENOENT,
ENOEXEC, ENOKEY, ENOLCK, ENOMEDIUM, ENOMEM, ENOMSG, ENONET, ENOPKG, ENOPROTOOPT, ENOSPC,
ENOSR, ENOSTR, ENOSYS, ENOTBLK, ENOTCONN, ENOTDIR, ENOTEMPTY, ENOTNAM, ENOTRECOVERABLE,
ENOTSOCK, ENOTTY, ENOTUNIQ, ENXIO, EOPNOTSUPP, EOVERFLOW, EOWNERDEAD, EPERM, EPFNOSUPPORT,
EPIPE, EPROTO, EPROTONOSUPPORT, EPROTOTYPE, ERANGE, EREMCHG, EREMOTE, EREMOTEIO, ERESTART,
EROFS, ESHUTDOWN, ESOCKTNOSUPPORT, ESPIPE, ESRCH, ESRMNT, ESTALE, ESTRPIPE, ETIME,
ETIMEDOUT, ETOOMANYREFS, ETXTBSY, EUCLEAN, EUNATCH, EUSERS, EWOULDBLOCK, EXDEV, EXFULL,
};
}
pub mod data {
pub use libc::iovec as IoVec;
pub use libc::sigaction as SigAction;
pub use libc::stat as Stat;
pub use libc::statvfs as StatVfs;
pub use libc::timespec as TimeSpec;
// TODO: Remove
pub fn timespec_from_mut_bytes(bytes: &mut [u8]) -> &mut TimeSpec {
assert!(bytes.len() >= core::mem::size_of::<TimeSpec>());
assert_eq!(
bytes.as_ptr() as usize % core::mem::align_of::<TimeSpec>(),
0
);
unsafe { &mut *bytes.as_mut_ptr().cast() }
}
// TODO: Remove
pub fn timespec_from_bytes(bytes: &[u8]) -> &TimeSpec {
assert!(bytes.len() >= core::mem::size_of::<TimeSpec>());
assert_eq!(
bytes.as_ptr() as usize % core::mem::align_of::<TimeSpec>(),
0
);
unsafe { &*bytes.as_ptr().cast() }
}
#[cfg(target_os = "redox")]
pub use libc::sigset_t as SigSet;
// TODO: Should libredox compile on non-Redox platforms?
#[cfg(not(target_os = "redox"))]
pub type SigSet = u64;
}
#[cfg(feature = "call")]
type RawResult = usize;
#[cfg(feature = "call")]
#[allow(dead_code)]
extern "C" {
// NOTE: Although there are version suffixes, there'd have to be strong reasons for adding new
// version.
fn redox_open_v1(path_base: *const u8, path_len: usize, flags: u32, mode: u16) -> RawResult;
fn redox_openat_v1(
fd: usize,
buf: *const u8,
path_len: usize,
flags: u32,
fcntl_flags: u32,
) -> RawResult;
fn redox_dup_v1(fd: usize, buf: *const u8, len: usize) -> RawResult;
fn redox_dup2_v1(old_fd: usize, new_fd: usize, buf: *const u8, len: usize) -> RawResult;
fn redox_read_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult;
fn redox_write_v1(fd: usize, src_base: *const u8, src_len: usize) -> RawResult;
fn redox_fsync_v1(fd: usize) -> RawResult;
fn redox_fdatasync_v1(fd: usize) -> RawResult;
fn redox_fchmod_v1(fd: usize, new_mode: u16) -> RawResult;
fn redox_fchown_v1(fd: usize, new_uid: u32, new_gid: u32) -> RawResult;
fn redox_fpath_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult;
fn redox_fstat_v1(fd: usize, dst: *mut data::Stat) -> RawResult;
fn redox_fstatvfs_v1(fd: usize, dst: *mut data::StatVfs) -> RawResult;
fn redox_futimens_v1(fd: usize, times: *const data::TimeSpec) -> RawResult;
fn redox_close_v1(fd: usize) -> RawResult;
// NOTE: While the Redox kernel currently doesn't distinguish between threads and processes,
// the return value of this function is expected to be treated as a process ID and not a thread
// ID.
fn redox_get_pid_v1() -> RawResult;
fn redox_get_euid_v1() -> RawResult;
fn redox_get_ruid_v1() -> RawResult;
fn redox_get_egid_v1() -> RawResult;
fn redox_get_rgid_v1() -> RawResult;
fn redox_get_ens_v0() -> RawResult;
// This function is used to get the credentials, pid, euid, egid etc. of the process with the target pid.
fn redox_get_proc_credentials_v1(cap_fd: usize, target_pid: usize, buf: &mut [u8])
-> RawResult;
fn redox_setrens_v1(rns: usize, ens: usize) -> RawResult;
fn redox_mkns_v1(names: *const data::IoVec, num_names: usize, _flags: u32) -> RawResult;
fn redox_kill_v1(pid: usize, signal: u32) -> RawResult;
fn redox_waitpid_v1(pid: usize, status: *mut i32, options: u32) -> RawResult;
fn redox_sigprocmask_v1(how: u32, new: *const u64, old: *mut u64) -> RawResult;
fn redox_sigaction_v1(
signal: u32,
new: *const data::SigAction,
old: *mut data::SigAction,
) -> RawResult;
fn redox_clock_gettime_v1(clock: usize, ts: *mut data::TimeSpec) -> RawResult;
fn redox_mmap_v1(
addr: *mut (),
unaligned_len: usize,
prot: u32,
flags: u32,
fd: usize,
offset: u64,
) -> RawResult;
fn redox_munmap_v1(addr: *mut (), unaligned_len: usize) -> RawResult;
fn redox_strerror_v1(dst: *mut u8, dst_len: *mut usize, error: u32) -> RawResult;
fn redox_sys_call_v0(
fd: usize,
payload: *mut u8,
payload_len: usize,
flags: usize,
metadata: *const u64,
metadata_len: usize,
) -> RawResult;
fn redox_get_socket_token_v0(fd: usize, payload: *mut u8, payload_len: usize) -> RawResult;
}
#[cfg(feature = "call")]
pub struct Fd(usize);
#[cfg(feature = "call")]
impl Fd {
#[inline]
pub fn open(path: &str, flags: i32, mode: u16) -> Result<Self> {
Ok(Self(call::open(path, flags, mode)?))
}
pub fn openat(&self, path: &str, flags: i32, fcntl_flags: u32) -> Result<Self> {
Ok(Self(call::openat(self.raw(), path, flags, fcntl_flags)?))
}
#[inline]
pub fn dup(&self, buf: &[u8]) -> Result<usize> {
call::dup(self.raw(), buf)
}
#[inline]
pub fn dup2(&self, new_fd: usize, buf: &[u8]) -> Result<usize> {
call::dup2(self.raw(), new_fd, buf)
}
#[inline]
pub const fn raw(&self) -> usize {
self.0
}
#[inline]
pub fn into_raw(self) -> usize {
let raw = self.raw();
core::mem::forget(self);
raw
}
#[inline]
pub fn read(&self, buf: &mut [u8]) -> Result<usize> {
call::read(self.raw(), buf)
}
#[inline]
pub fn write(&self, buf: &[u8]) -> Result<usize> {
call::write(self.raw(), buf)
}
#[inline]
pub fn fpath(&self, path: &mut [u8]) -> Result<usize> {
call::fpath(self.raw(), path)
}
#[inline]
pub fn fsync(&self) -> Result<()> {
call::fsync(self.raw())
}
#[inline]
pub fn fdatasync(&self) -> Result<()> {
call::fdatasync(self.raw())
}
#[inline]
pub fn chmod(&self, new_mode: u16) -> Result<()> {
call::fchmod(self.raw(), new_mode)
}
#[inline]
pub fn chown(&self, new_uid: u32, new_gid: u32) -> Result<()> {
call::fchown(self.raw(), new_uid, new_gid)
}
pub fn stat(&self) -> Result<data::Stat> {
call::fstat(self.raw())
}
pub fn statvfs(&self) -> Result<data::StatVfs> {
call::fstatvfs(self.raw())
}
// TODO: futimens
#[inline]
pub fn close(self) -> Result<()> {
call::close(self.into_raw())
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_ro(
&self,
payload: &mut [u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
call::call_ro(self.raw(), payload, flags, metadata)
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_wo(
&self,
payload: &[u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
call::call_wo(self.raw(), payload, flags, metadata)
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_rw(
&self,
payload: &mut [u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
call::call_rw(self.raw(), payload, flags, metadata)
}
}
#[cfg(feature = "call")]
impl Drop for Fd {
fn drop(&mut self) {
let _ = unsafe { redox_close_v1(self.0) };
}
}
#[cfg(feature = "call")]
pub mod call {
use core::mem::MaybeUninit;
use super::*;
/// flags and mode are binary compatible with libc
#[inline]
pub fn open(path: impl AsRef<str>, flags: i32, mode: u16) -> Result<usize> {
let path = path.as_ref();
Ok(Error::demux(unsafe {
redox_open_v1(path.as_ptr(), path.len(), flags as u32, mode)
})?)
}
#[inline]
pub fn openat(
fd: usize,
path: impl AsRef<[u8]>,
flags: i32,
fcntl_flags: u32,
) -> Result<usize> {
let path = path.as_ref();
Ok(Error::demux(unsafe {
redox_openat_v1(fd, path.as_ptr(), path.len(), flags as u32, fcntl_flags)
})?)
}
#[inline]
pub fn dup(fd: usize, buf: impl AsRef<[u8]>) -> Result<usize> {
let buf = buf.as_ref();
Ok(Error::demux(unsafe {
redox_dup_v1(fd, buf.as_ptr(), buf.len())
})?)
}
#[inline]
pub fn dup2(old_fd: usize, new_fd: usize, buf: impl AsRef<[u8]>) -> Result<usize> {
let buf = buf.as_ref();
Ok(Error::demux(unsafe {
redox_dup2_v1(old_fd, new_fd, buf.as_ptr(), buf.len())
})?)
}
#[inline]
pub fn read(raw_fd: usize, buf: &mut [u8]) -> Result<usize> {
Ok(Error::demux(unsafe {
redox_read_v1(raw_fd, buf.as_mut_ptr(), buf.len())
})?)
}
#[inline]
pub fn write(raw_fd: usize, buf: &[u8]) -> Result<usize> {
Error::demux(unsafe { redox_write_v1(raw_fd, buf.as_ptr(), buf.len()) })
}
#[inline]
pub fn fsync(raw_fd: usize) -> Result<()> {
Error::demux(unsafe { redox_fsync_v1(raw_fd) }).map(|_| ())
}
#[inline]
pub fn fdatasync(raw_fd: usize) -> Result<()> {
Error::demux(unsafe { redox_fdatasync_v1(raw_fd) }).map(|_| ())
}
#[inline]
pub fn fchmod(raw_fd: usize, new_mode: u16) -> Result<()> {
Error::demux(unsafe { redox_fchmod_v1(raw_fd, new_mode) })?;
Ok(())
}
#[inline]
pub fn fchown(raw_fd: usize, new_uid: u32, new_gid: u32) -> Result<()> {
Error::demux(unsafe { redox_fchown_v1(raw_fd, new_uid, new_gid) })?;
Ok(())
}
#[inline]
pub fn fpath(raw_fd: usize, buf: &mut [u8]) -> Result<usize> {
Error::demux(unsafe { redox_fpath_v1(raw_fd, buf.as_mut_ptr(), buf.len()) })
}
#[inline]
pub fn fstat(raw_fd: usize) -> Result<data::Stat> {
unsafe {
let mut ret = MaybeUninit::uninit();
Error::demux(redox_fstat_v1(raw_fd, ret.as_mut_ptr()))?;
Ok(ret.assume_init())
}
}
#[inline]
pub fn fstatvfs(raw_fd: usize) -> Result<data::StatVfs> {
unsafe {
let mut ret = MaybeUninit::uninit();
Error::demux(redox_fstatvfs_v1(raw_fd, ret.as_mut_ptr()))?;
Ok(ret.assume_init())
}
}
#[inline]
pub fn futimens(raw_fd: usize, times: &[data::TimeSpec; 2]) -> Result<()> {
Error::demux(unsafe { redox_futimens_v1(raw_fd, times.as_ptr()) })?;
Ok(())
}
#[inline]
pub fn close(raw_fd: usize) -> Result<()> {
Error::demux(unsafe { redox_close_v1(raw_fd) })?;
Ok(())
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_ro(
fd: usize,
payload: &mut [u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
Ok(Error::demux(unsafe {
redox_sys_call_v0(
fd,
payload.as_mut_ptr(),
payload.len(),
(flags | syscall::CallFlags::READ).bits(),
metadata.as_ptr(),
metadata.len(),
)
})?)
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_wo(
fd: usize,
payload: &[u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
Ok(Error::demux(unsafe {
redox_sys_call_v0(
fd,
payload.as_ptr() as *mut u8,
payload.len(),
(flags | syscall::CallFlags::WRITE).bits(),
metadata.as_ptr(),
metadata.len(),
)
})?)
}
#[cfg(feature = "redox_syscall")]
#[inline]
pub fn call_rw(
fd: usize,
payload: &mut [u8],
flags: syscall::CallFlags,
metadata: &[u64],
) -> Result<usize> {
Ok(Error::demux(unsafe {
redox_sys_call_v0(
fd,
payload.as_mut_ptr(),
payload.len(),
(flags | syscall::CallFlags::READ | syscall::CallFlags::WRITE).bits(),
metadata.as_ptr(),
metadata.len(),
)
})?)
}
#[inline]
pub fn geteuid() -> Result<usize> {
Error::demux(unsafe { redox_get_euid_v1() })
}
#[inline]
pub fn getruid() -> Result<usize> {
Error::demux(unsafe { redox_get_ruid_v1() })
}
#[inline]
pub fn getegid() -> Result<usize> {
Error::demux(unsafe { redox_get_egid_v1() })
}
#[inline]
pub fn getrgid() -> Result<usize> {
Error::demux(unsafe { redox_get_rgid_v1() })
}
#[inline]
pub fn getpid() -> Result<usize> {
Error::demux(unsafe { redox_get_pid_v1() })
}
#[inline]
pub fn getens() -> Result<usize> {
Error::demux(unsafe { redox_get_ens_v0() })
}
#[inline]
// [u8; size_of::<crate::protocol::ProcMeta>()]
pub fn get_proc_credentials(cap_fd: usize, target_pid: usize, buf: &mut [u8]) -> Result<usize> {
Error::demux(unsafe { redox_get_proc_credentials_v1(cap_fd, target_pid, buf) })
}
#[inline]
pub fn setrens(rns: usize, ens: usize) -> Result<usize> {
Error::demux(unsafe { redox_setrens_v1(rns, ens) })
}
#[inline]
pub fn waitpid(pid: usize, status: &mut i32, options: i32) -> Result<usize> {
Error::demux(unsafe { redox_waitpid_v1(pid, status as *mut i32, options as u32) })
}
#[inline]
pub fn kill(pid: usize, signal: u32) -> Result<()> {
Error::demux(unsafe { redox_kill_v1(pid, signal) }).map(|_| ())
}
#[inline]
pub fn clock_gettime(clock: i32) -> Result<data::TimeSpec> {
unsafe {
let mut ret = MaybeUninit::uninit();
Error::demux(redox_clock_gettime_v1(clock as usize, ret.as_mut_ptr()))?;
Ok(ret.assume_init())
}
}
#[inline]
pub fn sigprocmask(
how: i32,
newmask: Option<&data::SigSet>,
oldmask: Option<&mut data::SigSet>,
) -> Result<()> {
Error::demux(unsafe {
redox_sigprocmask_v1(
how as u32,
newmask.map_or(core::ptr::null(), |m| m),
oldmask.map_or(core::ptr::null_mut(), |m| m),
)
})
.map(|_| ())
}
#[inline]
pub fn sigaction(
signal: i32,
newact: Option<&data::SigAction>,
oldact: Option<&mut data::SigAction>,
) -> Result<()> {
Error::demux(unsafe {
redox_sigaction_v1(
signal as u32,
newact.map_or(core::ptr::null(), |m| m),
oldact.map_or(core::ptr::null_mut(), |m| m),
)
})
.map(|_| ())
}
#[derive(Clone, Copy, Debug)]
pub struct MmapArgs {
pub addr: *mut (),
pub length: usize,
pub prot: u32,
pub flags: u32,
pub fd: usize,
pub offset: u64,
}
#[inline]
pub unsafe fn mmap(args: MmapArgs) -> Result<*mut ()> {
Error::demux(redox_mmap_v1(
args.addr,
args.length,
args.prot,
args.flags,
args.fd,
args.offset,
))
.map(|addr| addr as *mut ())
}
#[inline]
pub unsafe fn munmap(addr: *mut (), length: usize) -> Result<()> {
Error::demux(redox_munmap_v1(addr, length)).map(|_| ())
}
#[inline]
pub fn strerror(error: u16, desc: &mut [u8]) -> Option<(&str, usize)> {
unsafe {
let mut len_inout = desc.len();
let copied_len = Error::demux(redox_strerror_v1(
desc.as_mut_ptr(),
&mut len_inout,
error.into(),
))
.ok()?;
Some((
core::str::from_utf8_unchecked(&desc[..copied_len]),
len_inout,
))
}
}
#[inline]
#[cfg(feature = "mkns")]
pub fn mkns(names: &[ioslice::IoSlice]) -> Result<usize> {
// no-op
let iovecs = ioslice::IoSlice::cast_to_raw_iovecs(names);
unsafe { Error::demux(redox_mkns_v1(iovecs.as_ptr(), iovecs.len(), 0)) }
}
#[inline]
pub fn get_socket_token(fd: usize, buf: &mut [u8]) -> Result<usize> {
Error::demux(unsafe { redox_get_socket_token_v0(fd, buf.as_mut_ptr(), buf.len()) })
}
}