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