summaryrefslogtreecommitdiff
path: root/Kernel/VM/RingBuffer.cpp
diff options
context:
space:
mode:
authorx-yl <kylepereira@mail.com>2021-06-20 17:46:04 +0400
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-09 13:19:21 +0430
commit1492bb2fd6893e2a39d461c3c8a12ec6cf4e7ffd (patch)
tree90adbee82af1ee8f2f2184016635653ecbfbd68a /Kernel/VM/RingBuffer.cpp
parent1c06d772628a0191289fe30edcc143e29ba2ca32 (diff)
downloadserenity-1492bb2fd6893e2a39d461c3c8a12ec6cf4e7ffd.zip
Kernel: Add support for reading from VirtIOConsole
This allows two-way communication with the host through a VirtIOConsole. This is necessary for features like clipboard sharing.
Diffstat (limited to 'Kernel/VM/RingBuffer.cpp')
-rw-r--r--Kernel/VM/RingBuffer.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Kernel/VM/RingBuffer.cpp b/Kernel/VM/RingBuffer.cpp
index e33f40271a..bfaa8da326 100644
--- a/Kernel/VM/RingBuffer.cpp
+++ b/Kernel/VM/RingBuffer.cpp
@@ -30,6 +30,25 @@ bool RingBuffer::copy_data_in(const UserOrKernelBuffer& buffer, size_t offset, s
return false;
}
+KResultOr<size_t> RingBuffer::copy_data_out(size_t size, UserOrKernelBuffer& buffer) const
+{
+ auto start = m_start_of_used % m_capacity_in_bytes;
+ auto num_bytes = min(min(m_num_used_bytes, size), m_capacity_in_bytes - start);
+ if (!buffer.write(m_region->vaddr().offset(start).as_ptr(), num_bytes))
+ return EIO;
+ return num_bytes;
+}
+
+KResultOr<PhysicalAddress> RingBuffer::reserve_space(size_t size)
+{
+ if (m_capacity_in_bytes < m_num_used_bytes + size)
+ return ENOSPC;
+ size_t start_of_free_area = (m_start_of_used + m_num_used_bytes) % m_capacity_in_bytes;
+ m_num_used_bytes += size;
+ PhysicalAddress start_of_reserved_space = m_region->physical_page(start_of_free_area / PAGE_SIZE)->paddr().offset(start_of_free_area % PAGE_SIZE);
+ return start_of_reserved_space;
+}
+
void RingBuffer::reclaim_space(PhysicalAddress chunk_start, size_t chunk_size)
{
VERIFY(start_of_used() == chunk_start);