1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

Kernel: Implement read functionality for MemoryDevice

So far we only had mmap(2) functionality on the /dev/mem device, but now
we can also do read(2) on it.

The test unit was updated to check we are doing it safely.
This commit is contained in:
Liav A 2021-12-23 21:49:31 +02:00 committed by Idan Horowitz
parent 6feb07fe43
commit ca254699ec
4 changed files with 81 additions and 18 deletions

View file

@ -209,13 +209,13 @@ UNMAP_AFTER_INIT void MemoryManager::register_reserved_ranges()
m_reserved_memory_ranges.append(ContiguousReservedMemoryRange { range.start, m_physical_memory_ranges.last().start.get() + m_physical_memory_ranges.last().length - range.start.get() });
}
bool MemoryManager::is_allowed_to_mmap_physical_memory_to_userspace(PhysicalAddress start_address, VirtualRange const& range) const
bool MemoryManager::is_allowed_to_read_physical_memory_for_userspace(PhysicalAddress start_address, size_t read_length) const
{
// Note: Guard against overflow in case someone tries to mmap on the edge of
// the RAM
if (start_address.offset_addition_would_overflow(range.size()))
if (start_address.offset_addition_would_overflow(read_length))
return false;
auto end_address = start_address.offset(range.size());
auto end_address = start_address.offset(read_length);
for (auto& current_range : m_reserved_memory_ranges) {
if (current_range.start > start_address)
continue;