diff options
author | Tom <tomut@yahoo.com> | 2022-03-27 12:48:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-27 18:54:56 +0200 |
commit | c2f6152db840a9b7cb08d1a1bee08e6486cdeae1 (patch) | |
tree | 892f24f629dc436fc8e5ceec1382b93b52f34e6c /Kernel/init.cpp | |
parent | 22308e52cfd9e0064838e8e28f195807516e2d2c (diff) | |
download | serenity-c2f6152db840a9b7cb08d1a1bee08e6486cdeae1.zip |
Kernel: Change the BSP Processor instance to not have a constructor
This solves a problem where any non-trivial member in the global BSP
Processor instance would get re-initialized (improperly), losing data
that was already initialized earlier.
Diffstat (limited to 'Kernel/init.cpp')
-rw-r--r-- | Kernel/init.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Kernel/init.cpp b/Kernel/init.cpp index c49a4ea339..17e9dc4957 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -100,7 +100,13 @@ READONLY_AFTER_INIT VirtualConsole* tty0; ProcessID g_init_pid { 0 }; -static Processor s_bsp_processor; // global but let's keep it "private" +ALWAYS_INLINE static Processor& bsp_processor() +{ + // This solves a problem where the bsp Processor instance + // gets "re"-initialized in init() when we run all global constructors. + alignas(Processor) static u8 bsp_processor_storage[sizeof(Processor)]; + return (Processor&)bsp_processor_storage; +} // SerenityOS Kernel C++ entry point :^) // @@ -179,7 +185,9 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) CommandLine::early_initialize(kernel_cmdline); memcpy(multiboot_copy_boot_modules_array, multiboot_modules, multiboot_modules_count * sizeof(multiboot_module_entry_t)); multiboot_copy_boot_modules_count = multiboot_modules_count; - s_bsp_processor.early_initialize(0); + + new (&bsp_processor()) Processor(); + bsp_processor().early_initialize(0); // Invoke the constructors needed for the kernel heap for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++) @@ -188,7 +196,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) load_kernel_symbol_table(); - s_bsp_processor.initialize(0); + bsp_processor().initialize(0); CommandLine::initialize(); Memory::MemoryManager::initialize(0); |