mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:37:34 +00:00
LibC: Run constructors on process startup.
Cooperate with the compiler to generate and execute the _init_array list of constructor functions on userspace program statup. This took two days to get working, my goodness. :^)
This commit is contained in:
parent
f1a2cb0882
commit
23bb276fcd
22 changed files with 101 additions and 61 deletions
|
@ -10,17 +10,31 @@ int errno;
|
|||
char** environ;
|
||||
//bool __environ_is_malloced;
|
||||
|
||||
void __malloc_init();
|
||||
void __stdio_init();
|
||||
void __libc_init()
|
||||
{
|
||||
void __malloc_init();
|
||||
__malloc_init();
|
||||
|
||||
void __stdio_init();
|
||||
__stdio_init();
|
||||
}
|
||||
|
||||
int _start(int argc, char** argv, char** env)
|
||||
{
|
||||
errno = 0;
|
||||
environ = env;
|
||||
//__environ_is_malloced = false;
|
||||
|
||||
__stdio_init();
|
||||
__malloc_init();
|
||||
__libc_init();
|
||||
|
||||
extern void _init();
|
||||
_init();
|
||||
|
||||
extern void (*__init_array_start[])(int, char**, char**) __attribute__((visibility("hidden")));
|
||||
extern void (*__init_array_end[])(int, char**, char**) __attribute__((visibility("hidden")));
|
||||
|
||||
const size_t size = __init_array_end - __init_array_start;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
(*__init_array_start[i])(argc, argv, env);
|
||||
|
||||
int status = main(argc, argv);
|
||||
|
||||
|
@ -37,4 +51,8 @@ int _start(int argc, char** argv, char** env)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
void __cxa_atexit()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue