2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-04-22 19:44:45 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
#include <AK/Optional.h>
|
2021-05-13 07:44:07 +03:00
|
|
|
#include <AK/OwnPtr.h>
|
2021-12-29 02:41:58 +03:00
|
|
|
#include <Kernel/Arch/RegisterState.h>
|
2021-08-14 20:47:37 +03:00
|
|
|
#include <Kernel/Forward.h>
|
2023-04-29 21:37:40 +03:00
|
|
|
#include <sys/arch/regs.h>
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
class ThreadTracer {
|
2019-04-22 19:44:45 +03:00
|
|
|
public:
|
2021-11-08 02:51:39 +03:00
|
|
|
static ErrorOr<NonnullOwnPtr<ThreadTracer>> try_create(ProcessID tracer) { return adopt_nonnull_own_or_enomem(new (nothrow) ThreadTracer(tracer)); }
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-08-08 18:32:34 +03:00
|
|
|
ProcessID tracer_pid() const { return m_tracer_pid; }
|
2021-11-07 00:06:08 +03:00
|
|
|
bool has_pending_signal(u32 signal) const { return (m_pending_signals & (1 << (signal - 1))) != 0; }
|
2020-03-28 11:47:16 +03:00
|
|
|
void set_signal(u32 signal) { m_pending_signals |= (1 << (signal - 1)); }
|
|
|
|
void unset_signal(u32 signal) { m_pending_signals &= ~(1 << (signal - 1)); }
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
bool is_tracing_syscalls() const { return m_trace_syscalls; }
|
|
|
|
void set_trace_syscalls(bool val) { m_trace_syscalls = val; }
|
2019-04-28 16:02:55 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
void set_regs(RegisterState const& regs);
|
|
|
|
void set_regs(PtraceRegisters const& regs) { m_regs = regs; }
|
2020-03-28 11:47:16 +03:00
|
|
|
bool has_regs() const { return m_regs.has_value(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
PtraceRegisters const& regs() const
|
2020-03-28 11:47:16 +03:00
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(m_regs.has_value());
|
2020-03-28 11:47:16 +03:00
|
|
|
return m_regs.value();
|
|
|
|
}
|
2019-04-28 16:02:55 +03:00
|
|
|
|
2021-09-07 15:48:13 +03:00
|
|
|
private:
|
2020-08-08 18:32:34 +03:00
|
|
|
explicit ThreadTracer(ProcessID);
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-08-08 18:32:34 +03:00
|
|
|
ProcessID m_tracer_pid { -1 };
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
// This is a bitmap for signals that are sent from the tracer to the tracee
|
|
|
|
// TODO: Since we do not currently support sending signals
|
|
|
|
// to the tracee via PT_CONTINUE, this bitmap is always zeroed
|
|
|
|
u32 m_pending_signals { 0 };
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2020-03-28 11:47:16 +03:00
|
|
|
bool m_trace_syscalls { false };
|
|
|
|
Optional<PtraceRegisters> m_regs;
|
2019-04-22 19:44:45 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|