2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-04-22 19:44:45 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/CircularQueue.h>
|
2019-07-09 15:46:23 +03:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2019-04-22 19:44:45 +03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
|
|
|
|
2019-04-28 16:02:55 +03:00
|
|
|
class ProcessTracer : public File {
|
2019-04-22 19:44:45 +03:00
|
|
|
public:
|
2019-06-21 19:37:47 +03:00
|
|
|
static NonnullRefPtr<ProcessTracer> create(pid_t pid) { return adopt(*new ProcessTracer(pid)); }
|
2019-04-28 16:02:55 +03:00
|
|
|
virtual ~ProcessTracer() override;
|
2019-04-22 19:44:45 +03:00
|
|
|
|
|
|
|
bool is_dead() const { return m_dead; }
|
|
|
|
void set_dead() { m_dead = true; }
|
|
|
|
|
2019-11-04 16:03:14 +03:00
|
|
|
virtual bool can_read(const FileDescription&) const override { return !m_calls.is_empty() || m_dead; }
|
2019-07-03 22:17:35 +03:00
|
|
|
virtual int read(FileDescription&, u8*, int) override;
|
2019-04-28 16:02:55 +03:00
|
|
|
|
2019-11-04 16:03:14 +03:00
|
|
|
virtual bool can_write(const FileDescription&) const override { return true; }
|
2019-07-03 22:17:35 +03:00
|
|
|
virtual int write(FileDescription&, const u8*, int) override { return -EIO; }
|
2019-04-28 16:02:55 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-04-22 19:44:45 +03:00
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
void did_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3, u32 result);
|
2019-04-22 19:44:45 +03:00
|
|
|
pid_t pid() const { return m_pid; }
|
|
|
|
|
|
|
|
private:
|
2019-04-28 16:02:55 +03:00
|
|
|
virtual const char* class_name() const override { return "ProcessTracer"; }
|
2019-04-22 19:44:45 +03:00
|
|
|
explicit ProcessTracer(pid_t);
|
|
|
|
|
|
|
|
struct CallData {
|
2019-07-03 22:17:35 +03:00
|
|
|
u32 function;
|
|
|
|
u32 arg1;
|
|
|
|
u32 arg2;
|
|
|
|
u32 arg3;
|
|
|
|
u32 result;
|
2019-04-22 19:44:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
pid_t m_pid;
|
|
|
|
bool m_dead { false };
|
|
|
|
CircularQueue<CallData, 200> m_calls;
|
|
|
|
};
|