1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 11:05:09 +00:00

Kernel: Don't override FramebufferDevice's memory regions on mmap

This additionally refactors FramebufferDevice::try_to_initialize to not
leave the FramebufferDevice in an invalid state on errors.
This also unifies the logic between FramebufferDevice::mmap and
FramebufferDevice::try_to_initialize.
This comes with the drawback of removing the UNMAP_AFTER_INIT attribute
from this function, which wasn't honoured by IntelNativeGraphicsAdapter
anyway.
This commit is contained in:
Hendiadyoin1 2022-02-18 16:53:17 +01:00 committed by Brian Gianforcaro
parent 790d620b39
commit 85ba70d86f
2 changed files with 22 additions and 12 deletions

View file

@ -40,11 +40,10 @@ ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescr
if (range.size() != framebuffer_length)
return EOVERFLOW;
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));
TRY(try_to_initialize());
if (m_userspace_framebuffer_region)
return m_userspace_framebuffer_region;
RefPtr<Memory::VMObject> chosen_vmobject;
if (m_graphical_writes_enabled) {
@ -99,16 +98,26 @@ void FramebufferDevice::activate_writes()
m_graphical_writes_enabled = true;
}
UNMAP_AFTER_INIT ErrorOr<void> FramebufferDevice::try_to_initialize()
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.
if (m_initialized)
return {};
auto framebuffer_length = TRY(buffer_length(0));
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));
auto real_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, framebuffer_length));
auto swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(framebuffer_length, AllocationStrategy::AllocateNow));
auto real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*real_framebuffer_vmobject, framebuffer_length, "Framebuffer", Memory::Region::Access::ReadWrite));
auto swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*swapped_framebuffer_vmobject, framebuffer_length, "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite));
m_real_framebuffer_vmobject = move(real_framebuffer_vmobject);
m_swapped_framebuffer_vmobject = move(swapped_framebuffer_vmobject);
m_real_framebuffer_region = move(real_framebuffer_region);
m_swapped_framebuffer_region = move(swapped_framebuffer_region);
m_initialized = true;
return {};
}