From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- lib/mlibc/sysdeps/dripos/generic/entry.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/mlibc/sysdeps/dripos/generic/entry.cpp (limited to 'lib/mlibc/sysdeps/dripos/generic/entry.cpp') diff --git a/lib/mlibc/sysdeps/dripos/generic/entry.cpp b/lib/mlibc/sysdeps/dripos/generic/entry.cpp new file mode 100644 index 0000000..2b8b914 --- /dev/null +++ b/lib/mlibc/sysdeps/dripos/generic/entry.cpp @@ -0,0 +1,35 @@ + +#include +#include +#include +#include + +// defined by the POSIX library +void __mlibc_initLocale(); + +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() { + __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, + __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); + exit(result); +} + -- cgit v1.2.3