Kernel: Call the constructors in the aarch64 init function

Now that we have separated the kmalloc.cpp constructors into a separate
library, we can actually call the constructors in the init function.
This commit is contained in:
Timon Kruiper 2022-05-09 11:37:09 +02:00 committed by Linus Groh
parent 2e49d6b001
commit ed4bfaed12
Notes: sideshowbarker 2024-07-17 11:07:25 +09:00
2 changed files with 19 additions and 0 deletions

View file

@ -38,6 +38,12 @@ extern "C" [[noreturn]] void halt();
extern "C" [[noreturn]] void init();
extern "C" void exception_common(TrapFrame const* const trap_frame);
typedef void (*ctor_func_t)();
extern ctor_func_t start_heap_ctors[];
extern ctor_func_t end_heap_ctors[];
extern ctor_func_t start_ctors[];
extern ctor_func_t end_ctors[];
extern "C" [[noreturn]] void init()
{
dbgln("Welcome to Serenity OS!");
@ -45,7 +51,16 @@ extern "C" [[noreturn]] void init()
dbgln("Observed deviations from that ideal are shortcomings of your imagination.");
dbgln();
// We call the constructors of kmalloc.cpp separately, because other constructors in the Kernel
// might rely on being able to call new/kmalloc in the constructor. We do have to run the
// kmalloc constructors, because kmalloc_init relies on that.
for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++)
(*ctor)();
kmalloc_init();
for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++)
(*ctor)();
Kernel::load_kernel_symbol_table();
auto firmware_version = query_firmware_version();

View file

@ -22,6 +22,10 @@ SECTIONS
.rodata ALIGN(4K) : AT (ADDR(.rodata))
{
start_heap_ctors = .;
*libkernel_heap.a:*(.init_array)
end_heap_ctors = .;
start_ctors = .;
*(.init_array)
end_ctors = .;