diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-03-02 10:51:27 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-03-02 10:51:27 +0100 |
| commit | be92787329b59cf0f2202ca7623055372df0d90f (patch) | |
| tree | 0f446cd46ffe2299926d8ccc971d95dfaacd9b18 /src | |
| parent | 26201d7e705714cd8ecca3fa28f51e819f9eb520 (diff) | |
| download | box64-be92787329b59cf0f2202ca7623055372df0d90f.tar.gz box64-be92787329b59cf0f2202ca7623055372df0d90f.zip | |
Preparing auxval handling
Diffstat (limited to 'src')
| -rwxr-xr-x | src/include/auxval.h | 13 | ||||
| -rwxr-xr-x | src/libtools/auxval.c | 59 | ||||
| -rwxr-xr-x | src/main.c | 3 |
3 files changed, 74 insertions, 1 deletions
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(); |