From fda6af7b8ed466ff71623de3f50b619942a69a70 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 19 May 2024 20:41:13 -0400 Subject: libc: Add auxv_entry() Signed-off-by: Ian Moffett --- lib/libc/include/sys/auxv.h | 2 ++ lib/libc/src/main.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'lib') diff --git a/lib/libc/include/sys/auxv.h b/lib/libc/include/sys/auxv.h index a776e05..9851ffd 100644 --- a/lib/libc/include/sys/auxv.h +++ b/lib/libc/include/sys/auxv.h @@ -53,4 +53,6 @@ struct auxv_entry { }; }; +unsigned long auxv_entry(unsigned long type); + #endif /* _SYS_AUXV_H */ diff --git a/lib/libc/src/main.c b/lib/libc/src/main.c index 890f3c8..afe2492 100644 --- a/lib/libc/src/main.c +++ b/lib/libc/src/main.c @@ -27,22 +27,49 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include int main(int argc, const char **argv, const char **envp); +static uint64_t auxv[AT_MAX_COUNT]; FILE *stdout; +unsigned long +auxv_entry(unsigned long type) +{ + if (type >= AT_MAX_COUNT) + return 0; + + return auxv[type]; +} + int __libc_entry(uint64_t *ctx) { + uint64_t envc = 0; uint64_t argc = *ctx; const char **argv = (const char **)(ctx + 1); const char **envp = (const char **)(argv + argc + 1); + const struct auxv_entry *auxvp = NULL; + + /* Count envp entries */ + for (const char **env = envp; *env != NULL; ++env) { + ++envc; + } stdout = fdopen(STDOUT_FILENO, "a"); + auxvp = (struct auxv_entry *)(envp + envc + 1); + + /* Populate 'auxv' */ + while (auxvp->tag != AT_NULL) { + if (auxvp->tag < AT_MAX_COUNT) { + auxv[auxvp->tag] = auxvp->val; + } + ++auxvp; + } return main(argc, argv, envp); } -- cgit v1.2.3