mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 22:08:26 +02:00
This contains downstream patches for Rustix, from: https://github.com/bytecodealliance/rustix/pull/1577 I think the people are cool with the changes generally, but we're essentially running into https://xkcd.com/2347/ right now and the maintainer doesn't have time to even look at it. To ease in the development of mesa3d_util, it's better to keep 3 downstream patches here, than potentially diverging mesa3d_util for actual consumers. Reviewed-by: LingMan Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41321>
253 lines
8.2 KiB
Diff
253 lines
8.2 KiB
Diff
From 680162aec19d93309123aeb9a983d361bdeeb38f Mon Sep 17 00:00:00 2001
|
|
From: Gurchetan Singh <gurchetan.singh.foss@gmail.com>
|
|
Date: Fri, 30 Jan 2026 07:41:51 -0800
|
|
Subject: [PATCH 3/4] rustix: enable rustix::thread::futex without
|
|
linux-raw-sys
|
|
|
|
It's desirable to enable futex for some cases that will be
|
|
run on Android. The strategy is just to define the constants
|
|
needed by the libc ourselves, if libc doesn't provide the
|
|
necessary constant. Long-term, that could make the libc
|
|
backend only depend on libc.
|
|
---
|
|
src/backend/libc/c.rs | 10 +++++++++
|
|
src/backend/libc/thread/futex.rs | 31 +++++++++++++++++-----------
|
|
src/backend/libc/thread/syscalls.rs | 32 +++++++++++++++++++++++++----
|
|
src/test_macro.rs | 3 +++
|
|
src/thread/mod.rs | 11 +++++-----
|
|
5 files changed, 66 insertions(+), 21 deletions(-)
|
|
create mode 100644 src/test_macro.rs
|
|
|
|
diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs
|
|
index 5eeff953..1a319a0f 100644
|
|
--- a/src/backend/libc/c.rs
|
|
+++ b/src/backend/libc/c.rs
|
|
@@ -515,6 +515,16 @@ pub(crate) use statx_flags::*;
|
|
#[cfg(target_os = "android")]
|
|
pub(crate) use __fsid_t as fsid_t;
|
|
|
|
+// Android's libc crate is missing some constants.
|
|
+// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
|
|
+// constants to libc.
|
|
+#[cfg(target_os = "android")]
|
|
+pub(crate) const CLONE_NEWTIME: c_int = 0x00000080;
|
|
+#[cfg(target_os = "android")]
|
|
+pub(crate) const FUTEX_WAITERS: u32 = 0x80000000;
|
|
+#[cfg(target_os = "android")]
|
|
+pub(crate) const FUTEX_OWNER_DIED: u32 = 0x40000000;
|
|
+
|
|
// FreeBSD added `timerfd_*` in FreeBSD 14. NetBSD added then in NetBSD 10.
|
|
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
|
|
syscall!(pub(crate) fn timerfd_create(
|
|
diff --git a/src/backend/libc/thread/futex.rs b/src/backend/libc/thread/futex.rs
|
|
index 5e836a9a..6d2e1495 100644
|
|
--- a/src/backend/libc/thread/futex.rs
|
|
+++ b/src/backend/libc/thread/futex.rs
|
|
@@ -17,6 +17,16 @@ bitflags::bitflags! {
|
|
}
|
|
}
|
|
|
|
+// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
|
|
+// constants to libc.
|
|
+const FUTEX2_SIZE_U8: u32 = 0;
|
|
+const FUTEX2_SIZE_U16: u32 = 1;
|
|
+const FUTEX2_SIZE_U32: u32 = 2;
|
|
+const FUTEX2_SIZE_U64: u32 = 3;
|
|
+const FUTEX2_SIZE_MASK: u32 = 3;
|
|
+const FUTEX2_NUMA: u32 = 4;
|
|
+const FUTEX2_PRIVATE: u32 = 128;
|
|
+
|
|
bitflags::bitflags! {
|
|
/// `FUTEX2_*` flags for use with the functions in [`Waitv`].
|
|
///
|
|
@@ -29,22 +39,19 @@ bitflags::bitflags! {
|
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
|
pub struct WaitFlags: u32 {
|
|
/// `FUTEX_U8`
|
|
- const SIZE_U8 = linux_raw_sys::general::FUTEX2_SIZE_U8;
|
|
+ const SIZE_U8 = FUTEX2_SIZE_U8;
|
|
/// `FUTEX_U16`
|
|
- const SIZE_U16 = linux_raw_sys::general::FUTEX2_SIZE_U16;
|
|
+ const SIZE_U16 = FUTEX2_SIZE_U16;
|
|
/// `FUTEX_U32`
|
|
- const SIZE_U32 = linux_raw_sys::general::FUTEX2_SIZE_U32;
|
|
+ const SIZE_U32 = FUTEX2_SIZE_U32;
|
|
/// `FUTEX_U64`
|
|
- const SIZE_U64 = linux_raw_sys::general::FUTEX2_SIZE_U64;
|
|
+ const SIZE_U64 = FUTEX2_SIZE_U64;
|
|
/// `FUTEX_SIZE_MASK`
|
|
- const SIZE_MASK = linux_raw_sys::general::FUTEX2_SIZE_MASK;
|
|
-
|
|
+ const SIZE_MASK = FUTEX2_SIZE_MASK;
|
|
/// `FUTEX2_NUMA`
|
|
- const NUMA = linux_raw_sys::general::FUTEX2_NUMA;
|
|
-
|
|
+ const NUMA = FUTEX2_NUMA;
|
|
/// `FUTEX2_PRIVATE`
|
|
- const PRIVATE = linux_raw_sys::general::FUTEX2_PRIVATE;
|
|
-
|
|
+ const PRIVATE = FUTEX2_PRIVATE;
|
|
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
|
|
const _ = !0;
|
|
}
|
|
@@ -85,7 +92,7 @@ pub(crate) enum Operation {
|
|
}
|
|
|
|
/// `FUTEX_WAITERS`
|
|
-pub const WAITERS: u32 = linux_raw_sys::general::FUTEX_WAITERS;
|
|
+pub const WAITERS: u32 = c::FUTEX_WAITERS;
|
|
|
|
/// `FUTEX_OWNER_DIED`
|
|
-pub const OWNER_DIED: u32 = linux_raw_sys::general::FUTEX_OWNER_DIED;
|
|
+pub const OWNER_DIED: u32 = c::FUTEX_OWNER_DIED;
|
|
diff --git a/src/backend/libc/thread/syscalls.rs b/src/backend/libc/thread/syscalls.rs
|
|
index 84356fee..5ea541fe 100644
|
|
--- a/src/backend/libc/thread/syscalls.rs
|
|
+++ b/src/backend/libc/thread/syscalls.rs
|
|
@@ -341,13 +341,13 @@ pub(crate) fn setns(fd: BorrowedFd<'_>, nstype: c::c_int) -> io::Result<c::c_int
|
|
unsafe { ret_c_int(setns(borrowed_fd(fd), nstype)) }
|
|
}
|
|
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
#[inline]
|
|
pub(crate) unsafe fn unshare(flags: crate::thread::UnshareFlags) -> io::Result<()> {
|
|
ret(c::unshare(flags.bits() as i32))
|
|
}
|
|
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
#[inline]
|
|
pub(crate) fn capget(
|
|
header: &mut linux_raw_sys::general::__user_cap_header_struct,
|
|
@@ -369,7 +369,7 @@ pub(crate) fn capget(
|
|
}
|
|
}
|
|
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
#[inline]
|
|
pub(crate) fn capset(
|
|
header: &mut linux_raw_sys::general::__user_cap_header_struct,
|
|
@@ -477,6 +477,7 @@ pub(crate) unsafe fn futex_val2(
|
|
let timeout = val2 as usize as *const Timespec;
|
|
|
|
#[cfg(all(
|
|
+ linux_raw_dep,
|
|
target_pointer_width = "32",
|
|
not(any(target_arch = "aarch64", target_arch = "x86_64"))
|
|
))]
|
|
@@ -506,6 +507,16 @@ pub(crate) unsafe fn futex_val2(
|
|
))
|
|
}
|
|
|
|
+ #[cfg(all(
|
|
+ not(linux_raw_dep),
|
|
+ target_pointer_width = "32",
|
|
+ not(any(target_arch = "aarch64", target_arch = "x86_64"))
|
|
+ ))]
|
|
+ {
|
|
+ let _ = (uaddr, op, flags, val, timeout, uaddr2, val3);
|
|
+ Err(io::Errno::NOSYS)
|
|
+ }
|
|
+
|
|
#[cfg(any(
|
|
target_pointer_width = "64",
|
|
target_arch = "aarch64",
|
|
@@ -548,6 +559,7 @@ pub(crate) unsafe fn futex_timeout(
|
|
val3: u32,
|
|
) -> io::Result<usize> {
|
|
#[cfg(all(
|
|
+ linux_raw_dep,
|
|
target_pointer_width = "32",
|
|
not(any(target_arch = "aarch64", target_arch = "x86_64"))
|
|
))]
|
|
@@ -585,6 +597,16 @@ pub(crate) unsafe fn futex_timeout(
|
|
})
|
|
}
|
|
|
|
+ #[cfg(all(
|
|
+ not(linux_raw_dep),
|
|
+ target_pointer_width = "32",
|
|
+ not(any(target_arch = "aarch64", target_arch = "x86_64"))
|
|
+ ))]
|
|
+ {
|
|
+ let _ = (uaddr, op, flags, val, timeout, uaddr2, val3);
|
|
+ Err(io::Errno::NOSYS)
|
|
+ }
|
|
+
|
|
#[cfg(any(
|
|
target_pointer_width = "64",
|
|
target_arch = "aarch64",
|
|
@@ -618,6 +640,7 @@ pub(crate) unsafe fn futex_timeout(
|
|
/// The raw pointers must point to valid aligned memory.
|
|
#[cfg(linux_kernel)]
|
|
#[cfg(all(
|
|
+ linux_raw_dep,
|
|
target_pointer_width = "32",
|
|
not(any(target_arch = "aarch64", target_arch = "x86_64"))
|
|
))]
|
|
@@ -666,8 +689,9 @@ pub(crate) fn futex_waitv(
|
|
timeout: Option<&Timespec>,
|
|
clockid: ClockId,
|
|
) -> io::Result<usize> {
|
|
+ use crate::backend::c::clockid_t;
|
|
use futex::Wait as FutexWait;
|
|
- use linux_raw_sys::general::__kernel_clockid_t as clockid_t;
|
|
+
|
|
syscall! {
|
|
fn futex_waitv(
|
|
waiters: *const FutexWait,
|
|
diff --git a/src/test_macro.rs b/src/test_macro.rs
|
|
new file mode 100644
|
|
index 00000000..f6a11a8f
|
|
--- /dev/null
|
|
+++ b/src/test_macro.rs
|
|
@@ -0,0 +1,3 @@
|
|
+use crate::ioctl_readwrite;
|
|
+
|
|
+fn main() {}
|
|
diff --git a/src/thread/mod.rs b/src/thread/mod.rs
|
|
index 26d1de42..b5e7e844 100644
|
|
--- a/src/thread/mod.rs
|
|
+++ b/src/thread/mod.rs
|
|
@@ -6,16 +6,16 @@ mod clock;
|
|
pub mod futex;
|
|
#[cfg(linux_kernel)]
|
|
mod id;
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
mod libcap;
|
|
#[cfg(linux_kernel)]
|
|
mod membarrier;
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
mod prctl;
|
|
#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
|
|
mod sched;
|
|
mod sched_yield;
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
mod setns;
|
|
|
|
#[cfg(not(target_os = "redox"))]
|
|
@@ -25,13 +25,14 @@ pub use id::*;
|
|
#[cfg(linux_kernel)]
|
|
// #[expect(deprecated, reason = "CapabilityFlags is deprecated")]
|
|
#[allow(deprecated)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySet, CapabilitySets};
|
|
#[cfg(linux_kernel)]
|
|
pub use membarrier::*;
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
pub use prctl::*;
|
|
#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
|
|
pub use sched::*;
|
|
pub use sched_yield::sched_yield;
|
|
-#[cfg(linux_kernel)]
|
|
+#[cfg(all(linux_kernel, linux_raw_dep))]
|
|
pub use setns::*;
|
|
--
|
|
2.54.0.545.g6539524ca2-goog
|
|
|