From e5189197f521089d5b315b17be44d012630d53ae Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sat, 28 Dec 2024 22:25:33 +0100 Subject: [PATCH 1/2] sysdeps: invoke locale initialisation from gnu::constructor Rather than requiring each new sysdep to call this manually, we can put it in a `[[gnu::constructor]]`. --- options/ansi/generic/locale.cpp | 3 ++- sysdeps/aero/generic/entry.cpp | 5 ----- sysdeps/astral/generic/entry.cpp | 5 ----- sysdeps/dripos/generic/entry.cpp | 5 ----- sysdeps/ironclad/generic/entry.cpp | 5 ----- sysdeps/keyronex/generic/entry.cpp | 5 ----- sysdeps/lemon/generic/entry.cpp | 5 ----- sysdeps/linux/generic/entry.cpp | 5 ----- sysdeps/lyre/generic/entry.cpp | 5 ----- sysdeps/managarm/generic/entry.cpp | 5 ----- sysdeps/vinix/generic/entry.cpp | 5 ----- 11 files changed, 2 insertions(+), 51 deletions(-) diff --git a/options/ansi/generic/locale.cpp b/options/ansi/generic/locale.cpp index 38f5859ed4..cc4ae974c7 100644 --- a/options/ansi/generic/locale.cpp +++ b/options/ansi/generic/locale.cpp @@ -71,7 +71,8 @@ namespace mlibc { const locale_description *messages_facet; } -void __mlibc_initLocale() { +[[gnu::constructor]] +static void init_locale() { mlibc::collate_facet = &mlibc::c_locale; mlibc::ctype_facet = &mlibc::c_locale; mlibc::monetary_facet = &mlibc::c_locale; diff --git a/sysdeps/aero/generic/entry.cpp b/sysdeps/aero/generic/entry.cpp index 77d6ed5060..6ef7403681 100644 --- a/sysdeps/aero/generic/entry.cpp +++ b/sysdeps/aero/generic/entry.cpp @@ -3,9 +3,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern char **environ; @@ -18,8 +15,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/astral/generic/entry.cpp b/sysdeps/astral/generic/entry.cpp index d027bde76f..63dbf33fe7 100644 --- a/sysdeps/astral/generic/entry.cpp +++ b/sysdeps/astral/generic/entry.cpp @@ -3,9 +3,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -19,8 +16,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/dripos/generic/entry.cpp b/sysdeps/dripos/generic/entry.cpp index 2b8b9144dd..7d73a141ec 100644 --- a/sysdeps/dripos/generic/entry.cpp +++ b/sysdeps/dripos/generic/entry.cpp @@ -4,9 +4,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern char **environ; @@ -19,8 +16,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/ironclad/generic/entry.cpp b/sysdeps/ironclad/generic/entry.cpp index 49c67745f2..bd9a342b63 100644 --- a/sysdeps/ironclad/generic/entry.cpp +++ b/sysdeps/ironclad/generic/entry.cpp @@ -4,9 +4,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -20,8 +17,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/keyronex/generic/entry.cpp b/sysdeps/keyronex/generic/entry.cpp index ff15c62c6f..544c52d058 100644 --- a/sysdeps/keyronex/generic/entry.cpp +++ b/sysdeps/keyronex/generic/entry.cpp @@ -7,9 +7,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern char **environ; @@ -23,8 +20,6 @@ static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, diff --git a/sysdeps/lemon/generic/entry.cpp b/sysdeps/lemon/generic/entry.cpp index f4cf144dc2..65c37cf7e2 100644 --- a/sysdeps/lemon/generic/entry.cpp +++ b/sysdeps/lemon/generic/entry.cpp @@ -3,9 +3,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern char **environ; @@ -18,8 +15,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/linux/generic/entry.cpp b/sysdeps/linux/generic/entry.cpp index aa049ce375..9af2186b3b 100644 --- a/sysdeps/linux/generic/entry.cpp +++ b/sysdeps/linux/generic/entry.cpp @@ -4,9 +4,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -22,8 +19,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/lyre/generic/entry.cpp b/sysdeps/lyre/generic/entry.cpp index 62201ba899..9b2c7ca031 100644 --- a/sysdeps/lyre/generic/entry.cpp +++ b/sysdeps/lyre/generic/entry.cpp @@ -7,9 +7,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -23,8 +20,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, diff --git a/sysdeps/managarm/generic/entry.cpp b/sysdeps/managarm/generic/entry.cpp index 6fdda27fa1..3a23847afb 100644 --- a/sysdeps/managarm/generic/entry.cpp +++ b/sysdeps/managarm/generic/entry.cpp @@ -14,9 +14,6 @@ #include #include -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -117,8 +114,6 @@ extern char **environ; static mlibc::exec_stack_data __mlibc_stack_data; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data( diff --git a/sysdeps/vinix/generic/entry.cpp b/sysdeps/vinix/generic/entry.cpp index cadab222cb..47a1df34f0 100644 --- a/sysdeps/vinix/generic/entry.cpp +++ b/sysdeps/vinix/generic/entry.cpp @@ -8,9 +8,6 @@ #include "syscall.h" -// defined by the POSIX library -void __mlibc_initLocale(); - extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); @@ -24,8 +21,6 @@ struct LibraryGuard { static LibraryGuard guard; LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); - // Parse the exec() stack. mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, From 00097cccbc18769f4b76212f28360cfe871bf708 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sat, 28 Dec 2024 22:28:47 +0100 Subject: [PATCH 2/2] sysdeps: invoke entry stack parsing from gnu::constructor --- options/elf/generic/startup.cpp | 27 +++++++------------------ options/elf/include/mlibc/elf/startup.h | 8 ++------ sysdeps/aero/generic/entry.cpp | 16 +-------------- sysdeps/astral/generic/entry.cpp | 17 +--------------- sysdeps/dripos/generic/entry.cpp | 18 +---------------- sysdeps/ironclad/generic/entry.cpp | 17 +--------------- sysdeps/keyronex/generic/entry.cpp | 19 +---------------- sysdeps/lemon/generic/entry.cpp | 18 +---------------- sysdeps/linux/generic/entry.cpp | 17 +--------------- sysdeps/lyre/generic/entry.cpp | 17 +--------------- sysdeps/managarm/generic/entry.cpp | 17 +--------------- sysdeps/vinix/generic/entry.cpp | 17 +--------------- 12 files changed, 19 insertions(+), 189 deletions(-) diff --git a/options/elf/generic/startup.cpp b/options/elf/generic/startup.cpp index d53881ba11..e45a1970b1 100644 --- a/options/elf/generic/startup.cpp +++ b/options/elf/generic/startup.cpp @@ -12,31 +12,18 @@ extern "C" size_t __init_array_end[]; extern "C" size_t __preinit_array_start[]; extern "C" size_t __preinit_array_end[]; -static int constructors_ran_already = 0; +extern "C" uintptr_t *__dlapi_entrystack(); -struct global_constructor_guard { - global_constructor_guard() { - constructors_ran_already = 1; - } -}; +namespace mlibc { -static global_constructor_guard g; +exec_stack_data entry_stack; -void __mlibc_run_constructors() { -/* - if (!constructors_ran_already) { - size_t constructor_count = (size_t)__init_array_end - (size_t)__init_array_start; - constructor_count /= sizeof(void*); - for (size_t i = 0; i < constructor_count; i++) { - void (*ptr)(void) = (void(*)(void))(__init_array_start[i]); - ptr(); - } - } -*/ +[[gnu::constructor]] +void init_libc() { + mlibc::parse_exec_stack(__dlapi_entrystack(), &entry_stack); + mlibc::set_startup_data(entry_stack.argc, entry_stack.argv, entry_stack.envp); } -namespace mlibc { - void parse_exec_stack(void *opaque_sp, exec_stack_data *data) { auto sp = reinterpret_cast(opaque_sp); data->argc = *sp++; diff --git a/options/elf/include/mlibc/elf/startup.h b/options/elf/include/mlibc/elf/startup.h index f3c286cd84..b7db485800 100644 --- a/options/elf/include/mlibc/elf/startup.h +++ b/options/elf/include/mlibc/elf/startup.h @@ -1,12 +1,6 @@ #ifndef MLIBC_ELF_STARTUP #define MLIBC_ELF_STARTUP -#ifndef __MLIBC_ABI_ONLY - -void __mlibc_run_constructors(); - -#endif /* !__MLIBC_ABI_ONLY */ - namespace mlibc { struct exec_stack_data { @@ -15,6 +9,8 @@ struct exec_stack_data { char **envp; }; +extern exec_stack_data entry_stack; + #ifndef __MLIBC_ABI_ONLY void parse_exec_stack(void *sp, exec_stack_data *data); diff --git a/sysdeps/aero/generic/entry.cpp b/sysdeps/aero/generic/entry.cpp index 6ef7403681..2d11d60ae5 100644 --- a/sysdeps/aero/generic/entry.cpp +++ b/sysdeps/aero/generic/entry.cpp @@ -6,26 +6,12 @@ extern "C" uintptr_t *__dlapi_entrystack(); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) { // TODO: call __dlapi_enter, otherwise static builds will break (see Linux // sysdeps) auto result = - main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/astral/generic/entry.cpp b/sysdeps/astral/generic/entry.cpp index 63dbf33fe7..661377e886 100644 --- a/sysdeps/astral/generic/entry.cpp +++ b/sysdeps/astral/generic/entry.cpp @@ -3,28 +3,13 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[]), uintptr_t *entry_stack) { __dlapi_enter(entry_stack); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/dripos/generic/entry.cpp b/sysdeps/dripos/generic/entry.cpp index 7d73a141ec..62c9dbefc4 100644 --- a/sysdeps/dripos/generic/entry.cpp +++ b/sysdeps/dripos/generic/entry.cpp @@ -4,27 +4,11 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); - extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) { // TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps) - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/ironclad/generic/entry.cpp b/sysdeps/ironclad/generic/entry.cpp index bd9a342b63..1ca8a1e185 100644 --- a/sysdeps/ironclad/generic/entry.cpp +++ b/sysdeps/ironclad/generic/entry.cpp @@ -4,29 +4,14 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { __dlapi_enter(entry_stack); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/keyronex/generic/entry.cpp b/sysdeps/keyronex/generic/entry.cpp index 544c52d058..8e1c1f90a2 100644 --- a/sysdeps/keyronex/generic/entry.cpp +++ b/sysdeps/keyronex/generic/entry.cpp @@ -7,24 +7,7 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); - extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() -{ - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, - __mlibc_stack_data.argv, __mlibc_stack_data.envp); -} namespace mlibc { int @@ -97,7 +80,7 @@ __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) // TODO: call __dlapi_enter, otherwise static builds will break (see // Linux sysdeps) - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/lemon/generic/entry.cpp b/sysdeps/lemon/generic/entry.cpp index 65c37cf7e2..d49998b75c 100644 --- a/sysdeps/lemon/generic/entry.cpp +++ b/sysdeps/lemon/generic/entry.cpp @@ -3,26 +3,10 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); - extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) { // TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps) - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/linux/generic/entry.cpp b/sysdeps/linux/generic/entry.cpp index 9af2186b3b..7e54e4e199 100644 --- a/sysdeps/linux/generic/entry.cpp +++ b/sysdeps/linux/generic/entry.cpp @@ -4,30 +4,15 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; size_t __hwcap; -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} - extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { __dlapi_enter(entry_stack); __hwcap = getauxval(AT_HWCAP); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/lyre/generic/entry.cpp b/sysdeps/lyre/generic/entry.cpp index 9b2c7ca031..f58dfc83e5 100644 --- a/sysdeps/lyre/generic/entry.cpp +++ b/sysdeps/lyre/generic/entry.cpp @@ -7,24 +7,9 @@ #include #include -extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} struct GPRState { uint64_t ds; @@ -111,7 +96,7 @@ extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, c //mlibc::sys_sigentry((void *)__mlibc_sigentry); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/managarm/generic/entry.cpp b/sysdeps/managarm/generic/entry.cpp index 3a23847afb..ba190713a0 100644 --- a/sysdeps/managarm/generic/entry.cpp +++ b/sysdeps/managarm/generic/entry.cpp @@ -104,26 +104,11 @@ HelHandle getHandleForFd(int fd) { void clearCachedInfos() { has_cached_infos = PTHREAD_ONCE_INIT; } -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data( - __mlibc_stack_data.argc, __mlibc_stack_data.argv, __mlibc_stack_data.envp - ); -} extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { __dlapi_enter(entry_stack); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); } diff --git a/sysdeps/vinix/generic/entry.cpp b/sysdeps/vinix/generic/entry.cpp index 47a1df34f0..e92186a1d7 100644 --- a/sysdeps/vinix/generic/entry.cpp +++ b/sysdeps/vinix/generic/entry.cpp @@ -8,24 +8,9 @@ #include "syscall.h" -extern "C" uintptr_t *__dlapi_entrystack(); extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; - -struct LibraryGuard { - LibraryGuard(); -}; - -static LibraryGuard guard; - -LibraryGuard::LibraryGuard() { - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); -} struct GPRState { uint64_t ds; @@ -110,6 +95,6 @@ extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, c mlibc::sys_sigentry((void *)__mlibc_sigentry); __dlapi_enter(entry_stack); - auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); exit(result); }