From c92b1de12933e6d8b391631b9d553aefba71d918 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 20 Jan 2022 12:57:41 +0100 Subject: [PATCH 1/4] Issue 22689: core.sys.posix.signal: Separate OS-specific sigaction type and flags from C runtime functions --- src/core/sys/posix/signal.d | 1301 +++++++++++++++++++---------------- 1 file changed, 695 insertions(+), 606 deletions(-) diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index 32e51561562..a554e6958b4 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -540,9 +540,54 @@ else static assert(false, "Unsupported platform"); } -version (CRuntime_Glibc) +version (linux) { - version (SystemZ) + version (CRuntime_Musl) + { + struct sigaction_t + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + sigset_t sa_mask; + int sa_flags; + void function() sa_restorer; + } + } + else version (CRuntime_Bionic) + { + version (D_LP64) + { + struct sigaction_t + { + int sa_flags; + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + sigset_t sa_mask; + void function() sa_restorer; + } + } + else + { + struct sigaction_t + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + sigset_t sa_mask; + int sa_flags; + void function() sa_restorer; + } + } + } + else version (SystemZ) { struct sigaction_t { @@ -558,15 +603,22 @@ version (CRuntime_Glibc) { sigfn_t sa_handler; } - int __glibc_reserved0; - int sa_flags; + version (CRuntime_Glibc) + { + int __glibc_reserved0; + int sa_flags; + } + else + { + c_ulong sa_flags; + } void function() sa_restorer; sigset_t sa_mask; } } - else + else version (HPPA_Any) { struct sigaction_t { @@ -582,33 +634,100 @@ version (CRuntime_Glibc) { sigfn_t sa_handler; } + version (CRuntime_Glibc) + { + version (D_LP64) + int __glibc_reserved0; + int sa_flags; + } + else + { + c_ulong sa_flags; + } sigset_t sa_mask; - int sa_flags; + } + } + else version (MIPS_Any) + { + struct sigaction_t + { + int sa_flags; + static if ( true /* __USE_POSIX199309 */ ) + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + } + else + { + sigfn_t sa_handler; + } + sigset_t sa_mask; void function() sa_restorer; + + version (CRuntime_Glibc) + { + static if ((void*).sizeof < 8) + int[1] sa_resv; + } } } -} -else version (CRuntime_Musl) -{ - struct sigaction_t + else version (SPARC_Any) { - static if ( true /* __USE_POSIX199309 */ ) + struct sigaction_t { - union + static if ( true /* __USE_POSIX199309 */ ) + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + } + else { sigfn_t sa_handler; - sigactfn_t sa_sigaction; + } + version (CRuntime_Glibc) + { + sigset_t sa_mask; + version (D_LP64) + int __glibc_reserved0; + int sa_flags; + void function() sa_restorer; + } + else + { + c_ulong sa_flags; + void function() sa_restorer; + sigset_t sa_mask; } } - else + } + else + { + struct sigaction_t { - sigfn_t sa_handler; - } - sigset_t sa_mask; - int sa_flags; + static if ( true /* __USE_POSIX199309 */ ) + { + union + { + sigfn_t sa_handler; + sigactfn_t sa_sigaction; + } + } + else + { + sigfn_t sa_handler; + } + sigset_t sa_mask; + int sa_flags; - void function() sa_restorer; + void function() sa_restorer; + } } } else version (FreeBSD) @@ -683,91 +802,6 @@ else version (Solaris) int[2] sa_resv; } } -else version (CRuntime_UClibc) -{ - version (ARM) version = sigaction_common; - else version (X86_64) version = sigaction_common; - - version (sigaction_common) - { - struct sigaction_t - { - static if ( true /* __USE_POSIX199309 */ ) - { - union - { - sigfn_t sa_handler; - sigactfn_t sa_sigaction; - } - } - else - { - sigfn_t sa_handler; - } - c_ulong sa_flags; - void function() sa_restorer; - sigset_t sa_mask; - } - } - else version (MIPS32) - { - struct sigaction_t - { - uint sa_flags; - static if ( true /* __USE_POSIX199309 */ ) - { - union - { - sigfn_t sa_handler; - sigactfn_t sa_sigaction; - } - } - else - { - sigfn_t sa_handler; - } - sigset_t sa_mask; - void function() sa_restorer; - } - } - else - { - static assert(false, "Architecture not supported."); - } -} -else version (CRuntime_Bionic) -{ - version (D_LP64) - { - struct sigaction_t - { - int sa_flags; - union - { - sigfn_t sa_handler; - sigactfn_t sa_sigaction; - } - - sigset_t sa_mask; - void function() sa_restorer; - } - } - else - { - struct sigaction_t - { - union - { - sigfn_t sa_handler; - sigactfn_t sa_sigaction; - } - - sigset_t sa_mask; - int sa_flags; - void function() sa_restorer; - } - } -} else version (Darwin) { struct sigaction_t @@ -808,49 +842,6 @@ SIGILL (defined in core.stdc.signal) SIGINT (defined in core.stdc.signal) SIGSEGV (defined in core.stdc.signal) SIGTERM (defined in core.stdc.signal) - -SA_NOCLDSTOP (CX|XSI) -SIG_BLOCK -SIG_UNBLOCK -SIG_SETMASK - -struct siginfo_t -{ - int si_signo; - int si_code; - - version (XSI) - { - int si_errno; - pid_t si_pid; - uid_t si_uid; - void* si_addr; - int si_status; - c_long si_band; - } - version (RTS) - { - sigval si_value; - } -} - -SI_USER -SI_QUEUE -SI_TIMER -SI_ASYNCIO -SI_MESGQ - -int kill(pid_t, int); -int sigaction(int, const scope sigaction_t*, sigaction_t*); -int sigaddset(sigset_t*, int); -int sigdelset(sigset_t*, int); -int sigemptyset(sigset_t*); -int sigfillset(sigset_t*); -int sigismember(const scope sigset_t*, int); -int sigpending(sigset_t*); -int sigprocmask(int, const scope sigset_t*, sigset_t*); -int sigsuspend(const scope sigset_t*); -int sigwait(const scope sigset_t*, int*); */ nothrow @nogc @@ -866,30 +857,227 @@ version (CRuntime_Glibc) { c_ulong[_SIGSET_NWORDS] __val; } +} +else version (Darwin) +{ + enum SIG_HOLD = cast(sigfn_t2) 5; - // pid_t (defined in core.sys.types) - - //SIGABRT (defined in core.stdc.signal) - //SIGFPE (defined in core.stdc.signal) - //SIGILL (defined in core.stdc.signal) - //SIGINT (defined in core.stdc.signal) - //SIGSEGV (defined in core.stdc.signal) - //SIGTERM (defined in core.stdc.signal) - - enum SA_NOCLDSTOP = 1; // (CX|XSI) - - enum SIG_BLOCK = 0; - enum SIG_UNBLOCK = 1; - enum SIG_SETMASK = 2; - - private enum __SI_MAX_SIZE = 128; + alias uint sigset_t; +} +else version (FreeBSD) +{ + enum SIG_HOLD = cast(sigfn_t2) 3; - static if ( __WORDSIZE == 64 ) + struct sigset_t { - private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4); + uint[4] __bits; } - else - { +} +else version (NetBSD) +{ + enum SIG_HOLD = cast(sigfn_t2) 3; + + struct sigset_t + { + uint[4] __bits; + } +} +else version (OpenBSD) +{ + enum SIG_CATCH = cast(sigfn_t2) 2; + enum SIG_HOLD = cast(sigfn_t2) 3; + + alias sigset_t = uint; +} +else version (DragonFlyBSD) +{ + enum SIG_CATCH = cast(sigfn_t2) 2; + enum SIG_HOLD = cast(sigfn_t2) 3; + + struct sigset_t + { + uint[4] __bits; + } +} +else version (Solaris) +{ + enum SIG_HOLD = cast(sigfn_t2)2; + + struct sigset_t + { + uint[4] __bits; + } +} +else version (CRuntime_Bionic) +{ + version (X86) + alias uint sigset_t; + else version (ARM) + alias uint sigset_t; + else version (AArch64) + struct sigset_t { ulong[1] sig; } + else version (X86_64) + alias ulong sigset_t; + else + static assert(false, "Architecture not supported."); +} +else version (CRuntime_Musl) +{ + struct sigset_t + { + c_ulong[128/c_long.sizeof] __bits; + } +} +else version (CRuntime_UClibc) +{ + enum SIG_HOLD = cast(sigfn_t2) 2; + + version (MIPS32) + private enum _SIGSET_NWORDS = 128 / (8 * c_ulong.sizeof); + else + private enum _SIGSET_NWORDS = 64 / (8 * c_ulong.sizeof); + + struct sigset_t + { + c_ulong[_SIGSET_NWORDS] __val; + } +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +SA_NOCLDSTOP (CX|XSI) +SIG_BLOCK +SIG_UNBLOCK +SIG_SETMASK +*/ + +version (linux) +{ + enum SA_NOCLDSTOP = 1; // (CX|XSI) + + version (MIPS_Any) + { + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + } + else version (SPARC_Any) + { + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 4; + } + else + { + enum SIG_BLOCK = 0; + enum SIG_UNBLOCK = 1; + enum SIG_SETMASK = 2; + } +} +else version (Darwin) +{ + enum SA_NOCLDSTOP = 8; // (CX|XSI) + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else version (FreeBSD) +{ + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else version (NetBSD) +{ + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else version (OpenBSD) +{ + enum SA_NOCLDSTOP = 0x0008; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else version (DragonFlyBSD) +{ + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else version (Solaris) +{ + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +struct siginfo_t +{ + int si_signo; + int si_code; + + version (XSI) + { + int si_errno; + pid_t si_pid; + uid_t si_uid; + void* si_addr; + int si_status; + c_long si_band; + } + version (RTS) + { + sigval si_value; + } +} + +SI_USER +SI_QUEUE +SI_TIMER +SI_ASYNCIO +SI_MESGQ + +int kill(pid_t, int); +int sigaction(int, const scope sigaction_t*, sigaction_t*); +int sigaddset(sigset_t*, int); +int sigdelset(sigset_t*, int); +int sigemptyset(sigset_t*); +int sigfillset(sigset_t*); +int sigismember(const scope sigset_t*, int); +int sigpending(sigset_t*); +int sigprocmask(int, const scope sigset_t*, sigset_t*); +int sigsuspend(const scope sigset_t*); +int sigwait(const scope sigset_t*, int*); +*/ + +version (CRuntime_Glibc) +{ + private enum __SI_MAX_SIZE = 128; + + static if ( __WORDSIZE == 64 ) + { + private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4); + } + else + { private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3); } @@ -987,24 +1175,6 @@ version (CRuntime_Glibc) } else version (Darwin) { - enum SIG_HOLD = cast(sigfn_t2) 5; - - alias uint sigset_t; - // pid_t (defined in core.sys.types) - - //SIGABRT (defined in core.stdc.signal) - //SIGFPE (defined in core.stdc.signal) - //SIGILL (defined in core.stdc.signal) - //SIGINT (defined in core.stdc.signal) - //SIGSEGV (defined in core.stdc.signal) - //SIGTERM (defined in core.stdc.signal) - - enum SA_NOCLDSTOP = 8; // (CX|XSI) - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - struct siginfo_t { int si_signo; @@ -1039,19 +1209,6 @@ else version (Darwin) } else version (FreeBSD) { - enum SIG_HOLD = cast(sigfn_t2) 3; - - struct sigset_t - { - uint[4] __bits; - } - - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - struct siginfo_t { int si_signo; @@ -1117,19 +1274,6 @@ else version (FreeBSD) } else version (NetBSD) { - enum SIG_HOLD = cast(sigfn_t2) 3; - - struct sigset_t - { - uint[4] __bits; - } - - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - union sigval_t { int sival_int; @@ -1213,17 +1357,6 @@ else version (NetBSD) } else version (OpenBSD) { - enum SIG_CATCH = cast(sigfn_t2) 2; - enum SIG_HOLD = cast(sigfn_t2) 3; - - alias sigset_t = uint; - - enum SA_NOCLDSTOP = 0x0008; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - private enum SI_MAXSZ = 128; private enum SI_PAD = (SI_MAXSZ / int.sizeof) - 3; @@ -1289,20 +1422,6 @@ else version (OpenBSD) } else version (DragonFlyBSD) { - enum SIG_CATCH = cast(sigfn_t2) 2; - enum SIG_HOLD = cast(sigfn_t2) 3; - - struct sigset_t - { - uint[4] __bits; - } - - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - struct siginfo_t { int si_signo; @@ -1338,17 +1457,6 @@ else version (DragonFlyBSD) } else version (Solaris) { - enum SIG_HOLD = cast(sigfn_t2)2; - - struct sigset_t - { - uint[4] __bits; - } - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - struct siginfo_t { int si_signo; @@ -1467,33 +1575,15 @@ else version (CRuntime_Bionic) import core.stdc.string : memset; version (X86) - { - alias uint sigset_t; enum int LONG_BIT = 32; - } else version (ARM) - { - alias uint sigset_t; enum int LONG_BIT = 32; - } else version (AArch64) - { - struct sigset_t { ulong[1] sig; } enum int LONG_BIT = 64; - } else version (X86_64) - { - alias ulong sigset_t; enum int LONG_BIT = 64; - } else - { static assert(false, "Architecture not supported."); - } - - enum SIG_BLOCK = 0; - enum SIG_UNBLOCK = 1; - enum SIG_SETMASK = 2; private enum SI_MAX_SIZE = 128; private enum SI_PAD_SIZE = ((SI_MAX_SIZE / int.sizeof) - 3); @@ -1601,24 +1691,6 @@ else version (CRuntime_Bionic) } else version (CRuntime_Musl) { - struct sigset_t - { - c_ulong[128/c_long.sizeof] __bits; - } - - version (MIPS_Any) - { - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - } - else - { - enum SIG_BLOCK = 0; - enum SIG_UNBLOCK = 1; - enum SIG_SETMASK = 2; - } - struct siginfo_t { int si_signo; @@ -1720,24 +1792,6 @@ else version (CRuntime_Musl) } else version (CRuntime_UClibc) { - enum SIG_HOLD = cast(sigfn_t2) 2; - - version (MIPS32) - private enum _SIGSET_NWORDS = 128 / (8 * c_ulong.sizeof); - else - private enum _SIGSET_NWORDS = 64 / (8 * c_ulong.sizeof); - - struct sigset_t - { - c_ulong[_SIGSET_NWORDS] __val; - } - - enum SA_NOCLDSTOP = 1; - - enum SIG_BLOCK = 0; - enum SIG_UNBLOCK = 1; - enum SIG_SETMASK = 2; - private enum __SI_MAX_SIZE = 128; static if ( __WORDSIZE == 64 ) @@ -1978,86 +2032,6 @@ SIGTRAP SIGVTALRM SIGXCPU SIGXFSZ - -SA_ONSTACK -SA_RESETHAND -SA_RESTART -SA_SIGINFO -SA_NOCLDWAIT -SA_NODEFER -SS_ONSTACK -SS_DISABLE -MINSIGSTKSZ -SIGSTKSZ - -ucontext_t // from ucontext -mcontext_t // from ucontext - -struct stack_t -{ - void* ss_sp; - size_t ss_size; - int ss_flags; -} - -struct sigstack -{ - int ss_onstack; - void* ss_sp; -} - -ILL_ILLOPC -ILL_ILLOPN -ILL_ILLADR -ILL_ILLTRP -ILL_PRVOPC -ILL_PRVREG -ILL_COPROC -ILL_BADSTK - -FPE_INTDIV -FPE_INTOVF -FPE_FLTDIV -FPE_FLTOVF -FPE_FLTUND -FPE_FLTRES -FPE_FLTINV -FPE_FLTSUB - -SEGV_MAPERR -SEGV_ACCERR - -BUS_ADRALN -BUS_ADRERR -BUS_OBJERR - -TRAP_BRKPT -TRAP_TRACE - -CLD_EXITED -CLD_KILLED -CLD_DUMPED -CLD_TRAPPED -CLD_STOPPED -CLD_CONTINUED - -POLL_IN -POLL_OUT -POLL_MSG -POLL_ERR -POLL_PRI -POLL_HUP - -sigfn_t bsd_signal(int sig, sigfn_t func); -sigfn_t sigset(int sig, sigfn_t func); - -int killpg(pid_t, int); -int sigaltstack(const scope stack_t*, stack_t*); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); */ version (CRuntime_Glibc) @@ -2144,13 +2118,347 @@ version (CRuntime_Glibc) } else static assert(0, "unimplemented"); +} +else version (Darwin) +{ + enum SIGPOLL = 7; + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (FreeBSD) +{ + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (NetBSD) +{ + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (OpenBSD) +{ + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (DragonFlyBSD) +{ + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (Solaris) +{ + enum SIGPOLL = 22; + enum SIGPROF = 29; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 28; + enum SIGXCPU = 30; + enum SIGXFSZ = 31; +} +else version (CRuntime_Bionic) +{ + enum SIGPOLL = 29; + enum SIGPROF = 27; + enum SIGSYS = 31; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; +} +else version (CRuntime_Musl) +{ + version (MIPS_Any) + { + enum SIGPOLL = 22; + enum SIGPROF = 29; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 28; + enum SIGXCPU = 30; + enum SIGXFSZ = 31; + } + else + { + enum SIGPOLL = 29; + enum SIGPROF = 27; + enum SIGSYS = 31; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + } +} +else version (CRuntime_UClibc) +{ + version (X86_64) + { + enum SIGTRAP = 5; + enum SIGIOT = 6; + enum SIGSTKFLT = 16; + enum SIGCLD = SIGCHLD; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum SIGVTALRM = 26; + enum SIGPROF = 27; + enum SIGWINCH = 28; + enum SIGPOLL = SIGIO; + enum SIGIO = 29; + enum SIGPWR = 30; + enum SIGSYS = 31; + enum SIGUNUSED = 31; + } + else version (MIPS32) + { + enum SIGTRAP = 5; + enum SIGIOT = 6; + enum SIGEMT = 7; + enum SIGFPE = 8; + enum SIGSYS = 12; + enum SIGCLD = SIGCHLD; + enum SIGPWR = 19; + enum SIGWINCH = 20; + enum SIGIO = 22; + enum SIGPOLL = SIGIO; + enum SIGVTALRM = 28; + enum SIGPROF = 29; + enum SIGXCPU = 30; + enum SIGXFSZ = 31; + } + else version (ARM) + { + enum SIGTRAP = 5; + enum SIGIOT = 6; + enum SIGSTKFLT = 16; + enum SIGCLD = SIGCHLD; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum SIGVTALRM = 26; + enum SIGPROF = 27; + enum SIGWINCH = 28; + enum SIGPOLL = SIGIO; + enum SIGIO = 29; + enum SIGPWR = 30; + enum SIGSYS = 31; + enum SIGUNUSED = 31; + } + else + static assert(0, "unimplemented"); +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +SA_ONSTACK +SA_RESETHAND +SA_RESTART +SA_SIGINFO +SA_NOCLDWAIT +SA_NODEFER +*/ + +version (linux) +{ + version (MIPS_Any) + { + enum SA_ONSTACK = 0x08000000; + enum SA_RESETHAND = 0x80000000; + enum SA_RESTART = 0x10000000; + enum SA_SIGINFO = 8; + enum SA_NOCLDWAIT = 0x10000; + enum SA_NODEFER = 0x40000000; + } + else + { + enum SA_ONSTACK = 0x08000000; + enum SA_RESETHAND = 0x80000000; + enum SA_RESTART = 0x10000000; + enum SA_SIGINFO = 4; + enum SA_NOCLDWAIT = 2; + enum SA_NODEFER = 0x40000000; + } + + enum SA_NOMASK = SA_NODEFER; + enum SA_ONESHOT = SA_RESETHAND; + enum SA_STACK = SA_ONSTACK; +} +else version (Darwin) +{ + enum SA_ONSTACK = 0x0001; + enum SA_RESETHAND = 0x0004; + enum SA_RESTART = 0x0002; + enum SA_SIGINFO = 0x0040; + enum SA_NOCLDWAIT = 0x0020; + enum SA_NODEFER = 0x0010; +} +else version (FreeBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } +} +else version (NetBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } +} +else version (OpenBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } +} +else version (DragonFlyBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } +} +else version (Solaris) +{ + enum + { + SA_ONSTACK = 0x00001, + SA_RESTART = 0x00004, + SA_RESETHAND = 0x00002, + SA_NODEFER = 0x00010, + SA_NOCLDWAIT = 0x10000, + SA_SIGINFO = 0x00008, + } +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +SS_ONSTACK +SS_DISABLE +MINSIGSTKSZ +SIGSTKSZ + +ucontext_t // from ucontext +mcontext_t // from ucontext + +struct stack_t +{ + void* ss_sp; + size_t ss_size; + int ss_flags; +} + +struct sigstack +{ + int ss_onstack; + void* ss_sp; +} + +ILL_ILLOPC +ILL_ILLOPN +ILL_ILLADR +ILL_ILLTRP +ILL_PRVOPC +ILL_PRVREG +ILL_COPROC +ILL_BADSTK + +FPE_INTDIV +FPE_INTOVF +FPE_FLTDIV +FPE_FLTOVF +FPE_FLTUND +FPE_FLTRES +FPE_FLTINV +FPE_FLTSUB + +SEGV_MAPERR +SEGV_ACCERR + +BUS_ADRALN +BUS_ADRERR +BUS_OBJERR + +TRAP_BRKPT +TRAP_TRACE + +CLD_EXITED +CLD_KILLED +CLD_DUMPED +CLD_TRAPPED +CLD_STOPPED +CLD_CONTINUED + +POLL_IN +POLL_OUT +POLL_MSG +POLL_ERR +POLL_PRI +POLL_HUP + +sigfn_t bsd_signal(int sig, sigfn_t func); +sigfn_t sigset(int sig, sigfn_t func); + +int killpg(pid_t, int); +int sigaltstack(const scope stack_t*, stack_t*); +int sighold(int); +int sigignore(int); +int siginterrupt(int, int); +int sigpause(int); +int sigrelse(int); +*/ - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 4; - enum SA_NOCLDWAIT = 2; - enum SA_NODEFER = 0x40000000; +version (CRuntime_Glibc) +{ enum SS_ONSTACK = 1; enum SS_DISABLE = 2; enum MINSIGSTKSZ = 2048; @@ -2253,20 +2561,6 @@ version (CRuntime_Glibc) } else version (Darwin) { - enum SIGPOLL = 7; - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum SA_ONSTACK = 0x0001; - enum SA_RESETHAND = 0x0004; - enum SA_RESTART = 0x0002; - enum SA_SIGINFO = 0x0040; - enum SA_NOCLDWAIT = 0x0020; - enum SA_NODEFER = 0x0010; enum SS_ONSTACK = 0x0001; enum SS_DISABLE = 0x0004; enum MINSIGSTKSZ = 32768; @@ -2363,24 +2657,6 @@ else version (Darwin) } else version (FreeBSD) { - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } - enum { SS_ONSTACK = 0x0001, @@ -2487,24 +2763,6 @@ else version (FreeBSD) } else version (NetBSD) { - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } - enum { SS_ONSTACK = 0x0001, @@ -2611,24 +2869,6 @@ else version (NetBSD) } else version (OpenBSD) { - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } - enum { SS_ONSTACK = 0x0001, @@ -2727,24 +2967,6 @@ else version (OpenBSD) } else version (DragonFlyBSD) { - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } - enum { SS_ONSTACK = 0x0001, @@ -2851,24 +3073,6 @@ else version (DragonFlyBSD) } else version (Solaris) { - enum SIGPOLL = 22; - enum SIGPROF = 29; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 28; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; - - enum - { - SA_ONSTACK = 0x00001, - SA_RESTART = 0x00004, - SA_RESETHAND = 0x00002, - SA_NODEFER = 0x00010, - SA_NOCLDWAIT = 0x10000, - SA_SIGINFO = 0x00008, - } - enum { SS_ONSTACK = 0x0001, @@ -2975,20 +3179,6 @@ else version (Solaris) } else version (CRuntime_Bionic) { - enum SIGPOLL = 29; - enum SIGPROF = 27; - enum SIGSYS = 31; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 4; - enum SA_NOCLDWAIT = 2; - enum SA_NODEFER = 0x40000000; enum SS_ONSTACK = 1; enum SS_DISABLE = 2; enum MINSIGSTKSZ = 2048; @@ -3076,41 +3266,6 @@ else version (CRuntime_Bionic) } else version (CRuntime_Musl) { - version (MIPS_Any) - { - enum SIGPOLL = 22; - enum SIGPROF = 29; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 28; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; - - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 8; - enum SA_NOCLDWAIT = 0x10000; - enum SA_NODEFER = 0x40000000; - } - else - { - enum SIGPOLL = 29; - enum SIGPROF = 27; - enum SIGSYS = 31; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 4; - enum SA_NOCLDWAIT = 2; - enum SA_NODEFER = 0x40000000; - } - enum SS_ONSTACK = 1; enum SS_DISABLE = 2; @@ -3250,77 +3405,11 @@ else version (CRuntime_Musl) } else version (CRuntime_UClibc) { - version (X86_64) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGSTKFLT = 16; - enum SIGCLD = SIGCHLD; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - enum SIGVTALRM = 26; - enum SIGPROF = 27; - enum SIGWINCH = 28; - enum SIGPOLL = SIGIO; - enum SIGIO = 29; - enum SIGPWR = 30; - enum SIGSYS = 31; - enum SIGUNUSED = 31; - } - else version (MIPS32) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGEMT = 7; - enum SIGFPE = 8; - enum SIGSYS = 12; - enum SIGCLD = SIGCHLD; - enum SIGPWR = 19; - enum SIGWINCH = 20; - enum SIGIO = 22; - enum SIGPOLL = SIGIO; - enum SIGVTALRM = 28; - enum SIGPROF = 29; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; - } - else version (ARM) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGSTKFLT = 16; - enum SIGCLD = SIGCHLD; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - enum SIGVTALRM = 26; - enum SIGPROF = 27; - enum SIGWINCH = 28; - enum SIGPOLL = SIGIO; - enum SIGIO = 29; - enum SIGPWR = 30; - enum SIGSYS = 31; - enum SIGUNUSED = 31; - } - else - static assert(0, "unimplemented"); - - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 4; - enum SA_NOCLDWAIT = 2; - enum SA_NODEFER = 0x40000000; enum SS_ONSTACK = 1; enum SS_DISABLE = 2; enum MINSIGSTKSZ = 2048; enum SIGSTKSZ = 8192; - enum SA_INTERRUPT = 0x20000000; - - enum SA_NOMASK = SA_NODEFER; - enum SA_ONESHOT = SA_RESETHAND; - enum SA_STACK = SA_ONSTACK; - version (MIPS32) { struct stack_t From edbb8bb3806e90f1d214ea96c5435f73a6a9aca5 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 20 Jan 2022 16:43:08 +0100 Subject: [PATCH 2/4] Issue 22689: core.sys.posix.signal: Separate OS-specific siginfo types and flags from C runtime functions --- src/core/sys/posix/signal.d | 2004 ++++++++++++----------------------- 1 file changed, 706 insertions(+), 1298 deletions(-) diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index a554e6958b4..babd652f11b 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -952,83 +952,7 @@ SA_NOCLDSTOP (CX|XSI) SIG_BLOCK SIG_UNBLOCK SIG_SETMASK -*/ - -version (linux) -{ - enum SA_NOCLDSTOP = 1; // (CX|XSI) - - version (MIPS_Any) - { - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; - } - else version (SPARC_Any) - { - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 4; - } - else - { - enum SIG_BLOCK = 0; - enum SIG_UNBLOCK = 1; - enum SIG_SETMASK = 2; - } -} -else version (Darwin) -{ - enum SA_NOCLDSTOP = 8; // (CX|XSI) - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else version (FreeBSD) -{ - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else version (NetBSD) -{ - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else version (OpenBSD) -{ - enum SA_NOCLDSTOP = 0x0008; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else version (DragonFlyBSD) -{ - enum SA_NOCLDSTOP = 8; - - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else version (Solaris) -{ - enum SIG_BLOCK = 1; - enum SIG_UNBLOCK = 2; - enum SIG_SETMASK = 3; -} -else -{ - static assert(false, "Unsupported platform"); -} -/* struct siginfo_t { int si_signo; @@ -1054,22 +978,31 @@ SI_QUEUE SI_TIMER SI_ASYNCIO SI_MESGQ - -int kill(pid_t, int); -int sigaction(int, const scope sigaction_t*, sigaction_t*); -int sigaddset(sigset_t*, int); -int sigdelset(sigset_t*, int); -int sigemptyset(sigset_t*); -int sigfillset(sigset_t*); -int sigismember(const scope sigset_t*, int); -int sigpending(sigset_t*); -int sigprocmask(int, const scope sigset_t*, sigset_t*); -int sigsuspend(const scope sigset_t*); -int sigwait(const scope sigset_t*, int*); */ -version (CRuntime_Glibc) +version (linux) { + enum SA_NOCLDSTOP = 1; // (CX|XSI) + + version (MIPS_Any) + { + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + } + else version (SPARC_Any) + { + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 4; + } + else + { + enum SIG_BLOCK = 0; + enum SIG_UNBLOCK = 1; + enum SIG_SETMASK = 2; + } + private enum __SI_MAX_SIZE = 128; static if ( __WORDSIZE == 64 ) @@ -1083,10 +1016,17 @@ version (CRuntime_Glibc) struct siginfo_t { - int si_signo; // Signal number - int si_errno; // If non-zero, an errno value associated with - // this signal, as defined in - int si_code; // Signal code + int si_signo; + version (MIPS_Any) // __SI_SWAP_ERRNO_CODE + { + int si_code; + int si_errno; + } + else + { + int si_errno; + int si_code; + } union _sifields_t { @@ -1095,32 +1035,31 @@ version (CRuntime_Glibc) // kill() struct _kill_t { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process + pid_t si_pid; + uid_t si_uid; } _kill_t _kill; - // POSIX.1b timers. struct _timer_t { - int si_tid; // Timer ID - int si_overrun; // Overrun count - sigval si_sigval; // Signal value + int si_tid; + int si_overrun; + sigval si_sigval; } _timer_t _timer; // POSIX.1b signals struct _rt_t { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process - sigval si_sigval; // Signal value + pid_t si_pid; + uid_t si_uid; + sigval si_sigval; } _rt_t _rt; // SIGCHLD struct _sigchild_t { - pid_t si_pid; // Which child - uid_t si_uid; // Real user ID of sending process - int si_status; // Exit value or signal + pid_t si_pid; + uid_t si_uid; + int si_status; clock_t si_utime; clock_t si_stime; } _sigchild_t _sigchld; @@ -1128,13 +1067,13 @@ version (CRuntime_Glibc) // SIGILL, SIGFPE, SIGSEGV, SIGBUS struct _sigfault_t { - void* si_addr; // Faulting insn/memory ref + void* si_addr; } _sigfault_t _sigfault; // SIGPOLL struct _sigpoll_t { - c_long si_band; // Band event for SIGPOLL + c_long si_band; int si_fd; } _sigpoll_t _sigpoll; } _sifields_t _sifields; @@ -1160,21 +1099,15 @@ version (CRuntime_Glibc) SI_USER, SI_KERNEL = 0x80 } - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t*); - int sigfillset(sigset_t*); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t*); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } else version (Darwin) { + enum SA_NOCLDSTOP = 8; // (CX|XSI) + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + struct siginfo_t { int si_signo; @@ -1194,21 +1127,15 @@ else version (Darwin) enum SI_TIMER = 0x10003; enum SI_ASYNCIO = 0x10004; enum SI_MESGQ = 0x10005; - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t*); - int sigfillset(sigset_t*); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t*); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } else version (FreeBSD) { + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + struct siginfo_t { int si_signo; @@ -1259,21 +1186,15 @@ else version (FreeBSD) enum SI_TIMER = 0x10003; enum SI_ASYNCIO = 0x10004; enum SI_MESGQ = 0x10005; - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t *); - int sigfillset(sigset_t *); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t *); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } else version (NetBSD) { + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + union sigval_t { int sival_int; @@ -1332,31 +1253,15 @@ else version (NetBSD) enum SI_TIMER = -2; enum SI_ASYNCIO = -3; enum SI_MESGQ = -4; - - int kill(pid_t, int); - int __sigaction14(int, const scope sigaction_t*, sigaction_t*); - int __sigaddset14(sigset_t*, int); - int __sigdelset14(sigset_t*, int); - int __sigemptyset14(sigset_t *); - int __sigfillset14(sigset_t *); - int __sigismember14(const scope sigset_t*, int); - int __sigpending14(sigset_t *); - int __sigprocmask14(int, const scope sigset_t*, sigset_t*); - int __sigsuspend14(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); - - alias __sigaction14 sigaction; - alias __sigaddset14 sigaddset; - alias __sigdelset14 sigdelset; - alias __sigemptyset14 sigemptyset; - alias __sigfillset14 sigfillset; - alias __sigismember14 sigismember; - alias __sigpending14 sigpending; - alias __sigprocmask14 sigprocmask; - alias __sigsuspend14 sigsuspend; } else version (OpenBSD) { + enum SA_NOCLDSTOP = 0x0008; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + private enum SI_MAXSZ = 128; private enum SI_PAD = (SI_MAXSZ / int.sizeof) - 3; @@ -1407,21 +1312,15 @@ else version (OpenBSD) enum SI_LWP = -1; enum SI_QUEUE = -2; enum SI_TIMER = -3; - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t *); - int sigfillset(sigset_t *); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t *); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } else version (DragonFlyBSD) { + enum SA_NOCLDSTOP = 8; + + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + struct siginfo_t { int si_signo; @@ -1442,21 +1341,13 @@ else version (DragonFlyBSD) enum SI_TIMER = -2; enum SI_ASYNCIO = -3; enum SI_MESGQ = -4; - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t *); - int sigfillset(sigset_t *); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t *); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } else version (Solaris) { + enum SIG_BLOCK = 1; + enum SIG_UNBLOCK = 2; + enum SIG_SETMASK = 3; + struct siginfo_t { int si_signo; @@ -1554,24 +1445,139 @@ else version (Solaris) enum SI_TIMER = -3; enum SI_ASYNCIO = -4; enum SI_MESGQ = -5; - - enum SIGIO = SIGPOLL; - - int kill(pid_t, int); - int sigaction(int, const scope sigaction_t*, sigaction_t*); - int sigaddset(sigset_t*, int); - int sigdelset(sigset_t*, int); - int sigemptyset(sigset_t*); - int sigfillset(sigset_t*); - int sigismember(const scope sigset_t*, int); - int sigpending(sigset_t*); - int sigprocmask(int, const scope sigset_t*, sigset_t*); - int sigsuspend(const scope sigset_t*); - int sigwait(const scope sigset_t*, int*); } -else version (CRuntime_Bionic) +else { - public import core.sys.posix.time: timer_t; + static assert(false, "Unsupported platform"); +} + +/* +int kill(pid_t, int); +int sigaction(int, const scope sigaction_t*, sigaction_t*); +int sigaddset(sigset_t*, int); +int sigdelset(sigset_t*, int); +int sigemptyset(sigset_t*); +int sigfillset(sigset_t*); +int sigismember(const scope sigset_t*, int); +int sigpending(sigset_t*); +int sigprocmask(int, const scope sigset_t*, sigset_t*); +int sigsuspend(const scope sigset_t*); +int sigwait(const scope sigset_t*, int*); +*/ + +version (CRuntime_Glibc) +{ + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t*); + int sigfillset(sigset_t*); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t*); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (Darwin) +{ + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t*); + int sigfillset(sigset_t*); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t*); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (FreeBSD) +{ + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t *); + int sigfillset(sigset_t *); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t *); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (NetBSD) +{ + int kill(pid_t, int); + int __sigaction14(int, const scope sigaction_t*, sigaction_t*); + int __sigaddset14(sigset_t*, int); + int __sigdelset14(sigset_t*, int); + int __sigemptyset14(sigset_t *); + int __sigfillset14(sigset_t *); + int __sigismember14(const scope sigset_t*, int); + int __sigpending14(sigset_t *); + int __sigprocmask14(int, const scope sigset_t*, sigset_t*); + int __sigsuspend14(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); + + alias __sigaction14 sigaction; + alias __sigaddset14 sigaddset; + alias __sigdelset14 sigdelset; + alias __sigemptyset14 sigemptyset; + alias __sigfillset14 sigfillset; + alias __sigismember14 sigismember; + alias __sigpending14 sigpending; + alias __sigprocmask14 sigprocmask; + alias __sigsuspend14 sigsuspend; +} +else version (OpenBSD) +{ + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t *); + int sigfillset(sigset_t *); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t *); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (DragonFlyBSD) +{ + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t *); + int sigfillset(sigset_t *); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t *); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (Solaris) +{ + enum SIGIO = SIGPOLL; + + int kill(pid_t, int); + int sigaction(int, const scope sigaction_t*, sigaction_t*); + int sigaddset(sigset_t*, int); + int sigdelset(sigset_t*, int); + int sigemptyset(sigset_t*); + int sigfillset(sigset_t*); + int sigismember(const scope sigset_t*, int); + int sigpending(sigset_t*); + int sigprocmask(int, const scope sigset_t*, sigset_t*); + int sigsuspend(const scope sigset_t*); + int sigwait(const scope sigset_t*, int*); +} +else version (CRuntime_Bionic) +{ + public import core.sys.posix.time: timer_t; import core.stdc.string : memset; version (X86) @@ -1585,74 +1591,6 @@ else version (CRuntime_Bionic) else static assert(false, "Architecture not supported."); - private enum SI_MAX_SIZE = 128; - private enum SI_PAD_SIZE = ((SI_MAX_SIZE / int.sizeof) - 3); - - struct siginfo_t - { - int si_signo; - int si_errno; - int si_code; - - union _sifields_t - { - int[SI_PAD_SIZE] _pad; - - struct _kill_t - { - pid_t _pid; - uid_t _uid; - } _kill_t _kill; - - struct _timer_t - { - timer_t _tid; - int _overrun; - sigval _sigval; - int _sys_private; - } _timer_t _timer; - - struct _rt_t - { - pid_t _pid; - uid_t _uid; - sigval _sigval; - } _rt_t _rt; - - struct _sigchild_t - { - pid_t _pid; - uid_t _uid; - int _status; - clock_t _utime; - clock_t _stime; - } _sigchild_t _sigchld; - - struct _sigfault_t - { - void* _addr; - } _sigfault_t _sigfault; - - struct _sigpoll_t - { - c_long _band; - int _fd; - } _sigpoll_t _sigpoll; - } _sifields_t _sifields; - } - - enum - { - SI_TKILL = -6, - SI_SIGIO, - SI_ASYNCIO, - SI_MESGQ, - SI_TIMER, - SI_QUEUE, - SI_USER, - SI_KERNEL = 0x80 - } - int kill(pid_t, int); int sigaction(int, const scope sigaction_t*, sigaction_t*); @@ -1691,93 +1629,6 @@ else version (CRuntime_Bionic) } else version (CRuntime_Musl) { - struct siginfo_t - { - int si_signo; - version (MIPS_Any) // __SI_SWAP_ERRNO_CODE - { - int si_code; - int si_errno; - } - else - { - int si_errno; - int si_code; - } - union __si_fields_t - { - char[128 - 2*int.sizeof - c_long.sizeof] __pad = 0; - struct __si_common_t - { - union __first_t - { - struct __piduid_t - { - pid_t si_pid; - uid_t si_uid; - } - __piduid_t __piduid; - - struct __timer_t - { - int si_timerid; - int si_overrun; - } - __timer_t __timer; - } - __first_t __first; - - union __second_t - { - sigval si_value; - struct __sigchld_t - { - int si_status; - clock_t si_utime; - clock_t si_stime; - } - __sigchld_t __sigchld; - } - __second_t __second; - } - __si_common_t __si_common; - - struct __sigfault_t - { - void *si_addr; - short si_addr_lsb; - union __first_t - { - struct __addr_bnd_t - { - void *si_lower; - void *si_upper; - } - __addr_bnd_t __addr_bnd; - uint si_pkey; - } - __first_t __first; - } - __sigfault_t __sigfault; - - struct __sigpoll_t - { - c_long si_band; - int si_fd; - } - __sigpoll_t __sigpoll; - - struct __sigsys_t - { - void *si_call_addr; - int si_syscall; - uint si_arch; - } - __sigsys_t __sigsys; - } - __si_fields_t __si_fields; - } - int kill(pid_t, int); int sigaction(int, const scope sigaction_t*, sigaction_t*); int sigaddset(sigset_t*, int); @@ -1792,217 +1643,6 @@ else version (CRuntime_Musl) } else version (CRuntime_UClibc) { - private enum __SI_MAX_SIZE = 128; - - static if ( __WORDSIZE == 64 ) - { - private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 4); - } - else - { - private enum __SI_PAD_SIZE = ((__SI_MAX_SIZE / int.sizeof) - 3); - } - - version (ARM) version = siginfo_common; - else version (X86_64) version = siginfo_common; - - version (siginfo_common) - { - struct siginfo_t - { - int si_signo; // Signal number - int si_errno; // If non-zero, an errno value associated with - // this signal, as defined in - int si_code; // Signal code - - union _sifields_t - { - int[__SI_PAD_SIZE] _pad; - - // kill() - struct _kill_t - { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process - } _kill_t _kill; - - // POSIX.1b timers. - struct _timer_t - { - int si_tid; // Timer ID - int si_overrun; // Overrun count - sigval si_sigval; // Signal value - } _timer_t _timer; - - // POSIX.1b signals - struct _rt_t - { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process - sigval si_sigval; // Signal value - } _rt_t _rt; - - // SIGCHLD - struct _sigchild_t - { - pid_t si_pid; // Which child - uid_t si_uid; // Real user ID of sending process - int si_status; // Exit value or signal - clock_t si_utime; - clock_t si_stime; - } _sigchild_t _sigchld; - - // SIGILL, SIGFPE, SIGSEGV, SIGBUS - struct _sigfault_t - { - void* si_addr; // Faulting insn/memory ref - } _sigfault_t _sigfault; - - // SIGPOLL - struct _sigpoll_t - { - c_long si_band; // Band event for SIGPOLL; - int si_fd; - } _sigpoll_t _sigpoll; - - // SIGSYS - struct _sigsys_t - { - void* _call_addr; // Calling user insn. - int _syscall; // Triggering system call number. - uint _arch; // AUDIT_ARCH_* of syscall. - } _sigsys_t _sigsys; - - } _sifields_t _sifields; - - nothrow @nogc: - @property ref pid_t si_pid()() { return _sifields._kill.si_pid; } - @property ref uid_t si_uid()() { return _sifields._kill.si_uid; } - @property ref int si_timerid()() { return _sifields._timer.si_tid;} - @property ref int si_overrun()() { return _sifields._timer.si_overrun; } - @property ref int si_status()() { return _sifields._sigchld.si_status; } - @property ref clock_t si_utime()() { return _sifields._sigchld.si_utime; } - @property ref clock_t si_stime()() { return _sifields._sigchld.si_stime; } - @property ref sigval si_value()() { return _sifields._rt.si_sigval; } - @property ref int si_int()() { return _sifields._rt.si_sigval.sival_int; } - @property ref void* si_ptr()() { return _sifields._rt.si_sigval.sival_ptr; } - @property ref void* si_addr()() { return _sifields._sigfault.si_addr; } - @property ref c_long si_band()() { return _sifields._sigpoll.si_band; } - @property ref int si_fd()() { return _sifields._sigpoll.si_fd; } - @property ref void* si_call_addr()() { return _sifields._sigsys._call_addr; } - @property ref int si_syscall()() { return _sifields._sigsys._syscall; } - @property ref uint si_arch()() { return _sifields._sigsys._arch; } - } - } - else version (MIPS32) - { - struct siginfo_t - { - int si_signo; // Signal number - int si_errno; // If non-zero, an errno value associated with - // this signal, as defined in - int si_code; // Signal code - - int[__SI_MAX_SIZE / int.sizeof - __SI_PAD_SIZE - 3] __pad0; - - union _sifields_t - { - int[__SI_PAD_SIZE] _pad; - - // kill() - struct _kill_t - { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process - } _kill_t _kill; - - // POSIX.1b timers. - struct _timer_t - { - int si_tid; // Timer ID - int si_overrun; // Overrun count - sigval si_sigval; // Signal value - } _timer_t _timer; - - // POSIX.1b signals - struct _rt_t - { - pid_t si_pid; // Sending process ID - uid_t si_uid; // Real user ID of sending process - sigval si_sigval; // Signal value - } _rt_t _rt; - - // SIGCHLD - struct _sigchild_t - { - pid_t si_pid; // Which child - uid_t si_uid; // Real user ID of sending process - int si_status; // Exit value or signal - clock_t si_utime; - clock_t si_stime; - } _sigchild_t _sigchld; - - // SIGILL, SIGFPE, SIGSEGV, SIGBUS - struct _sigfault_t - { - void* si_addr; // Faulting insn/memory ref - short si_addr_lsb; - } _sigfault_t _sigfault; - - // SIGPOLL - struct _sigpoll_t - { - c_long si_band; // Band event for SIGPOLL; - int si_fd; - } _sigpoll_t _sigpoll; - - // SIGSYS - struct _sigsys_t - { - void* _call_addr; // Calling user insn. - int _syscall; // Triggering system call number. - uint _arch; // AUDIT_ARCH_* of syscall. - } _sigsys_t _sigsys; - - } _sifields_t _sifields; - - nothrow @nogc: - @property ref pid_t si_pid()() { return _sifields._kill.si_pid; } - @property ref uid_t si_uid()() { return _sifields._kill.si_uid; } - @property ref int si_timerid()() { return _sifields._timer.si_tid;} - @property ref int si_overrun()() { return _sifields._timer.si_overrun; } - @property ref int si_status()() { return _sifields._sigchld.si_status; } - @property ref clock_t si_utime()() { return _sifields._sigchld.si_utime; } - @property ref clock_t si_stime()() { return _sifields._sigchld.si_stime; } - @property ref sigval si_value()() { return _sifields._rt.si_sigval; } - @property ref int si_int()() { return _sifields._rt.si_sigval.sival_int; } - @property ref void* si_ptr()() { return _sifields._rt.si_sigval.sival_ptr; } - @property ref void* si_addr()() { return _sifields._sigfault.si_addr; } - @property ref c_long si_band()() { return _sifields._sigpoll.si_band; } - @property ref int si_fd()() { return _sifields._sigpoll.si_fd; } - @property ref void* si_call_addr()() { return _sifields._sigsys._call_addr; } - @property ref int si_syscall()() { return _sifields._sigsys._syscall; } - @property ref uint si_arch()() { return _sifields._sigsys._arch; } - } - } - else - { - static assert(false, "Architecture not supported."); - } - - enum - { - SI_ASYNCNL = -60, - SI_TKILL = -6, - SI_SIGIO, - SI_ASYNCIO, - SI_MESGQ, - SI_TIMER, - SI_QUEUE, - SI_USER, - SI_KERNEL = 0x80 - } - int kill(pid_t, int); int sigaction(int, const scope sigaction_t*, sigaction_t*); int sigaddset(sigset_t*, int); @@ -2256,125 +1896,17 @@ else version (CRuntime_UClibc) enum SIGCLD = SIGCHLD; enum SIGXCPU = 24; enum SIGXFSZ = 25; - enum SIGVTALRM = 26; - enum SIGPROF = 27; - enum SIGWINCH = 28; - enum SIGPOLL = SIGIO; - enum SIGIO = 29; - enum SIGPWR = 30; - enum SIGSYS = 31; - enum SIGUNUSED = 31; - } - else - static assert(0, "unimplemented"); -} -else -{ - static assert(false, "Unsupported platform"); -} - -/* -SA_ONSTACK -SA_RESETHAND -SA_RESTART -SA_SIGINFO -SA_NOCLDWAIT -SA_NODEFER -*/ - -version (linux) -{ - version (MIPS_Any) - { - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 8; - enum SA_NOCLDWAIT = 0x10000; - enum SA_NODEFER = 0x40000000; - } - else - { - enum SA_ONSTACK = 0x08000000; - enum SA_RESETHAND = 0x80000000; - enum SA_RESTART = 0x10000000; - enum SA_SIGINFO = 4; - enum SA_NOCLDWAIT = 2; - enum SA_NODEFER = 0x40000000; - } - - enum SA_NOMASK = SA_NODEFER; - enum SA_ONESHOT = SA_RESETHAND; - enum SA_STACK = SA_ONSTACK; -} -else version (Darwin) -{ - enum SA_ONSTACK = 0x0001; - enum SA_RESETHAND = 0x0004; - enum SA_RESTART = 0x0002; - enum SA_SIGINFO = 0x0040; - enum SA_NOCLDWAIT = 0x0020; - enum SA_NODEFER = 0x0010; -} -else version (FreeBSD) -{ - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } -} -else version (NetBSD) -{ - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } -} -else version (OpenBSD) -{ - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } -} -else version (DragonFlyBSD) -{ - enum - { - SA_ONSTACK = 0x0001, - SA_RESTART = 0x0002, - SA_RESETHAND = 0x0004, - SA_NODEFER = 0x0010, - SA_NOCLDWAIT = 0x0020, - SA_SIGINFO = 0x0040, - } -} -else version (Solaris) -{ - enum - { - SA_ONSTACK = 0x00001, - SA_RESTART = 0x00004, - SA_RESETHAND = 0x00002, - SA_NODEFER = 0x00010, - SA_NOCLDWAIT = 0x10000, - SA_SIGINFO = 0x00008, + enum SIGVTALRM = 26; + enum SIGPROF = 27; + enum SIGWINCH = 28; + enum SIGPOLL = SIGIO; + enum SIGIO = 29; + enum SIGPWR = 30; + enum SIGSYS = 31; + enum SIGUNUSED = 31; } + else + static assert(0, "unimplemented"); } else { @@ -2382,26 +1914,12 @@ else } /* -SS_ONSTACK -SS_DISABLE -MINSIGSTKSZ -SIGSTKSZ - -ucontext_t // from ucontext -mcontext_t // from ucontext - -struct stack_t -{ - void* ss_sp; - size_t ss_size; - int ss_flags; -} - -struct sigstack -{ - int ss_onstack; - void* ss_sp; -} +SA_ONSTACK +SA_RESETHAND +SA_RESTART +SA_SIGINFO +SA_NOCLDWAIT +SA_NODEFER ILL_ILLOPC ILL_ILLOPN @@ -2444,42 +1962,33 @@ POLL_MSG POLL_ERR POLL_PRI POLL_HUP - -sigfn_t bsd_signal(int sig, sigfn_t func); -sigfn_t sigset(int sig, sigfn_t func); - -int killpg(pid_t, int); -int sigaltstack(const scope stack_t*, stack_t*); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); */ -version (CRuntime_Glibc) +version (linux) { - enum SS_ONSTACK = 1; - enum SS_DISABLE = 2; - enum MINSIGSTKSZ = 2048; - enum SIGSTKSZ = 8192; - - //ucontext_t (defined in core.sys.posix.ucontext) - //mcontext_t (defined in core.sys.posix.ucontext) - - struct stack_t + version (MIPS_Any) { - void* ss_sp; - int ss_flags; - size_t ss_size; + enum SA_ONSTACK = 0x08000000; + enum SA_RESETHAND = 0x80000000; + enum SA_RESTART = 0x10000000; + enum SA_SIGINFO = 8; + enum SA_NOCLDWAIT = 0x10000; + enum SA_NODEFER = 0x40000000; } - - struct sigstack + else { - void* ss_sp; - int ss_onstack; + enum SA_ONSTACK = 0x08000000; + enum SA_RESETHAND = 0x80000000; + enum SA_RESTART = 0x10000000; + enum SA_SIGINFO = 4; + enum SA_NOCLDWAIT = 2; + enum SA_NODEFER = 0x40000000; } + enum SA_NOMASK = SA_NODEFER; + enum SA_ONESHOT = SA_RESETHAND; + enum SA_STACK = SA_ONSTACK; + enum { ILL_ILLOPC = 1, @@ -2542,45 +2051,15 @@ version (CRuntime_Glibc) POLL_PRI, POLL_HUP } - - sigfn_t bsd_signal(int sig, sigfn_t func); - sigfn_t sigset(int sig, sigfn_t func); - - nothrow: - @nogc: - sigfn_t2 bsd_signal(int sig, sigfn_t2 func); - sigfn_t2 sigset(int sig, sigfn_t2 func); - - int killpg(pid_t, int); - int sigaltstack(const scope stack_t*, stack_t*); - int sighold(int); - int sigignore(int); - int siginterrupt(int, int); - int sigpause(int); - int sigrelse(int); } else version (Darwin) { - enum SS_ONSTACK = 0x0001; - enum SS_DISABLE = 0x0004; - enum MINSIGSTKSZ = 32768; - enum SIGSTKSZ = 131072; - - //ucontext_t (defined in core.sys.posix.ucontext) - //mcontext_t (defined in core.sys.posix.ucontext) - - struct stack_t - { - void* ss_sp; - size_t ss_size; - int ss_flags; - } - - struct sigstack - { - void* ss_sp; - int ss_onstack; - } + enum SA_ONSTACK = 0x0001; + enum SA_RESETHAND = 0x0004; + enum SA_RESTART = 0x0002; + enum SA_SIGINFO = 0x0040; + enum SA_NOCLDWAIT = 0x0020; + enum SA_NODEFER = 0x0010; enum ILL_ILLOPC = 1; enum ILL_ILLOPN = 4; @@ -2638,48 +2117,167 @@ else version (Darwin) POLL_PRI, POLL_HUP } +} +else version (FreeBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } - sigfn_t bsd_signal(int sig, sigfn_t func); - sigfn_t sigset(int sig, sigfn_t func); + enum + { + ILL_ILLOPC = 1, + ILL_ILLOPN, + ILL_ILLADR, + ILL_ILLTRP, + ILL_PRVOPC, + ILL_PRVREG, + ILL_COPROC, + ILL_BADSTK, + } - nothrow: - @nogc: - sigfn_t2 bsd_signal(int sig, sigfn_t2 func); - sigfn_t2 sigset(int sig, sigfn_t2 func); + enum + { + BUS_ADRALN = 1, + BUS_ADRERR, + BUS_OBJERR, + } - int killpg(pid_t, int); - int sigaltstack(const scope stack_t*, stack_t*); - int sighold(int); - int sigignore(int); - int siginterrupt(int, int); - int sigpause(int); - int sigrelse(int); + enum + { + SEGV_MAPERR = 1, + SEGV_ACCERR, + } + + enum + { + FPE_INTOVF = 1, + FPE_INTDIV, + FPE_FLTDIV, + FPE_FLTOVF, + FPE_FLTUND, + FPE_FLTRES, + FPE_FLTINV, + FPE_FLTSUB, + } + + enum + { + TRAP_BRKPT = 1, + TRAP_TRACE, + } + + enum + { + CLD_EXITED = 1, + CLD_KILLED, + CLD_DUMPED, + CLD_TRAPPED, + CLD_STOPPED, + CLD_CONTINUED, + } + + enum + { + POLL_IN = 1, + POLL_OUT, + POLL_MSG, + POLL_ERR, + POLL_PRI, + POLL_HUP, + } } -else version (FreeBSD) +else version (NetBSD) { enum { - SS_ONSTACK = 0x0001, - SS_DISABLE = 0x0004, + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, + } + + enum + { + ILL_ILLOPC = 1, + ILL_ILLOPN, + ILL_ILLADR, + ILL_ILLTRP, + ILL_PRVOPC, + ILL_PRVREG, + ILL_COPROC, + ILL_BADSTK, + } + + enum + { + BUS_ADRALN = 1, + BUS_ADRERR, + BUS_OBJERR, + } + + enum + { + SEGV_MAPERR = 1, + SEGV_ACCERR, + } + + enum + { + FPE_INTOVF = 1, + FPE_INTDIV, + FPE_FLTDIV, + FPE_FLTOVF, + FPE_FLTUND, + FPE_FLTRES, + FPE_FLTINV, + FPE_FLTSUB, + } + + enum + { + TRAP_BRKPT = 1, + TRAP_TRACE, } - enum MINSIGSTKSZ = 512 * 4; - enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - - //ucontext_t (defined in core.sys.posix.ucontext) - //mcontext_t (defined in core.sys.posix.ucontext) - - struct stack_t + enum { - void* ss_sp; - size_t ss_size; - int ss_flags; + CLD_EXITED = 1, + CLD_KILLED, + CLD_DUMPED, + CLD_TRAPPED, + CLD_STOPPED, + CLD_CONTINUED, } - struct sigstack + enum { - void* ss_sp; - int ss_onstack; + POLL_IN = 1, + POLL_OUT, + POLL_MSG, + POLL_ERR, + POLL_PRI, + POLL_HUP, + } +} +else version (OpenBSD) +{ + enum + { + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, } enum @@ -2692,6 +2290,7 @@ else version (FreeBSD) ILL_PRVREG, ILL_COPROC, ILL_BADSTK, + NSIGILL = ILL_BADSTK, } enum @@ -2699,30 +2298,34 @@ else version (FreeBSD) BUS_ADRALN = 1, BUS_ADRERR, BUS_OBJERR, + NSIGBUS = BUS_OBJERR, } enum { SEGV_MAPERR = 1, SEGV_ACCERR, + NSIGSEGV = SEGV_ACCERR, } enum { - FPE_INTOVF = 1, - FPE_INTDIV, + FPE_INTDIV = 1, + FPE_INTOVF, FPE_FLTDIV, FPE_FLTOVF, FPE_FLTUND, FPE_FLTRES, FPE_FLTINV, FPE_FLTSUB, + NSIGFPE = FPE_FLTSUB, } enum { TRAP_BRKPT = 1, TRAP_TRACE, + NSIGTRAP = TRAP_TRACE, } enum @@ -2733,6 +2336,7 @@ else version (FreeBSD) CLD_TRAPPED, CLD_STOPPED, CLD_CONTINUED, + NSIGCLD = CLD_CONTINUED, } enum @@ -2743,49 +2347,19 @@ else version (FreeBSD) POLL_ERR, POLL_PRI, POLL_HUP, + NSIGPOLL = POLL_HUP, } - - //sigfn_t bsd_signal(int sig, sigfn_t func); - sigfn_t sigset(int sig, sigfn_t func); - - nothrow: - @nogc: - //sigfn_t2 bsd_signal(int sig, sigfn_t2 func); - sigfn_t2 sigset(int sig, sigfn_t2 func); - - int killpg(pid_t, int); - int sigaltstack(const scope stack_t*, stack_t*); - int sighold(int); - int sigignore(int); - int siginterrupt(int, int); - int sigpause(int); - int sigrelse(int); } -else version (NetBSD) +else version (DragonFlyBSD) { enum { - SS_ONSTACK = 0x0001, - SS_DISABLE = 0x0004, - } - - enum MINSIGSTKSZ = 8192; - enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - - //ucontext_t (defined in core.sys.posix.ucontext) - //mcontext_t (defined in core.sys.posix.ucontext) - - struct stack_t - { - void* ss_sp; - size_t ss_size; - int ss_flags; - } - - struct sigstack - { - void* ss_sp; - int ss_onstack; + SA_ONSTACK = 0x0001, + SA_RESTART = 0x0002, + SA_RESETHAND = 0x0004, + SA_NODEFER = 0x0010, + SA_NOCLDWAIT = 0x0020, + SA_SIGINFO = 0x0040, } enum @@ -2850,42 +2424,17 @@ else version (NetBSD) POLL_PRI, POLL_HUP, } - - //sigfn_t bsd_signal(int sig, sigfn_t func); - sigfn_t sigset(int sig, sigfn_t func); - - nothrow: - @nogc: - //sigfn_t2 bsd_signal(int sig, sigfn_t2 func); - sigfn_t2 sigset(int sig, sigfn_t2 func); - - int killpg(pid_t, int); - int sigaltstack(const scope stack_t*, stack_t*); - int sighold(int); - int sigignore(int); - int siginterrupt(int, int); - int sigpause(int); - int sigrelse(int); } -else version (OpenBSD) +else version (Solaris) { enum { - SS_ONSTACK = 0x0001, - SS_DISABLE = 0x0004, - } - - enum MINSIGSTKSZ = 8192; - enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - - //ucontext_t (defined in core.sys.posix.ucontext) - //mcontext_t (defined in core.sys.posix.ucontext) - - struct stack_t - { - void* ss_sp; - size_t ss_size; - int ss_flags; + SA_ONSTACK = 0x00001, + SA_RESTART = 0x00004, + SA_RESETHAND = 0x00002, + SA_NODEFER = 0x00010, + SA_NOCLDWAIT = 0x10000, + SA_SIGINFO = 0x00008, } enum @@ -2898,7 +2447,6 @@ else version (OpenBSD) ILL_PRVREG, ILL_COPROC, ILL_BADSTK, - NSIGILL = ILL_BADSTK, } enum @@ -2906,14 +2454,12 @@ else version (OpenBSD) BUS_ADRALN = 1, BUS_ADRERR, BUS_OBJERR, - NSIGBUS = BUS_OBJERR, } enum { SEGV_MAPERR = 1, SEGV_ACCERR, - NSIGSEGV = SEGV_ACCERR, } enum @@ -2926,14 +2472,17 @@ else version (OpenBSD) FPE_FLTRES, FPE_FLTINV, FPE_FLTSUB, - NSIGFPE = FPE_FLTSUB, + FPE_FLTDEN, } enum { TRAP_BRKPT = 1, TRAP_TRACE, - NSIGTRAP = TRAP_TRACE, + TRAP_RWATCH, + TRAP_WWATCH, + TRAP_XWATCH, + TRAP_DTRACE, } enum @@ -2944,28 +2493,136 @@ else version (OpenBSD) CLD_TRAPPED, CLD_STOPPED, CLD_CONTINUED, - NSIGCLD = CLD_CONTINUED, } enum { - POLL_IN = 1, - POLL_OUT, - POLL_MSG, - POLL_ERR, - POLL_PRI, - POLL_HUP, - NSIGPOLL = POLL_HUP, + POLL_IN = 1, + POLL_OUT, + POLL_MSG, + POLL_ERR, + POLL_PRI, + POLL_HUP, + } +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +SS_ONSTACK +SS_DISABLE +MINSIGSTKSZ +SIGSTKSZ + +ucontext_t // from ucontext +mcontext_t // from ucontext + +struct stack_t +{ + void* ss_sp; + size_t ss_size; + int ss_flags; +} + +struct sigstack +{ + int ss_onstack; + void* ss_sp; +} + +sigfn_t bsd_signal(int sig, sigfn_t func); +sigfn_t sigset(int sig, sigfn_t func); + +int killpg(pid_t, int); +int sigaltstack(const scope stack_t*, stack_t*); +int sighold(int); +int sigignore(int); +int siginterrupt(int, int); +int sigpause(int); +int sigrelse(int); +*/ + +version (CRuntime_Glibc) +{ + enum SS_ONSTACK = 1; + enum SS_DISABLE = 2; + enum MINSIGSTKSZ = 2048; + enum SIGSTKSZ = 8192; + + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) + + struct stack_t + { + void* ss_sp; + int ss_flags; + size_t ss_size; + } + + struct sigstack + { + void* ss_sp; + int ss_onstack; + } + + sigfn_t bsd_signal(int sig, sigfn_t func); + sigfn_t sigset(int sig, sigfn_t func); + + nothrow: + @nogc: + sigfn_t2 bsd_signal(int sig, sigfn_t2 func); + sigfn_t2 sigset(int sig, sigfn_t2 func); + + int killpg(pid_t, int); + int sigaltstack(const scope stack_t*, stack_t*); + int sighold(int); + int sigignore(int); + int siginterrupt(int, int); + int sigpause(int); + int sigrelse(int); +} +else version (Darwin) +{ + enum SS_ONSTACK = 0x0001; + enum SS_DISABLE = 0x0004; + enum MINSIGSTKSZ = 32768; + enum SIGSTKSZ = 131072; + + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) + + struct stack_t + { + void* ss_sp; + size_t ss_size; + int ss_flags; + } + + struct sigstack + { + void* ss_sp; + int ss_onstack; } + sigfn_t bsd_signal(int sig, sigfn_t func); + sigfn_t sigset(int sig, sigfn_t func); + nothrow: @nogc: + sigfn_t2 bsd_signal(int sig, sigfn_t2 func); + sigfn_t2 sigset(int sig, sigfn_t2 func); + int killpg(pid_t, int); int sigaltstack(const scope stack_t*, stack_t*); + int sighold(int); + int sigignore(int); int siginterrupt(int, int); int sigpause(int); + int sigrelse(int); } -else version (DragonFlyBSD) +else version (FreeBSD) { enum { @@ -2973,7 +2630,7 @@ else version (DragonFlyBSD) SS_DISABLE = 0x0004, } - enum MINSIGSTKSZ = 8192; + enum MINSIGSTKSZ = 512 * 4; enum SIGSTKSZ = (MINSIGSTKSZ + 32768); //ucontext_t (defined in core.sys.posix.ucontext) @@ -2992,67 +2649,47 @@ else version (DragonFlyBSD) int ss_onstack; } - enum - { - ILL_ILLOPC = 1, - ILL_ILLOPN, - ILL_ILLADR, - ILL_ILLTRP, - ILL_PRVOPC, - ILL_PRVREG, - ILL_COPROC, - ILL_BADSTK, - } + //sigfn_t bsd_signal(int sig, sigfn_t func); + sigfn_t sigset(int sig, sigfn_t func); - enum - { - BUS_ADRALN = 1, - BUS_ADRERR, - BUS_OBJERR, - } + nothrow: + @nogc: + //sigfn_t2 bsd_signal(int sig, sigfn_t2 func); + sigfn_t2 sigset(int sig, sigfn_t2 func); + int killpg(pid_t, int); + int sigaltstack(const scope stack_t*, stack_t*); + int sighold(int); + int sigignore(int); + int siginterrupt(int, int); + int sigpause(int); + int sigrelse(int); +} +else version (NetBSD) +{ enum { - SEGV_MAPERR = 1, - SEGV_ACCERR, + SS_ONSTACK = 0x0001, + SS_DISABLE = 0x0004, } - enum - { - FPE_INTOVF = 1, - FPE_INTDIV, - FPE_FLTDIV, - FPE_FLTOVF, - FPE_FLTUND, - FPE_FLTRES, - FPE_FLTINV, - FPE_FLTSUB, - } + enum MINSIGSTKSZ = 8192; + enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - enum - { - TRAP_BRKPT = 1, - TRAP_TRACE, - } + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) - enum + struct stack_t { - CLD_EXITED = 1, - CLD_KILLED, - CLD_DUMPED, - CLD_TRAPPED, - CLD_STOPPED, - CLD_CONTINUED, + void* ss_sp; + size_t ss_size; + int ss_flags; } - enum + struct sigstack { - POLL_IN = 1, - POLL_OUT, - POLL_MSG, - POLL_ERR, - POLL_PRI, - POLL_HUP, + void* ss_sp; + int ss_onstack; } //sigfn_t bsd_signal(int sig, sigfn_t func); @@ -3071,102 +2708,67 @@ else version (DragonFlyBSD) int sigpause(int); int sigrelse(int); } -else version (Solaris) +else version (OpenBSD) { enum { SS_ONSTACK = 0x0001, - SS_DISABLE = 0x0002, - } - - enum MINSIGSTKSZ = 2048; - enum SIGSTKSZ = 8192; - - struct stack_t - { - void* ss_sp; - size_t ss_size; - int ss_flags; + SS_DISABLE = 0x0004, } - struct sigstack - { - void* ss_sp; - int ss_onstack; - } + enum MINSIGSTKSZ = 8192; + enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - enum - { - ILL_ILLOPC = 1, - ILL_ILLOPN, - ILL_ILLADR, - ILL_ILLTRP, - ILL_PRVOPC, - ILL_PRVREG, - ILL_COPROC, - ILL_BADSTK, - } + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) - enum + struct stack_t { - BUS_ADRALN = 1, - BUS_ADRERR, - BUS_OBJERR, + void* ss_sp; + size_t ss_size; + int ss_flags; } + nothrow: + @nogc: + int killpg(pid_t, int); + int sigaltstack(const scope stack_t*, stack_t*); + int siginterrupt(int, int); + int sigpause(int); +} +else version (DragonFlyBSD) +{ enum { - SEGV_MAPERR = 1, - SEGV_ACCERR, + SS_ONSTACK = 0x0001, + SS_DISABLE = 0x0004, } - enum - { - FPE_INTDIV = 1, - FPE_INTOVF, - FPE_FLTDIV, - FPE_FLTOVF, - FPE_FLTUND, - FPE_FLTRES, - FPE_FLTINV, - FPE_FLTSUB, - FPE_FLTDEN, - } + enum MINSIGSTKSZ = 8192; + enum SIGSTKSZ = (MINSIGSTKSZ + 32768); - enum - { - TRAP_BRKPT = 1, - TRAP_TRACE, - TRAP_RWATCH, - TRAP_WWATCH, - TRAP_XWATCH, - TRAP_DTRACE, - } + //ucontext_t (defined in core.sys.posix.ucontext) + //mcontext_t (defined in core.sys.posix.ucontext) - enum + struct stack_t { - CLD_EXITED = 1, - CLD_KILLED, - CLD_DUMPED, - CLD_TRAPPED, - CLD_STOPPED, - CLD_CONTINUED, + void* ss_sp; + size_t ss_size; + int ss_flags; } - enum + struct sigstack { - POLL_IN = 1, - POLL_OUT, - POLL_MSG, - POLL_ERR, - POLL_PRI, - POLL_HUP, + void* ss_sp; + int ss_onstack; } + //sigfn_t bsd_signal(int sig, sigfn_t func); sigfn_t sigset(int sig, sigfn_t func); nothrow: @nogc: + //sigfn_t2 bsd_signal(int sig, sigfn_t2 func); sigfn_t2 sigset(int sig, sigfn_t2 func); int killpg(pid_t, int); @@ -3177,81 +2779,56 @@ else version (Solaris) int sigpause(int); int sigrelse(int); } -else version (CRuntime_Bionic) +else version (Solaris) { - enum SS_ONSTACK = 1; - enum SS_DISABLE = 2; - enum MINSIGSTKSZ = 2048; - enum SIGSTKSZ = 8192; - - struct stack_t - { - void* ss_sp; - int ss_flags; - size_t ss_size; - } - - enum - { - ILL_ILLOPC = 1, - ILL_ILLOPN, - ILL_ILLADR, - ILL_ILLTRP, - ILL_PRVOPC, - ILL_PRVREG, - ILL_COPROC, - ILL_BADSTK - } - - enum - { - FPE_INTDIV = 1, - FPE_INTOVF, - FPE_FLTDIV, - FPE_FLTOVF, - FPE_FLTUND, - FPE_FLTRES, - FPE_FLTINV, - FPE_FLTSUB - } - enum { - SEGV_MAPERR = 1, - SEGV_ACCERR + SS_ONSTACK = 0x0001, + SS_DISABLE = 0x0002, } - enum - { - BUS_ADRALN = 1, - BUS_ADRERR, - BUS_OBJERR - } + enum MINSIGSTKSZ = 2048; + enum SIGSTKSZ = 8192; - enum + struct stack_t { - TRAP_BRKPT = 1, - TRAP_TRACE + void* ss_sp; + size_t ss_size; + int ss_flags; } - enum + struct sigstack { - CLD_EXITED = 1, - CLD_KILLED, - CLD_DUMPED, - CLD_TRAPPED, - CLD_STOPPED, - CLD_CONTINUED + void* ss_sp; + int ss_onstack; } - enum + sigfn_t sigset(int sig, sigfn_t func); + + nothrow: + @nogc: + sigfn_t2 sigset(int sig, sigfn_t2 func); + + int killpg(pid_t, int); + int sigaltstack(const scope stack_t*, stack_t*); + int sighold(int); + int sigignore(int); + int siginterrupt(int, int); + int sigpause(int); + int sigrelse(int); +} +else version (CRuntime_Bionic) +{ + enum SS_ONSTACK = 1; + enum SS_DISABLE = 2; + enum MINSIGSTKSZ = 2048; + enum SIGSTKSZ = 8192; + + struct stack_t { - POLL_IN = 1, - POLL_OUT, - POLL_MSG, - POLL_ERR, - POLL_PRI, - POLL_HUP + void* ss_sp; + int ss_flags; + size_t ss_size; } sigfn_t bsd_signal(int, sigfn_t); @@ -3324,69 +2901,6 @@ else version (CRuntime_Musl) } } - enum - { - ILL_ILLOPC = 1, - ILL_ILLOPN, - ILL_ILLADR, - ILL_ILLTRP, - ILL_PRVOPC, - ILL_PRVREG, - ILL_COPROC, - ILL_BADSTK - } - - enum - { - FPE_INTDIV = 1, - FPE_INTOVF, - FPE_FLTDIV, - FPE_FLTOVF, - FPE_FLTUND, - FPE_FLTRES, - FPE_FLTINV, - FPE_FLTSUB - } - - enum - { - SEGV_MAPERR = 1, - SEGV_ACCERR - } - - enum - { - BUS_ADRALN = 1, - BUS_ADRERR, - BUS_OBJERR - } - - enum - { - TRAP_BRKPT = 1, - TRAP_TRACE - } - - enum - { - CLD_EXITED = 1, - CLD_KILLED, - CLD_DUMPED, - CLD_TRAPPED, - CLD_STOPPED, - CLD_CONTINUED - } - - enum - { - POLL_IN = 1, - POLL_OUT, - POLL_MSG, - POLL_ERR, - POLL_PRI, - POLL_HUP - } - sigfn_t bsd_signal(int sig, sigfn_t func); sigfn_t sigset(int sig, sigfn_t func); @@ -3435,76 +2949,6 @@ else version (CRuntime_UClibc) int ss_onstack; } - // `si_code' values for SIGILL signal. - enum - { - ILL_ILLOPC = 1, // Illegal opcode. - ILL_ILLOPN, // Illegal operand. - ILL_ILLADR, // Illegal addressing mode. - ILL_ILLTRP, // Illegal trap. - ILL_PRVOPC, // Privileged opcode. - ILL_PRVREG, // Privileged register. - ILL_COPROC, // Coprocessor error. - ILL_BADSTK // Internal stack error. - } - - // `si_code' values for SIGFPE signal. - enum - { - FPE_INTDIV = 1, // Integer divide by zero. - FPE_INTOVF, // Integer overflow. - FPE_FLTDIV, // Floating point divide by zero. - FPE_FLTOVF, // Floating point overflow. - FPE_FLTUND, // Floating point underflow. - FPE_FLTRES, // Floating point inexact result. - FPE_FLTINV, // Floating point invalid operation. - FPE_FLTSUB // Subscript out of range. - } - - // `si_code' values for SIGSEGV signal. - enum - { - SEGV_MAPERR = 1, // Address not mapped to object. - SEGV_ACCERR // Invalid permissions for mapped object. - } - - // `si_code' values for SIGBUS signal. - enum - { - BUS_ADRALN = 1, // Invalid address alignment. - BUS_ADRERR, // Non-existant physical address. - BUS_OBJERR // Object specific hardware error. - } - - // `si_code' values for SIGTRAP signal. - enum - { - TRAP_BRKPT = 1, // Process breakpoint. - TRAP_TRACE // Process trace trap. - } - - // `si_code' values for SIGCHLD signal. - enum - { - CLD_EXITED = 1, // Child has exited. - CLD_KILLED, // Child was killed. - CLD_DUMPED, // Child terminated abnormally. - CLD_TRAPPED, // Traced child has trapped. - CLD_STOPPED, // Child has stopped. - CLD_CONTINUED // Stopped child has continued. - } - - // `si_code' values for SIGPOLL signal. - enum - { - POLL_IN = 1, // Data input available. - POLL_OUT, // Output buffers available. - POLL_MSG, // Input message available. - POLL_ERR, // I/O error. - POLL_PRI, // High priority input available. - POLL_HUP // Device disconnected. - } - sigfn_t sigset(int sig, sigfn_t func); nothrow: @@ -3613,16 +3057,12 @@ struct sigevent void(*)(sigval) sigev_notify_function; pthread_attr_t* sigev_notify_attributes; } - -int sigqueue(pid_t, int, const sigval); -int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); -int sigwaitinfo(const scope sigset_t*, siginfo_t*); */ nothrow: @nogc: -version (CRuntime_Glibc) +version (linux) { private enum __SIGEV_MAX_SIZE = 64; @@ -3641,22 +3081,18 @@ version (CRuntime_Glibc) int sigev_signo; int sigev_notify; - union _sigev_un_t + union { int[__SIGEV_PAD_SIZE] _pad; pid_t _tid; - struct _sigev_thread_t + struct { - void function(sigval) _function; - void* _attribute; - } _sigev_thread_t _sigev_thread; - } _sigev_un_t _sigev_un; + void function(sigval) sigev_notify_function; + void* sigev_notify_attributes; + } + } } - - int sigqueue(pid_t, int, const sigval); - int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); - int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (FreeBSD) { @@ -3665,21 +3101,17 @@ else version (FreeBSD) int sigev_notify; int sigev_signo; sigval sigev_value; - union _sigev_un + union { lwpid_t _threadid; - struct _sigev_thread + struct { - void function(sigval) _function; - void* _attribute; + void function(sigval) sigev_notify_function; + void* sigev_notify_attributes; } c_long[8] __spare__; } } - - int sigqueue(pid_t, int, const sigval); - int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); - int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (NetBSD) { @@ -3691,10 +3123,6 @@ else version (NetBSD) void function(sigval) sigev_notify_function; void /* pthread_attr_t */*sigev_notify_attributes; } - - int sigqueue(pid_t, int, const sigval); - int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); - int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (OpenBSD) { @@ -3723,10 +3151,6 @@ else version (DragonFlyBSD) _sigval_t sigev_value; void function(_sigval_t) sigev_notify_function; } - - int sigqueue(pid_t, int, const sigval); - int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); - int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (Darwin) { @@ -3750,84 +3174,68 @@ else version (Solaris) pthread_attr_t* sigev_notify_attributes; int __sigev_pad2; } +} +else +{ + static assert(false, "Unsupported platform"); +} + +/* +int sigqueue(pid_t, int, const sigval); +int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); +int sigwaitinfo(const scope sigset_t*, siginfo_t*); +*/ + +nothrow: +@nogc: +version (CRuntime_Glibc) +{ + int sigqueue(pid_t, int, const sigval); + int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); + int sigwaitinfo(const scope sigset_t*, siginfo_t*); +} +else version (FreeBSD) +{ + int sigqueue(pid_t, int, const sigval); + int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); + int sigwaitinfo(const scope sigset_t*, siginfo_t*); +} +else version (NetBSD) +{ + int sigqueue(pid_t, int, const sigval); + int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); + int sigwaitinfo(const scope sigset_t*, siginfo_t*); +} +else version (OpenBSD) +{ +} +else version (DragonFlyBSD) +{ + int sigqueue(pid_t, int, const sigval); + int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); + int sigwaitinfo(const scope sigset_t*, siginfo_t*); +} +else version (Darwin) +{ +} +else version (Solaris) +{ int sigqueue(pid_t, int, const sigval); int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (CRuntime_Bionic) { - private enum __ARCH_SIGEV_PREAMBLE_SIZE = (int.sizeof * 2) + sigval.sizeof; - private enum SIGEV_MAX_SIZE = 64; - private enum SIGEV_PAD_SIZE = (SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) - / int.sizeof; - - struct sigevent - { - sigval sigev_value; - int sigev_signo; - int sigev_notify; - - union _sigev_un_t - { - int[SIGEV_PAD_SIZE] _pad; - int _tid; - - struct _sigev_thread_t - { - void function(sigval) _function; - void* _attribute; - } _sigev_thread_t _sigev_thread; - } _sigev_un_t _sigev_un; - } } else version (CRuntime_Musl) { - struct sigevent - { - sigval sigev_value; - int sigev_signo; - int sigev_notify; - void function(sigval) sigev_notify_function; - pthread_attr_t *sigev_notify_attributes; - char[56 - 3 * c_long.sizeof] __pad = void; - } + int sigqueue(pid_t, int, const sigval); + int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); + int sigwaitinfo(const scope sigset_t*, siginfo_t*); } else version (CRuntime_UClibc) { - private enum __SIGEV_MAX_SIZE = 64; - - static if ( __WORDSIZE == 64 ) - { - private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 4); - } - else - { - private enum __SIGEV_PAD_SIZE = ((__SIGEV_MAX_SIZE / int.sizeof) - 3); - } - - struct sigevent - { - sigval sigev_value; - int sigev_signo; - int sigev_notify; - - union _sigev_un_t - { - int[__SIGEV_PAD_SIZE] _pad; - pid_t _tid; - - struct _sigev_thread_t - { - void function(sigval) _function; - void* _attribute; - } _sigev_thread_t _sigev_thread; - } _sigev_un_t _sigev_un; - } - - @property void function(sigval) sigev_notify_function(ref sigevent _sigevent) { return _sigevent._sigev_un._sigev_thread._function; } - @property void* sigev_notify_attributes(ref sigevent _sigevent) { return _sigevent._sigev_un._sigev_thread._attribute; } - int sigqueue(pid_t, int, const sigval); int sigtimedwait(const scope sigset_t*, siginfo_t*, const scope timespec*); int sigwaitinfo(const scope sigset_t*, siginfo_t*); From a311c6ed53a7058fde8080fc46732e564f597b1c Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 20 Jan 2022 16:56:10 +0100 Subject: [PATCH 3/4] Issue 22689: core.sys.posix.signal: Separate OS-specific signum flags from C runtime functions --- src/core/sys/posix/signal.d | 353 ++++++++++++------------------------ 1 file changed, 121 insertions(+), 232 deletions(-) diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index babd652f11b..951265944e9 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -151,13 +151,15 @@ version (Solaris) return sig; } } -else version (FreeBSD) { +else version (FreeBSD) +{ // Note: it appears that FreeBSD (prior to 7) and OSX do not support realtime signals // https://github.com/freebsd/freebsd/blob/e79c62ff68fc74d88cb6f479859f6fae9baa5101/sys/sys/signal.h#L117 enum SIGRTMIN = 65; enum SIGRTMAX = 126; } -else version (DragonFlyBSD) { +else version (DragonFlyBSD) +{ enum SIGRTMIN = 35; enum SIGRTMAX = 126; } @@ -831,8 +833,6 @@ else // C Extension (CX) // /* -SIG_HOLD - sigset_t pid_t (defined in core.sys.types) @@ -849,8 +849,6 @@ nothrow @nogc version (CRuntime_Glibc) { - enum SIG_HOLD = cast(sigfn_t2) 1; - private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof); struct sigset_t @@ -860,14 +858,10 @@ version (CRuntime_Glibc) } else version (Darwin) { - enum SIG_HOLD = cast(sigfn_t2) 5; - alias uint sigset_t; } else version (FreeBSD) { - enum SIG_HOLD = cast(sigfn_t2) 3; - struct sigset_t { uint[4] __bits; @@ -875,8 +869,6 @@ else version (FreeBSD) } else version (NetBSD) { - enum SIG_HOLD = cast(sigfn_t2) 3; - struct sigset_t { uint[4] __bits; @@ -884,16 +876,10 @@ else version (NetBSD) } else version (OpenBSD) { - enum SIG_CATCH = cast(sigfn_t2) 2; - enum SIG_HOLD = cast(sigfn_t2) 3; - alias sigset_t = uint; } else version (DragonFlyBSD) { - enum SIG_CATCH = cast(sigfn_t2) 2; - enum SIG_HOLD = cast(sigfn_t2) 3; - struct sigset_t { uint[4] __bits; @@ -901,8 +887,6 @@ else version (DragonFlyBSD) } else version (Solaris) { - enum SIG_HOLD = cast(sigfn_t2)2; - struct sigset_t { uint[4] __bits; @@ -930,8 +914,6 @@ else version (CRuntime_Musl) } else version (CRuntime_UClibc) { - enum SIG_HOLD = cast(sigfn_t2) 2; - version (MIPS32) private enum _SIGSET_NWORDS = 128 / (8 * c_ulong.sizeof); else @@ -948,6 +930,8 @@ else } /* +SIG_HOLD + SA_NOCLDSTOP (CX|XSI) SIG_BLOCK SIG_UNBLOCK @@ -982,6 +966,8 @@ SI_MESGQ version (linux) { + enum SIG_HOLD = cast(sigfn_t2) 2; + enum SA_NOCLDSTOP = 1; // (CX|XSI) version (MIPS_Any) @@ -1102,6 +1088,8 @@ version (linux) } else version (Darwin) { + enum SIG_HOLD = cast(sigfn_t2) 5; + enum SA_NOCLDSTOP = 8; // (CX|XSI) enum SIG_BLOCK = 1; @@ -1130,6 +1118,8 @@ else version (Darwin) } else version (FreeBSD) { + enum SIG_HOLD = cast(sigfn_t2) 3; + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1189,6 +1179,8 @@ else version (FreeBSD) } else version (NetBSD) { + enum SIG_HOLD = cast(sigfn_t2) 3; + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1256,6 +1248,9 @@ else version (NetBSD) } else version (OpenBSD) { + enum SIG_CATCH = cast(sigfn_t2) 2; + enum SIG_HOLD = cast(sigfn_t2) 3; + enum SA_NOCLDSTOP = 0x0008; enum SIG_BLOCK = 1; @@ -1315,6 +1310,9 @@ else version (OpenBSD) } else version (DragonFlyBSD) { + enum SIG_CATCH = cast(sigfn_t2) 2; + enum SIG_HOLD = cast(sigfn_t2) 3; + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1344,6 +1342,8 @@ else version (DragonFlyBSD) } else version (Solaris) { + enum SIG_HOLD = cast(sigfn_t2)2; + enum SIG_BLOCK = 1; enum SIG_UNBLOCK = 2; enum SIG_SETMASK = 3; @@ -1561,8 +1561,6 @@ else version (DragonFlyBSD) } else version (Solaris) { - enum SIGIO = SIGPOLL; - int kill(pid_t, int); int sigaction(int, const scope sigaction_t*, sigaction_t*); int sigaddset(sigset_t*, int); @@ -1672,9 +1670,58 @@ SIGTRAP SIGVTALRM SIGXCPU SIGXFSZ + +SA_ONSTACK +SA_RESETHAND +SA_RESTART +SA_SIGINFO +SA_NOCLDWAIT +SA_NODEFER + +ILL_ILLOPC +ILL_ILLOPN +ILL_ILLADR +ILL_ILLTRP +ILL_PRVOPC +ILL_PRVREG +ILL_COPROC +ILL_BADSTK + +FPE_INTDIV +FPE_INTOVF +FPE_FLTDIV +FPE_FLTOVF +FPE_FLTUND +FPE_FLTRES +FPE_FLTINV +FPE_FLTSUB + +SEGV_MAPERR +SEGV_ACCERR + +BUS_ADRALN +BUS_ADRERR +BUS_OBJERR + +TRAP_BRKPT +TRAP_TRACE + +CLD_EXITED +CLD_KILLED +CLD_DUMPED +CLD_TRAPPED +CLD_STOPPED +CLD_CONTINUED + +POLL_IN +POLL_OUT +POLL_MSG +POLL_ERR +POLL_PRI +POLL_HUP */ -version (CRuntime_Glibc) +version (linux) { version (X86_Any) { @@ -1758,214 +1805,7 @@ version (CRuntime_Glibc) } else static assert(0, "unimplemented"); -} -else version (Darwin) -{ - enum SIGPOLL = 7; - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (FreeBSD) -{ - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (NetBSD) -{ - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (OpenBSD) -{ - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (DragonFlyBSD) -{ - // No SIGPOLL on *BSD - enum SIGPROF = 27; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (Solaris) -{ - enum SIGPOLL = 22; - enum SIGPROF = 29; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 28; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; -} -else version (CRuntime_Bionic) -{ - enum SIGPOLL = 29; - enum SIGPROF = 27; - enum SIGSYS = 31; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; -} -else version (CRuntime_Musl) -{ - version (MIPS_Any) - { - enum SIGPOLL = 22; - enum SIGPROF = 29; - enum SIGSYS = 12; - enum SIGTRAP = 5; - enum SIGVTALRM = 28; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; - } - else - { - enum SIGPOLL = 29; - enum SIGPROF = 27; - enum SIGSYS = 31; - enum SIGTRAP = 5; - enum SIGVTALRM = 26; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - } -} -else version (CRuntime_UClibc) -{ - version (X86_64) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGSTKFLT = 16; - enum SIGCLD = SIGCHLD; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - enum SIGVTALRM = 26; - enum SIGPROF = 27; - enum SIGWINCH = 28; - enum SIGPOLL = SIGIO; - enum SIGIO = 29; - enum SIGPWR = 30; - enum SIGSYS = 31; - enum SIGUNUSED = 31; - } - else version (MIPS32) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGEMT = 7; - enum SIGFPE = 8; - enum SIGSYS = 12; - enum SIGCLD = SIGCHLD; - enum SIGPWR = 19; - enum SIGWINCH = 20; - enum SIGIO = 22; - enum SIGPOLL = SIGIO; - enum SIGVTALRM = 28; - enum SIGPROF = 29; - enum SIGXCPU = 30; - enum SIGXFSZ = 31; - } - else version (ARM) - { - enum SIGTRAP = 5; - enum SIGIOT = 6; - enum SIGSTKFLT = 16; - enum SIGCLD = SIGCHLD; - enum SIGXCPU = 24; - enum SIGXFSZ = 25; - enum SIGVTALRM = 26; - enum SIGPROF = 27; - enum SIGWINCH = 28; - enum SIGPOLL = SIGIO; - enum SIGIO = 29; - enum SIGPWR = 30; - enum SIGSYS = 31; - enum SIGUNUSED = 31; - } - else - static assert(0, "unimplemented"); -} -else -{ - static assert(false, "Unsupported platform"); -} - -/* -SA_ONSTACK -SA_RESETHAND -SA_RESTART -SA_SIGINFO -SA_NOCLDWAIT -SA_NODEFER -ILL_ILLOPC -ILL_ILLOPN -ILL_ILLADR -ILL_ILLTRP -ILL_PRVOPC -ILL_PRVREG -ILL_COPROC -ILL_BADSTK - -FPE_INTDIV -FPE_INTOVF -FPE_FLTDIV -FPE_FLTOVF -FPE_FLTUND -FPE_FLTRES -FPE_FLTINV -FPE_FLTSUB - -SEGV_MAPERR -SEGV_ACCERR - -BUS_ADRALN -BUS_ADRERR -BUS_OBJERR - -TRAP_BRKPT -TRAP_TRACE - -CLD_EXITED -CLD_KILLED -CLD_DUMPED -CLD_TRAPPED -CLD_STOPPED -CLD_CONTINUED - -POLL_IN -POLL_OUT -POLL_MSG -POLL_ERR -POLL_PRI -POLL_HUP -*/ - -version (linux) -{ version (MIPS_Any) { enum SA_ONSTACK = 0x08000000; @@ -2054,6 +1894,14 @@ version (linux) } else version (Darwin) { + enum SIGPOLL = 7; + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum SA_ONSTACK = 0x0001; enum SA_RESETHAND = 0x0004; enum SA_RESTART = 0x0002; @@ -2120,6 +1968,14 @@ else version (Darwin) } else version (FreeBSD) { + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum { SA_ONSTACK = 0x0001, @@ -2195,6 +2051,14 @@ else version (FreeBSD) } else version (NetBSD) { + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum { SA_ONSTACK = 0x0001, @@ -2270,6 +2134,14 @@ else version (NetBSD) } else version (OpenBSD) { + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum { SA_ONSTACK = 0x0001, @@ -2352,6 +2224,14 @@ else version (OpenBSD) } else version (DragonFlyBSD) { + // No SIGPOLL on *BSD + enum SIGPROF = 27; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 26; + enum SIGXCPU = 24; + enum SIGXFSZ = 25; + enum { SA_ONSTACK = 0x0001, @@ -2427,6 +2307,15 @@ else version (DragonFlyBSD) } else version (Solaris) { + enum SIGPOLL = 22; + enum SIGIO = SIGPOLL; + enum SIGPROF = 29; + enum SIGSYS = 12; + enum SIGTRAP = 5; + enum SIGVTALRM = 28; + enum SIGXCPU = 30; + enum SIGXFSZ = 31; + enum { SA_ONSTACK = 0x00001, From 8c3de4fda378aac04a43f11ed7117cf3e8f8b39c Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 20 Jan 2022 17:36:22 +0100 Subject: [PATCH 4/4] Issue 22689: core.sys.posix.signal: Separate OS-specific sigset types from C runtime functions --- src/core/sys/posix/signal.d | 125 +++++++++++------------------------- 1 file changed, 36 insertions(+), 89 deletions(-) diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index 951265944e9..68aee980ef3 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -833,6 +833,8 @@ else // C Extension (CX) // /* +SIG_HOLD + sigset_t pid_t (defined in core.sys.types) @@ -842,95 +844,6 @@ SIGILL (defined in core.stdc.signal) SIGINT (defined in core.stdc.signal) SIGSEGV (defined in core.stdc.signal) SIGTERM (defined in core.stdc.signal) -*/ - -nothrow @nogc -{ - -version (CRuntime_Glibc) -{ - private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof); - - struct sigset_t - { - c_ulong[_SIGSET_NWORDS] __val; - } -} -else version (Darwin) -{ - alias uint sigset_t; -} -else version (FreeBSD) -{ - struct sigset_t - { - uint[4] __bits; - } -} -else version (NetBSD) -{ - struct sigset_t - { - uint[4] __bits; - } -} -else version (OpenBSD) -{ - alias sigset_t = uint; -} -else version (DragonFlyBSD) -{ - struct sigset_t - { - uint[4] __bits; - } -} -else version (Solaris) -{ - struct sigset_t - { - uint[4] __bits; - } -} -else version (CRuntime_Bionic) -{ - version (X86) - alias uint sigset_t; - else version (ARM) - alias uint sigset_t; - else version (AArch64) - struct sigset_t { ulong[1] sig; } - else version (X86_64) - alias ulong sigset_t; - else - static assert(false, "Architecture not supported."); -} -else version (CRuntime_Musl) -{ - struct sigset_t - { - c_ulong[128/c_long.sizeof] __bits; - } -} -else version (CRuntime_UClibc) -{ - version (MIPS32) - private enum _SIGSET_NWORDS = 128 / (8 * c_ulong.sizeof); - else - private enum _SIGSET_NWORDS = 64 / (8 * c_ulong.sizeof); - - struct sigset_t - { - c_ulong[_SIGSET_NWORDS] __val; - } -} -else -{ - static assert(false, "Unsupported platform"); -} - -/* -SIG_HOLD SA_NOCLDSTOP (CX|XSI) SIG_BLOCK @@ -964,10 +877,20 @@ SI_ASYNCIO SI_MESGQ */ +nothrow @nogc +{ + version (linux) { enum SIG_HOLD = cast(sigfn_t2) 2; + private enum _SIGSET_NWORDS = 1024 / (8 * c_ulong.sizeof); + + struct sigset_t + { + c_ulong[_SIGSET_NWORDS] __val; + } + enum SA_NOCLDSTOP = 1; // (CX|XSI) version (MIPS_Any) @@ -1090,6 +1013,8 @@ else version (Darwin) { enum SIG_HOLD = cast(sigfn_t2) 5; + alias uint sigset_t; + enum SA_NOCLDSTOP = 8; // (CX|XSI) enum SIG_BLOCK = 1; @@ -1120,6 +1045,11 @@ else version (FreeBSD) { enum SIG_HOLD = cast(sigfn_t2) 3; + struct sigset_t + { + uint[4] __bits; + } + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1181,6 +1111,11 @@ else version (NetBSD) { enum SIG_HOLD = cast(sigfn_t2) 3; + struct sigset_t + { + uint[4] __bits; + } + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1251,6 +1186,8 @@ else version (OpenBSD) enum SIG_CATCH = cast(sigfn_t2) 2; enum SIG_HOLD = cast(sigfn_t2) 3; + alias sigset_t = uint; + enum SA_NOCLDSTOP = 0x0008; enum SIG_BLOCK = 1; @@ -1313,6 +1250,11 @@ else version (DragonFlyBSD) enum SIG_CATCH = cast(sigfn_t2) 2; enum SIG_HOLD = cast(sigfn_t2) 3; + struct sigset_t + { + uint[4] __bits; + } + enum SA_NOCLDSTOP = 8; enum SIG_BLOCK = 1; @@ -1344,6 +1286,11 @@ else version (Solaris) { enum SIG_HOLD = cast(sigfn_t2)2; + struct sigset_t + { + uint[4] __bits; + } + enum SIG_BLOCK = 1; enum SIG_UNBLOCK = 2; enum SIG_SETMASK = 3;