diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/rustix/src/backend/linux_raw/system | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/rustix/src/backend/linux_raw/system')
| -rw-r--r-- | vendor/rustix/src/backend/linux_raw/system/mod.rs | 2 | ||||
| -rw-r--r-- | vendor/rustix/src/backend/linux_raw/system/syscalls.rs | 91 | ||||
| -rw-r--r-- | vendor/rustix/src/backend/linux_raw/system/types.rs | 39 |
3 files changed, 132 insertions, 0 deletions
diff --git a/vendor/rustix/src/backend/linux_raw/system/mod.rs b/vendor/rustix/src/backend/linux_raw/system/mod.rs new file mode 100644 index 00000000..1e0181a9 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/system/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod syscalls; +pub(crate) mod types; diff --git a/vendor/rustix/src/backend/linux_raw/system/syscalls.rs b/vendor/rustix/src/backend/linux_raw/system/syscalls.rs new file mode 100644 index 00000000..bbee2680 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/system/syscalls.rs @@ -0,0 +1,91 @@ +//! linux_raw syscalls supporting `rustix::system`. +//! +//! # Safety +//! +//! See the `rustix::backend` module documentation for details. +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] + +use super::types::RawUname; +use crate::backend::c; +use crate::backend::conv::{c_int, ret, ret_infallible, slice}; +use crate::fd::BorrowedFd; +use crate::ffi::CStr; +use crate::io; +use crate::system::{RebootCommand, Sysinfo}; +use core::mem::MaybeUninit; + +#[inline] +pub(crate) fn uname() -> RawUname { + let mut uname = MaybeUninit::<RawUname>::uninit(); + unsafe { + ret_infallible(syscall!(__NR_uname, &mut uname)); + uname.assume_init() + } +} + +#[inline] +pub(crate) fn sysinfo() -> Sysinfo { + let mut info = MaybeUninit::<Sysinfo>::uninit(); + unsafe { + ret_infallible(syscall!(__NR_sysinfo, &mut info)); + info.assume_init() + } +} + +#[inline] +pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { + let (ptr, len) = slice(name); + unsafe { ret(syscall_readonly!(__NR_sethostname, ptr, len)) } +} + +#[inline] +pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> { + let (ptr, len) = slice(name); + unsafe { ret(syscall_readonly!(__NR_setdomainname, ptr, len)) } +} + +#[inline] +pub(crate) fn reboot(cmd: RebootCommand) -> io::Result<()> { + unsafe { + ret(syscall_readonly!( + __NR_reboot, + c_int(c::LINUX_REBOOT_MAGIC1), + c_int(c::LINUX_REBOOT_MAGIC2), + c_int(cmd as i32) + )) + } +} + +#[inline] +pub(crate) fn init_module(image: &[u8], param_values: &CStr) -> io::Result<()> { + let (image, len) = slice(image); + unsafe { + ret(syscall_readonly!( + __NR_init_module, + image, + len, + param_values + )) + } +} + +#[inline] +pub(crate) fn finit_module( + fd: BorrowedFd<'_>, + param_values: &CStr, + flags: c::c_int, +) -> io::Result<()> { + unsafe { + ret(syscall_readonly!( + __NR_finit_module, + fd, + param_values, + c_int(flags) + )) + } +} + +#[inline] +pub(crate) fn delete_module(name: &CStr, flags: c::c_int) -> io::Result<()> { + unsafe { ret(syscall_readonly!(__NR_delete_module, name, c_int(flags))) } +} diff --git a/vendor/rustix/src/backend/linux_raw/system/types.rs b/vendor/rustix/src/backend/linux_raw/system/types.rs new file mode 100644 index 00000000..92cc5278 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/system/types.rs @@ -0,0 +1,39 @@ +use crate::ffi; +use core::mem::size_of; + +/// `sysinfo` +#[non_exhaustive] +#[repr(C)] +pub struct Sysinfo { + /// Seconds since boot + pub uptime: ffi::c_long, + /// 1, 5, and 15 minute load averages + pub loads: [ffi::c_ulong; 3], + /// Total usable main memory size + pub totalram: ffi::c_ulong, + /// Available memory size + pub freeram: ffi::c_ulong, + /// Amount of shared memory + pub sharedram: ffi::c_ulong, + /// Memory used by buffers + pub bufferram: ffi::c_ulong, + /// Total swap space size + pub totalswap: ffi::c_ulong, + /// Swap space still available + pub freeswap: ffi::c_ulong, + /// Number of current processes + pub procs: ffi::c_ushort, + + pub(crate) pad: ffi::c_ushort, + + /// Total high memory size + pub totalhigh: ffi::c_ulong, + /// Available high memory size + pub freehigh: ffi::c_ulong, + /// Memory unit size in bytes + pub mem_unit: ffi::c_uint, + + pub(crate) f: [u8; 20 - 2 * size_of::<ffi::c_long>() - size_of::<ffi::c_int>()], +} + +pub(crate) type RawUname = linux_raw_sys::system::new_utsname; |
