-
Notifications
You must be signed in to change notification settings - Fork 680
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
feat: I/O safety for 'sys/signal' #1936
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Module sys/signal now adopts I/O safety |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Type `SigevNotify` is no longer `PartialEq`, `Eq` and `Hash` due to the use of `BorrowedFd` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
// Portions of this file are Copyright 2014 The Rust Project Developers. | ||
// See https://www.rust-lang.org/policies/licenses. | ||
|
||
//! Operating system signals. | ||
|
||
use crate::errno::Errno; | ||
|
@@ -10,8 +7,6 @@ use std::fmt; | |
use std::hash::{Hash, Hasher}; | ||
use std::mem; | ||
use std::ops::BitOr; | ||
#[cfg(freebsdlike)] | ||
use std::os::unix::io::RawFd; | ||
use std::ptr; | ||
use std::str::FromStr; | ||
|
||
|
@@ -1114,8 +1109,8 @@ pub type type_of_thread_id = libc::pid_t; | |
// as a pointer, because neither libc nor the kernel ever dereference it. nix | ||
// therefore presents it as an intptr_t, which is how kevent uses it. | ||
#[cfg(not(any(target_os = "fuchsia", target_os = "hurd", target_os = "openbsd", target_os = "redox")))] | ||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub enum SigevNotify { | ||
#[derive(Clone, Copy, Debug)] | ||
pub enum SigevNotify<'fd> { | ||
/// No notification will be delivered | ||
SigevNone, | ||
/// Notify by delivering a signal to the process. | ||
|
@@ -1131,7 +1126,7 @@ pub enum SigevNotify { | |
#[cfg(freebsdlike)] | ||
SigevKevent { | ||
/// File descriptor of the kqueue to notify. | ||
kq: RawFd, | ||
kq: std::os::fd::BorrowedFd<'fd>, | ||
/// Will be contained in the kevent's `udata` field. | ||
udata: libc::intptr_t | ||
}, | ||
|
@@ -1140,7 +1135,7 @@ pub enum SigevNotify { | |
#[cfg(feature = "event")] | ||
SigevKeventFlags { | ||
/// File descriptor of the kqueue to notify. | ||
kq: RawFd, | ||
kq: std::os::fd::BorrowedFd<'fd>, | ||
/// Will be contained in the kevent's `udata` field. | ||
udata: libc::intptr_t, | ||
/// Flags that will be set on the delivered event. See `kevent(2)`. | ||
|
@@ -1161,6 +1156,14 @@ pub enum SigevNotify { | |
/// structure of the queued signal. | ||
si_value: libc::intptr_t | ||
}, | ||
/// A helper variant to resolve the unused parameter (`'fd`) problem on | ||
/// platforms other than FreeBSD and DragonFlyBSD. | ||
/// | ||
/// This variant can never be constructed due to the usage of an enum with 0 | ||
/// variants. | ||
#[doc(hidden)] | ||
#[cfg(not(freebsdlike))] | ||
_Unreachable(&'fd std::convert::Infallible), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the associated type of this variant to |
||
} | ||
} | ||
|
||
|
@@ -1337,15 +1340,19 @@ mod sigevent { | |
}, | ||
#[cfg(freebsdlike)] | ||
SigevNotify::SigevKevent{kq, udata} => { | ||
use std::os::fd::AsRawFd; | ||
|
||
sev.sigev_notify = libc::SIGEV_KEVENT; | ||
sev.sigev_signo = kq; | ||
sev.sigev_signo = kq.as_raw_fd(); | ||
sev.sigev_value.sival_ptr = udata as *mut libc::c_void; | ||
}, | ||
#[cfg(target_os = "freebsd")] | ||
#[cfg(feature = "event")] | ||
SigevNotify::SigevKeventFlags{kq, udata, flags} => { | ||
use std::os::fd::AsRawFd; | ||
|
||
sev.sigev_notify = libc::SIGEV_KEVENT; | ||
sev.sigev_signo = kq; | ||
sev.sigev_signo = kq.as_raw_fd(); | ||
sev.sigev_value.sival_ptr = udata as *mut libc::c_void; | ||
sev._sigev_un._kevent_flags = flags.bits(); | ||
}, | ||
|
@@ -1363,6 +1370,8 @@ mod sigevent { | |
sev.sigev_value.sival_ptr = si_value as *mut libc::c_void; | ||
sev.sigev_notify_thread_id = thread_id; | ||
} | ||
#[cfg(not(freebsdlike))] | ||
SigevNotify::_Unreachable(_) => unreachable!("This variant could never be constructed") | ||
} | ||
SigEvent{sigevent: sev} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this header, looks like it is the only header we have.