From fdf03852c968f11b942376aa225248cdc26bd904 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 19 Feb 2021 18:41:50 +0100 Subject: [PATCH] Kernel: Slap UNMAP_AFTER_INIT on a whole bunch of functions There's no real system here, I just added it to various functions that I don't believe we ever want to call after initialization has finished. With these changes, we're able to unmap 60 KiB of kernel text after init. :^) --- Kernel/Arch/i386/CPU.cpp | 20 ++++++++++---------- Kernel/Console.cpp | 4 ++-- Kernel/Devices/FullDevice.cpp | 4 ++-- Kernel/Devices/I8042Controller.cpp | 4 ++-- Kernel/Devices/NullDevice.cpp | 4 ++-- Kernel/Devices/RandomDevice.cpp | 4 ++-- Kernel/Devices/ZeroDevice.cpp | 4 ++-- Kernel/FileSystem/VirtualFileSystem.cpp | 6 +++--- Kernel/Heap/SlabAllocator.cpp | 2 +- Kernel/Heap/kmalloc.cpp | 2 +- Kernel/Interrupts/APIC.cpp | 14 +++++++------- Kernel/Interrupts/InterruptManagement.cpp | 12 ++++++------ Kernel/Process.cpp | 2 +- Kernel/Scheduler.cpp | 4 ++-- Kernel/TTY/PTYMultiplexer.cpp | 4 ++-- Kernel/TTY/VirtualConsole.cpp | 6 +++--- Kernel/Thread.cpp | 2 +- Kernel/Time/APICTimer.cpp | 6 +++--- Kernel/Time/TimeManagement.cpp | 8 ++++---- Kernel/VM/MemoryManager.cpp | 15 ++++++++------- Kernel/VM/PageDirectory.cpp | 2 +- Kernel/init.cpp | 8 ++++---- 22 files changed, 69 insertions(+), 68 deletions(-) diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index cc34e5dc5f..64e377f439 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -454,24 +454,24 @@ void unregister_generic_interrupt_handler(u8 interrupt_number, GenericInterruptH ASSERT_NOT_REACHED(); } -void register_interrupt_handler(u8 index, void (*f)()) +UNMAP_AFTER_INIT void register_interrupt_handler(u8 index, void (*f)()) { s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].high = ((u32)(f)&0xffff0000) | 0x8e00; } -void register_user_callable_interrupt_handler(u8 index, void (*f)()) +UNMAP_AFTER_INIT void register_user_callable_interrupt_handler(u8 index, void (*f)()) { s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].high = ((u32)(f)&0xffff0000) | 0xef00; } -void flush_idt() +UNMAP_AFTER_INIT void flush_idt() { asm("lidt %0" ::"m"(s_idtr)); } -static void idt_init() +UNMAP_AFTER_INIT static void idt_init() { s_idtr.address = s_idt; s_idtr.limit = 256 * 8 - 1; @@ -815,7 +815,7 @@ Processor& Processor::by_id(u32 cpu) } } -void Processor::cpu_detect() +UNMAP_AFTER_INIT void Processor::cpu_detect() { // NOTE: This is called during Processor::early_initialize, we cannot // safely log at this point because we don't have kmalloc @@ -900,7 +900,7 @@ void Processor::cpu_detect() set_feature(CPUFeature::RDSEED); } -void Processor::cpu_setup() +UNMAP_AFTER_INIT void Processor::cpu_setup() { // NOTE: This is called during Processor::early_initialize, we cannot // safely log at this point because we don't have kmalloc @@ -1013,7 +1013,7 @@ String Processor::features_string() const return builder.build(); } -void Processor::early_initialize(u32 cpu) +UNMAP_AFTER_INIT void Processor::early_initialize(u32 cpu) { m_self = this; @@ -1048,7 +1048,7 @@ void Processor::early_initialize(u32 cpu) ASSERT(¤t() == this); // sanity check } -void Processor::initialize(u32 cpu) +UNMAP_AFTER_INIT void Processor::initialize(u32 cpu) { ASSERT(m_self == this); ASSERT(¤t() == this); // sanity check @@ -1774,7 +1774,7 @@ u32 Processor::smp_wake_n_idle_processors(u32 wake_count) return did_wake_count; } -void Processor::smp_enable() +UNMAP_AFTER_INIT void Processor::smp_enable() { size_t msg_pool_size = Processor::count() * 100u; size_t msg_entries_cnt = Processor::count(); @@ -2167,7 +2167,7 @@ void Processor::deferred_call_queue(void (*callback)(void*), void* data, void (* cur_proc.deferred_call_queue_entry(entry); } -void Processor::gdt_init() +UNMAP_AFTER_INIT void Processor::gdt_init() { m_gdt_length = 0; m_gdtr.address = nullptr; diff --git a/Kernel/Console.cpp b/Kernel/Console.cpp index 4efe2fec79..3229281f71 100644 --- a/Kernel/Console.cpp +++ b/Kernel/Console.cpp @@ -36,7 +36,7 @@ static AK::Singleton s_the; static Kernel::SpinLock g_console_lock; -void Console::initialize() +UNMAP_AFTER_INIT void Console::initialize() { s_the.ensure_instance(); } @@ -51,7 +51,7 @@ bool Console::is_initialized() return s_the.is_initialized(); } -Console::Console() +UNMAP_AFTER_INIT Console::Console() : CharacterDevice(5, 1) { } diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index cbe5ca0d1d..f68524f5b9 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -32,12 +32,12 @@ namespace Kernel { -FullDevice::FullDevice() +UNMAP_AFTER_INIT FullDevice::FullDevice() : CharacterDevice(1, 7) { } -FullDevice::~FullDevice() +UNMAP_AFTER_INIT FullDevice::~FullDevice() { } diff --git a/Kernel/Devices/I8042Controller.cpp b/Kernel/Devices/I8042Controller.cpp index 8798ea1c49..451ee1b513 100644 --- a/Kernel/Devices/I8042Controller.cpp +++ b/Kernel/Devices/I8042Controller.cpp @@ -33,7 +33,7 @@ namespace Kernel { static I8042Controller* s_the; -void I8042Controller::initialize() +UNMAP_AFTER_INIT void I8042Controller::initialize() { if (ACPI::Parser::the()->have_8042()) new I8042Controller; @@ -45,7 +45,7 @@ I8042Controller& I8042Controller::the() return *s_the; } -I8042Controller::I8042Controller() +UNMAP_AFTER_INIT I8042Controller::I8042Controller() { ASSERT(!s_the); s_the = this; diff --git a/Kernel/Devices/NullDevice.cpp b/Kernel/Devices/NullDevice.cpp index 260e8d9aa8..6b4d05c653 100644 --- a/Kernel/Devices/NullDevice.cpp +++ b/Kernel/Devices/NullDevice.cpp @@ -42,12 +42,12 @@ NullDevice& NullDevice::the() return *s_the; } -NullDevice::NullDevice() +UNMAP_AFTER_INIT NullDevice::NullDevice() : CharacterDevice(1, 3) { } -NullDevice::~NullDevice() +UNMAP_AFTER_INIT NullDevice::~NullDevice() { } diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index 728e5456b4..69351535a7 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -29,12 +29,12 @@ namespace Kernel { -RandomDevice::RandomDevice() +UNMAP_AFTER_INIT RandomDevice::RandomDevice() : CharacterDevice(1, 8) { } -RandomDevice::~RandomDevice() +UNMAP_AFTER_INIT RandomDevice::~RandomDevice() { } diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index f0b0302f64..299ecaac3a 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -30,12 +30,12 @@ namespace Kernel { -ZeroDevice::ZeroDevice() +UNMAP_AFTER_INIT ZeroDevice::ZeroDevice() : CharacterDevice(1, 5) { } -ZeroDevice::~ZeroDevice() +UNMAP_AFTER_INIT ZeroDevice::~ZeroDevice() { } diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index d71933b617..d7fc8fa278 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -44,7 +44,7 @@ static AK::Singleton s_the; static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase? static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY; -void VFS::initialize() +UNMAP_AFTER_INIT void VFS::initialize() { s_the.ensure_instance(); } @@ -54,14 +54,14 @@ VFS& VFS::the() return *s_the; } -VFS::VFS() +UNMAP_AFTER_INIT VFS::VFS() { #if VFS_DEBUG klog() << "VFS: Constructing VFS"; #endif } -VFS::~VFS() +UNMAP_AFTER_INIT VFS::~VFS() { } diff --git a/Kernel/Heap/SlabAllocator.cpp b/Kernel/Heap/SlabAllocator.cpp index 47e913978a..55720013c4 100644 --- a/Kernel/Heap/SlabAllocator.cpp +++ b/Kernel/Heap/SlabAllocator.cpp @@ -141,7 +141,7 @@ void for_each_allocator(Callback callback) callback(s_slab_allocator_128); } -void slab_alloc_init() +UNMAP_AFTER_INIT void slab_alloc_init() { s_slab_allocator_16.init(128 * KiB); s_slab_allocator_32.init(128 * KiB); diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index 6b17a52538..e2697dfa46 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -211,7 +211,7 @@ void kmalloc_enable_expand() g_kmalloc_global->allocate_backup_memory(); } -void kmalloc_init() +UNMAP_AFTER_INIT void kmalloc_init() { // Zero out heap since it's placed after end_of_kernel_bss. memset(kmalloc_eternal_heap, 0, sizeof(kmalloc_eternal_heap)); diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index 0350e7284e..888ec06761 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -146,7 +146,7 @@ APIC& APIC::the() return *s_apic; } -void APIC::initialize() +UNMAP_AFTER_INIT void APIC::initialize() { ASSERT(!APIC::initialized()); s_apic.ensure_instance(); @@ -234,7 +234,7 @@ u8 APIC::spurious_interrupt_vector() + reinterpret_cast(&varname) \ - reinterpret_cast(&apic_ap_start)) -bool APIC::init_bsp() +UNMAP_AFTER_INIT bool APIC::init_bsp() { // FIXME: Use the ACPI MADT table if (!MSR::have()) @@ -300,7 +300,7 @@ bool APIC::init_bsp() return true; } -void APIC::do_boot_aps() +UNMAP_AFTER_INIT void APIC::do_boot_aps() { ASSERT(m_processor_enabled_cnt > 1); u32 aps_to_enable = m_processor_enabled_cnt - 1; @@ -400,7 +400,7 @@ void APIC::do_boot_aps() #endif } -void APIC::boot_aps() +UNMAP_AFTER_INIT void APIC::boot_aps() { if (m_processor_enabled_cnt <= 1) return; @@ -421,7 +421,7 @@ void APIC::boot_aps() m_apic_ap_continue.store(1, AK::MemoryOrder::memory_order_release); } -void APIC::enable(u32 cpu) +UNMAP_AFTER_INIT void APIC::enable(u32 cpu) { if (cpu >= 8) { // TODO: x2apic support? @@ -472,7 +472,7 @@ Thread* APIC::get_idle_thread(u32 cpu) const return m_ap_idle_threads[cpu - 1]; } -void APIC::init_finished(u32 cpu) +UNMAP_AFTER_INIT void APIC::init_finished(u32 cpu) { // This method is called once the boot stack is no longer needed ASSERT(cpu > 0); @@ -525,7 +525,7 @@ void APIC::send_ipi(u32 cpu) write_icr(ICRReg(IRQ_APIC_IPI + IRQ_VECTOR_BASE, ICRReg::Fixed, ICRReg::Logical, ICRReg::Assert, ICRReg::TriggerMode::Edge, ICRReg::NoShorthand, cpu)); } -APICTimer* APIC::initialize_timers(HardwareTimerBase& calibration_timer) +UNMAP_AFTER_INIT APICTimer* APIC::initialize_timers(HardwareTimerBase& calibration_timer) { if (!m_apic_base) return nullptr; diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index 55878dc9eb..e0f43b8ae3 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -56,7 +56,7 @@ InterruptManagement& InterruptManagement::the() return *s_interrupt_management; } -void InterruptManagement::initialize() +UNMAP_AFTER_INIT void InterruptManagement::initialize() { ASSERT(!InterruptManagement::initialized()); s_interrupt_management = new InterruptManagement(); @@ -125,7 +125,7 @@ RefPtr InterruptManagement::get_responsible_irq_controller(u8 int ASSERT_NOT_REACHED(); } -PhysicalAddress InterruptManagement::search_for_madt() +UNMAP_AFTER_INIT PhysicalAddress InterruptManagement::search_for_madt() { dbgln("Early access to ACPI tables for interrupt setup"); auto rsdp = ACPI::StaticParsing::find_rsdp(); @@ -134,13 +134,13 @@ PhysicalAddress InterruptManagement::search_for_madt() return ACPI::StaticParsing::find_table(rsdp.value(), "APIC"); } -InterruptManagement::InterruptManagement() +UNMAP_AFTER_INIT InterruptManagement::InterruptManagement() : m_madt(search_for_madt()) { m_interrupt_controllers.resize(1); } -void InterruptManagement::switch_to_pic_mode() +UNMAP_AFTER_INIT void InterruptManagement::switch_to_pic_mode() { klog() << "Interrupts: Switch to Legacy PIC mode"; InterruptDisabler disabler; @@ -159,7 +159,7 @@ void InterruptManagement::switch_to_pic_mode() } } -void InterruptManagement::switch_to_ioapic_mode() +UNMAP_AFTER_INIT void InterruptManagement::switch_to_ioapic_mode() { klog() << "Interrupts: Switch to IOAPIC mode"; InterruptDisabler disabler; @@ -196,7 +196,7 @@ void InterruptManagement::switch_to_ioapic_mode() APIC::the().init_bsp(); } -void InterruptManagement::locate_apic_data() +UNMAP_AFTER_INIT void InterruptManagement::locate_apic_data() { ASSERT(!m_madt.is_null()); auto madt = map_typed(m_madt); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index d1675c2ee8..973b9a06eb 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -78,7 +78,7 @@ ProcessID Process::allocate_pid() return next_pid.fetch_add(1, AK::MemoryOrder::memory_order_acq_rel); } -void Process::initialize() +UNMAP_AFTER_INIT void Process::initialize() { g_modules = new HashMap>; diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 62cadec3f7..de785601f9 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -168,7 +168,7 @@ void Scheduler::queue_runnable_thread(Thread& thread) g_ready_queues_mask |= (1u << priority); } -void Scheduler::start() +UNMAP_AFTER_INIT void Scheduler::start() { ASSERT_INTERRUPTS_DISABLED(); @@ -488,7 +488,7 @@ Process* Scheduler::colonel() return s_colonel_process; } -void Scheduler::initialize() +UNMAP_AFTER_INIT void Scheduler::initialize() { ASSERT(&Processor::current() != nullptr); // sanity check diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp index cef533d6a0..dc0c24d4fb 100644 --- a/Kernel/TTY/PTYMultiplexer.cpp +++ b/Kernel/TTY/PTYMultiplexer.cpp @@ -42,7 +42,7 @@ PTYMultiplexer& PTYMultiplexer::the() return *s_the; } -PTYMultiplexer::PTYMultiplexer() +UNMAP_AFTER_INIT PTYMultiplexer::PTYMultiplexer() : CharacterDevice(5, 2) { m_freelist.ensure_capacity(s_max_pty_pairs); @@ -50,7 +50,7 @@ PTYMultiplexer::PTYMultiplexer() m_freelist.unchecked_append(i - 1); } -PTYMultiplexer::~PTYMultiplexer() +UNMAP_AFTER_INIT PTYMultiplexer::~PTYMultiplexer() { } diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index 47d6ae9e60..5fa2e52141 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -49,7 +49,7 @@ void VirtualConsole::flush_vga_cursor() IO::out8(0x3d5, LSB(value)); } -void VirtualConsole::initialize() +UNMAP_AFTER_INIT void VirtualConsole::initialize() { s_vga_buffer = (u8*)0xc00b8000; s_active_console = -1; @@ -63,7 +63,7 @@ void VirtualConsole::set_graphical(bool graphical) m_graphical = graphical; } -VirtualConsole::VirtualConsole(const unsigned index) +UNMAP_AFTER_INIT VirtualConsole::VirtualConsole(const unsigned index) : TTY(4, index) , m_index(index) , m_terminal(*this) @@ -76,7 +76,7 @@ VirtualConsole::VirtualConsole(const unsigned index) s_consoles[index] = this; } -VirtualConsole::~VirtualConsole() +UNMAP_AFTER_INIT VirtualConsole::~VirtualConsole() { ASSERT_NOT_REACHED(); } diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 891a5672fe..b906bcb483 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -48,7 +48,7 @@ namespace Kernel { SpinLock Thread::g_tid_map_lock; READONLY_AFTER_INIT HashMap* Thread::g_tid_map; -void Thread::initialize() +UNMAP_AFTER_INIT void Thread::initialize() { g_tid_map = new HashMap(); } diff --git a/Kernel/Time/APICTimer.cpp b/Kernel/Time/APICTimer.cpp index 2b0a80e24f..a7bf3052a6 100644 --- a/Kernel/Time/APICTimer.cpp +++ b/Kernel/Time/APICTimer.cpp @@ -36,7 +36,7 @@ namespace Kernel { #define APIC_TIMER_MEASURE_CPU_CLOCK -APICTimer* APICTimer::initialize(u8 interrupt_number, HardwareTimerBase& calibration_source) +UNMAP_AFTER_INIT APICTimer* APICTimer::initialize(u8 interrupt_number, HardwareTimerBase& calibration_source) { auto* timer = new APICTimer(interrupt_number, nullptr); if (!timer->calibrate(calibration_source)) { @@ -46,13 +46,13 @@ APICTimer* APICTimer::initialize(u8 interrupt_number, HardwareTimerBase& calibra return timer; } -APICTimer::APICTimer(u8 interrupt_number, Function callback) +UNMAP_AFTER_INIT APICTimer::APICTimer(u8 interrupt_number, Function callback) : HardwareTimer(interrupt_number, move(callback)) { disable_remap(); } -bool APICTimer::calibrate(HardwareTimerBase& calibration_source) +UNMAP_AFTER_INIT bool APICTimer::calibrate(HardwareTimerBase& calibration_source) { ASSERT_INTERRUPTS_DISABLED(); diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 1ac2a4b1cd..aaf336b833 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -145,7 +145,7 @@ u64 TimeManagement::uptime_ms() const return ms; } -void TimeManagement::initialize(u32 cpu) +UNMAP_AFTER_INIT void TimeManagement::initialize(u32 cpu) { if (cpu == 0) { ASSERT(!s_the.is_initialized()); @@ -187,7 +187,7 @@ time_t TimeManagement::boot_time() const return RTC::boot_time(); } -TimeManagement::TimeManagement() +UNMAP_AFTER_INIT TimeManagement::TimeManagement() { bool probe_non_legacy_hardware_timers = !(kernel_command_line().lookup("time").value_or("modern") == "legacy"); if (ACPI::is_enabled()) { @@ -255,7 +255,7 @@ bool TimeManagement::is_hpet_periodic_mode_allowed() ASSERT_NOT_REACHED(); } -bool TimeManagement::probe_and_set_non_legacy_hardware_timers() +UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_non_legacy_hardware_timers() { if (!ACPI::is_enabled()) return false; @@ -309,7 +309,7 @@ bool TimeManagement::probe_and_set_non_legacy_hardware_timers() return true; } -bool TimeManagement::probe_and_set_legacy_hardware_timers() +UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_legacy_hardware_timers() { if (ACPI::is_enabled()) { if (ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) { diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index b780f82655..90e764575d 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -81,7 +81,7 @@ bool MemoryManager::is_initialized() return s_the != nullptr; } -MemoryManager::MemoryManager() +UNMAP_AFTER_INIT MemoryManager::MemoryManager() { ScopedSpinLock lock(s_mm_lock); m_kernel_page_directory = PageDirectory::create_kernel_page_directory(); @@ -104,11 +104,11 @@ MemoryManager::MemoryManager() m_lazy_committed_page = allocate_committed_user_physical_page(); } -MemoryManager::~MemoryManager() +UNMAP_AFTER_INIT MemoryManager::~MemoryManager() { } -void MemoryManager::protect_kernel_image() +UNMAP_AFTER_INIT void MemoryManager::protect_kernel_image() { ScopedSpinLock page_lock(kernel_page_directory().get_lock()); // Disable writing to the kernel text and rodata segments. @@ -125,7 +125,7 @@ void MemoryManager::protect_kernel_image() } } -void MemoryManager::protect_readonly_after_init_memory() +UNMAP_AFTER_INIT void MemoryManager::protect_readonly_after_init_memory() { ScopedSpinLock mm_lock(s_mm_lock); ScopedSpinLock page_lock(kernel_page_directory().get_lock()); @@ -153,9 +153,10 @@ void MemoryManager::unmap_memory_after_init() } dmesgln("Unmapped {} KiB of kernel text after init! :^)", (end - start) / KiB); + //Processor::halt(); } -void MemoryManager::register_reserved_ranges() +UNMAP_AFTER_INIT void MemoryManager::register_reserved_ranges() { ASSERT(!m_physical_memory_ranges.is_empty()); ContiguousReservedMemoryRange range; @@ -194,7 +195,7 @@ bool MemoryManager::is_allowed_to_mmap_to_userspace(PhysicalAddress start_addres return false; } -void MemoryManager::parse_memory_map() +UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() { RefPtr physical_region; @@ -414,7 +415,7 @@ void MemoryManager::release_pte(PageDirectory& page_directory, VirtualAddress va } } -void MemoryManager::initialize(u32 cpu) +UNMAP_AFTER_INIT void MemoryManager::initialize(u32 cpu) { auto mm_data = new MemoryManagerData; Processor::current().set_mm_data(*mm_data); diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index 19f4a6836d..5bc207c761 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -54,7 +54,7 @@ extern "C" PageDirectoryEntry* boot_pdpt[4]; extern "C" PageDirectoryEntry boot_pd0[1024]; extern "C" PageDirectoryEntry boot_pd3[1024]; -PageDirectory::PageDirectory() +UNMAP_AFTER_INIT PageDirectory::PageDirectory() { m_range_allocator.initialize_with_range(VirtualAddress(0xc0800000), 0x3f000000); m_identity_range_allocator.initialize_with_range(VirtualAddress(FlatPtr(0x00000000)), 0x00200000); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 002a0a6841..fff7ec64b7 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -116,7 +116,7 @@ static Processor s_bsp_processor; // global but let's keep it "private" // Once multi-tasking is ready, we spawn a new thread that starts in the // init_stage2() function. Initialization continues there. -extern "C" [[noreturn]] void init() +extern "C" UNMAP_AFTER_INIT [[noreturn]] void init() { setup_serial_debug(); @@ -196,7 +196,7 @@ extern "C" [[noreturn]] void init() // // The purpose of init_ap() is to initialize APs for multi-tasking. // -extern "C" [[noreturn]] void init_ap(u32 cpu, Processor* processor_info) +extern "C" UNMAP_AFTER_INIT [[noreturn]] void init_ap(u32 cpu, Processor* processor_info) { processor_info->early_initialize(cpu); @@ -213,7 +213,7 @@ extern "C" [[noreturn]] void init_ap(u32 cpu, Processor* processor_info) // This method is called once a CPU enters the scheduler and its idle thread // At this point the initial boot stack can be freed // -extern "C" void init_finished(u32 cpu) +extern "C" UNMAP_AFTER_INIT void init_finished(u32 cpu) { if (cpu == 0) { // TODO: we can reuse the boot stack, maybe for kmalloc()? @@ -323,7 +323,7 @@ void init_stage2(void*) ASSERT_NOT_REACHED(); } -void setup_serial_debug() +UNMAP_AFTER_INIT void setup_serial_debug() { // serial_debug will output all the klog() and dbgln() data to COM1 at // 8-N-1 57600 baud. this is particularly useful for debugging the boot