signal.odin 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. #+build linux, darwin, netbsd, openbsd, freebsd, haiku
  2. package posix
  3. import "base:intrinsics"
  4. import "core:c"
  5. when ODIN_OS == .Darwin {
  6. foreign import lib "system:System"
  7. } else {
  8. foreign import lib "system:c"
  9. }
  10. // signal.h - signals
  11. foreign lib {
  12. /*
  13. Raise a signal to the process/group specified by pid.
  14. If sig is 0, this function can be used to check if the pid is just checked for validity.
  15. If pid is -1, the signal is sent to all processes that the current process has permission to send.
  16. If pid is negative (not -1), the signal is sent to all processes in the group identifier by the
  17. absolute value.
  18. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html ]]
  19. */
  20. kill :: proc(pid: pid_t, sig: Signal) -> result ---
  21. /*
  22. Shorthand for `kill(-pgrp, sig)` which will kill all processes in the given process group.
  23. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html ]]
  24. */
  25. killpg :: proc(pgrp: pid_t, sig: Signal) -> result ---
  26. /*
  27. Writes a language-dependent message to stderror.
  28. Example:
  29. posix.psignal(.SIGSEGV, "that didn't go well")
  30. Possible Output:
  31. that didn't go well: Segmentation fault
  32. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/psignal.html ]]
  33. */
  34. psignal :: proc(signum: Signal, message: cstring) ---
  35. /*
  36. Send a signal to a thread.
  37. As with kill, if sig is 0, only validation (of the pthread_t given) is done and no signal is sent.
  38. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html ]]
  39. */
  40. pthread_kill :: proc(thread: pthread_t, sig: Signal) -> Errno ---
  41. /*
  42. Examine and change blocked signals.
  43. Equivalent to sigprocmask(), without the restriction that the call be made in a single-threaded process.
  44. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html ]]
  45. */
  46. pthread_sigmask :: proc(how: Sig, set: ^sigset_t, oset: ^sigset_t) -> Errno ---
  47. /*
  48. Examine and change blocked signals in a single-threaded process.
  49. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html ]]
  50. */
  51. @(link_name=LSIGPROCMASK)
  52. sigprocmask :: proc(how: Sig, set: ^sigset_t, oldset: ^sigset_t) -> result ---
  53. /*
  54. Examine and change a signal action.
  55. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html ]]
  56. */
  57. @(link_name=LSIGACTION)
  58. sigaction :: proc(sig: Signal, act: ^sigaction_t, oact: ^sigaction_t) -> result ---
  59. @(link_name=LSIGADDSET)
  60. sigaddset :: proc(set: ^sigset_t, signo: Signal) -> result ---
  61. @(link_name=LSIGDELSET)
  62. sigdelset :: proc(^sigset_t, Signal) -> c.int ---
  63. @(link_name=LSIGEMPTYSET)
  64. sigemptyset :: proc(^sigset_t) -> c.int ---
  65. @(link_name=LSIGFILLSET)
  66. sigfillset :: proc(^sigset_t) -> c.int ---
  67. /*
  68. Set and get the signal alternate stack context.
  69. Example:
  70. sigstk := posix.stack_t {
  71. ss_sp = make([^]byte, posix.SIGSTKSZ) or_else panic("allocation failure"),
  72. ss_size = posix.SIGSTKSZ,
  73. ss_flags = {},
  74. }
  75. if posix.sigaltstack(&sigstk, nil) != .OK {
  76. fmt.panicf("sigaltstack failure: %v", posix.strerror(posix.errno()))
  77. }
  78. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaltstack.html ]]
  79. */
  80. @(link_name=LSIGALTSTACK)
  81. sigaltstack :: proc(ss: ^stack_t, oss: ^stack_t) -> result ---
  82. /*
  83. Adds sig to the signal mask of the calling process.
  84. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sighold.html ]]
  85. */
  86. sighold :: proc(sig: Signal) -> result ---
  87. /*
  88. Sets the disposition of sig to SIG_IGN.
  89. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sighold.html ]]
  90. */
  91. sigignore :: proc(sig: Signal) -> result ---
  92. /*
  93. Removes sig from the signal mask of the calling process and suspend the calling process until
  94. a signal is received.
  95. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sighold.html ]]
  96. */
  97. sigpause :: proc(sig: Signal) -> result ---
  98. /*
  99. Removes sig from the signal mask of the calling process.
  100. Returns: always -1.
  101. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sighold.html ]]
  102. */
  103. sigrelse :: proc(sig: Signal) -> result ---
  104. /*
  105. Changes the restart behavior when a function is interrupted by the specified signal.
  106. If flag is true, SA_RESTART is removed, added otherwise.
  107. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/siginterrupt.html ]]
  108. */
  109. siginterrupt :: proc(sig: Signal, flag: b32) -> result ---
  110. /*
  111. Test for a signal in a signal set.
  112. Returns: 1 if it is a member, 0 if not, -1 (setting errno) on failure
  113. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigismember.html ]]
  114. */
  115. @(link_name=LSIGISMEMBER)
  116. sigismember :: proc(set: ^sigset_t, signo: Signal) -> c.int ---
  117. /*
  118. Stores the set of signals that are blocked from delivery to the calling thread and that are pending
  119. on the process or the calling thread.
  120. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigpending.html ]]
  121. */
  122. @(link_name=LSIGPENDING)
  123. sigpending :: proc(set: ^sigset_t) -> result ---
  124. /*
  125. Wait for one of the given signals.
  126. Returns: always -1
  127. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsuspend.html ]]
  128. */
  129. @(link_name=LSIGSUSPEND)
  130. sigsuspend :: proc(sigmask: ^sigset_t) -> result ---
  131. /*
  132. Wait for queued signals.
  133. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigwait.html ]]
  134. */
  135. sigwait :: proc(set: ^sigset_t, sig: ^Signal) -> Errno ---
  136. /* NOTE: unimplemented on darwin.
  137. void psiginfo(const siginfo_t *, const char *);
  138. int sigqueue(pid_t, int, union sigval);
  139. void (*sigset(int, void (*)(int)))(int);
  140. int sigsuspend(const sigset_t *);
  141. int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict,
  142. const struct timespec *restrict);
  143. int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict);
  144. */
  145. }
  146. sigval :: struct #raw_union {
  147. sigval_int: c.int, /* [PSX] integer signal value */
  148. sigval_ptr: rawptr, /* [PSX] pointer signal value */
  149. }
  150. ILL_Code :: enum c.int {
  151. // Illegal opcode.
  152. ILLOPC = ILL_ILLOPC,
  153. // Illegal operand.
  154. ILLOPN = ILL_ILLOPN,
  155. // Illegal addressing mode.
  156. ILLADR = ILL_ILLADR,
  157. // Illegal trap.
  158. ILLTRP = ILL_ILLTRP,
  159. // Priviledged opcode.
  160. PRVOPC = ILL_PRVOPC,
  161. // Priviledged register.
  162. PRVREG = ILL_PRVREG,
  163. // Coprocessor error.
  164. COPROC = ILL_COPROC,
  165. // Internal stack error.
  166. BADSTK = ILL_BADSTK,
  167. }
  168. FPE_Code :: enum c.int {
  169. // Integer divide by zero.
  170. INTDIV = FPE_INTDIV,
  171. // Integer overflow.
  172. INTOVF = FPE_INTOVF,
  173. // Floating-point divide by zero.
  174. FLTDIV = FPE_FLTDIV,
  175. // Floating-point overflow.
  176. FLTOVF = FPE_FLTOVF,
  177. // Floating-point underflow.
  178. FLTUND = FPE_FLTUND,
  179. // Floating-point inexact result.
  180. FLTRES = FPE_FLTRES,
  181. // Invalid floating-point operation.
  182. FLTINV = FPE_FLTINV,
  183. // Subscript out of range.
  184. FLTSUB = FPE_FLTSUB,
  185. }
  186. SEGV_Code :: enum c.int {
  187. // Address not mapped to object.
  188. MAPERR = SEGV_MAPERR,
  189. // Invalid permissions for mapped object.
  190. ACCERR = SEGV_ACCERR,
  191. }
  192. BUS_Code :: enum c.int {
  193. // Invalid address alignment.
  194. ADRALN = BUS_ADRALN,
  195. // Nonexistent physical address.
  196. ADRERR = BUS_ADRERR,
  197. // Object-specific hardware error.
  198. OBJERR = BUS_OBJERR,
  199. }
  200. TRAP_Code :: enum c.int {
  201. // Process breakpoint.
  202. BRKPT = TRAP_BRKPT,
  203. // Process trace trap.
  204. TRACE = TRAP_TRACE,
  205. }
  206. CLD_Code :: enum c.int {
  207. // Child has exited..
  208. EXITED = CLD_EXITED,
  209. // Child has terminated abnormally and did not create a core file.
  210. KILLED = CLD_KILLED,
  211. // Child has terminated abnormally and created a core file.
  212. DUMPED = CLD_DUMPED,
  213. // Traced child trapped.
  214. TRAPPED = CLD_TRAPPED,
  215. // Child has stopped.
  216. STOPPED = CLD_STOPPED,
  217. // Stopped child has continued.
  218. CONTINUED = CLD_CONTINUED,
  219. }
  220. POLL_Code :: enum c.int {
  221. // Data input is available.
  222. IN = POLL_IN,
  223. // Output buffers available.
  224. OUT = POLL_OUT,
  225. // Input message available.
  226. MSG = POLL_MSG,
  227. // I/O error.
  228. ERR = POLL_ERR,
  229. // High priority input available.
  230. PRI = POLL_PRI,
  231. // Device disconnected.
  232. HUP = POLL_HUP,
  233. }
  234. Any_Code :: enum c.int {
  235. // Signal sent by kill().
  236. USER = SI_USER,
  237. // Signal sent by sigqueue().
  238. QUEUE = SI_QUEUE,
  239. // Signal generated by expiration of a timer set by timer_settime().
  240. TIMER = SI_TIMER,
  241. // Signal generated by completion of an asynchronous I/O request.
  242. ASYNCIO = SI_ASYNCIO,
  243. // Signal generated by arrival of a message on an empty message queue.
  244. MESGQ = SI_MESGQ,
  245. }
  246. SA_Flags_Bits :: enum c.int {
  247. // Do not generate SIGCHLD when children stop or stopped children continue.
  248. NOCLDSTOP = log2(SA_NOCLDSTOP),
  249. // Cause signal delivery to occur on an alternate stack.
  250. ONSTACK = log2(SA_ONSTACK),
  251. // Cause signal disposition to be set to SIG_DFL on entry to signal handlers.
  252. RESETHAND = log2(SA_RESETHAND),
  253. // Cause certain functions to become restartable.
  254. RESTART = log2(SA_RESTART),
  255. // Cause extra information to be passed to signal handlers at the time of receipt of a signal.
  256. SIGINFO = log2(SA_SIGINFO),
  257. // Cause implementation not to create zombie processes or status information on child termination.
  258. NOCLDWAIT = log2(SA_NOCLDWAIT),
  259. // Cause signal not to be automatically blocked on entry to signal handler.
  260. SA_NODEFER = log2(SA_NODEFER),
  261. }
  262. SA_Flags :: bit_set[SA_Flags_Bits; c.int]
  263. SS_Flag_Bits :: enum c.int {
  264. // Process is executing on an alternate signal stack.
  265. ONSTACK = log2(SS_ONSTACK),
  266. // Alternate signal stack is disabled.
  267. DISABLE = log2(SS_DISABLE),
  268. }
  269. SS_Flags :: bit_set[SS_Flag_Bits; c.int]
  270. Sig :: enum c.int {
  271. // Resulting set is the union of the current set and the signal set and the complement of
  272. // the signal set pointed to by the argument.
  273. BLOCK = SIG_BLOCK,
  274. // Resulting set is the intersection of the current set and the complement of the signal set
  275. // pointed to by the argument.
  276. UNBLOCK = SIG_UNBLOCK,
  277. // Resulting set is the signal set pointed to by the argument.
  278. SETMASK = SIG_SETMASK,
  279. }
  280. when ODIN_OS == .NetBSD {
  281. @(private) LSIGPROCMASK :: "__sigprocmask14"
  282. @(private) LSIGACTION :: "__sigaction_siginfo"
  283. @(private) LSIGADDSET :: "__sigaddset14"
  284. @(private) LSIGDELSET :: "__sigdelset14"
  285. @(private) LSIGEMPTYSET :: "__sigemptyset14"
  286. @(private) LSIGFILLSET :: "__sigfillset14"
  287. @(private) LSIGALTSTACK :: "__sigaltstack14"
  288. @(private) LSIGISMEMBER :: "__sigismember14"
  289. @(private) LSIGPENDING :: "__sigpending14"
  290. @(private) LSIGSUSPEND :: "__sigsuspend14"
  291. } else {
  292. @(private) LSIGPROCMASK :: "sigprocmask"
  293. @(private) LSIGACTION :: "sigaction"
  294. @(private) LSIGADDSET :: "sigaddset"
  295. @(private) LSIGDELSET :: "sigdelset"
  296. @(private) LSIGEMPTYSET :: "sigemptyset"
  297. @(private) LSIGFILLSET :: "sigfillset"
  298. @(private) LSIGALTSTACK :: "sigaltstack"
  299. @(private) LSIGISMEMBER :: "sigismember"
  300. @(private) LSIGPENDING :: "sigpending"
  301. @(private) LSIGSUSPEND :: "sigsuspend"
  302. }
  303. when ODIN_OS == .Darwin {
  304. // Request that signal be held
  305. SIG_HOLD :: rawptr(uintptr(5))
  306. uid_t :: distinct c.uint32_t
  307. sigset_t :: distinct c.uint32_t
  308. SIGHUP :: 1
  309. SIGQUIT :: 3
  310. SIGTRAP :: 5
  311. SIGPOLL :: 7
  312. SIGKILL :: 9
  313. SIGBUS :: 10
  314. SIGSYS :: 12
  315. SIGPIPE :: 13
  316. SIGALRM :: 14
  317. SIGURG :: 16
  318. SIGCONT :: 19
  319. SIGSTOP :: 17
  320. SIGTSTP :: 18
  321. SIGCHLD :: 20
  322. SIGTTIN :: 21
  323. SIGTTOU :: 22
  324. SIGXCPU :: 24
  325. SIGXFSZ :: 25
  326. SIGVTALRM :: 26
  327. SIGPROF :: 27
  328. SIGWINCH :: 28
  329. SIGUSR1 :: 30
  330. SIGUSR2 :: 31
  331. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  332. // `_t` has been added.
  333. sigaction_t :: struct {
  334. using _: struct #raw_union {
  335. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  336. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  337. },
  338. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  339. sa_flags: SA_Flags, /* [PSX] special flags */
  340. }
  341. SIG_BLOCK :: 1
  342. SIG_UNBLOCK :: 2
  343. SIG_SETMASK :: 3
  344. SA_NOCLDSTOP :: 0x0008
  345. SA_ONSTACK :: 0x0001
  346. SA_RESETHAND :: 0x0004
  347. SA_RESTART :: 0x0002
  348. SA_SIGINFO :: 0x0040
  349. SA_NOCLDWAIT :: 0x0020
  350. SA_NODEFER :: 0x0010
  351. SS_ONSTACK :: 0x0001
  352. SS_DISABLE :: 0x0004
  353. MINSIGSTKSZ :: 32768
  354. SIGSTKSZ :: 131072
  355. stack_t :: struct {
  356. ss_sp: rawptr, /* [PSX] stack base or pointer */
  357. ss_size: c.size_t, /* [PSX] stack size */
  358. ss_flags: SS_Flags, /* [PSX] flags */
  359. }
  360. siginfo_t :: struct {
  361. si_signo: Signal, /* [PSX] signal number */
  362. si_errno: Errno, /* [PSX] errno value associated with this signal */
  363. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  364. ill: ILL_Code,
  365. fpe: FPE_Code,
  366. segv: SEGV_Code,
  367. bus: BUS_Code,
  368. trap: TRAP_Code,
  369. chld: CLD_Code,
  370. poll: POLL_Code,
  371. any: Any_Code,
  372. },
  373. si_pid: pid_t, /* [PSX] sending process ID */
  374. si_uid: uid_t, /* [PSX] real user ID of sending process */
  375. si_status: c.int, /* [PSX] exit value or signal */
  376. si_addr: rawptr, /* [PSX] address of faulting instruction */
  377. si_value: sigval, /* [PSX] signal value */
  378. si_band: c.long, /* [PSX] band event for SIGPOLL */
  379. __pad: [7]c.ulong,
  380. }
  381. ILL_ILLOPC :: 1
  382. ILL_ILLOPN :: 4
  383. ILL_ILLADR :: 5
  384. ILL_ILLTRP :: 2
  385. ILL_PRVOPC :: 3
  386. ILL_PRVREG :: 6
  387. ILL_COPROC :: 7
  388. ILL_BADSTK :: 8
  389. FPE_INTDIV :: 7
  390. FPE_INTOVF :: 8
  391. FPE_FLTDIV :: 1
  392. FPE_FLTOVF :: 2
  393. FPE_FLTUND :: 3
  394. FPE_FLTRES :: 4
  395. FPE_FLTINV :: 5
  396. FPE_FLTSUB :: 6
  397. SEGV_MAPERR :: 1
  398. SEGV_ACCERR :: 2
  399. BUS_ADRALN :: 1
  400. BUS_ADRERR :: 2
  401. BUS_OBJERR :: 3
  402. TRAP_BRKPT :: 1
  403. TRAP_TRACE :: 2
  404. CLD_EXITED :: 1
  405. CLD_KILLED :: 2
  406. CLD_DUMPED :: 3
  407. CLD_TRAPPED :: 4
  408. CLD_STOPPED :: 5
  409. CLD_CONTINUED :: 6
  410. POLL_IN :: 1
  411. POLL_OUT :: 2
  412. POLL_MSG :: 3
  413. POLL_ERR :: 4
  414. POLL_PRI :: 5
  415. POLL_HUP :: 6
  416. SI_USER :: 0x10001
  417. SI_QUEUE :: 0x10002
  418. SI_TIMER :: 0x10003
  419. SI_ASYNCIO :: 0x10004
  420. SI_MESGQ :: 0x10005
  421. } else when ODIN_OS == .FreeBSD {
  422. // Request that signal be held
  423. SIG_HOLD :: rawptr(uintptr(3))
  424. uid_t :: distinct c.uint32_t
  425. sigset_t :: struct {
  426. __bits: [4]c.uint32_t,
  427. }
  428. SIGHUP :: 1
  429. SIGQUIT :: 3
  430. SIGTRAP :: 5
  431. SIGPOLL :: 7
  432. SIGKILL :: 9
  433. SIGBUS :: 10
  434. SIGSYS :: 12
  435. SIGPIPE :: 13
  436. SIGALRM :: 14
  437. SIGURG :: 16
  438. SIGCONT :: 19
  439. SIGSTOP :: 17
  440. SIGTSTP :: 18
  441. SIGCHLD :: 20
  442. SIGTTIN :: 21
  443. SIGTTOU :: 22
  444. SIGXCPU :: 24
  445. SIGXFSZ :: 25
  446. SIGVTALRM :: 26
  447. SIGPROF :: 27
  448. SIGWINCH :: 28
  449. SIGUSR1 :: 30
  450. SIGUSR2 :: 31
  451. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  452. // `_t` has been added.
  453. sigaction_t :: struct {
  454. using _: struct #raw_union {
  455. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  456. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  457. },
  458. sa_flags: SA_Flags, /* [PSX] special flags */
  459. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  460. }
  461. SIG_BLOCK :: 1
  462. SIG_UNBLOCK :: 2
  463. SIG_SETMASK :: 3
  464. SA_NOCLDSTOP :: 0x0008
  465. SA_ONSTACK :: 0x0001
  466. SA_RESETHAND :: 0x0004
  467. SA_RESTART :: 0x0002
  468. SA_SIGINFO :: 0x0040
  469. SA_NOCLDWAIT :: 0x0020
  470. SA_NODEFER :: 0x0010
  471. SS_ONSTACK :: 0x0001
  472. SS_DISABLE :: 0x0004
  473. when ODIN_ARCH == .arm64 || ODIN_ARCH == .arm32 {
  474. MINSIGSTKSZ :: 1024 * 4
  475. } else when ODIN_ARCH == .amd64 || ODIN_ARCH == .i386 {
  476. MINSIGSTKSZ :: 512 * 4
  477. }
  478. SIGSTKSZ :: MINSIGSTKSZ + 32768
  479. stack_t :: struct {
  480. ss_sp: rawptr, /* [PSX] stack base or pointer */
  481. ss_size: c.size_t, /* [PSX] stack size */
  482. ss_flags: SS_Flags, /* [PSX] flags */
  483. }
  484. siginfo_t :: struct {
  485. si_signo: Signal, /* [PSX] signal number */
  486. si_errno: Errno, /* [PSX] errno value associated with this signal */
  487. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  488. ill: ILL_Code,
  489. fpe: FPE_Code,
  490. segv: SEGV_Code,
  491. bus: BUS_Code,
  492. trap: TRAP_Code,
  493. chld: CLD_Code,
  494. poll: POLL_Code,
  495. any: Any_Code,
  496. },
  497. si_pid: pid_t, /* [PSX] sending process ID */
  498. si_uid: uid_t, /* [PSX] real user ID of sending process */
  499. si_status: c.int, /* [PSX] exit value or signal */
  500. si_addr: rawptr, /* [PSX] address of faulting instruction */
  501. si_value: sigval, /* [PSX] signal value */
  502. using _reason: struct #raw_union {
  503. _fault: struct {
  504. _trapno: c.int, /* machine specific trap code */
  505. },
  506. _timer: struct {
  507. _timerid: c.int,
  508. _overrun: c.int,
  509. },
  510. _mesgq: struct {
  511. _mqd: c.int,
  512. },
  513. using _poll: struct {
  514. si_band: c.long, /* [PSX] band event for SIGPOLL */
  515. },
  516. _capsicum: struct {
  517. _syscall: c.int, /* syscall number for signals delivered as a result of system calls denied by capsicum */
  518. },
  519. __spare__: struct {
  520. __spare1__: c.long,
  521. __spare2__: [7]c.int,
  522. },
  523. },
  524. }
  525. ILL_ILLOPC :: 1
  526. ILL_ILLOPN :: 2
  527. ILL_ILLADR :: 3
  528. ILL_ILLTRP :: 4
  529. ILL_PRVOPC :: 5
  530. ILL_PRVREG :: 6
  531. ILL_COPROC :: 7
  532. ILL_BADSTK :: 8
  533. FPE_INTDIV :: 2
  534. FPE_INTOVF :: 1
  535. FPE_FLTDIV :: 3
  536. FPE_FLTOVF :: 4
  537. FPE_FLTUND :: 5
  538. FPE_FLTRES :: 6
  539. FPE_FLTINV :: 7
  540. FPE_FLTSUB :: 8
  541. SEGV_MAPERR :: 1
  542. SEGV_ACCERR :: 2
  543. BUS_ADRALN :: 1
  544. BUS_ADRERR :: 2
  545. BUS_OBJERR :: 3
  546. TRAP_BRKPT :: 1
  547. TRAP_TRACE :: 2
  548. CLD_EXITED :: 1
  549. CLD_KILLED :: 2
  550. CLD_DUMPED :: 3
  551. CLD_TRAPPED :: 4
  552. CLD_STOPPED :: 5
  553. CLD_CONTINUED :: 6
  554. POLL_IN :: 1
  555. POLL_OUT :: 2
  556. POLL_MSG :: 3
  557. POLL_ERR :: 4
  558. POLL_PRI :: 5
  559. POLL_HUP :: 6
  560. SI_USER :: 0x10001
  561. SI_QUEUE :: 0x10002
  562. SI_TIMER :: 0x10003
  563. SI_ASYNCIO :: 0x10004
  564. SI_MESGQ :: 0x10005
  565. } else when ODIN_OS == .NetBSD {
  566. // Request that signal be held
  567. SIG_HOLD :: rawptr(uintptr(3))
  568. uid_t :: distinct c.uint32_t
  569. sigset_t :: struct {
  570. __bits: [4]c.uint32_t,
  571. }
  572. SIGHUP :: 1
  573. SIGQUIT :: 3
  574. SIGTRAP :: 5
  575. SIGPOLL :: 7
  576. SIGKILL :: 9
  577. SIGBUS :: 10
  578. SIGSYS :: 12
  579. SIGPIPE :: 13
  580. SIGALRM :: 14
  581. SIGURG :: 16
  582. SIGCONT :: 19
  583. SIGSTOP :: 17
  584. SIGTSTP :: 18
  585. SIGCHLD :: 20
  586. SIGTTIN :: 21
  587. SIGTTOU :: 22
  588. SIGXCPU :: 24
  589. SIGXFSZ :: 25
  590. SIGVTALRM :: 26
  591. SIGPROF :: 27
  592. SIGWINCH :: 28
  593. SIGUSR1 :: 30
  594. SIGUSR2 :: 31
  595. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  596. // `_t` has been added.
  597. sigaction_t :: struct {
  598. using _: struct #raw_union {
  599. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  600. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  601. },
  602. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  603. sa_flags: SA_Flags, /* [PSX] special flags */
  604. }
  605. SIG_BLOCK :: 1
  606. SIG_UNBLOCK :: 2
  607. SIG_SETMASK :: 3
  608. SA_NOCLDSTOP :: 0x0008
  609. SA_ONSTACK :: 0x0001
  610. SA_RESETHAND :: 0x0004
  611. SA_RESTART :: 0x0002
  612. SA_SIGINFO :: 0x0040
  613. SA_NOCLDWAIT :: 0x0020
  614. SA_NODEFER :: 0x0010
  615. SS_ONSTACK :: 0x0001
  616. SS_DISABLE :: 0x0004
  617. MINSIGSTKSZ :: 8192
  618. SIGSTKSZ :: MINSIGSTKSZ + 32768
  619. stack_t :: struct {
  620. ss_sp: rawptr, /* [PSX] stack base or pointer */
  621. ss_size: c.size_t, /* [PSX] stack size */
  622. ss_flags: SS_Flags, /* [PSX] flags */
  623. }
  624. @(private)
  625. lwpid_t :: c.int32_t
  626. siginfo_t :: struct #raw_union {
  627. si_pad: [128]byte,
  628. using _info: struct {
  629. si_signo: Signal, /* [PSX] signal number */
  630. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  631. ill: ILL_Code,
  632. fpe: FPE_Code,
  633. segv: SEGV_Code,
  634. bus: BUS_Code,
  635. trap: TRAP_Code,
  636. chld: CLD_Code,
  637. poll: POLL_Code,
  638. any: Any_Code,
  639. },
  640. si_errno: Errno, /* [PSX] errno value associated with this signal */
  641. // #ifdef _LP64
  642. /* In _LP64 the union starts on an 8-byte boundary. */
  643. _pad: c.int,
  644. // #endif
  645. using _reason: struct #raw_union {
  646. using _rt: struct {
  647. _pid: pid_t,
  648. _uid: uid_t,
  649. si_value: sigval, /* [PSX] signal value */
  650. },
  651. using _child: struct {
  652. si_pid: pid_t, /* [PSX] sending process ID */
  653. si_uid: uid_t, /* [PSX] real user ID of sending process */
  654. si_status: c.int, /* [PSX] exit value or signal */
  655. _utime: clock_t,
  656. _stime: clock_t,
  657. },
  658. using _fault: struct {
  659. si_addr: rawptr, /* [PSX] address of faulting instruction */
  660. _trap: c.int,
  661. _trap2: c.int,
  662. _trap3: c.int,
  663. },
  664. using _poll: struct {
  665. si_band: c.long, /* [PSX] band event for SIGPOLL */
  666. _fd: FD,
  667. },
  668. _syscall: struct {
  669. _sysnum: c.int,
  670. _retval: [2]c.int,
  671. _error: c.int,
  672. _args: [8]c.uint64_t,
  673. },
  674. _ptrace_state: struct {
  675. _pe_report_event: c.int,
  676. _option: struct #raw_union {
  677. _pe_other_pid: pid_t,
  678. _pe_lwp: lwpid_t,
  679. },
  680. },
  681. },
  682. },
  683. }
  684. ILL_ILLOPC :: 1
  685. ILL_ILLOPN :: 2
  686. ILL_ILLADR :: 3
  687. ILL_ILLTRP :: 4
  688. ILL_PRVOPC :: 5
  689. ILL_PRVREG :: 6
  690. ILL_COPROC :: 7
  691. ILL_BADSTK :: 8
  692. FPE_INTDIV :: 1
  693. FPE_INTOVF :: 2
  694. FPE_FLTDIV :: 3
  695. FPE_FLTOVF :: 4
  696. FPE_FLTUND :: 5
  697. FPE_FLTRES :: 6
  698. FPE_FLTINV :: 7
  699. FPE_FLTSUB :: 8
  700. SEGV_MAPERR :: 1
  701. SEGV_ACCERR :: 2
  702. BUS_ADRALN :: 1
  703. BUS_ADRERR :: 2
  704. BUS_OBJERR :: 3
  705. TRAP_BRKPT :: 1
  706. TRAP_TRACE :: 2
  707. CLD_EXITED :: 1
  708. CLD_KILLED :: 2
  709. CLD_DUMPED :: 3
  710. CLD_TRAPPED :: 4
  711. CLD_STOPPED :: 5
  712. CLD_CONTINUED :: 6
  713. POLL_IN :: 1
  714. POLL_OUT :: 2
  715. POLL_MSG :: 3
  716. POLL_ERR :: 4
  717. POLL_PRI :: 5
  718. POLL_HUP :: 6
  719. SI_USER :: 0
  720. SI_QUEUE :: -1
  721. SI_TIMER :: -2
  722. SI_ASYNCIO :: -3
  723. SI_MESGQ :: -4
  724. } else when ODIN_OS == .OpenBSD {
  725. // Request that signal be held
  726. SIG_HOLD :: rawptr(uintptr(3))
  727. uid_t :: distinct c.uint32_t
  728. sigset_t :: distinct c.uint32_t
  729. SIGHUP :: 1
  730. SIGQUIT :: 3
  731. SIGTRAP :: 5
  732. SIGPOLL :: 7
  733. SIGKILL :: 9
  734. SIGBUS :: 10
  735. SIGSYS :: 12
  736. SIGPIPE :: 13
  737. SIGALRM :: 14
  738. SIGURG :: 16
  739. SIGCONT :: 19
  740. SIGSTOP :: 17
  741. SIGTSTP :: 18
  742. SIGCHLD :: 20
  743. SIGTTIN :: 21
  744. SIGTTOU :: 22
  745. SIGXCPU :: 24
  746. SIGXFSZ :: 25
  747. SIGVTALRM :: 26
  748. SIGPROF :: 27
  749. SIGWINCH :: 28
  750. SIGUSR1 :: 30
  751. SIGUSR2 :: 31
  752. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  753. // `_t` has been added.
  754. sigaction_t :: struct {
  755. using _: struct #raw_union {
  756. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  757. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  758. },
  759. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  760. sa_flags: SA_Flags, /* [PSX] special flags */
  761. }
  762. SIG_BLOCK :: 1
  763. SIG_UNBLOCK :: 2
  764. SIG_SETMASK :: 3
  765. SA_NOCLDSTOP :: 0x0008
  766. SA_ONSTACK :: 0x0001
  767. SA_RESETHAND :: 0x0004
  768. SA_RESTART :: 0x0002
  769. SA_SIGINFO :: 0x0040
  770. SA_NOCLDWAIT :: 0x0020
  771. SA_NODEFER :: 0x0010
  772. SS_ONSTACK :: 0x0001
  773. SS_DISABLE :: 0x0004
  774. MINSIGSTKSZ :: 3 << 12
  775. SIGSTKSZ :: MINSIGSTKSZ + (1 << 12) * 4
  776. stack_t :: struct {
  777. ss_sp: rawptr, /* [PSX] stack base or pointer */
  778. ss_size: c.size_t, /* [PSX] stack size */
  779. ss_flags: SS_Flags, /* [PSX] flags */
  780. }
  781. SI_MAXSZ :: 128
  782. SI_PAD :: (SI_MAXSZ / size_of(c.int)) - 3
  783. siginfo_t :: struct {
  784. si_signo: Signal, /* [PSX] signal number */
  785. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  786. ill: ILL_Code,
  787. fpe: FPE_Code,
  788. segv: SEGV_Code,
  789. bus: BUS_Code,
  790. trap: TRAP_Code,
  791. chld: CLD_Code,
  792. poll: POLL_Code,
  793. any: Any_Code,
  794. },
  795. si_errno: Errno, /* [PSX] errno value associated with this signal */
  796. using _data: struct #raw_union {
  797. _pad: [SI_PAD]c.int,
  798. using _proc: struct {
  799. si_pid: pid_t, /* [PSX] sending process ID */
  800. si_uid: uid_t, /* [PSX] real user ID of sending process */
  801. using _pdata: struct #raw_union {
  802. using _kill: struct {
  803. si_value: sigval,
  804. },
  805. using _cld: struct {
  806. _utime: clock_t,
  807. _stime: clock_t,
  808. si_status: c.int,
  809. },
  810. },
  811. },
  812. using _fault: struct {
  813. si_addr: rawptr,
  814. _trapno: c.int,
  815. },
  816. using _file: struct {
  817. _fd: FD,
  818. si_band: c.long, /* [PSX] band event for SIGPOLL */
  819. },
  820. },
  821. }
  822. ILL_ILLOPC :: 1
  823. ILL_ILLOPN :: 2
  824. ILL_ILLADR :: 3
  825. ILL_ILLTRP :: 4
  826. ILL_PRVOPC :: 5
  827. ILL_PRVREG :: 6
  828. ILL_COPROC :: 7
  829. ILL_BADSTK :: 8
  830. FPE_INTDIV :: 1
  831. FPE_INTOVF :: 2
  832. FPE_FLTDIV :: 3
  833. FPE_FLTOVF :: 4
  834. FPE_FLTUND :: 5
  835. FPE_FLTRES :: 6
  836. FPE_FLTINV :: 7
  837. FPE_FLTSUB :: 8
  838. SEGV_MAPERR :: 1
  839. SEGV_ACCERR :: 2
  840. BUS_ADRALN :: 1
  841. BUS_ADRERR :: 2
  842. BUS_OBJERR :: 3
  843. TRAP_BRKPT :: 1
  844. TRAP_TRACE :: 2
  845. CLD_EXITED :: 1
  846. CLD_KILLED :: 2
  847. CLD_DUMPED :: 3
  848. CLD_TRAPPED :: 4
  849. CLD_STOPPED :: 5
  850. CLD_CONTINUED :: 6
  851. POLL_IN :: 1
  852. POLL_OUT :: 2
  853. POLL_MSG :: 3
  854. POLL_ERR :: 4
  855. POLL_PRI :: 5
  856. POLL_HUP :: 6
  857. SI_USER :: 0
  858. SI_QUEUE :: -2
  859. SI_TIMER :: -3
  860. SI_ASYNCIO :: -4 // NOTE: not implemented
  861. SI_MESGQ :: -5 // NOTE: not implemented
  862. } else when ODIN_OS == .Linux {
  863. // Request that signal be held
  864. SIG_HOLD :: rawptr(uintptr(2))
  865. uid_t :: distinct c.uint32_t
  866. sigset_t :: struct {
  867. __val: [1024/(8 * size_of(c.ulong))]c.ulong,
  868. }
  869. SIGHUP :: 1
  870. SIGQUIT :: 3
  871. SIGTRAP :: 5
  872. SIGBUS :: 7
  873. SIGKILL :: 9
  874. SIGUSR1 :: 10
  875. SIGUSR2 :: 12
  876. SIGPIPE :: 13
  877. SIGALRM :: 14
  878. SIGCHLD :: 17
  879. SIGCONT :: 18
  880. SIGSTOP :: 19
  881. SIGTSTP :: 20
  882. SIGTTIN :: 21
  883. SIGTTOU :: 22
  884. SIGURG :: 23
  885. SIGXCPU :: 24
  886. SIGXFSZ :: 25
  887. SIGVTALRM :: 26
  888. SIGPROF :: 27
  889. SIGWINCH :: 28
  890. SIGPOLL :: 29
  891. SIGSYS :: 31
  892. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  893. // `_t` has been added.
  894. sigaction_t :: struct {
  895. using _: struct #raw_union {
  896. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  897. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  898. },
  899. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  900. sa_flags: SA_Flags, /* [PSX] special flags */
  901. sa_restorer: proc "c" (),
  902. }
  903. SIG_BLOCK :: 0
  904. SIG_UNBLOCK :: 1
  905. SIG_SETMASK :: 2
  906. SA_NOCLDSTOP :: 1
  907. SA_NOCLDWAIT :: 2
  908. SA_SIGINFO :: 4
  909. SA_ONSTACK :: 0x08000000
  910. SA_RESTART :: 0x10000000
  911. SA_NODEFER :: 0x40000000
  912. SA_RESETHAND :: 0x80000000
  913. SS_ONSTACK :: 1
  914. SS_DISABLE :: 2
  915. when ODIN_ARCH == .arm64 {
  916. MINSIGSTKSZ :: 6144
  917. SIGSTKSZ :: 12288
  918. } else {
  919. MINSIGSTKSZ :: 2048
  920. SIGSTKSZ :: 8192
  921. }
  922. stack_t :: struct {
  923. ss_sp: rawptr, /* [PSX] stack base or pointer */
  924. ss_flags: SS_Flags, /* [PSX] flags */
  925. ss_size: c.size_t, /* [PSX] stack size */
  926. }
  927. @(private)
  928. __SI_MAX_SIZE :: 128
  929. when size_of(int) == 8 {
  930. @(private)
  931. _pad0 :: struct {
  932. _pad0: c.int,
  933. }
  934. @(private)
  935. __SI_PAD_SIZE :: (__SI_MAX_SIZE / size_of(c.int)) - 4
  936. } else {
  937. @(private)
  938. _pad0 :: struct {}
  939. @(private)
  940. __SI_PAD_SIZE :: (__SI_MAX_SIZE / size_of(c.int)) - 3
  941. }
  942. siginfo_t :: struct #align(8) {
  943. si_signo: Signal, /* [PSX] signal number */
  944. si_errno: Errno, /* [PSX] errno value associated with this signal */
  945. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  946. ill: ILL_Code,
  947. fpe: FPE_Code,
  948. segv: SEGV_Code,
  949. bus: BUS_Code,
  950. trap: TRAP_Code,
  951. chld: CLD_Code,
  952. poll: POLL_Code,
  953. any: Any_Code,
  954. },
  955. __pad0: _pad0,
  956. using _sifields: struct #raw_union {
  957. _pad: [__SI_PAD_SIZE]c.int,
  958. using _: struct {
  959. si_pid: pid_t, /* [PSX] sending process ID */
  960. si_uid: uid_t, /* [PSX] real user ID of sending process */
  961. using _: struct #raw_union {
  962. si_status: c.int, /* [PSX] exit value or signal */
  963. si_value: sigval, /* [PSX] signal value */
  964. },
  965. },
  966. using _: struct {
  967. si_addr: rawptr, /* [PSX] address of faulting instruction */
  968. },
  969. using _: struct {
  970. si_band: c.long, /* [PSX] band event for SIGPOLL */
  971. },
  972. },
  973. }
  974. ILL_ILLOPC :: 1
  975. ILL_ILLOPN :: 2
  976. ILL_ILLADR :: 3
  977. ILL_ILLTRP :: 4
  978. ILL_PRVOPC :: 5
  979. ILL_PRVREG :: 6
  980. ILL_COPROC :: 7
  981. ILL_BADSTK :: 8
  982. FPE_INTDIV :: 1
  983. FPE_INTOVF :: 2
  984. FPE_FLTDIV :: 3
  985. FPE_FLTOVF :: 4
  986. FPE_FLTUND :: 5
  987. FPE_FLTRES :: 6
  988. FPE_FLTINV :: 7
  989. FPE_FLTSUB :: 8
  990. SEGV_MAPERR :: 1
  991. SEGV_ACCERR :: 2
  992. BUS_ADRALN :: 1
  993. BUS_ADRERR :: 2
  994. BUS_OBJERR :: 3
  995. TRAP_BRKPT :: 1
  996. TRAP_TRACE :: 2
  997. CLD_EXITED :: 1
  998. CLD_KILLED :: 2
  999. CLD_DUMPED :: 3
  1000. CLD_TRAPPED :: 4
  1001. CLD_STOPPED :: 5
  1002. CLD_CONTINUED :: 6
  1003. POLL_IN :: 1
  1004. POLL_OUT :: 2
  1005. POLL_MSG :: 3
  1006. POLL_ERR :: 4
  1007. POLL_PRI :: 5
  1008. POLL_HUP :: 6
  1009. SI_USER :: 0
  1010. SI_QUEUE :: -1
  1011. SI_TIMER :: -2
  1012. SI_MESGQ :: -3
  1013. SI_ASYNCIO :: -4
  1014. } else when ODIN_OS == .Haiku {
  1015. // Request that signal be held
  1016. SIG_HOLD :: rawptr(uintptr(3))
  1017. uid_t :: distinct c.uint32_t
  1018. sigset_t :: distinct u64
  1019. SIGHUP :: 1 // hangup -- tty is gone!
  1020. //SIGINT :: 2 // interrupt
  1021. SIGQUIT :: 3 // `quit' special character typed in tty
  1022. //SIGILL :: 4 // illegal instruction
  1023. SIGCHLD :: 5 // child process exited
  1024. //SIGABRT :: 6 // abort() called, dont' catch
  1025. SIGPIPE :: 7 // write to a pipe w/no readers
  1026. //SIGFPE :: 8 // floating point exception
  1027. SIGKILL :: 9 // kill a team (not catchable)
  1028. SIGSTOP :: 10 // suspend a thread (not catchable)
  1029. //SIGSEGV :: 11 // segmentation violation (read: invalid pointer)
  1030. SIGCONT :: 12 // continue execution if suspended
  1031. SIGTSTP :: 13 // `stop' special character typed in tty
  1032. SIGALRM :: 14 // an alarm has gone off (see alarm())
  1033. //SIGTERM :: 15 // termination requested
  1034. SIGTTIN :: 16 // read of tty from bg process
  1035. SIGTTOU :: 17 // write to tty from bg process
  1036. SIGUSR1 :: 18 // app defined signal 1
  1037. SIGUSR2 :: 19 // app defined signal 2
  1038. SIGWINCH :: 20 // tty window size changed
  1039. SIGKILLTHR :: 21 // be specific: kill just the thread, not team
  1040. SIGTRAP :: 22 // Trace/breakpoint trap
  1041. SIGPOLL :: 23 // Pollable event
  1042. SIGPROF :: 24 // Profiling timer expired
  1043. SIGSYS :: 25 // Bad system call
  1044. SIGURG :: 26 // High bandwidth data is available at socket
  1045. SIGVTALRM :: 27 // Virtual timer expired
  1046. SIGXCPU :: 28 // CPU time limit exceeded
  1047. SIGXFSZ :: 29 // File size limit exceeded
  1048. SIGBUS :: 30 // access to undefined portion of a memory object
  1049. // NOTE: this is actually defined as `sigaction`, but due to the function with the same name
  1050. // `_t` has been added.
  1051. sigaction_t :: struct {
  1052. using _: struct #raw_union {
  1053. sa_handler: proc "c" (Signal), /* [PSX] signal-catching function or one of the SIG_IGN or SIG_DFL */
  1054. sa_sigaction: proc "c" (Signal, ^siginfo_t, rawptr), /* [PSX] signal-catching function */
  1055. },
  1056. sa_mask: sigset_t, /* [PSX] set of signals to be blocked during execution of the signal handling function */
  1057. sa_flags: SA_Flags, /* [PSX] special flags */
  1058. sa_userdata: rawptr, /* will be passed to the signal handler, BeOS extension */
  1059. }
  1060. SIG_BLOCK :: 1
  1061. SIG_UNBLOCK :: 2
  1062. SIG_SETMASK :: 3
  1063. SA_NOCLDSTOP :: 0x01
  1064. SA_NOCLDWAIT :: 0x02
  1065. SA_RESETHAND :: 0x04
  1066. SA_NODEFER :: 0x08
  1067. SA_RESTART :: 0x10
  1068. SA_ONSTACK :: 0x20
  1069. SA_SIGINFO :: 0x40
  1070. SS_ONSTACK :: 1
  1071. SS_DISABLE :: 2
  1072. MINSIGSTKSZ :: 8192
  1073. SIGSTKSZ :: 16384
  1074. stack_t :: struct {
  1075. ss_sp: rawptr, /* [PSX] stack base or pointer */
  1076. ss_size: c.size_t, /* [PSX] stack size */
  1077. ss_flags: SS_Flags, /* [PSX] flags */
  1078. }
  1079. siginfo_t :: struct {
  1080. si_signo: Signal, /* [PSX] signal number */
  1081. si_code: struct #raw_union { /* [PSX] specific more detailed codes per signal */
  1082. ill: ILL_Code,
  1083. fpe: FPE_Code,
  1084. segv: SEGV_Code,
  1085. bus: BUS_Code,
  1086. trap: TRAP_Code,
  1087. chld: CLD_Code,
  1088. poll: POLL_Code,
  1089. any: Any_Code,
  1090. },
  1091. si_errno: Errno, /* [PSX] errno value associated with this signal */
  1092. si_pid: pid_t, /* sending process ID */
  1093. si_uid: uid_t, /* real user ID of sending process */
  1094. si_addr: rawptr, /* address of faulting instruction */
  1095. si_status: c.int, /* exit value or signal */
  1096. si_band: c.long, /* band event for SIGPOLL */
  1097. si_value: sigval, /* signal value */
  1098. }
  1099. /* any signal */
  1100. SI_USER :: 0 /* signal sent by user */
  1101. SI_QUEUE :: 1 /* signal sent by sigqueue() */
  1102. SI_TIMER :: 2 /* signal sent on timer_settime() timeout */
  1103. SI_ASYNCIO :: 3 /* signal sent on asynchronous I/O completion */
  1104. SI_MESGQ :: 4 /* signal sent on arrival of message on empty message queue */
  1105. /* SIGILL */
  1106. ILL_ILLOPC :: 10 /* illegal opcode */
  1107. ILL_ILLOPN :: 11 /* illegal operand */
  1108. ILL_ILLADR :: 12 /* illegal addressing mode */
  1109. ILL_ILLTRP :: 13 /* illegal trap */
  1110. ILL_PRVOPC :: 14 /* privileged opcode */
  1111. ILL_PRVREG :: 15 /* privileged register */
  1112. ILL_COPROC :: 16 /* coprocessor error */
  1113. ILL_BADSTK :: 17 /* internal stack error */
  1114. /* SIGFPE */
  1115. FPE_INTDIV :: 20 /* integer division by zero */
  1116. FPE_INTOVF :: 21 /* integer overflow */
  1117. FPE_FLTDIV :: 22 /* floating-point division by zero */
  1118. FPE_FLTOVF :: 23 /* floating-point overflow */
  1119. FPE_FLTUND :: 24 /* floating-point underflow */
  1120. FPE_FLTRES :: 25 /* floating-point inexact result */
  1121. FPE_FLTINV :: 26 /* invalid floating-point operation */
  1122. FPE_FLTSUB :: 27 /* subscript out of range */
  1123. /* SIGSEGV */
  1124. SEGV_MAPERR :: 30 /* address not mapped to object */
  1125. SEGV_ACCERR :: 31 /* invalid permissions for mapped object */
  1126. /* SIGBUS */
  1127. BUS_ADRALN :: 40 /* invalid address alignment */
  1128. BUS_ADRERR :: 41 /* nonexistent physical address */
  1129. BUS_OBJERR :: 42 /* object-specific hardware error */
  1130. /* SIGTRAP */
  1131. TRAP_BRKPT :: 50 /* process breakpoint */
  1132. TRAP_TRACE :: 51 /* process trace trap. */
  1133. /* SIGCHLD */
  1134. CLD_EXITED :: 60 /* child exited */
  1135. CLD_KILLED :: 61 /* child terminated abnormally without core dump */
  1136. CLD_DUMPED :: 62 /* child terminated abnormally with core dump */
  1137. CLD_TRAPPED :: 63 /* traced child trapped */
  1138. CLD_STOPPED :: 64 /* child stopped */
  1139. CLD_CONTINUED :: 65 /* stopped child continued */
  1140. /* SIGPOLL */
  1141. POLL_IN :: 70 /* input available */
  1142. POLL_OUT :: 71 /* output available */
  1143. POLL_MSG :: 72 /* input message available */
  1144. POLL_ERR :: 73 /* I/O error */
  1145. POLL_PRI :: 74 /* high priority input available */
  1146. POLL_HUP :: 75 /* device disconnected */
  1147. }