/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rustix-1.1.2/src/prctl.rs
Line | Count | Source |
1 | | //! Helper functions for `prctl` syscalls. |
2 | | |
3 | | #![allow(unsafe_code)] |
4 | | |
5 | | use crate::backend::prctl::syscalls; |
6 | | use crate::ffi::{c_int, c_void}; |
7 | | use crate::io; |
8 | | use crate::utils::as_mut_ptr; |
9 | | use bitflags::bitflags; |
10 | | use core::mem::MaybeUninit; |
11 | | use core::ptr::null_mut; |
12 | | |
13 | | #[cfg(linux_raw_dep)] |
14 | | bitflags! { |
15 | | /// `PR_PAC_AP*` |
16 | | #[repr(transparent)] |
17 | | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] |
18 | | pub struct PointerAuthenticationKeys: u32 { |
19 | | /// `PR_PAC_APIAKEY`—Instruction authentication key `A`. |
20 | | const INSTRUCTION_AUTHENTICATION_KEY_A = linux_raw_sys::prctl::PR_PAC_APIAKEY; |
21 | | /// `PR_PAC_APIBKEY`—Instruction authentication key `B`. |
22 | | const INSTRUCTION_AUTHENTICATION_KEY_B = linux_raw_sys::prctl::PR_PAC_APIBKEY; |
23 | | /// `PR_PAC_APDAKEY`—Data authentication key `A`. |
24 | | const DATA_AUTHENTICATION_KEY_A = linux_raw_sys::prctl::PR_PAC_APDAKEY; |
25 | | /// `PR_PAC_APDBKEY`—Data authentication key `B`. |
26 | | const DATA_AUTHENTICATION_KEY_B = linux_raw_sys::prctl::PR_PAC_APDBKEY; |
27 | | /// `PR_PAC_APGAKEY`—Generic authentication `A` key. |
28 | | const GENERIC_AUTHENTICATION_KEY_A = linux_raw_sys::prctl::PR_PAC_APGAKEY; |
29 | | |
30 | | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
31 | | const _ = !0; |
32 | | } |
33 | | } |
34 | | |
35 | | #[inline] |
36 | 0 | pub(crate) unsafe fn prctl_1arg(option: c_int) -> io::Result<c_int> { |
37 | | const NULL: *mut c_void = null_mut(); |
38 | 0 | syscalls::prctl(option, NULL, NULL, NULL, NULL) |
39 | 0 | } |
40 | | |
41 | | #[inline] |
42 | 0 | pub(crate) unsafe fn prctl_2args(option: c_int, arg2: *mut c_void) -> io::Result<c_int> { |
43 | | const NULL: *mut c_void = null_mut(); |
44 | 0 | syscalls::prctl(option, arg2, NULL, NULL, NULL) |
45 | 0 | } |
46 | | |
47 | | #[inline] |
48 | 0 | pub(crate) unsafe fn prctl_3args( |
49 | 0 | option: c_int, |
50 | 0 | arg2: *mut c_void, |
51 | 0 | arg3: *mut c_void, |
52 | 0 | ) -> io::Result<c_int> { |
53 | 0 | syscalls::prctl(option, arg2, arg3, null_mut(), null_mut()) |
54 | 0 | } |
55 | | |
56 | | #[inline] |
57 | 0 | pub(crate) unsafe fn prctl_get_at_arg2_optional<P>(option: i32) -> io::Result<P> { |
58 | 0 | let mut value: MaybeUninit<P> = MaybeUninit::uninit(); |
59 | 0 | prctl_2args(option, value.as_mut_ptr().cast())?; |
60 | 0 | Ok(value.assume_init()) |
61 | 0 | } |
62 | | |
63 | | #[inline] |
64 | 0 | pub(crate) unsafe fn prctl_get_at_arg2<P, T>(option: i32) -> io::Result<T> |
65 | 0 | where |
66 | 0 | P: Default, |
67 | 0 | T: TryFrom<P, Error = io::Errno>, |
68 | | { |
69 | 0 | let mut value: P = Default::default(); |
70 | 0 | prctl_2args(option, as_mut_ptr(&mut value).cast())?; |
71 | 0 | TryFrom::try_from(value) |
72 | 0 | } |