8#include <cosmos/compiler.hxx> 
    9#include <cosmos/io/iovector.hxx> 
   10#include <cosmos/proc/ptrace.hxx> 
   11#include <cosmos/proc/signal.hxx> 
   12#include <cosmos/proc/SigSet.hxx> 
   13#include <cosmos/utils.hxx> 
   18struct user_regs_struct;
 
   19struct user_fpregs_struct;
 
   29struct InputMemoryRegion;
 
   52                CONT              = to_integral(ptrace::Request::CONT),
 
   53                DETACH            = to_integral(ptrace::Request::DETACH),
 
   54                SYSCALL           = to_integral(ptrace::Request::SYSCALL),
 
   55                SINGLESTEP        = to_integral(ptrace::Request::SINGLESTEP),
 
   57                SYSEMU            = to_integral(ptrace::Request::SYSEMU),
 
   58                SYSEMU_SINGLESTEP = to_integral(ptrace::Request::SYSEMU_SINGLESTEP),
 
   60                LISTEN            = to_integral(ptrace::Request::LISTEN)
 
 
   69        ProcessID pid()
 const {
 
   74                return pid() != ProcessID::INVALID;
 
   89                this->request(ptrace::Request::SEIZE, 
nullptr, opts.
raw());
 
 
  111                this->request(ptrace::Request::ATTACH);
 
 
  121                this->request(ptrace::Request::DETACH);
 
 
  138                                mode != RestartMode::LISTEN && signal ? signal->raw() : 
SignalNr{0});
 
 
  157                this->request(ptrace::Request::INTERRUPT);
 
 
  167                this->request(ptrace::Request::SETOPTIONS, 
nullptr, opts.
raw());
 
 
  180                return *(this->request(ptrace::Request::PEEKDATA, addr));
 
 
  185                this->request(ptrace::Request::POKEDATA, addr, value);
 
 
  199                return *(this->request(ptrace::Request::PEEKUSER, offset));
 
 
  208                this->request(ptrace::Request::POKEUSER, offset, value);
 
 
  223                this->request(ptrace::Request::GETREGS, 
nullptr, &out);
 
 
  233                this->request(ptrace::Request::SETREGS, 
nullptr, &out);
 
 
  245                this->request(ptrace::Request::GETFPREGS, 
nullptr, &out);
 
 
  253                this->request(ptrace::Request::SETFPREGS, 
nullptr, &out);
 
 
  266                this->request(ptrace::Request::GETREGSET, type, iovec.asIovec());
 
 
  271                this->request(ptrace::Request::SETREGSET, type, iovec.asIovec());
 
 
  275        void getSigInfo(
SigInfo &info) 
const;
 
  286        void setSigInfo(
const SigInfo &info);
 
  303                this->request(ptrace::Request::GETSIGMASK, 
sizeof(*set.raw()), set.raw());
 
 
  308                this->request(ptrace::Request::SETSIGMASK, 
sizeof(*set.raw()), set.raw());
 
 
  320                const auto pid = getEventMsg();
 
 
  332                const auto status = getEventMsg();
 
 
  345                const auto seccomp_ret_data = getEventMsg();
 
  346                return static_cast<uint16_t
>(seccomp_ret_data);
 
 
  366        void getSeccompFilter(std::vector<struct sock_filter> &instructions, 
const unsigned long prog_index) 
const;
 
  379        void getThreadArea(
struct user_desc &desc) 
const;
 
  386        void setThreadArea(
const struct user_desc &desc);
 
  410                unsigned long msg = 0;
 
  411                this->request(ptrace::Request::GETEVENTMSG, 
nullptr, &msg);
 
 
  415        template <
typename ADDR=
void*, 
typename DATA=
void*>
 
  416        std::optional<long> request(
const ptrace::Request req, ADDR addr = 
nullptr, DATA data = 
nullptr)
 const {
 
  421                return cosmos::ptrace::trace(req, m_pid,
 
  422                                const_cast<void*
>(
reinterpret_cast<const void*
>(addr)),
 
  423                                const_cast<void*
>(
reinterpret_cast<const void*
>(data)));
 
  430        template <
typename DATA=
void*>
 
  431        std::optional<long> request(
const ptrace::Request req, std::nullptr_t, DATA data = 
nullptr)
 const {
 
  432                return request(req, 
static_cast<void*
>(
nullptr), data);
 
 
A typesafe bit mask representation using class enums.
EnumBaseType raw() const
Returns the raw bitfield integer.
Signal information struct used when receiving signals.
A bit set of signal numbers for use in system calls.
Thin wrapper class around the ptrace() system call.
void setFloatRegisters(const struct user_fpregs_struct &out)
Modify the tracee's floating point registers.
uint16_t getSeccompRetDataEventMsg() const
Returns the SECCOMP_RET_DATA in the context of a ptrace-event-stop.
RestartMode
Different ways to restart a tracee.
void setSigMask(const SigSet &set)
Change the tracee's mask of blocked signals.
void setRegisters(const struct user_regs_struct &out)
Modify the tracee's general purpose registers.
ExitStatus getExitEventMsg() const
Returns the exit code of the tracee in the context of a ptrace-event-stop.
void getRegisterSet(const ptrace::RegisterType type, InputMemoryRegion &iovec) const
Retrieve a set of registers from the tracee.
ProcessID getPIDEventMsg() const
Returns the PID of a newly created child of the tracee in the context of a ptrace-event-stop.
void interrupt()
Interrupt the tracee.
void setRegisterSet(const ptrace::RegisterType type, OutputMemoryRegion &iovec)
Modify a set of registers in the tracee.
void pokeData(const long *addr, long value)
Write one word of data into the tracee's memory.
void seize(const ptrace::Opts opts)
Seize a tracee.
long peekData(const long *addr) const
Read one word of data from the tracee's memory.
void setOptions(const ptrace::Opts opts)
Set tracing options for the given tracee.
long peekUser(const long *offset) const
Read one word of data from the tracee's user area.
void attach()
Attach to a process, making it a tracee.
void detach()
Detach from and restart the tracee.
void pokeUser(const long *offset, long value)
Change one word of data in the tracee's user area.
void getSigMask(SigSet &set) const
Obtain the tracee's mask of blocked signals.
void getFloatRegisters(struct user_fpregs_struct &out) const
Copy the tracee's floating point registers into the provided structure.
void restart(const RestartMode mode, const std::optional< Signal > signal={})
Continues a traced process, optionally delivering signal.
unsigned long getEventMsg() const
Returns the current event message for a ptrace-event-stop.
void getRegisters(struct user_regs_struct &out) const
Copy the tracee's general purpose registers into the provided structure.
Wrapper around data structure used with ptrace::Request::PEEKSIGINFO.
ExitStatus
Represents an exit status code from a child process.
SignalNr
A primitive signal number specification.
Request
Basic requests that can be passed to the ptrace() system call.
RegisterType
Different types of register sets that can be read from a tracee via Request::GETREGSET.
IOMemoryRegion for output (write) operations.
Wrapper around data structure used with ptrace::Request::GET_SYSCALL_INFO.