comparison druntime/import/core/sys/posix/signal.d @ 1458:e0b2d67cfe7c

Added druntime (this should be removed once it works).
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 02 Jun 2009 17:43:06 +0100
parents
children
comparison
equal deleted inserted replaced
1456:7b218ec1044f 1458:e0b2d67cfe7c
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>.
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 *
9 * Copyright Sean Kelly 2005 - 2009.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE_1_0.txt or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
13 */
14 module core.sys.posix.signal;
15
16 private import core.sys.posix.config;
17 public import core.stdc.signal;
18 public import core.stdc.stddef; // for size_t
19 public import core.sys.posix.sys.types; // for pid_t
20 //public import core.sys.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 core.stdc.signal)
32 SIG_ERR (defined in core.stdc.signal)
33 SIG_IGN (defined in core.stdc.signal)
34
35 sig_atomic_t (defined in core.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 core.stdc.signal)
51 SIGALRM
52 SIGBUS
53 SIGCHLD
54 SIGCONT
55 SIGFPE (defined in core.stdc.signal)
56 SIGHUP
57 SIGILL (defined in core.stdc.signal)
58 SIGINT (defined in core.stdc.signal)
59 SIGKILL
60 SIGPIPE
61 SIGQUIT
62 SIGSEGV (defined in core.stdc.signal)
63 SIGSTOP
64 SIGTERM (defined in core.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 core.stdc.signal)
80 int raise(int sig); (defined in core.stdc.signal)
81 */
82
83 //SIG_DFL (defined in core.stdc.signal)
84 //SIG_ERR (defined in core.stdc.signal)
85 //SIG_IGN (defined in core.stdc.signal)
86
87 //sig_atomic_t (defined in core.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 core.stdc.signal)
111 enum SIGALRM = 14;
112 enum SIGBUS = 7;
113 enum SIGCHLD = 17;
114 enum SIGCONT = 18;
115 //SIGFPE (defined in core.stdc.signal)
116 enum SIGHUP = 1;
117 //SIGILL (defined in core.stdc.signal)
118 //SIGINT (defined in core.stdc.signal)
119 enum SIGKILL = 9;
120 enum SIGPIPE = 13;
121 enum SIGQUIT = 3;
122 //SIGSEGV (defined in core.stdc.signal)
123 enum SIGSTOP = 19;
124 //SIGTERM (defined in core.stdc.signal)
125 enum SIGTSTP = 20;
126 enum SIGTTIN = 21;
127 enum SIGTTOU = 22;
128 enum SIGUSR1 = 10;
129 enum SIGUSR2 = 12;
130 enum SIGURG = 23;
131 }
132 else version( OSX )
133 {
134 //SIGABRT (defined in core.stdc.signal)
135 enum SIGALRM = 14;
136 enum SIGBUS = 10;
137 enum SIGCHLD = 20;
138 enum SIGCONT = 19;
139 //SIGFPE (defined in core.stdc.signal)
140 enum SIGHUP = 1;
141 //SIGILL (defined in core.stdc.signal)
142 //SIGINT (defined in core.stdc.signal)
143 enum SIGKILL = 9;
144 enum SIGPIPE = 13;
145 enum SIGQUIT = 3;
146 //SIGSEGV (defined in core.stdc.signal)
147 enum SIGSTOP = 17;
148 //SIGTERM (defined in core.stdc.signal)
149 enum SIGTSTP = 18;
150 enum SIGTTIN = 21;
151 enum SIGTTOU = 22;
152 enum SIGUSR1 = 30;
153 enum SIGUSR2 = 31;
154 enum SIGURG = 16;
155 }
156 else version( freebsd )
157 {
158 //SIGABRT (defined in core.stdc.signal)
159 enum SIGALRM = 14;
160 enum SIGBUS = 10;
161 enum SIGCHLD = 20;
162 enum SIGCONT = 19;
163 //SIGFPE (defined in core.stdc.signal)
164 enum SIGHUP = 1;
165 //SIGILL (defined in core.stdc.signal)
166 //SIGINT (defined in core.stdc.signal)
167 enum SIGKILL = 9;
168 enum SIGPIPE = 13;
169 enum SIGQUIT = 3;
170 //SIGSEGV (defined in core.stdc.signal)
171 enum SIGSTOP = 17;
172 //SIGTERM (defined in core.stdc.signal)
173 enum SIGTSTP = 18;
174 enum SIGTTIN = 21;
175 enum SIGTTOU = 22;
176 enum SIGUSR1 = 30;
177 enum SIGUSR2 = 31;
178 enum SIGURG = 16;
179 }
180
181 struct sigaction_t
182 {
183 static if( true /* __USE_POSIX199309 */ )
184 {
185 union
186 {
187 sigfn_t sa_handler;
188 sigactfn_t sa_sigaction;
189 }
190 }
191 else
192 {
193 sigfn_t sa_handler;
194 }
195 sigset_t sa_mask;
196 int sa_flags;
197
198 version( OSX ) {} else {
199 void function() sa_restorer;
200 }
201 }
202
203 //
204 // C Extension (CX)
205 //
206 /*
207 SIG_HOLD
208
209 sigset_t
210 pid_t (defined in core.sys.types)
211
212 SIGABRT (defined in core.stdc.signal)
213 SIGFPE (defined in core.stdc.signal)
214 SIGILL (defined in core.stdc.signal)
215 SIGINT (defined in core.stdc.signal)
216 SIGSEGV (defined in core.stdc.signal)
217 SIGTERM (defined in core.stdc.signal)
218
219 SA_NOCLDSTOP (CX|XSI)
220 SIG_BLOCK
221 SIG_UNBLOCK
222 SIG_SETMASK
223
224 struct siginfo_t
225 {
226 int si_signo;
227 int si_code;
228
229 version( XSI )
230 {
231 int si_errno;
232 pid_t si_pid;
233 uid_t si_uid;
234 void* si_addr;
235 int si_status;
236 c_long si_band;
237 }
238 version( RTS )
239 {
240 sigval si_value;
241 }
242 }
243
244 SI_USER
245 SI_QUEUE
246 SI_TIMER
247 SI_ASYNCIO
248 SI_MESGQ
249
250 int kill(pid_t, int);
251 int sigaction(int, in sigaction_t*, sigaction_t*);
252 int sigaddset(sigset_t*, int);
253 int sigdelset(sigset_t*, int);
254 int sigemptyset(sigset_t*);
255 int sigfillset(sigset_t*);
256 int sigismember(in sigset_t*, int);
257 int sigpending(sigset_t*);
258 int sigprocmask(int, in sigset_t*, sigset_t*);
259 int sigsuspend(in sigset_t*);
260 int sigwait(in sigset_t*, int*);
261 */
262
263 version( linux )
264 {
265 enum SIG_HOLD = cast(sigfn_t) 1;
266
267 private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof);
268
269 struct sigset_t
270 {
271 c_ulong[_SIGSET_NWORDS] __val;
272 }
273
274 // pid_t (defined in core.sys.types)
275
276 //SIGABRT (defined in core.stdc.signal)
277 //SIGFPE (defined in core.stdc.signal)
278 //SIGILL (defined in core.stdc.signal)
279 //SIGINT (defined in core.stdc.signal)
280 //SIGSEGV (defined in core.stdc.signal)
281 //SIGTERM (defined in core.stdc.signal)
282
283 enum SA_NOCLDSTOP = 1; // (CX|XSI)
284
285 enum SIG_BLOCK = 0;
286 enum SIG_UNBLOCK = 1;
287 enum SIG_SETMASK = 2;
288
289 private enum __SI_MAX_SIZE = 128;
290
291 static if( false /* __WORDSIZE == 64 */ )
292 {
293 private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4);
294 }
295 else
296 {
297 private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3);
298 }
299
300 struct siginfo_t
301 {
302 int si_signo; // Signal number
303 int si_errno; // If non-zero, an errno value associated with
304 // this signal, as defined in <errno.h>
305 int si_code; // Signal code
306
307 union _sifields_t
308 {
309 int _pad[__SI_PAD_SIZE];
310
311 // kill()
312 struct _kill_t
313 {
314 pid_t si_pid; // Sending process ID
315 uid_t si_uid; // Real user ID of sending process
316 } _kill_t _kill;
317
318 // POSIX.1b timers.
319 struct _timer_t
320 {
321 int si_tid; // Timer ID
322 int si_overrun; // Overrun count
323 sigval si_sigval; // Signal value
324 } _timer_t _timer;
325
326 // POSIX.1b signals
327 struct _rt_t
328 {
329 pid_t si_pid; // Sending process ID
330 uid_t si_uid; // Real user ID of sending process
331 sigval si_sigval; // Signal value
332 } _rt_t _rt;
333
334 // SIGCHLD
335 struct _sigchild_t
336 {
337 pid_t si_pid; // Which child
338 uid_t si_uid; // Real user ID of sending process
339 int si_status; // Exit value or signal
340 clock_t si_utime;
341 clock_t si_stime;
342 } _sigchild_t _sigchld;
343
344 // SIGILL, SIGFPE, SIGSEGV, SIGBUS
345 struct _sigfault_t
346 {
347 void* si_addr; // Faulting insn/memory ref
348 } _sigfault_t _sigfault;
349
350 // SIGPOLL
351 struct _sigpoll_t
352 {
353 c_long si_band; // Band event for SIGPOLL
354 int si_fd;
355 } _sigpoll_t _sigpoll;
356 } _sifields_t _sifields;
357 }
358
359 enum
360 {
361 SI_ASYNCNL = -60,
362 SI_TKILL = -6,
363 SI_SIGIO,
364 SI_ASYNCIO,
365 SI_MESGQ,
366 SI_TIMER,
367 SI_QUEUE,
368 SI_USER,
369 SI_KERNEL = 0x80
370 }
371
372 int kill(pid_t, int);
373 int sigaction(int, in sigaction_t*, sigaction_t*);
374 int sigaddset(sigset_t*, int);
375 int sigdelset(sigset_t*, int);
376 int sigemptyset(sigset_t*);
377 int sigfillset(sigset_t*);
378 int sigismember(in sigset_t*, int);
379 int sigpending(sigset_t*);
380 int sigprocmask(int, in sigset_t*, sigset_t*);
381 int sigsuspend(in sigset_t*);
382 int sigwait(in sigset_t*, int*);
383 }
384 else version( OSX )
385 {
386 //SIG_HOLD
387
388 alias uint sigset_t;
389 // pid_t (defined in core.sys.types)
390
391 //SIGABRT (defined in core.stdc.signal)
392 //SIGFPE (defined in core.stdc.signal)
393 //SIGILL (defined in core.stdc.signal)
394 //SIGINT (defined in core.stdc.signal)
395 //SIGSEGV (defined in core.stdc.signal)
396 //SIGTERM (defined in core.stdc.signal)
397
398 //SA_NOCLDSTOP (CX|XSI)
399
400 //SIG_BLOCK
401 //SIG_UNBLOCK
402 //SIG_SETMASK
403
404 struct siginfo_t
405 {
406 int si_signo;
407 int si_errno;
408 int si_code;
409 pid_t si_pid;
410 uid_t si_uid;
411 int si_status;
412 void* si_addr;
413 sigval si_value;
414 int si_band;
415 uint pad[7];
416 }
417
418 //SI_USER
419 //SI_QUEUE
420 //SI_TIMER
421 //SI_ASYNCIO
422 //SI_MESGQ
423
424 int kill(pid_t, int);
425 int sigaction(int, in sigaction_t*, sigaction_t*);
426 int sigaddset(sigset_t*, int);
427 int sigdelset(sigset_t*, int);
428 int sigemptyset(sigset_t*);
429 int sigfillset(sigset_t*);
430 int sigismember(in sigset_t*, int);
431 int sigpending(sigset_t*);
432 int sigprocmask(int, in sigset_t*, sigset_t*);
433 int sigsuspend(in sigset_t*);
434 int sigwait(in sigset_t*, int*);
435 }
436 else version( freebsd )
437 {
438 struct sigset_t
439 {
440 uint __bits[4];
441 }
442
443 struct siginfo_t
444 {
445 int si_signo;
446 int si_errno;
447 int si_code;
448 pid_t si_pid;
449 uid_t si_uid;
450 int si_status;
451 void* si_addr;
452 sigval si_value;
453 union __reason
454 {
455 struct __fault
456 {
457 int _trapno;
458 }
459 __fault _fault;
460 struct __timer
461 {
462 int _timerid;
463 int _overrun;
464 }
465 __timer _timer;
466 struct __mesgq
467 {
468 int _mqd;
469 }
470 __mesgq _mesgq;
471 struct __poll
472 {
473 c_long _band;
474 }
475 __poll _poll;
476 struct ___spare___
477 {
478 c_long __spare1__;
479 int[7] __spare2__;
480 }
481 ___spare___ __spare__;
482 }
483 __reason _reason;
484 }
485
486 int kill(pid_t, int);
487 int sigaction(int, in sigaction_t*, sigaction_t);
488 int sigaddset(sigset_t*, int);
489 int sigdelset(sigset_t*, int);
490 int sigemptyset(sigset_t *);
491 int sigfillset(sigset_t *);
492 int sigismember(in sigset_t *, int);
493 int sigpending(sigset_t *);
494 int sigprocmask(int, in sigset_t*, sigset_t*);
495 int sigsuspend(in sigset_t *);
496 int sigwait(in sigset_t*, int*);
497 }
498
499
500 //
501 // XOpen (XSI)
502 //
503 /*
504 SIGPOLL
505 SIGPROF
506 SIGSYS
507 SIGTRAP
508 SIGVTALRM
509 SIGXCPU
510 SIGXFSZ
511
512 SA_ONSTACK
513 SA_RESETHAND
514 SA_RESTART
515 SA_SIGINFO
516 SA_NOCLDWAIT
517 SA_NODEFER
518 SS_ONSTACK
519 SS_DISABLE
520 MINSIGSTKSZ
521 SIGSTKSZ
522
523 ucontext_t // from ucontext
524 mcontext_t // from ucontext
525
526 struct stack_t
527 {
528 void* ss_sp;
529 size_t ss_size;
530 int ss_flags;
531 }
532
533 struct sigstack
534 {
535 int ss_onstack;
536 void* ss_sp;
537 }
538
539 ILL_ILLOPC
540 ILL_ILLOPN
541 ILL_ILLADR
542 ILL_ILLTRP
543 ILL_PRVOPC
544 ILL_PRVREG
545 ILL_COPROC
546 ILL_BADSTK
547
548 FPE_INTDIV
549 FPE_INTOVF
550 FPE_FLTDIV
551 FPE_FLTOVF
552 FPE_FLTUND
553 FPE_FLTRES
554 FPE_FLTINV
555 FPE_FLTSUB
556
557 SEGV_MAPERR
558 SEGV_ACCERR
559
560 BUS_ADRALN
561 BUS_ADRERR
562 BUS_OBJERR
563
564 TRAP_BRKPT
565 TRAP_TRACE
566
567 CLD_EXITED
568 CLD_KILLED
569 CLD_DUMPED
570 CLD_TRAPPED
571 CLD_STOPPED
572 CLD_CONTINUED
573
574 POLL_IN
575 POLL_OUT
576 POLL_MSG
577 POLL_ERR
578 POLL_PRI
579 POLL_HUP
580
581 sigfn_t bsd_signal(int sig, sigfn_t func);
582 sigfn_t sigset(int sig, sigfn_t func);
583
584 int killpg(pid_t, int);
585 int sigaltstack(in stack_t*, stack_t*);
586 int sighold(int);
587 int sigignore(int);
588 int siginterrupt(int, int);
589 int sigpause(int);
590 int sigrelse(int);
591 */
592
593 version( linux )
594 {
595 enum SIGPOLL = 29;
596 enum SIGPROF = 27;
597 enum SIGSYS = 31;
598 enum SIGTRAP = 5;
599 enum SIGVTALRM = 26;
600 enum SIGXCPU = 24;
601 enum SIGXFSZ = 25;
602
603 enum SA_ONSTACK = 0x08000000;
604 enum SA_RESETHAND = 0x80000000;
605 enum SA_RESTART = 0x10000000;
606 enum SA_SIGINFO = 4;
607 enum SA_NOCLDWAIT = 2;
608 enum SA_NODEFER = 0x40000000;
609 enum SS_ONSTACK = 1;
610 enum SS_DISABLE = 2;
611 enum MINSIGSTKSZ = 2048;
612 enum SIGSTKSZ = 8192;
613
614 //ucontext_t (defined in core.sys.posix.ucontext)
615 //mcontext_t (defined in core.sys.posix.ucontext)
616
617 struct stack_t
618 {
619 void* ss_sp;
620 int ss_flags;
621 size_t ss_size;
622 }
623
624 struct sigstack
625 {
626 void* ss_sp;
627 int ss_onstack;
628 }
629
630 enum
631 {
632 ILL_ILLOPC = 1,
633 ILL_ILLOPN,
634 ILL_ILLADR,
635 ILL_ILLTRP,
636 ILL_PRVOPC,
637 ILL_PRVREG,
638 ILL_COPROC,
639 ILL_BADSTK
640 }
641
642 enum
643 {
644 FPE_INTDIV = 1,
645 FPE_INTOVF,
646 FPE_FLTDIV,
647 FPE_FLTOVF,
648 FPE_FLTUND,
649 FPE_FLTRES,
650 FPE_FLTINV,
651 FPE_FLTSUB
652 }
653
654 enum
655 {
656 SEGV_MAPERR = 1,
657 SEGV_ACCERR
658 }
659
660 enum
661 {
662 BUS_ADRALN = 1,
663 BUS_ADRERR,
664 BUS_OBJERR
665 }
666
667 enum
668 {
669 TRAP_BRKPT = 1,
670 TRAP_TRACE
671 }
672
673 enum
674 {
675 CLD_EXITED = 1,
676 CLD_KILLED,
677 CLD_DUMPED,
678 CLD_TRAPPED,
679 CLD_STOPPED,
680 CLD_CONTINUED
681 }
682
683 enum
684 {
685 POLL_IN = 1,
686 POLL_OUT,
687 POLL_MSG,
688 POLL_ERR,
689 POLL_PRI,
690 POLL_HUP
691 }
692
693 sigfn_t bsd_signal(int sig, sigfn_t func);
694 sigfn_t sigset(int sig, sigfn_t func);
695
696 int killpg(pid_t, int);
697 int sigaltstack(in stack_t*, stack_t*);
698 int sighold(int);
699 int sigignore(int);
700 int siginterrupt(int, int);
701 int sigpause(int);
702 int sigrelse(int);
703 }
704
705 //
706 // Timer (TMR)
707 //
708 /*
709 NOTE: This should actually be defined in core.sys.posix.time.
710 It is defined here instead to break a circular import.
711
712 struct timespec
713 {
714 time_t tv_sec;
715 int tv_nsec;
716 }
717 */
718
719 version( linux )
720 {
721 struct timespec
722 {
723 time_t tv_sec;
724 c_long tv_nsec;
725 }
726 }
727 else version( OSX )
728 {
729 struct timespec
730 {
731 time_t tv_sec;
732 c_long tv_nsec;
733 }
734 }
735 else version( freebsd )
736 {
737 struct timespec
738 {
739 time_t tv_sec;
740 c_long tv_nsec;
741 }
742 }
743
744 //
745 // Realtime Signals (RTS)
746 //
747 /*
748 struct sigevent
749 {
750 int sigev_notify;
751 int sigev_signo;
752 sigval sigev_value;
753 void(*)(sigval) sigev_notify_function;
754 pthread_attr_t* sigev_notify_attributes;
755 }
756
757 int sigqueue(pid_t, int, in sigval);
758 int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
759 int sigwaitinfo(in sigset_t*, siginfo_t*);
760 */
761
762 version( linux )
763 {
764 private enum __SIGEV_MAX_SIZE = 64;
765
766 static if( false /* __WORDSIZE == 64 */ )
767 {
768 private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4);
769 }
770 else
771 {
772 private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3);
773 }
774
775 struct sigevent
776 {
777 sigval sigev_value;
778 int sigev_signo;
779 int sigev_notify;
780
781 union _sigev_un_t
782 {
783 int[__SIGEV_PAD_SIZE] _pad;
784 pid_t _tid;
785
786 struct _sigev_thread_t
787 {
788 void function(sigval) _function;
789 void* _attribute;
790 } _sigev_thread_t _sigev_thread;
791 } _sigev_un_t _sigev_un;
792 }
793
794 int sigqueue(pid_t, int, in sigval);
795 int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
796 int sigwaitinfo(in sigset_t*, siginfo_t*);
797 }
798 else version( freebsd )
799 {
800 struct sigevent
801 {
802 int sigev_notify;
803 int sigev_signo;
804 sigval sigev_value;
805 union _sigev_un
806 {
807 lwpid_t _threadid;
808 struct _sigev_thread
809 {
810 void function(sigval) _function;
811 void* _attribute;
812 }
813 c_long[8] __spare__;
814 }
815 }
816
817 int sigqueue(pid_t, int, in sigval);
818 int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
819 int sigwaitinfo(in sigset_t*, siginfo_t*);
820 }
821 //
822 // Threads (THR)
823 //
824 /*
825 int pthread_kill(pthread_t, int);
826 int pthread_sigmask(int, in sigset_t*, sigset_t*);
827 */
828
829 version( linux )
830 {
831 int pthread_kill(pthread_t, int);
832 int pthread_sigmask(int, in sigset_t*, sigset_t*);
833 }
834 else version( OSX )
835 {
836 int pthread_kill(pthread_t, int);
837 int pthread_sigmask(int, in sigset_t*, sigset_t*);
838 }
839 else version( freebsd )
840 {
841 int pthread_kill(pthread_t, int);
842 int pthread_sigmask(int, in sigset_t*, sigset_t*);
843 }