Skip to content

Commit

Permalink
fix(driver,poll): mark submit unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Feb 19, 2024
1 parent eb0f2b1 commit 3e04836
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions compio-driver/src/poll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ impl Driver {
RawOp::new(user_data, op)
}

fn submit(&mut self, user_data: usize, arg: WaitArg) -> io::Result<()> {
/// # Safety
/// The input fd should be valid.
unsafe fn submit(&mut self, user_data: usize, arg: WaitArg) -> io::Result<()> {
let need_add = !self.registry.contains_key(&arg.fd);
let queue = self.registry.entry(arg.fd).or_default();
queue.push_back_interest(user_data, arg.interest);
// We use fd as the key.
let event = queue.event(arg.fd as usize);
unsafe {
if need_add {
self.poll.add(arg.fd, event)?;
} else {
let fd = BorrowedFd::borrow_raw(arg.fd);
self.poll.modify(fd, event)?;
}
if need_add {
self.poll.add(arg.fd, event)?;
} else {
let fd = BorrowedFd::borrow_raw(arg.fd);
self.poll.modify(fd, event)?;
}
Ok(())
}
Expand All @@ -207,7 +207,10 @@ impl Driver {
let op_pin = op.as_pin();
match op_pin.pre_submit() {
Ok(Decision::Wait(arg)) => {
self.submit(user_data, arg)?;
// SAFETY: fd is from the OpCode.
unsafe {
self.submit(user_data, arg)?;
}
Poll::Pending
}
Ok(Decision::Completed(res)) => Poll::Ready(Ok(res)),
Expand Down

0 comments on commit 3e04836

Please sign in to comment.