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