Add zig build system
This commit is contained in:
parent
e11b6cc0b3
commit
0038ff7254
5 changed files with 259 additions and 51 deletions
67
src/getauxval_backport.c
Normal file
67
src/getauxval_backport.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <elf.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef GETAUXVAL_BACKPORT_ELF64
|
||||
typedef Elf64_auxv_t __auxv_t;
|
||||
#else
|
||||
typedef Elf32_auxv_t __auxv_t;
|
||||
#endif
|
||||
|
||||
#define AUXV_FILE "/proc/self/auxv"
|
||||
|
||||
#ifdef GETAUXVAL_BACKPORT_FILE
|
||||
|
||||
unsigned long __getauxval_file(unsigned long type) {
|
||||
FILE *f = fopen(AUXV_FILE, "rb");
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
unsigned long val = 0;
|
||||
__auxv_t aux;
|
||||
|
||||
while (fread(&aux, sizeof(aux), 1, f) == 1 && aux.a_type != AT_NULL) {
|
||||
if (aux.a_type == type) {
|
||||
val = aux.a_un.a_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern char **environ;
|
||||
|
||||
char **envp_auxv = NULL;
|
||||
|
||||
unsigned long __getauxval_envp(unsigned long type) {
|
||||
if (envp_auxv == NULL) {
|
||||
envp_auxv = environ;
|
||||
while (*envp_auxv++ != NULL)
|
||||
;
|
||||
}
|
||||
|
||||
__auxv_t *auxv;
|
||||
|
||||
for (auxv = (__auxv_t *)envp_auxv; auxv->a_type != AT_NULL; auxv++) {
|
||||
if (auxv->a_type == type) {
|
||||
return auxv->a_un.a_val;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
unsigned long getauxval(unsigned long type) {
|
||||
#ifdef GETAUXVAL_BACKPORT_FILE
|
||||
return __getauxval_file(type);
|
||||
#else
|
||||
return __getauxval_envp(type);
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue