int init(){
#if STATIC_WORKQUEUE
    pthread_workqueue_init_np();
#endif
#if STATIC_KQUEUE
    libkqueue_init();
#endif
    libdispatch_init();

    return 0;
}
void 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,
	};

	static const struct _libpthread_functions libpthread_funcs = {
		.version = 1,
		.exit = exit,
	};

	__libkernel_init(&libkernel_funcs, envp, apple, vars);

	bootstrap_init();
	__libplatform_init(NULL, envp, apple, vars);

	__pthread_init(&libpthread_funcs, envp, apple, vars);
	__libc_init(vars, libSystem_atfork_prepare, libSystem_atfork_parent, libSystem_atfork_child, apple);

	// TODO: Move __malloc_init before __libc_init after breaking malloc's upward link to Libc
	__malloc_init(apple);

	_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;
}

/*
 * 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)
{
	_libSC_info_fork_prepare();
	xpc_atfork_prepare();
	dispatch_atfork_prepare();
	_pthread_fork_prepare();
	_malloc_fork_prepare();
}

void libSystem_atfork_parent(void)
{
	_malloc_fork_parent();
	_pthread_fork_parent();
	dispatch_atfork_parent();
	xpc_atfork_parent();
	_libSC_info_fork_parent();
}
Beispiel #3
0
DISPATCH_EXPORT DISPATCH_NOTHROW
void
_libdispatch_init(void)
{
	libdispatch_init();
}