commit e63fc5f72ec73a07af4fe2b67e541cc06768f593
parent dcc798b0778075e952183f4b814feed6620f8f89
Author: Sebastian <sebastian@sebsite.pw>
Date: Sat, 4 Feb 2023 00:50:19 -0500
unix::signal: add code enum
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 66 insertions(+), 3 deletions(-)
diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha
@@ -151,13 +151,76 @@ export type siginfo = union {
// [[errors::errno]] to convert to a Hare-native error.
errno: rt::errno,
// The signal code, if any.
- // TODO: Add enum type for this
- code: int,
+ code: code,
},
// Pads the structure out to the length used by the kernel; do not use.
_si_pad: [128 - 3 * size(int)]u8,
};
+// A code indicating why a signal was sent.
+export type code = enum int {
+ USER = 0, // sent by userspace program (kill)
+ KERNEL = 128, // sent by kernel
+ QUEUE = -1, // sent by sigqueue
+ TIMER = -2, // generated by expiration of a timer
+ MESQ = -3, // generated by arrival of a message on an empty queue
+ ASYNCIO = -4, // generated by completion of an asynchronous I/O request
+ SIGIO = -5,
+ TKILL = -6, // sent by userspace program (tkill, tgkill)
+ ASYNCNL = -60,
+
+ ILLOPC = 1, // SIGILL: illegal opcode
+ ILLOPN = 2, // SIGILL: illegal operand
+ ILLADR = 3, // SIGILL: illegal addressing mode
+ ILLTRP = 4, // SIGILL: illegal trap
+ PRVOPC = 5, // SIGILL: privileged opcode
+ PRVREG = 6, // SIGILL: privileged register
+ COPROC = 7, // SIGILL: coprocessor error
+ BADSTK = 8, // SIGILL: internal stack error
+
+ INTDIV = 1, // SIGFPE: integer divide by zero
+ INTOVF = 2, // SIGFPE: integer overflow
+ FLTDIV = 3, // SIGFPE: floating-point divide by zero
+ FLTOVF = 4, // SIGFPE: floating-point overflow
+ FLTUND = 5, // SIGFPE: floating-point underflow
+ FLTRES = 6, // SIGFPE: floating-point inexact result
+ FLTINV = 7, // SIGFPE: invalid floating-point operation
+ FLTSUB = 8, // SIGFPE: subscript out of range
+
+ MAPERR = 1, // SIGSEGV: address not mapped to object
+ ACCERR = 2, // SIGSEGV: invalid permissions for mapped object
+ BNDERR = 3, // SIGSEGV: failed address bound checks
+ PKUERR = 4, // SIGSEGV: access was denied by memory protection keys
+ MTEAERR = 8, // SIGSEGV
+ MTESERR = 9, // SIGSEGV
+
+ ADRALN = 1, // SIGBUS: invalid address alignment
+ ADRERR = 2, // SIGBUS: nonexistent physical address
+ OBJERR = 3, // SIGBUS: object-specific hardware error
+ MCEERR_AR = 4, // SIGBUS: hardware memory error consumed on a machine check; action required
+ MCEERR_AO = 5, // SIGBUS: hardware memory error detected in process but not consumed; action optional
+
+ BRKPT = 1, // SIGTRAP: process breakpoint
+ TRACE = 2, // SIGTRAP: process trace trap
+ BRANCH = 3, // SIGTRAP: process taken branch trap
+ HWBKPT = 4, // SIGTRAP: hardware breakpoint/watchpoint
+ UNK = 5, // SIGTRAP
+
+ EXITED = 1, // SIGCHLD: child exited
+ KILLED = 2, // SIGCHLD: child terminated abnormally without a core file
+ DUMPED = 3, // SIGCHLD: child terminated abnormally with a core file
+ TRAPPED = 4, // SIGCHLD: traced child has trapped
+ STOPPED = 5, // SIGCHLD: child has stopped
+ CONTINUED = 6, // SIGCHLD: stopped child has continued
+
+ IN = 1, // SIGPOLL: data input available
+ OUT = 2, // SIGPOLL: output buffers available
+ MSG = 3, // SIGPOLL: input message available
+ ERR = 4, // SIGPOLL: I/O error
+ PRI = 5, // SIGPOLL: high priority input available
+ HUP = 6, // SIGPOLL: device disconnected
+};
+
// Flags used to configure the behavior of a signal handler.
export type flag = enum int {
// For use with [[SIGCHLD]]. Prevents notifications when child processes
@@ -221,7 +284,7 @@ export fn read(fd: io::file) (siginfo | errors::error) = {
return siginfo {
signo = si.ssi_signo: signal,
errno = si.ssi_errno: rt::errno,
- code = si.ssi_code,
+ code = si.ssi_code: code,
...
};
};