source: azure_iot_hub/trunk/musl-1.1.18/src/env/__libc_start_main.c@ 389

Last change on this file since 389 was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 2.2 KB
Line 
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
9void __init_tls(size_t *);
10
11#ifndef __c2__
12static void dummy(void) {}
13weak_alias(dummy, _init);
14#else
15__attribute((weak))
16void _init(void) {}
17#endif
18
19#ifndef __c2__
20__attribute__((__weak__, __visibility__("hidden")))
21extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
22#else
23extern void(*const __init_array_start)(void);
24#define __init_array_end __init_array_start
25#endif
26
27#ifndef __c2__
28static void dummy1(void *p) {}
29weak_alias(dummy1, __init_ssp);
30#else
31__attribute((weak))
32void __init_ssp(void *p) {}
33#endif
34
35#define AUX_CNT 38
36
37void __init_libc(char **envp, char *pn)
38{
39 size_t i, *auxv, aux[AUX_CNT] = { 0 };
40 __environ = envp;
41 for (i=0; envp[i]; i++);
42 libc.auxv = auxv = (void *)(envp+i+1);
43 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
44 __hwcap = aux[AT_HWCAP];
45 __sysinfo = aux[AT_SYSINFO];
46 libc.page_size = aux[AT_PAGESZ];
47
48 if (!pn) pn = (void*)aux[AT_EXECFN];
49 if (!pn) pn = "";
50 __progname = __progname_full = pn;
51 for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
52
53 __init_tls(aux);
54 __init_ssp((void *)aux[AT_RANDOM]);
55
56 if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
57 && !aux[AT_SECURE]) return;
58
59 struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
60#ifdef SYS_poll
61 __syscall(SYS_poll, pfd, 3, 0);
62#else
63 __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
64#endif
65 for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
66 if (__sys_open("/dev/null", O_RDWR)<0)
67 a_crash();
68 libc.secure = 1;
69}
70
71static void libc_start_init(void)
72{
73 _init();
74 uintptr_t a = (uintptr_t)&__init_array_start;
75 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
76 (*(void (**)(void))a)();
77}
78
79#ifndef __c2__
80weak_alias(libc_start_init, __libc_start_init);
81#else
82void __libc_start_init(void)
83{
84 libc_start_init();
85}
86#undef exit
87#define exit(x) x
88#endif
89
90int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
91{
92 char **envp = argv+argc+1;
93
94 __init_libc(envp, argv[0]);
95 __libc_start_init();
96
97 /* Pass control to the application */
98 exit(main(argc, argv, envp));
99 return 0;
100}
Note: See TracBrowser for help on using the repository browser.