diff --git a/src/io_uring/bindgen_types.rs b/src/io_uring/bindgen_types.rs new file mode 100644 index 000000000..11f5f01ac --- /dev/null +++ b/src/io_uring/bindgen_types.rs @@ -0,0 +1,99 @@ +//! Local versions of types that bindgen would use. + +/// This represents an incomplete array field at the end of a struct. +/// +/// This is called `__IncompleteArrayField` in bindgen bindings. +#[repr(C)] +#[derive(Default)] +pub struct IncompleteArrayField(::core::marker::PhantomData, [T; 0]); + +#[allow(missing_docs)] +impl IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + IncompleteArrayField(::core::marker::PhantomData, []) + } + + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} + +impl ::core::fmt::Debug for IncompleteArrayField { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("IncompleteArrayField") + } +} + +/// This represents a toplevel union field. +/// +/// This is called `__BindgenUnionField` in bindgen bindings. +pub struct UnionField(::core::marker::PhantomData); + +#[allow(missing_docs)] +impl UnionField { + #[inline] + pub const fn new() -> Self { + UnionField(::core::marker::PhantomData) + } + + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} + +impl ::core::default::Default for UnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} + +impl ::core::clone::Clone for UnionField { + #[inline] + fn clone(&self) -> Self { + *self + } +} + +impl ::core::marker::Copy for UnionField {} + +impl ::core::fmt::Debug for UnionField { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("UnionField") + } +} + +impl ::core::hash::Hash for UnionField { + fn hash(&self, _state: &mut H) {} +} + +impl ::core::cmp::PartialEq for UnionField { + fn eq(&self, _other: &UnionField) -> bool { + true + } +} + +impl ::core::cmp::Eq for UnionField {} diff --git a/src/io_uring.rs b/src/io_uring/mod.rs similarity index 99% rename from src/io_uring.rs rename to src/io_uring/mod.rs index f888a90c9..d64c92add 100644 --- a/src/io_uring.rs +++ b/src/io_uring/mod.rs @@ -24,8 +24,11 @@ //! [rustix-uring]: https://crates.io/crates/rustix-uring #![allow(unsafe_code)] +mod bindgen_types; + use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; use crate::{backend, io}; +use bindgen_types::*; use core::ffi::c_void; use core::mem::MaybeUninit; use core::ptr::{null_mut, write_bytes}; @@ -1210,7 +1213,7 @@ pub struct io_uring_cqe { pub user_data: io_uring_user_data, pub res: i32, pub flags: IoringCqeFlags, - pub big_cqe: sys::__IncompleteArrayField, + pub big_cqe: IncompleteArrayField, } #[allow(missing_docs)] @@ -1286,7 +1289,7 @@ pub struct io_uring_probe { pub ops_len: u8, pub resv: u16, pub resv2: [u32; 3], - pub ops: sys::__IncompleteArrayField, + pub ops: IncompleteArrayField, } #[allow(missing_docs)] @@ -1416,15 +1419,15 @@ pub struct buf_ring_tail_struct { #[repr(C)] #[derive(Debug, Default)] pub struct buf_ring_bufs_struct { - pub bufs: sys::__IncompleteArrayField, + pub bufs: IncompleteArrayField, } #[allow(missing_docs)] #[repr(C)] #[derive(Debug, Default)] pub struct tail_or_bufs_struct { - pub tail: sys::__BindgenUnionField, - pub bufs: sys::__BindgenUnionField, + pub tail: UnionField, + pub bufs: UnionField, pub union_field: [u64; 2], }