Browse Source

Kernel/Graphics: Allocate VGA window region according to the usual rules

We should not allocate a kernel region inside the constructor of the
VGATextModeConsole class. We do use MUST() because allocation cannot
fail at this point, but that happens in the static factory method
instead.
Liav A 3 năm trước cách đây
mục cha
commit
cd8bcd06c6

+ 5 - 3
Kernel/Graphics/Console/VGATextModeConsole.cpp

@@ -13,12 +13,14 @@ namespace Kernel::Graphics {
 
 UNMAP_AFTER_INIT NonnullRefPtr<VGATextModeConsole> VGATextModeConsole::initialize()
 {
-    return adopt_ref(*new VGATextModeConsole());
+    auto vga_window_size = MUST(Memory::page_round_up(0xc0000 - 0xa0000));
+    auto vga_window_region = MUST(MM.allocate_kernel_region(PhysicalAddress(0xa0000), vga_window_size, "VGA Display"sv, Memory::Region::Access::ReadWrite));
+    return adopt_ref(*new (nothrow) VGATextModeConsole(move(vga_window_region)));
 }
 
-UNMAP_AFTER_INIT VGATextModeConsole::VGATextModeConsole()
+UNMAP_AFTER_INIT VGATextModeConsole::VGATextModeConsole(NonnullOwnPtr<Memory::Region> vga_window_region)
     : Console(80, 25)
-    , m_vga_window_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), Memory::page_round_up(0xc0000 - 0xa0000).release_value_but_fixme_should_propagate_errors(), "VGA Display"sv, Memory::Region::Access::ReadWrite).release_value())
+    , m_vga_window_region(move(vga_window_region))
     , m_current_vga_window(m_vga_window_region->vaddr().offset(0x18000).as_ptr())
 {
     for (size_t index = 0; index < height(); index++) {

+ 1 - 1
Kernel/Graphics/Console/VGATextModeConsole.h

@@ -36,7 +36,7 @@ public:
 private:
     void clear_vga_row(u16 row);
 
-    VGATextModeConsole();
+    explicit VGATextModeConsole(NonnullOwnPtr<Memory::Region>);
 
     mutable Spinlock m_vga_lock;