9 void __init_tls(size_t *);
12 static void dummy() {}
13 weak_alias(dummy, _init);
14 extern void (*const __init_array_start)() __attribute__((weak));
15 extern void (*const __init_array_end)() __attribute__((weak));
18 static void dummy1(void *p) {}
19 weak_alias(dummy1, __init_ssp);
23 extern size_t __hwcap, __sysinfo;
24 extern char *__progname, *__progname_full;
29 void __init_libc(char **envp, char *pn)
31 size_t i, *auxv, aux[AUX_CNT] = { 0 };
33 for (i=0; envp[i]; i++);
34 libc.auxv = auxv = (void *)(envp+i+1);
35 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
36 __hwcap = aux[AT_HWCAP];
37 __sysinfo = aux[AT_SYSINFO];
38 libc.page_size = aux[AT_PAGESZ];
41 __progname = __progname_full = pn;
42 for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
46 __init_ssp((void *)aux[AT_RANDOM]);
48 if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
49 && !aux[AT_SECURE]) return;
51 struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
53 __syscall(SYS_poll, pfd, 3, 0);
55 __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
57 for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
58 if (__sys_open("/dev/null", O_RDWR)<0)
63 int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
65 char **envp = argv+argc+1;
68 __init_libc(envp, argv[0]);
70 uintptr_t a = (uintptr_t)&__init_array_start;
71 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
75 /* Pass control to the application */
76 exit(main(argc, argv, envp));