Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224// Modified by Lubos Dolezel to support older (10.8) libc and newer libsystem_kernel/* * Copyright (c) 2007, 2008, 2011 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */
#include <TargetConditionals.h> // for TARGET_OS_EMBEDDED
#include <_libkernel_init.h>#include <dlfcn.h>#include <errno.h>#include <stdlib.h>
struct ProgramVars; /* forward reference */
// system library initialisersextern void bootstrap_init(void); // from liblaunch.dylibextern void mach_init(void); // from libsystem_mach.dylibextern void pthread_init(void); // from libc.aextern void __libc_init(const struct ProgramVars *vars, void (*atfork_prepare)(void), void (*atfork_parent)(void), void (*atfork_child)(void), const char *apple[]); // from libc.aextern void __malloc_init(const char* apple[]); // from libmallocextern void __keymgr_initializer(void); // from libkeymgr.aextern void _dyld_initializer(void); // from libdyld.aextern void libdispatch_init(void); // from libdispatch.aextern void _libxpc_initializer(void); // from libxpcextern void __objc_initialize(void);
// signal malloc stack logging that initialisation has finishedextern void __stack_logging_early_finished(void); // form libsystem_c.dylib
// system library atfork handlersextern void _cthread_fork_prepare(void);extern void _cthread_fork_parent(void);extern void _cthread_fork_child(void);extern void _cthread_fork_child_postinit(void);
extern void _mig_fork_child(void);extern void _mach_fork_child(void);extern void _cproc_fork_child(void);extern void _libc_fork_child(void);extern void _notify_fork_child(void);extern void _dyld_fork_child(void);extern void xpc_atfork_prepare(void);extern void xpc_atfork_parent(void);extern void xpc_atfork_child(void);
// advance decls for below;void libSystem_atfork_prepare(void);void libSystem_atfork_parent(void);void libSystem_atfork_child(void);
// from mig_support.c in libcmach_port_t _mig_get_reply_port(void);void _mig_set_reply_port(mach_port_t);
void cthread_set_errno_self(int);void* pthread_self(void);
static void _pthread_exit_if_canceled(int err) { if (pthread_self()) _pthread_testcancel(pthread_self(), 1); }
struct ProgramVars{ const void* mh; int* NXArgcPtr; const char*** NXArgvPtr; const char*** environPtr; const char** __prognamePtr;};
/* * libsyscall_initializer() initializes all of libSystem.dylib <rdar://problem/4892197> *///staticvoid libSystem_initializer(int argc, const char* argv[], const char* envp[] /*, const char* apple[], const struct ProgramVars* vars*/){ static const struct _libkernel_functions libkernel_funcs = { .version = 1, .dlsym = dlsym, .malloc = malloc, .free = free, .realloc = realloc, ._pthread_exit_if_canceled = _pthread_exit_if_canceled, };
int* x_argc; char*** x_argv; char*** x_envp; char** apple = { NULL }; struct ProgramVars vars;
/* Early initialization - original Apple code assumes pthread_init() doesn't print errors */ __darling_get_args(&x_argc, &x_argv, &x_envp, &vars);
if (!*x_argc) { char* excl;
// Darling libdyld is not being used // to execute a Mach-O binary. // Use what the ELF loader gave us. *x_argc = argc - 1; *x_argv = argv + 1; *x_envp = envp;
excl = strchr(argv[1], '!'); if (excl != NULL) argv[1] = excl+1;
vars.NXArgcPtr = x_argc; vars.NXArgvPtr = x_argv; vars.environPtr = x_envp; vars.__prognamePtr = &(*x_argv)[0]; vars.mh = NULL; __darling_set_environ(envp); // Initialize glibc's environ } __darling_set_libc_vars(x_argc, x_argv, x_envp); /* cerror() calls require working pthread_self() */ char dummy_self[4096]; memset(dummy_self, 0, sizeof(dummy_self)); __pthread_set_self(dummy_self);
__libkernel_init(&libkernel_funcs, *envp, apple, &vars);
bootstrap_init(); mach_init(); pthread_init(); __libc_init(&vars, libSystem_atfork_prepare, libSystem_atfork_parent, libSystem_atfork_child, apple); __malloc_init(apple); __keymgr_initializer(); _dyld_initializer(); libdispatch_init(); _libxpc_initializer();
__stack_logging_early_finished();
/* <rdar://problem/11588042> * C99 standard has the following in section 7.5(3): * "The value of errno is zero at program startup, but is never set * to zero by any library function." */ errno = 0; __objc_initialize();}
void (*const init_array []) (void) __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) = { &libSystem_initializer };
/* * libSystem_atfork_{prepare,parent,child}() are called by libc when we fork, then we deal with running fork handlers * for everyone else. */void libSystem_atfork_prepare(void){ xpc_atfork_prepare(); _cthread_fork_prepare();}
void libSystem_atfork_parent(void){ _cthread_fork_parent(); xpc_atfork_parent();}
void libSystem_atfork_child(void){ // Mach ports are not inherited across fork except for the Bootstrap. // So why is the following line not needed on OS X? _mig_fork_child();
_dyld_fork_child(); _cthread_fork_child(); bootstrap_init(); _mach_fork_child(); _cproc_fork_child(); _libc_fork_child(); _notify_fork_child(); xpc_atfork_child();
_cthread_fork_child_postinit();}
/* * Old crt1.o glue used to call through mach_init_routine which was used to initialize libSystem. * LibSystem now auto-initializes but mach_init_routine is left for binary compatibility. */static void mach_init_old(void) {}void (*mach_init_routine)(void) = &mach_init_old;
/* * This __crashreporter_info__ symbol is for all non-dylib parts of libSystem. */const char *__crashreporter_info__;//asm (".desc __crashreporter_info__, 0x10");