diff options
Diffstat (limited to 'vendor/rustix/src/thread')
-rw-r--r-- | vendor/rustix/src/thread/clock.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/thread/id.rs | 3 | ||||
-rw-r--r-- | vendor/rustix/src/thread/libcap.rs | 39 | ||||
-rw-r--r-- | vendor/rustix/src/thread/mod.rs | 16 | ||||
-rw-r--r-- | vendor/rustix/src/thread/prctl.rs | 22 | ||||
-rw-r--r-- | vendor/rustix/src/thread/setns.rs | 4 |
6 files changed, 46 insertions, 42 deletions
diff --git a/vendor/rustix/src/thread/clock.rs b/vendor/rustix/src/thread/clock.rs index 620cb4ec0..7a8c11968 100644 --- a/vendor/rustix/src/thread/clock.rs +++ b/vendor/rustix/src/thread/clock.rs @@ -1,6 +1,6 @@ use crate::{backend, io}; -pub use backend::time::types::Timespec; +pub use crate::timespec::Timespec; #[cfg(not(any( apple, @@ -11,7 +11,7 @@ pub use backend::time::types::Timespec; target_os = "redox", target_os = "wasi", )))] -pub use backend::time::types::ClockId; +pub use crate::clockid::ClockId; /// `clock_nanosleep(id, 0, request, remain)`—Sleeps for a duration on a /// given clock. diff --git a/vendor/rustix/src/thread/id.rs b/vendor/rustix/src/thread/id.rs index 3143b068b..6e193c366 100644 --- a/vendor/rustix/src/thread/id.rs +++ b/vendor/rustix/src/thread/id.rs @@ -1,4 +1,5 @@ -use crate::process::{Gid, Pid, Uid}; +use crate::pid::Pid; +use crate::ugid::{Gid, Uid}; use crate::{backend, io}; /// `gettid()`—Returns the thread ID. diff --git a/vendor/rustix/src/thread/libcap.rs b/vendor/rustix/src/thread/libcap.rs index f4798b8f4..8d2368720 100644 --- a/vendor/rustix/src/thread/libcap.rs +++ b/vendor/rustix/src/thread/libcap.rs @@ -1,7 +1,7 @@ use bitflags::bitflags; use core::mem::MaybeUninit; -use crate::process::Pid; +use crate::pid::Pid; use crate::{backend, io}; /// `__user_cap_data_struct` @@ -17,6 +17,8 @@ pub struct CapabilitySets { bitflags! { /// `CAP_*` constants. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct CapabilityFlags: u64 { /// `CAP_CHOWN` const CHOWN = 1 << linux_raw_sys::general::CAP_CHOWN; @@ -140,32 +142,25 @@ fn capget(pid: Option<Pid>) -> io::Result<CapabilitySets> { }; backend::thread::syscalls::capget(&mut header, &mut data)?; - // SAFETY: v3 is a 64-bit implementation, so the kernel filled in both data - // structs. + // SAFETY: v3 is a 64-bit implementation, so the kernel filled in both + // data structs. unsafe { (data[0].assume_init(), data[1].assume_init()) } }; - { - // TODO: With Rust 1.53, we can use u32::BITS in the shifts. - const BITS: u32 = 32; - let effective = u64::from(data.0.effective) | (u64::from(data.1.effective) << BITS); - let permitted = u64::from(data.0.permitted) | (u64::from(data.1.permitted) << BITS); - let inheritable = u64::from(data.0.inheritable) | (u64::from(data.1.inheritable) << BITS); + let effective = u64::from(data.0.effective) | (u64::from(data.1.effective) << u32::BITS); + let permitted = u64::from(data.0.permitted) | (u64::from(data.1.permitted) << u32::BITS); + let inheritable = u64::from(data.0.inheritable) | (u64::from(data.1.inheritable) << u32::BITS); - // SAFETY: the kernel returns a partitioned bitset that we just combined above - Ok(CapabilitySets { - effective: unsafe { CapabilityFlags::from_bits_unchecked(effective) }, - permitted: unsafe { CapabilityFlags::from_bits_unchecked(permitted) }, - inheritable: unsafe { CapabilityFlags::from_bits_unchecked(inheritable) }, - }) - } + // The kernel returns a partitioned bitset that we just combined above. + Ok(CapabilitySets { + effective: CapabilityFlags::from_bits_retain(effective), + permitted: CapabilityFlags::from_bits_retain(permitted), + inheritable: CapabilityFlags::from_bits_retain(inheritable), + }) } #[inline] fn capset(pid: Option<Pid>, sets: CapabilitySets) -> io::Result<()> { - // TODO: With Rust 1.53, we can use u32::BITS in the shifts. - const BITS: u32 = 32; - let mut header = linux_raw_sys::general::__user_cap_header_struct { version: linux_raw_sys::general::_LINUX_CAPABILITY_VERSION_3, pid: Pid::as_raw(pid) as backend::c::c_int, @@ -177,9 +172,9 @@ fn capset(pid: Option<Pid>, sets: CapabilitySets) -> io::Result<()> { inheritable: sets.inheritable.bits() as u32, }, linux_raw_sys::general::__user_cap_data_struct { - effective: (sets.effective.bits() >> BITS) as u32, - permitted: (sets.permitted.bits() >> BITS) as u32, - inheritable: (sets.inheritable.bits() >> BITS) as u32, + effective: (sets.effective.bits() >> u32::BITS) as u32, + permitted: (sets.permitted.bits() >> u32::BITS) as u32, + inheritable: (sets.inheritable.bits() >> u32::BITS) as u32, }, ]; diff --git a/vendor/rustix/src/thread/mod.rs b/vendor/rustix/src/thread/mod.rs index 86f231bcb..fa4897025 100644 --- a/vendor/rustix/src/thread/mod.rs +++ b/vendor/rustix/src/thread/mod.rs @@ -4,24 +4,24 @@ mod clock; #[cfg(linux_raw)] mod futex; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod id; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod libcap; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod prctl; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod setns; #[cfg(not(target_os = "redox"))] pub use clock::*; #[cfg(linux_raw)] pub use futex::{futex, FutexFlags, FutexOperation}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use id::{gettid, set_thread_gid, set_thread_res_gid, set_thread_res_uid, set_thread_uid}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySets}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use prctl::*; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use setns::*; diff --git a/vendor/rustix/src/thread/prctl.rs b/vendor/rustix/src/thread/prctl.rs index 2e11ff247..a9f411640 100644 --- a/vendor/rustix/src/thread/prctl.rs +++ b/vendor/rustix/src/thread/prctl.rs @@ -9,7 +9,6 @@ //! correctly. #![allow(unsafe_code)] -use core::convert::TryFrom; use core::mem::MaybeUninit; use core::num::NonZeroU64; use core::ptr; @@ -19,13 +18,14 @@ use core::sync::atomic::AtomicU8; use bitflags::bitflags; use crate::backend::c::{c_int, c_uint, c_void}; -use crate::backend::process::syscalls; +use crate::backend::prctl::syscalls; use crate::ffi::{CStr, CString}; use crate::io; -use crate::process::{ - prctl_1arg, prctl_2args, prctl_3args, prctl_get_at_arg2_optional, Pid, - PointerAuthenticationKeys, +use crate::pid::Pid; +use crate::prctl::{ + prctl_1arg, prctl_2args, prctl_3args, prctl_get_at_arg2_optional, PointerAuthenticationKeys, }; +use crate::utils::as_ptr; // // PR_GET_KEEPCAPS/PR_SET_KEEPCAPS @@ -54,7 +54,7 @@ const PR_SET_KEEPCAPS: c_int = 8; /// [`prctl(PR_SET_KEEPCAPS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] pub fn set_keep_capabilities(enable: bool) -> io::Result<()> { - unsafe { prctl_2args(PR_SET_KEEPCAPS, enable as usize as *mut _) }.map(|_r| ()) + unsafe { prctl_2args(PR_SET_KEEPCAPS, usize::from(enable) as *mut _) }.map(|_r| ()) } // @@ -411,6 +411,8 @@ const PR_GET_SECUREBITS: c_int = 27; bitflags! { /// `SECBIT_*`. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct CapabilitiesSecureBits: u32 { /// If this bit is set, then the kernel does not grant capabilities when /// a `set-user-ID-root` program is executed, or when a process with an effective or real @@ -520,7 +522,7 @@ const PR_SET_NO_NEW_PRIVS: c_int = 38; /// [`prctl(PR_SET_NO_NEW_PRIVS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] pub fn set_no_new_privs(no_new_privs: bool) -> io::Result<()> { - unsafe { prctl_2args(PR_SET_NO_NEW_PRIVS, no_new_privs as usize as *mut _) }.map(|_r| ()) + unsafe { prctl_2args(PR_SET_NO_NEW_PRIVS, usize::from(no_new_privs) as *mut _) }.map(|_r| ()) } // @@ -568,7 +570,7 @@ const PR_SET_THP_DISABLE: c_int = 41; /// [`prctl(PR_SET_THP_DISABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html #[inline] pub fn disable_transparent_huge_pages(thp_disable: bool) -> io::Result<()> { - unsafe { prctl_2args(PR_SET_THP_DISABLE, thp_disable as usize as *mut _) }.map(|_r| ()) + unsafe { prctl_2args(PR_SET_THP_DISABLE, usize::from(thp_disable) as *mut _) }.map(|_r| ()) } // @@ -732,6 +734,8 @@ const PR_MTE_TAG_MASK: u32 = 0xffff_u32 << PR_MTE_TAG_SHIFT; bitflags! { /// Zero means addresses that are passed for the purpose of being dereferenced by the kernel must be untagged. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct TaggedAddressMode: u32 { /// Addresses that are passed for the purpose of being dereferenced by the kernel may be tagged. const ENABLED = 1_u32 << 0; @@ -854,7 +858,7 @@ pub unsafe fn enable_syscall_user_dispatch( PR_SYS_DISPATCH_ON as *mut _, always_allowed_region.as_ptr() as *mut _, always_allowed_region.len() as *mut _, - fast_switch_flag as *const AtomicU8 as *mut _, + as_ptr(fast_switch_flag) as *mut _, ) .map(|_r| ()) } diff --git a/vendor/rustix/src/thread/setns.rs b/vendor/rustix/src/thread/setns.rs index 81c9225e3..2669cc7a7 100644 --- a/vendor/rustix/src/thread/setns.rs +++ b/vendor/rustix/src/thread/setns.rs @@ -11,6 +11,8 @@ use crate::io; bitflags! { /// Thread name space type. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct ThreadNameSpaceType: u32 { /// Time name space. const TIME = CLONE_NEWTIME; @@ -55,6 +57,8 @@ pub enum LinkNameSpaceType { bitflags! { /// `CLONE_*` for use with [`unshare`]. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UnshareFlags: u32 { /// `CLONE_FILES`. const FILES = CLONE_FILES; |