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

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

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 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
OLDNEW
1 #include <elf.h> 1 #include <elf.h>
2 #include <poll.h> 2 #include <poll.h>
3 #include <fcntl.h> 3 #include <fcntl.h>
4 #include <signal.h> 4 #include <signal.h>
5 #include "syscall.h" 5 #include "syscall.h"
6 #include "atomic.h" 6 #include "atomic.h"
7 #include "libc.h" 7 #include "libc.h"
8 8
9 void __init_tls(size_t *); 9 void __init_tls(size_t*);
10 10
11 static void dummy(void) {} 11 static void dummy(void) {}
12 weak_alias(dummy, _init); 12 weak_alias(dummy, _init);
13 13
14 __attribute__((__weak__, __visibility__("hidden"))) 14 __attribute__((__weak__, __visibility__("hidden"))) extern void (
15 extern void (*const __init_array_start)(void), (*const __init_array_end)(void); 15 *const __init_array_start)(void),
16 (*const __init_array_end)(void);
16 17
17 static void dummy1(void *p) {} 18 static void dummy1(void* p) {}
18 weak_alias(dummy1, __init_ssp); 19 weak_alias(dummy1, __init_ssp);
19 20
20 #define AUX_CNT 38 21 #define AUX_CNT 38
21 22
22 void __init_libc(char **envp, char *pn) 23 void __init_libc(char** envp, char* pn) {
23 { 24 size_t i, *auxv, aux[AUX_CNT] = {0};
24 » size_t i, *auxv, aux[AUX_CNT] = { 0 }; 25 __environ = envp;
25 » __environ = envp; 26 for (i = 0; envp[i]; i++)
26 » for (i=0; envp[i]; i++); 27 ;
27 » libc.auxv = auxv = (void *)(envp+i+1); 28 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 for (i = 0; auxv[i]; i += 2)
29 » __hwcap = aux[AT_HWCAP]; 30 if (auxv[i] < AUX_CNT)
30 » __sysinfo = aux[AT_SYSINFO]; 31 aux[auxv[i]] = auxv[i + 1];
31 » libc.page_size = aux[AT_PAGESZ]; 32 __hwcap = aux[AT_HWCAP];
33 __sysinfo = aux[AT_SYSINFO];
34 libc.page_size = aux[AT_PAGESZ];
32 35
33 » if (pn) { 36 if (pn) {
34 » » __progname = __progname_full = pn; 37 __progname = __progname_full = pn;
35 » » for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1; 38 for (i = 0; pn[i]; i++)
36 » } 39 if (pn[i] == '/')
40 __progname = pn + i + 1;
41 }
37 42
38 » __init_tls(aux); 43 __init_tls(aux);
39 » __init_ssp((void *)aux[AT_RANDOM]); 44 __init_ssp((void*)aux[AT_RANDOM]);
40 45
41 » if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID] 46 if (aux[AT_UID] == aux[AT_EUID] && aux[AT_GID] == aux[AT_EGID] &&
42 » » && !aux[AT_SECURE]) return; 47 !aux[AT_SECURE])
48 return;
43 49
44 » struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} }; 50 struct pollfd pfd[3] = {{.fd = 0}, {.fd = 1}, {.fd = 2}};
45 #ifdef SYS_poll 51 #ifdef SYS_poll
46 » __syscall(SYS_poll, pfd, 3, 0); 52 __syscall(SYS_poll, pfd, 3, 0);
47 #else 53 #else
48 » __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8); 54 __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG / 8);
49 #endif 55 #endif
50 » for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL) 56 for (i = 0; i < 3; i++)
51 » » if (__sys_open("/dev/null", O_RDWR)<0) 57 if (pfd[i].revents & POLLNVAL)
52 » » » a_crash(); 58 if (__sys_open("/dev/null", O_RDWR) < 0)
53 » libc.secure = 1; 59 a_crash();
60 libc.secure = 1;
54 } 61 }
55 62
56 static void libc_start_init(void) 63 static void libc_start_init(void) {
57 { 64 _init();
58 » _init(); 65 uintptr_t a = (uintptr_t)&__init_array_start;
59 » uintptr_t a = (uintptr_t)&__init_array_start; 66 for (; a < (uintptr_t)&__init_array_end; a += sizeof(void (*)()))
60 » for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)())) 67 (*(void (**)())a)();
61 » » (*(void (**)())a)();
62 } 68 }
63 69
64 weak_alias(libc_start_init, __libc_start_init); 70 weak_alias(libc_start_init, __libc_start_init);
65 71
66 int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) 72 int __libc_start_main(int (*main)(int, char**, char**), int argc, char** argv) {
67 { 73 char** envp = argv + argc + 1;
68 » char **envp = argv+argc+1;
69 74
70 » __init_libc(envp, argv[0]); 75 __init_libc(envp, argv[0]);
71 » __libc_start_init(); 76 __libc_start_init();
72 77
73 » /* Pass control to the application */ 78 /* Pass control to the application */
74 » exit(main(argc, argv, envp)); 79 exit(main(argc, argv, envp));
75 » return 0; 80 return 0;
76 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698