Skip to content

Commit

Permalink
Kernel: Change the BSP Processor instance to not have a constructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomuta authored and awesomekling committed Mar 27, 2022
1 parent 22308e5 commit c2f6152
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Kernel/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :^)
//
Expand Down Expand Up @@ -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++)
Expand All @@ -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);
Expand Down

0 comments on commit c2f6152

Please sign in to comment.