-
Notifications
You must be signed in to change notification settings - Fork 90
refactor(driver)!: make opcode unsafe #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,7 +107,12 @@ impl From<io_uring::squeue::Entry128> 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. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
+114
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// The returned Entry from `create_entry` must be valid until the operation is | |
| /// completed. | |
| /// Implementors must uphold the safety contract between the io-uring submission | |
| /// entry created by [`create_entry`] and any user-space resources it refers to. | |
| /// | |
| /// In particular: | |
| /// - The `io_uring::squeue::Entry` / `Entry128` value itself does *not* need to | |
| /// stay alive after `create_entry` returns; the runtime may move, copy, or drop | |
| /// that value at will. | |
| /// - However, every resource that the submission entry *refers to* (for example, | |
| /// buffer pointers and lengths, `iovec`/slice arrays, strings, and any other | |
| /// memory or file descriptors passed to the kernel through the SQE) must remain | |
| /// allocated, properly aligned, and valid for the kernel to read/write for the | |
| /// entire lifetime of the in-flight operation. | |
| /// | |
| /// For the purposes of this contract, an operation is considered *completed* once | |
| /// the runtime has finished handling the associated io-uring completion queue | |
| /// entry (CQE), including CQEs that report an explicit cancellation (for example, | |
| /// via an `AsyncCancel` request). Until that point, implementations must not free, | |
| /// move, or otherwise invalidate any memory or descriptors that are referenced by | |
| /// the submission entry in a way that would make the kernel observe dangling or | |
| /// misaligned pointers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
OpCodeis now an unsafe trait, the# Safetysection should enumerate the concrete invariants implementors must uphold (e.g.,OpType::Eventhandles must remain valid until completion,OpType::Blockingrequiresoperateto be thread-safe, andOverlappedrequires correct use ofoptr). Right now it’s very high-level and easy for downstream implementors to miss required guarantees that can lead to UB.