diff options
author | Ian Moffett <ian@osmora.org> | 2024-05-19 20:41:13 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-05-19 20:41:13 -0400 |
commit | fda6af7b8ed466ff71623de3f50b619942a69a70 (patch) | |
tree | bd6b1c0781d1891996afdd2c4b21f2bddeff04e5 /lib/libc/src/main.c | |
parent | 54add4b6a6176beb05199d542929fbdf27264820 (diff) |
libc: Add auxv_entry()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/libc/src/main.c')
-rw-r--r-- | lib/libc/src/main.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 <sys/auxv.h> #include <stdint.h> #include <stdio.h> #include <unistd.h> 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); } |