Add safety comments.
These will soon be required by a lint. Bug: 290018030 Test: m vm virtmgr Change-Id: Id628b2a88f1cb0235fbccc748c52514e64561fe5
This commit is contained in:
parent
7f9b2c1739
commit
9fbd1683d4
1 changed files with 12 additions and 6 deletions
|
@ -39,20 +39,26 @@ pub struct TombstonedConnection {
|
|||
}
|
||||
|
||||
impl TombstonedConnection {
|
||||
/// # Safety
|
||||
///
|
||||
/// The file descriptors must be valid and open.
|
||||
unsafe fn from_raw_fds(
|
||||
tombstoned_socket: RawFd,
|
||||
text_output_fd: RawFd,
|
||||
proto_output_fd: RawFd,
|
||||
) -> Self {
|
||||
Self {
|
||||
tombstoned_socket: File::from_raw_fd(tombstoned_socket),
|
||||
// SAFETY: The caller guarantees that the file descriptor is valid and open.
|
||||
tombstoned_socket: unsafe { File::from_raw_fd(tombstoned_socket) },
|
||||
text_output: if text_output_fd >= 0 {
|
||||
Some(File::from_raw_fd(text_output_fd))
|
||||
// SAFETY: The caller guarantees that the file descriptor is valid and open.
|
||||
Some(unsafe { File::from_raw_fd(text_output_fd) })
|
||||
} else {
|
||||
None
|
||||
},
|
||||
proto_output: if proto_output_fd >= 0 {
|
||||
Some(File::from_raw_fd(proto_output_fd))
|
||||
// SAFETY: The caller guarantees that the file descriptor is valid and open.
|
||||
Some(unsafe { File::from_raw_fd(proto_output_fd) })
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
@ -71,6 +77,8 @@ impl TombstonedConnection {
|
|||
&mut proto_output_fd,
|
||||
dump_type,
|
||||
) {
|
||||
// SAFETY: If tombstoned_connect_files returns successfully then they file descriptors
|
||||
// are valid and open.
|
||||
Ok(unsafe { Self::from_raw_fds(tombstoned_socket, text_output_fd, proto_output_fd) })
|
||||
} else {
|
||||
Err(Error)
|
||||
|
@ -146,8 +154,6 @@ mod tests {
|
|||
.write_all(b"test data")
|
||||
.expect("Failed to write to text output FD.");
|
||||
|
||||
connection
|
||||
.notify_completion()
|
||||
.expect("Failed to notify completion.");
|
||||
connection.notify_completion().expect("Failed to notify completion.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue