Skip to content

Commit

Permalink
split futex into individual functions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielschemmel committed Jul 26, 2024
1 parent 011fb50 commit 89dac89
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 28 deletions.
24 changes: 13 additions & 11 deletions src/backend/libc/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use crate::thread::{NanosleepRelativeResult, Timespec};
#[cfg(all(target_env = "gnu", fix_y2038))]
use crate::timespec::LibcTimespec;
use core::mem::MaybeUninit;
use core::sync::atomic::AtomicU32;
#[cfg(linux_kernel)]
use {
super::futex::FutexOperation,
crate::backend::conv::{borrowed_fd, ret_c_int, ret_usize},
crate::fd::BorrowedFd,
crate::pid::Pid,
crate::thread::{FutexFlags, FutexOperation},
crate::thread::FutexFlags,
crate::utils::as_mut_ptr,
};
#[cfg(not(any(
Expand Down Expand Up @@ -418,12 +420,12 @@ pub(crate) fn setresgid_thread(
// TODO: This could be de-multiplexed.
#[cfg(linux_kernel)]
pub(crate) unsafe fn futex(
uaddr: *mut u32,
uaddr: *const AtomicU32,
op: FutexOperation,
flags: FutexFlags,
val: u32,
utime: *const Timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32,
) -> io::Result<usize> {
#[cfg(all(
Expand All @@ -437,11 +439,11 @@ pub(crate) unsafe fn futex(

syscall! {
fn futex_time64(
uaddr: *mut u32,
uaddr: *const AtomicU32,
futex_op: c::c_int,
val: u32,
timeout: *const Timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32
) via SYS_futex_time64 -> c::ssize_t
}
Expand Down Expand Up @@ -473,11 +475,11 @@ pub(crate) unsafe fn futex(
{
syscall! {
fn futex(
uaddr: *mut u32,
uaddr: *const AtomicU32,
futex_op: c::c_int,
val: u32,
timeout: *const linux_raw_sys::general::__kernel_timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32
) via SYS_futex -> c::c_long
}
Expand All @@ -499,21 +501,21 @@ pub(crate) unsafe fn futex(
not(any(target_arch = "aarch64", target_arch = "x86_64"))
))]
unsafe fn futex_old(
uaddr: *mut u32,
uaddr: *const AtomicU32,
op: FutexOperation,
flags: FutexFlags,
val: u32,
utime: *const Timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32,
) -> io::Result<usize> {
syscall! {
fn futex(
uaddr: *mut u32,
uaddr: *const AtomicU32,
futex_op: c::c_int,
val: u32,
timeout: *const linux_raw_sys::general::__kernel_old_timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32
) via SYS_futex -> c::c_long
}
Expand Down
14 changes: 11 additions & 3 deletions src/backend/linux_raw/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,19 @@ impl<'a, Num: ArgNumber> From<(crate::net::SocketType, crate::net::SocketFlags)>
}

#[cfg(feature = "thread")]
impl<'a, Num: ArgNumber> From<(crate::thread::FutexOperation, crate::thread::FutexFlags)>
for ArgReg<'a, Num>
impl<'a, Num: ArgNumber>
From<(
crate::backend::thread::futex::FutexOperation,
crate::thread::FutexFlags,
)> for ArgReg<'a, Num>
{
#[inline]
fn from(pair: (crate::thread::FutexOperation, crate::thread::FutexFlags)) -> Self {
fn from(
pair: (
crate::backend::thread::futex::FutexOperation,
crate::thread::FutexFlags,
),
) -> Self {
c_uint(pair.0 as u32 | pair.1.bits())
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/backend/linux_raw/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]

use super::futex::FutexOperation;
use crate::backend::c;
use crate::backend::conv::{
by_mut, by_ref, c_int, c_uint, ret, ret_c_int, ret_c_int_infallible, ret_usize, slice,
Expand All @@ -13,8 +14,9 @@ use crate::backend::conv::{
use crate::fd::BorrowedFd;
use crate::io;
use crate::pid::Pid;
use crate::thread::{ClockId, FutexFlags, FutexOperation, NanosleepRelativeResult, Timespec};
use crate::thread::{ClockId, FutexFlags, NanosleepRelativeResult, Timespec};
use core::mem::MaybeUninit;
use core::sync::atomic::AtomicU32;
#[cfg(target_pointer_width = "32")]
use linux_raw_sys::general::timespec as __kernel_old_timespec;
use linux_raw_sys::general::{__kernel_timespec, TIMER_ABSTIME};
Expand Down Expand Up @@ -206,12 +208,12 @@ pub(crate) fn gettid() -> Pid {
// TODO: This could be de-multiplexed.
#[inline]
pub(crate) unsafe fn futex(
uaddr: *mut u32,
uaddr: *const AtomicU32,
op: FutexOperation,
flags: FutexFlags,
val: u32,
utime: *const Timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32,
) -> io::Result<usize> {
#[cfg(target_pointer_width = "32")]
Expand Down Expand Up @@ -249,12 +251,12 @@ pub(crate) unsafe fn futex(

#[cfg(target_pointer_width = "32")]
unsafe fn futex_old(
uaddr: *mut u32,
uaddr: *const AtomicU32,
op: FutexOperation,
flags: FutexFlags,
val: u32,
utime: *const Timespec,
uaddr2: *mut u32,
uaddr2: *const AtomicU32,
val3: u32,
) -> io::Result<usize> {
let old_utime = __kernel_old_timespec {
Expand Down
Loading

0 comments on commit 89dac89

Please sign in to comment.