diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/rustix/src/backend/libc/system | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/rustix/src/backend/libc/system')
-rw-r--r-- | vendor/rustix/src/backend/libc/system/mod.rs | 3 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/system/syscalls.rs | 67 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/system/types.rs | 8 |
3 files changed, 78 insertions, 0 deletions
diff --git a/vendor/rustix/src/backend/libc/system/mod.rs b/vendor/rustix/src/backend/libc/system/mod.rs new file mode 100644 index 0000000..bff7fd5 --- /dev/null +++ b/vendor/rustix/src/backend/libc/system/mod.rs @@ -0,0 +1,3 @@ +#[cfg(not(windows))] +pub(crate) mod syscalls; +pub(crate) mod types; diff --git a/vendor/rustix/src/backend/libc/system/syscalls.rs b/vendor/rustix/src/backend/libc/system/syscalls.rs new file mode 100644 index 0000000..05d674b --- /dev/null +++ b/vendor/rustix/src/backend/libc/system/syscalls.rs @@ -0,0 +1,67 @@ +//! libc syscalls supporting `rustix::process`. + +use super::types::RawUname; +use crate::backend::c; +#[cfg(not(target_os = "wasi"))] +use crate::backend::conv::ret_infallible; +#[cfg(target_os = "linux")] +use crate::system::RebootCommand; +#[cfg(linux_kernel)] +use crate::system::Sysinfo; +use core::mem::MaybeUninit; +#[cfg(not(any( + target_os = "emscripten", + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] +use {crate::backend::conv::ret, crate::io}; + +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn uname() -> RawUname { + let mut uname = MaybeUninit::<RawUname>::uninit(); + unsafe { + let r = c::uname(uname.as_mut_ptr()); + + // On POSIX, `uname` is documented to return non-negative on success + // instead of the usual 0, though some specific systems do document + // that they always use zero allowing us to skip this check. + #[cfg(not(any(apple, freebsdlike, linux_like, target_os = "netbsd")))] + let r = core::cmp::min(r, 0); + + ret_infallible(r); + uname.assume_init() + } +} + +#[cfg(linux_kernel)] +pub(crate) fn sysinfo() -> Sysinfo { + let mut info = MaybeUninit::<Sysinfo>::uninit(); + unsafe { + ret_infallible(c::sysinfo(info.as_mut_ptr())); + info.assume_init() + } +} + +#[cfg(not(any( + target_os = "emscripten", + target_os = "espidf", + target_os = "redox", + target_os = "vita", + target_os = "wasi" +)))] +pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { + unsafe { + ret(c::sethostname( + name.as_ptr().cast(), + name.len().try_into().map_err(|_| io::Errno::INVAL)?, + )) + } +} + +#[cfg(target_os = "linux")] +pub(crate) fn reboot(cmd: RebootCommand) -> io::Result<()> { + unsafe { ret(c::reboot(cmd as i32)) } +} diff --git a/vendor/rustix/src/backend/libc/system/types.rs b/vendor/rustix/src/backend/libc/system/types.rs new file mode 100644 index 0000000..731e89b --- /dev/null +++ b/vendor/rustix/src/backend/libc/system/types.rs @@ -0,0 +1,8 @@ +use crate::backend::c; + +/// `sysinfo` +#[cfg(linux_kernel)] +pub type Sysinfo = c::sysinfo; + +#[cfg(not(target_os = "wasi"))] +pub(crate) type RawUname = c::utsname; |