-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc][signal] clean up usage of sighandler_t #125745
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
Changes from all commits
62e8a9c
c84b8f2
669bb96
19e518a
d486708
5864bf7
3730708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| //===-- Definition of struct __sighandler_t -------------------------------===// | ||
| //===-- Definition of sighandler_t ----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_TYPES___SIGHANDLER_T_H | ||
| #define LLVM_LIBC_TYPES___SIGHANDLER_T_H | ||
| #ifndef LLVM_LIBC_TYPES_SIGHANDLER_T_H | ||
| #define LLVM_LIBC_TYPES_SIGHANDLER_T_H | ||
|
|
||
| typedef void (*__sighandler_t)(int); | ||
| #ifdef __linux__ | ||
| // For compatibility with glibc. | ||
| typedef void (*sighandler_t)(int); | ||
| #endif | ||
|
|
||
| #endif // LLVM_LIBC_TYPES___SIGHANDLER_T_H | ||
| #endif // LLVM_LIBC_TYPES_SIGHANDLER_T_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,4 @@ struct sigaction { | |
| #endif | ||
| }; | ||
|
|
||
| typedef void (*__sighandler_t)(int); | ||
|
|
||
| #endif // LLVM_LIBC_TYPES_STRUCT_SIGACTION_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,17 @@ | |
|
|
||
| #include "src/signal/signal.h" | ||
| #include "hdr/signal_macros.h" | ||
| #include "hdr/types/sighandler_t.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
| #include "src/signal/sigaction.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(sighandler_t, signal, (int signum, sighandler_t handler)) { | ||
| // Our LLVM_LIBC_FUNCTION macro doesn't handle function pointer return types. | ||
| using signal_handler = void (*)(int); | ||
|
Member
Author
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. perhaps
Member
Author
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. hmm...no nevermind. We'd only be able to do
Member
Author
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. Perhaps
Member
Author
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. ah, no, I get an error related to overload resolution. Ok will leave for now. |
||
|
|
||
| LLVM_LIBC_FUNCTION(signal_handler, signal, | ||
| (int signum, signal_handler handler)) { | ||
| struct sigaction action, old; | ||
| action.sa_handler = handler; | ||
| action.sa_flags = SA_RESTART; | ||
|
|
||
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.
sure you don't want a
_GNU_SOURCEor whatever your internal equivalent is? (both glibc and bionic have__USE_GNUas the post-<features.h>-inclusion internal equivalent.)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.
No, we don't currently hold folk's code hostage based on them defining
_GNU_SOURCEor not, and I don't plan to add it.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.
i flirted with that myself for bionic, but it's a bit more complicated in practice --- "what when the GNU variant conflicts with the POSIX one?", say, or "what when people are trying to build code that's incompatible with GNU extensions [because they use some of the names themselves, say]"...
(the weird one for Android is
_BSD_SOURCEwhere by historical accident that's always on. but_GNU_SOURCEis something developers are used to turning on/off either via-std=gnu23vs-std=c23or-D/#define.)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.
I was thinking more about this last night, and
qsort_rcame to mind.So I guess I should change my stance slightly from "never" to "perhaps when there is a conflict."
Is there a conflict here? Well,
sig_tandsighandler_tdon't conflict with each other, and the issue isn't as severe asqsort_r. But Bionic provides both without requiring users to pledge allegiance; if bionic doesn't llvm-libc should not either (IMO).But I will keep that in mind that
_GNU_SOURCEand_BSD_SOURCEdo exist more for than just pledges of allegiance and holding user code hostage, and that we may need to deploy those in llvm-libc in the future. I still don't think we need to here (yet; famous last words).Wait...what?!
uh...so perhaps not a bug in clang as the first two statements made me think...but WTF!?
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.
yeah, as you can probably tell, i do think "provide all the things until/unless proven problematic" is a developer-friendly option.
the only real counterargument i've heard is "it's bad for source portability in the other direction". but i've always cared more that people's stuff "just works" when ported to the libc i have control over rather than what might happen when ported away (in part because that's probably less common anyway; any library that's first developed on Android seems likely to be Android-specific in some way, or you'd probably make it cross-platform from the beginning).
oh, yeah, that's it ... i never do this myself, so i can never remember which combinations imply
_GNU_SOURCE, just that there are dragons in that area.madness indeed. (especially because
gnuvscdoes let you opt in/out of language extensions. if you were going to do anything here, consistency would have been nice. i assume there was a historical accident somewhere -- like bionic's always-on_BSD_SOURCEand they just couldn't fix it by the time they realized.)