Skip to content

Commit bdeee86

Browse files
authored
Merge pull request dlang#3617 from hatf0/move-sigusr-to-sigrt
[trivial] Move SIGUSR1/SIGUSR2 to SIGRT for GC Signed-off-by: Dennis <[email protected]> Signed-off-by: Luís Ferreira <[email protected]> Signed-off-by: Razvan Nitu <[email protected]> Merged-on-behalf-of: Nicholas Wilson <[email protected]>
2 parents a63ae87 + a7a3221 commit bdeee86

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

changelog/posix_gc_signals.dd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Posix (excl. Darwin): Switch default GC signals from SIGUSR1/2 to SIGRTMIN/SIGRTMIN+1
2+
3+
As the SIGUSR ones might be used by 'system' libraries (e.g., Android
4+
Dalvik VM or LLVM libFuzzer), while the SIGRT ones are reserved for
5+
user-defined purposes and less likely to collide.
6+
7+
The used signals can still be customized with an early call to
8+
`core.thread.osthread.thread_setGCSignals()`.

src/core/memory.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* Notes_to_implementors:
4040
* $(UL
41-
* $(LI On POSIX systems, the signals SIGUSR1 and SIGUSR2 are reserved
41+
* $(LI On POSIX systems, the signals `SIGRTMIN` and `SIGRTMIN + 1` are reserved
4242
* by this module for use in the garbage collector implementation.
4343
* Typically, they will be used to stop and resume other threads
4444
* when performing a collection, but an implementation may choose

src/core/thread/osthread.d

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ version (CoreDdoc)
11851185
{
11861186
/**
11871187
* Instruct the thread module, when initialized, to use a different set of
1188-
* signals besides SIGUSR1 and SIGUSR2 for suspension and resumption of threads.
1188+
* signals besides SIGRTMIN and SIGRTMIN + 1 for suspension and resumption of threads.
11891189
* This function should be called at most once, prior to thread_init().
11901190
* This function is Posix-only.
11911191
*/
@@ -1215,8 +1215,8 @@ else version (Posix)
12151215

12161216
version (Posix)
12171217
{
1218-
private __gshared int suspendSignalNumber = SIGUSR1;
1219-
private __gshared int resumeSignalNumber = SIGUSR2;
1218+
private __gshared int suspendSignalNumber;
1219+
private __gshared int resumeSignalNumber;
12201220
}
12211221

12221222
private extern (D) ThreadBase attachThread(ThreadBase _thisThread) @nogc nothrow
@@ -1937,11 +1937,6 @@ extern (C) void thread_init() @nogc
19371937
initLowlevelThreads();
19381938
Thread.initLocks();
19391939

1940-
// The Android VM runtime intercepts SIGUSR1 and apparently doesn't allow
1941-
// its signal handler to run, so swap the two signals on Android, since
1942-
// thread_resumeHandler does nothing.
1943-
version (Android) thread_setGCSignals(SIGUSR2, SIGUSR1);
1944-
19451940
version (Darwin)
19461941
{
19471942
// thread id different in forked child process
@@ -1957,6 +1952,16 @@ extern (C) void thread_init() @nogc
19571952
}
19581953
else version (Posix)
19591954
{
1955+
if ( suspendSignalNumber == 0 )
1956+
{
1957+
suspendSignalNumber = SIGRTMIN;
1958+
}
1959+
1960+
if ( resumeSignalNumber == 0 )
1961+
{
1962+
resumeSignalNumber = SIGRTMIN + 1;
1963+
assert(resumeSignalNumber <= SIGRTMAX);
1964+
}
19601965
int status;
19611966
sigaction_t suspend = void;
19621967
sigaction_t resume = void;

0 commit comments

Comments
 (0)