Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: fusl/src/env/__libc_start_main.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/env/__init_tls.c ('k') | fusl/src/env/__reset_tls.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <elf.h>
2 #include <poll.h>
3 #include <fcntl.h>
4 #include <signal.h>
5 #include "syscall.h"
6 #include "atomic.h"
7 #include "libc.h"
8
9 void __init_tls(size_t *);
10
11 static void dummy(void) {}
12 weak_alias(dummy, _init);
13
14 __attribute__((__weak__, __visibility__("hidden")))
15 extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
16
17 static void dummy1(void *p) {}
18 weak_alias(dummy1, __init_ssp);
19
20 #define AUX_CNT 38
21
22 void __init_libc(char **envp, char *pn)
23 {
24 size_t i, *auxv, aux[AUX_CNT] = { 0 };
25 __environ = envp;
26 for (i=0; envp[i]; i++);
27 libc.auxv = auxv = (void *)(envp+i+1);
28 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
29 __hwcap = aux[AT_HWCAP];
30 __sysinfo = aux[AT_SYSINFO];
31 libc.page_size = aux[AT_PAGESZ];
32
33 if (pn) {
34 __progname = __progname_full = pn;
35 for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
36 }
37
38 __init_tls(aux);
39 __init_ssp((void *)aux[AT_RANDOM]);
40
41 if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
42 && !aux[AT_SECURE]) return;
43
44 struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
45 #ifdef SYS_poll
46 __syscall(SYS_poll, pfd, 3, 0);
47 #else
48 __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
49 #endif
50 for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
51 if (__sys_open("/dev/null", O_RDWR)<0)
52 a_crash();
53 libc.secure = 1;
54 }
55
56 static void libc_start_init(void)
57 {
58 _init();
59 uintptr_t a = (uintptr_t)&__init_array_start;
60 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
61 (*(void (**)())a)();
62 }
63
64 weak_alias(libc_start_init, __libc_start_init);
65
66 int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
67 {
68 char **envp = argv+argc+1;
69
70 __init_libc(envp, argv[0]);
71 __libc_start_init();
72
73 /* Pass control to the application */
74 exit(main(argc, argv, envp));
75 return 0;
76 }
OLDNEW
« no previous file with comments | « fusl/src/env/__init_tls.c ('k') | fusl/src/env/__reset_tls.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698