8 void __init_tls(size_t *);
11 static void dummy() {}
12 weak_alias(dummy, _init);
13 extern void (*const __init_array_start)() __attribute__((weak));
14 extern void (*const __init_array_end)() __attribute__((weak));
17 static void dummy1(void *p) {}
18 weak_alias(dummy1, __init_ssp);
22 extern size_t __hwcap, __sysinfo;
23 extern char *__progname, *__progname_full;
25 void __init_libc(char **envp, char *pn)
27 size_t i, *auxv, aux[AUX_CNT] = { 0 };
29 for (i=0; envp[i]; i++);
30 libc.auxv = auxv = (void *)(envp+i+1);
31 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
32 __hwcap = aux[AT_HWCAP];
33 __sysinfo = aux[AT_SYSINFO];
34 libc.page_size = aux[AT_PAGESZ];
37 __progname = __progname_full = pn;
38 for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
42 __init_ssp((void *)aux[AT_RANDOM]);
44 if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
45 && !aux[AT_SECURE]) return;
47 struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
48 __syscall(SYS_poll, pfd, 3, 0);
49 for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
50 if (__syscall(SYS_open, "/dev/null", O_RDWR|O_LARGEFILE)<0)
55 int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
57 char **envp = argv+argc+1;
60 __init_libc(envp, argv[0]);
62 uintptr_t a = (uintptr_t)&__init_array_start;
63 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
67 /* Pass control to to application */
68 exit(main(argc, argv, envp));