diff --git a/changelog/posix_gc_signals.dd b/changelog/posix_gc_signals.dd new file mode 100644 index 0000000000..80f07cb3be --- /dev/null +++ b/changelog/posix_gc_signals.dd @@ -0,0 +1,8 @@ +Posix (excl. Darwin): Switch default GC signals from SIGUSR1/2 to SIGRTMIN/SIGRTMIN+1 + +As the SIGUSR ones might be used by 'system' libraries (e.g., Android +Dalvik VM or LLVM libFuzzer), while the SIGRT ones are reserved for +user-defined purposes and less likely to collide. + +The used signals can still be customized with an early call to +`core.thread.osthread.thread_setGCSignals()`. diff --git a/src/core/memory.d b/src/core/memory.d index b63b11100c..7d1356af0b 100644 --- a/src/core/memory.d +++ b/src/core/memory.d @@ -38,7 +38,7 @@ * * Notes_to_implementors: * $(UL - * $(LI On POSIX systems, the signals SIGUSR1 and SIGUSR2 are reserved + * $(LI On POSIX systems, the signals `SIGRTMIN` and `SIGRTMIN + 1` are reserved * by this module for use in the garbage collector implementation. * Typically, they will be used to stop and resume other threads * when performing a collection, but an implementation may choose diff --git a/src/core/thread/osthread.d b/src/core/thread/osthread.d index d531d0674c..6c889d3b9c 100644 --- a/src/core/thread/osthread.d +++ b/src/core/thread/osthread.d @@ -1185,7 +1185,7 @@ version (CoreDdoc) { /** * Instruct the thread module, when initialized, to use a different set of - * signals besides SIGUSR1 and SIGUSR2 for suspension and resumption of threads. + * signals besides SIGRTMIN and SIGRTMIN + 1 for suspension and resumption of threads. * This function should be called at most once, prior to thread_init(). * This function is Posix-only. */ @@ -1215,8 +1215,8 @@ else version (Posix) version (Posix) { - private __gshared int suspendSignalNumber = SIGUSR1; - private __gshared int resumeSignalNumber = SIGUSR2; + private __gshared int suspendSignalNumber; + private __gshared int resumeSignalNumber; } private extern (D) ThreadBase attachThread(ThreadBase _thisThread) @nogc nothrow @@ -1937,11 +1937,6 @@ extern (C) void thread_init() @nogc initLowlevelThreads(); Thread.initLocks(); - // The Android VM runtime intercepts SIGUSR1 and apparently doesn't allow - // its signal handler to run, so swap the two signals on Android, since - // thread_resumeHandler does nothing. - version (Android) thread_setGCSignals(SIGUSR2, SIGUSR1); - version (Darwin) { // thread id different in forked child process @@ -1957,6 +1952,16 @@ extern (C) void thread_init() @nogc } else version (Posix) { + if ( suspendSignalNumber == 0 ) + { + suspendSignalNumber = SIGRTMIN; + } + + if ( resumeSignalNumber == 0 ) + { + resumeSignalNumber = SIGRTMIN + 1; + assert(resumeSignalNumber <= SIGRTMAX); + } int status; sigaction_t suspend = void; sigaction_t resume = void;