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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/env/__libc_start_main.c
diff --git a/fusl/src/env/__libc_start_main.c b/fusl/src/env/__libc_start_main.c
new file mode 100644
index 0000000000000000000000000000000000000000..5c79be28f0b5c8205a53ad1f23510b57da9ca7d4
--- /dev/null
+++ b/fusl/src/env/__libc_start_main.c
@@ -0,0 +1,76 @@
+#include <elf.h>
+#include <poll.h>
+#include <fcntl.h>
+#include <signal.h>
+#include "syscall.h"
+#include "atomic.h"
+#include "libc.h"
+
+void __init_tls(size_t *);
+
+static void dummy(void) {}
+weak_alias(dummy, _init);
+
+__attribute__((__weak__, __visibility__("hidden")))
+extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
+
+static void dummy1(void *p) {}
+weak_alias(dummy1, __init_ssp);
+
+#define AUX_CNT 38
+
+void __init_libc(char **envp, char *pn)
+{
+ size_t i, *auxv, aux[AUX_CNT] = { 0 };
+ __environ = envp;
+ for (i=0; envp[i]; i++);
+ libc.auxv = auxv = (void *)(envp+i+1);
+ for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
+ __hwcap = aux[AT_HWCAP];
+ __sysinfo = aux[AT_SYSINFO];
+ libc.page_size = aux[AT_PAGESZ];
+
+ if (pn) {
+ __progname = __progname_full = pn;
+ for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
+ }
+
+ __init_tls(aux);
+ __init_ssp((void *)aux[AT_RANDOM]);
+
+ if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
+ && !aux[AT_SECURE]) return;
+
+ struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
+#ifdef SYS_poll
+ __syscall(SYS_poll, pfd, 3, 0);
+#else
+ __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
+#endif
+ for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
+ if (__sys_open("/dev/null", O_RDWR)<0)
+ a_crash();
+ libc.secure = 1;
+}
+
+static void libc_start_init(void)
+{
+ _init();
+ uintptr_t a = (uintptr_t)&__init_array_start;
+ for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
+ (*(void (**)())a)();
+}
+
+weak_alias(libc_start_init, __libc_start_init);
+
+int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
+{
+ char **envp = argv+argc+1;
+
+ __init_libc(envp, argv[0]);
+ __libc_start_init();
+
+ /* Pass control to the application */
+ exit(main(argc, argv, envp));
+ return 0;
+}
« 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