comparison tango/tango/stdc/posix/signal.d @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents
children
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Public Domain
5 * License: Public Domain
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 */
9 module tango.stdc.posix.signal;
10
11 private import tango.stdc.posix.config;
12 public import tango.stdc.signal;
13 public import tango.stdc.stddef; // for size_t
14 public import tango.stdc.posix.sys.types; // for pid_t
15 //public import tango.stdc.posix.time; // for timespec, now defined here
16
17 extern (C):
18
19 private alias void function(int) sigfn_t;
20 private alias void function(int, siginfo_t*, void*) sigactfn_t;
21
22 //
23 // Required
24 //
25 /*
26 SIG_DFL (defined in tango.stdc.signal)
27 SIG_ERR (defined in tango.stdc.signal)
28 SIG_IGN (defined in tango.stdc.signal)
29
30 sig_atomic_t (defined in tango.stdc.signal)
31
32 SIGEV_NONE
33 SIGEV_SIGNAL
34 SIGEV_THREAD
35
36 union sigval
37 {
38 int sival_int;
39 void* sival_ptr;
40 }
41
42 SIGRTMIN
43 SIGRTMAX
44
45 SIGABRT (defined in tango.stdc.signal)
46 SIGALRM
47 SIGBUS
48 SIGCHLD
49 SIGCONT
50 SIGFPE (defined in tango.stdc.signal)
51 SIGHUP
52 SIGILL (defined in tango.stdc.signal)
53 SIGINT (defined in tango.stdc.signal)
54 SIGKILL
55 SIGPIPE
56 SIGQUIT
57 SIGSEGV (defined in tango.stdc.signal)
58 SIGSTOP
59 SIGTERM (defined in tango.stdc.signal)
60 SIGTSTP
61 SIGTTIN
62 SIGTTOU
63 SIGUSR1
64 SIGUSR2
65 SIGURG
66
67 struct sigaction_t
68 {
69 sigfn_t sa_handler;
70 sigset_t sa_mask;
71 sigactfn_t sa_sigaction;
72 }
73
74 sigfn_t signal(int sig, sigfn_t func); (defined in tango.stdc.signal)
75 int raise(int sig); (defined in tango.stdc.signal)
76 */
77
78 //SIG_DFL (defined in tango.stdc.signal)
79 //SIG_ERR (defined in tango.stdc.signal)
80 //SIG_IGN (defined in tango.stdc.signal)
81
82 //sig_atomic_t (defined in tango.stdc.signal)
83
84 enum
85 {
86 SIGEV_SIGNAL,
87 SIGEV_NONE,
88 SIGEV_THREAD
89 }
90
91 union sigval
92 {
93 int sival_int;
94 void* sival_ptr;
95 }
96
97 private extern (C) int __libc_current_sigrtmin();
98 private extern (C) int __libc_current_sigrtmax();
99
100 alias __libc_current_sigrtmin SIGRTMIN;
101 alias __libc_current_sigrtmax SIGRTMAX;
102
103 version( linux )
104 {
105 //SIGABRT (defined in tango.stdc.signal)
106 const SIGALRM = 14;
107 const SIGBUS = 7;
108 const SIGCHLD = 17;
109 const SIGCONT = 18;
110 //SIGFPE (defined in tango.stdc.signal)
111 const SIGHUP = 1;
112 //SIGILL (defined in tango.stdc.signal)
113 //SIGINT (defined in tango.stdc.signal)
114 const SIGKILL = 9;
115 const SIGPIPE = 13;
116 const SIGQUIT = 3;
117 //SIGSEGV (defined in tango.stdc.signal)
118 const SIGSTOP = 19;
119 //SIGTERM (defined in tango.stdc.signal)
120 const SIGTSTP = 20;
121 const SIGTTIN = 21;
122 const SIGTTOU = 22;
123 const SIGUSR1 = 10;
124 const SIGUSR2 = 12;
125 const SIGURG = 23;
126 }
127 else version( darwin )
128 {
129 //SIGABRT (defined in tango.stdc.signal)
130 const SIGALRM = 14;
131 const SIGBUS = 10;
132 const SIGCHLD = 20;
133 const SIGCONT = 19;
134 //SIGFPE (defined in tango.stdc.signal)
135 const SIGHUP = 1;
136 //SIGILL (defined in tango.stdc.signal)
137 //SIGINT (defined in tango.stdc.signal)
138 const SIGKILL = 9;
139 const SIGPIPE = 13;
140 const SIGQUIT = 3;
141 //SIGSEGV (defined in tango.stdc.signal)
142 const SIGSTOP = 17;
143 //SIGTERM (defined in tango.stdc.signal)
144 const SIGTSTP = 18;
145 const SIGTTIN = 21;
146 const SIGTTOU = 22;
147 const SIGUSR1 = 30;
148 const SIGUSR2 = 31;
149 const SIGURG = 16;
150 }
151
152 struct sigaction_t
153 {
154 static if( true /* __USE_POSIX199309 */ )
155 {
156 union
157 {
158 sigfn_t sa_handler;
159 sigactfn_t sa_sigaction;
160 }
161 }
162 else
163 {
164 sigfn_t sa_handler;
165 }
166 sigset_t sa_mask;
167 int sa_flags;
168
169 version( darwin ) {} else {
170 void function() sa_restorer;
171 }
172 }
173
174 //
175 // C Extension (CX)
176 //
177 /*
178 SIG_HOLD
179
180 sigset_t
181 pid_t (defined in sys.types)
182
183 SIGABRT (defined in tango.stdc.signal)
184 SIGFPE (defined in tango.stdc.signal)
185 SIGILL (defined in tango.stdc.signal)
186 SIGINT (defined in tango.stdc.signal)
187 SIGSEGV (defined in tango.stdc.signal)
188 SIGTERM (defined in tango.stdc.signal)
189
190 SA_NOCLDSTOP (CX|XSI)
191 SIG_BLOCK
192 SIG_UNBLOCK
193 SIG_SETMASK
194
195 struct siginfo_t
196 {
197 int si_signo;
198 int si_code;
199
200 version( XSI )
201 {
202 int si_errno;
203 pid_t si_pid;
204 uid_t si_uid;
205 void* si_addr;
206 int si_status;
207 c_long si_band;
208 }
209 version( RTS )
210 {
211 sigval si_value;
212 }
213 }
214
215 SI_USER
216 SI_QUEUE
217 SI_TIMER
218 SI_ASYNCIO
219 SI_MESGQ
220
221 int kill(pid_t, int);
222 int sigaction(int, sigaction_t*, sigaction_t*);
223 int sigaddset(sigset_t*, int);
224 int sigdelset(sigset_t*, int);
225 int sigemptyset(sigset_t*);
226 int sigfillset(sigset_t*);
227 int sigismember( sigset_t*, int);
228 int sigpending(sigset_t*);
229 int sigprocmask(int, sigset_t*, sigset_t*);
230 int sigsuspend(sigset_t*);
231 int sigwait(sigset_t*, int*);
232 */
233
234 version( linux )
235 {
236 const SIG_HOLD = cast(sigfn_t) 1;
237
238 private const _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof);
239
240 struct sigset_t
241 {
242 c_ulong[_SIGSET_NWORDS] __val;
243 }
244
245 // pid_t (defined in sys.types)
246
247 //SIGABRT (defined in tango.stdc.signal)
248 //SIGFPE (defined in tango.stdc.signal)
249 //SIGILL (defined in tango.stdc.signal)
250 //SIGINT (defined in tango.stdc.signal)
251 //SIGSEGV (defined in tango.stdc.signal)
252 //SIGTERM (defined in tango.stdc.signal)
253
254 const SA_NOCLDSTOP = 1; // (CX|XSI)
255
256 const SIG_BLOCK = 0;
257 const SIG_UNBLOCK = 1;
258 const SIG_SETMASK = 2;
259
260 private const __SI_MAX_SIZE = 128;
261
262 static if( false /* __WORDSIZE == 64 */ )
263 {
264 private const __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4);
265 }
266 else
267 {
268 private const __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3);
269 }
270
271 struct siginfo_t
272 {
273 int si_signo; // Signal number
274 int si_errno; // If non-zero, an errno value associated with
275 // this signal, as defined in <errno.h>
276 int si_code; // Signal code
277
278 union _sifields_t
279 {
280 int _pad[__SI_PAD_SIZE];
281
282 // kill()
283 struct _kill_t
284 {
285 pid_t si_pid; // Sending process ID
286 uid_t si_uid; // Real user ID of sending process
287 } _kill_t _kill;
288
289 // POSIX.1b timers.
290 struct _timer_t
291 {
292 int si_tid; // Timer ID
293 int si_overrun; // Overrun count
294 sigval si_sigval; // Signal value
295 } _timer_t _timer;
296
297 // POSIX.1b signals
298 struct _rt_t
299 {
300 pid_t si_pid; // Sending process ID
301 uid_t si_uid; // Real user ID of sending process
302 sigval si_sigval; // Signal value
303 } _rt_t _rt;
304
305 // SIGCHLD
306 struct _sigchild_t
307 {
308 pid_t si_pid; // Which child
309 uid_t si_uid; // Real user ID of sending process
310 int si_status; // Exit value or signal
311 clock_t si_utime;
312 clock_t si_stime;
313 } _sigchild_t _sigchld;
314
315 // SIGILL, SIGFPE, SIGSEGV, SIGBUS
316 struct _sigfault_t
317 {
318 void* si_addr; // Faulting insn/memory ref
319 } _sigfault_t _sigfault;
320
321 // SIGPOLL
322 struct _sigpoll_t
323 {
324 c_long si_band; // Band event for SIGPOLL
325 int si_fd;
326 } _sigpoll_t _sigpoll;
327 } _sifields_t _sifields;
328 }
329
330 enum
331 {
332 SI_ASYNCNL = -60,
333 SI_TKILL = -6,
334 SI_SIGIO,
335 SI_ASYNCIO,
336 SI_MESGQ,
337 SI_TIMER,
338 SI_QUEUE,
339 SI_USER,
340 SI_KERNEL = 0x80
341 }
342
343 int kill(pid_t, int);
344 int sigaction(int, sigaction_t*, sigaction_t*);
345 int sigaddset(sigset_t*, int);
346 int sigdelset(sigset_t*, int);
347 int sigemptyset(sigset_t*);
348 int sigfillset(sigset_t*);
349 int sigismember( sigset_t*, int);
350 int sigpending(sigset_t*);
351 int sigprocmask(int, sigset_t*, sigset_t*);
352 int sigsuspend(sigset_t*);
353 int sigwait(sigset_t*, int*);
354 }
355 else version( darwin )
356 {
357 //SIG_HOLD
358
359 alias uint sigset_t;
360 // pid_t (defined in sys.types)
361
362 //SIGABRT (defined in tango.stdc.signal)
363 //SIGFPE (defined in tango.stdc.signal)
364 //SIGILL (defined in tango.stdc.signal)
365 //SIGINT (defined in tango.stdc.signal)
366 //SIGSEGV (defined in tango.stdc.signal)
367 //SIGTERM (defined in tango.stdc.signal)
368
369 //SA_NOCLDSTOP (CX|XSI)
370
371 //SIG_BLOCK
372 //SIG_UNBLOCK
373 //SIG_SETMASK
374
375 struct siginfo_t
376 {
377 int si_signo;
378 int si_errno;
379 int si_code;
380 pid_t si_pid;
381 uid_t si_uid;
382 int si_status;
383 void* si_addr;
384 sigval si_value;
385 int si_band;
386 uint pad[7];
387 }
388
389 //SI_USER
390 //SI_QUEUE
391 //SI_TIMER
392 //SI_ASYNCIO
393 //SI_MESGQ
394
395 int kill(pid_t, int);
396 int sigaction(int, sigaction_t*, sigaction_t*);
397 int sigaddset(sigset_t*, int);
398 int sigdelset(sigset_t*, int);
399 int sigemptyset(sigset_t*);
400 int sigfillset(sigset_t*);
401 int sigismember( sigset_t*, int);
402 int sigpending(sigset_t*);
403 int sigprocmask(int, sigset_t*, sigset_t*);
404 int sigsuspend(sigset_t*);
405 int sigwait(sigset_t*, int*);
406 }
407
408 //
409 // XOpen (XSI)
410 //
411 /*
412 SIGPOLL
413 SIGPROF
414 SIGSYS
415 SIGTRAP
416 SIGVTALRM
417 SIGXCPU
418 SIGXFSZ
419
420 SA_ONSTACK
421 SA_RESETHAND
422 SA_RESTART
423 SA_SIGINFO
424 SA_NOCLDWAIT
425 SA_NODEFER
426 SS_ONSTACK
427 SS_DISABLE
428 MINSIGSTKSZ
429 SIGSTKSZ
430
431 ucontext_t // from ucontext
432 mcontext_t // from ucontext
433
434 struct stack_t
435 {
436 void* ss_sp;
437 size_t ss_size;
438 int ss_flags;
439 }
440
441 struct sigstack
442 {
443 int ss_onstack;
444 void* ss_sp;
445 }
446
447 ILL_ILLOPC
448 ILL_ILLOPN
449 ILL_ILLADR
450 ILL_ILLTRP
451 ILL_PRVOPC
452 ILL_PRVREG
453 ILL_COPROC
454 ILL_BADSTK
455
456 FPE_INTDIV
457 FPE_INTOVF
458 FPE_FLTDIV
459 FPE_FLTOVF
460 FPE_FLTUND
461 FPE_FLTRES
462 FPE_FLTINV
463 FPE_FLTSUB
464
465 SEGV_MAPERR
466 SEGV_ACCERR
467
468 BUS_ADRALN
469 BUS_ADRERR
470 BUS_OBJERR
471
472 TRAP_BRKPT
473 TRAP_TRACE
474
475 CLD_EXITED
476 CLD_KILLED
477 CLD_DUMPED
478 CLD_TRAPPED
479 CLD_STOPPED
480 CLD_CONTINUED
481
482 POLL_IN
483 POLL_OUT
484 POLL_MSG
485 POLL_ERR
486 POLL_PRI
487 POLL_HUP
488
489 sigfn_t bsd_signal(int sig, sigfn_t func);
490 sigfn_t sigset(int sig, sigfn_t func);
491
492 int killpg(pid_t, int);
493 int sigaltstack(stack_t*, stack_t*);
494 int sighold(int);
495 int sigignore(int);
496 int siginterrupt(int, int);
497 int sigpause(int);
498 int sigrelse(int);
499 */
500
501 version( linux )
502 {
503 const SIGPOLL = 29;
504 const SIGPROF = 27;
505 const SIGSYS = 31;
506 const SIGTRAP = 5;
507 const SIGVTALRM = 26;
508 const SIGXCPU = 24;
509 const SIGXFSZ = 25;
510
511 const SA_ONSTACK = 0x08000000;
512 const SA_RESETHAND = 0x80000000;
513 const SA_RESTART = 0x10000000;
514 const SA_SIGINFO = 4;
515 const SA_NOCLDWAIT = 2;
516 const SA_NODEFER = 0x40000000;
517 const SS_ONSTACK = 1;
518 const SS_DISABLE = 2;
519 const MINSIGSTKSZ = 2048;
520 const SIGSTKSZ = 8192;
521
522 //ucontext_t (defined in tango.stdc.posix.ucontext)
523 //mcontext_t (defined in tango.stdc.posix.ucontext)
524
525 struct stack_t
526 {
527 void* ss_sp;
528 int ss_flags;
529 size_t ss_size;
530 }
531
532 struct sigstack
533 {
534 void* ss_sp;
535 int ss_onstack;
536 }
537
538 enum
539 {
540 ILL_ILLOPC = 1,
541 ILL_ILLOPN,
542 ILL_ILLADR,
543 ILL_ILLTRP,
544 ILL_PRVOPC,
545 ILL_PRVREG,
546 ILL_COPROC,
547 ILL_BADSTK
548 }
549
550 enum
551 {
552 FPE_INTDIV = 1,
553 FPE_INTOVF,
554 FPE_FLTDIV,
555 FPE_FLTOVF,
556 FPE_FLTUND,
557 FPE_FLTRES,
558 FPE_FLTINV,
559 FPE_FLTSUB
560 }
561
562 enum
563 {
564 SEGV_MAPERR = 1,
565 SEGV_ACCERR
566 }
567
568 enum
569 {
570 BUS_ADRALN = 1,
571 BUS_ADRERR,
572 BUS_OBJERR
573 }
574
575 enum
576 {
577 TRAP_BRKPT = 1,
578 TRAP_TRACE
579 }
580
581 enum
582 {
583 CLD_EXITED = 1,
584 CLD_KILLED,
585 CLD_DUMPED,
586 CLD_TRAPPED,
587 CLD_STOPPED,
588 CLD_CONTINUED
589 }
590
591 enum
592 {
593 POLL_IN = 1,
594 POLL_OUT,
595 POLL_MSG,
596 POLL_ERR,
597 POLL_PRI,
598 POLL_HUP
599 }
600
601 sigfn_t bsd_signal(int sig, sigfn_t func);
602 sigfn_t sigset(int sig, sigfn_t func);
603
604 int killpg(pid_t, int);
605 int sigaltstack(stack_t*, stack_t*);
606 int sighold(int);
607 int sigignore(int);
608 int siginterrupt(int, int);
609 int sigpause(int);
610 int sigrelse(int);
611 }
612
613 //
614 // Timer (TMR)
615 //
616 /*
617 NOTE: This should actually be defined in tango.stdc.posix.time.
618 It is defined here instead to break a circular import.
619
620 struct timespec
621 {
622 time_t tv_sec;
623 int tv_nsec;
624 }
625 */
626
627 version( linux )
628 {
629 struct timespec
630 {
631 time_t tv_sec;
632 c_long tv_nsec;
633 }
634 }
635 else version( darwin )
636 {
637 struct timespec
638 {
639 time_t tv_sec;
640 c_long tv_nsec;
641 }
642 }
643
644 //
645 // Realtime Signals (RTS)
646 //
647 /*
648 struct sigevent
649 {
650 int sigev_notify;
651 int sigev_signo;
652 sigval sigev_value;
653 void(*)(sigval) sigev_notify_function;
654 pthread_attr_t* sigev_notify_attributes;
655 }
656
657 int sigqueue(pid_t, int, sigval);
658 int sigtimedwait( sigset_t*, siginfo_t*, timespec*);
659 int sigwaitinfo( sigset_t*, siginfo_t*);
660 */
661
662 version( linux )
663 {
664 private const __SIGEV_MAX_SIZE = 64;
665
666 static if( false /* __WORDSIZE == 64 */ )
667 {
668 private const __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4);
669 }
670 else
671 {
672 private const __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3);
673 }
674
675 struct sigevent
676 {
677 sigval sigev_value;
678 int sigev_signo;
679 int sigev_notify;
680
681 union _sigev_un_t
682 {
683 int[__SIGEV_PAD_SIZE] _pad;
684 pid_t _tid;
685
686 struct _sigev_thread_t
687 {
688 void function(sigval) _function;
689 void* _attribute;
690 } _sigev_thread_t _sigev_thread;
691 } _sigev_un_t _sigev_un;
692 }
693
694 int sigqueue(pid_t, int, sigval);
695 int sigtimedwait( sigset_t*, siginfo_t*, timespec*);
696 int sigwaitinfo( sigset_t*, siginfo_t*);
697 }
698
699 //
700 // Threads (THR)
701 //
702 /*
703 int pthread_kill(pthread_t, int);
704 int pthread_sigmask(int, sigset_t*, sigset_t*);
705 */
706
707 version( linux )
708 {
709 int pthread_kill(pthread_t, int);
710 int pthread_sigmask(int, sigset_t*, sigset_t*);
711 }
712 else version( darwin )
713 {
714 int pthread_kill(pthread_t, int);
715 int pthread_sigmask(int, sigset_t*, sigset_t*);
716 }