14#include <cosmos/error/errno.hxx>
15#include <cosmos/fs/types.hxx>
16#include <cosmos/io/types.hxx>
17#include <cosmos/memory.hxx>
18#include <cosmos/proc/ptrace.hxx>
19#include <cosmos/proc/signal.hxx>
20#include <cosmos/proc/types.hxx>
21#include <cosmos/time/types.hxx>
22#include <cosmos/utils.hxx>
119 explicit CustomData(
union sigval val) : m_val{val} {}
127 return m_val.sival_int;
138 return m_val.sival_ptr;
179 enum class TimerID :
int {};
222 OPERAND = ILL_ILLOPN,
223 ADDRESS = ILL_ILLADR,
225 PRIV_OP = ILL_PRVOPC,
226 PRIV_REG = ILL_PRVREG,
228 BAD_STACK = ILL_BADSTK,
229 BAD_IADDR = ILL_BADIADDR,
244 INT_DIV_ZERO = FPE_INTDIV,
245 INT_OVERFLOW = FPE_INTOVF,
246 FLOAT_DIV_ZERO = FPE_FLTDIV,
247 FLOAT_OVERFLOW = FPE_FLTOVF,
248 FLOAT_UNDERFLOW = FPE_FLTUND,
249 FLOAT_INEXACT = FPE_FLTRES,
250 FLOAT_INVALID = FPE_FLTINV,
251 FLOAT_SUB_RANGE = FPE_FLTSUB,
252 FLOAT_UNKNOWN = FPE_FLTUNK,
253 FLOAT_CONDTRAP = FPE_CONDTRAP,
268 MAP_ERROR = SEGV_MAPERR,
269 ACCESS_ERROR = SEGV_ACCERR,
270 BOUND_ERROR = SEGV_BNDERR,
271 PROT_KEY_ERROR = SEGV_PKUERR,
272 ACCESS_ADI = SEGV_ACCADI,
273 MCD_DISRUPT = SEGV_ADIDERR,
274 PRECISE_MCD = SEGV_ADIPERR,
275 ASYNC_MTE = SEGV_MTEAERR,
276 SYNC_MTE = SEGV_MTESERR,
277 CPROT_ERROR = SEGV_CPERR,
281 void *lower =
nullptr;
282 void *upper =
nullptr;
286 enum class ProtectionKey :
unsigned int {
296 std::optional<ProtectionKey>
key;
305 ALIGNMENT = BUS_ADRALN,
306 NOT_EXISTING = BUS_ADRERR,
307 OBJECT_ERROR = BUS_OBJERR,
308 MCE_ACTION_REQUIRED = BUS_MCEERR_AR,
309 MCE_ACTION_OPTIONAL = BUS_MCEERR_AO,
330 TRAPPED = CLD_TRAPPED,
331 STOPPED = CLD_STOPPED,
332 CONTINUED = CLD_CONTINUED
338 bool exited()
const {
return event == Event::EXITED; }
341 bool killed()
const {
return event == Event::KILLED; }
344 bool dumped()
const {
return event == Event::DUMPED; }
347 bool trapped()
const {
return event == Event::TRAPPED; }
350 bool continued()
const {
return event == Event::CONTINUED; }
353 bool stopped()
const {
return event == Event::STOPPED; }
357 return exited() && *status == ExitStatus::SUCCESS;
362 return event == Event::KILLED ||
363 event == Event::DUMPED ||
364 event == Event::STOPPED ||
365 event == Event::CONTINUED;
370 return event != Event::INVALID;
374 event = Event::INVALID;
375 child.pid = ProcessID::INVALID;
376 status = std::nullopt;
377 signal = std::nullopt;
428 SECCOMP = SYS_SECCOMP,
507 Source source()
const;
520 return m_raw.si_code >= 0;
524 bool isFaultSignal()
const;
527 std::optional<const UserSigData> userSigData()
const;
530 std::optional<const QueueSigData> queueSigData()
const;
533 std::optional<const MsgQueueData> msgQueueData()
const;
536 std::optional<const TimerData> timerData()
const;
542 std::optional<const SysData> sysData()
const;
548 std::optional<const ChildData> childData()
const;
554 std::optional<const PollData> pollData()
const;
560 std::optional<const IllData> illData()
const;
566 std::optional<const FPEData> fpeData()
const;
572 std::optional<const SegfaultData> segfaultData()
const;
578 std::optional<const BusData> busData()
const;
585 const siginfo_t* raw()
const {
600 return Errno{m_raw.si_errno};
603 ProcessCtx procCtx()
const {
604 return ProcessCtx{pid(), uid()};
612 return UserID{m_raw.si_uid};
Signal information struct used when receiving signals.
bool isTrustedSource() const
Returns whether the signal was sent from a trusted source (i.e. the kernel).
Source
The source of a signal.
Signal sigNr() const
Returns the signal number that occurred.
Errno error() const
Returns an error code that is generally unused on Linux (always 0).
SigInfo(const no_init_t)
Leaves the underlying data structure uninitialized.
void clear()
Zeroes out the low level siginfo_t data structure.
SigInfo()
Creates a zero-initialized SigInfo wrapper.
Represents a POSIX signal number and offers a minimal API around it.
Errno
Strong enum type representing errno error constants.
FileNum
Primitive file descriptor.
@ OUTPUT
writing is possible.
@ INPUT
there is data to read.
@ ERROR
an error condition exists (also occurs on the write end of a pipe, when the read end has been closed)...
@ PRIORITY
an exceptional condition exists: out-of-band data on TCP socket, PTY master has seen a state change o...
void zero_object(T &obj)
Completely overwrites the given object with zeroes.
SignalNr
A primitive signal number specification.
Arch
System call ABI architecture.
Additional data delivered with SIGBUS signals.
Reason reason
The reason why SIGBUS was delivered.
Reason
Different reasons for delivering a SIGBUS signal.
std::optional< short > addr_lsb
For Reason::MCE_ACTION_REQUIRED and Reason::MCE_ACTION_OPTIONAL this contains the least significant b...
Additional data found in SigInfo with SIGCHILD.
bool dumped() const
Returns whether the child dumped core due to a signal.
bool continued() const
Returns whether the child continued due to a signal.
std::optional< ExitStatus > status
Contains the process's exit status, if applicable.
bool valid() const
Returns whether the structure contains valid information.
std::optional< Signal > signal
Contains the signal number that caused the child process to change state.
bool exited() const
Returns whether the child exited.
bool stopped() const
Returns whether the child stopped.
bool killed() const
Returns whether the child was killed by a signal.
Event event
The kind of child process event that occurred.
std::optional< ClockTicks > system_time
The CPU time the child spent in kernel space.
bool signaled() const
Returns whether the child received a signal.
bool exitedSuccessfully() const
Returns whether the child exited and had an exit status of 0.
ProcessCtx child
the PID and its real user ID the signal is about.
Event
Types of SIGCHLD events that can occur.
bool trapped() const
Returns true if the child entered a tracing trap.
std::optional< ClockTicks > user_time
The CPU time the child spent in user space.
Additional custom SigInfo data.
int asInt() const
Returns custom data sent with the signal.
void * asPtr() const
Returns custom data sent with the signal.
Extra data delivered with SIGFPE signals.
Reason
Different reasons for delivering floating-point exceptions.
Reason reason
The reason why SIGFPE was delivered.
Additional data found in SigInfo for one of the memory fault / trap signals.
void * addr
The address of the fault / trap.
Additional data delivered with SIGILL signals.
Reason reason
The reason why SIGILL was delivered.
Reason
Different reasons for delivering a SIGILL signal.
Additional data found in SigInfo with Source::MESGQ.
ProcessCtx msg_sender
The PID and real user ID of the process that sent a message queue message.
CustomData data
Custom data supplied via mq_notify().
Additional data found in SigInfo with SIGPOLL.
Reason
Different reasons for delivering SIGPOLL.
PollEvents events
The I/O events that occurred for fd.
FileNum fd
The file descriptor for which the event occurred.
Information about the process a signal is from or about.
ProcessID pid
PID of the process.
UserID uid
real user ID of the process
Additional data found in SigInfo with Source::QUEUE.
ProcessCtx sender
The PID and real user ID of the sending process.
CustomData data
Custom data supplied along with the signal.
Additional data delivered with SIGSEGV signals.
Reason
Different reasons for delivering a SIGSEGV signal.
Reason reason
The reason why SIGSEGV was delivered.
std::optional< Bound > bound
For Reason::BOUND_ERROR this contains the lower and upper bound.
std::optional< ProtectionKey > key
For Reason::PROT_KEY_ERROR this contains the protection key that caused the fault.
Additional data found in SigInfo delivered with SIGSYS.
Reason reason
Why SIGSYS was delivered.
Reason
Different reasons for delivering SIGYS.
void * call_addr
The calling user space instruction.
Errno error
The SECCOMP_RET_DATA portion or Errno::SUCCESS if seccomp is not involved.
int call_nr
The system call number.
ptrace::Arch arch
The system call ABI.
Additional data found in SigInfo with Source::TIMER.
int overrun
The timer overrun count.
TimerID id
The ID of the timer which expired.
Additional data found in SigInfo with Source::USER.
ProcessCtx sender
The PID and real user ID of the sending process.
Type used to invoke constructors that explicitly don't zero-initialize low level data structures.