mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
Implement /proc/PID/vm.
Refactored SyntheticFileSystem to maintain an arbitrary directory structure. ProcFileSystem creates a directory entry in /proc for each new process.
This commit is contained in:
parent
10347b9ae8
commit
a32b3a3ddf
Notes:
sideshowbarker
2024-07-19 18:38:09 +09:00
Author: https://github.com/awesomekling
Commit: a32b3a3ddf
15 changed files with 217 additions and 39 deletions
|
@ -1,6 +1,14 @@
|
|||
#include "ProcFileSystem.h"
|
||||
#include "Task.h"
|
||||
|
||||
static ProcFileSystem* s_the;
|
||||
|
||||
ProcFileSystem& ProcFileSystem::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
RetainPtr<ProcFileSystem> ProcFileSystem::create()
|
||||
{
|
||||
return adopt(*new ProcFileSystem);
|
||||
|
@ -8,15 +16,56 @@ RetainPtr<ProcFileSystem> ProcFileSystem::create()
|
|||
|
||||
ProcFileSystem::ProcFileSystem()
|
||||
{
|
||||
s_the = this;
|
||||
}
|
||||
|
||||
ProcFileSystem::~ProcFileSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void ProcFileSystem::addProcess(Task& task)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
char buf[16];
|
||||
ksprintf(buf, "%d", task.pid());
|
||||
auto dir = addFile(createDirectory(buf));
|
||||
m_pid2inode.set(task.pid(), dir.index());
|
||||
addFile(createGeneratedFile("vm", [&task] {
|
||||
InterruptDisabler disabler;
|
||||
char* buffer;
|
||||
auto stringImpl = StringImpl::createUninitialized(80 + task.regionCount() * 80, buffer);
|
||||
memset(buffer, 0, stringImpl->length());
|
||||
char* ptr = buffer;
|
||||
ptr += ksprintf(ptr, "BEGIN END SIZE NAME\n");
|
||||
for (auto& region : task.regions()) {
|
||||
ptr += ksprintf(ptr, "%x -- %x %x %s\n",
|
||||
region->linearAddress.get(),
|
||||
region->linearAddress.offset(region->size - 1).get(),
|
||||
region->size,
|
||||
region->name.characters());
|
||||
}
|
||||
*ptr = '\0';
|
||||
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
|
||||
}), dir.index());
|
||||
}
|
||||
|
||||
void ProcFileSystem::removeProcess(Task& task)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
auto pid = task.pid();
|
||||
auto it = m_pid2inode.find(pid);
|
||||
ASSERT(it != m_pid2inode.end());
|
||||
bool success = removeFile((*it).value);
|
||||
ASSERT(success);
|
||||
m_pid2inode.remove(pid);
|
||||
}
|
||||
|
||||
bool ProcFileSystem::initialize()
|
||||
{
|
||||
SyntheticFileSystem::initialize();
|
||||
|
||||
auto d = addFile(createDirectory("sys"));
|
||||
|
||||
addFile(createGeneratedFile("summary", [] {
|
||||
InterruptDisabler disabler;
|
||||
auto tasks = Task::allTasks();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue