about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-03-02 10:51:27 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-03-02 10:51:27 +0100
commitbe92787329b59cf0f2202ca7623055372df0d90f (patch)
tree0f446cd46ffe2299926d8ccc971d95dfaacd9b18
parent26201d7e705714cd8ecca3fa28f51e819f9eb520 (diff)
downloadbox64-be92787329b59cf0f2202ca7623055372df0d90f.tar.gz
box64-be92787329b59cf0f2202ca7623055372df0d90f.zip
Preparing auxval handling
-rwxr-xr-xCMakeLists.txt1
-rwxr-xr-xsrc/include/auxval.h13
-rwxr-xr-xsrc/libtools/auxval.c59
-rwxr-xr-xsrc/main.c3
4 files changed, 75 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16564e17..177b34cf 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,6 +103,7 @@ set(ELFLOADER_SRC
     "${BOX64_ROOT}/src/elfs/elfloader.c"
     "${BOX64_ROOT}/src/elfs/elfparser.c"
     "${BOX64_ROOT}/src/elfs/elfload_dump.c"
+    "${BOX64_ROOT}/src/libtools/auxval.c"
     "${BOX64_ROOT}/src/tools/box64stack.c"
     "${BOX64_ROOT}/src/tools/pathcoll.c"
     "${BOX64_ROOT}/src/tools/fileutils.c"
diff --git a/src/include/auxval.h b/src/include/auxval.h
new file mode 100755
index 00000000..6688d78f
--- /dev/null
+++ b/src/include/auxval.h
@@ -0,0 +1,13 @@
+#ifndef __AUXVAL_H__
+#define __AUXVAL_H__
+
+typedef struct x64emu_s x64emu_t;
+
+#ifndef BUILD_LIB
+int init_auxval(int argc, const char **argv, const char **env);
+#endif
+
+unsigned long real_getauxval(unsigned long type);
+//unsigned long my_getauxval(x64emu_t* emu, unsigned long type);
+
+#endif //__AUXVAL_H__
\ No newline at end of file
diff --git a/src/libtools/auxval.c b/src/libtools/auxval.c
new file mode 100755
index 00000000..a038f2dd
--- /dev/null
+++ b/src/libtools/auxval.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <syscall.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <fts.h>
+
+#include "box64context.h"
+#include "debug.h"
+//#include "x64emu.h"
+//#include "emu/x64emu_private.h"
+#include "box64stack.h"
+#include "auxval.h"
+
+static uintptr_t* auxval_start = NULL;
+
+int init_auxval(int argc, const char **argv, const char **env) {
+    // auxval vector is after envs...
+    while(*env)
+        env++;
+    auxval_start = (uintptr_t*)(env+1);
+    return 0;
+}
+
+#ifdef BUILD_LIB
+__attribute__((section(".init_array"))) static void *init_auxval_constructor = &init_auxval;
+#endif
+
+unsigned long real_getauxval(unsigned long type)
+{
+    if(!auxval_start)
+        return 0;
+    uintptr_t* p = auxval_start;
+    while(*p) {
+        if(*p == type)
+            return p[1];
+        p+=2;
+    }
+    return 0;
+}
+
+//EXPORT unsigned long my_getauxval(x64emu_t* emu, unsigned long type)
+//{
+//    uintptr_t* p = emu->context->auxval_start;
+//    while(*p) {
+//        if(*p == type)
+//            return p[1];
+//        p+=2;
+//    }
+//    return 0;
+//}
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
index 4d5b7fe8..d9052a58 100755
--- a/src/main.c
+++ b/src/main.c
@@ -17,6 +17,7 @@
 #include "elfloader.h"
 #include "custommem.h"
 #include "box64stack.h"
+#include "auxval.h"
 
 box64context_t *my_context = NULL;
 int box64_log = LOG_NONE;
@@ -524,7 +525,7 @@ static void free_contextargv()
 const char **environ __attribute__((weak)) = NULL;
 int main(int argc, const char **argv, const char **env) {
 
-    //init_auxval(argc, argv, environ?environ:env);
+    init_auxval(argc, argv, environ?environ:env);
     // trying to open and load 1st arg
     if(argc==1) {
         PrintBox64Version();