@@ -16,9 +16,9 @@ use crate::pid::Pid;
1616use crate :: thread:: { futex, ClockId , NanosleepRelativeResult , Timespec } ;
1717use core:: mem:: MaybeUninit ;
1818use core:: sync:: atomic:: AtomicU32 ;
19- #[ cfg( target_pointer_width = "32" ) ]
20- use linux_raw_sys:: general:: timespec as __kernel_old_timespec;
2119use linux_raw_sys:: general:: { __kernel_timespec, TIMER_ABSTIME } ;
20+ #[ cfg( target_pointer_width = "32" ) ]
21+ use { crate :: utils:: option_as_ptr, linux_raw_sys:: general:: timespec as __kernel_old_timespec} ;
2222
2323#[ inline]
2424pub ( crate ) fn clock_nanosleep_relative (
@@ -204,6 +204,9 @@ pub(crate) fn gettid() -> Pid {
204204 }
205205}
206206
207+ /// # Safety
208+ ///
209+ /// The raw pointers must point to valid aligned memory.
207210#[ inline]
208211pub ( crate ) unsafe fn futex_val2 (
209212 uaddr : * const AtomicU32 ,
@@ -214,9 +217,12 @@ pub(crate) unsafe fn futex_val2(
214217 uaddr2 : * const AtomicU32 ,
215218 val3 : u32 ,
216219) -> io:: Result < usize > {
217- // The least-significant four bytes of the timeout pointer are used as `val2`.
218- // ["the kernel casts the timeout value first to unsigned long, then to uint32_t"](https://man7.org/linux/man-pages/man2/futex.2.html),
219- // so we perform that exact conversion in reverse to create the pointer.
220+ // Pass `val2` in the least-significant bytes of the `timeout` argument.
221+ // [“the kernel casts the timeout value first to unsigned long, then to
222+ // uint32_t”], so we perform that exact conversion in reverse to create
223+ // the pointer.
224+ //
225+ // [“the kernel casts the timeout value first to unsigned long, then to uint32_t”]: https://man7.org/linux/man-pages/man2/futex.2.html
220226 let timeout = val2 as usize as * const Timespec ;
221227
222228 #[ cfg( target_pointer_width = "32" ) ]
@@ -243,6 +249,9 @@ pub(crate) unsafe fn futex_val2(
243249 ) )
244250}
245251
252+ /// # Safety
253+ ///
254+ /// The raw pointers must point to valid aligned memory.
246255#[ inline]
247256pub ( crate ) unsafe fn futex_timeout (
248257 uaddr : * const AtomicU32 ,
@@ -286,6 +295,9 @@ pub(crate) unsafe fn futex_timeout(
286295 ) )
287296}
288297
298+ /// # Safety
299+ ///
300+ /// The raw pointers must point to valid aligned memory.
289301#[ cfg( target_pointer_width = "32" ) ]
290302unsafe fn futex_old_timespec (
291303 uaddr : * const AtomicU32 ,
@@ -312,10 +324,7 @@ unsafe fn futex_old_timespec(
312324 uaddr,
313325 ( op, flags) ,
314326 c_uint( val) ,
315- old_timeout
316- . as_ref( )
317- . map( |timeout| timeout as * const __kernel_old_timespec)
318- . unwrap_or( core:: ptr:: null( ) ) ,
327+ option_as_ptr( old_timeout. as_ref( ) ) ,
319328 uaddr2,
320329 c_uint( val3)
321330 ) )
0 commit comments