Fix: Replace sighandler_t with sig_t for Apple and BSDs - #5008
Conversation
This comment has been minimized.
This comment has been minimized.
|
Not sure if the author intends on finishing this up. If not, I've solved the Note these changes should be enough to close issue #1273, but it doesn't solve Footnotes |
|
This PR was waiting for someone to review it for me. I can take another look after 8/9. If you have already resolved the issue and it is ready to merge, feel free to go ahead! |
|
Nay, just wanted to know if you were still on it. I did make some changes, But this PR can probably merged as the required changes once we get All other relevant targets (BSDs and Apple) can just rely on It would be nice to have Footnotes |
| #[cfg(any( | ||
| target_os = "macos", | ||
| target_os = "ios", | ||
| target_os = "tvos", | ||
| target_os = "watchos", | ||
| target_os = "visionos", | ||
| target_os = "freebsd", | ||
| target_os = "dragonfly", | ||
| target_os = "openbsd", | ||
| target_os = "netbsd" | ||
| ))] | ||
| pub type sig_t = sighandler_t; |
There was a problem hiding this comment.
This can go in src/unix/bsd/mod.rs so we don't need the cfg
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
| // going to need tweaking because raw pointers to functions aren't a thing just | ||
| // yet in Rust. |
There was a problem hiding this comment.
Isn't Option<unsafe extern "C" fn()> basically a raw pointer to a function?
There was a problem hiding this comment.
Kind of but in a very footgunny way, IMO. #4998 and the thread https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/type.20representing.20raw.20function.20pointers/with/606804857
Introduce new alias `sig_t` to `sighandler_t` for both Apple and BSD targets. Replace all uses of `sighandler_t` with `sig_t` in Apple and BSD targets. These platforms don't use the GNU-specific extension that `sighandler_t` is. See the following list for details on each system. - Apple: <https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/signal.h#L501> - FreeBSD: <https://github.com/freebsd/freebsd-src/blob/77d6c45afdca8a524a88edfb3097d4d9dc90b583/sys/sys/signal.h#L160> - DragonFlyBSD: <https://github.com/DragonFlyBSD/DragonFlyBSD/blob/e8a62118fe4823bb5982e5d759e5ffaa6b6aae21/sys/sys/signal.h#L257> - NetBSD: <https://github.com/NetBSD/src/blob/5c8b04300c02b550f331bc0b7357f0fc71909aaa/sys/sys/signal.h#L247> - OpenBSD: <https://github.com/openbsd/src/blob/f8480ad0276ad54ce9f7ed2b2004c86f9f1a9521/sys/sys/signal.h#L148> Note this patch doesn't try to fix the `sigaction` situation where most systems use a specific field of the upstream `union` in its first field. That is work for another patchset (and further discussion.) Co-authored-by: Adam Martinez <149513579+dybucc@users.noreply.github.com>
Head branch was pushed to by a user without write access
| // FIXME(1.0): once we settle for a definition for `sighandler_t`, ensure it's | ||
| // sound for `sig_t` to be a raw pointer to it, as that's the definition in the | ||
| // BSDs and Apple targets. | ||
| // | ||
| // See <https://github.com/freebsd/freebsd-src/blob/77d6c45afdca8a524a88edfb3097d4d9dc90b583/sys/sys/signal.h#L160> | ||
| // and <https://github.com/freebsd/freebsd-src/blob/77d6c45afdca8a524a88edfb3097d4d9dc90b583/sys/sys/signal.h#L408> | ||
| // for FreeBSD details. | ||
| // | ||
| // Because `sighandler_t` is defined in FreeBSD as a function alias that | ||
| // implicitly decays to the function pointer and not a "straight" alias to a | ||
| // function pointer, we can probably keep the same definitions in other BSDs. | ||
| // | ||
| // They have no `sighandler_t` but do have the same `sig_t`. Of course, this is | ||
| // going to need tweaking because raw pointers to functions aren't a thing just | ||
| // yet in Rust. | ||
| pub type sig_t = *const crate::sighandler_t; |
There was a problem hiding this comment.
Actually, reading things closer since Mads pointed it out, I think this should just be a type sig_t = Option<unsafe extern "C" fn(c_int)> and then sighandler_t needs to be deleted. Opsem says that's sound even for non-dereferenceable values, which was one of the questions in the past. The other question is whether or not it's a footgun, which I still think it is, but that applies to all function pointers in this crate.
Sorry for adding another change, but I think that gets us closer to where we want to be. You can also drop this comment since it will only have the problem that all function pointers have, and I don't think there's anything really worth noting about the FreeBSD definition (but do feel free to put any of it into the commit message).
There was a problem hiding this comment.
Also it looks like you need to recheck the semver files based on the CI failure.
Description
This PR tries to fix #1273.
Sources
sighandler_t(a GNU extension) is not defined on most non-glibc platforms: macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, AIX 5.1, HP-UX 11, Solaris 11.4, Cygwin, mingw, MSVC 14.
Checklist
libc-test/semverhave been updated*LASTor*MAXareincluded (see #3131)
cd libc-test && cargo test --target mytarget);especially relevant for platforms that may not be checked in CI