diff --git a/compio-driver/src/sys/fusion/op.rs b/compio-driver/src/sys/fusion/op.rs index 115efb367..4288e2f3e 100644 --- a/compio-driver/src/sys/fusion/op.rs +++ b/compio-driver/src/sys/fusion/op.rs @@ -77,7 +77,7 @@ macro_rules! op { } } - impl<$($ty: $trait),*> poll::OpCode for $name<$($ty),*> { + unsafe impl<$($ty: $trait),*> poll::OpCode for $name<$($ty),*> { fn pre_submit(self: std::pin::Pin<&mut Self>) -> std::io::Result { unsafe { self.map_unchecked_mut(|x| x.inner.poll() ) }.pre_submit() } @@ -93,7 +93,7 @@ macro_rules! op { } } - impl<$($ty: $trait),*> iour::OpCode for $name<$($ty),*> { + unsafe impl<$($ty: $trait),*> iour::OpCode for $name<$($ty),*> { fn create_entry(self: std::pin::Pin<&mut Self>) -> OpEntry { unsafe { self.map_unchecked_mut(|x| x.inner.iour() ) }.create_entry() } @@ -179,7 +179,7 @@ macro_rules! mop { } } - impl<$($ty: $trait),*> poll::OpCode for $name<$($ty),*> { + unsafe impl<$($ty: $trait),*> poll::OpCode for $name<$($ty),*> { fn pre_submit(self: std::pin::Pin<&mut Self>) -> std::io::Result { unsafe { self.map_unchecked_mut(|x| x.inner.poll() ) }.pre_submit() } @@ -195,7 +195,7 @@ macro_rules! mop { } } - impl<$($ty: $trait),*> iour::OpCode for $name<$($ty),*> { + unsafe impl<$($ty: $trait),*> iour::OpCode for $name<$($ty),*> { fn create_entry(self: std::pin::Pin<&mut Self>) -> OpEntry { unsafe { self.map_unchecked_mut(|x| x.inner.iour() ) }.create_entry() } diff --git a/compio-driver/src/sys/iocp/mod.rs b/compio-driver/src/sys/iocp/mod.rs index 205181f93..e055f3998 100644 --- a/compio-driver/src/sys/iocp/mod.rs +++ b/compio-driver/src/sys/iocp/mod.rs @@ -274,7 +274,12 @@ pub enum OpType { } /// Abstraction of IOCP operations. -pub trait OpCode { +/// +/// # Safety +/// +/// Implementors must ensure that the operation is safe to be polled +/// according to the returned [`OpType`]. +pub unsafe trait OpCode { /// Determines that the operation is really overlapped defined by Windows /// API. If not, the driver will try to operate it in another thread. fn op_type(&self) -> OpType { diff --git a/compio-driver/src/sys/iocp/op.rs b/compio-driver/src/sys/iocp/op.rs index 84a15aae8..80db5ed40 100644 --- a/compio-driver/src/sys/iocp/op.rs +++ b/compio-driver/src/sys/iocp/op.rs @@ -110,7 +110,7 @@ fn get_wsa_fn(handle: RawFd, fguid: GUID) -> io::Result> { Ok(fptr) } -impl< +unsafe impl< D: std::marker::Send + 'static, F: (FnOnce() -> BufResult) + std::marker::Send + 'static, > OpCode for Asyncify @@ -131,7 +131,7 @@ impl< } } -impl< +unsafe impl< S, D: std::marker::Send + 'static, F: (FnOnce(&S) -> BufResult) + std::marker::Send + 'static, @@ -154,7 +154,7 @@ impl< } } -impl OpCode for CloseFile { +unsafe impl OpCode for CloseFile { fn op_type(&self) -> OpType { OpType::Blocking } @@ -166,7 +166,7 @@ impl OpCode for CloseFile { } } -impl OpCode for ReadAt { +unsafe impl OpCode for ReadAt { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { if let Some(overlapped) = unsafe { optr.as_mut() } { overlapped.Anonymous.Anonymous.Offset = (self.offset & 0xFFFFFFFF) as _; @@ -192,7 +192,7 @@ impl OpCode for ReadAt { } } -impl OpCode for WriteAt { +unsafe impl OpCode for WriteAt { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { if let Some(overlapped) = unsafe { optr.as_mut() } { overlapped.Anonymous.Anonymous.Offset = (self.offset & 0xFFFFFFFF) as _; @@ -217,7 +217,7 @@ impl OpCode for WriteAt { } } -impl OpCode for ReadManagedAt { +unsafe impl OpCode for ReadManagedAt { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { unsafe { self.project().op.operate(optr) } } @@ -227,7 +227,7 @@ impl OpCode for ReadManagedAt { } } -impl OpCode for Read { +unsafe impl OpCode for Read { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let fd = self.fd.as_fd().as_raw_fd(); let slice = self.project().buffer.sys_slice_mut(); @@ -249,7 +249,7 @@ impl OpCode for Read { } } -impl OpCode for Write { +unsafe impl OpCode for Write { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let slice = self.buffer.as_init(); let mut transferred = 0; @@ -270,7 +270,7 @@ impl OpCode for Write { } } -impl OpCode for ReadManaged { +unsafe impl OpCode for ReadManaged { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { unsafe { self.project().op.operate(optr) } } @@ -280,7 +280,7 @@ impl OpCode for ReadManaged { } } -impl OpCode for Sync { +unsafe impl OpCode for Sync { fn op_type(&self) -> OpType { OpType::Blocking } @@ -292,7 +292,7 @@ impl OpCode for Sync { } } -impl OpCode for ShutdownSocket { +unsafe impl OpCode for ShutdownSocket { fn op_type(&self) -> OpType { OpType::Blocking } @@ -309,7 +309,7 @@ impl OpCode for ShutdownSocket { } } -impl OpCode for CloseSocket { +unsafe impl OpCode for CloseSocket { fn op_type(&self) -> OpType { OpType::Blocking } @@ -407,7 +407,7 @@ impl Accept { } } -impl OpCode for Accept { +unsafe impl OpCode for Accept { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let accept_fn = ACCEPT_EX .get_or_try_init(|| get_wsa_fn(self.fd.as_fd().as_raw_fd(), WSAID_ACCEPTEX))? @@ -455,7 +455,7 @@ impl Connect { } } -impl OpCode for Connect { +unsafe impl OpCode for Connect { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let connect_fn = CONNECT_EX .get_or_try_init(|| get_wsa_fn(self.fd.as_fd().as_raw_fd(), WSAID_CONNECTEX))? @@ -518,7 +518,7 @@ impl IntoInner for Recv { } } -impl OpCode for Recv { +unsafe impl OpCode for Recv { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); let fd = this.fd.as_fd().as_raw_fd(); @@ -544,7 +544,7 @@ impl OpCode for Recv { } } -impl OpCode for RecvManaged { +unsafe impl OpCode for RecvManaged { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { unsafe { self.project().op.operate(optr) } } @@ -587,7 +587,7 @@ impl IntoInner for RecvVectored { } } -impl OpCode for RecvVectored { +unsafe impl OpCode for RecvVectored { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); let fd = this.fd.as_fd().as_raw_fd(); @@ -649,7 +649,7 @@ impl IntoInner for Send { } } -impl OpCode for Send { +unsafe impl OpCode for Send { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); *this.slice = this.buffer.as_ref().sys_slice(); @@ -706,7 +706,7 @@ impl IntoInner for SendVectored { } } -impl OpCode for SendVectored { +unsafe impl OpCode for SendVectored { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); *this.slices = this.buffer.as_ref().sys_slices(); @@ -769,7 +769,7 @@ impl IntoInner for RecvFrom { } } -impl OpCode for RecvFrom { +unsafe impl OpCode for RecvFrom { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); let fd = this.fd.as_fd().as_raw_fd(); @@ -836,7 +836,7 @@ impl IntoInner for RecvFromVectored { } } -impl OpCode for RecvFromVectored { +unsafe impl OpCode for RecvFromVectored { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); let fd = this.fd.as_fd().as_raw_fd(); @@ -899,7 +899,7 @@ impl IntoInner for SendTo { } } -impl OpCode for SendTo { +unsafe impl OpCode for SendTo { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); *this.slice = this.buffer.as_ref().sys_slice(); @@ -960,7 +960,7 @@ impl IntoInner for SendToVectored { } } -impl OpCode for SendToVectored { +unsafe impl OpCode for SendToVectored { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); *this.slices = this.buffer.as_ref().sys_slices(); @@ -1042,7 +1042,7 @@ impl IntoInner for RecvMsg { } } -impl OpCode for RecvMsg { +unsafe impl OpCode for RecvMsg { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let recvmsg_fn = WSA_RECVMSG .get_or_try_init(|| get_wsa_fn(self.fd.as_fd().as_raw_fd(), WSAID_WSARECVMSG))? @@ -1126,7 +1126,7 @@ impl IntoInner for SendMsg { } } -impl OpCode for SendMsg { +unsafe impl OpCode for SendMsg { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let this = self.project(); @@ -1174,7 +1174,7 @@ impl ConnectNamedPipe { } } -impl OpCode for ConnectNamedPipe { +unsafe impl OpCode for ConnectNamedPipe { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let res = unsafe { ConnectNamedPipe(self.fd.as_fd().as_raw_fd() as _, optr) }; win32_result(res, 0) @@ -1219,7 +1219,7 @@ impl IntoInner for DeviceIoControl { } } -impl OpCode for DeviceIoControl { +unsafe impl OpCode for DeviceIoControl { unsafe fn operate(self: Pin<&mut Self>, optr: *mut OVERLAPPED) -> Poll> { let mut this = self.project(); diff --git a/compio-driver/src/sys/iour/mod.rs b/compio-driver/src/sys/iour/mod.rs index ff0c0568f..cc94a3de5 100644 --- a/compio-driver/src/sys/iour/mod.rs +++ b/compio-driver/src/sys/iour/mod.rs @@ -107,7 +107,12 @@ impl From for OpEntry { } /// Abstraction of io-uring operations. -pub trait OpCode { +/// +/// # Safety +/// +/// The returned Entry from `create_entry` must be valid until the operation is +/// completed. +pub unsafe trait OpCode { /// Create submission entry. fn create_entry(self: Pin<&mut Self>) -> OpEntry; diff --git a/compio-driver/src/sys/iour/op.rs b/compio-driver/src/sys/iour/op.rs index 3865b173e..f821f9744 100644 --- a/compio-driver/src/sys/iour/op.rs +++ b/compio-driver/src/sys/iour/op.rs @@ -18,7 +18,7 @@ use super::OpCode; pub use crate::sys::unix_op::*; use crate::{OpEntry, op::*, sys_slice::*, syscall}; -impl< +unsafe impl< D: std::marker::Send + 'static, F: (FnOnce() -> BufResult) + std::marker::Send + 'static, > OpCode for Asyncify @@ -39,7 +39,7 @@ impl< } } -impl< +unsafe impl< S, D: std::marker::Send + 'static, F: (FnOnce(&S) -> BufResult) + std::marker::Send + 'static, @@ -61,7 +61,7 @@ impl< } } -impl OpCode for OpenFile { +unsafe impl OpCode for OpenFile { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::OpenAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr()) .flags(self.flags | libc::O_CLOEXEC) @@ -71,7 +71,7 @@ impl OpCode for OpenFile { } } -impl OpCode for CloseFile { +unsafe impl OpCode for CloseFile { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Close::new(Fd(self.fd.as_fd().as_raw_fd())) .build() @@ -79,7 +79,7 @@ impl OpCode for CloseFile { } } -impl OpCode for TruncateFile { +unsafe impl OpCode for TruncateFile { fn create_entry(self: Pin<&mut Self>) -> OpEntry { if super::is_op_supported(opcode::Ftruncate::CODE) { return opcode::Ftruncate::new(Fd(self.fd.as_fd().as_raw_fd()), self.size) @@ -113,7 +113,7 @@ impl FileStat { } } -impl OpCode for FileStat { +unsafe impl OpCode for FileStat { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); static EMPTY_NAME: &[u8] = b"\0"; @@ -155,7 +155,7 @@ impl PathStat { } } -impl OpCode for PathStat { +unsafe impl OpCode for PathStat { fn create_entry(mut self: Pin<&mut Self>) -> OpEntry { let mut flags = libc::AT_EMPTY_PATH; if !self.follow_symlink { @@ -181,7 +181,7 @@ impl IntoInner for PathStat { } } -impl OpCode for ReadAt { +unsafe impl OpCode for ReadAt { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); let fd = Fd(this.fd.as_fd().as_raw_fd()); @@ -197,7 +197,7 @@ impl OpCode for ReadAt { } } -impl OpCode for ReadVectoredAt { +unsafe impl OpCode for ReadVectoredAt { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slices = this.buffer.sys_slices_mut(); @@ -212,7 +212,7 @@ impl OpCode for ReadVectoredAt { } } -impl OpCode for WriteAt { +unsafe impl OpCode for WriteAt { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let slice = self.buffer.as_init(); opcode::Write::new( @@ -226,7 +226,7 @@ impl OpCode for WriteAt { } } -impl OpCode for WriteVectoredAt { +unsafe impl OpCode for WriteVectoredAt { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slices = this.buffer.as_ref().sys_slices(); @@ -241,7 +241,7 @@ impl OpCode for WriteVectoredAt { } } -impl OpCode for Read { +unsafe impl OpCode for Read { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let fd = self.fd.as_fd().as_raw_fd(); let slice = self.project().buffer.sys_slice_mut(); @@ -255,7 +255,7 @@ impl OpCode for Read { } } -impl OpCode for ReadVectored { +unsafe impl OpCode for ReadVectored { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slices = this.buffer.sys_slices_mut(); @@ -269,7 +269,7 @@ impl OpCode for ReadVectored { } } -impl OpCode for Write { +unsafe impl OpCode for Write { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let slice = self.buffer.as_init(); opcode::Write::new( @@ -282,7 +282,7 @@ impl OpCode for Write { } } -impl OpCode for WriteVectored { +unsafe impl OpCode for WriteVectored { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slices = this.buffer.as_ref().sys_slices(); @@ -296,7 +296,7 @@ impl OpCode for WriteVectored { } } -impl OpCode for Sync { +unsafe impl OpCode for Sync { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Fsync::new(Fd(self.fd.as_fd().as_raw_fd())) .flags(if self.datasync { @@ -309,7 +309,7 @@ impl OpCode for Sync { } } -impl OpCode for Unlink { +unsafe impl OpCode for Unlink { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::UnlinkAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr()) .flags(if self.dir { libc::AT_REMOVEDIR } else { 0 }) @@ -318,7 +318,7 @@ impl OpCode for Unlink { } } -impl OpCode for CreateDir { +unsafe impl OpCode for CreateDir { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::MkDirAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr()) .mode(self.mode) @@ -327,7 +327,7 @@ impl OpCode for CreateDir { } } -impl OpCode for Rename { +unsafe impl OpCode for Rename { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::RenameAt::new( Fd(libc::AT_FDCWD), @@ -340,7 +340,7 @@ impl OpCode for Rename { } } -impl OpCode for Symlink { +unsafe impl OpCode for Symlink { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::SymlinkAt::new( Fd(libc::AT_FDCWD), @@ -352,7 +352,7 @@ impl OpCode for Symlink { } } -impl OpCode for HardLink { +unsafe impl OpCode for HardLink { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::LinkAt::new( Fd(libc::AT_FDCWD), @@ -365,7 +365,7 @@ impl OpCode for HardLink { } } -impl OpCode for CreateSocket { +unsafe impl OpCode for CreateSocket { fn create_entry(self: Pin<&mut Self>) -> OpEntry { if super::is_op_supported(opcode::Socket::CODE) { opcode::Socket::new( @@ -389,7 +389,7 @@ impl OpCode for CreateSocket { } } -impl OpCode for ShutdownSocket { +unsafe impl OpCode for ShutdownSocket { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Shutdown::new(Fd(self.fd.as_fd().as_raw_fd()), self.how()) .build() @@ -397,7 +397,7 @@ impl OpCode for ShutdownSocket { } } -impl OpCode for CloseSocket { +unsafe impl OpCode for CloseSocket { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Close::new(Fd(self.fd.as_fd().as_raw_fd())) .build() @@ -405,7 +405,7 @@ impl OpCode for CloseSocket { } } -impl OpCode for Accept { +unsafe impl OpCode for Accept { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); opcode::Accept::new( @@ -425,7 +425,7 @@ impl OpCode for Accept { } } -impl OpCode for Connect { +unsafe impl OpCode for Connect { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Connect::new( Fd(self.fd.as_fd().as_raw_fd()), @@ -437,7 +437,7 @@ impl OpCode for Connect { } } -impl OpCode for Recv { +unsafe impl OpCode for Recv { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let fd = self.fd.as_fd().as_raw_fd(); let flags = self.flags; @@ -453,7 +453,7 @@ impl OpCode for Recv { } } -impl OpCode for RecvVectored { +unsafe impl OpCode for RecvVectored { fn create_entry(mut self: Pin<&mut Self>) -> OpEntry { self.as_mut().set_msg(); let this = self.project(); @@ -464,7 +464,7 @@ impl OpCode for RecvVectored { } } -impl OpCode for Send { +unsafe impl OpCode for Send { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let slice = self.buffer.as_init(); opcode::Send::new( @@ -478,7 +478,7 @@ impl OpCode for Send { } } -impl OpCode for SendVectored { +unsafe impl OpCode for SendVectored { fn create_entry(mut self: Pin<&mut Self>) -> OpEntry { self.as_mut().set_msg(); let this = self.project(); @@ -547,7 +547,7 @@ impl RecvFrom { } } -impl OpCode for RecvFrom { +unsafe impl OpCode for RecvFrom { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); let slice = this.slice.insert(this.buffer.sys_slice_mut()); @@ -585,7 +585,7 @@ impl RecvFromVectored { } } -impl OpCode for RecvFromVectored { +unsafe impl OpCode for RecvFromVectored { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slice = this.buffer.sys_slices_mut(); @@ -656,7 +656,7 @@ impl SendTo { } } -impl OpCode for SendTo { +unsafe impl OpCode for SendTo { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); let slice = this.slice.insert(this.buffer.as_ref().sys_slice()); @@ -693,7 +693,7 @@ impl SendToVectored { } } -impl OpCode for SendToVectored { +unsafe impl OpCode for SendToVectored { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let this = self.project(); *this.slice = this.buffer.as_ref().sys_slices(); @@ -709,7 +709,7 @@ impl IntoInner for SendToVectored { } } -impl OpCode for RecvMsg { +unsafe impl OpCode for RecvMsg { fn create_entry(mut self: Pin<&mut Self>) -> OpEntry { self.as_mut().set_msg(); let this = self.project(); @@ -720,7 +720,7 @@ impl OpCode for RecvMsg { } } -impl OpCode for SendMsg { +unsafe impl OpCode for SendMsg { fn create_entry(mut self: Pin<&mut Self>) -> OpEntry { self.as_mut().set_msg(); let this = self.project(); @@ -731,7 +731,7 @@ impl OpCode for SendMsg { } } -impl OpCode for PollOnce { +unsafe impl OpCode for PollOnce { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let flags = match self.interest { Interest::Readable => libc::POLLIN, @@ -743,7 +743,7 @@ impl OpCode for PollOnce { } } -impl OpCode for Splice { +unsafe impl OpCode for Splice { fn create_entry(self: Pin<&mut Self>) -> OpEntry { opcode::Splice::new( Fd(self.fd_in.as_fd().as_raw_fd()), @@ -799,7 +799,7 @@ mod buf_ring { } } - impl OpCode for ReadManagedAt { + unsafe impl OpCode for ReadManagedAt { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let fd = Fd(self.fd.as_fd().as_raw_fd()); let offset = self.offset; @@ -857,7 +857,7 @@ mod buf_ring { } } - impl OpCode for ReadManaged { + unsafe impl OpCode for ReadManaged { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let fd = self.fd.as_fd().as_raw_fd(); opcode::Read::new(Fd(fd), ptr::null_mut(), self.len) @@ -915,7 +915,7 @@ mod buf_ring { } } - impl OpCode for RecvManaged { + unsafe impl OpCode for RecvManaged { fn create_entry(self: Pin<&mut Self>) -> OpEntry { let fd = self.fd.as_fd().as_raw_fd(); opcode::Recv::new(Fd(fd), ptr::null_mut(), self.len) diff --git a/compio-driver/src/sys/poll/mod.rs b/compio-driver/src/sys/poll/mod.rs index e0a5f8235..2bea99528 100644 --- a/compio-driver/src/sys/poll/mod.rs +++ b/compio-driver/src/sys/poll/mod.rs @@ -42,13 +42,13 @@ impl From for Track { /// Abstraction of operations. /// -/// # Implementation notes +/// # Safety /// /// If `pre_submit` returns `Decision::Wait`, `op_type` must also return /// `Some(OpType::Fd)` with same fds as the `WaitArg`s. Similarly, if /// `pre_submit` returns `Decision::Aio`, `op_type` must return /// `Some(OpType::Aio)` with the correct `aiocb` pointer. -pub trait OpCode { +pub unsafe trait OpCode { /// Perform the operation before submit, and return [`Decision`] to /// indicate whether submitting the operation to polling is required. fn pre_submit(self: Pin<&mut Self>) -> io::Result; diff --git a/compio-driver/src/sys/poll/op.rs b/compio-driver/src/sys/poll/op.rs index c1f6617ad..c1e5c4876 100644 --- a/compio-driver/src/sys/poll/op.rs +++ b/compio-driver/src/sys/poll/op.rs @@ -25,7 +25,7 @@ use super::{AsFd, Decision, OpCode, OpType, syscall}; pub use crate::sys::unix_op::*; use crate::{op::*, sys_slice::*}; -impl< +unsafe impl< D: std::marker::Send + 'static, F: (FnOnce() -> BufResult) + std::marker::Send + 'static, > OpCode for Asyncify @@ -46,7 +46,7 @@ impl< } } -impl< +unsafe impl< S, D: std::marker::Send + 'static, F: (FnOnce(&S) -> BufResult) + std::marker::Send + 'static, @@ -68,7 +68,7 @@ impl< } } -impl OpCode for OpenFile { +unsafe impl OpCode for OpenFile { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -82,7 +82,7 @@ impl OpCode for OpenFile { } } -impl OpCode for CloseFile { +unsafe impl OpCode for CloseFile { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -92,7 +92,7 @@ impl OpCode for CloseFile { } } -impl OpCode for TruncateFile { +unsafe impl OpCode for TruncateFile { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -120,7 +120,7 @@ impl FileStat { } } -impl OpCode for FileStat { +unsafe impl OpCode for FileStat { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -176,7 +176,7 @@ impl PathStat { } } -impl OpCode for PathStat { +unsafe impl OpCode for PathStat { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -219,7 +219,7 @@ impl IntoInner for PathStat { } } -impl OpCode for ReadAt { +unsafe impl OpCode for ReadAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { #[cfg(aio)] { @@ -252,7 +252,7 @@ impl OpCode for ReadAt { } } -impl OpCode for ReadVectoredAt { +unsafe impl OpCode for ReadVectoredAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { #[cfg(freebsd)] { @@ -291,7 +291,7 @@ impl OpCode for ReadVectoredAt { } } -impl OpCode for WriteAt { +unsafe impl OpCode for WriteAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { #[cfg(aio)] { @@ -329,7 +329,7 @@ impl OpCode for WriteAt { } } -impl OpCode for WriteVectoredAt { +unsafe impl OpCode for WriteVectoredAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { #[cfg(freebsd)] { @@ -368,7 +368,7 @@ impl OpCode for WriteVectoredAt { } } -impl OpCode for crate::op::managed::ReadManagedAt { +unsafe impl OpCode for crate::op::managed::ReadManagedAt { fn pre_submit(self: Pin<&mut Self>) -> io::Result { self.project().op.pre_submit() } @@ -382,7 +382,7 @@ impl OpCode for crate::op::managed::ReadManagedAt { } } -impl OpCode for Read { +unsafe impl OpCode for Read { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_readable(self.fd.as_fd().as_raw_fd())) } @@ -398,7 +398,7 @@ impl OpCode for Read { } } -impl OpCode for ReadVectored { +unsafe impl OpCode for ReadVectored { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_readable(self.fd.as_fd().as_raw_fd())) } @@ -420,7 +420,7 @@ impl OpCode for ReadVectored { } } -impl OpCode for Write { +unsafe impl OpCode for Write { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_writable(self.fd.as_fd().as_raw_fd())) } @@ -441,7 +441,7 @@ impl OpCode for Write { } } -impl OpCode for WriteVectored { +unsafe impl OpCode for WriteVectored { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_writable(self.fd.as_fd().as_raw_fd())) } @@ -463,7 +463,7 @@ impl OpCode for WriteVectored { } } -impl OpCode for crate::op::managed::ReadManaged { +unsafe impl OpCode for crate::op::managed::ReadManaged { fn pre_submit(self: Pin<&mut Self>) -> io::Result { self.project().op.pre_submit() } @@ -477,7 +477,7 @@ impl OpCode for crate::op::managed::ReadManaged { } } -impl OpCode for Sync { +unsafe impl OpCode for Sync { fn pre_submit(self: Pin<&mut Self>) -> io::Result { #[cfg(aio)] { @@ -526,7 +526,7 @@ impl OpCode for Sync { } } -impl OpCode for Unlink { +unsafe impl OpCode for Unlink { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -541,7 +541,7 @@ impl OpCode for Unlink { } } -impl OpCode for CreateDir { +unsafe impl OpCode for CreateDir { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -552,7 +552,7 @@ impl OpCode for CreateDir { } } -impl OpCode for Rename { +unsafe impl OpCode for Rename { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -563,7 +563,7 @@ impl OpCode for Rename { } } -impl OpCode for Symlink { +unsafe impl OpCode for Symlink { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -574,7 +574,7 @@ impl OpCode for Symlink { } } -impl OpCode for HardLink { +unsafe impl OpCode for HardLink { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -645,7 +645,7 @@ impl CreateSocket { } } -impl OpCode for CreateSocket { +unsafe impl OpCode for CreateSocket { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -655,7 +655,7 @@ impl OpCode for CreateSocket { } } -impl OpCode for ShutdownSocket { +unsafe impl OpCode for ShutdownSocket { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -667,7 +667,7 @@ impl OpCode for ShutdownSocket { } } -impl OpCode for CloseSocket { +unsafe impl OpCode for CloseSocket { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::Blocking) } @@ -727,7 +727,7 @@ impl Accept { } } -impl OpCode for Accept { +unsafe impl OpCode for Accept { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { let fd = self.fd.as_fd().as_raw_fd(); syscall!(self.as_mut().call(), wait_readable(fd)) @@ -748,7 +748,7 @@ impl OpCode for Accept { } } -impl OpCode for Connect { +unsafe impl OpCode for Connect { fn pre_submit(self: Pin<&mut Self>) -> io::Result { syscall!( libc::connect( @@ -785,7 +785,7 @@ impl OpCode for Connect { } } -impl OpCode for Recv { +unsafe impl OpCode for Recv { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_readable(self.fd.as_fd().as_raw_fd())) } @@ -802,7 +802,7 @@ impl OpCode for Recv { } } -impl OpCode for Send { +unsafe impl OpCode for Send { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_writable(self.fd.as_fd().as_raw_fd())) } @@ -824,7 +824,7 @@ impl OpCode for Send { } } -impl OpCode for crate::op::managed::RecvManaged { +unsafe impl OpCode for crate::op::managed::RecvManaged { fn pre_submit(self: Pin<&mut Self>) -> io::Result { self.project().op.pre_submit() } @@ -845,7 +845,7 @@ impl RecvVectored { } } -impl OpCode for RecvVectored { +unsafe impl OpCode for RecvVectored { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.fd.as_fd().as_raw_fd(); @@ -867,7 +867,7 @@ impl SendVectored { } } -impl OpCode for SendVectored { +unsafe impl OpCode for SendVectored { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.as_mut().project().fd.as_fd().as_raw_fd(); @@ -930,7 +930,7 @@ impl RecvFrom { } } -impl OpCode for RecvFrom { +unsafe impl OpCode for RecvFrom { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { let fd = self.fd.as_fd().as_raw_fd(); syscall!(self.as_mut().call(), wait_readable(fd)) @@ -998,7 +998,7 @@ impl RecvFromVectored { } } -impl OpCode for RecvFromVectored { +unsafe impl OpCode for RecvFromVectored { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.as_mut().project().fd.as_fd().as_raw_fd(); @@ -1062,7 +1062,7 @@ impl SendTo { } } -impl OpCode for SendTo { +unsafe impl OpCode for SendTo { fn pre_submit(self: Pin<&mut Self>) -> io::Result { syscall!(self.call(), wait_writable(self.fd.as_fd().as_raw_fd())) } @@ -1128,7 +1128,7 @@ impl SendToVectored { } } -impl OpCode for SendToVectored { +unsafe impl OpCode for SendToVectored { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.fd.as_fd().as_raw_fd(); @@ -1159,7 +1159,7 @@ impl RecvMsg { } } -impl OpCode for RecvMsg { +unsafe impl OpCode for RecvMsg { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.fd.as_fd().as_raw_fd(); @@ -1181,7 +1181,7 @@ impl SendMsg { } } -impl OpCode for SendMsg { +unsafe impl OpCode for SendMsg { fn pre_submit(mut self: Pin<&mut Self>) -> io::Result { self.as_mut().set_msg(); let fd = self.fd.as_fd().as_raw_fd(); @@ -1197,7 +1197,7 @@ impl OpCode for SendMsg { } } -impl OpCode for PollOnce { +unsafe impl OpCode for PollOnce { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_for( self.fd.as_fd().as_raw_fd(), @@ -1215,7 +1215,7 @@ impl OpCode for PollOnce { } #[cfg(linux_all)] -impl OpCode for Splice { +unsafe impl OpCode for Splice { fn pre_submit(self: Pin<&mut Self>) -> io::Result { use super::WaitArg; diff --git a/compio-driver/tests/splice.rs b/compio-driver/tests/splice.rs index 9ee5cb2fc..9a6b85ca9 100644 --- a/compio-driver/tests/splice.rs +++ b/compio-driver/tests/splice.rs @@ -79,7 +79,7 @@ mod splice_impl { } } - impl OpCode for Splice { + unsafe impl OpCode for Splice { fn pre_submit(self: Pin<&mut Self>) -> io::Result { Ok(Decision::wait_for_many([ WaitArg::readable(self.fd_in.as_fd().as_raw_fd()), diff --git a/compio-fs/src/stdio/windows.rs b/compio-fs/src/stdio/windows.rs index f54208dac..424b81eaf 100644 --- a/compio-fs/src/stdio/windows.rs +++ b/compio-fs/src/stdio/windows.rs @@ -29,7 +29,7 @@ impl StdRead { } } -impl OpCode for StdRead { +unsafe impl OpCode for StdRead { fn op_type(&self) -> OpType { OpType::Blocking } @@ -80,7 +80,7 @@ impl StdWrite { } } -impl OpCode for StdWrite { +unsafe impl OpCode for StdWrite { fn op_type(&self) -> OpType { OpType::Blocking } diff --git a/compio-net/src/poll_fd/windows.rs b/compio-net/src/poll_fd/windows.rs index 01b99bc86..4c47e6852 100644 --- a/compio-net/src/poll_fd/windows.rs +++ b/compio-net/src/poll_fd/windows.rs @@ -197,7 +197,7 @@ impl IntoInner for WaitWSAEvent { } } -impl OpCode for WaitWSAEvent { +unsafe impl OpCode for WaitWSAEvent { fn op_type(&self) -> OpType { OpType::Event(self.ev_object.as_raw_fd()) } diff --git a/compio-process/src/windows.rs b/compio-process/src/windows.rs index 91285cb0d..0aa42b51f 100644 --- a/compio-process/src/windows.rs +++ b/compio-process/src/windows.rs @@ -28,7 +28,7 @@ impl WaitProcess { } } -impl OpCode for WaitProcess { +unsafe impl OpCode for WaitProcess { fn op_type(&self) -> OpType { OpType::Event(self.child.as_raw_handle() as _) } diff --git a/compio-runtime/tests/event.rs b/compio-runtime/tests/event.rs index 9c51f1d3c..3a805fcb0 100644 --- a/compio-runtime/tests/event.rs +++ b/compio-runtime/tests/event.rs @@ -35,7 +35,7 @@ fn win32_event() { event: OwnedHandle, } - impl OpCode for WaitEvent { + unsafe impl OpCode for WaitEvent { fn op_type(&self) -> OpType { OpType::Event(self.event.as_raw_handle() as _) }