mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
Kernel: Use KBuffers for ProcFS and SynthFS
Instead of generating ByteBuffers and keeping those lying around, have these filesystems generate KBuffers instead. These are way less spooky to leave around for a while. Since FileDescription will keep a generated file buffer around until userspace has read the whole thing, this prevents trivially exhausting the kmalloc heap by opening many files in /proc for example. The code responsible for generating each /proc file is not perfectly efficient and many of them still use ByteBuffers internally but they at least go away when we return now. :^)
This commit is contained in:
parent
6b6b86fbf3
commit
79e22acb22
7 changed files with 58 additions and 43 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <AK/Types.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
class Process;
|
||||
|
@ -36,7 +37,7 @@ private:
|
|||
|
||||
struct ProcFSDirectoryEntry {
|
||||
ProcFSDirectoryEntry() {}
|
||||
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RefPtr<ProcFSInode>&& a_inode = nullptr)
|
||||
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<Optional<KBuffer>(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RefPtr<ProcFSInode>&& a_inode = nullptr)
|
||||
: name(a_name)
|
||||
, proc_file_type(a_proc_file_type)
|
||||
, read_callback(move(a_read_callback))
|
||||
|
@ -47,7 +48,7 @@ private:
|
|||
|
||||
const char* name { nullptr };
|
||||
unsigned proc_file_type { 0 };
|
||||
Function<ByteBuffer(InodeIdentifier)> read_callback;
|
||||
Function<Optional<KBuffer>(InodeIdentifier)> read_callback;
|
||||
Function<ssize_t(InodeIdentifier, const ByteBuffer&)> write_callback;
|
||||
RefPtr<ProcFSInode> inode;
|
||||
InodeIdentifier identifier(unsigned fsid) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue