uintptr_t start_sim(int argc, const char* argv[], const char* envp[], const char* apple[], const macho_header* mainExecutableMH, const macho_header* dyldMH, uintptr_t dyldSlide, const dyld::SyscallHelpers* sc, uintptr_t* startGlue) { // if simulator dyld loaded slid, it needs to rebase itself // we have to do this before using any global variables if ( dyldSlide != 0 ) { rebaseDyld(dyldMH, dyldSlide); } // save table of syscall pointers gSyscallHelpers = sc; // allow dyld to use mach messaging mach_init(); // set up random value for stack canary __guard_setup(apple); // setup gProcessInfo to point to host dyld's struct dyld::gProcessInfo = (struct dyld_all_image_infos*)(sc->getProcessInfo()); syncProcessInfo(); // now that we are done bootstrapping dyld, call dyld's main uintptr_t appsSlide = slideOfMainExecutable(mainExecutableMH); return dyld::_main(mainExecutableMH, appsSlide, argc, argv, envp, apple, startGlue); }
// // This is code to bootstrap dyld. This work in normally done for a program by dyld and crt. // In dyld we have to do this manually. // uintptr_t start(const struct macho_header* appsMachHeader, int argc, const char* argv[], intptr_t slide, const struct macho_header* dyldsMachHeader, uintptr_t* startGlue) { // if kernel had to slide dyld, we need to fix up load sensitive locations // we have to do this before using any global variables if ( slide != 0 ) { rebaseDyld(dyldsMachHeader, slide); } // allow dyld to use mach messaging mach_init(); // kernel sets up env pointer to be just past end of agv array const char** envp = &argv[argc+1]; // kernel sets up apple pointer to be just past end of envp array const char** apple = envp; while(*apple != NULL) { ++apple; } ++apple; // set up random value for stack canary __guard_setup(apple); #if DYLD_INITIALIZER_SUPPORT // run all C++ initializers inside dyld runDyldInitializers(dyldsMachHeader, slide, argc, argv, envp, apple); #endif // now that we are done bootstrapping dyld, call dyld's main uintptr_t appsSlide = slideOfMainExecutable(appsMachHeader); return dyld::_main(appsMachHeader, appsSlide, argc, argv, envp, apple, startGlue); }
_libc_init(void) { if (libc_initialised) return; libc_initialised = 1; if (__ps_strings != NULL) __libc_dlauxinfo = __ps_strings->ps_argvstr + __ps_strings->ps_nargvstr + __ps_strings->ps_nenvstr + 2; /* For -fstack-protector */ __guard_setup(); /* Atomic operations */ __libc_atomic_init(); /* XXX: we don't have tls */ #if 0 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) /* Initialize TLS for statically linked programs. */ __libc_static_tls_setup(); #endif #endif /* Threads */ __libc_thr_init(); /* Initialize the atexit mutexes */ __libc_atexit_init(); /* Initialize environment memory RB tree. */ __libc_env_init(); }
void __libc_init(const struct ProgramVars *vars, void (*atfork_prepare)(void), void (*atfork_parent)(void), void (*atfork_child)(void), const char *apple[]) { _program_vars_init(vars); _libc_fork_init(atfork_prepare, atfork_parent, atfork_child); _init_clock_port(); __chk_init(); __xlocale_init(); __guard_setup(apple); }
void _libc_initializer(const struct _libc_functions *funcs, const char *envp[], const char *apple[], const struct ProgramVars *vars) { _program_vars_init(vars); _libc_fork_init(funcs); __confstr_init(funcs); __atexit_init(); _init_clock_port(); __chk_init(); __xlocale_init(); __guard_setup(apple); }
/* LINTED used */ void __libc_init(void) { /* For -fstack-protector */ __guard_setup(); /* Atomic operations */ __libc_atomic_init(); #ifdef _REENTRANT /* Threads */ __libc_thr_init(); #endif /* Initialize the atexit mutexes */ __libc_atexit_init(); /* Initialize environment memory RB tree. */ __libc_env_init(); }