All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, Ammar Faizi <ammarfaizi2@gnuweeb.org>
Subject: [PATCH 20/22] nolibc/stdlib: Implement `getauxval(3)` function
Date: Mon,  9 Jan 2023 09:42:06 +0100	[thread overview]
Message-ID: <20230109084208.27355-21-w@1wt.eu> (raw)
In-Reply-To: <20230109084208.27355-1-w@1wt.eu>

From: Ammar Faizi <ammarfaizi2@gnuweeb.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@gnuweeb.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 a24000d1e822..894c955d027e 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)
 {
-- 
2.17.5


  parent reply	other threads:[~2023-01-09  8:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  8:41 [PATCH 00/22] nolibc: usability improvements (errno, environ, auxv) Willy Tarreau
2023-01-09  8:41 ` [PATCH 01/22] tools/nolibc: make compiler and assembler agree on the section around _start Willy Tarreau
2023-01-09  8:41 ` [PATCH 02/22] tools/nolibc: enable support for thumb1 mode for ARM Willy Tarreau
2023-01-09  8:41 ` [PATCH 03/22] tools/nolibc: support thumb mode with frame pointers on ARM Willy Tarreau
2023-01-09  8:41 ` [PATCH 04/22] tools/nolibc: remove local definitions of O_* flags for open/fcntl Willy Tarreau
2023-01-09  8:41 ` [PATCH 05/22] tools/nolibc: make errno a weak symbol instead of a static one Willy Tarreau
2023-01-09  8:41 ` [PATCH 06/22] tools/nolibc: export environ as a weak symbol on x86_64 Willy Tarreau
2023-01-09  8:41 ` [PATCH 07/22] tools/nolibc: export environ as a weak symbol on i386 Willy Tarreau
2023-01-09  8:41 ` [PATCH 08/22] tools/nolibc: export environ as a weak symbol on arm64 Willy Tarreau
2023-01-09  8:41 ` [PATCH 09/22] tools/nolibc: export environ as a weak symbol on arm Willy Tarreau
2023-01-09  8:41 ` [PATCH 10/22] tools/nolibc: export environ as a weak symbol on mips Willy Tarreau
2023-01-09  8:41 ` [PATCH 11/22] tools/nolibc: export environ as a weak symbol on riscv Willy Tarreau
2023-01-09  8:41 ` [PATCH 12/22] tools/nolibc: export environ as a weak symbol on s390 Willy Tarreau
2023-01-09  8:41 ` [PATCH 13/22] tools/nolibc: add auxiliary vector retrieval for i386 Willy Tarreau
2023-01-09  8:42 ` [PATCH 14/22] tools/nolibc: add auxiliary vector retrieval for x86_64 Willy Tarreau
2023-01-09  8:42 ` [PATCH 15/22] tools/nolibc: add auxiliary vector retrieval for arm64 Willy Tarreau
2023-01-09  8:42 ` [PATCH 16/22] tools/nolibc: add auxiliary vector retrieval for arm Willy Tarreau
2023-01-09  8:42 ` [PATCH 17/22] tools/nolibc: add auxiliary vector retrieval for riscv Willy Tarreau
2023-01-09  8:42 ` [PATCH 18/22] tools/nolibc: add auxiliary vector retrieval for mips Willy Tarreau
2023-01-09  8:42 ` [PATCH 19/22] tools/nolibc: add auxiliary vector retrieval for s390 Willy Tarreau
2023-01-09  8:42 ` Willy Tarreau [this message]
2023-01-09  8:42 ` [PATCH 21/22] nolibc/sys: Implement `getpagesize(2)` function Willy Tarreau
2023-01-09  8:42 ` [PATCH 22/22] selftests/nolibc: Add `getpagesize(2)` selftest Willy Tarreau
2023-01-09  9:15 ` [PATCH 00/22] nolibc: usability improvements (errno, environ, auxv) Ammar Faizi
2023-01-09  9:17   ` Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109084208.27355-21-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.