int NXArgc = 0;
char **NXArgv = (char **)0;
char **environ = (char **)0;
char *__progname = "";
#if defined(CRT1)
asm(".desc _NXArgc, 0x10");
asm(".desc _NXArgv, 0x10");
asm(".desc _environ, 0x10");
asm(".desc __mh_execute_header, 0x10");
#if defined(__ppc__) || defined(__i386__)
asm(".comm _catch_exception_raise, 4");
asm(".desc _catch_exception_raise, 0x10");
asm(".comm _catch_exception_raise_state, 4");
asm(".desc _catch_exception_raise_state, 0x10");
asm(".comm _catch_exception_raise_state_identity, 4");
asm(".desc _catch_exception_raise_state_identity, 0x10");
asm(".comm _do_mach_notify_dead_name, 4");
asm(".desc _do_mach_notify_dead_name, 0x10");
asm(".comm _do_seqnos_mach_notify_dead_name, 4");
asm(".desc _do_seqnos_mach_notify_dead_name, 0x10");
asm(".comm _do_mach_notify_no_senders, 4");
asm(".desc _do_mach_notify_no_senders, 0x10");
asm(".comm _do_seqnos_mach_notify_no_senders, 4");
asm(".desc _do_seqnos_mach_notify_no_senders, 0x10");
asm(".comm _do_mach_notify_port_deleted, 4");
asm(".desc _do_mach_notify_port_deleted, 0x10");
asm(".comm _do_seqnos_mach_notify_port_deleted, 4");
asm(".desc _do_seqnos_mach_notify_port_deleted, 0x10");
asm(".comm _do_mach_notify_send_once, 4");
asm(".desc _do_mach_notify_send_once, 0x10");
asm(".comm _do_seqnos_mach_notify_send_once, 4");
asm(".desc _do_seqnos_mach_notify_send_once, 0x10");
asm(".comm _clock_alarm_reply, 4");
asm(".desc _clock_alarm_reply, 0x10");
asm(".comm _receive_samples, 4");
asm(".desc _receive_samples, 0x10");
#endif
asm(".desc ___progname, 0x10");
#endif
extern int (*mach_init_routine)(void);
extern int (*_cthread_init_routine)(void);
#ifdef CRT0
asm(".comm __cplus_init, 4");
extern void _cplus_init(void);
#endif
#if defined(__ppc__) && defined(CRT1)
asm(".comm ___darwin_gcc3_preregister_frame_info, 4");
extern void __darwin_gcc3_preregister_frame_info (void);
static void (*pointer_to__darwin_gcc3_preregister_frame_info)(void) =
__darwin_gcc3_preregister_frame_info;
#endif
extern int main(
int argc,
char **argv,
char **envp,
char **apple);
extern void exit(
int status) __attribute__ ((noreturn));
extern int atexit(
void (*fcn)(void));
#ifdef GCRT
extern void moninit(
void);
static void _mcleanup(
void);
extern void monitor(
char *lowpc,
char *highpc,
char *buf,
int bufsiz,
int nfunc);
#endif
#ifdef CRT1
extern void _dyld_init_check(
void);
static void _call_mod_init_funcs(
void);
__private_extern__
int _dyld_func_lookup(
const char *dyld_func_name,
unsigned long *address);
extern void __keymgr_dwarf2_register_sections (void);
#endif
#if defined(CRT1) && !defined(POSTSCRIPT) && defined(__ppc__)
static void _call_objcInit(void);
#endif
extern int errno;
__private_extern__
void
_start(
int argc,
char **argv,
char **envp)
{
int i;
char *p, **apple;
#if defined(__ppc__) ||defined(__ppc64__) || defined(__i386__)
char **q;
#endif
#ifdef CRT1
void (*term)(void);
#endif
#if defined(CRT1) && !defined(__i386__)
_dyld_init_check();
#endif
NXArgc = argc;
NXArgv = argv;
environ = envp;
if(mach_init_routine != 0)
(void) mach_init_routine();
if(_cthread_init_routine != 0)
(*_cthread_init_routine)();
#ifdef CRT1
__keymgr_dwarf2_register_sections ();
#endif
#if defined(__ppc__) && defined(CRT1)
if(*((int *)pointer_to__darwin_gcc3_preregister_frame_info) != 0)
pointer_to__darwin_gcc3_preregister_frame_info ();
#endif
#ifdef CRT0
if(*((int *)_cplus_init) != 0)
_cplus_init();
#endif
#ifdef CRT1
_call_mod_init_funcs();
#endif
#if defined(CRT1) && !defined(POSTSCRIPT) && defined(__ppc__)
_call_objcInit();
#endif
#ifdef GCRT
atexit(_mcleanup);
moninit();
#endif
#ifdef CRT1
_dyld_func_lookup("__dyld_mod_term_funcs", (unsigned long *)&term);
if(term != 0)
atexit(term);
#endif
errno = 0;
if(argv[0] != 0){
p = 0;
for(i = 0; argv[0][i] != 0; i++){
if(argv[0][i] == '/')
p = argv[0] + i;
}
if(p != 0)
__progname = p + 1;
else
__progname = argv[0];
}
#if defined(__ppc__) ||defined(__ppc64__) || defined(__i386__)
for(q = envp; *q != (char *)0; q++)
;
apple = q + 1;
#endif
exit(main(argc, argv, envp, apple));
}
#ifdef GCRT
static
void
_mcleanup(
void)
{
monitor(0,0,0,0,0);
}
#endif
#ifdef CRT1
static
void
_call_mod_init_funcs(void)
{
void (*p)(void);
_dyld_func_lookup("__dyld_make_delayed_module_initializer_calls",
(unsigned long *)&p);
p();
}
#endif
#if defined(CRT1) && !defined(POSTSCRIPT) && defined(__ppc__)
static
const char *
crt_basename(const char *path)
{
const char *s;
const char *last = path;
for (s = path; *s != '\0'; s++) {
if (*s == '/') last = s+1;
}
return last;
}
static
int
crt_strbeginswith(const char *s1, const char *s2)
{
int i;
for (i = 0; ; i++) {
if (s2[i] == '\0') return 1;
else if (s1[i] != s2[i]) return 0;
}
}
static
void
_call_objcInit(void)
{
unsigned int i, count;
unsigned int (*_dyld_image_count_fn)(void);
const char *(*_dyld_get_image_name_fn)(unsigned int image_index);
const void *(*_dyld_get_image_header_fn)(unsigned int image_index);
const void *(*NSLookupSymbolInImage_fn)(const void *image, const char *symbolName, unsigned int options);
void *(*NSAddressOfSymbol_fn)(const void *symbol);
_dyld_func_lookup("__dyld_image_count",
(unsigned long *)&_dyld_image_count_fn);
_dyld_func_lookup("__dyld_get_image_name",
(unsigned long *)&_dyld_get_image_name_fn);
_dyld_func_lookup("__dyld_get_image_header",
(unsigned long *)&_dyld_get_image_header_fn);
_dyld_func_lookup("__dyld_NSLookupSymbolInImage",
(unsigned long *)&NSLookupSymbolInImage_fn);
_dyld_func_lookup("__dyld_NSAddressOfSymbol",
(unsigned long *)&NSAddressOfSymbol_fn);
if (!_dyld_image_count_fn) return;
if (!_dyld_get_image_name_fn) return;
if (!_dyld_get_image_header_fn) return;
if (!NSLookupSymbolInImage_fn) return;
if (!NSAddressOfSymbol_fn) return;
count = (*_dyld_image_count_fn)();
for (i = 0; i < count; i++) {
const void *image;
const char *path = (*_dyld_get_image_name_fn)(i);
const char *base = crt_basename(path);
if (!crt_strbeginswith(base, "libobjc")) continue;
if ((image = (*_dyld_get_image_header_fn)(i))) {
const void *symbol;
if ((symbol = (*NSLookupSymbolInImage_fn)(image,"__objcInit",4))) {
void (*_objcInit_fn)(void) =
(void(*)(void))(*NSAddressOfSymbol_fn)(symbol);
if (_objcInit_fn) {
(*_objcInit_fn)();
break;
}
}
}
}
}
#endif