1 /**
2  * D header file for POSIX.
3  *
4  * on posix SIGUSR1 and SIGUSR2 are used by the gc, and should not be used/handled/blocked
5  *
6  * Copyright: Public Domain
7  * License:   Public Domain
8  * Authors:   Sean Kelly
9  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
10  */
11 module tango.stdc.posix.signal;
12 
13 private import tango.stdc.posix.config;
14 version( solaris ) {
15     private import tango.stdc.stdint;
16 }
17 public import tango.stdc.signal;
18 public import tango.stdc.stddef;          // for size_t
19 public import tango.stdc.posix.sys.types; // for pid_t
20 //public import tango.stdc.posix.time;      // for timespec, now defined here
21 
22 extern (C):
23 
24 private alias void function(int) sigfn_t;
25 private alias void function(int, siginfo_t*, void*) sigactfn_t;
26 
27 //
28 // Required
29 //
30 /*
31 SIG_DFL (defined in tango.stdc.signal)
32 SIG_ERR (defined in tango.stdc.signal)
33 SIG_IGN (defined in tango.stdc.signal)
34 
35 sig_atomic_t (defined in tango.stdc.signal)
36 
37 SIGEV_NONE
38 SIGEV_SIGNAL
39 SIGEV_THREAD
40 
41 union sigval
42 {
43     int   sival_int;
44     void* sival_ptr;
45 }
46 
47 SIGRTMIN
48 SIGRTMAX
49 
50 SIGABRT (defined in tango.stdc.signal)
51 SIGALRM
52 SIGBUS
53 SIGCHLD
54 SIGCONT
55 SIGFPE (defined in tango.stdc.signal)
56 SIGHUP
57 SIGILL (defined in tango.stdc.signal)
58 SIGINT (defined in tango.stdc.signal)
59 SIGKILL
60 SIGPIPE
61 SIGQUIT
62 SIGSEGV (defined in tango.stdc.signal)
63 SIGSTOP
64 SIGTERM (defined in tango.stdc.signal)
65 SIGTSTP
66 SIGTTIN
67 SIGTTOU
68 SIGUSR1
69 SIGUSR2
70 SIGURG
71 
72 struct sigaction_t
73 {
74     sigfn_t     sa_handler;
75     sigset_t    sa_mask;
76     sigactfn_t  sa_sigaction;
77 }
78 
79 sigfn_t signal(int sig, sigfn_t func); (defined in tango.stdc.signal)
80 int raise(int sig);                    (defined in tango.stdc.signal)
81 */
82 
83 //SIG_DFL (defined in tango.stdc.signal)
84 //SIG_ERR (defined in tango.stdc.signal)
85 //SIG_IGN (defined in tango.stdc.signal)
86 
87 //sig_atomic_t (defined in tango.stdc.signal)
88 
89 enum
90 {
91   SIGEV_SIGNAL,
92   SIGEV_NONE,
93   SIGEV_THREAD
94 }
95 
96 union sigval
97 {
98     int     sival_int;
99     void*   sival_ptr;
100 }
101 
102 private extern (C) int __libc_current_sigrtmin();
103 private extern (C) int __libc_current_sigrtmax();
104 
105 alias __libc_current_sigrtmin SIGRTMIN;
106 alias __libc_current_sigrtmax SIGRTMAX;
107 
108 version( linux )
109 {
110     //SIGABRT (defined in tango.stdc.signal)
111     const SIGALRM   = 14;
112     const SIGBUS    = 7;
113     const SIGCHLD   = 17;
114     const SIGCONT   = 18;
115     //SIGFPE (defined in tango.stdc.signal)
116     const SIGHUP    = 1;
117     //SIGILL (defined in tango.stdc.signal)
118     //SIGINT (defined in tango.stdc.signal)
119     const SIGKILL   = 9;
120     const SIGPIPE   = 13;
121     const SIGQUIT   = 3;
122     //SIGSEGV (defined in tango.stdc.signal)
123     const SIGSTOP   = 19;
124     //SIGTERM (defined in tango.stdc.signal)
125     const SIGTSTP   = 20;
126     const SIGTTIN   = 21;
127     const SIGTTOU   = 22;
128     const SIGUSR1   = 10;
129     const SIGUSR2   = 12;
130     const SIGURG    = 23;
131 }
132 else version( darwin )
133 {
134     //SIGABRT (defined in tango.stdc.signal)
135     const SIGALRM   = 14;
136     const SIGBUS    = 10;
137     const SIGCHLD   = 20;
138     const SIGCONT   = 19;
139     //SIGFPE (defined in tango.stdc.signal)
140     const SIGHUP    = 1;
141     //SIGILL (defined in tango.stdc.signal)
142     //SIGINT (defined in tango.stdc.signal)
143     const SIGKILL   = 9;
144     const SIGPIPE   = 13;
145     const SIGQUIT   = 3;
146     //SIGSEGV (defined in tango.stdc.signal)
147     const SIGSTOP   = 17;
148     //SIGTERM (defined in tango.stdc.signal)
149     const SIGTSTP   = 18;
150     const SIGTTIN   = 21;
151     const SIGTTOU   = 22;
152     const SIGUSR1   = 30;
153     const SIGUSR2   = 31;
154     const SIGURG    = 16;
155 }
156 else version( FreeBSD )
157 {
158     //SIGABRT (defined in tango.stdc.signal)
159     const SIGALRM   = 14;
160     const SIGBUS    = 10;
161     const SIGCHLD   = 20;
162     const SIGCONT   = 19;
163     //SIGFPE (defined in tango.stdc.signal)
164     const SIGHUP    = 1;
165     //SIGILL (defined in tango.stdc.signal)
166     //SIGINT (defined in tango.stdc.signal)
167     const SIGKILL   = 9;
168     const SIGPIPE   = 13;
169     const SIGQUIT   = 3;
170     //SIGSEGV (defined in tango.stdc.signal)
171     const SIGSTOP   = 17;
172     //SIGTERM (defined in tango.stdc.signal)
173     const SIGTSTP   = 18;
174     const SIGTTIN   = 21;
175     const SIGTTOU   = 22;
176     const SIGUSR1   = 30;
177     const SIGUSR2   = 31;
178     const SIGURG    = 16;
179 }
180 else version( solaris )
181 {
182     //SIGABRT (defined in tango.stdc.signal)
183     const SIGALRM   = 14;   /* alarm clock */
184     const SIGBUS    = 10;   /* bus error */
185     const SIGCHLD   = 18;   /* child status change alias (POSIX) */
186     const SIGCONT   = 25;   /* stopped process has been continued */
187     //SIGFPE (defined in tango.stdc.signal)
188     const SIGHUP    = 1;    /* hangup */
189     //SIGILL (defined in tango.stdc.signal)
190     //SIGINT (defined in tango.stdc.signal)
191     const SIGKILL   = 9;    /* kill (cannot be caught or ignored) */
192     const SIGPIPE   = 13;   /* write on a pipe with no one to read it */
193     const SIGQUIT   = 3;    /* quit (ASCII FS) */
194     //SIGSEGV (defined in tango.stdc.signal)
195     const SIGSTOP   = 23;   /* stop (cannot be caught or ignored) */
196     //SIGTERM (defined in tango.stdc.signal)
197     const SIGTSTP   = 24;   /* user stop requested from tty */
198     const SIGTTIN   = 26;   /* background tty read attempted */
199     const SIGTTOU   = 27;   /* background tty write attempted */
200     const SIGUSR1   = 16;   /* user defined signal 1 */
201     const SIGUSR2   = 17;   /* user defined signal 2 */
202     const SIGURG    = 21;   /* urgent socket condition */
203 /+
204     const SIGTRAP   = 5;    /* trace trap (not reset when caught) */
205     const SIGIOT    = 6;    /* IOT instruction */
206     const SIGEMT    = 7;    /* EMT instruction */
207     const SIGSYS    = 12;   /* bad argument to system call */
208     const SIGCLD    = 18;   /* child status change */
209     const SIGPWR    = 19;   /* power-fail restart */
210     const SIGWINCH  = 20;   /* window size change */
211     const SIGPOLL   = 22;   /* pollable event occured */
212     const SIGIO     = SIGPOLL;  /* socket I/O possible (SIGPOLL alias) */
213     const SIGVTALRM = 28;   /* virtual timer expired */
214     const SIGPROF   = 29;   /* profiling timer expired */
215     const SIGXCPU   = 30;   /* exceeded cpu limit */
216     const SIGXFSZ   = 31;   /* exceeded file size limit */
217     const SIGWAITING= 32;   /* reserved signal no longer used by threading code */
218     const SIGLWP    = 33;   /* reserved signal no longer used by threading code */
219     const SIGFREEZE = 34;   /* special signal used by CPR */
220     const SIGTHAW   = 35;   /* special signal used by CPR */
221     const SIGCANCEL = 36;   /* reserved signal for thread cancellation */
222     const SIGLOST   = 37;   /* resource lost (eg, record-lock lost) */
223     const SIGXRES   = 38;   /* resource control exceeded */
224     const SIGJVM1   = 39;   /* reserved signal for Java Virtual Machine */
225     const SIGJVM2   = 40;   /* reserved signal for Java Virtual Machine */
226 +/
227 }
228 else
229 {
230    static assert(0, "Platform not supported...");
231 }
232 
233 struct sigaction_t
234 {
235     static if( true /* __USE_POSIX199309 */ )
236     {
237         union
238         {
239             sigfn_t     sa_handler;
240             sigactfn_t  sa_sigaction;
241         }
242     }
243     else
244     {
245         sigfn_t     sa_handler;
246     }
247     version(FreeBSD){
248         int             sa_flags;
249         sigset_t        sa_mask;
250     }else{
251         sigset_t        sa_mask;
252         int             sa_flags;
253     }
254 
255     version( darwin ) {} else {
256     void function() sa_restorer;
257     }
258 }
259 
260 //
261 // C Extension (CX)
262 //
263 /*
264 SIG_HOLD
265 
266 sigset_t
267 pid_t   (defined in sys.types)
268 
269 SIGABRT (defined in tango.stdc.signal)
270 SIGFPE  (defined in tango.stdc.signal)
271 SIGILL  (defined in tango.stdc.signal)
272 SIGINT  (defined in tango.stdc.signal)
273 SIGSEGV (defined in tango.stdc.signal)
274 SIGTERM (defined in tango.stdc.signal)
275 
276 SA_NOCLDSTOP (CX|XSI)
277 SIG_BLOCK
278 SIG_UNBLOCK
279 SIG_SETMASK
280 
281 struct siginfo_t
282 {
283     int     si_signo;
284     int     si_code;
285 
286     version( XSI )
287     {
288         int     si_errno;
289         pid_t   si_pid;
290         uid_t   si_uid;
291         void*   si_addr;
292         int     si_status;
293         c_long  si_band;
294     }
295     version( RTS )
296     {
297         sigval  si_value;
298     }
299 }
300 
301 SI_USER
302 SI_QUEUE
303 SI_TIMER
304 SI_ASYNCIO
305 SI_MESGQ
306 
307 int kill(pid_t, int);
308 int sigaction(int, in sigaction_t*, sigaction_t*);
309 int sigaddset(sigset_t*, int);
310 int sigdelset(sigset_t*, int);
311 int sigemptyset(sigset_t*);
312 int sigfillset(sigset_t*);
313 int sigismember(in sigset_t*, int);
314 int sigpending(sigset_t*);
315 int sigprocmask(int, in sigset_t*, sigset_t*);
316 int sigsuspend(in sigset_t*);
317 int sigwait(in sigset_t*, int*);
318 */
319 
320 version( linux )
321 {
322     const SIG_HOLD = cast(sigfn_t) 1;
323 
324     private const _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof);
325 
326     struct sigset_t
327     {
328         c_ulong[_SIGSET_NWORDS] __val;
329     }
330 
331     // pid_t  (defined in sys.types)
332 
333     //SIGABRT (defined in tango.stdc.signal)
334     //SIGFPE  (defined in tango.stdc.signal)
335     //SIGILL  (defined in tango.stdc.signal)
336     //SIGINT  (defined in tango.stdc.signal)
337     //SIGSEGV (defined in tango.stdc.signal)
338     //SIGTERM (defined in tango.stdc.signal)
339 
340     const SA_NOCLDSTOP  = 1; // (CX|XSI)
341 
342     const SIG_BLOCK     = 0;
343     const SIG_UNBLOCK   = 1;
344     const SIG_SETMASK   = 2;
345 
346     private const __SI_MAX_SIZE = 128;
347 
348     static if( false /* __WORDSIZE == 64 */ )
349     {
350         private const __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4);
351     }
352     else
353     {
354         private const __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3);
355     }
356 
357     struct siginfo_t
358     {
359         int si_signo;       // Signal number
360         int si_errno;       // If non-zero, an errno value associated with
361                             // this signal, as defined in <errno.h>
362         int si_code;        // Signal code
363 
364         union _sifields_t
365         {
366             int[__SI_PAD_SIZE] _pad;
367 
368             // kill()
369             struct _kill_t
370             {
371                 pid_t si_pid; // Sending process ID
372                 uid_t si_uid; // Real user ID of sending process
373             } _kill_t _kill;
374 
375             // POSIX.1b timers.
376             struct _timer_t
377             {
378                 int    si_tid;     // Timer ID
379                 int    si_overrun; // Overrun count
380                 sigval si_sigval;  // Signal value
381             } _timer_t _timer;
382 
383             // POSIX.1b signals
384             struct _rt_t
385             {
386                 pid_t  si_pid;    // Sending process ID
387                 uid_t  si_uid;    // Real user ID of sending process
388                 sigval si_sigval; // Signal value
389             } _rt_t _rt;
390 
391             // SIGCHLD
392             struct _sigchild_t
393             {
394                 pid_t   si_pid;    // Which child
395                 uid_t   si_uid;    // Real user ID of sending process
396                 int     si_status; // Exit value or signal
397                 clock_t si_utime;
398                 clock_t si_stime;
399             } _sigchild_t _sigchld;
400 
401             // SIGILL, SIGFPE, SIGSEGV, SIGBUS
402             struct _sigfault_t
403             {
404                 void*     si_addr;  // Faulting insn/memory ref
405             } _sigfault_t _sigfault;
406 
407             // SIGPOLL
408             struct _sigpoll_t
409             {
410                 c_long   si_band;   // Band event for SIGPOLL
411                 int      si_fd;
412             } _sigpoll_t _sigpoll;
413         } _sifields_t _sifields;
414     }
415 
416     enum
417     {
418         SI_ASYNCNL = -60,
419         SI_TKILL   = -6,
420         SI_SIGIO,
421         SI_ASYNCIO,
422         SI_MESGQ,
423         SI_TIMER,
424         SI_QUEUE,
425         SI_USER,
426         SI_KERNEL  = 0x80
427     }
428 
429     int kill(pid_t, int);
430     int sigaction(int, in sigaction_t*, sigaction_t*);
431     int sigaddset(sigset_t*, int);
432     int sigdelset(sigset_t*, int);
433     int sigemptyset(sigset_t*);
434     int sigfillset(sigset_t*);
435     int sigismember(in sigset_t*, int);
436     int sigpending(sigset_t*);
437     int sigprocmask(int, in sigset_t*, sigset_t*);
438     int sigsuspend(in sigset_t*);
439     int sigwait(in sigset_t*, int*);
440 }
441 else version( darwin )
442 {
443     //SIG_HOLD
444 
445     alias uint sigset_t;
446     // pid_t  (defined in sys.types)
447 
448     //SIGABRT (defined in tango.stdc.signal)
449     //SIGFPE  (defined in tango.stdc.signal)
450     //SIGILL  (defined in tango.stdc.signal)
451     //SIGINT  (defined in tango.stdc.signal)
452     //SIGSEGV (defined in tango.stdc.signal)
453     //SIGTERM (defined in tango.stdc.signal)
454 
455     //SA_NOCLDSTOP (CX|XSI)
456 
457     const SIG_BLOCK=1;
458     const SIG_UNBLOCK=2;
459     const SIG_SETMASK=3;
460 
461     struct siginfo_t
462     {
463         int     si_signo;
464         int     si_errno;
465         int     si_code;
466         pid_t   si_pid;
467         uid_t   si_uid;
468         int     si_status;
469         void*   si_addr;
470         sigval  si_value;
471         int     si_band;
472         uint[7] pad;
473     }
474 
475     //SI_USER
476     //SI_QUEUE
477     //SI_TIMER
478     //SI_ASYNCIO
479     //SI_MESGQ
480 
481     int kill(pid_t, int);
482     int sigaction(int, in sigaction_t*, sigaction_t*);
483     int sigaddset(sigset_t*, int);
484     int sigdelset(sigset_t*, int);
485     int sigemptyset(sigset_t*);
486     int sigfillset(sigset_t*);
487     int sigismember(in sigset_t*, int);
488     int sigpending(sigset_t*);
489     int sigprocmask(int, in sigset_t*, sigset_t*);
490     int sigsuspend(in sigset_t*);
491     int sigwait(in sigset_t*, int*);
492     int sigaltstack(void * , void * );
493 }
494 else version( FreeBSD )
495 {
496     struct sigset_t
497     {
498         uint[4] __bits;
499     }
500    
501     const SIG_BLOCK = 2;
502     const SIG_UNBLOCK = 1;
503     const SIG_SETMASK = 3;
504    
505     struct siginfo_t
506     {
507         int si_signo;
508         int si_errno;
509         int si_code;
510         pid_t si_pid;
511         uid_t si_uid;
512         int si_status;
513         void* si_addr;
514         sigval si_value;
515         union __reason
516         {
517             struct __fault
518             {
519                 int _trapno;
520             }
521             __fault _fault;
522             struct __timer
523             {
524                 int _timerid;
525                 int _overrun;
526             }
527             __timer _timer;
528             struct __mesgq
529             {
530                 int _mqd;
531             }
532             __mesgq _mesgq;
533             struct __poll
534             {
535                 c_long _band;
536             }
537             __poll _poll;
538             struct ___spare___
539             {
540                 c_long __spare1__;
541                 int[7] __spare2__;
542             }
543             ___spare___ __spare__;
544         }
545         __reason _reason;
546     }
547 
548     int kill(pid_t, int);
549     int sigaction(int, in sigaction_t*, sigaction_t*);
550     int sigaddset(sigset_t*, int);
551     int sigdelset(sigset_t*, int);
552     int sigemptyset(sigset_t *);
553     int sigfillset(sigset_t *);
554     int sigismember(in sigset_t *, int);
555     int sigpending(sigset_t *);
556     int sigprocmask(int, in sigset_t*, sigset_t*);
557     int sigsuspend(in sigset_t *);
558     int sigwait(in sigset_t*, int*);
559 }
560 else version( solaris )
561 {
562     alias id_t taskid_t;
563     alias id_t projid_t;
564     alias id_t poolid_t;
565     alias id_t zoneid_t;
566     alias id_t ctid_t;
567     
568     const SIG_HOLD = cast(sigfn_t) 2;
569     
570     struct sigset_t
571     {
572         uint[4] __sigbits;
573     }
574     
575     // pid_t  (defined in sys.types)
576 
577     //SIGABRT (defined in tango.stdc.signal)
578     //SIGFPE  (defined in tango.stdc.signal)
579     //SIGILL  (defined in tango.stdc.signal)
580     //SIGINT  (defined in tango.stdc.signal)
581     //SIGSEGV (defined in tango.stdc.signal)
582     //SIGTERM (defined in tango.stdc.signal)
583 
584     const SA_NOCLDSTOP  = 0x00020000; // (CX|XSI)
585 
586     const SIG_BLOCK     = 1;
587     const SIG_UNBLOCK   = 2;
588     const SIG_SETMASK   = 3;
589 
590     static if( /* _LP64 */ size_t.sizeof == 8 ) {
591         const SI_MAXSZ  = 256;
592         const SI_PAD    = ((SI_MAXSZ / int.sizeof) - 4);
593     }
594     else {
595         const SI_MAXSZ  = 128;
596         const SI_PAD    = ((SI_MAXSZ / int.sizeof) - 3);
597     }
598     
599     struct siginfo_t
600     {
601         int     si_signo;           /* signal from signal.h */
602         int     si_code;            /* code from above  */
603         int     si_errno;           /* error from errno.h   */
604     static if( /* _LP64 */ size_t.sizeof == 8 ) {
605         int     si_pad;             /* _LP64 union starts on an 8-byte boundary */
606     }
607         union __data
608         {
609             int[SI_PAD] __pad;      /* for future growth    */
610 
611             struct __proc           /* kill(), SIGCLD, siqqueue() */
612             {
613                 pid_t   __pid;      /* process ID       */
614                 union __pdata
615                 {
616                     struct __kill {
617                         uid_t   __uid;
618                         sigval  __value;
619                     }
620                     struct __cld {
621                         clock_t __utime;
622                         int     __status;
623                         clock_t __stime;
624                     }
625                 }
626                 ctid_t      __ctid;     /* contract ID      */
627                 zoneid_t    __zoneid;   /* zone ID      */
628             }
629             
630             struct __fault  /* SIGSEGV, SIGBUS, SIGILL, SIGTRAP, SIGFPE */
631             {
632                 void*   __addr;     /* faulting address */
633                 int     __trapno;   /* illegal trap number  */
634                 caddr_t __pc;       /* instruction address  */
635             }
636 
637             struct __file           /* SIGPOLL, SIGXFSZ */
638             {
639             /* fd not currently available for SIGPOLL */
640                 int     __fd;       /* file descriptor  */
641                 long    __band;
642             }
643 
644             struct __prof           /* SIGPROF */
645             {
646                 caddr_t     __faddr;        /* last fault address   */
647                 timespec    __tstamp;       /* real time stamp  */
648                 short       __syscall;      /* current syscall  */
649                 char        __nsysarg;      /* number of arguments  */
650                 char        __fault;        /* last fault type  */
651                 long[8]     __sysarg;       /* syscall arguments    */
652                 int[10]     __mstate;       /* see <sys/msacct.h>   */
653             }
654 
655             struct __rctl {         /* SI_RCTL */
656                 int32_t     __entity;   /* type of entity exceeding */
657             }
658         }
659     }
660 
661     enum
662     {
663         SI_NOINFO   = 32767,    /* no signal information */
664         SI_DTRACE   = 2050,     /* kernel generated signal via DTrace action */
665         SI_RCTL     = 2049,     /* kernel generated signal via rctl action */
666         SI_USER     = 0,        /* user generated signal via kill() */
667         SI_LWP      = -1,       /* user generated signal via lwp_kill() */
668         SI_QUEUE    = -2,       /* user generated signal via sigqueue() */
669         SI_TIMER    = -3,       /* from timer expiration */
670         SI_ASYNCIO  = -4,       /* from asynchronous I/O completion */
671         SI_MESGQ    = -5        /* from message arrival */
672     }
673 
674     int kill(pid_t, int);
675     int sigaction(int, in sigaction_t*, sigaction_t*);
676     int sigaddset(sigset_t*, int);
677     int sigdelset(sigset_t*, int);
678     int sigemptyset(sigset_t*);
679     int sigfillset(sigset_t*);
680     int sigismember(in sigset_t*, int);
681     int sigpending(sigset_t*);
682     int sigprocmask(int, in sigset_t*, sigset_t*);
683     int sigsuspend(in sigset_t*);
684     int sigwait(in sigset_t*, int*);
685 }
686 
687 //
688 // XOpen (XSI)
689 //
690 /*
691 SIGPOLL
692 SIGPROF
693 SIGSYS
694 SIGTRAP
695 SIGVTALRM
696 SIGXCPU
697 SIGXFSZ
698 
699 SA_ONSTACK
700 SA_RESETHAND
701 SA_RESTART
702 SA_SIGINFO
703 SA_NOCLDWAIT
704 SA_NODEFER
705 SS_ONSTACK
706 SS_DISABLE
707 MINSIGSTKSZ
708 SIGSTKSZ
709 
710 ucontext_t // from ucontext
711 mcontext_t // from ucontext
712 
713 struct stack_t
714 {
715     void*   ss_sp;
716     size_t  ss_size;
717     int     ss_flags;
718 }
719 
720 struct sigstack
721 {
722     int   ss_onstack;
723     void* ss_sp;
724 }
725 
726 ILL_ILLOPC
727 ILL_ILLOPN
728 ILL_ILLADR
729 ILL_ILLTRP
730 ILL_PRVOPC
731 ILL_PRVREG
732 ILL_COPROC
733 ILL_BADSTK
734 
735 FPE_INTDIV
736 FPE_INTOVF
737 FPE_FLTDIV
738 FPE_FLTOVF
739 FPE_FLTUND
740 FPE_FLTRES
741 FPE_FLTINV
742 FPE_FLTSUB
743 
744 SEGV_MAPERR
745 SEGV_ACCERR
746 
747 BUS_ADRALN
748 BUS_ADRERR
749 BUS_OBJERR
750 
751 TRAP_BRKPT
752 TRAP_TRACE
753 
754 CLD_EXITED
755 CLD_KILLED
756 CLD_DUMPED
757 CLD_TRAPPED
758 CLD_STOPPED
759 CLD_CONTINUED
760 
761 POLL_IN
762 POLL_OUT
763 POLL_MSG
764 POLL_ERR
765 POLL_PRI
766 POLL_HUP
767 
768 sigfn_t bsd_signal(int sig, sigfn_t func);
769 sigfn_t sigset(int sig, sigfn_t func);
770 
771 int killpg(pid_t, int);
772 int sigaltstack(in stack_t*, stack_t*);
773 int sighold(int);
774 int sigignore(int);
775 int siginterrupt(int, int);
776 int sigpause(int);
777 int sigrelse(int);
778 */
779 
780 version( linux )
781 {
782     const SIGPOLL       = 29;
783     const SIGPROF       = 27;
784     const SIGSYS        = 31;
785     const SIGTRAP       = 5;
786     const SIGVTALRM     = 26;
787     const SIGXCPU       = 24;
788     const SIGXFSZ       = 25;
789 
790     const SA_ONSTACK    = 0x08000000;
791     const SA_RESETHAND  = 0x80000000;
792     const SA_RESTART    = 0x10000000;
793     const SA_SIGINFO    = 4;
794     const SA_NOCLDWAIT  = 2;
795     const SA_NODEFER    = 0x40000000;
796     const SS_ONSTACK    = 1;
797     const SS_DISABLE    = 2;
798     const MINSIGSTKSZ   = 2048;
799     const SIGSTKSZ      = 8192;
800 
801     //ucontext_t (defined in tango.stdc.posix.ucontext)
802     //mcontext_t (defined in tango.stdc.posix.ucontext)
803 
804     struct stack_t
805     {
806         void*   ss_sp;
807         int     ss_flags;
808         size_t  ss_size;
809     }
810 
811     struct sigstack
812     {
813         void*   ss_sp;
814         int     ss_onstack;
815     }
816 
817     enum
818     {
819         ILL_ILLOPC = 1,
820         ILL_ILLOPN,
821         ILL_ILLADR,
822         ILL_ILLTRP,
823         ILL_PRVOPC,
824         ILL_PRVREG,
825         ILL_COPROC,
826         ILL_BADSTK
827     }
828 
829     enum
830     {
831         FPE_INTDIV = 1,
832         FPE_INTOVF,
833         FPE_FLTDIV,
834         FPE_FLTOVF,
835         FPE_FLTUND,
836         FPE_FLTRES,
837         FPE_FLTINV,
838         FPE_FLTSUB
839     }
840 
841     enum
842     {
843         SEGV_MAPERR = 1,
844         SEGV_ACCERR
845     }
846 
847     enum
848     {
849         BUS_ADRALN = 1,
850         BUS_ADRERR,
851         BUS_OBJERR
852     }
853 
854     enum
855     {
856         TRAP_BRKPT = 1,
857         TRAP_TRACE
858     }
859 
860     enum
861     {
862         CLD_EXITED = 1,
863         CLD_KILLED,
864         CLD_DUMPED,
865         CLD_TRAPPED,
866         CLD_STOPPED,
867         CLD_CONTINUED
868     }
869 
870     enum
871     {
872         POLL_IN = 1,
873         POLL_OUT,
874         POLL_MSG,
875         POLL_ERR,
876         POLL_PRI,
877         POLL_HUP
878     }
879 
880     sigfn_t bsd_signal(int sig, sigfn_t func);
881     sigfn_t sigset(int sig, sigfn_t func);
882 
883     int killpg(pid_t, int);
884     int sigaltstack(in stack_t*, stack_t*);
885     int sighold(int);
886     int sigignore(int);
887     int siginterrupt(int, int);
888     int sigpause(int);
889     int sigrelse(int);
890 }
891 else version( FreeBSD )
892 {
893     const SIGPROF       = 27;
894     const SIGSYS        = 12;
895     const SIGTRAP       = 5;
896     const SIGVTALRM     = 26;
897     const SIGXCPU       = 24;
898     const SIGXFSZ       = 25;
899 
900     const SA_ONSTACK    = 0x0001;
901     const SA_RESETHAND  = 0x0004;
902     const SA_RESTART    = 0x0002;
903     const SA_SIGINFO    = 0x0040;
904     const SA_NOCLDWAIT  = 0x0020;
905     const SA_NODEFER    = 0x0010;
906     const SS_ONSTACK    = 0x0001;
907     const SS_DISABLE    = 0x0004;
908     const MINSIGSTKSZ   = (512 * 4);
909     const SIGSTKSZ      = (MINSIGSTKSZ + 32768);
910 
911     //ucontext_t (defined in tango.stdc.posix.ucontext)
912     //mcontext_t (defined in tango.stdc.posix.ucontext)
913 
914     struct stack_t
915     {
916         void* ss_sp;
917         size_t ss_size;
918         int ss_flags;
919     }
920 
921     struct sigstack
922     {
923         char* ss_sp;
924         int ss_onstack;
925     }
926 
927     enum
928     {
929         ILL_ILLOPC = 1,
930         ILL_ILLOPN,
931         ILL_ILLADR,
932         ILL_ILLTRP,
933         ILL_PRVOPC,
934         ILL_PRVREG,
935         ILL_COPROC,
936         ILL_BADSTK
937     }
938 
939     enum
940     {
941         FPE_INTOVF = 1,
942         FPE_INTDIV,
943         FPE_FLTDIV,
944         FPE_FLTOVF,
945         FPE_FLTUND,
946         FPE_FLTRES,
947         FPE_FLTINV,
948         FPE_FLTSUB
949     }
950 
951     enum
952     {
953         SEGV_MAPERR = 1,
954         SEGV_ACCERR
955     }
956 
957     enum
958     {
959         BUS_ADRALN = 1,
960         BUS_ADRERR,
961         BUS_OBJERR
962     }
963 
964     enum
965     {
966         TRAP_BRKPT = 1,
967         TRAP_TRACE
968     }
969 
970     enum
971     {
972         CLD_EXITED = 1,
973         CLD_KILLED,
974         CLD_DUMPED,
975         CLD_TRAPPED,
976         CLD_STOPPED,
977         CLD_CONTINUED
978     }
979 
980     enum
981     {
982         POLL_IN = 1,
983         POLL_OUT,
984         POLL_MSG,
985         POLL_ERR,
986         POLL_PRI,
987         POLL_HUP
988     }
989 
990     //sigfn_t bsd_signal(int sig, sigfn_t func);
991     //sigfn_t sigset(int sig, sigfn_t func);
992 
993     int killpg(pid_t, int);
994     int sigaltstack(stack_t*, stack_t*);
995     //int sighold(int);
996     int sigblock(int);
997     int sigignore(int);
998     int siginterrupt(int, int);
999     int sigpause(int);
1000     int sigrelse(int);
1001 }
1002 version(darwin){
1003     // to complete
1004     const int SA_ONSTACK   = 0x0001;
1005     const int SA_RESTART   = 0x0002;
1006     const int SA_RESETHAND = 0x0004;
1007     const int SA_NOCLDSTOP = 0x0008;
1008     const int SA_NODEFER   = 0x0010;
1009     const int SA_NOCLDWAIT = 0x0020;
1010     const int SA_SIGINFO   = 0x0040;
1011     const int SA_USERTRAMP = 0x0100;
1012     const MINSIGSTKSZ = 32768;
1013     const SIGSTKSZ = 131072;
1014 }
1015 version(solaris)
1016 {
1017     const SA_ONSTACK = 0x00000001;
1018     const SA_RESETHAND = 0x00000002;
1019     const SA_RESTART = 0x00000004;
1020     const SA_SIGINFO = 0x00000008;
1021 
1022     /* this is only valid for SIGCLD */
1023     const SA_NOCLDWAIT = 0x00010000; /* don't save zombie children  */
1024 
1025     const SA_NODEFER = 0x00000010;
1026     const SS_ONSTACK = 0x00000001;
1027     const SS_DISABLE = 0x00000002;
1028     const MINSIGSTKSZ = 2048;
1029     const SIGSTKSZ = 8192;
1030 
1031     struct stack_t {
1032         void* ss_sp;
1033         size_t ss_size;
1034         int ss_flags;
1035     };
1036 
1037 
1038     struct sigstack {
1039         void* ss_sp;
1040         int ss_onstack;
1041     };
1042 }
1043 
1044 
1045 //
1046 // Timer (TMR)
1047 //
1048 /*
1049 NOTE: This should actually be defined in tango.stdc.posix.time.
1050       It is defined here instead to break a circular import.
1051 
1052 struct timespec
1053 {
1054     time_t  tv_sec;
1055     int     tv_nsec;
1056 }
1057 */
1058 
1059 version( linux )
1060 {
1061     struct timespec
1062     {
1063         time_t  tv_sec;
1064         c_long  tv_nsec;
1065     }
1066 }
1067 else version( darwin )
1068 {
1069     struct timespec
1070     {
1071         time_t  tv_sec;
1072         c_long  tv_nsec;
1073     }
1074 }
1075 else version( FreeBSD )
1076 {
1077     struct timespec
1078     {
1079         time_t  tv_sec;
1080         c_long  tv_nsec;
1081     }
1082 }
1083 else version ( solaris )
1084 {
1085     struct timespec         /* definition per POSIX.4 */
1086     {
1087         time_t  tv_sec;     /* seconds */
1088         c_long  tv_nsec;    /* and nanoseconds */
1089     }
1090 }
1091 
1092 //
1093 // Realtime Signals (RTS)
1094 //
1095 /*
1096 struct sigevent
1097 {
1098     int             sigev_notify;
1099     int             sigev_signo;
1100     sigval          sigev_value;
1101     void(*)(sigval) sigev_notify_function;
1102     pthread_attr_t* sigev_notify_attributes;
1103 }
1104 
1105 int sigqueue(pid_t, int, in sigval);
1106 int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1107 int sigwaitinfo(in sigset_t*, siginfo_t*);
1108 */
1109 
1110 version( linux )
1111 {
1112     private const __SIGEV_MAX_SIZE = 64;
1113 
1114     static if( false /* __WORDSIZE == 64 */ )
1115     {
1116         private const __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4);
1117     }
1118     else
1119     {
1120         private const __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3);
1121     }
1122 
1123     struct sigevent
1124     {
1125         sigval      sigev_value;
1126         int         sigev_signo;
1127         int         sigev_notify;
1128 
1129         union _sigev_un_t
1130         {
1131             int[__SIGEV_PAD_SIZE] _pad;
1132             pid_t                 _tid;
1133 
1134             struct _sigev_thread_t
1135             {
1136                 void function(sigval)   _function;
1137                 void*                   _attribute;
1138             } _sigev_thread_t _sigev_thread;
1139         } _sigev_un_t _sigev_un;
1140     }
1141 
1142     int sigqueue(pid_t, int, in sigval);
1143     int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1144     int sigwaitinfo(in sigset_t*, siginfo_t*);
1145 }
1146 else version( FreeBSD )
1147 {
1148     struct sigevent
1149     {
1150         int             sigev_notify;
1151         int             sigev_signo;
1152         sigval          sigev_value;
1153         struct __sigev_thread {
1154             void function(sigval) _function;
1155             void* _attribute;
1156         }
1157         union  _sigev_un
1158         {
1159             lwpid_t _threadid;
1160             __sigev_thread _sigev_thread;
1161             c_long[8] __spare__;
1162         }
1163     }
1164 
1165     int sigqueue(pid_t, int, in sigval);
1166     int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1167     int sigwaitinfo(in sigset_t*, siginfo_t*);
1168 }
1169 else version ( solaris )
1170 {
1171     struct sigevent {
1172         int                     sigev_notify;   /* notification mode */
1173         int                     sigev_signo;    /* signal number */
1174         sigval                  sigev_value;    /* signal value */
1175         void function(sigval)   sigev_notify_function;
1176         pthread_attr_t*         sigev_notify_attributes;
1177         private int             __sigev_pad2;
1178     }
1179 } else version (darwin){
1180     struct sigevent {
1181      int sigev_notify;
1182      int sigev_signo;
1183      sigval sigev_value;
1184      void function(sigval) sigev_notify_function;
1185      pthread_attr_t *sigev_notify_attributes;
1186     }
1187 }
1188 
1189 //
1190 // Threads (THR)
1191 //
1192 /*
1193 int pthread_kill(pthread_t, int);
1194 int pthread_sigmask(int, in sigset_t*, sigset_t*);
1195 */
1196 
1197 version( linux )
1198 {
1199     int pthread_kill(pthread_t, int);
1200     int pthread_sigmask(int, in sigset_t*, sigset_t*);
1201 }
1202 else version( darwin )
1203 {
1204     int pthread_kill(pthread_t, int);
1205     int pthread_sigmask(int, in sigset_t*, sigset_t*);
1206 }
1207 else version( FreeBSD )
1208 {
1209     int pthread_kill(pthread_t, int);
1210     int pthread_sigmask(int, in sigset_t*, sigset_t*);
1211 }
1212 else version( solaris )
1213 {
1214     int pthread_kill(pthread_t, int);
1215     int pthread_sigmask(int, in sigset_t*, sigset_t*);
1216 }