PageRenderTime 92ms CodeModel.GetById 17ms app.highlight 67ms RepoModel.GetById 2ms app.codeStats 0ms

/src/core/sys/posix/signal.d

http://github.com/AlexeyProkhin/druntime
D | 1462 lines | 999 code | 138 blank | 325 comment | 24 complexity | 1b44955fc2c31269892cf0b180002a92 MD5 | raw file
   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              Alex Rønne Petersen
   8 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
   9 */
  10
  11/*          Copyright Sean Kelly 2005 - 2009.
  12 * Distributed under the Boost Software License, Version 1.0.
  13 *    (See accompanying file LICENSE or copy at
  14 *          http://www.boost.org/LICENSE_1_0.txt)
  15 */
  16module core.sys.posix.signal;
  17
  18private import core.sys.posix.config;
  19public import core.stdc.signal;
  20public import core.stdc.stddef;         // for size_t
  21public import core.sys.posix.sys.types; // for pid_t
  22//public import core.sys.posix.time;      // for timespec, now defined here
  23
  24version (Posix):
  25extern (C):
  26
  27//
  28// Required
  29//
  30/*
  31SIG_DFL (defined in core.stdc.signal)
  32SIG_ERR (defined in core.stdc.signal)
  33SIG_IGN (defined in core.stdc.signal)
  34
  35sig_atomic_t (defined in core.stdc.signal)
  36
  37SIGEV_NONE
  38SIGEV_SIGNAL
  39SIGEV_THREAD
  40
  41union sigval
  42{
  43    int   sival_int;
  44    void* sival_ptr;
  45}
  46
  47SIGRTMIN
  48SIGRTMAX
  49
  50SIGABRT (defined in core.stdc.signal)
  51SIGALRM
  52SIGBUS
  53SIGCHLD
  54SIGCONT
  55SIGFPE (defined in core.stdc.signal)
  56SIGHUP
  57SIGILL (defined in core.stdc.signal)
  58SIGINT (defined in core.stdc.signal)
  59SIGKILL
  60SIGPIPE
  61SIGQUIT
  62SIGSEGV (defined in core.stdc.signal)
  63SIGSTOP
  64SIGTERM (defined in core.stdc.signal)
  65SIGTSTP
  66SIGTTIN
  67SIGTTOU
  68SIGUSR1
  69SIGUSR2
  70SIGURG
  71
  72struct sigaction_t
  73{
  74    sigfn_t     sa_handler;
  75    sigset_t    sa_mask;
  76    sigactfn_t  sa_sigaction;
  77}
  78
  79sigfn_t signal(int sig, sigfn_t func); (defined in core.stdc.signal)
  80int 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
  89version( Posix )
  90{
  91    private alias void function(int) sigfn_t;
  92    private alias void function(int, siginfo_t*, void*) sigactfn_t;
  93
  94    enum
  95    {
  96      SIGEV_SIGNAL,
  97      SIGEV_NONE,
  98      SIGEV_THREAD
  99    }
 100
 101    union sigval
 102    {
 103        int     sival_int;
 104        void*   sival_ptr;
 105    }
 106
 107    private extern (C) int __libc_current_sigrtmin();
 108    private extern (C) int __libc_current_sigrtmax();
 109
 110    alias __libc_current_sigrtmin SIGRTMIN;
 111    alias __libc_current_sigrtmax SIGRTMAX;
 112}
 113
 114version( linux )
 115{
 116    version (MIPS)
 117    {
 118        //SIGABRT (defined in core.stdc.signal)
 119        enum SIGALRM    = 14;
 120        enum SIGBUS     = 10;
 121        enum SIGCHLD    = 18;
 122        enum SIGCONT    = 25;
 123        //SIGFPE (defined in core.stdc.signal)
 124        enum SIGHUP     = 1;
 125        //SIGILL (defined in core.stdc.signal)
 126        //SIGINT (defined in core.stdc.signal)
 127        enum SIGKILL    = 9;
 128        enum SIGPIPE    = 13;
 129        enum SIGQUIT    = 3;
 130        //SIGSEGV (defined in core.stdc.signal)
 131        enum SIGSTOP    = 23;
 132        //SIGTERM (defined in core.stdc.signal)
 133        enum SIGTSTP    = 24;
 134        enum SIGTTIN    = 26;
 135        enum SIGTTOU    = 27;
 136        enum SIGUSR1    = 16;
 137        enum SIGUSR2    = 17;
 138        enum SIGURG     = 21;
 139    }
 140    else
 141    {
 142        //SIGABRT (defined in core.stdc.signal)
 143        enum SIGALRM    = 14;
 144        enum SIGBUS     = 7;
 145        enum SIGCHLD    = 17;
 146        enum SIGCONT    = 18;
 147        //SIGFPE (defined in core.stdc.signal)
 148        enum SIGHUP     = 1;
 149        //SIGILL (defined in core.stdc.signal)
 150        //SIGINT (defined in core.stdc.signal)
 151        enum SIGKILL    = 9;
 152        enum SIGPIPE    = 13;
 153        enum SIGQUIT    = 3;
 154        //SIGSEGV (defined in core.stdc.signal)
 155        enum SIGSTOP    = 19;
 156        //SIGTERM (defined in core.stdc.signal)
 157        enum SIGTSTP    = 20;
 158        enum SIGTTIN    = 21;
 159        enum SIGTTOU    = 22;
 160        enum SIGUSR1    = 10;
 161        enum SIGUSR2    = 12;
 162        enum SIGURG     = 23;
 163    }
 164}
 165else version( OSX )
 166{
 167    //SIGABRT (defined in core.stdc.signal)
 168    enum SIGALRM    = 14;
 169    enum SIGBUS     = 10;
 170    enum SIGCHLD    = 20;
 171    enum SIGCONT    = 19;
 172    //SIGFPE (defined in core.stdc.signal)
 173    enum SIGHUP     = 1;
 174    //SIGILL (defined in core.stdc.signal)
 175    //SIGINT (defined in core.stdc.signal)
 176    enum SIGKILL    = 9;
 177    enum SIGPIPE    = 13;
 178    enum SIGQUIT    = 3;
 179    //SIGSEGV (defined in core.stdc.signal)
 180    enum SIGSTOP    = 17;
 181    //SIGTERM (defined in core.stdc.signal)
 182    enum SIGTSTP    = 18;
 183    enum SIGTTIN    = 21;
 184    enum SIGTTOU    = 22;
 185    enum SIGUSR1    = 30;
 186    enum SIGUSR2    = 31;
 187    enum SIGURG     = 16;
 188}
 189else version( FreeBSD )
 190{
 191    //SIGABRT (defined in core.stdc.signal)
 192    enum SIGALRM    = 14;
 193    enum SIGBUS     = 10;
 194    enum SIGCHLD    = 20;
 195    enum SIGCONT    = 19;
 196    //SIGFPE (defined in core.stdc.signal)
 197    enum SIGHUP     = 1;
 198    //SIGILL (defined in core.stdc.signal)
 199    //SIGINT (defined in core.stdc.signal)
 200    enum SIGKILL    = 9;
 201    enum SIGPIPE    = 13;
 202    enum SIGQUIT    = 3;
 203    //SIGSEGV (defined in core.stdc.signal)
 204    enum SIGSTOP    = 17;
 205    //SIGTERM (defined in core.stdc.signal)
 206    enum SIGTSTP    = 18;
 207    enum SIGTTIN    = 21;
 208    enum SIGTTOU    = 22;
 209    enum SIGUSR1    = 30;
 210    enum SIGUSR2    = 31;
 211    enum SIGURG     = 16;
 212}
 213else version (Solaris)
 214{
 215    enum SIGALRM = 14;
 216    enum SIGBUS = 10;
 217    enum SIGCHLD = 18;
 218    enum SIGCONT = 25;
 219    enum SIGHUP = 1;
 220    enum SIGKILL = 9;
 221    enum SIGPIPE = 13;
 222    enum SIGQUIT = 3;
 223    enum SIGSTOP = 23;
 224    enum SIGTSTP = 24;
 225    enum SIGTTIN = 26;
 226    enum SIGTTOU = 27;
 227    enum SIGUSR1 = 16;
 228    enum SIGUSR2 = 17;
 229    enum SIGURG = 21;
 230}
 231else
 232{
 233    static assert(false, "Unsupported platform");
 234}
 235
 236version( FreeBSD )
 237{
 238    struct sigaction_t
 239    {
 240        union
 241        {
 242            sigfn_t     sa_handler;
 243            sigactfn_t  sa_sigaction;
 244        }
 245        int      sa_flags;
 246        sigset_t sa_mask;
 247    }
 248}
 249else version (Solaris)
 250{
 251    struct sigaction_t
 252    {
 253        int sa_flags;
 254
 255        union
 256        {
 257            sigfn_t sa_handler;
 258            sigactfn_t sa_sigaction;
 259        }
 260
 261        sigset_t sa_mask;
 262    }
 263}
 264else version( Posix )
 265{
 266    struct sigaction_t
 267    {
 268        static if( true /* __USE_POSIX199309 */ )
 269        {
 270            union
 271            {
 272                sigfn_t     sa_handler;
 273                sigactfn_t  sa_sigaction;
 274            }
 275        }
 276        else
 277        {
 278            sigfn_t     sa_handler;
 279        }
 280        sigset_t        sa_mask;
 281        int             sa_flags;
 282
 283        version( OSX ) {} else {
 284        void function() sa_restorer;
 285        }
 286    }
 287}
 288else
 289{
 290    static assert(false, "Unsupported platform");
 291}
 292
 293//
 294// C Extension (CX)
 295//
 296/*
 297SIG_HOLD
 298
 299sigset_t
 300pid_t   (defined in core.sys.types)
 301
 302SIGABRT (defined in core.stdc.signal)
 303SIGFPE  (defined in core.stdc.signal)
 304SIGILL  (defined in core.stdc.signal)
 305SIGINT  (defined in core.stdc.signal)
 306SIGSEGV (defined in core.stdc.signal)
 307SIGTERM (defined in core.stdc.signal)
 308
 309SA_NOCLDSTOP (CX|XSI)
 310SIG_BLOCK
 311SIG_UNBLOCK
 312SIG_SETMASK
 313
 314struct siginfo_t
 315{
 316    int     si_signo;
 317    int     si_code;
 318
 319    version( XSI )
 320    {
 321        int     si_errno;
 322        pid_t   si_pid;
 323        uid_t   si_uid;
 324        void*   si_addr;
 325        int     si_status;
 326        c_long  si_band;
 327    }
 328    version( RTS )
 329    {
 330        sigval  si_value;
 331    }
 332}
 333
 334SI_USER
 335SI_QUEUE
 336SI_TIMER
 337SI_ASYNCIO
 338SI_MESGQ
 339
 340int kill(pid_t, int);
 341int sigaction(int, in sigaction_t*, sigaction_t*);
 342int sigaddset(sigset_t*, int);
 343int sigdelset(sigset_t*, int);
 344int sigemptyset(sigset_t*);
 345int sigfillset(sigset_t*);
 346int sigismember(in sigset_t*, int);
 347int sigpending(sigset_t*);
 348int sigprocmask(int, in sigset_t*, sigset_t*);
 349int sigsuspend(in sigset_t*);
 350int sigwait(in sigset_t*, int*);
 351*/
 352
 353version( linux )
 354{
 355    enum SIG_HOLD = cast(sigfn_t) 1;
 356
 357    private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof);
 358
 359    struct sigset_t
 360    {
 361        c_ulong[_SIGSET_NWORDS] __val;
 362    }
 363
 364    // pid_t  (defined in core.sys.types)
 365
 366    //SIGABRT (defined in core.stdc.signal)
 367    //SIGFPE  (defined in core.stdc.signal)
 368    //SIGILL  (defined in core.stdc.signal)
 369    //SIGINT  (defined in core.stdc.signal)
 370    //SIGSEGV (defined in core.stdc.signal)
 371    //SIGTERM (defined in core.stdc.signal)
 372
 373    enum SA_NOCLDSTOP   = 1; // (CX|XSI)
 374
 375    enum SIG_BLOCK      = 0;
 376    enum SIG_UNBLOCK    = 1;
 377    enum SIG_SETMASK    = 2;
 378
 379    private enum __SI_MAX_SIZE = 128;
 380
 381    static if( false /* __WORDSIZE == 64 */ )
 382    {
 383        private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4);
 384    }
 385    else
 386    {
 387        private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3);
 388    }
 389
 390    struct siginfo_t
 391    {
 392        int si_signo;       // Signal number
 393        int si_errno;       // If non-zero, an errno value associated with
 394                            // this signal, as defined in <errno.h>
 395        int si_code;        // Signal code
 396
 397        union _sifields_t
 398        {
 399            int _pad[__SI_PAD_SIZE];
 400
 401            // kill()
 402            struct _kill_t
 403            {
 404                pid_t si_pid; // Sending process ID
 405                uid_t si_uid; // Real user ID of sending process
 406            } _kill_t _kill;
 407
 408            // POSIX.1b timers.
 409            struct _timer_t
 410            {
 411                int    si_tid;     // Timer ID
 412                int    si_overrun; // Overrun count
 413                sigval si_sigval;  // Signal value
 414            } _timer_t _timer;
 415
 416            // POSIX.1b signals
 417            struct _rt_t
 418            {
 419                pid_t  si_pid;    // Sending process ID
 420                uid_t  si_uid;    // Real user ID of sending process
 421                sigval si_sigval; // Signal value
 422            } _rt_t _rt;
 423
 424            // SIGCHLD
 425            struct _sigchild_t
 426            {
 427                pid_t   si_pid;    // Which child
 428                uid_t   si_uid;    // Real user ID of sending process
 429                int     si_status; // Exit value or signal
 430                clock_t si_utime;
 431                clock_t si_stime;
 432            } _sigchild_t _sigchld;
 433
 434            // SIGILL, SIGFPE, SIGSEGV, SIGBUS
 435            struct _sigfault_t
 436            {
 437                void*     si_addr;  // Faulting insn/memory ref
 438            } _sigfault_t _sigfault;
 439
 440            // SIGPOLL
 441            struct _sigpoll_t
 442            {
 443                c_long   si_band;   // Band event for SIGPOLL
 444                int      si_fd;
 445            } _sigpoll_t _sigpoll;
 446        } _sifields_t _sifields;
 447
 448        @property ref pid_t si_pid() { return _sifields._kill.si_pid; }
 449        @property ref uid_t si_uid() { return _sifields._kill.si_uid; }
 450        @property ref void* si_addr() { return _sifields._sigfault.si_addr; }
 451        @property ref int si_status() { return _sifields._sigchld.si_status; }
 452        @property ref c_long si_band() { return _sifields._sigpoll.si_band; }
 453        @property ref sigval si_value() { return _sifields._rt.si_sigval; }
 454    }
 455
 456    enum
 457    {
 458        SI_ASYNCNL = -60,
 459        SI_TKILL   = -6,
 460        SI_SIGIO,
 461        SI_ASYNCIO,
 462        SI_MESGQ,
 463        SI_TIMER,
 464        SI_QUEUE,
 465        SI_USER,
 466        SI_KERNEL  = 0x80
 467    }
 468
 469    int kill(pid_t, int);
 470    int sigaction(int, in sigaction_t*, sigaction_t*);
 471    int sigaddset(sigset_t*, int);
 472    int sigdelset(sigset_t*, int);
 473    int sigemptyset(sigset_t*);
 474    int sigfillset(sigset_t*);
 475    int sigismember(in sigset_t*, int);
 476    int sigpending(sigset_t*);
 477    int sigprocmask(int, in sigset_t*, sigset_t*);
 478    int sigsuspend(in sigset_t*);
 479    int sigwait(in sigset_t*, int*);
 480}
 481else version( OSX )
 482{
 483    //SIG_HOLD
 484
 485    alias uint sigset_t;
 486    // pid_t  (defined in core.sys.types)
 487
 488    //SIGABRT (defined in core.stdc.signal)
 489    //SIGFPE  (defined in core.stdc.signal)
 490    //SIGILL  (defined in core.stdc.signal)
 491    //SIGINT  (defined in core.stdc.signal)
 492    //SIGSEGV (defined in core.stdc.signal)
 493    //SIGTERM (defined in core.stdc.signal)
 494
 495    //SA_NOCLDSTOP (CX|XSI)
 496
 497    //SIG_BLOCK
 498    //SIG_UNBLOCK
 499    //SIG_SETMASK
 500
 501    struct siginfo_t
 502    {
 503        int     si_signo;
 504        int     si_errno;
 505        int     si_code;
 506        pid_t   si_pid;
 507        uid_t   si_uid;
 508        int     si_status;
 509        void*   si_addr;
 510        sigval  si_value;
 511        int     si_band;
 512        uint    pad[7];
 513    }
 514
 515    //SI_USER
 516    //SI_QUEUE
 517    //SI_TIMER
 518    //SI_ASYNCIO
 519    //SI_MESGQ
 520
 521    int kill(pid_t, int);
 522    int sigaction(int, in sigaction_t*, sigaction_t*);
 523    int sigaddset(sigset_t*, int);
 524    int sigdelset(sigset_t*, int);
 525    int sigemptyset(sigset_t*);
 526    int sigfillset(sigset_t*);
 527    int sigismember(in sigset_t*, int);
 528    int sigpending(sigset_t*);
 529    int sigprocmask(int, in sigset_t*, sigset_t*);
 530    int sigsuspend(in sigset_t*);
 531    int sigwait(in sigset_t*, int*);
 532}
 533else version( FreeBSD )
 534{
 535    struct sigset_t
 536    {
 537        uint __bits[4];
 538    }
 539
 540    struct siginfo_t
 541    {
 542        int si_signo;
 543        int si_errno;
 544        int si_code;
 545        pid_t si_pid;
 546        uid_t si_uid;
 547        int si_status;
 548        void* si_addr;
 549        sigval si_value;
 550        union __reason
 551        {
 552            struct __fault
 553            {
 554                int _trapno;
 555            }
 556            __fault _fault;
 557            struct __timer
 558            {
 559                int _timerid;
 560                int _overrun;
 561            }
 562            __timer _timer;
 563            struct __mesgq
 564            {
 565                int _mqd;
 566            }
 567            __mesgq _mesgq;
 568            struct __poll
 569            {
 570                c_long _band;
 571            }
 572            __poll _poll;
 573            struct ___spare___
 574            {
 575                c_long __spare1__;
 576                int[7] __spare2__;
 577            }
 578            ___spare___ __spare__;
 579        }
 580        __reason _reason;
 581
 582        @property ref c_long si_band() { return _reason._poll._band; }
 583    }
 584
 585    int kill(pid_t, int);
 586    int sigaction(int, in sigaction_t*, sigaction_t*);
 587    int sigaddset(sigset_t*, int);
 588    int sigdelset(sigset_t*, int);
 589    int sigemptyset(sigset_t *);
 590    int sigfillset(sigset_t *);
 591    int sigismember(in sigset_t *, int);
 592    int sigpending(sigset_t *);
 593    int sigprocmask(int, in sigset_t*, sigset_t*);
 594    int sigsuspend(in sigset_t *);
 595    int sigwait(in sigset_t*, int*);
 596}
 597else version (Solaris)
 598{
 599    enum SIG_HOLD = cast(sigfn_t)2;
 600
 601    struct sigset_t
 602    {
 603        uint __bits[4];
 604    }
 605
 606    struct siginfo_t
 607    {
 608        int si_signo;
 609        int si_code;
 610        int si_errno;
 611
 612        version (D_LP64)
 613            int si_pad;
 614
 615        union ___data
 616        {
 617            version (D_LP64)
 618                int si_pad[(256 / int.sizeof) - 4];
 619            else
 620                int si_pad[(128 / int.sizeof) - 3];
 621
 622            struct ___proc
 623            {
 624                pid_t __pid;
 625
 626                union ___pdata
 627                {
 628                    struct ___kill
 629                    {
 630                        uid_t __uid;
 631                        sigval __value;
 632                    }
 633
 634                    ___kill __kill;
 635
 636                    struct ___cld
 637                    {
 638                        clock_t __utime;
 639                        int __status;
 640                        clock_t __stime;
 641                    }
 642
 643                    ___cld __cld;
 644                }
 645
 646                ___pdata __pdata;
 647                ctid_t __ctid;
 648                zoneid_t __zoneid;
 649            }
 650
 651            ___proc __proc;
 652
 653            struct ___fault
 654            {
 655                void* __addr;
 656                int __trapno;
 657                caddr_t __pc;
 658            }
 659
 660            ___fault __fault;
 661
 662            struct ___file
 663            {
 664                int __fd;
 665                c_long __band;
 666            }
 667
 668            ___file __file;
 669
 670            struct ___prof
 671            {
 672                caddr_t __faddr;
 673                timestruc_t __tstamp;
 674                short __syscall;
 675                char __nsysarg;
 676                char __fault;
 677                c_long __sysarg[8];
 678                int __mstate[10];
 679            }
 680
 681            ___prof __prof;
 682
 683            struct ___rctl
 684            {
 685                int __entity;
 686            }
 687
 688            ___rctl __rctl;
 689        }
 690
 691        ___data __data;
 692    }
 693
 694    int kill(pid_t, int);
 695    int sigaction(int, in sigaction_t*, sigaction_t*);
 696    int sigaddset(sigset_t*, int);
 697    int sigdelset(sigset_t*, int);
 698    int sigemptyset(sigset_t*);
 699    int sigfillset(sigset_t*);
 700    int sigismember(in sigset_t*, int);
 701    int sigpending(sigset_t*);
 702    int sigprocmask(int, in sigset_t*, sigset_t*);
 703    int sigsuspend(in sigset_t*);
 704    int sigwait(in sigset_t*, int*);
 705}
 706else
 707{
 708    static assert(false, "Unsupported platform");
 709}
 710
 711
 712//
 713// XOpen (XSI)
 714//
 715/*
 716SIGPOLL
 717SIGPROF
 718SIGSYS
 719SIGTRAP
 720SIGVTALRM
 721SIGXCPU
 722SIGXFSZ
 723
 724SA_ONSTACK
 725SA_RESETHAND
 726SA_RESTART
 727SA_SIGINFO
 728SA_NOCLDWAIT
 729SA_NODEFER
 730SS_ONSTACK
 731SS_DISABLE
 732MINSIGSTKSZ
 733SIGSTKSZ
 734
 735ucontext_t // from ucontext
 736mcontext_t // from ucontext
 737
 738struct stack_t
 739{
 740    void*   ss_sp;
 741    size_t  ss_size;
 742    int     ss_flags;
 743}
 744
 745struct sigstack
 746{
 747    int   ss_onstack;
 748    void* ss_sp;
 749}
 750
 751ILL_ILLOPC
 752ILL_ILLOPN
 753ILL_ILLADR
 754ILL_ILLTRP
 755ILL_PRVOPC
 756ILL_PRVREG
 757ILL_COPROC
 758ILL_BADSTK
 759
 760FPE_INTDIV
 761FPE_INTOVF
 762FPE_FLTDIV
 763FPE_FLTOVF
 764FPE_FLTUND
 765FPE_FLTRES
 766FPE_FLTINV
 767FPE_FLTSUB
 768
 769SEGV_MAPERR
 770SEGV_ACCERR
 771
 772BUS_ADRALN
 773BUS_ADRERR
 774BUS_OBJERR
 775
 776TRAP_BRKPT
 777TRAP_TRACE
 778
 779CLD_EXITED
 780CLD_KILLED
 781CLD_DUMPED
 782CLD_TRAPPED
 783CLD_STOPPED
 784CLD_CONTINUED
 785
 786POLL_IN
 787POLL_OUT
 788POLL_MSG
 789POLL_ERR
 790POLL_PRI
 791POLL_HUP
 792
 793sigfn_t bsd_signal(int sig, sigfn_t func);
 794sigfn_t sigset(int sig, sigfn_t func);
 795
 796int killpg(pid_t, int);
 797int sigaltstack(in stack_t*, stack_t*);
 798int sighold(int);
 799int sigignore(int);
 800int siginterrupt(int, int);
 801int sigpause(int);
 802int sigrelse(int);
 803*/
 804
 805version( linux )
 806{
 807    version (MIPS)
 808    {
 809        enum SIGPOLL    = 22;
 810        enum SIGPROF    = 29;
 811        enum SIGSYS     = 12;
 812        enum SIGTRAP    = 5;
 813        enum SIGVTALRM  = 28;
 814        enum SIGXCPU    = 30;
 815        enum SIGXFSZ    = 31;
 816    }
 817    else
 818    {
 819        enum SIGPOLL        = 29;
 820        enum SIGPROF        = 27;
 821        enum SIGSYS         = 31;
 822        enum SIGTRAP        = 5;
 823        enum SIGVTALRM      = 26;
 824        enum SIGXCPU        = 24;
 825        enum SIGXFSZ        = 25;
 826    }
 827    enum SA_ONSTACK     = 0x08000000;
 828    enum SA_RESETHAND   = 0x80000000;
 829    enum SA_RESTART     = 0x10000000;
 830    enum SA_SIGINFO     = 4;
 831    enum SA_NOCLDWAIT   = 2;
 832    enum SA_NODEFER     = 0x40000000;
 833    enum SS_ONSTACK     = 1;
 834    enum SS_DISABLE     = 2;
 835    enum MINSIGSTKSZ    = 2048;
 836    enum SIGSTKSZ       = 8192;
 837
 838    //ucontext_t (defined in core.sys.posix.ucontext)
 839    //mcontext_t (defined in core.sys.posix.ucontext)
 840
 841    struct stack_t
 842    {
 843        void*   ss_sp;
 844        int     ss_flags;
 845        size_t  ss_size;
 846    }
 847
 848    struct sigstack
 849    {
 850        void*   ss_sp;
 851        int     ss_onstack;
 852    }
 853
 854    enum
 855    {
 856        ILL_ILLOPC = 1,
 857        ILL_ILLOPN,
 858        ILL_ILLADR,
 859        ILL_ILLTRP,
 860        ILL_PRVOPC,
 861        ILL_PRVREG,
 862        ILL_COPROC,
 863        ILL_BADSTK
 864    }
 865
 866    enum
 867    {
 868        FPE_INTDIV = 1,
 869        FPE_INTOVF,
 870        FPE_FLTDIV,
 871        FPE_FLTOVF,
 872        FPE_FLTUND,
 873        FPE_FLTRES,
 874        FPE_FLTINV,
 875        FPE_FLTSUB
 876    }
 877
 878    enum
 879    {
 880        SEGV_MAPERR = 1,
 881        SEGV_ACCERR
 882    }
 883
 884    enum
 885    {
 886        BUS_ADRALN = 1,
 887        BUS_ADRERR,
 888        BUS_OBJERR
 889    }
 890
 891    enum
 892    {
 893        TRAP_BRKPT = 1,
 894        TRAP_TRACE
 895    }
 896
 897    enum
 898    {
 899        CLD_EXITED = 1,
 900        CLD_KILLED,
 901        CLD_DUMPED,
 902        CLD_TRAPPED,
 903        CLD_STOPPED,
 904        CLD_CONTINUED
 905    }
 906
 907    enum
 908    {
 909        POLL_IN = 1,
 910        POLL_OUT,
 911        POLL_MSG,
 912        POLL_ERR,
 913        POLL_PRI,
 914        POLL_HUP
 915    }
 916
 917    sigfn_t bsd_signal(int sig, sigfn_t func);
 918    sigfn_t sigset(int sig, sigfn_t func);
 919
 920    int killpg(pid_t, int);
 921    int sigaltstack(in stack_t*, stack_t*);
 922    int sighold(int);
 923    int sigignore(int);
 924    int siginterrupt(int, int);
 925    int sigpause(int);
 926    int sigrelse(int);
 927}
 928else version( OSX )
 929{
 930    enum SIGPOLL        = 7;
 931    enum SIGPROF        = 27;
 932    enum SIGSYS         = 12;
 933    enum SIGTRAP        = 5;
 934    enum SIGVTALRM      = 26;
 935    enum SIGXCPU        = 24;
 936    enum SIGXFSZ        = 25;
 937
 938    enum SA_ONSTACK     = 0x0001;
 939    enum SA_RESETHAND   = 0x0004;
 940    enum SA_RESTART     = 0x0002;
 941    enum SA_SIGINFO     = 0x0040;
 942    enum SA_NOCLDWAIT   = 0x0020;
 943    enum SA_NODEFER     = 0x0010;
 944    enum SS_ONSTACK     = 0x0001;
 945    enum SS_DISABLE     = 0x0004;
 946    enum MINSIGSTKSZ    = 32768;
 947    enum SIGSTKSZ       = 131072;
 948
 949    //ucontext_t (defined in core.sys.posix.ucontext)
 950    //mcontext_t (defined in core.sys.posix.ucontext)
 951
 952    struct stack_t
 953    {
 954        void*   ss_sp;
 955        size_t  ss_size;
 956        int     ss_flags;
 957    }
 958
 959    struct sigstack
 960    {
 961        void*   ss_sp;
 962        int     ss_onstack;
 963    }
 964
 965    enum ILL_ILLOPC = 1;
 966    enum ILL_ILLOPN = 4;
 967    enum ILL_ILLADR = 5;
 968    enum ILL_ILLTRP = 2;
 969    enum ILL_PRVOPC = 3;
 970    enum ILL_PRVREG = 6;
 971    enum ILL_COPROC = 7;
 972    enum ILL_BADSTK = 8;
 973
 974    enum FPE_INTDIV = 7;
 975    enum FPE_INTOVF = 8;
 976    enum FPE_FLTDIV = 1;
 977    enum FPE_FLTOVF = 2;
 978    enum FPE_FLTUND = 3;
 979    enum FPE_FLTRES = 4;
 980    enum FPE_FLTINV = 5;
 981    enum FPE_FLTSUB = 6;
 982
 983    enum
 984    {
 985        SEGV_MAPERR = 1,
 986        SEGV_ACCERR
 987    }
 988
 989    enum
 990    {
 991        BUS_ADRALN = 1,
 992        BUS_ADRERR,
 993        BUS_OBJERR
 994    }
 995
 996    enum
 997    {
 998        TRAP_BRKPT = 1,
 999        TRAP_TRACE
1000    }
1001
1002    enum
1003    {
1004        CLD_EXITED = 1,
1005        CLD_KILLED,
1006        CLD_DUMPED,
1007        CLD_TRAPPED,
1008        CLD_STOPPED,
1009        CLD_CONTINUED
1010    }
1011
1012    enum
1013    {
1014        POLL_IN = 1,
1015        POLL_OUT,
1016        POLL_MSG,
1017        POLL_ERR,
1018        POLL_PRI,
1019        POLL_HUP
1020    }
1021
1022    sigfn_t bsd_signal(int sig, sigfn_t func);
1023    sigfn_t sigset(int sig, sigfn_t func);
1024
1025    int killpg(pid_t, int);
1026    int sigaltstack(in stack_t*, stack_t*);
1027    int sighold(int);
1028    int sigignore(int);
1029    int siginterrupt(int, int);
1030    int sigpause(int);
1031    int sigrelse(int);
1032}
1033else version( FreeBSD )
1034{
1035    // No SIGPOLL on *BSD
1036    enum SIGPROF        = 27;
1037    enum SIGSYS         = 12;
1038    enum SIGTRAP        = 5;
1039    enum SIGVTALRM      = 26;
1040    enum SIGXCPU        = 24;
1041    enum SIGXFSZ        = 25;
1042
1043    enum
1044    {
1045        SA_ONSTACK      = 0x0001,
1046        SA_RESTART      = 0x0002,
1047        SA_RESETHAND    = 0x0004,
1048        SA_NODEFER      = 0x0010,
1049        SA_NOCLDWAIT    = 0x0020,
1050        SA_SIGINFO      = 0x0040,
1051    }
1052
1053    enum
1054    {
1055        SS_ONSTACK = 0x0001,
1056        SS_DISABLE = 0x0004,
1057    }
1058
1059    enum MINSIGSTKSZ = 512 * 4;
1060    enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
1061;
1062    //ucontext_t (defined in core.sys.posix.ucontext)
1063    //mcontext_t (defined in core.sys.posix.ucontext)
1064
1065    struct stack_t
1066    {
1067        void*   ss_sp;
1068        size_t  ss_size;
1069        int     ss_flags;
1070    }
1071
1072    struct sigstack
1073    {
1074        void*   ss_sp;
1075        int     ss_onstack;
1076    }
1077
1078    enum
1079    {
1080        ILL_ILLOPC = 1,
1081        ILL_ILLOPN,
1082        ILL_ILLADR,
1083        ILL_ILLTRP,
1084        ILL_PRVOPC,
1085        ILL_PRVREG,
1086        ILL_COPROC,
1087        ILL_BADSTK,
1088    }
1089
1090    enum
1091    {
1092        BUS_ADRALN = 1,
1093        BUS_ADRERR,
1094        BUS_OBJERR,
1095    }
1096
1097    enum
1098    {
1099        SEGV_MAPERR = 1,
1100        SEGV_ACCERR,
1101    }
1102
1103    enum
1104    {
1105        FPE_INTOVF = 1,
1106        FPE_INTDIV,
1107        FPE_FLTDIV,
1108        FPE_FLTOVF,
1109        FPE_FLTUND,
1110        FPE_FLTRES,
1111        FPE_FLTINV,
1112        FPE_FLTSUB,
1113    }
1114
1115    enum
1116    {
1117        TRAP_BRKPT = 1,
1118        TRAP_TRACE,
1119    }
1120
1121    enum
1122    {
1123        CLD_EXITED = 1,
1124        CLD_KILLED,
1125        CLD_DUMPED,
1126        CLD_TRAPPED,
1127        CLD_STOPPED,
1128        CLD_CONTINUED,
1129    }
1130
1131    enum
1132    {
1133        POLL_IN = 1,
1134        POLL_OUT,
1135        POLL_MSG,
1136        POLL_ERR,
1137        POLL_PRI,
1138        POLL_HUP,
1139    }
1140
1141    //sigfn_t bsd_signal(int sig, sigfn_t func);
1142    sigfn_t sigset(int sig, sigfn_t func);
1143
1144    int killpg(pid_t, int);
1145    int sigaltstack(in stack_t*, stack_t*);
1146    int sighold(int);
1147    int sigignore(int);
1148    int siginterrupt(int, int);
1149    int sigpause(int);
1150    int sigrelse(int);
1151}
1152else version (Solaris)
1153{
1154    enum SIGPOLL = 22;
1155    enum SIGPROF = 29;
1156    enum SIGSYS = 12;
1157    enum SIGTRAP = 5;
1158    enum SIGVTALRM = 31;
1159    enum SIGXCPU = 30;
1160    enum SIGXFSZ = 25;
1161
1162    enum
1163    {
1164        SA_ONSTACK = 0x00001,
1165        SA_RESTART = 0x00004,
1166        SA_RESETHAND = 0x00002,
1167        SA_NODEFER = 0x00010,
1168        SA_NOCLDWAIT = 0x10000,
1169        SA_SIGINFO = 0x00008,
1170    }
1171
1172    enum
1173    {
1174        SS_ONSTACK = 0x0001,
1175        SS_DISABLE = 0x0002,
1176    }
1177
1178    enum MINSIGSTKSZ = 2048;
1179    enum SIGSTKSZ = 8192;
1180
1181    struct stack_t
1182    {
1183        void* ss_sp;
1184        size_t ss_size;
1185        int ss_flags;
1186    }
1187
1188    struct sigstack
1189    {
1190        void* ss_sp;
1191        int ss_onstack;
1192    }
1193
1194    enum
1195    {
1196        ILL_ILLOPC = 1,
1197        ILL_ILLOPN,
1198        ILL_ILLADR,
1199        ILL_ILLTRP,
1200        ILL_PRVOPC,
1201        ILL_PRVREG,
1202        ILL_COPROC,
1203        ILL_BADSTK,
1204    }
1205
1206    enum
1207    {
1208        BUS_ADRALN = 1,
1209        BUS_ADRERR,
1210        BUS_OBJERR,
1211    }
1212
1213    enum
1214    {
1215        SEGV_MAPERR = 1,
1216        SEGV_ACCERR,
1217    }
1218
1219    enum
1220    {
1221        FPE_INTDIV = 1,
1222        FPE_INTOVF,
1223        FPE_FLTDIV,
1224        FPE_FLTOVF,
1225        FPE_FLTUND,
1226        FPE_FLTRES,
1227        FPE_FLTINV,
1228        FPE_FLTSUB,
1229        FPE_FLTDEN,
1230    }
1231
1232    enum
1233    {
1234        TRAP_BRKPT = 1,
1235        TRAP_TRACE,
1236        TRAP_RWATCH,
1237        TRAP_WWATCH,
1238        TRAP_XWATCH,
1239        TRAP_DTRACE,
1240    }
1241
1242    enum
1243    {
1244        CLD_EXITED = 1,
1245        CLD_KILLED,
1246        CLD_DUMPED,
1247        CLD_TRAPPED,
1248        CLD_STOPPED,
1249        CLD_CONTINUED,
1250    }
1251
1252    enum
1253    {
1254        POLL_IN = 1,
1255        POLL_OUT,
1256        POLL_MSG,
1257        POLL_ERR,
1258        POLL_PRI,
1259        POLL_HUP,
1260    }
1261
1262    sigfn_t sigset(int sig, sigfn_t func);
1263
1264    int killpg(pid_t, int);
1265    int sigaltstack(in stack_t*, stack_t*);
1266    int sighold(int);
1267    int sigignore(int);
1268    int siginterrupt(int, int);
1269    int sigpause(int);
1270    int sigrelse(int);
1271}
1272else
1273{
1274    static assert(false, "Unsupported platform");
1275}
1276
1277//
1278// Timer (TMR)
1279//
1280/*
1281NOTE: This should actually be defined in core.sys.posix.time.
1282      It is defined here instead to break a circular import.
1283
1284struct timespec
1285{
1286    time_t  tv_sec;
1287    int     tv_nsec;
1288}
1289*/
1290
1291version( linux )
1292{
1293    struct timespec
1294    {
1295        time_t  tv_sec;
1296        c_long  tv_nsec;
1297    }
1298}
1299else version( OSX )
1300{
1301    struct timespec
1302    {
1303        time_t  tv_sec;
1304        c_long  tv_nsec;
1305    }
1306}
1307else version( FreeBSD )
1308{
1309    struct timespec
1310    {
1311        time_t  tv_sec;
1312        c_long  tv_nsec;
1313    }
1314}
1315else version (Solaris)
1316{
1317    struct timespec
1318    {
1319        time_t tv_sec;
1320        c_long tv_nsec;
1321    }
1322
1323    alias timespec timestruc_t;
1324}
1325else
1326{
1327    static assert(false, "Unsupported platform");
1328}
1329
1330//
1331// Realtime Signals (RTS)
1332//
1333/*
1334struct sigevent
1335{
1336    int             sigev_notify;
1337    int             sigev_signo;
1338    sigval          sigev_value;
1339    void(*)(sigval) sigev_notify_function;
1340    pthread_attr_t* sigev_notify_attributes;
1341}
1342
1343int sigqueue(pid_t, int, in sigval);
1344int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1345int sigwaitinfo(in sigset_t*, siginfo_t*);
1346*/
1347
1348version( linux )
1349{
1350    private enum __SIGEV_MAX_SIZE = 64;
1351
1352    static if( false /* __WORDSIZE == 64 */ )
1353    {
1354        private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4);
1355    }
1356    else
1357    {
1358        private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3);
1359    }
1360
1361    struct sigevent
1362    {
1363        sigval      sigev_value;
1364        int         sigev_signo;
1365        int         sigev_notify;
1366
1367        union _sigev_un_t
1368        {
1369            int[__SIGEV_PAD_SIZE] _pad;
1370            pid_t                 _tid;
1371
1372            struct _sigev_thread_t
1373            {
1374                void function(sigval)   _function;
1375                void*                   _attribute;
1376            } _sigev_thread_t _sigev_thread;
1377        } _sigev_un_t _sigev_un;
1378    }
1379
1380    int sigqueue(pid_t, int, in sigval);
1381    int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1382    int sigwaitinfo(in sigset_t*, siginfo_t*);
1383}
1384else version( FreeBSD )
1385{
1386    struct sigevent
1387    {
1388        int             sigev_notify;
1389        int             sigev_signo;
1390        sigval          sigev_value;
1391        union  _sigev_un
1392        {
1393            lwpid_t _threadid;
1394            struct _sigev_thread
1395            {
1396                void function(sigval) _function;
1397                void* _attribute;
1398            }
1399            c_long[8] __spare__;
1400        }
1401    }
1402
1403    int sigqueue(pid_t, int, in sigval);
1404    int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1405    int sigwaitinfo(in sigset_t*, siginfo_t*);
1406}
1407else version (OSX)
1408{
1409}
1410else version (Solaris)
1411{
1412    struct sigevent
1413    {
1414        int sigev_notify;
1415        int sigev_signo;
1416        sigval sigev_value;
1417        void function(sigval) sigev_notify_function;
1418        pthread_attr_t* sigev_notify_attributes;
1419        int __sigev_pad2;
1420    }
1421
1422    int sigqueue(pid_t, int, in sigval);
1423    int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
1424    int sigwaitinfo(in sigset_t*, siginfo_t*);
1425}
1426else
1427{
1428    static assert(false, "Unsupported platform");
1429}
1430
1431//
1432// Threads (THR)
1433//
1434/*
1435int pthread_kill(pthread_t, int);
1436int pthread_sigmask(int, in sigset_t*, sigset_t*);
1437*/
1438
1439version( linux )
1440{
1441    int pthread_kill(pthread_t, int);
1442    int pthread_sigmask(int, in sigset_t*, sigset_t*);
1443}
1444else version( OSX )
1445{
1446    int pthread_kill(pthread_t, int);
1447    int pthread_sigmask(int, in sigset_t*, sigset_t*);
1448}
1449else version( FreeBSD )
1450{
1451    int pthread_kill(pthread_t, int);
1452    int pthread_sigmask(int, in sigset_t*, sigset_t*);
1453}
1454else version (Solaris)
1455{
1456    int pthread_kill(pthread_t, int);
1457    int pthread_sigmask(int, in sigset_t*, sigset_t*);
1458}
1459else
1460{
1461    static assert(false, "Unsupported platform");
1462}