[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230108130853.840948-2-ammar.faizi@intel.com>
Date: Sun, 8 Jan 2023 20:08:50 +0700
From: Ammar Faizi <ammarfaizi2@...weeb.org>
To: Willy Tarreau <w@....eu>
Cc: Ammar Faizi <ammarfaizi2@...weeb.org>,
Shuah Khan <shuah@...nel.org>,
"Paul E. McKenney" <paulmck@...nel.org>,
Sven Schnelle <svens@...ux.ibm.com>,
Alviro Iskandar Setiawan <alviro.iskandar@...weeb.org>,
GNU/Weeb Mailing List <gwml@...r.gnuweeb.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux Kselftest Mailing List
<linux-kselftest@...r.kernel.org>
Subject: [PATCH v1 1/3] nolibc/stdlib: Implement `getauxval(3)` function
From: Ammar Faizi <ammarfaizi2@...weeb.org>
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 <ammarfaizi2@...weeb.org>
---
tools/include/nolibc/stdlib.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h
index 92378c4b9660..cdca557c4013 100644
--- a/tools/include/nolibc/stdlib.h
+++ b/tools/include/nolibc/stdlib.h
@@ -12,6 +12,7 @@
#include "types.h"
#include "sys.h"
#include "string.h"
+#include <linux/auxvec.h>
struct nolibc_heap {
size_t len;
@@ -108,6 +109,32 @@ char *getenv(const char *name)
return _getenv(name, environ);
}
+static __attribute__((unused))
+unsigned long getauxval(unsigned long type)
+{
+ const unsigned long *auxv = _auxv;
+ unsigned long ret;
+
+ if (!auxv)
+ return 0;
+
+ while (1) {
+ if (!auxv[0] && !auxv[1]) {
+ ret = 0;
+ break;
+ }
+
+ if (auxv[0] == type) {
+ ret = auxv[1];
+ break;
+ }
+
+ auxv += 2;
+ }
+
+ return ret;
+}
+
static __attribute__((unused))
void *malloc(size_t len)
{
--
Ammar Faizi
Powered by blists - more mailing lists