2#include <clues/format.hxx>
3#include <clues/items/signal.hxx>
4#include <clues/logger.hxx>
5#include <clues/macros.h>
6#include <clues/private/kernel/sigaction.hxx>
7#include <clues/sysnrs/generic.hxx>
8#include <clues/Tracee.hxx>
11#include <cosmos/formatting.hxx>
12#include <cosmos/proc/signal.hxx>
14namespace clues::item {
17 switch (cosmos::to_integral(m_op)) {
18 CASE_ENUM_TO_STR(SIG_BLOCK);
19 CASE_ENUM_TO_STR(SIG_UNBLOCK);
20 CASE_ENUM_TO_STR(SIG_SETMASK);
21 default:
return cosmos::sprintf(
"unknown (%d)",
valueAs<int>());
26 if (
m_val == Word::ZERO &&
m_call->callNr() == SystemCallNr::FCNTL) {
31 return "0 (default SIGIO)";
40 const auto raw = m_sigaction->raw();
48 if (m_sigaction->getFlags()[cosmos::SigAction::Flag::SIGINFO]) {
49 ss << format::pointer(
ForeignPtr{
reinterpret_cast<uintptr_t
>(raw->sa_sigaction)});
51 if (raw->sa_handler == SIG_IGN)
53 else if (raw->sa_handler == SIG_DFL)
56 ss << format::pointer(
ForeignPtr{
reinterpret_cast<uintptr_t
>(raw->sa_handler)});
59 ss <<
", mask=" << format::signal_set(m_sigaction->mask()) <<
", flags="
60 << format::saflags(m_sigaction->getFlags().raw()) <<
", restorer="
61 << format::pointer(
ForeignPtr{
reinterpret_cast<uintptr_t
>(raw->sa_restorer)}) <<
"}";
68template <
typename KERN_SIGACTION>
69void convert_to(
const KERN_SIGACTION &kern_act, cosmos::SigAction &action) {
70 auto raw_act =
const_cast<struct sigaction*
>(
static_cast<const cosmos::SigAction&
>(action).raw());
71 auto &mask = action.mask();
74 if constexpr (
sizeof(kern_act.mask) > 4) {
75 *mask.raw() = kern_act.mask;
78 if constexpr (
sizeof(kern_act.mask) == 4) {
84 mask.raw()->__val[0] = kern_act.mask;
87 using RestorerPtr = void (*)();
88 using HandlerPtr = void (*)(int);
99 raw_act->sa_restorer = (RestorerPtr)(uintptr_t)kern_act.restorer;
100 raw_act->sa_handler = (HandlerPtr)(uintptr_t)kern_act.handler;
101 raw_act->sa_flags =
static_cast<int>(kern_act.flags);
105template <
typename KERN_SIGACTION>
106void fetch_sigaction(
const ForeignPtr ptr,
const Tracee &proc, std::optional<cosmos::SigAction> &action) {
107 KERN_SIGACTION kern_act;
109 if (!proc.readStruct(ptr, kern_act)) {
114 convert_to(kern_act, *action);
121 if (isOut() && proc.isEnterStop()) {
127 m_sigaction = cosmos::SigAction{};
130 switch (
m_call->callNr()) {
131 case SystemCallNr::RT_SIGACTION: {
132 if (
m_call->is32BitEmulationABI()) {
133 fetch_sigaction<kernel_sigaction32>(asPtr(), proc, m_sigaction);
135 fetch_sigaction<kernel_sigaction>(asPtr(), proc, m_sigaction);
138 }
case SystemCallNr::SIGACTION: {
139 fetch_sigaction<kernel_old_sigaction>(asPtr(), proc, m_sigaction);
143 LOG_WARN(
"Unexpected system call encountered in SigActionParameter");
150 if (proc.isEnterStop() && isOut()) {
156 m_sigset = cosmos::SigSet{};
159 if (
m_call->callNr() == SystemCallNr::SIGPROCMASK) {
167 m_sigset->raw()->__val[0] = mask;
169 if (!proc.
readStruct(asPtr(), *m_sigset->raw())) {
178 return format::signal_set(*m_sigset);
const SystemCall * m_call
The system call context this item part of.
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
Word m_val
The raw register value for the item.
Base class for traced processes.
bool readStruct(const ForeignPtr addr, T &out) const
Reads a system call struct from the tracee's address space into out.
std::string str() const override
Returns a human readable string representation of the item.
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
std::string str() const override
Returns a human readable string representation of the item.
std::string str() const override
Returns a human readable string representation of the item.
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
std::string str() const override
Returns a human readable string representation of the item.
ForeignPtr
Strongly typed opaque pointer to tracee memory.