summaryrefslogtreecommitdiff
path: root/Kernel/KBuffer.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-05 11:35:49 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-05 11:37:48 +0200
commit79e22acb225d8aaa4d20540afa50faac17ea29bf (patch)
tree0506c16d60f755cac4a866cc0804c1175a48a95a /Kernel/KBuffer.h
parent6b6b86fbf31bdf713fe6be8f6de410429248e061 (diff)
downloadserenity-79e22acb225d8aaa4d20540afa50faac17ea29bf.zip
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. :^)
Diffstat (limited to 'Kernel/KBuffer.h')
-rw-r--r--Kernel/KBuffer.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h
index 4d718d6ebe..71f71bbb66 100644
--- a/Kernel/KBuffer.h
+++ b/Kernel/KBuffer.h
@@ -65,11 +65,16 @@ public:
const KBufferImpl& impl() const { return m_impl; }
- KBuffer(NonnullRefPtr<KBufferImpl>&& impl)
- : m_impl(move(impl))
+ KBuffer(const ByteBuffer& buffer)
+ : m_impl(KBufferImpl::copy(buffer.data(), buffer.size()))
{
}
private:
+ explicit KBuffer(NonnullRefPtr<KBufferImpl>&& impl)
+ : m_impl(move(impl))
+ {
+ }
+
NonnullRefPtr<KBufferImpl> m_impl;
};