ladybird/Kernel/ProcFileSystem.cpp
Andreas Kling 0c5bbac86e Add an InterruptDisabler helper class and use that for kmalloc.
The naive spinlock was not nearly enough to protect kmalloc from
reentrancy problems.

I don't want to deal with coming up with a fancy lock for kmalloc
right now, so I made an InterruptDisabler thingy instead.
It does CLI and then STI iff interrupts were previously enabled.
2018-10-24 11:07:53 +02:00

47 lines
1.2 KiB
C++

#include "ProcFileSystem.h"
#include "Task.h"
RetainPtr<ProcFileSystem> ProcFileSystem::create()
{
return adopt(*new ProcFileSystem);
}
ProcFileSystem::ProcFileSystem()
{
}
ProcFileSystem::~ProcFileSystem()
{
}
bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
addFile(createGeneratedFile("summary", [] {
InterruptDisabler disabler;
auto tasks = Task::allTasks();
char* buffer;
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 128, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
ptr += ksprintf(ptr, "PID OWNER STATE NSCHED NAME\n");
for (auto* task : tasks) {
ptr += ksprintf(ptr, "%w %w:%w %b %w %s\n",
task->pid(),
task->uid(),
task->gid(),
task->state(),
task->timesScheduled(),
task->name().characters());
}
ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
*ptr = '\0';
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
}));
return true;
}
const char* ProcFileSystem::className() const
{
return "procfs";
}