1 | //! linux_raw syscalls supporting `rustix::system`. |
2 | //! |
3 | //! # Safety |
4 | //! |
5 | //! See the `rustix::backend` module documentation for details. |
6 | #![allow (unsafe_code, clippy::undocumented_unsafe_blocks)] |
7 | |
8 | use super::types::RawUname; |
9 | use crate::backend::c; |
10 | use crate::backend::conv::{c_int, ret, ret_infallible, slice}; |
11 | #[cfg (any(target_os = "linux" , target_os = "android" ))] |
12 | use crate::fd::BorrowedFd; |
13 | use crate::ffi::CStr; |
14 | use crate::io; |
15 | use crate::system::{RebootCommand, Sysinfo}; |
16 | use core::mem::MaybeUninit; |
17 | |
18 | #[inline ] |
19 | pub(crate) fn uname() -> RawUname { |
20 | let mut uname: MaybeUninit = MaybeUninit::<RawUname>::uninit(); |
21 | unsafe { |
22 | ret_infallible(raw:syscall!(__NR_uname, &mut uname)); |
23 | uname.assume_init() |
24 | } |
25 | } |
26 | |
27 | #[inline ] |
28 | pub(crate) fn sysinfo() -> Sysinfo { |
29 | let mut info: MaybeUninit = MaybeUninit::<Sysinfo>::uninit(); |
30 | unsafe { |
31 | ret_infallible(raw:syscall!(__NR_sysinfo, &mut info)); |
32 | info.assume_init() |
33 | } |
34 | } |
35 | |
36 | #[inline ] |
37 | pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { |
38 | let (ptr: ArgReg<'_, A0>, len: ArgReg<'_, A1>) = slice(name); |
39 | unsafe { ret(raw:syscall_readonly!(__NR_sethostname, ptr, len)) } |
40 | } |
41 | |
42 | #[inline ] |
43 | pub(crate) fn reboot(cmd: RebootCommand) -> io::Result<()> { |
44 | unsafe { |
45 | ret(raw:syscall_readonly!( |
46 | __NR_reboot, |
47 | c_int(c::LINUX_REBOOT_MAGIC1), |
48 | c_int(c::LINUX_REBOOT_MAGIC2), |
49 | c_int(cmd as i32) |
50 | )) |
51 | } |
52 | } |
53 | |
54 | #[inline ] |
55 | pub(crate) fn init_module(image: &[u8], param_values: &CStr) -> io::Result<()> { |
56 | let (image: ArgReg<'_, A0>, len: ArgReg<'_, A1>) = slice(image); |
57 | unsafe { |
58 | ret(raw:syscall_readonly!( |
59 | __NR_init_module, |
60 | image, |
61 | len, |
62 | param_values |
63 | )) |
64 | } |
65 | } |
66 | |
67 | #[inline ] |
68 | pub(crate) fn finit_module( |
69 | fd: BorrowedFd<'_>, |
70 | param_values: &CStr, |
71 | flags: c::c_int, |
72 | ) -> io::Result<()> { |
73 | unsafe { |
74 | ret(raw:syscall_readonly!( |
75 | __NR_finit_module, |
76 | fd, |
77 | param_values, |
78 | c_int(flags) |
79 | )) |
80 | } |
81 | } |
82 | |
83 | #[inline ] |
84 | pub(crate) fn delete_module(name: &CStr, flags: c::c_int) -> io::Result<()> { |
85 | unsafe { ret(raw:syscall_readonly!(__NR_delete_module, name, c_int(flags))) } |
86 | } |
87 | |