mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[libc] Pull crt0 out into its own module
Sorta. crt0 is a separate module as far as bonnibel is concerned, but it's still part of the libc module file.
This commit is contained in:
38
src/libraries/libc/arch/amd64/init.cpp
Normal file
38
src/libraries/libc/arch/amd64/init.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stddef.h>
|
||||
|
||||
using cb = void (*)(void);
|
||||
extern cb __preinit_array_start;
|
||||
extern cb __preinit_array_end;
|
||||
extern cb __init_array_start;
|
||||
extern cb __init_array_end;
|
||||
|
||||
namespace {
|
||||
|
||||
void
|
||||
run_ctor_list(cb *array, cb *end)
|
||||
{
|
||||
if (!array || !end)
|
||||
return;
|
||||
|
||||
size_t i = 0;
|
||||
while (true) {
|
||||
const cb &ctor = array[i++];
|
||||
if (&ctor == end) return;
|
||||
if (ctor) ctor();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run_global_ctors()
|
||||
{
|
||||
run_ctor_list(&__preinit_array_start, &__preinit_array_end);
|
||||
run_ctor_list(&__init_array_start, &__init_array_end);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
void __init_libc()
|
||||
{
|
||||
run_global_ctors();
|
||||
}
|
||||
Reference in New Issue
Block a user