Skip to content

Commit c61a078

Browse files
ammarfaizi2paulmckrcu
authored andcommitted
nolibc/stdlib: Implement getauxval(3) function
Previous commits save the address of the auxiliary vector into a global variable @_auxv. This commit creates a new function 'getauxval()' as a helper function to get the auxv value based on the given key. The behavior of this function is identic with the function documented in 'man 3 getauxval'. This function is also needed to implement 'getpagesize()' function that we will wire up in the next patches. Signed-off-by: Ammar Faizi <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 241c4b4 commit c61a078

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tools/include/nolibc/stdlib.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "types.h"
1313
#include "sys.h"
1414
#include "string.h"
15+
#include <linux/auxvec.h>
1516

1617
struct nolibc_heap {
1718
size_t len;
@@ -108,6 +109,32 @@ char *getenv(const char *name)
108109
return _getenv(name, environ);
109110
}
110111

112+
static __attribute__((unused))
113+
unsigned long getauxval(unsigned long type)
114+
{
115+
const unsigned long *auxv = _auxv;
116+
unsigned long ret;
117+
118+
if (!auxv)
119+
return 0;
120+
121+
while (1) {
122+
if (!auxv[0] && !auxv[1]) {
123+
ret = 0;
124+
break;
125+
}
126+
127+
if (auxv[0] == type) {
128+
ret = auxv[1];
129+
break;
130+
}
131+
132+
auxv += 2;
133+
}
134+
135+
return ret;
136+
}
137+
111138
static __attribute__((unused))
112139
void *malloc(size_t len)
113140
{

0 commit comments

Comments
 (0)