2#include <cosmos/error/ApiError.hxx>
3#include <cosmos/io/ILogger.hxx>
4#include <cosmos/proc/process.hxx>
7#include <clues/AutoAttachedTracee.hxx>
8#include <clues/logger.hxx>
9#include <clues/syscalls/process.hxx>
10#include <clues/sysnrs/generic.hxx>
16bool shares_file_descriptors_with_parent(
const SystemCall &sc) {
35 case SystemCallNr::CLONE3: {
40 return args->flags()[cosmos::CloneFlag::SHARE_FILES];
46 case SystemCallNr::CLONE: {
49 const auto flags = clone_sc.flags.flags();
51 return flags[cosmos::CloneFlag::SHARE_FILES];
53 case SystemCallNr::FORK:
54 case SystemCallNr::VFORK:
return false;
56 LOG_ERROR(
"PTRACE auto-attach event but last system call is not recognized?!");
66 Tracee{engine, consumer, parent} {
70 const SystemCall &sc) {
75 if (!shares_file_descriptors_with_parent(sc)) {
80AutoAttachedTracee::~AutoAttachedTracee() {
83 }
catch (
const cosmos::CosmosError &ce) {
84 LOG_DEBUG(
"Couldn't detach from PID " << cosmos::to_integral(
m_ptrace.pid()) <<
":\n\n" << ce.what());
AutoAttachedTracee(Engine &engine, EventConsumer &consumer, TraceePtr parent)
Create a traced process object by attaching to the given process ID.
void configure(const cosmos::ProcessID pid, const cosmos::ptrace::Event event, const SystemCall &sc)
Sets the given process ID as the process to be traced.
Callback interface for consumers of tracing events.
Access to System Call Data.
SystemCallNr callNr() const
Returns the system call table number for this system call.
void setPID(const cosmos::ProcessID tracee)
Sets the tracee PID.
@ WAIT_FOR_ATTACH_STOP
we're still waiting for the PTRACE_INTERRUPT event stop.
bool detach()
Attempt to detach the Tracee.
Tracee(Engine &engine, EventConsumer &consumer, TraceePtr sibling=nullptr)
Flags m_flags
These keep track of various state on the tracer side.
cosmos::Tracee m_ptrace
libcosmos API for the Tracee.
const std::optional< cosmos::CloneArgs > & args() const
Returns an optional containing the cosmos::CloneArgs structure, if available.
item::CloneArgs cl_args
Combined clone arguments.
Wrapper for the clone() and clone2() system calls.