The OpenD Programming Language

1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2009.
5  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6  * Authors:   Sean Kelly,
7               Alex Rønne Petersen
8  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9  * Source:    $(DRUNTIMESRC core/sys/posix/_signal.d)
10  */
11 
12 module core.sys.posix.signal;
13 
14 import core.sys.posix.config;
15 public import core.stdc.signal;
16 public import core.sys.posix.sys.types; // for pid_t
17 public import core.sys.posix.time; // for timespec
18 
19 version (OSX)
20     version = Darwin;
21 else version (iOS)
22     version = Darwin;
23 else version (TVOS)
24     version = Darwin;
25 else version (WatchOS)
26     version = Darwin;
27 
28 version (ARM)     version = ARM_Any;
29 version (AArch64) version = ARM_Any;
30 version (HPPA)    version = HPPA_Any;
31 version (MIPS32)  version = MIPS_Any;
32 version (MIPS64)  version = MIPS_Any;
33 version (PPC)     version = PPC_Any;
34 version (PPC64)   version = PPC_Any;
35 version (RISCV32) version = RISCV_Any;
36 version (RISCV64) version = RISCV_Any;
37 version (S390)    version = IBMZ_Any;
38 version (SPARC)   version = SPARC_Any;
39 version (SPARC64) version = SPARC_Any;
40 version (SystemZ) version = IBMZ_Any;
41 version (X86)     version = X86_Any;
42 version (X86_64)  version = X86_Any;
43 
44 version (Posix):
45 extern (C):
46 //nothrow:  // this causes http://issues.dlang.org/show_bug.cgi?id=12738 (which has been fixed)
47 //@system:
48 
49 //
50 // Required
51 //
52 /*
53 SIG_DFL (defined in core.stdc.signal)
54 SIG_ERR (defined in core.stdc.signal)
55 SIG_IGN (defined in core.stdc.signal)
56 
57 sig_atomic_t (defined in core.stdc.signal)
58 
59 SIGEV_NONE
60 SIGEV_SIGNAL
61 SIGEV_THREAD
62 
63 union sigval
64 {
65     int   sival_int;
66     void* sival_ptr;
67 }
68 
69 SIGRTMIN
70 SIGRTMAX
71 
72 SIGABRT (defined in core.stdc.signal)
73 SIGALRM
74 SIGBUS
75 SIGCHLD
76 SIGCONT
77 SIGFPE (defined in core.stdc.signal)
78 SIGHUP
79 SIGILL (defined in core.stdc.signal)
80 SIGINT (defined in core.stdc.signal)
81 SIGKILL
82 SIGPIPE
83 SIGQUIT
84 SIGSEGV (defined in core.stdc.signal)
85 SIGSTOP
86 SIGTERM (defined in core.stdc.signal)
87 SIGTSTP
88 SIGTTIN
89 SIGTTOU
90 SIGUSR1
91 SIGUSR2
92 SIGURG
93 
94 struct sigaction_t
95 {
96     sigfn_t     sa_handler;
97     sigset_t    sa_mask;
98     sigactfn_t  sa_sigaction;
99 }
100 
101 sigfn_t signal(int sig, sigfn_t func); (defined in core.stdc.signal)
102 int raise(int sig);                    (defined in core.stdc.signal)
103 */
104 
105 //SIG_DFL (defined in core.stdc.signal)
106 //SIG_ERR (defined in core.stdc.signal)
107 //SIG_IGN (defined in core.stdc.signal)
108 
109 //sig_atomic_t (defined in core.stdc.signal)
110 
111 private alias void function(int) sigfn_t;
112 private alias void function(int, siginfo_t*, void*) sigactfn_t;
113 
114 // nothrow versions
115 nothrow @nogc
116 {
117     private alias void function(int) sigfn_t2;
118     private alias void function(int, siginfo_t*, void*) sigactfn_t2;
119 }
120 
121 enum
122 {
123   SIGEV_SIGNAL,
124   SIGEV_NONE,
125   SIGEV_THREAD
126 }
127 
128 union sigval
129 {
130     int     sival_int;
131     void*   sival_ptr;
132 }
133 
134 version (Solaris)
135 {
136     import core.sys.posix.unistd;
137 
138     @property int SIGRTMIN() nothrow @nogc {
139         __gshared static int sig = -1;
140         if (sig == -1) {
141             sig = cast(int)sysconf(_SC_SIGRT_MIN);
142         }
143         return sig;
144     }
145 
146     @property int SIGRTMAX() nothrow @nogc {
147         __gshared static int sig = -1;
148         if (sig == -1) {
149             sig = cast(int)sysconf(_SC_SIGRT_MAX);
150         }
151         return sig;
152     }
153 }
154 else version (FreeBSD)
155 {
156     // Note: it appears that FreeBSD (prior to 7) and OSX do not support realtime signals
157     // https://github.com/freebsd/freebsd/blob/e79c62ff68fc74d88cb6f479859f6fae9baa5101/sys/sys/signal.h#L117
158     enum SIGRTMIN = 65;
159     enum SIGRTMAX = 126;
160 }
161 else version (DragonFlyBSD)
162 {
163     enum SIGRTMIN = 35;
164     enum SIGRTMAX = 126;
165 }
166 else version (NetBSD)
167 {
168     enum SIGRTMIN = 33;
169     enum SIGRTMAX = 63;
170 }
171 else version (linux)
172 {
173     // Note: CRuntime_Bionic switched to calling these functions
174     // since Lollipop, and Glibc, UClib and Musl all implement them
175     // the same way since it's part of LSB.
176     private extern (C) nothrow @nogc
177     {
178         int __libc_current_sigrtmin();
179         int __libc_current_sigrtmax();
180     }
181 
182     @property int SIGRTMIN() nothrow @nogc @system {
183         __gshared static int sig = -1;
184         if (sig == -1) {
185             sig = __libc_current_sigrtmin();
186         }
187         return sig;
188     }
189 
190     @property int SIGRTMAX() nothrow @nogc @system {
191         __gshared static int sig = -1;
192         if (sig == -1) {
193             sig = __libc_current_sigrtmax();
194         }
195         return sig;
196     }
197 }
198 
199 version (linux)
200 {
201     version (X86_Any)
202     {
203         //SIGABRT (defined in core.stdc.signal)
204         enum SIGALRM    = 14;
205         enum SIGBUS     = 7;
206         enum SIGCHLD    = 17;
207         enum SIGCONT    = 18;
208         //SIGFPE (defined in core.stdc.signal)
209         enum SIGHUP     = 1;
210         //SIGILL (defined in core.stdc.signal)
211         //SIGINT (defined in core.stdc.signal)
212         enum SIGKILL    = 9;
213         enum SIGPIPE    = 13;
214         enum SIGQUIT    = 3;
215         //SIGSEGV (defined in core.stdc.signal)
216         enum SIGSTOP    = 19;
217         //SIGTERM (defined in core.stdc.signal)
218         enum SIGTSTP    = 20;
219         enum SIGTTIN    = 21;
220         enum SIGTTOU    = 22;
221         enum SIGUSR1    = 10;
222         enum SIGUSR2    = 12;
223         enum SIGURG     = 23;
224     }
225     else version (HPPA_Any)
226     {
227         //SIGABRT (defined in core.stdc.signal)
228         enum SIGALRM    = 14;
229         enum SIGBUS     = 10;
230         enum SIGCHLD    = 18;
231         enum SIGCONT    = 26;
232         //SIGFPE (defined in core.stdc.signal)
233         enum SIGHUP     = 1;
234         //SIGILL (defined in core.stdc.signal)
235         //SIGINT (defined in core.stdc.signal)
236         enum SIGKILL    = 9;
237         enum SIGPIPE    = 13;
238         enum SIGQUIT    = 3;
239         //SIGSEGV (defined in core.stdc.signal)
240         enum SIGSTOP    = 24;
241         //SIGTERM (defined in core.stdc.signal)
242         enum SIGTSTP    = 25;
243         enum SIGTTIN    = 27;
244         enum SIGTTOU    = 28;
245         enum SIGUSR1    = 16;
246         enum SIGUSR2    = 17;
247         enum SIGURG     = 29;
248     }
249     else version (MIPS_Any)
250     {
251         //SIGABRT (defined in core.stdc.signal)
252         enum SIGALRM    = 14;
253         enum SIGBUS     = 10;
254         enum SIGCHLD    = 18;
255         enum SIGCONT    = 25;
256         //SIGFPE (defined in core.stdc.signal)
257         enum SIGHUP     = 1;
258         //SIGILL (defined in core.stdc.signal)
259         //SIGINT (defined in core.stdc.signal)
260         enum SIGKILL    = 9;
261         enum SIGPIPE    = 13;
262         enum SIGQUIT    = 3;
263         //SIGSEGV (defined in core.stdc.signal)
264         enum SIGSTOP    = 23;
265         //SIGTERM (defined in core.stdc.signal)
266         enum SIGTSTP    = 24;
267         enum SIGTTIN    = 26;
268         enum SIGTTOU    = 27;
269         enum SIGUSR1    = 16;
270         enum SIGUSR2    = 17;
271         enum SIGURG     = 21;
272     }
273     else version (PPC_Any)
274     {
275         //SIGABRT (defined in core.stdc.signal)
276         enum SIGALRM    = 14;
277         enum SIGBUS     = 7;
278         enum SIGCHLD    = 17;
279         enum SIGCONT    = 18;
280         //SIGFPE (defined in core.stdc.signal)
281         enum SIGHUP     = 1;
282         //SIGILL (defined in core.stdc.signal)
283         //SIGINT (defined in core.stdc.signal)
284         enum SIGKILL    = 9;
285         enum SIGPIPE    = 13;
286         enum SIGQUIT    = 3;
287         //SIGSEGV (defined in core.stdc.signal)
288         enum SIGSTOP    = 19;
289         //SIGTERM (defined in core.stdc.signal)
290         enum SIGTSTP    = 20;
291         enum SIGTTIN    = 21;
292         enum SIGTTOU    = 22;
293         enum SIGUSR1    = 10;
294         enum SIGUSR2    = 12;
295         enum SIGURG     = 23;
296     }
297     else version (ARM_Any)
298     {
299         //SIGABRT (defined in core.stdc.signal)
300         enum SIGALRM    = 14;
301         enum SIGBUS     = 7;
302         enum SIGCHLD    = 17;
303         enum SIGCONT    = 18;
304         //SIGFPE (defined in core.stdc.signal)
305         enum SIGHUP     = 1;
306         //SIGILL (defined in core.stdc.signal)
307         //SIGINT (defined in core.stdc.signal)
308         enum SIGKILL    = 9;
309         enum SIGPIPE    = 13;
310         enum SIGQUIT    = 3;
311         //SIGSEGV (defined in core.stdc.signal)
312         enum SIGSTOP    = 19;
313         //SIGTERM (defined in core.stdc.signal)
314         enum SIGTSTP    = 20;
315         enum SIGTTIN    = 21;
316         enum SIGTTOU    = 22;
317         enum SIGUSR1    = 10;
318         enum SIGUSR2    = 12;
319         enum SIGURG     = 23;
320     }
321     else version (RISCV_Any)
322     {
323         //SIGABRT (defined in core.stdc.signal)
324         enum SIGALRM    = 14;
325         enum SIGBUS     = 7;
326         enum SIGCHLD    = 17;
327         enum SIGCONT    = 18;
328         //SIGFPE (defined in core.stdc.signal)
329         enum SIGHUP     = 1;
330         //SIGILL (defined in core.stdc.signal)
331         //SIGINT (defined in core.stdc.signal)
332         enum SIGKILL    = 9;
333         enum SIGPIPE    = 13;
334         enum SIGQUIT    = 3;
335         //SIGSEGV (defined in core.stdc.signal)
336         enum SIGSTOP    = 19;
337         //SIGTERM (defined in core.stdc.signal)
338         enum SIGTSTP    = 20;
339         enum SIGTTIN    = 21;
340         enum SIGTTOU    = 22;
341         enum SIGUSR1    = 10;
342         enum SIGUSR2    = 12;
343         enum SIGURG     = 23;
344     }
345     else version (SPARC_Any)
346     {
347         //SIGABRT (defined in core.stdc.signal)
348         enum SIGALRM    = 14;
349         enum SIGBUS     = 10;
350         enum SIGCHLD    = 20;
351         enum SIGCONT    = 19;
352         //SIGFPE (defined in core.stdc.signal)
353         enum SIGHUP     = 1;
354         //SIGILL (defined in core.stdc.signal)
355         //SIGINT (defined in core.stdc.signal)
356         enum SIGKILL    = 9;
357         enum SIGPIPE    = 13;
358         enum SIGQUIT    = 3;
359         //SIGSEGV (defined in core.stdc.signal)
360         enum SIGSTOP    = 17;
361         //SIGTERM (defined in core.stdc.signal)
362         enum SIGTSTP    = 18;
363         enum SIGTTIN    = 21;
364         enum SIGTTOU    = 22;
365         enum SIGUSR1    = 30;
366         enum SIGUSR2    = 31;
367         enum SIGURG     = 16;
368     }
369     else version (IBMZ_Any)
370     {
371         //SIGABRT (defined in core.stdc.signal)
372         enum SIGALRM    = 14;
373         enum SIGBUS     = 7;
374         enum SIGCHLD    = 17;
375         enum SIGCONT    = 18;
376         //SIGFPE (defined in core.stdc.signal)
377         enum SIGHUP     = 1;
378         //SIGILL (defined in core.stdc.signal)
379         //SIGINT (defined in core.stdc.signal)
380         enum SIGKILL    = 9;
381         enum SIGPIPE    = 13;
382         enum SIGQUIT    = 3;
383         //SIGSEGV (defined in core.stdc.signal)
384         enum SIGSTOP    = 19;
385         //SIGTERM (defined in core.stdc.signal)
386         enum SIGTSTP    = 20;
387         enum SIGTTIN    = 21;
388         enum SIGTTOU    = 22;
389         enum SIGUSR1    = 10;
390         enum SIGUSR2    = 12;
391         enum SIGURG     = 23;
392     }
393     else version (LoongArch64)
394     {
395         //SIGABRT (defined in core.stdc.signal)
396         enum SIGALRM    = 14;
397         enum SIGBUS     = 7;
398         enum SIGCHLD    = 17;
399         enum SIGCONT    = 18;
400         //SIGFPE (defined in core.stdc.signal)
401         enum SIGHUP     = 1;
402         //SIGILL (defined in core.stdc.signal)
403         //SIGINT (defined in core.stdc.signal)
404         enum SIGKILL    = 9;
405         enum SIGPIPE    = 13;
406         enum SIGQUIT    = 3;
407         //SIGSEGV (defined in core.stdc.signal)
408         enum SIGSTOP    = 19;
409         //SIGTERM (defined in core.stdc.signal)
410         enum SIGTSTP    = 20;
411         enum SIGTTIN    = 21;
412         enum SIGTTOU    = 22;
413         enum SIGUSR1    = 10;
414         enum SIGUSR2    = 12;
415         enum SIGURG     = 23;
416     }
417     else
418         static assert(0, "unimplemented");
419 }
420 else version (Darwin)
421 {
422     //SIGABRT (defined in core.stdc.signal)
423     enum SIGALRM    = 14;
424     enum SIGBUS     = 10;
425     enum SIGCHLD    = 20;
426     enum SIGCONT    = 19;
427     //SIGFPE (defined in core.stdc.signal)
428     enum SIGHUP     = 1;
429     //SIGILL (defined in core.stdc.signal)
430     //SIGINT (defined in core.stdc.signal)
431     enum SIGKILL    = 9;
432     enum SIGPIPE    = 13;
433     enum SIGQUIT    = 3;
434     //SIGSEGV (defined in core.stdc.signal)
435     enum SIGSTOP    = 17;
436     //SIGTERM (defined in core.stdc.signal)
437     enum SIGTSTP    = 18;
438     enum SIGTTIN    = 21;
439     enum SIGTTOU    = 22;
440     enum SIGUSR1    = 30;
441     enum SIGUSR2    = 31;
442     enum SIGURG     = 16;
443 }
444 else version (FreeBSD)
445 {
446     //SIGABRT (defined in core.stdc.signal)
447     enum SIGALRM    = 14;
448     enum SIGBUS     = 10;
449     enum SIGCHLD    = 20;
450     enum SIGCONT    = 19;
451     //SIGFPE (defined in core.stdc.signal)
452     enum SIGHUP     = 1;
453     //SIGILL (defined in core.stdc.signal)
454     //SIGINT (defined in core.stdc.signal)
455     enum SIGKILL    = 9;
456     enum SIGPIPE    = 13;
457     enum SIGQUIT    = 3;
458     //SIGSEGV (defined in core.stdc.signal)
459     enum SIGSTOP    = 17;
460     //SIGTERM (defined in core.stdc.signal)
461     enum SIGTSTP    = 18;
462     enum SIGTTIN    = 21;
463     enum SIGTTOU    = 22;
464     enum SIGUSR1    = 30;
465     enum SIGUSR2    = 31;
466     enum SIGURG     = 16;
467 }
468 else version (NetBSD)
469 {
470     //SIGABRT (defined in core.stdc.signal)
471     enum SIGALRM    = 14;
472     enum SIGBUS     = 10;
473     enum SIGCHLD    = 20;
474     enum SIGCONT    = 19;
475     //SIGFPE (defined in core.stdc.signal)
476     enum SIGHUP     = 1;
477     //SIGILL (defined in core.stdc.signal)
478     //SIGINT (defined in core.stdc.signal)
479     enum SIGKILL    = 9;
480     enum SIGPIPE    = 13;
481     enum SIGQUIT    = 3;
482     //SIGSEGV (defined in core.stdc.signal)
483     enum SIGSTOP    = 17;
484     //SIGTERM (defined in core.stdc.signal)
485     enum SIGTSTP    = 18;
486     enum SIGTTIN    = 21;
487     enum SIGTTOU    = 22;
488     enum SIGUSR1    = 30;
489     enum SIGUSR2    = 31;
490     enum SIGURG     = 16;
491 }
492 else version (OpenBSD)
493 {
494     //SIGABRT (defined in core.stdc.signal)
495     enum SIGALRM    = 14;
496     enum SIGBUS     = 10;
497     enum SIGCHLD    = 20;
498     enum SIGCONT    = 19;
499     //SIGFPE (defined in core.stdc.signal)
500     enum SIGHUP     = 1;
501     //SIGILL (defined in core.stdc.signal)
502     //SIGINT (defined in core.stdc.signal)
503     enum SIGKILL    = 9;
504     enum SIGPIPE    = 13;
505     enum SIGQUIT    = 3;
506     //SIGSEGV (defined in core.stdc.signal)
507     enum SIGSTOP    = 17;
508     //SIGTERM (defined in core.stdc.signal)
509     enum SIGTSTP    = 18;
510     enum SIGTTIN    = 21;
511     enum SIGTTOU    = 22;
512     enum SIGUSR1    = 30;
513     enum SIGUSR2    = 31;
514     enum SIGURG     = 16;
515 }
516 else version (DragonFlyBSD)
517 {
518     //SIGABRT (defined in core.stdc.signal)
519     enum SIGALRM    = 14;
520     enum SIGBUS     = 10;
521     enum SIGCHLD    = 20;
522     enum SIGCONT    = 19;
523     //SIGFPE (defined in core.stdc.signal)
524     enum SIGHUP     = 1;
525     //SIGILL (defined in core.stdc.signal)
526     //SIGINT (defined in core.stdc.signal)
527     enum SIGKILL    = 9;
528     enum SIGPIPE    = 13;
529     enum SIGQUIT    = 3;
530     //SIGSEGV (defined in core.stdc.signal)
531     enum SIGSTOP    = 17;
532     //SIGTERM (defined in core.stdc.signal)
533     enum SIGTSTP    = 18;
534     enum SIGTTIN    = 21;
535     enum SIGTTOU    = 22;
536     enum SIGUSR1    = 30;
537     enum SIGUSR2    = 31;
538     enum SIGURG     = 16;
539 }
540 else version (Solaris)
541 {
542     //SIGABRT (defined in core.stdc.signal)
543     enum SIGALRM = 14;
544     enum SIGBUS = 10;
545     enum SIGCHLD = 18;
546     enum SIGCONT = 25;
547     //SIGFPE (defined in core.stdc.signal)
548     enum SIGHUP = 1;
549     //SIGILL (defined in core.stdc.signal)
550     //SIGINT (defined in core.stdc.signal)
551     enum SIGKILL = 9;
552     enum SIGPIPE = 13;
553     enum SIGQUIT = 3;
554     //SIGSEGV (defined in core.stdc.signal)
555     enum SIGSTOP = 23;
556     //SIGTERM (defined in core.stdc.signal)
557     enum SIGTSTP = 24;
558     enum SIGTTIN = 26;
559     enum SIGTTOU = 27;
560     enum SIGUSR1 = 16;
561     enum SIGUSR2 = 17;
562     enum SIGURG = 21;
563 }
564 else
565 {
566     static assert(false, "Unsupported platform");
567 }
568 
569 version (linux)
570 {
571     version (CRuntime_Musl)
572     {
573         struct sigaction_t
574         {
575             union
576             {
577                 sigfn_t     sa_handler;
578                 sigactfn_t  sa_sigaction;
579             }
580             sigset_t        sa_mask;
581             int             sa_flags;
582             void function() sa_restorer;
583         }
584     }
585     else version (CRuntime_Bionic)
586     {
587         version (D_LP64)
588         {
589             struct sigaction_t
590             {
591                 int            sa_flags;
592                 union
593                 {
594                     sigfn_t    sa_handler;
595                     sigactfn_t sa_sigaction;
596                 }
597                 sigset_t        sa_mask;
598                 void function() sa_restorer;
599         }
600         }
601         else
602         {
603             struct sigaction_t
604             {
605                 union
606                 {
607                     sigfn_t    sa_handler;
608                     sigactfn_t sa_sigaction;
609                 }
610                 sigset_t        sa_mask;
611                 int             sa_flags;
612                 void function() sa_restorer;
613             }
614         }
615     }
616     else version (SystemZ)
617     {
618         struct sigaction_t
619         {
620             static if ( true /* __USE_POSIX199309 */ )
621             {
622                 union
623                 {
624                     sigfn_t     sa_handler;
625                     sigactfn_t  sa_sigaction;
626                 }
627             }
628             else
629             {
630                 sigfn_t     sa_handler;
631             }
632             version (CRuntime_Glibc)
633             {
634                 int         __glibc_reserved0;
635                 int         sa_flags;
636             }
637             else
638             {
639                 c_ulong     sa_flags;
640             }
641 
642             void function() sa_restorer;
643 
644             sigset_t        sa_mask;
645         }
646     }
647     else version (HPPA_Any)
648     {
649         struct sigaction_t
650         {
651             static if ( true /* __USE_POSIX199309 */ )
652             {
653                 union
654                 {
655                     sigfn_t     sa_handler;
656                     sigactfn_t  sa_sigaction;
657                 }
658             }
659             else
660             {
661                 sigfn_t     sa_handler;
662             }
663             version (CRuntime_Glibc)
664             {
665                 version (D_LP64)
666                     int     __glibc_reserved0;
667                 int         sa_flags;
668             }
669             else
670             {
671                 c_ulong     sa_flags;
672             }
673             sigset_t        sa_mask;
674         }
675     }
676     else version (MIPS_Any)
677     {
678         struct sigaction_t
679         {
680             int sa_flags;
681 
682             static if ( true /* __USE_POSIX199309 */ )
683             {
684                 union
685                 {
686                     sigfn_t     sa_handler;
687                     sigactfn_t  sa_sigaction;
688                 }
689             }
690             else
691             {
692                 sigfn_t     sa_handler;
693             }
694             sigset_t        sa_mask;
695             void function() sa_restorer;
696 
697             version (CRuntime_Glibc)
698             {
699                 static if ((void*).sizeof < 8)
700                     int[1]  sa_resv;
701             }
702         }
703     }
704     else version (SPARC_Any)
705     {
706         struct sigaction_t
707         {
708             static if ( true /* __USE_POSIX199309 */ )
709             {
710                 union
711                 {
712                     sigfn_t     sa_handler;
713                     sigactfn_t  sa_sigaction;
714                 }
715             }
716             else
717             {
718                 sigfn_t     sa_handler;
719             }
720             version (CRuntime_Glibc)
721             {
722                 sigset_t    sa_mask;
723                 version (D_LP64)
724                     int     __glibc_reserved0;
725                 int         sa_flags;
726                 void function() sa_restorer;
727             }
728             else
729             {
730                 c_ulong     sa_flags;
731                 void function() sa_restorer;
732                 sigset_t    sa_mask;
733             }
734         }
735     }
736     else
737     {
738         struct sigaction_t
739         {
740             static if ( true /* __USE_POSIX199309 */ )
741             {
742                 union
743                 {
744                     sigfn_t     sa_handler;
745                     sigactfn_t  sa_sigaction;
746                 }
747             }
748             else
749             {
750                 sigfn_t     sa_handler;
751             }
752             sigset_t        sa_mask;
753             int             sa_flags;
754 
755             void function() sa_restorer;
756         }
757     }
758 }
759 else version (FreeBSD)
760 {
761     struct sigaction_t
762     {
763         union
764         {
765             sigfn_t     sa_handler;
766             sigactfn_t  sa_sigaction;
767         }
768         int      sa_flags;
769         sigset_t sa_mask;
770     }
771 }
772 else version (NetBSD)
773 {
774     struct sigaction_t
775     {
776         union
777         {
778             sigfn_t     sa_handler;
779             sigactfn_t  sa_sigaction;
780         }
781         sigset_t sa_mask;
782         int      sa_flags;
783     }
784 }
785 else version (OpenBSD)
786 {
787     struct sigaction_t
788     {
789         union
790         {
791             sigfn_t     __sa_handler;
792             alias sa_handler = __sa_handler;
793             sigactfn_t  __sa_sigaction;
794             alias sa_sigaction = __sa_sigaction;
795         }
796         sigset_t sa_mask;
797         int      sa_flags;
798     }
799 }
800 else version (DragonFlyBSD)
801 {
802     struct sigaction_t
803     {
804         union
805         {
806             sigfn_t     sa_handler;
807             sigactfn_t  sa_sigaction;
808         }
809         int      sa_flags;
810         sigset_t sa_mask;
811     }
812 }
813 else version (Solaris)
814 {
815     struct sigaction_t
816     {
817         int sa_flags;
818 
819         union
820         {
821             sigfn_t sa_handler;
822             sigactfn_t sa_sigaction;
823         }
824 
825         sigset_t sa_mask;
826         version (D_LP64) {}
827         else
828             int[2] sa_resv;
829     }
830 }
831 else version (Darwin)
832 {
833     struct sigaction_t
834     {
835         static if ( true /* __USE_POSIX199309 */ )
836         {
837             union
838             {
839                 sigfn_t     sa_handler;
840                 sigactfn_t  sa_sigaction;
841             }
842         }
843         else
844         {
845             sigfn_t     sa_handler;
846         }
847         sigset_t        sa_mask;
848         int             sa_flags;
849     }
850 }
851 else
852 {
853     static assert(false, "Unsupported platform");
854 }
855 
856 //
857 // C Extension (CX)
858 //
859 /*
860 SIG_HOLD
861 
862 sigset_t
863 pid_t   (defined in core.sys.types)
864 
865 SIGABRT (defined in core.stdc.signal)
866 SIGFPE  (defined in core.stdc.signal)
867 SIGILL  (defined in core.stdc.signal)
868 SIGINT  (defined in core.stdc.signal)
869 SIGSEGV (defined in core.stdc.signal)
870 SIGTERM (defined in core.stdc.signal)
871 
872 SA_NOCLDSTOP (CX|XSI)
873 SIG_BLOCK
874 SIG_UNBLOCK
875 SIG_SETMASK
876 
877 struct siginfo_t
878 {
879     int     si_signo;
880     int     si_code;
881 
882     version (XSI)
883     {
884         int     si_errno;
885         pid_t   si_pid;
886         uid_t   si_uid;
887         void*   si_addr;
888         int     si_status;
889         c_long  si_band;
890     }
891     version (RTS)
892     {
893         sigval  si_value;
894     }
895 }
896 
897 SI_USER
898 SI_QUEUE
899 SI_TIMER
900 SI_ASYNCIO
901 SI_MESGQ
902 */
903 
904 nothrow @nogc
905 {
906 
907 version (linux)
908 {
909     enum SIG_HOLD = cast(sigfn_t2) 2;
910 
911     private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof);
912 
913     struct sigset_t
914     {
915         c_ulong[_SIGSET_NWORDS] __val;
916     }
917 
918     enum SA_NOCLDSTOP   = 1; // (CX|XSI)
919 
920     version (MIPS_Any)
921     {
922         enum SIG_BLOCK      = 1;
923         enum SIG_UNBLOCK    = 2;
924         enum SIG_SETMASK    = 3;
925     }
926     else version (SPARC_Any)
927     {
928         enum SIG_BLOCK      = 1;
929         enum SIG_UNBLOCK    = 2;
930         enum SIG_SETMASK    = 4;
931     }
932     else
933     {
934         enum SIG_BLOCK      = 0;
935         enum SIG_UNBLOCK    = 1;
936         enum SIG_SETMASK    = 2;
937     }
938 
939     private enum __SI_MAX_SIZE = 128;
940 
941     static if ( __WORDSIZE == 64 )
942     {
943         private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4);
944     }
945     else
946     {
947         private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3);
948     }
949 
950     struct siginfo_t
951     {
952         int si_signo;
953         version (MIPS_Any)  // __SI_SWAP_ERRNO_CODE
954         {
955             int si_code;
956             int si_errno;
957         }
958         else
959         {
960             int si_errno;
961             int si_code;
962         }
963 
964         union _sifields_t
965         {
966             int[__SI_PAD_SIZE] _pad;
967 
968             // kill()
969             struct _kill_t
970             {
971                 pid_t si_pid;
972                 uid_t si_uid;
973             } _kill_t _kill;
974             // POSIX.1b timers.
975             struct _timer_t
976             {
977                 int    si_tid;
978                 int    si_overrun;
979                 sigval si_sigval;
980             } _timer_t _timer;
981 
982             // POSIX.1b signals
983             struct _rt_t
984             {
985                 pid_t  si_pid;
986                 uid_t  si_uid;
987                 sigval si_sigval;
988             } _rt_t _rt;
989 
990             // SIGCHLD
991             struct _sigchild_t
992             {
993                 pid_t   si_pid;
994                 uid_t   si_uid;
995                 int     si_status;
996                 clock_t si_utime;
997                 clock_t si_stime;
998             } _sigchild_t _sigchld;
999 
1000             // SIGILL, SIGFPE, SIGSEGV, SIGBUS
1001             struct _sigfault_t
1002             {
1003                 void*     si_addr;
1004             } _sigfault_t _sigfault;
1005 
1006             // SIGPOLL
1007             struct _sigpoll_t
1008             {
1009                 c_long   si_band;
1010                 int      si_fd;
1011             } _sigpoll_t _sigpoll;
1012         } _sifields_t _sifields;
1013 
1014     nothrow @nogc:
1015         @property ref pid_t si_pid() return { return _sifields._kill.si_pid; }
1016         @property ref uid_t si_uid() return { return _sifields._kill.si_uid; }
1017         @property ref void* si_addr() return { return _sifields._sigfault.si_addr; }
1018         @property ref int si_status() return { return _sifields._sigchld.si_status; }
1019         @property ref c_long si_band() return { return _sifields._sigpoll.si_band; }
1020         @property ref sigval si_value() return { return _sifields._rt.si_sigval; }
1021     }
1022 
1023     enum
1024     {
1025         SI_ASYNCNL = -60,
1026         SI_TKILL   = -6,
1027         SI_SIGIO,
1028         SI_ASYNCIO,
1029         SI_MESGQ,
1030         SI_TIMER,
1031         SI_QUEUE,
1032         SI_USER,
1033         SI_KERNEL  = 0x80
1034     }
1035 }
1036 else version (Darwin)
1037 {
1038     enum SIG_HOLD = cast(sigfn_t2) 5;
1039 
1040     alias uint sigset_t;
1041 
1042     enum SA_NOCLDSTOP = 8; // (CX|XSI)
1043 
1044     enum SIG_BLOCK   = 1;
1045     enum SIG_UNBLOCK = 2;
1046     enum SIG_SETMASK = 3;
1047 
1048     struct siginfo_t
1049     {
1050         int     si_signo;
1051         int     si_errno;
1052         int     si_code;
1053         pid_t   si_pid;
1054         uid_t   si_uid;
1055         int     si_status;
1056         void*   si_addr;
1057         sigval  si_value;
1058         int     si_band;
1059         uint[7] pad;
1060     }
1061 
1062     enum SI_USER    = 0x10001;
1063     enum SI_QUEUE   = 0x10002;
1064     enum SI_TIMER   = 0x10003;
1065     enum SI_ASYNCIO = 0x10004;
1066     enum SI_MESGQ   = 0x10005;
1067 }
1068 else version (FreeBSD)
1069 {
1070     enum SIG_HOLD = cast(sigfn_t2) 3;
1071 
1072     struct sigset_t
1073     {
1074         uint[4] __bits;
1075     }
1076 
1077     enum SA_NOCLDSTOP = 8;
1078 
1079     enum SIG_BLOCK = 1;
1080     enum SIG_UNBLOCK = 2;
1081     enum SIG_SETMASK = 3;
1082 
1083     struct siginfo_t
1084     {
1085         int si_signo;
1086         int si_errno;
1087         int si_code;
1088         pid_t si_pid;
1089         uid_t si_uid;
1090         int si_status;
1091         void* si_addr;
1092         sigval si_value;
1093         union __reason
1094         {
1095             struct __fault
1096             {
1097                 int _trapno;
1098             }
1099             __fault _fault;
1100             struct __timer
1101             {
1102                 int _timerid;
1103                 int _overrun;
1104             }
1105             __timer _timer;
1106             struct __mesgq
1107             {
1108                 int _mqd;
1109             }
1110             __mesgq _mesgq;
1111             struct __poll
1112             {
1113                 c_long _band;
1114             }
1115             __poll _poll;
1116             struct ___spare___
1117             {
1118                 c_long __spare1__;
1119                 int[7] __spare2__;
1120             }
1121             ___spare___ __spare__;
1122         }
1123         __reason _reason;
1124 
1125         @property ref c_long si_band() return { return _reason._poll._band; }
1126     }
1127 
1128     enum SI_USER    = 0x10001;
1129     enum SI_QUEUE   = 0x10002;
1130     enum SI_TIMER   = 0x10003;
1131     enum SI_ASYNCIO = 0x10004;
1132     enum SI_MESGQ   = 0x10005;
1133 }
1134 else version (NetBSD)
1135 {
1136     enum SIG_HOLD = cast(sigfn_t2) 3;
1137 
1138     struct sigset_t
1139     {
1140         uint[4] __bits;
1141     }
1142 
1143     enum SA_NOCLDSTOP = 8;
1144 
1145     enum SIG_BLOCK = 1;
1146     enum SIG_UNBLOCK = 2;
1147     enum SIG_SETMASK = 3;
1148 
1149     union sigval_t
1150     {
1151         int   sival_int;
1152         void* sival_ptr;
1153     }
1154 
1155     struct _ksiginfo
1156     {
1157         int     _signo;
1158         int     _code;
1159         int     _errno;
1160         version (D_LP64)
1161             int _pad;
1162 
1163         union reason_t
1164         {
1165             struct rt_t
1166             {
1167                 pid_t    _pid;
1168                 uid_t    _uid;
1169                 sigval_t _value;
1170             } rt_t _rt;
1171             struct child_t
1172             {
1173                 pid_t   _pid;
1174                 uid_t   _uid;
1175                 int     _status;
1176                 clock_t _utime;
1177                 clock_t _stime;
1178             } child_t _child;
1179             struct fault_t
1180             {
1181                 void* _addr;
1182                 int   _trap;
1183                 int   _trap2;
1184                 int   _trap3;
1185             } fault_t fault;
1186             struct poll_t
1187             {
1188                 c_long _band;
1189                 int  _fd;
1190             } poll_t _poll;
1191         }
1192         reason_t _reason;
1193     }
1194 
1195     union siginfo_t
1196     {
1197         ubyte[128] si_pad;
1198         _ksiginfo _info;
1199         @property ref c_long si_band() return { return _info._reason._poll._band; }
1200     }
1201 
1202     enum SI_USER    = 0;
1203     enum SI_QUEUE   = -1;
1204     enum SI_TIMER   = -2;
1205     enum SI_ASYNCIO = -3;
1206     enum SI_MESGQ   = -4;
1207 }
1208 else version (OpenBSD)
1209 {
1210     enum SIG_CATCH = cast(sigfn_t2) 2;
1211     enum SIG_HOLD = cast(sigfn_t2) 3;
1212 
1213     alias sigset_t = uint;
1214 
1215     enum SA_NOCLDSTOP = 0x0008;
1216 
1217     enum SIG_BLOCK = 1;
1218     enum SIG_UNBLOCK = 2;
1219     enum SIG_SETMASK = 3;
1220 
1221     private enum SI_MAXSZ = 128;
1222     private enum SI_PAD = (SI_MAXSZ / int.sizeof) - 3;
1223 
1224     struct siginfo_t
1225     {
1226         int si_signo;
1227         int si_errno;
1228         int si_code;
1229         union _data
1230         {
1231             int[SI_PAD] _pad;
1232             struct _proc
1233             {
1234                 pid_t _pid;
1235                 union _pdata
1236                 {
1237                     struct _kill
1238                     {
1239                         uid_t _uid;
1240                         sigval _value;
1241                     }
1242                     struct _cld
1243                     {
1244                         clock_t _utime;
1245                         clock_t _stime;
1246                         int _status;
1247                     }
1248                 }
1249             }
1250             struct _fault
1251             {
1252                 caddr_t _addr;
1253                 int _trapno;
1254             }
1255         }
1256         alias si_pid     = _data._proc._pid;
1257         alias si_status  = _data._proc._pdata._cld._status;
1258         alias si_stime   = _data._proc._pdata._cld._stime;
1259         alias si_utime   = _data._proc._pdata._cld._utime;
1260         alias si_uid     = _data._proc._pdata._kill._uid;
1261         alias si_value   = _data._proc._pdata._kill._value;
1262         alias si_addr    = _data._fault._addr;
1263         alias si_trapno  = _data._fault._trapno;
1264     }
1265 
1266     enum SI_NOINFO = 32767;
1267     enum SI_USER   = 0;
1268     enum SI_LWP    = -1;
1269     enum SI_QUEUE  = -2;
1270     enum SI_TIMER  = -3;
1271 }
1272 else version (DragonFlyBSD)
1273 {
1274     enum SIG_CATCH = cast(sigfn_t2) 2;
1275     enum SIG_HOLD = cast(sigfn_t2) 3;
1276 
1277     struct sigset_t
1278     {
1279         uint[4] __bits;
1280     }
1281 
1282     enum SA_NOCLDSTOP = 8;
1283 
1284     enum SIG_BLOCK = 1;
1285     enum SIG_UNBLOCK = 2;
1286     enum SIG_SETMASK = 3;
1287 
1288     struct siginfo_t
1289     {
1290         int si_signo;
1291         int si_errno;
1292         int si_code;
1293         int si_pid;
1294         uint si_uid;
1295         int si_status;
1296         void* si_addr;
1297         sigval si_value;
1298         c_long si_band;
1299         int[7]   __spare;
1300     }
1301 
1302     enum SI_UNDEFINED = 0x00000;
1303     enum SI_USER      =  0;
1304     enum SI_QUEUE     = -1;
1305     enum SI_TIMER     = -2;
1306     enum SI_ASYNCIO   = -3;
1307     enum SI_MESGQ     = -4;
1308 }
1309 else version (Solaris)
1310 {
1311     enum SIG_HOLD = cast(sigfn_t2)2;
1312 
1313     struct sigset_t
1314     {
1315         uint[4] __bits;
1316     }
1317 
1318     enum SIG_BLOCK = 1;
1319     enum SIG_UNBLOCK = 2;
1320     enum SIG_SETMASK = 3;
1321 
1322     struct siginfo_t
1323     {
1324         int si_signo;
1325         int si_code;
1326         int si_errno;
1327 
1328         version (D_LP64)
1329             int si_pad;
1330 
1331         union ___data
1332         {
1333             version (D_LP64)
1334                 int[(256 / int.sizeof) - 4] si_pad;
1335             else
1336                 int[(128 / int.sizeof) - 3] si_pad;
1337 
1338             struct ___proc
1339             {
1340                 pid_t __pid;
1341 
1342                 union ___pdata
1343                 {
1344                     struct ___kill
1345                     {
1346                         uid_t __uid;
1347                         sigval __value;
1348                     }
1349 
1350                     ___kill __kill;
1351 
1352                     struct ___cld
1353                     {
1354                         clock_t __utime;
1355                         int __status;
1356                         clock_t __stime;
1357                     }
1358 
1359                     ___cld __cld;
1360                 }
1361 
1362                 ___pdata __pdata;
1363                 ctid_t __ctid;
1364                 zoneid_t __zoneid;
1365             }
1366 
1367             ___proc __proc;
1368 
1369             struct ___fault
1370             {
1371                 void* __addr;
1372                 int __trapno;
1373                 caddr_t __pc;
1374             }
1375 
1376             ___fault __fault;
1377 
1378             struct ___file
1379             {
1380                 int __fd;
1381                 c_long __band;
1382             }
1383 
1384             ___file __file;
1385 
1386             struct ___prof
1387             {
1388                 caddr_t __faddr;
1389                 timestruc_t __tstamp;
1390                 short __syscall;
1391                 char __nsysarg = 0;
1392                 char __fault = 0;
1393                 c_long[8] __sysarg;
1394                 int[10] __mstate;
1395             }
1396 
1397             ___prof __prof;
1398 
1399             struct ___rctl
1400             {
1401                 int __entity;
1402             }
1403 
1404             ___rctl __rctl;
1405         }
1406 
1407         ___data __data;
1408     }
1409 
1410     enum SI_NOINFO  = 32767;
1411     enum SI_DTRACE  = 2050;
1412     enum SI_RCTL    = 2049;
1413     enum SI_USER    = 0;
1414     enum SI_LWP     = -1;
1415     enum SI_QUEUE   = -2;
1416     enum SI_TIMER   = -3;
1417     enum SI_ASYNCIO = -4;
1418     enum SI_MESGQ   = -5;
1419 }
1420 else
1421 {
1422     static assert(false, "Unsupported platform");
1423 }
1424 
1425 /*
1426 int kill(pid_t, int);
1427 int sigaction(int, const scope sigaction_t*, sigaction_t*);
1428 int sigaddset(sigset_t*, int);
1429 int sigdelset(sigset_t*, int);
1430 int sigemptyset(sigset_t*);
1431 int sigfillset(sigset_t*);
1432 int sigismember(const scope sigset_t*, int);
1433 int sigpending(sigset_t*);
1434 int sigprocmask(int, const scope sigset_t*, sigset_t*);
1435 int sigsuspend(const scope sigset_t*);
1436 int sigwait(const scope sigset_t*, int*);
1437 */
1438 
1439 version (CRuntime_Glibc)
1440 {
1441     int kill(pid_t, int);
1442     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1443     int sigaddset(sigset_t*, int);
1444     int sigdelset(sigset_t*, int);
1445     int sigemptyset(sigset_t*);
1446     int sigfillset(sigset_t*);
1447     int sigismember(const scope sigset_t*, int);
1448     int sigpending(sigset_t*);
1449     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1450     int sigsuspend(const scope sigset_t*);
1451     int sigwait(const scope sigset_t*, int*);
1452 }
1453 else version (Darwin)
1454 {
1455     int kill(pid_t, int);
1456     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1457     int sigaddset(sigset_t*, int);
1458     int sigdelset(sigset_t*, int);
1459     int sigemptyset(sigset_t*);
1460     int sigfillset(sigset_t*);
1461     int sigismember(const scope sigset_t*, int);
1462     int sigpending(sigset_t*);
1463     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1464     int sigsuspend(const scope sigset_t*);
1465     int sigwait(const scope sigset_t*, int*);
1466 }
1467 else version (FreeBSD)
1468 {
1469     int kill(pid_t, int);
1470     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1471     int sigaddset(sigset_t*, int);
1472     int sigdelset(sigset_t*, int);
1473     int sigemptyset(sigset_t *);
1474     int sigfillset(sigset_t *);
1475     int sigismember(const scope sigset_t*, int);
1476     int sigpending(sigset_t *);
1477     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1478     int sigsuspend(const scope sigset_t*);
1479     int sigwait(const scope sigset_t*, int*);
1480 }
1481 else version (NetBSD)
1482 {
1483     int kill(pid_t, int);
1484     int __sigaction14(int, const scope sigaction_t*, sigaction_t*);
1485     int __sigaddset14(sigset_t*, int);
1486     int __sigdelset14(sigset_t*, int);
1487     int __sigemptyset14(sigset_t *);
1488     int __sigfillset14(sigset_t *);
1489     int __sigismember14(const scope sigset_t*, int);
1490     int __sigpending14(sigset_t *);
1491     int __sigprocmask14(int, const scope sigset_t*, sigset_t*);
1492     int __sigsuspend14(const scope sigset_t*);
1493     int sigwait(const scope sigset_t*, int*);
1494 
1495     alias __sigaction14 sigaction;
1496     alias __sigaddset14 sigaddset;
1497     alias __sigdelset14 sigdelset;
1498     alias __sigemptyset14 sigemptyset;
1499     alias __sigfillset14 sigfillset;
1500     alias __sigismember14 sigismember;
1501     alias __sigpending14 sigpending;
1502     alias __sigprocmask14 sigprocmask;
1503     alias __sigsuspend14 sigsuspend;
1504 }
1505 else version (OpenBSD)
1506 {
1507     int kill(pid_t, int);
1508     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1509     int sigaddset(sigset_t*, int);
1510     int sigdelset(sigset_t*, int);
1511     int sigemptyset(sigset_t *);
1512     int sigfillset(sigset_t *);
1513     int sigismember(const scope sigset_t*, int);
1514     int sigpending(sigset_t *);
1515     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1516     int sigsuspend(const scope sigset_t*);
1517     int sigwait(const scope sigset_t*, int*);
1518 }
1519 else version (DragonFlyBSD)
1520 {
1521     int kill(pid_t, int);
1522     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1523     int sigaddset(sigset_t*, int);
1524     int sigdelset(sigset_t*, int);
1525     int sigemptyset(sigset_t *);
1526     int sigfillset(sigset_t *);
1527     int sigismember(const scope sigset_t*, int);
1528     int sigpending(sigset_t *);
1529     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1530     int sigsuspend(const scope sigset_t*);
1531     int sigwait(const scope sigset_t*, int*);
1532 }
1533 else version (Solaris)
1534 {
1535     int kill(pid_t, int);
1536     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1537     int sigaddset(sigset_t*, int);
1538     int sigdelset(sigset_t*, int);
1539     int sigemptyset(sigset_t*);
1540     int sigfillset(sigset_t*);
1541     int sigismember(const scope sigset_t*, int);
1542     int sigpending(sigset_t*);
1543     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1544     int sigsuspend(const scope sigset_t*);
1545     int sigwait(const scope sigset_t*, int*);
1546 }
1547 else version (CRuntime_Bionic)
1548 {
1549     public import core.sys.posix.time: timer_t;
1550     import core.stdc.string : memset;
1551 
1552     version (X86)
1553         enum int LONG_BIT = 32;
1554     else version (ARM)
1555         enum int LONG_BIT = 32;
1556     else version (AArch64)
1557         enum int LONG_BIT = 64;
1558     else version (X86_64)
1559         enum int LONG_BIT = 64;
1560     else
1561         static assert(false, "Architecture not supported.");
1562 
1563     int kill(pid_t, int);
1564     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1565 
1566     // These functions are defined inline in bionic.
1567     int sigaddset(sigset_t* set, int signum) @system
1568     {
1569         c_ulong* local_set = cast(c_ulong*) set;
1570         signum--;
1571         local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
1572         return 0;
1573     }
1574 
1575     int sigdelset(sigset_t* set, int signum) @system
1576     {
1577         c_ulong* local_set = cast(c_ulong*) set;
1578         signum--;
1579         local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
1580         return 0;
1581     }
1582 
1583     int sigemptyset(sigset_t* set) { memset(set, 0, (*set).sizeof); return 0; }
1584 
1585     int sigfillset(sigset_t* set) { memset(set, ~0, (*set).sizeof); return 0; }
1586 
1587     int sigismember(sigset_t* set, int signum) @system
1588     {
1589         c_ulong* local_set = cast(c_ulong*) set;
1590         signum--;
1591         return cast(int) ((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
1592     }
1593 
1594     int sigpending(sigset_t*);
1595     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1596     int sigsuspend(const scope sigset_t*);
1597     int sigwait(const scope sigset_t*, int*);
1598 }
1599 else version (CRuntime_Musl)
1600 {
1601     int kill(pid_t, int);
1602     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1603     int sigaddset(sigset_t*, int);
1604     int sigdelset(sigset_t*, int);
1605     int sigemptyset(sigset_t*);
1606     int sigfillset(sigset_t*);
1607     int sigismember(const scope sigset_t*, int);
1608     int sigpending(sigset_t*);
1609     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1610     int sigsuspend(const scope sigset_t*);
1611     int sigwait(const scope sigset_t*, int*);
1612 }
1613 else version (CRuntime_UClibc)
1614 {
1615     int kill(pid_t, int);
1616     int sigaction(int, const scope sigaction_t*, sigaction_t*);
1617     int sigaddset(sigset_t*, int);
1618     int sigdelset(sigset_t*, int);
1619     int sigemptyset(sigset_t*);
1620     int sigfillset(sigset_t*);
1621     int sigismember(const scope sigset_t*, int);
1622     int sigpending(sigset_t*);
1623     int sigprocmask(int, const scope sigset_t*, sigset_t*);
1624     int sigsuspend(const scope sigset_t*);
1625     int sigwait(const scope sigset_t*, int*);
1626 }
1627 else
1628 {
1629     static assert(false, "Unsupported platform");
1630 }
1631 }
1632 
1633 //
1634 // XOpen (XSI)
1635 //
1636 /*
1637 SIGPOLL
1638 SIGPROF
1639 SIGSYS
1640 SIGTRAP
1641 SIGVTALRM
1642 SIGXCPU
1643 SIGXFSZ
1644 
1645 SA_ONSTACK
1646 SA_RESETHAND
1647 SA_RESTART
1648 SA_SIGINFO
1649 SA_NOCLDWAIT
1650 SA_NODEFER
1651 
1652 ILL_ILLOPC
1653 ILL_ILLOPN
1654 ILL_ILLADR
1655 ILL_ILLTRP
1656 ILL_PRVOPC
1657 ILL_PRVREG
1658 ILL_COPROC
1659 ILL_BADSTK
1660 
1661 FPE_INTDIV
1662 FPE_INTOVF
1663 FPE_FLTDIV
1664 FPE_FLTOVF
1665 FPE_FLTUND
1666 FPE_FLTRES
1667 FPE_FLTINV
1668 FPE_FLTSUB
1669 
1670 SEGV_MAPERR
1671 SEGV_ACCERR
1672 
1673 BUS_ADRALN
1674 BUS_ADRERR
1675 BUS_OBJERR
1676 
1677 TRAP_BRKPT
1678 TRAP_TRACE
1679 
1680 CLD_EXITED
1681 CLD_KILLED
1682 CLD_DUMPED
1683 CLD_TRAPPED
1684 CLD_STOPPED
1685 CLD_CONTINUED
1686 
1687 POLL_IN
1688 POLL_OUT
1689 POLL_MSG
1690 POLL_ERR
1691 POLL_PRI
1692 POLL_HUP
1693 */
1694 
1695 version (linux)
1696 {
1697     version (X86_Any)
1698     {
1699         enum SIGPOLL        = 29;
1700         enum SIGPROF        = 27;
1701         enum SIGSYS         = 31;
1702         enum SIGTRAP        = 5;
1703         enum SIGVTALRM      = 26;
1704         enum SIGXCPU        = 24;
1705         enum SIGXFSZ        = 25;
1706     }
1707     else version (HPPA_Any)
1708     {
1709         enum SIGPOLL    = 22;
1710         enum SIGPROF    = 21;
1711         enum SIGSYS     = 31;
1712         enum SIGTRAP    = 5;
1713         enum SIGVTALRM  = 20;
1714         enum SIGXCPU    = 12;
1715         enum SIGXFSZ    = 30;
1716     }
1717     else version (MIPS_Any)
1718     {
1719         enum SIGPOLL    = 22;
1720         enum SIGPROF    = 29;
1721         enum SIGSYS     = 12;
1722         enum SIGTRAP    = 5;
1723         enum SIGVTALRM  = 28;
1724         enum SIGXCPU    = 30;
1725         enum SIGXFSZ    = 31;
1726     }
1727     else version (PPC_Any)
1728     {
1729         enum SIGPOLL    = 29;
1730         enum SIGPROF    = 27;
1731         enum SIGSYS     = 31;
1732         enum SIGTRAP    = 5;
1733         enum SIGVTALRM  = 26;
1734         enum SIGXCPU    = 24;
1735         enum SIGXFSZ    = 25;
1736     }
1737     else version (ARM_Any)
1738     {
1739         enum SIGPOLL    = 29;
1740         enum SIGPROF    = 27;
1741         enum SIGSYS     = 31;
1742         enum SIGTRAP    = 5;
1743         enum SIGVTALRM  = 26;
1744         enum SIGXCPU    = 24;
1745         enum SIGXFSZ    = 25;
1746     }
1747     else version (RISCV_Any)
1748     {
1749         enum SIGPOLL    = 29;
1750         enum SIGPROF    = 27;
1751         enum SIGSYS     = 31;
1752         enum SIGTRAP    = 5;
1753         enum SIGVTALRM  = 26;
1754         enum SIGXCPU    = 24;
1755         enum SIGXFSZ    = 25;
1756     }
1757     else version (SPARC_Any)
1758     {
1759         enum SIGPOLL    = 23;
1760         enum SIGPROF    = 27;
1761         enum SIGSYS     = 12;
1762         enum SIGTRAP    = 5;
1763         enum SIGVTALRM  = 26;
1764         enum SIGXCPU    = 24;
1765         enum SIGXFSZ    = 25;
1766     }
1767     else version (IBMZ_Any)
1768     {
1769         enum SIGPOLL    = 29;
1770         enum SIGPROF    = 27;
1771         enum SIGSYS     = 31;
1772         enum SIGTRAP    = 5;
1773         enum SIGVTALRM  = 26;
1774         enum SIGXCPU    = 24;
1775         enum SIGXFSZ    = 25;
1776     }
1777     else version (LoongArch64)
1778     {
1779         enum SIGPOLL    = 29;
1780         enum SIGPROF    = 27;
1781         enum SIGSYS     = 31;
1782         enum SIGTRAP    = 5;
1783         enum SIGVTALRM  = 26;
1784         enum SIGXCPU    = 24;
1785         enum SIGXFSZ    = 25;
1786     }
1787     else
1788         static assert(0, "unimplemented");
1789 
1790     version (MIPS_Any)
1791     {
1792         enum SA_ONSTACK   = 0x08000000;
1793         enum SA_RESETHAND = 0x80000000;
1794         enum SA_RESTART   = 0x10000000;
1795         enum SA_SIGINFO   = 8;
1796         enum SA_NOCLDWAIT = 0x10000;
1797         enum SA_NODEFER   = 0x40000000;
1798     }
1799     else
1800     {
1801         enum SA_ONSTACK   = 0x08000000;
1802         enum SA_RESETHAND = 0x80000000;
1803         enum SA_RESTART   = 0x10000000;
1804         enum SA_SIGINFO   = 4;
1805         enum SA_NOCLDWAIT = 2;
1806         enum SA_NODEFER   = 0x40000000;
1807     }
1808 
1809     enum SA_NOMASK      = SA_NODEFER;
1810     enum SA_ONESHOT     = SA_RESETHAND;
1811     enum SA_STACK       = SA_ONSTACK;
1812 
1813     enum
1814     {
1815         ILL_ILLOPC = 1,
1816         ILL_ILLOPN,
1817         ILL_ILLADR,
1818         ILL_ILLTRP,
1819         ILL_PRVOPC,
1820         ILL_PRVREG,
1821         ILL_COPROC,
1822         ILL_BADSTK
1823     }
1824 
1825     enum
1826     {
1827         FPE_INTDIV = 1,
1828         FPE_INTOVF,
1829         FPE_FLTDIV,
1830         FPE_FLTOVF,
1831         FPE_FLTUND,
1832         FPE_FLTRES,
1833         FPE_FLTINV,
1834         FPE_FLTSUB
1835     }
1836 
1837     enum
1838     {
1839         SEGV_MAPERR = 1,
1840         SEGV_ACCERR
1841     }
1842 
1843     enum
1844     {
1845         BUS_ADRALN = 1,
1846         BUS_ADRERR,
1847         BUS_OBJERR
1848     }
1849 
1850     enum
1851     {
1852         TRAP_BRKPT = 1,
1853         TRAP_TRACE
1854     }
1855 
1856     enum
1857     {
1858         CLD_EXITED = 1,
1859         CLD_KILLED,
1860         CLD_DUMPED,
1861         CLD_TRAPPED,
1862         CLD_STOPPED,
1863         CLD_CONTINUED
1864     }
1865 
1866     enum
1867     {
1868         POLL_IN = 1,
1869         POLL_OUT,
1870         POLL_MSG,
1871         POLL_ERR,
1872         POLL_PRI,
1873         POLL_HUP
1874     }
1875 }
1876 else version (Darwin)
1877 {
1878     enum SIGPOLL        = 7;
1879     enum SIGPROF        = 27;
1880     enum SIGSYS         = 12;
1881     enum SIGTRAP        = 5;
1882     enum SIGVTALRM      = 26;
1883     enum SIGXCPU        = 24;
1884     enum SIGXFSZ        = 25;
1885 
1886     enum SA_ONSTACK     = 0x0001;
1887     enum SA_RESETHAND   = 0x0004;
1888     enum SA_RESTART     = 0x0002;
1889     enum SA_SIGINFO     = 0x0040;
1890     enum SA_NOCLDWAIT   = 0x0020;
1891     enum SA_NODEFER     = 0x0010;
1892 
1893     enum ILL_ILLOPC = 1;
1894     enum ILL_ILLOPN = 4;
1895     enum ILL_ILLADR = 5;
1896     enum ILL_ILLTRP = 2;
1897     enum ILL_PRVOPC = 3;
1898     enum ILL_PRVREG = 6;
1899     enum ILL_COPROC = 7;
1900     enum ILL_BADSTK = 8;
1901 
1902     enum FPE_INTDIV = 7;
1903     enum FPE_INTOVF = 8;
1904     enum FPE_FLTDIV = 1;
1905     enum FPE_FLTOVF = 2;
1906     enum FPE_FLTUND = 3;
1907     enum FPE_FLTRES = 4;
1908     enum FPE_FLTINV = 5;
1909     enum FPE_FLTSUB = 6;
1910 
1911     enum
1912     {
1913         SEGV_MAPERR = 1,
1914         SEGV_ACCERR
1915     }
1916 
1917     enum
1918     {
1919         BUS_ADRALN = 1,
1920         BUS_ADRERR,
1921         BUS_OBJERR
1922     }
1923 
1924     enum
1925     {
1926         TRAP_BRKPT = 1,
1927         TRAP_TRACE
1928     }
1929 
1930     enum
1931     {
1932         CLD_EXITED = 1,
1933         CLD_KILLED,
1934         CLD_DUMPED,
1935         CLD_TRAPPED,
1936         CLD_STOPPED,
1937         CLD_CONTINUED
1938     }
1939 
1940     enum
1941     {
1942         POLL_IN = 1,
1943         POLL_OUT,
1944         POLL_MSG,
1945         POLL_ERR,
1946         POLL_PRI,
1947         POLL_HUP
1948     }
1949 }
1950 else version (FreeBSD)
1951 {
1952     // No SIGPOLL on *BSD
1953     enum SIGPROF        = 27;
1954     enum SIGSYS         = 12;
1955     enum SIGTRAP        = 5;
1956     enum SIGVTALRM      = 26;
1957     enum SIGXCPU        = 24;
1958     enum SIGXFSZ        = 25;
1959 
1960     enum
1961     {
1962         SA_ONSTACK      = 0x0001,
1963         SA_RESTART      = 0x0002,
1964         SA_RESETHAND    = 0x0004,
1965         SA_NODEFER      = 0x0010,
1966         SA_NOCLDWAIT    = 0x0020,
1967         SA_SIGINFO      = 0x0040,
1968     }
1969 
1970     enum
1971     {
1972         ILL_ILLOPC = 1,
1973         ILL_ILLOPN,
1974         ILL_ILLADR,
1975         ILL_ILLTRP,
1976         ILL_PRVOPC,
1977         ILL_PRVREG,
1978         ILL_COPROC,
1979         ILL_BADSTK,
1980     }
1981 
1982     enum
1983     {
1984         BUS_ADRALN = 1,
1985         BUS_ADRERR,
1986         BUS_OBJERR,
1987     }
1988 
1989     enum
1990     {
1991         SEGV_MAPERR = 1,
1992         SEGV_ACCERR,
1993     }
1994 
1995     enum
1996     {
1997         FPE_INTOVF = 1,
1998         FPE_INTDIV,
1999         FPE_FLTDIV,
2000         FPE_FLTOVF,
2001         FPE_FLTUND,
2002         FPE_FLTRES,
2003         FPE_FLTINV,
2004         FPE_FLTSUB,
2005     }
2006 
2007     enum
2008     {
2009         TRAP_BRKPT = 1,
2010         TRAP_TRACE,
2011     }
2012 
2013     enum
2014     {
2015         CLD_EXITED = 1,
2016         CLD_KILLED,
2017         CLD_DUMPED,
2018         CLD_TRAPPED,
2019         CLD_STOPPED,
2020         CLD_CONTINUED,
2021     }
2022 
2023     enum
2024     {
2025         POLL_IN = 1,
2026         POLL_OUT,
2027         POLL_MSG,
2028         POLL_ERR,
2029         POLL_PRI,
2030         POLL_HUP,
2031     }
2032 }
2033 else version (NetBSD)
2034 {
2035     // No SIGPOLL on *BSD
2036     enum SIGPROF        = 27;
2037     enum SIGSYS         = 12;
2038     enum SIGTRAP        = 5;
2039     enum SIGVTALRM      = 26;
2040     enum SIGXCPU        = 24;
2041     enum SIGXFSZ        = 25;
2042 
2043     enum
2044     {
2045         SA_ONSTACK      = 0x0001,
2046         SA_RESTART      = 0x0002,
2047         SA_RESETHAND    = 0x0004,
2048         SA_NODEFER      = 0x0010,
2049         SA_NOCLDWAIT    = 0x0020,
2050         SA_SIGINFO      = 0x0040,
2051     }
2052 
2053     enum
2054     {
2055         ILL_ILLOPC = 1,
2056         ILL_ILLOPN,
2057         ILL_ILLADR,
2058         ILL_ILLTRP,
2059         ILL_PRVOPC,
2060         ILL_PRVREG,
2061         ILL_COPROC,
2062         ILL_BADSTK,
2063     }
2064 
2065     enum
2066     {
2067         BUS_ADRALN = 1,
2068         BUS_ADRERR,
2069         BUS_OBJERR,
2070     }
2071 
2072     enum
2073     {
2074         SEGV_MAPERR = 1,
2075         SEGV_ACCERR,
2076     }
2077 
2078     enum
2079     {
2080         FPE_INTOVF = 1,
2081         FPE_INTDIV,
2082         FPE_FLTDIV,
2083         FPE_FLTOVF,
2084         FPE_FLTUND,
2085         FPE_FLTRES,
2086         FPE_FLTINV,
2087         FPE_FLTSUB,
2088     }
2089 
2090     enum
2091     {
2092         TRAP_BRKPT = 1,
2093         TRAP_TRACE,
2094     }
2095 
2096     enum
2097     {
2098         CLD_EXITED = 1,
2099         CLD_KILLED,
2100         CLD_DUMPED,
2101         CLD_TRAPPED,
2102         CLD_STOPPED,
2103         CLD_CONTINUED,
2104     }
2105 
2106     enum
2107     {
2108         POLL_IN = 1,
2109         POLL_OUT,
2110         POLL_MSG,
2111         POLL_ERR,
2112         POLL_PRI,
2113         POLL_HUP,
2114     }
2115 }
2116 else version (OpenBSD)
2117 {
2118     // No SIGPOLL on *BSD
2119     enum SIGPROF        = 27;
2120     enum SIGSYS         = 12;
2121     enum SIGTRAP        = 5;
2122     enum SIGVTALRM      = 26;
2123     enum SIGXCPU        = 24;
2124     enum SIGXFSZ        = 25;
2125 
2126     enum
2127     {
2128         SA_ONSTACK      = 0x0001,
2129         SA_RESTART      = 0x0002,
2130         SA_RESETHAND    = 0x0004,
2131         SA_NODEFER      = 0x0010,
2132         SA_NOCLDWAIT    = 0x0020,
2133         SA_SIGINFO      = 0x0040,
2134     }
2135 
2136     enum
2137     {
2138         ILL_ILLOPC = 1,
2139         ILL_ILLOPN,
2140         ILL_ILLADR,
2141         ILL_ILLTRP,
2142         ILL_PRVOPC,
2143         ILL_PRVREG,
2144         ILL_COPROC,
2145         ILL_BADSTK,
2146         NSIGILL = ILL_BADSTK,
2147     }
2148 
2149     enum
2150     {
2151         BUS_ADRALN = 1,
2152         BUS_ADRERR,
2153         BUS_OBJERR,
2154         NSIGBUS = BUS_OBJERR,
2155     }
2156 
2157     enum
2158     {
2159         SEGV_MAPERR = 1,
2160         SEGV_ACCERR,
2161         NSIGSEGV = SEGV_ACCERR,
2162     }
2163 
2164     enum
2165     {
2166         FPE_INTDIV = 1,
2167         FPE_INTOVF,
2168         FPE_FLTDIV,
2169         FPE_FLTOVF,
2170         FPE_FLTUND,
2171         FPE_FLTRES,
2172         FPE_FLTINV,
2173         FPE_FLTSUB,
2174         NSIGFPE = FPE_FLTSUB,
2175     }
2176 
2177     enum
2178     {
2179         TRAP_BRKPT = 1,
2180         TRAP_TRACE,
2181         NSIGTRAP = TRAP_TRACE,
2182     }
2183 
2184     enum
2185     {
2186         CLD_EXITED = 1,
2187         CLD_KILLED,
2188         CLD_DUMPED,
2189         CLD_TRAPPED,
2190         CLD_STOPPED,
2191         CLD_CONTINUED,
2192         NSIGCLD = CLD_CONTINUED,
2193     }
2194 
2195     enum
2196     {
2197         POLL_IN = 1,
2198         POLL_OUT,
2199         POLL_MSG,
2200         POLL_ERR,
2201         POLL_PRI,
2202         POLL_HUP,
2203         NSIGPOLL = POLL_HUP,
2204     }
2205 }
2206 else version (DragonFlyBSD)
2207 {
2208     // No SIGPOLL on *BSD
2209     enum SIGPROF        = 27;
2210     enum SIGSYS         = 12;
2211     enum SIGTRAP        = 5;
2212     enum SIGVTALRM      = 26;
2213     enum SIGXCPU        = 24;
2214     enum SIGXFSZ        = 25;
2215 
2216     enum
2217     {
2218         SA_ONSTACK      = 0x0001,
2219         SA_RESTART      = 0x0002,
2220         SA_RESETHAND    = 0x0004,
2221         SA_NODEFER      = 0x0010,
2222         SA_NOCLDWAIT    = 0x0020,
2223         SA_SIGINFO      = 0x0040,
2224     }
2225 
2226     enum
2227     {
2228         ILL_ILLOPC = 1,
2229         ILL_ILLOPN,
2230         ILL_ILLADR,
2231         ILL_ILLTRP,
2232         ILL_PRVOPC,
2233         ILL_PRVREG,
2234         ILL_COPROC,
2235         ILL_BADSTK,
2236     }
2237 
2238     enum
2239     {
2240         BUS_ADRALN = 1,
2241         BUS_ADRERR,
2242         BUS_OBJERR,
2243     }
2244 
2245     enum
2246     {
2247         SEGV_MAPERR = 1,
2248         SEGV_ACCERR,
2249     }
2250 
2251     enum
2252     {
2253         FPE_INTOVF = 1,
2254         FPE_INTDIV,
2255         FPE_FLTDIV,
2256         FPE_FLTOVF,
2257         FPE_FLTUND,
2258         FPE_FLTRES,
2259         FPE_FLTINV,
2260         FPE_FLTSUB,
2261     }
2262 
2263     enum
2264     {
2265         TRAP_BRKPT = 1,
2266         TRAP_TRACE,
2267     }
2268 
2269     enum
2270     {
2271         CLD_EXITED = 1,
2272         CLD_KILLED,
2273         CLD_DUMPED,
2274         CLD_TRAPPED,
2275         CLD_STOPPED,
2276         CLD_CONTINUED,
2277     }
2278 
2279     enum
2280     {
2281         POLL_IN = 1,
2282         POLL_OUT,
2283         POLL_MSG,
2284         POLL_ERR,
2285         POLL_PRI,
2286         POLL_HUP,
2287     }
2288 }
2289 else version (Solaris)
2290 {
2291     enum SIGPOLL = 22;
2292     enum SIGIO = SIGPOLL;
2293     enum SIGPROF = 29;
2294     enum SIGSYS = 12;
2295     enum SIGTRAP = 5;
2296     enum SIGVTALRM = 28;
2297     enum SIGXCPU = 30;
2298     enum SIGXFSZ = 31;
2299 
2300     enum
2301     {
2302         SA_ONSTACK = 0x00001,
2303         SA_RESTART = 0x00004,
2304         SA_RESETHAND = 0x00002,
2305         SA_NODEFER = 0x00010,
2306         SA_NOCLDWAIT = 0x10000,
2307         SA_SIGINFO = 0x00008,
2308     }
2309 
2310     enum
2311     {
2312         ILL_ILLOPC = 1,
2313         ILL_ILLOPN,
2314         ILL_ILLADR,
2315         ILL_ILLTRP,
2316         ILL_PRVOPC,
2317         ILL_PRVREG,
2318         ILL_COPROC,
2319         ILL_BADSTK,
2320     }
2321 
2322     enum
2323     {
2324         BUS_ADRALN = 1,
2325         BUS_ADRERR,
2326         BUS_OBJERR,
2327     }
2328 
2329     enum
2330     {
2331         SEGV_MAPERR = 1,
2332         SEGV_ACCERR,
2333     }
2334 
2335     enum
2336     {
2337         FPE_INTDIV = 1,
2338         FPE_INTOVF,
2339         FPE_FLTDIV,
2340         FPE_FLTOVF,
2341         FPE_FLTUND,
2342         FPE_FLTRES,
2343         FPE_FLTINV,
2344         FPE_FLTSUB,
2345         FPE_FLTDEN,
2346     }
2347 
2348     enum
2349     {
2350         TRAP_BRKPT = 1,
2351         TRAP_TRACE,
2352         TRAP_RWATCH,
2353         TRAP_WWATCH,
2354         TRAP_XWATCH,
2355         TRAP_DTRACE,
2356     }
2357 
2358     enum
2359     {
2360         CLD_EXITED = 1,
2361         CLD_KILLED,
2362         CLD_DUMPED,
2363         CLD_TRAPPED,
2364         CLD_STOPPED,
2365         CLD_CONTINUED,
2366     }
2367 
2368     enum
2369     {
2370         POLL_IN = 1,
2371         POLL_OUT,
2372         POLL_MSG,
2373         POLL_ERR,
2374         POLL_PRI,
2375         POLL_HUP,
2376     }
2377 }
2378 else
2379 {
2380     static assert(false, "Unsupported platform");
2381 }
2382 
2383 /*
2384 SS_ONSTACK
2385 SS_DISABLE
2386 MINSIGSTKSZ
2387 SIGSTKSZ
2388 
2389 ucontext_t // from ucontext
2390 mcontext_t // from ucontext
2391 
2392 struct stack_t
2393 {
2394     void*   ss_sp;
2395     size_t  ss_size;
2396     int     ss_flags;
2397 }
2398 
2399 struct sigstack
2400 {
2401     int   ss_onstack;
2402     void* ss_sp;
2403 }
2404 
2405 sigfn_t bsd_signal(int sig, sigfn_t func);
2406 sigfn_t sigset(int sig, sigfn_t func);
2407 
2408 int killpg(pid_t, int);
2409 int sigaltstack(const scope stack_t*, stack_t*);
2410 int sighold(int);
2411 int sigignore(int);
2412 int siginterrupt(int, int);
2413 int sigpause(int);
2414 int sigrelse(int);
2415 */
2416 
2417 version (CRuntime_Glibc)
2418 {
2419     enum SS_ONSTACK     = 1;
2420     enum SS_DISABLE     = 2;
2421     enum MINSIGSTKSZ    = 2048;
2422     enum SIGSTKSZ       = 8192;
2423 
2424     //ucontext_t (defined in core.sys.posix.ucontext)
2425     //mcontext_t (defined in core.sys.posix.ucontext)
2426 
2427     version (MIPS_Any)
2428     {
2429         struct stack_t
2430         {
2431             void*   ss_sp;
2432             size_t  ss_size;
2433             int     ss_flags;
2434         }
2435     }
2436     else
2437     {
2438         struct stack_t
2439         {
2440             void*   ss_sp;
2441             int     ss_flags;
2442             size_t  ss_size;
2443         }
2444     }
2445 
2446     struct sigstack
2447     {
2448         void*   ss_sp;
2449         int     ss_onstack;
2450     }
2451 
2452     sigfn_t bsd_signal(int sig, sigfn_t func);
2453     sigfn_t sigset(int sig, sigfn_t func);
2454 
2455   nothrow:
2456   @nogc:
2457     sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2458     sigfn_t2 sigset(int sig, sigfn_t2 func);
2459 
2460     int killpg(pid_t, int);
2461     int sigaltstack(const scope stack_t*, stack_t*);
2462     int sighold(int);
2463     int sigignore(int);
2464     int siginterrupt(int, int);
2465     int sigpause(int);
2466     int sigrelse(int);
2467 }
2468 else version (Darwin)
2469 {
2470     enum SS_ONSTACK     = 0x0001;
2471     enum SS_DISABLE     = 0x0004;
2472     enum MINSIGSTKSZ    = 32768;
2473     enum SIGSTKSZ       = 131072;
2474 
2475     //ucontext_t (defined in core.sys.posix.ucontext)
2476     //mcontext_t (defined in core.sys.posix.ucontext)
2477 
2478     struct stack_t
2479     {
2480         void*   ss_sp;
2481         size_t  ss_size;
2482         int     ss_flags;
2483     }
2484 
2485     struct sigstack
2486     {
2487         void*   ss_sp;
2488         int     ss_onstack;
2489     }
2490 
2491     sigfn_t bsd_signal(int sig, sigfn_t func);
2492     sigfn_t sigset(int sig, sigfn_t func);
2493 
2494   nothrow:
2495   @nogc:
2496     sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2497     sigfn_t2 sigset(int sig, sigfn_t2 func);
2498 
2499     int killpg(pid_t, int);
2500     int sigaltstack(const scope stack_t*, stack_t*);
2501     int sighold(int);
2502     int sigignore(int);
2503     int siginterrupt(int, int);
2504     int sigpause(int);
2505     int sigrelse(int);
2506 }
2507 else version (FreeBSD)
2508 {
2509     enum
2510     {
2511         SS_ONSTACK = 0x0001,
2512         SS_DISABLE = 0x0004,
2513     }
2514 
2515     enum MINSIGSTKSZ = 512 * 4;
2516     enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
2517 
2518     //ucontext_t (defined in core.sys.posix.ucontext)
2519     //mcontext_t (defined in core.sys.posix.ucontext)
2520 
2521     struct stack_t
2522     {
2523         void*   ss_sp;
2524         size_t  ss_size;
2525         int     ss_flags;
2526     }
2527 
2528     struct sigstack
2529     {
2530         void*   ss_sp;
2531         int     ss_onstack;
2532     }
2533 
2534     //sigfn_t bsd_signal(int sig, sigfn_t func);
2535     sigfn_t sigset(int sig, sigfn_t func);
2536 
2537   nothrow:
2538   @nogc:
2539     //sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2540     sigfn_t2 sigset(int sig, sigfn_t2 func);
2541 
2542     int killpg(pid_t, int);
2543     int sigaltstack(const scope stack_t*, stack_t*);
2544     int sighold(int);
2545     int sigignore(int);
2546     int siginterrupt(int, int);
2547     int sigpause(int);
2548     int sigrelse(int);
2549 }
2550 else version (NetBSD)
2551 {
2552     enum
2553     {
2554         SS_ONSTACK = 0x0001,
2555         SS_DISABLE = 0x0004,
2556     }
2557 
2558     enum MINSIGSTKSZ = 8192;
2559     enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
2560 
2561     //ucontext_t (defined in core.sys.posix.ucontext)
2562     //mcontext_t (defined in core.sys.posix.ucontext)
2563 
2564     struct stack_t
2565     {
2566         void*   ss_sp;
2567         size_t  ss_size;
2568         int     ss_flags;
2569     }
2570 
2571     struct sigstack
2572     {
2573         void*   ss_sp;
2574         int     ss_onstack;
2575     }
2576 
2577     //sigfn_t bsd_signal(int sig, sigfn_t func);
2578     sigfn_t sigset(int sig, sigfn_t func);
2579 
2580   nothrow:
2581   @nogc:
2582     //sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2583     sigfn_t2 sigset(int sig, sigfn_t2 func);
2584 
2585     int killpg(pid_t, int);
2586     int sigaltstack(const scope stack_t*, stack_t*);
2587     int sighold(int);
2588     int sigignore(int);
2589     int siginterrupt(int, int);
2590     int sigpause(int);
2591     int sigrelse(int);
2592 }
2593 else version (OpenBSD)
2594 {
2595     enum
2596     {
2597         SS_ONSTACK = 0x0001,
2598         SS_DISABLE = 0x0004,
2599     }
2600 
2601     enum MINSIGSTKSZ = 8192;
2602     enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
2603 
2604     //ucontext_t (defined in core.sys.posix.ucontext)
2605     //mcontext_t (defined in core.sys.posix.ucontext)
2606 
2607     struct stack_t
2608     {
2609         void*   ss_sp;
2610         size_t  ss_size;
2611         int     ss_flags;
2612     }
2613 
2614   nothrow:
2615   @nogc:
2616     int killpg(pid_t, int);
2617     int sigaltstack(const scope stack_t*, stack_t*);
2618     int siginterrupt(int, int);
2619     int sigpause(int);
2620 }
2621 else version (DragonFlyBSD)
2622 {
2623     enum
2624     {
2625         SS_ONSTACK = 0x0001,
2626         SS_DISABLE = 0x0004,
2627     }
2628 
2629     enum MINSIGSTKSZ = 8192;
2630     enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
2631 
2632     //ucontext_t (defined in core.sys.posix.ucontext)
2633     //mcontext_t (defined in core.sys.posix.ucontext)
2634 
2635     struct stack_t
2636     {
2637         void*   ss_sp;
2638         size_t  ss_size;
2639         int     ss_flags;
2640     }
2641 
2642     struct sigstack
2643     {
2644         void*   ss_sp;
2645         int     ss_onstack;
2646     }
2647 
2648     //sigfn_t bsd_signal(int sig, sigfn_t func);
2649     sigfn_t sigset(int sig, sigfn_t func);
2650 
2651   nothrow:
2652   @nogc:
2653     //sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2654     sigfn_t2 sigset(int sig, sigfn_t2 func);
2655 
2656     int killpg(pid_t, int);
2657     int sigaltstack(const scope stack_t*, stack_t*);
2658     int sighold(int);
2659     int sigignore(int);
2660     int siginterrupt(int, int);
2661     int sigpause(int);
2662     int sigrelse(int);
2663 }
2664 else version (Solaris)
2665 {
2666     enum
2667     {
2668         SS_ONSTACK = 0x0001,
2669         SS_DISABLE = 0x0002,
2670     }
2671 
2672     enum MINSIGSTKSZ = 2048;
2673     enum SIGSTKSZ = 8192;
2674 
2675     struct stack_t
2676     {
2677         void* ss_sp;
2678         size_t ss_size;
2679         int ss_flags;
2680     }
2681 
2682     struct sigstack
2683     {
2684         void* ss_sp;
2685         int ss_onstack;
2686     }
2687 
2688     sigfn_t sigset(int sig, sigfn_t func);
2689 
2690   nothrow:
2691   @nogc:
2692     sigfn_t2 sigset(int sig, sigfn_t2 func);
2693 
2694     int killpg(pid_t, int);
2695     int sigaltstack(const scope stack_t*, stack_t*);
2696     int sighold(int);
2697     int sigignore(int);
2698     int siginterrupt(int, int);
2699     int sigpause(int);
2700     int sigrelse(int);
2701 }
2702 else version (CRuntime_Bionic)
2703 {
2704     enum SS_ONSTACK     = 1;
2705     enum SS_DISABLE     = 2;
2706     enum MINSIGSTKSZ    = 2048;
2707     enum SIGSTKSZ       = 8192;
2708 
2709     struct stack_t
2710     {
2711         void*   ss_sp;
2712         int     ss_flags;
2713         size_t  ss_size;
2714     }
2715 
2716     sigfn_t bsd_signal(int, sigfn_t);
2717 
2718   nothrow:
2719   @nogc:
2720     sigfn_t2 bsd_signal(int, sigfn_t2);
2721 
2722     int killpg(int, int);
2723     int sigaltstack(const scope stack_t*, stack_t*);
2724     int siginterrupt(int, int);
2725 }
2726 else version (CRuntime_Musl)
2727 {
2728     enum SS_ONSTACK = 1;
2729     enum SS_DISABLE = 2;
2730 
2731     version (ARM)
2732     {
2733         enum MINSIGSTKSZ = 2048;
2734         enum SIGSTKSZ    = 8192;
2735     }
2736     else version (AArch64)
2737     {
2738         enum MINSIGSTKSZ = 6144;
2739         enum SIGSTKSZ    = 12288;
2740     }
2741     else version (IBMZ_Any)
2742     {
2743         enum MINSIGSTKSZ = 4096;
2744         enum SIGSTKSZ    = 10240;
2745     }
2746     else version (MIPS_Any)
2747     {
2748         enum MINSIGSTKSZ = 2048;
2749         enum SIGSTKSZ    = 8192;
2750     }
2751     else version (PPC_Any)
2752     {
2753         enum MINSIGSTKSZ = 4096;
2754         enum SIGSTKSZ    = 10240;
2755     }
2756     else version (X86_Any)
2757     {
2758         enum MINSIGSTKSZ = 2048;
2759         enum SIGSTKSZ    = 8192;
2760     }
2761     else
2762         static assert(0, "unimplemented");
2763 
2764     //ucontext_t (defined in core.sys.posix.ucontext)
2765     //mcontext_t (defined in core.sys.posix.ucontext)
2766 
2767     version (MIPS_Any)
2768     {
2769         struct stack_t
2770         {
2771             void*  ss_sp;
2772             size_t ss_size;
2773             int    ss_flags;
2774         }
2775     }
2776     else
2777     {
2778         struct stack_t
2779         {
2780             void*  ss_sp;
2781             int    ss_flags;
2782             size_t ss_size;
2783         }
2784     }
2785 
2786     sigfn_t bsd_signal(int sig, sigfn_t func);
2787     sigfn_t sigset(int sig, sigfn_t func);
2788 
2789   nothrow:
2790   @nogc:
2791     sigfn_t2 bsd_signal(int sig, sigfn_t2 func);
2792     sigfn_t2 sigset(int sig, sigfn_t2 func);
2793 
2794     int killpg(pid_t, int);
2795     int sigaltstack(const scope stack_t*, stack_t*);
2796     int sighold(int);
2797     int sigignore(int);
2798     int siginterrupt(int, int);
2799     int sigpause(int);
2800     int sigrelse(int);
2801 }
2802 else version (CRuntime_UClibc)
2803 {
2804     enum SS_ONSTACK     = 1;
2805     enum SS_DISABLE     = 2;
2806     enum MINSIGSTKSZ    = 2048;
2807     enum SIGSTKSZ       = 8192;
2808 
2809     version (MIPS_Any)
2810     {
2811         struct stack_t
2812         {
2813             void *ss_sp;
2814             size_t ss_size;
2815             int ss_flags;
2816         }
2817     }
2818     else
2819     {
2820         struct stack_t
2821         {
2822             void*   ss_sp;
2823             int     ss_flags;
2824             size_t  ss_size;
2825         }
2826      }
2827 
2828     struct sigstack
2829     {
2830         void*   ss_sp;
2831         int     ss_onstack;
2832     }
2833 
2834     sigfn_t sigset(int sig, sigfn_t func);
2835 
2836   nothrow:
2837   @nogc:
2838     sigfn_t2 sigset(int sig, sigfn_t2 func);
2839 
2840     int killpg(pid_t, int);
2841     int sigaltstack(const scope stack_t*, stack_t*);
2842     int sighold(int);
2843     int sigignore(int);
2844     int siginterrupt(int, int);
2845     int sigpause(int);
2846     int sigrelse(int);
2847 }
2848 else
2849 {
2850     static assert(false, "Unsupported platform");
2851 }
2852 
2853 //
2854 // Realtime Signals (RTS)
2855 //
2856 /*
2857 struct sigevent
2858 {
2859     int             sigev_notify;
2860     int             sigev_signo;
2861     sigval          sigev_value;
2862     void(*)(sigval) sigev_notify_function;
2863     pthread_attr_t* sigev_notify_attributes;
2864 }
2865 */
2866 
2867 nothrow:
2868 @nogc:
2869 
2870 version (linux)
2871 {
2872     private enum __SIGEV_MAX_SIZE = 64;
2873 
2874     static if ( __WORDSIZE == 64 )
2875     {
2876         private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4);
2877     }
2878     else
2879     {
2880         private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3);
2881     }
2882 
2883     struct sigevent
2884     {
2885         sigval      sigev_value;
2886         int         sigev_signo;
2887         int         sigev_notify;
2888 
2889         union
2890         {
2891             int[__SIGEV_PAD_SIZE] _pad;
2892             pid_t                 _tid;
2893 
2894             struct
2895             {
2896                 void function(sigval) sigev_notify_function;
2897                 void*                 sigev_notify_attributes;
2898             }
2899         }
2900     }
2901 }
2902 else version (FreeBSD)
2903 {
2904     struct sigevent
2905     {
2906         int             sigev_notify;
2907         int             sigev_signo;
2908         sigval          sigev_value;
2909         union
2910         {
2911             lwpid_t _threadid;
2912             struct
2913             {
2914                 void function(sigval) sigev_notify_function;
2915                 void* sigev_notify_attributes;
2916             }
2917             c_long[8] __spare__;
2918         }
2919     }
2920 }
2921 else version (NetBSD)
2922 {
2923     struct sigevent
2924     {
2925         int             sigev_notify;
2926         int             sigev_signo;
2927         sigval          sigev_value;
2928         void function(sigval) sigev_notify_function;
2929         void /* pthread_attr_t */*sigev_notify_attributes;
2930     }
2931 }
2932 else version (OpenBSD)
2933 {
2934     // OpenBSD does not implement sigevent.
2935     alias sigevent = void;
2936 }
2937 else version (DragonFlyBSD)
2938 {
2939     union  _sigev_un_t
2940     {
2941         int                       sigev_signo;
2942         int                       sigev_notify_kqueue;
2943         void /*pthread_attr_t*/ * sigev_notify_attributes;
2944     }
2945     union _sigval_t
2946     {
2947         int                       sival_int;
2948         void                    * sival_ptr;
2949         int                       sigval_int;
2950         void                    * sigval_ptr;
2951     }
2952     struct sigevent
2953     {
2954         int                       sigev_notify;
2955         _sigev_un_t               sigev_un;
2956         _sigval_t                 sigev_value;
2957         void function(_sigval_t)  sigev_notify_function;
2958     }
2959 }
2960 else version (Darwin)
2961 {
2962     struct sigevent
2963     {
2964         int sigev_notify;
2965         int sigev_signo;
2966         sigval sigev_value;
2967         void function(sigval) sigev_notify_function;
2968         pthread_attr_t* sigev_notify_attributes;
2969     }
2970 }
2971 else version (Solaris)
2972 {
2973     struct sigevent
2974     {
2975         int sigev_notify;
2976         int sigev_signo;
2977         sigval sigev_value;
2978         void function(sigval) sigev_notify_function;
2979         pthread_attr_t* sigev_notify_attributes;
2980         int __sigev_pad2;
2981     }
2982 }
2983 else
2984 {
2985     static assert(false, "Unsupported platform");
2986 }
2987 
2988 /*
2989 int sigqueue(pid_t, int, const sigval);
2990 int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
2991 int sigwaitinfo(const scope sigset_t*, siginfo_t*);
2992 */
2993 
2994 nothrow:
2995 @nogc:
2996 
2997 version (CRuntime_Glibc)
2998 {
2999     int sigqueue(pid_t, int, const sigval);
3000     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3001     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3002 }
3003 else version (FreeBSD)
3004 {
3005     int sigqueue(pid_t, int, const sigval);
3006     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3007     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3008 }
3009 else version (NetBSD)
3010 {
3011     int sigqueue(pid_t, int, const sigval);
3012     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3013     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3014 }
3015 else version (OpenBSD)
3016 {
3017 }
3018 else version (DragonFlyBSD)
3019 {
3020     int sigqueue(pid_t, int, const sigval);
3021     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3022     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3023 }
3024 else version (Darwin)
3025 {
3026 }
3027 else version (Solaris)
3028 {
3029     int sigqueue(pid_t, int, const sigval);
3030     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3031     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3032 }
3033 else version (CRuntime_Bionic)
3034 {
3035 }
3036 else version (CRuntime_Musl)
3037 {
3038     int sigqueue(pid_t, int, const sigval);
3039     pragma(mangle, muslRedirTime64Mangle!("sigtimedwait", "__sigtimedwait_time64"))
3040     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3041     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3042 }
3043 else version (CRuntime_UClibc)
3044 {
3045     int sigqueue(pid_t, int, const sigval);
3046     int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*);
3047     int sigwaitinfo(const scope sigset_t*, siginfo_t*);
3048 }
3049 else
3050 {
3051     static assert(false, "Unsupported platform");
3052 }
3053 
3054 //
3055 // Threads (THR)
3056 //
3057 /*
3058 int pthread_kill(pthread_t, int);
3059 int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3060 */
3061 
3062 version (CRuntime_Glibc)
3063 {
3064     int pthread_kill(pthread_t, int);
3065     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3066 }
3067 else version (Darwin)
3068 {
3069     int pthread_kill(pthread_t, int);
3070     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3071 }
3072 else version (FreeBSD)
3073 {
3074     int pthread_kill(pthread_t, int);
3075     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3076 }
3077 else version (NetBSD)
3078 {
3079     int pthread_kill(pthread_t, int);
3080     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3081 }
3082 else version (OpenBSD)
3083 {
3084     int pthread_kill(pthread_t, int);
3085     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3086 }
3087 else version (DragonFlyBSD)
3088 {
3089     int pthread_kill(pthread_t, int);
3090     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3091 }
3092 else version (Solaris)
3093 {
3094     int pthread_kill(pthread_t, int);
3095     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3096 }
3097 else version (CRuntime_Bionic)
3098 {
3099     int pthread_kill(pthread_t, int);
3100     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3101 }
3102 else version (CRuntime_Musl)
3103 {
3104     int pthread_kill(pthread_t, int);
3105     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3106 }
3107 else version (CRuntime_UClibc)
3108 {
3109     int pthread_kill(pthread_t, int);
3110     int pthread_sigmask(int, const scope sigset_t*, sigset_t*);
3111     int pthread_sigqueue(pthread_t, int, sigval);
3112 }
3113 else
3114 {
3115     static assert(false, "Unsupported platform");
3116 }