summaryrefslogtreecommitdiff
path: root/lib/libc/internal/libc_main.c
blob: 7ac15ab4c0100d2341e6c4de4d32f13c9bbf712f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <libc.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/cdefs.h>

extern void __init_vdso(void);

struct libc __libc;
char **environ;
char *__progname;

extern int main(int, char **, char **);

__used void __libc_main(uintptr_t *rsp)
{
	char **argv;
	size_t *auxv;
	int argc;

	argc = (int)(*rsp);
	argv = (char **)(++rsp);

	rsp += argc;

	environ = (char **)(++rsp);
	__progname = argv[0];

	while (*rsp)
		rsp++;

	auxv = (size_t *)++rsp;

	for (size_t i = 0; auxv[i]; i += 2)
		__libc.auxv[auxv[i]] = auxv[i + 1];

	__init_vdso();

	exit(main(argc, argv, environ));
}