123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- #define _ERRNO_H
- #include <features.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <elf.h>
- #include <link.h>
- #include <bits/uClibc_page.h>
- #include <paths.h>
- #include <asm/errno.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/sysmacros.h>
- #ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
- #endif
- #ifndef __ARCH_HAS_NO_LDSO__
- extern __typeof(open) __libc_open;
- libc_hidden_proto(__libc_open)
- extern __typeof(fcntl) __libc_fcntl;
- libc_hidden_proto(__libc_fcntl)
- #endif
- #ifndef SHARED
- void *__libc_stack_end=NULL;
- # ifdef __UCLIBC_HAS_SSP__
- # include <dl-osinfo.h>
- # ifndef THREAD_SET_STACK_GUARD
- # include <stdint.h>
- uintptr_t stack_chk_guard;
- uintptr_t __stack_chk_guard attribute_relro;
- # ifdef __UCLIBC_HAS_SSP_COMPAT__
- # ifdef __HAVE_SHARED__
- strong_alias(__stack_chk_guard,__guard)
- # else
- uintptr_t __guard attribute_relro;
- # endif
- # endif
- # elif defined __UCLIBC_HAS_SSP_COMPAT__
- uintptr_t __guard attribute_relro;
- # endif
- # endif
- void internal_function _dl_aux_init (ElfW(auxv_t) *av);
- #endif
- extern int *weak_const_function __errno_location(void);
- libc_hidden_proto(__errno_location)
- extern int *weak_const_function __h_errno_location(void);
- libc_hidden_proto(__h_errno_location)
- extern void weak_function _stdio_init(void) attribute_hidden;
- #ifdef __UCLIBC_HAS_LOCALE__
- extern void weak_function _locale_init(void) attribute_hidden;
- #endif
- #ifdef __UCLIBC_HAS_THREADS__
- extern void weak_function __pthread_initialize_minimal(void);
- #endif
- #if defined (__UCLIBC_CTOR_DTOR__) && !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
- extern void _dl_app_init_array(void);
- extern void _dl_app_fini_array(void);
- # ifndef SHARED
- extern void (*__preinit_array_start []) (void) attribute_hidden;
- extern void (*__preinit_array_end []) (void) attribute_hidden;
- extern void (*__init_array_start []) (void) attribute_hidden;
- extern void (*__init_array_end []) (void) attribute_hidden;
- extern void (*__fini_array_start []) (void) attribute_hidden;
- extern void (*__fini_array_end []) (void) attribute_hidden;
- # endif
- #endif
- attribute_hidden const char *__uclibc_progname = "";
- #ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
- const char *program_invocation_short_name = "";
- const char *program_invocation_name = "";
- #endif
- #ifdef __UCLIBC_HAS___PROGNAME__
- weak_alias (program_invocation_short_name, __progname)
- weak_alias (program_invocation_name, __progname_full)
- #endif
- char **__environ = 0;
- weak_alias(__environ, environ)
- size_t __pagesize = 0;
- #ifndef O_NOFOLLOW
- # define O_NOFOLLOW 0
- #endif
- #ifndef __ARCH_HAS_NO_LDSO__
- static void __check_one_fd(int fd, int mode)
- {
-
- if (__libc_fcntl(fd, F_GETFD) == -1)
- {
-
- int nullfd = __libc_open(_PATH_DEVNULL, mode);
-
- if (nullfd!=fd)
- {
- abort();
- }
- }
- }
- static int __check_suid(void)
- {
- uid_t uid, euid;
- gid_t gid, egid;
- uid = getuid();
- euid = geteuid();
- if (uid != euid)
- return 1;
- gid = getgid();
- egid = getegid();
- if (gid != egid)
- return 1;
- return 0;
- }
- #endif
- extern void __uClibc_init(void);
- libc_hidden_proto(__uClibc_init)
- void __uClibc_init(void)
- {
- static smallint been_there_done_that;
- if (been_there_done_that)
- return;
- been_there_done_that++;
-
- __pagesize = PAGE_SIZE;
- #ifdef __UCLIBC_HAS_THREADS__
-
- if (likely(__pthread_initialize_minimal!=NULL))
- __pthread_initialize_minimal();
- #endif
- #ifndef SHARED
- # ifdef __UCLIBC_HAS_SSP__
-
- stack_chk_guard = _dl_setup_stack_chk_guard();
- # ifdef THREAD_SET_STACK_GUARD
- THREAD_SET_STACK_GUARD (stack_chk_guard);
- # ifdef __UCLIBC_HAS_SSP_COMPAT__
- __guard = stack_chk_guard;
- # endif
- # else
- __stack_chk_guard = stack_chk_guard;
- # if !defined __HAVE_SHARED__ && defined __UCLIBC_HAS_SSP_COMPAT__
- __guard = stack_chk_guard;
- # endif
- # endif
- # endif
- #endif
- #ifdef __UCLIBC_HAS_LOCALE__
-
- if (likely(_locale_init!=NULL))
- _locale_init();
- #endif
-
- if (likely(_stdio_init != NULL))
- _stdio_init();
- }
- libc_hidden_def(__uClibc_init)
- #ifdef __UCLIBC_CTOR_DTOR__
- void attribute_hidden (*__app_fini)(void) = NULL;
- #endif
- void attribute_hidden (*__rtld_fini)(void) = NULL;
- extern void __uClibc_fini(void);
- libc_hidden_proto(__uClibc_fini)
- void __uClibc_fini(void)
- {
- #ifdef __UCLIBC_CTOR_DTOR__
-
- # ifdef SHARED
- _dl_app_fini_array();
- # elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
- size_t i = __fini_array_end - __fini_array_start;
- while (i-- > 0)
- (*__fini_array_start [i]) ();
- # endif
- if (__app_fini != NULL)
- (__app_fini)();
- #endif
- if (__rtld_fini != NULL)
- (__rtld_fini)();
- }
- libc_hidden_def(__uClibc_fini)
- void __uClibc_main(int (*main)(int, char **, char **), int argc,
- char **argv, void (*app_init)(void), void (*app_fini)(void),
- void (*rtld_fini)(void), void *stack_end) attribute_noreturn;
- void __uClibc_main(int (*main)(int, char **, char **), int argc,
- char **argv, void (*app_init)(void), void (*app_fini)(void),
- void (*rtld_fini)(void), void *stack_end)
- {
- #ifndef __ARCH_HAS_NO_LDSO__
- unsigned long *aux_dat;
- ElfW(auxv_t) auxvt[AT_EGID + 1];
- #endif
- #ifndef SHARED
- __libc_stack_end = stack_end;
- #endif
- __rtld_fini = rtld_fini;
-
- __environ = &argv[argc + 1];
-
- if ((char *) __environ == *argv) {
-
- __environ = &argv[argc];
- }
- #ifndef __ARCH_HAS_NO_LDSO__
-
- memset(auxvt, 0x00, sizeof(auxvt));
- aux_dat = (unsigned long*)__environ;
- while (*aux_dat) {
- aux_dat++;
- }
- aux_dat++;
- while (*aux_dat) {
- ElfW(auxv_t) *auxv_entry = (ElfW(auxv_t) *) aux_dat;
- if (auxv_entry->a_type <= AT_EGID) {
- memcpy(&(auxvt[auxv_entry->a_type]), auxv_entry, sizeof(ElfW(auxv_t)));
- }
- aux_dat += 2;
- }
- #ifndef SHARED
-
- _dl_aux_init (auxvt);
- #endif
- #endif
-
- __uClibc_init();
- #ifndef __ARCH_HAS_NO_LDSO__
-
- __pagesize = (auxvt[AT_PAGESZ].a_un.a_val)? auxvt[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
-
- if ((auxvt[AT_UID].a_un.a_val == (size_t)-1 && __check_suid()) ||
- (auxvt[AT_UID].a_un.a_val != (size_t)-1 &&
- (auxvt[AT_UID].a_un.a_val != auxvt[AT_EUID].a_un.a_val ||
- auxvt[AT_GID].a_un.a_val != auxvt[AT_EGID].a_un.a_val)))
- {
- __check_one_fd (STDIN_FILENO, O_RDONLY | O_NOFOLLOW);
- __check_one_fd (STDOUT_FILENO, O_RDWR | O_NOFOLLOW);
- __check_one_fd (STDERR_FILENO, O_RDWR | O_NOFOLLOW);
- }
- #endif
- __uclibc_progname = *argv;
- #ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
- if (*argv != NULL) {
- program_invocation_name = *argv;
- program_invocation_short_name = strrchr(*argv, '/');
- if (program_invocation_short_name != NULL)
- ++program_invocation_short_name;
- else
- program_invocation_short_name = program_invocation_name;
- }
- #endif
- #ifdef __UCLIBC_CTOR_DTOR__
-
- __app_fini = app_fini;
-
- # if !defined (SHARED) && !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
-
- {
- const size_t size = __preinit_array_end - __preinit_array_start;
- size_t i;
- for (i = 0; i < size; i++)
- (*__preinit_array_start [i]) ();
- }
- # endif
-
- if (app_init!=NULL) {
- app_init();
- }
-
- # ifdef SHARED
- _dl_app_init_array();
- # elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
- {
- const size_t size = __init_array_end - __init_array_start;
- size_t i;
- for (i = 0; i < size; i++)
- (*__init_array_start [i]) ();
- }
- # endif
- #endif
-
- if (likely(__errno_location!=NULL))
- *(__errno_location()) = 0;
-
- if (likely(__h_errno_location!=NULL))
- *(__h_errno_location()) = 0;
-
- exit(main(argc, argv, __environ));
- }
- #if defined(__UCLIBC_HAS_THREADS__) && !defined(SHARED)
- static int __pthread_return_0 (void) { return 0; }
- static void __pthread_return_void (void) { return; }
- weak_alias (__pthread_return_0, __pthread_mutex_init)
- weak_alias (__pthread_return_0, __pthread_mutex_lock)
- weak_alias (__pthread_return_0, __pthread_mutex_trylock)
- weak_alias (__pthread_return_0, __pthread_mutex_unlock)
- weak_alias (__pthread_return_void, _pthread_cleanup_push_defer)
- weak_alias (__pthread_return_void, _pthread_cleanup_pop_restore)
- # ifdef __UCLIBC_HAS_THREADS_NATIVE__
- weak_alias (__pthread_return_0, __pthread_mutexattr_init)
- weak_alias (__pthread_return_0, __pthread_mutexattr_destroy)
- weak_alias (__pthread_return_0, __pthread_mutexattr_settype)
- # endif
- #endif
|