Skip to content

Commit 7324261

Browse files
committed
Incorporate parts of @RalfJung's comment.
rust-lang/socket2#218 (comment)
1 parent 3abe7cc commit 7324261

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

text/0000-io-safety.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ and [`RawHandle`]/[`RawSocket`] on Windows, which represent raw OS resource
6262
handles. These don't provide any behavior on their own, and just represent
6363
identifiers which can be passed to low-level OS APIs.
6464

65-
These raw handles can be thought of as raw pointers, with similar hazards. The
66-
consequences of using an unintentionally aliased raw resource handle could
67-
include corrupted output or silently lost input data. It could also mean that
68-
code in one crate could accidentally corrupt or observe private data in another
69-
crate. Protection from these hazards is called *I/O safety*.
65+
These raw handles can be thought of as raw pointers, with similar hazards.
66+
While it's safe to *obtain* a raw pointer, *dereferencing* a raw pointer could
67+
invoke undefined behavior if it isn't a valid pointer or if it outlives the
68+
lifetime of the memory it points to. Similarly, it's safe to *obtain* a raw
69+
handle, via [`AsRawFd::as_raw_fd`] and similar, but using it to do I/O could
70+
lead to corrupted output, lost or leaked input data, or violated encapsulation
71+
boundaries, if it isn't a valid handle or it's used after the `close` of its
72+
resource. And in both cases, the effects can be non-local, affecting otherwise
73+
unrelated parts of a program. Protection from raw pointer hazards is called
74+
memory safety, so protection from raw handle hazards is called *I/O safety*.
7075

7176
Rust's standard library also has high-level types such as [`File`] and
7277
[`TcpStream`] which are wrappers around these raw handles, providing high-level

0 commit comments

Comments
 (0)