mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
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.
This commit is contained in:
parent
1c06d77262
commit
1492bb2fd6
5 changed files with 74 additions and 8 deletions
|
@ -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);
|
||||
|
|
|
@ -17,10 +17,14 @@ public:
|
|||
|
||||
bool has_space() const { return m_num_used_bytes < m_capacity_in_bytes; }
|
||||
bool copy_data_in(const UserOrKernelBuffer& buffer, size_t offset, size_t length, PhysicalAddress& start_of_copied_data, size_t& bytes_copied);
|
||||
KResultOr<size_t> copy_data_out(size_t size, UserOrKernelBuffer& buffer) const;
|
||||
KResultOr<PhysicalAddress> reserve_space(size_t size);
|
||||
void reclaim_space(PhysicalAddress chunk_start, size_t chunk_size);
|
||||
PhysicalAddress start_of_used() const;
|
||||
|
||||
SpinLock<u8>& lock() { return m_lock; }
|
||||
size_t used_bytes() const { return m_num_used_bytes; }
|
||||
PhysicalAddress start_of_region() const { return m_region->physical_page(0)->paddr(); }
|
||||
|
||||
private:
|
||||
OwnPtr<Region> m_region;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue