2#include <cosmos/error/UsageError.hxx>
3#include <cosmos/proc/SigInfo.hxx>
4#include <cosmos/proc/signal.hxx>
10static_assert(
sizeof(SigInfo) ==
sizeof(siginfo_t),
"SigInfo size mismatch");
13 const std::initializer_list<Signal> SPECIAL_SIGS{
14 signal::FPE, signal::BUS, signal::ILL, signal::SEGV,
15 signal::BUS, signal::TRAP, signal::CHILD, signal::POLL,
25 return Source{m_raw.si_code};
43 signal::ILL, signal::FPE, signal::SEGV,
44 signal::BUS, signal::TRAP});
74 TimerData::TimerID{m_raw.si_timerid},
83 if (
sigNr() == signal::CHILD) {
85 const auto event = Event{m_raw.si_code};
96 const auto is_waitid_res =
error() == Errno::INVALID_ARG;
101 event == Event::EXITED ? std::make_optional(
ExitStatus{m_raw.si_status}) : std::nullopt,
102 event == Event::EXITED ? std::nullopt : std::make_optional(
Signal{
SignalNr{m_raw.si_status}}),
103 is_waitid_res ? std::nullopt : std::make_optional(
ClockTicks{m_raw.si_utime}),
104 is_waitid_res ? std::nullopt : std::make_optional(
ClockTicks{m_raw.si_stime})
112 if (
sigNr() == signal::BAD_SYS) {
127 if (
sigNr() == signal::IO_EVENT ||
sigNr() == signal::POLL) {
141 if (
sigNr() == signal::ILL) {
152 if (
sigNr() == signal::FPE) {
163 if (
sigNr() == signal::SEGV) {
165 const auto reason = Reason{m_raw.si_code};
169 reason == Reason::BOUND_ERROR ?
172 reason == Reason::PROT_KEY_ERROR ?
173 std::make_optional(SegfaultData::ProtectionKey{m_raw.si_pkey}) :
182 if (
sigNr() == signal::BUS) {
184 const auto reason = Reason{m_raw.si_code};
188 in_list(reason, {Reason::MCE_ACTION_REQUIRED, Reason::MCE_ACTION_OPTIONAL}) ?
189 std::make_optional(m_raw.si_addr_lsb) :
std::optional< const ChildData > childData() const
Returns signal::CHILD specific data.
bool isTrustedSource() const
Returns whether the signal was sent from a trusted source (i.e. the kernel).
Source
The source of a signal.
@ KERNEL
sent by the kernel.
@ MESGQ
POSIX message queue state changed.
@ TIMER
POSIX timer expired.
@ QUEUE
sent from user space via sigqueue().
Signal sigNr() const
Returns the signal number that occurred.
std::optional< const QueueSigData > queueSigData() const
Returns the Source::QUEUE specific data.
Errno error() const
Returns an error code that is generally unused on Linux (always 0).
std::optional< const BusData > busData() const
Returns SIGBUS specific data.
bool isFaultSignal() const
Returns whether the signal is one of the fault signals.
std::optional< const SysData > sysData() const
Returns signal::BAD_SYS specific data.
std::optional< const TimerData > timerData() const
Returns the Source::TIMER specific data.
std::optional< const PollData > pollData() const
Returns signal::POLL specific data.
std::optional< const IllData > illData() const
Returns SIGILL specific data.
std::optional< const FPEData > fpeData() const
Returns SIGFPE specific data.
std::optional< const MsgQueueData > msgQueueData() const
Returns the Source::MSGQ specific data.
Source source() const
Returns the source of the signal.
std::optional< const SegfaultData > segfaultData() const
Returns SIGSEGV specific data.
std::optional< const UserSigData > userSigData() const
Returns the Source::USER specific data.
Represents a POSIX signal number and offers a minimal API around it.
FileNum
Primitive file descriptor.
ExitStatus
Represents an exit status code from a child process.
SignalNr
A primitive signal number specification.
Arch
System call ABI architecture.
Additional data delivered with SIGBUS signals.
Reason
Different reasons for delivering a SIGBUS signal.
Additional data found in SigInfo with SIGCHILD.
Event
Types of SIGCHLD events that can occur.
Additional custom SigInfo data.
Extra data delivered with SIGFPE signals.
Reason
Different reasons for delivering floating-point exceptions.
Additional data delivered with SIGILL signals.
Reason
Different reasons for delivering a SIGILL signal.
Additional data found in SigInfo with Source::MESGQ.
Additional data found in SigInfo with SIGPOLL.
Reason
Different reasons for delivering SIGPOLL.
Additional data found in SigInfo with Source::QUEUE.
Additional data delivered with SIGSEGV signals.
Reason
Different reasons for delivering a SIGSEGV signal.
Additional data found in SigInfo delivered with SIGSYS.
Reason
Different reasons for delivering SIGYS.
Additional data found in SigInfo with Source::TIMER.
Additional data found in SigInfo with Source::USER.
ClockTicks
Type used to express time in clock ticks unit in some APIs.
bool in_list(const T &v, const std::initializer_list< T > &l)
Checks whether the value v is found in the given list of values l.