-
Notifications
You must be signed in to change notification settings - Fork 175
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
Make kevent
safe, using BorrowedFd
for changelist
#939
base: main
Are you sure you want to change the base?
Conversation
Which manpage are you using? I think this is guaranteed for FreeBSD, but not other BSDs. I don't have the issue on hand, but I know that not removing the FD from kqueue has caused I/O safety issues in other projects. |
The same wording seems to be in all of them.
https://man.freebsd.org/cgi/man.cgi?query=kevent It's caused safety issues in other projects, or there was concern that it might be unsafe? Though it may be unsafe to actually use the fd returned in |
Okay then. I'm fine with it as long as the sunfish is. |
I haven't fully caught up on this yet, but I do want to raise a potential concern. In general, it's not sufficient to say "I'm only providing users with |
My thoughts on this:
Specifically, I'm was looking at this since it's one of the few |
I do agree with this. There is nuance here though. If we say "the code that gets the So, it is about things that violate safety. Putting the One possible alternative approach here would be to have an alternate version of |
That would satisfy the use case of avoiding unnecessary Though it makes this a bit more complicated, and I don't see it as necessary. (But this could be done with the generic approach used in this PR by returning
In principle, any function that accepts a So if I wanted to pass the From a safety standpoint, this is similar to functions returning raw pointers. It's generally expected in Rust for getter functions returning
These considerations can be mentioned in a doc comment either way. |
It looks like #488 initially used something like this, but there was concern about the safety if an fd is closed while it is in a kqueue. But it doesn't seem to have been established that this actually violates io safety.
kevent(2)
documents that the fd is removed from any kqueues referencing it if it is closed. While that may result in behavior the caller doesn't expect, it shouldn't be unsafe. There should be no way for an fd being inserted into a kqueue then closed to impact a new fd that is opened with the same value, which is generally the concern with IO safety.I haven't tested this yet other than
cargo check
from a Linux system, and this would be a breaking API change. But if it can be safe, it should be changed in the next semver breaking version of Rustix.