diff options
author | Guilherme Goncalves <guilherme.p.gonc@gmail.com> | 2021-12-24 11:22:11 -0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-28 23:08:50 +0100 |
commit | 33b78915d377dfb950d93f150b8470aea2c1e66f (patch) | |
tree | 0be4e64332e2e7120720496f5db9dd1ffc6704b3 /Kernel/Graphics | |
parent | 11599a334232d203c21a21662375ac952e3d7f0a (diff) | |
download | serenity-33b78915d377dfb950d93f150b8470aea2c1e66f.zip |
Kernel: Propagate overflow errors from Memory::page_round_up
Fixes #11402.
Diffstat (limited to 'Kernel/Graphics')
-rw-r--r-- | Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp | 5 | ||||
-rw-r--r-- | Kernel/Graphics/Console/VGAConsole.cpp | 2 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.cpp | 28 | ||||
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/FramebufferDevice.h | 2 |
4 files changed, 21 insertions, 16 deletions
diff --git a/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp b/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp index 08989b1b55..0b9cc6730f 100644 --- a/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp +++ b/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp @@ -27,8 +27,9 @@ void ContiguousFramebufferConsole::set_resolution(size_t width, size_t height, s m_height = height; m_pitch = pitch; - dbgln("Framebuffer Console: taking {} bytes", Memory::page_round_up(pitch * height)); - auto region_or_error = MM.allocate_kernel_region(m_framebuffer_address, Memory::page_round_up(pitch * height), "Framebuffer Console", Memory::Region::Access::ReadWrite, Memory::Region::Cacheable::Yes); + size_t size = Memory::page_round_up(pitch * height).release_value_but_fixme_should_propagate_errors(); + dbgln("Framebuffer Console: taking {} bytes", size); + auto region_or_error = MM.allocate_kernel_region(m_framebuffer_address, size, "Framebuffer Console", Memory::Region::Access::ReadWrite, Memory::Region::Cacheable::Yes); VERIFY(!region_or_error.is_error()); m_framebuffer_region = region_or_error.release_value(); diff --git a/Kernel/Graphics/Console/VGAConsole.cpp b/Kernel/Graphics/Console/VGAConsole.cpp index acd9049753..9336978189 100644 --- a/Kernel/Graphics/Console/VGAConsole.cpp +++ b/Kernel/Graphics/Console/VGAConsole.cpp @@ -11,7 +11,7 @@ namespace Kernel::Graphics { UNMAP_AFTER_INIT VGAConsole::VGAConsole(const VGACompatibleAdapter& adapter, Mode mode, size_t width, size_t height) : Console(width, height) - , m_vga_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), Memory::page_round_up(0xc0000 - 0xa0000), "VGA Display", Memory::Region::Access::ReadWrite).release_value()) + , m_vga_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), Memory::page_round_up(0xc0000 - 0xa0000).release_value_but_fixme_should_propagate_errors(), "VGA Display", Memory::Region::Access::ReadWrite).release_value()) , m_adapter(adapter) , m_mode(mode) { diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index 6d41721871..862e0a7151 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -36,14 +36,15 @@ ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescr if (offset != 0) return ENXIO; auto framebuffer_length = TRY(buffer_length(0)); - if (range.size() != Memory::page_round_up(framebuffer_length)) + framebuffer_length = TRY(Memory::page_round_up(framebuffer_length)); + if (range.size() != framebuffer_length) return EOVERFLOW; - m_userspace_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_length))); - m_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_length))); - m_swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(framebuffer_length), AllocationStrategy::AllocateNow)); - m_real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer", Memory::Region::Access::ReadWrite)); - m_swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite)); + m_userspace_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, framebuffer_length)); + m_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, framebuffer_length)); + m_swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(framebuffer_length, AllocationStrategy::AllocateNow)); + m_real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, framebuffer_length, "Framebuffer", Memory::Region::Access::ReadWrite)); + m_swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, framebuffer_length, "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite)); RefPtr<Memory::VMObject> chosen_vmobject; if (m_graphical_writes_enabled) { @@ -68,7 +69,8 @@ void FramebufferDevice::deactivate_writes() return; auto framebuffer_length_or_error = buffer_length(0); VERIFY(!framebuffer_length_or_error.is_error()); - memcpy(m_swapped_framebuffer_region->vaddr().as_ptr(), m_real_framebuffer_region->vaddr().as_ptr(), Memory::page_round_up(framebuffer_length_or_error.release_value())); + size_t rounded_framebuffer_length = Memory::page_round_up(framebuffer_length_or_error.release_value()).release_value_but_fixme_should_propagate_errors(); + memcpy(m_swapped_framebuffer_region->vaddr().as_ptr(), m_real_framebuffer_region->vaddr().as_ptr(), rounded_framebuffer_length); auto vmobject = m_swapped_framebuffer_vmobject; m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull()); m_userspace_framebuffer_region->remap(); @@ -85,7 +87,8 @@ void FramebufferDevice::activate_writes() auto framebuffer_length_or_error = buffer_length(0); VERIFY(!framebuffer_length_or_error.is_error()); - memcpy(m_real_framebuffer_region->vaddr().as_ptr(), m_swapped_framebuffer_region->vaddr().as_ptr(), Memory::page_round_up(framebuffer_length_or_error.release_value())); + size_t rounded_framebuffer_length = Memory::page_round_up(framebuffer_length_or_error.release_value()).release_value_but_fixme_should_propagate_errors(); + memcpy(m_real_framebuffer_region->vaddr().as_ptr(), m_swapped_framebuffer_region->vaddr().as_ptr(), rounded_framebuffer_length); auto vmobject = m_userspace_real_framebuffer_vmobject; m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull()); m_userspace_framebuffer_region->remap(); @@ -97,10 +100,11 @@ UNMAP_AFTER_INIT ErrorOr<void> FramebufferDevice::try_to_initialize() // FIXME: Would be nice to be able to unify this with mmap above, but this // function is UNMAP_AFTER_INIT for the time being. auto framebuffer_length = TRY(buffer_length(0)); - m_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_length))); - m_swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(framebuffer_length), AllocationStrategy::AllocateNow)); - m_real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer", Memory::Region::Access::ReadWrite)); - m_swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite)); + framebuffer_length = TRY(Memory::page_round_up(framebuffer_length)); + m_real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, framebuffer_length)); + m_swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(framebuffer_length, AllocationStrategy::AllocateNow)); + m_real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, framebuffer_length, "Framebuffer", Memory::Region::Access::ReadWrite)); + m_swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, framebuffer_length, "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite)); return {}; } diff --git a/Kernel/Graphics/VirtIOGPU/FramebufferDevice.h b/Kernel/Graphics/VirtIOGPU/FramebufferDevice.h index e8aa88683d..ed72e47af7 100644 --- a/Kernel/Graphics/VirtIOGPU/FramebufferDevice.h +++ b/Kernel/Graphics/VirtIOGPU/FramebufferDevice.h @@ -40,7 +40,7 @@ public: static size_t calculate_framebuffer_size(size_t width, size_t height) { // VirtIO resources can only map on page boundaries! - return Memory::page_round_up(sizeof(u32) * width * height); + return Memory::page_round_up(sizeof(u32) * width * height).value(); } u8* framebuffer_data(); |