Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/posix_gc_signals.dd
Original file line number Diff line number Diff line change
@@ -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()`.
2 changes: 1 addition & 1 deletion src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions src/core/thread/osthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down