2019-04-22 16:44:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/CircularQueue.h>
|
2019-07-09 12:46:23 +00:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2019-04-22 16:44:45 +00:00
|
|
|
#include <Kernel/UnixTypes.h>
|
|
|
|
|
2019-04-28 13:02:55 +00:00
|
|
|
class ProcessTracer : public File {
|
2019-04-22 16:44:45 +00:00
|
|
|
public:
|
2019-06-21 16:37:47 +00:00
|
|
|
static NonnullRefPtr<ProcessTracer> create(pid_t pid) { return adopt(*new ProcessTracer(pid)); }
|
2019-04-28 13:02:55 +00:00
|
|
|
virtual ~ProcessTracer() override;
|
2019-04-22 16:44:45 +00:00
|
|
|
|
|
|
|
bool is_dead() const { return m_dead; }
|
|
|
|
void set_dead() { m_dead = true; }
|
|
|
|
|
2019-06-07 07:36:51 +00:00
|
|
|
virtual bool can_read(FileDescription&) const override { return !m_calls.is_empty() || m_dead; }
|
2019-07-03 19:17:35 +00:00
|
|
|
virtual int read(FileDescription&, u8*, int) override;
|
2019-04-28 13:02:55 +00:00
|
|
|
|
2019-06-07 07:36:51 +00:00
|
|
|
virtual bool can_write(FileDescription&) const override { return true; }
|
2019-07-03 19:17:35 +00:00
|
|
|
virtual int write(FileDescription&, const u8*, int) override { return -EIO; }
|
2019-04-28 13:02:55 +00:00
|
|
|
|
2019-06-07 07:36:51 +00:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-04-22 16:44:45 +00:00
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
void did_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3, u32 result);
|
2019-04-22 16:44:45 +00:00
|
|
|
pid_t pid() const { return m_pid; }
|
|
|
|
|
|
|
|
private:
|
2019-04-28 13:02:55 +00:00
|
|
|
virtual const char* class_name() const override { return "ProcessTracer"; }
|
2019-04-22 16:44:45 +00:00
|
|
|
explicit ProcessTracer(pid_t);
|
|
|
|
|
|
|
|
struct CallData {
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 function;
|
|
|
|
u32 arg1;
|
|
|
|
u32 arg2;
|
|
|
|
u32 arg3;
|
|
|
|
u32 result;
|
2019-04-22 16:44:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pid_t m_pid;
|
|
|
|
bool m_dead { false };
|
|
|
|
CircularQueue<CallData, 200> m_calls;
|
|
|
|
};
|