LibC: Add sys/auxv.h with getauxval
This commit is contained in:
@@ -2,12 +2,6 @@
|
||||
#include <BAN/Debug.h>
|
||||
#include <BAN/StringView.h>
|
||||
|
||||
#include <LibELF/AuxiliaryVector.h>
|
||||
|
||||
#include <kernel/API/SharedPage.h>
|
||||
#include <kernel/API/Syscall.h>
|
||||
#include <kernel/Memory/Types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -19,6 +13,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/banan-os.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -36,7 +31,6 @@ struct init_funcs_t
|
||||
|
||||
extern "C" char** environ;
|
||||
|
||||
volatile Kernel::API::SharedPage* g_shared_page = nullptr;
|
||||
|
||||
#define DUMP_BACKTRACE 1
|
||||
#define DEMANGLE_BACKTRACE 0
|
||||
@@ -58,28 +52,11 @@ void __stack_chk_fail(void) { abort(); }
|
||||
|
||||
static void __dump_backtrace(int, siginfo_t*, void*);
|
||||
|
||||
static LibELF::AuxiliaryVector* find_auxv(char** envp)
|
||||
{
|
||||
if (envp == nullptr)
|
||||
return nullptr;
|
||||
|
||||
char** null_env = envp;
|
||||
while (*null_env)
|
||||
null_env++;
|
||||
|
||||
return reinterpret_cast<LibELF::AuxiliaryVector*>(null_env + 1);
|
||||
}
|
||||
|
||||
extern "C" void _init_libc(char** environ, init_funcs_t init_funcs, init_funcs_t fini_funcs)
|
||||
{
|
||||
if (::environ == nullptr)
|
||||
::environ = environ;
|
||||
|
||||
if (auto* auxv = find_auxv(environ))
|
||||
for (auto* aux = auxv; aux->a_type != LibELF::AT_NULL; aux++)
|
||||
if (aux->a_type == LibELF::AT_SHARED_PAGE)
|
||||
g_shared_page = static_cast<Kernel::API::SharedPage*>(aux->a_un.a_ptr);
|
||||
|
||||
#if defined(__x86_64__)
|
||||
if (uthread* self = reinterpret_cast<uthread*>(syscall(SYS_GET_FSBASE)))
|
||||
#elif defined(__i686__)
|
||||
|
||||
Reference in New Issue
Block a user