Skip to content

Commit fdb524e

Browse files
authored
Use io_uring_ptr for pointers in io_uring_getevents_arg. (#1338)
* Use `io_uring_ptr` for pointers in `io_uring_getevents_arg`. io_uring represents pointers as `u64`. Rustix uses an `io_uring_ptr` struct which is layout-compatible with `u64` but preserves pointer provenance. * Align io_uring_ptr to 8 on arm. * Add a testcase for io_uring_ptr.
1 parent de5dd39 commit fdb524e

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,14 @@ advice applies to the end of the file. To convert an arbitrary `u64` value to
230230

231231
[`rustix::fs::fadvise`]: https://docs.rs/rustix/1.0.0/rustix/fs/fn.fadvise.html
232232

233+
The [`sigmask`] and [`ts`] fields of [`rustix::io_uring::getevents_arg`]
234+
changed from `u64` to [`rustix::io_uring::io_uring_ptr`], to better preserve
235+
pointer provenance.
236+
237+
[`sigmask`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html#structfield.sigmask
238+
[`ts`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html#structfield.ts
239+
[`rustix::io_uring::getevents_arg`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html
240+
[`rustix::io_uring::io_uring_ptr`]: https://docs.rs/rustix/1.0.0-prerelease.0/rustix/io_uring/struct.io_uring_ptr.html
241+
233242
All explicitly deprecated functions and types have been removed. Their
234243
deprecation messages will have identified alternatives.

src/io_uring/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ pub const IORING_NOTIF_USAGE_ZC_COPIED: i32 = sys::IORING_NOTIF_USAGE_ZC_COPIED
959959
/// preserve strict-provenance, use a `*mut c_void`. On platforms where
960960
/// pointers are narrower than 64 bits, this requires additional padding.
961961
#[repr(C)]
962+
#[cfg_attr(target_arch = "arm", repr(align(8)))]
962963
#[derive(Copy, Clone)]
963964
#[non_exhaustive]
964965
pub struct io_uring_ptr {
@@ -1395,10 +1396,10 @@ pub struct io_uring_rsrc_update2 {
13951396
#[repr(C)]
13961397
#[derive(Debug, Copy, Clone, Default)]
13971398
pub struct io_uring_getevents_arg {
1398-
pub sigmask: u64,
1399+
pub sigmask: io_uring_ptr,
13991400
pub sigmask_sz: u32,
14001401
pub min_wait_usec: u32,
1401-
pub ts: u64,
1402+
pub ts: io_uring_ptr,
14021403
}
14031404

14041405
#[allow(missing_docs)]
@@ -1559,7 +1560,23 @@ mod tests {
15591560
fn io_uring_layouts() {
15601561
use sys as c;
15611562

1563+
// `io_uring_ptr` is a replacement for `u64`.
15621564
assert_eq_size!(io_uring_ptr, u64);
1565+
assert_eq_align!(io_uring_ptr, u64);
1566+
1567+
// Test that pointers are stored in io_uring_ptr` in the way that
1568+
// io_uring stores them in a `u64`.
1569+
unsafe {
1570+
const MAGIC: u64 = !0x0123456789abcdef;
1571+
let ptr = io_uring_ptr::from(MAGIC as usize as *mut c_void);
1572+
assert_eq!(ptr.ptr, MAGIC as usize as *mut c_void);
1573+
#[cfg(target_pointer_width = "16")]
1574+
assert_eq!(ptr.__pad16, 0);
1575+
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
1576+
assert_eq!(ptr.__pad32, 0);
1577+
let int = core::mem::transmute::<io_uring_ptr, u64>(ptr);
1578+
assert_eq!(int, MAGIC as usize as u64);
1579+
}
15631580

15641581
check_renamed_type!(off_or_addr2_union, io_uring_sqe__bindgen_ty_1);
15651582
check_renamed_type!(addr_or_splice_off_in_union, io_uring_sqe__bindgen_ty_2);

0 commit comments

Comments
 (0)