11#include <cosmos/error/RuntimeError.hxx>
12#include <cosmos/error/UsageError.hxx>
13#include <cosmos/io/iovector.hxx>
14#include <cosmos/proc/ptrace.hxx>
15#include <cosmos/types.hxx>
16#include <cosmos/utils.hxx>
19#include <clues/regs/traits.hxx>
20#include <clues/sysnrs/fwd.hxx>
21#include <clues/types.hxx>
36 static constexpr auto ABI = abi;
37 using register_t = ABIRegisterData::register_t;
41 explicit RegisterSet(
const cosmos::no_init_t &) {
49 void fillIov(cosmos::InputMemoryRegion &iov) {
52 static_assert(
sizeof(
m_regs) ==
sizeof(
typename ABIRegisterData::register_t) * ABIRegisterData::NUM_REGS);
54 iov.setLength(
sizeof(
m_regs));
58 void iovFilled(
const cosmos::InputMemoryRegion &iov) {
59 if (iov.getLength() <
sizeof(
m_regs)) {
60 throw cosmos::RuntimeError{
"received incomplete register set"};
66 return cosmos::ptrace::RegisterType::GENERAL_PURPOSE;
88 auto pars =
m_regs.syscallPars();
89 if (number >= pars.size()) {
90 throw cosmos::UsageError{
"invalid system call parameter nr."};
116template <clues::ABI abi>
Holds a set of registers for the given ABI.
void fillIov(cosmos::InputMemoryRegion &iov)
Prepares iov for doing a ptrace system call of type ptrace::Request::GETREGSET.
register_t syscallRes() const
Returns the system call result on exit from a syscall.
SystemCallNr syscallNr() const
Returns the generic SystemCallNr on entry to a syscall.
register_t syscallParameter(const size_t number) const
Returns the content of the given system call parameter register.
auto & raw() const
Provides access to the raw RegisterData based data structure.
void iovFilled(const cosmos::InputMemoryRegion &iov)
Verify data received from a ptrace system call of type ptrace::Request::GETREGSET.
RegisterDataTraits< abi >::type ABIRegisterData
This is the concrete type holding the raw register data for this ABI.
auto abiSyscallNr() const
Returns the ABI-specific system call number on entry to a syscall.
ABIRegisterData m_regs
The raw data structure holding the ABI specific register data.
static constexpr cosmos::ptrace::RegisterType registerType()
The type to pass to ptrace::Request::GETREGSET for obtaining the general purpose registers.
std::variant< RegisterSet< ABI::I386 >, RegisterSet< ABI::X86_64 >, RegisterSet< ABI::X32 >, RegisterSet< ABI::AARCH64 > > AnyRegisterSet
A variant to hold any of the ABI-specific RegisterSet types.
SystemCallNr
Abstract system call number usable across architectures and ABIs.
clues::SystemCallNr to_generic(const SystemCallNrAARCH64 nr)
Convert the native system call nr. into its generic representation.
std::nullptr_t type
the proper RegisterData type for this ABI.