-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FromRawFd should be unsafe #1043
Comments
Great catch. I agree that |
One thing we could also possibly do here in addition to making it |
As pointed out in [RFC issue 1043][rfc] it is quite useful to have the standard I/O types to provide the contract that they are the sole owner of the underlying object they represent. This guarantee enables writing safe interfaces like the `MemoryMap` API sketched out in that issue. [rfc]: rust-lang/rfcs#1043 As constructing objects from these raw handles may end up violating these ownership gurantees, the functions for construction are now marked unsafe. [breaking-change] Closes rust-lang#1043
The current intention for this trait is to be a cheap-as-possible raising operation from a lower-level representation into what the standard library is expecting, so I wouldn't personally expect any checks to be made about the actual value itself (e.g. that's up to the job of the application to work correctly). That's my personal feeling at least :) |
Closed by rust-lang/rust#24251 |
As pointed out in [RFC issue 1043][rfc] it is quite useful to have the standard I/O types to provide the contract that they are the sole owner of the underlying object they represent. This guarantee enables writing safe interfaces like the `MemoryMap` API sketched out in that issue. [rfc]: rust-lang/rfcs#1043 As constructing objects from these raw handles may end up violating these ownership gurantees, the functions for construction are now marked unsafe. [breaking-change] Closes rust-lang/rfcs#1043
As pointed out in [RFC issue 1043][rfc] it is quite useful to have the standard I/O types to provide the contract that they are the sole owner of the underlying object they represent. This guarantee enables writing safe interfaces like the `MemoryMap` API sketched out in that issue. [rfc]: rust-lang/rfcs#1043 As constructing objects from these raw handles may end up violating these ownership gurantees, the functions for construction are now marked unsafe. [breaking-change] Closes rust-lang/rfcs#1043
As pointed out in [RFC issue 1043][rfc] it is quite useful to have the standard I/O types to provide the contract that they are the sole owner of the underlying object they represent. This guarantee enables writing safe interfaces like the `MemoryMap` API sketched out in that issue. [rfc]: rust-lang/rfcs#1043 As constructing objects from these raw handles may end up violating these ownership gurantees, the functions for construction are now marked unsafe. [breaking-change] Closes rust-lang/rfcs#1043
I'm not sure I quite follow here.
Is the problem here supposed to be that dropping
edit: The same applies to Windows file mappings and file handles:
|
Good point, a better example would be writing arbitrary data to the file. |
Related question. is there a "safe" trait to get a raw descriptor?
|
|
@sfackler My point is a "safe" way to get a fd, meaning that the implementor of the trait will need to use "unsafe" in order to return a fd, but the whoever calls look at my example right now you can do:
Which will obviously won't be fine |
Not in the standard library. However, you can implement this yourself: |
Currently, AFAIK, this is the only way to manipulate a file using a file descriptor directly without writing an unsafe block. If this trait remains safe, the following MemoryMap interface (for example) can't be safe:
The text was updated successfully, but these errors were encountered: