-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Document FromRawFd unsafety #72175
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Currently the documentation of FromRawFd uses vague language:
What kind of memory safety issues is this quote referring to?
Using the nix crate it is not hard to write FromRawFd using only safe code:
This is the simplest way but you can also use
closeon the returned file descriptor and then callFile::openagain to create twoFiles with the same underlying file descriptor.What about performing the various
fcntloperation on the value returned byas_raw_fd? Can these also cause memory unsafety? Must all methods operating on file descriptors in nix be marked unsafe becauseas_raw_fdis a safe function?Given the current state of the
AsRawFdand the existence of other safe crates which allow manipulating the returned file descriptor, there should be very good reasons to keepfrom_raw_fdunsafe and these should be documented. Otherwisefrom_raw_fdshould be made safe with a clear warning that odd (but not unsafe) things might happen if the assumptions about ownership are violated.