From 98cbfec5643090601b4b11da4657722a7767e331 Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Fri, 29 Jan 2021 15:38:22 +0100 Subject: [PATCH] sysdeps/managarm: Change the startup code to use the generic version Signed-off-by: Dennis Bonke --- sysdeps/managarm/generic/entry.cpp | 31 +++++++++--------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/sysdeps/managarm/generic/entry.cpp b/sysdeps/managarm/generic/entry.cpp index f7695c90..b9e31802 100644 --- a/sysdeps/managarm/generic/entry.cpp +++ b/sysdeps/managarm/generic/entry.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // defined by the POSIX library void __mlibc_initLocale(); @@ -115,33 +116,19 @@ struct LibraryGuard { static LibraryGuard guard; -static int __mlibc_argc; -static char **__mlibc_argv; +extern char **environ; +static mlibc::exec_stack_data __mlibc_stack_data; LibraryGuard::LibraryGuard() { __mlibc_initLocale(); - // Parse the environment. - // TODO: Copy the arguments instead of pointing to them? - auto env = __dlapi_entrystack(); - __mlibc_argc = *env++; - __mlibc_argv = reinterpret_cast(env); - env += __mlibc_argc; // Skip all arguments. - __ensure(!*env); - env++; - - while(*env) { - auto string = reinterpret_cast(*env); - auto fail = putenv(string); - __ensure(!fail); - env++; - } + // 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); } -// The environment was build by the LibraryGuard. -extern char **environ; - -extern "C" void __mlibc_entry(int (*main_function)(int argc, char *argv[], char *env[])) { - auto result = main_function(__mlibc_argc, __mlibc_argv, environ); +extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], char *env[])) { + auto result = main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); exit(result); }