redox-driver-sys: add # Safety doc to pcid_client.rs from_raw_fd
Documents the safety contract: the fd is freshly opened by either connect() or connect_by_path() and ownership transfers exactly once to the File.
This commit is contained in:
@@ -97,6 +97,11 @@ impl PcidClient {
|
||||
}
|
||||
|
||||
fn connect_common(channel_fd: RawFd) -> Self {
|
||||
// SAFETY: `from_raw_fd` is unsafe because the caller must guarantee that
|
||||
// `channel_fd` is a valid open file descriptor not aliased by any other
|
||||
// owned File. The two callers (`connect` and `connect_by_path`) both open
|
||||
// a fresh fd via `libredox::call::open`/`openat` and pass it through
|
||||
// here exactly once, transferring ownership to the returned File.
|
||||
let channel = unsafe { File::from_raw_fd(channel_fd) };
|
||||
Self { channel }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user