summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-06-28 20:11:49 -0400
committerIan Moffett <ian@osmora.org>2025-06-28 20:11:49 -0400
commit46190922e0fb42d27bc7c8ed85d9fd44664f50ef (patch)
treef6d8cd1f1b752cedb37c1f3b7ba52bf7c00055fe
parent228310e565d809e587cb0b8ab77353d6751a12e2 (diff)
usr: libc: Store auxiliary vector tag/value pairs
This commit introduces the global libc '__libc_auxv' containing auxiliary vector entries as per the System V Application Binary Interface Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--lib/libc/src/main.c33
-rw-r--r--sys/include/sys/exec.h3
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/libc/src/main.c b/lib/libc/src/main.c
index b178c07..02a648b 100644
--- a/lib/libc/src/main.c
+++ b/lib/libc/src/main.c
@@ -27,23 +27,50 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/exec.h>
#include <stdint.h>
#include <stddef.h>
extern int __libc_stdio_init(void);
extern int __malloc_mem_init(void);
+uint64_t __libc_auxv[_AT_MAX];
int main(int argc, char **argv);
+struct auxv_entry {
+ uint64_t tag;
+ uint64_t val;
+};
+
int
__libc_entry(uint64_t *ctx)
{
+ const struct auxv_entry *auxvp;
int status;
- uint64_t argc;
+ uint64_t argc, envc, tag;
char **argv;
+ char **envp;
+
+ argc = *ctx;
+ argv = (char **)(ctx + 1);
+ envp = (char **)(argv + argc + 1);
+
+ envc = 0;
+ while (envp[envc] != NULL) {
+ ++envc;
+ }
+
+ auxvp = (void *)(envp + envc + 1);
+ for (int i = 0; i < _AT_MAX; ++i) {
+ if (auxvp->tag == AT_NULL) {
+ break;
+ }
+ if (auxvp->tag < _AT_MAX) {
+ __libc_auxv[auxvp->tag] = auxvp->val;
+ }
- argc = *(ctx++);
- argv = (char **)((ctx++));
+ ++auxvp;
+ }
if ((status = __libc_stdio_init()) != 0) {
return status;
diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h
index 7e720fc..aa2a729 100644
--- a/sys/include/sys/exec.h
+++ b/sys/include/sys/exec.h
@@ -32,7 +32,6 @@
#include <sys/types.h>
-#if defined(_KERNEL)
/* Danger: Do not change these !! */
#define AT_NULL 0
@@ -45,7 +44,9 @@
#define AT_RANDOM 7
#define AT_EXECFN 8
#define AT_PAGESIZE 9
+#define _AT_MAX 16
+#if defined(_KERNEL)
#define MAX_PHDRS 32
#define STACK_PUSH(PTR, VAL) *(--(PTR)) = VAL
#define AUXVAL(PTR, TAG, VAL) \