Skip to content

Commit 55f18be

Browse files
committed
wording; and explain some of the possible consequences of violating io-safety
1 parent 334a54c commit 55f18be

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

library/std/src/io/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
//! subsume similar concepts that exist across a wide range of operating systems even if they might
246246
//! use a different name, such as "handle".) An exclusively owned file descriptor is one that no
247247
//! other code is allowed to close, but the owner is allowed to close it any time. A type that owns
248-
//! its file descriptor should close it in its `drop` function. Types like [`File`] generally own
248+
//! its file descriptor should usually close it in its `drop` function. Types like [`File`] generally own
249249
//! their file descriptor. Similarly, file descriptors can be *borrowed*. This indicates that the
250250
//! file descriptor will not be closed for the lifetime of the borrow, but it does *not* imply any
251251
//! right to close this file descriptor, since it will likely be owned by someone else.
@@ -257,6 +257,12 @@
257257
//! other words, a safe function that takes a regular integer, treats it as a file descriptor, and
258258
//! closes it, is *unsound*.
259259
//!
260+
//! Not upholding I/O safety and closing a file descriptor without proof of ownership can lead to
261+
//! misbehavior and even Undefined Behavior in code that relies on ownership of its file
262+
//! descriptors: the closed file descriptor could be re-allocated to some other library (such as the
263+
//! allocator or a memory mapping library) and now accessing the file descriptor will interfere in
264+
//! arbitrarily destructive ways with that other library.
265+
//!
260266
//! Note that this does not talk about performing other operations on the file descriptor, such as
261267
//! reading or writing. For example, on Unix, the [`OwnedFd`] and [`BorrowedFd`] types from the
262268
//! standard library do *not* exclude that there is other code that reads or writes the same

library/std/src/os/unix/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! This module provides three types for representing file descriptors,
88
//! with different ownership properties: raw, borrowed, and owned, which are
9-
//! analogous to types used for representing pointers. These types realize the Unix version of [I/O safety].
9+
//! analogous to types used for representing pointers. These types reflect the Unix version of [I/O safety].
1010
//!
1111
//! | Type | Analogous to |
1212
//! | ------------------ | ------------ |

library/std/src/os/windows/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! This module provides three types for representing raw handles and sockets
88
//! with different ownership properties: raw, borrowed, and owned, which are
9-
//! analogous to types used for representing pointers. These types realize the Windows version of [I/O safety].
9+
//! analogous to types used for representing pointers. These types reflect the Windows version of [I/O safety].
1010
//!
1111
//! | Type | Analogous to |
1212
//! | ---------------------- | ------------ |

0 commit comments

Comments
 (0)