Esempio n. 1
0
File: darwin.c Progetto: 8l/go-learn
// Exception watching thread, started in addpid above.
static void*
excthread(void *v)
{
	extern boolean_t exc_server();
	mach_msg_server(exc_server, 2048, excport, 0);
	return 0;
}
Esempio n. 2
0
static void*
mach_exception_handler(void *port)
{
	// Calls catch_exception_raise.
	extern boolean_t exc_server();
	mach_msg_server(exc_server, 2048, (mach_port_t)port, 0);
	abort(); // never returns
}
Esempio n. 3
0
void *mach_segv_listener(void *arg)
{
    (void)arg;
    while (1) {
        int ret = mach_msg_server(exc_server,2048,segv_port,MACH_MSG_TIMEOUT_NONE);
        jl_safe_printf("mach_msg_server: %s\n", mach_error_string(ret));
        jl_exit(128+SIGSEGV);
    }
}
Esempio n. 4
0
void *catcher(void *dummy)
{
  extern boolean_t mach_exc_server(mach_msg_header_t *InHeadP,
                                   mach_msg_header_t *OutHeadP);

  pthread_setname_np("Dylan exception catcher");
  mach_msg_server(mach_exc_server, 2048, exception_port, 0);
  abort();
}
Esempio n. 5
0
void *
mach_exception_handler(void *port)
{
  mach_msg_server(exc_server, 2048, (mach_port_t) port, 0);
  /* mach_msg_server should never return, but it should dispatch mach
   * exceptions to our catch_exception_raise function
   */
  lose("mach_msg_server returned");
}
Esempio n. 6
0
/*
 * The main event loop.  Wait for trigger messages or signals and handle them.
 * It should not return unless there is a problem.
 */
void
auditd_wait_for_events(void)
{
	kern_return_t   result;

	/*
	 * Call the mach messaging server loop.
 	 */
	result = mach_msg_server(auditd_combined_server, MAX_MSG_SIZE,
	    port_set, MACH_MSG_OPTION_NONE);
}
Esempio n. 7
0
void
default_pager_thread(
	void *arg)
{
	default_pager_thread_t	*dpt;
	mach_port_t		pset;
	kern_return_t		kr;
	static char		here[] = "default_pager_thread";
	mach_msg_options_t	server_options;

	dpt = (default_pager_thread_t *)arg;
	cthread_set_data(cthread_self(), (char *) dpt);

	/*
	 * Threads handling external objects cannot have
	 * privileges.  Otherwise a burst of data-requests for an
	 * external object could empty the free-page queue,
	 * because the fault code only reserves real pages for
	 * requests sent to internal objects.
	 */

	if (dpt->dpt_internal) {
		default_pager_thread_privileges();
		pset = default_pager_internal_set;
	} else {
		pset = default_pager_external_set;
	}

	dpt->dpt_initialized_p = TRUE; /* Ready for requests.  */

	server_options = MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_SEQNO);
	for (;;) {
		kr = mach_msg_server(default_pager_demux_object,
				     default_pager_msg_size,
				     pset,
				     server_options);
		Panic("mach_msg_server failed");
	}
}
Esempio n. 8
0
static void* exceptionHandlerEntryPoint(void* arg) {
    // mach_msg_server() never returns
    mach_msg_server(exc_server, sizeof(mach_msg_base_t) + 1024, mach_ex_port,  0);
    return NULL;
}
Esempio n. 9
0
/*** Main ***/
int main(int argc, char **argv, char **envp) {
    Bool listenOnly = FALSE;
    int i;
    mach_msg_size_t mxmsgsz = sizeof(union MaxMsgSize) + MAX_TRAILER_SIZE;
    mach_port_t mp;
    kern_return_t kr;

    /* Setup our environment for our children */
    setup_env();
    
    /* The server must not run the PanoramiX operations. */
    noPanoramiXExtension = TRUE;

    /* Setup the initial crasherporter info */
    strlcpy(__crashreporter_info__, __crashreporter_info__base, __crashreporter_info__len);
    
    fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
    for(i=0; i < argc; i++) {
        fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
        if(!strcmp(argv[i], "--listenonly")) {
            listenOnly = TRUE;
        }
    }

    mp = checkin_or_register(server_bootstrap_name);
    if(mp == MACH_PORT_NULL) {
        fprintf(stderr, "NULL mach service: %s", server_bootstrap_name);
        return EXIT_FAILURE;
    }
    
    /* Check if we need to do something other than listen, and make another
     * thread handle it.
     */
    if(!listenOnly) {
        pid_t child1, child2;
        int status;

        /* Do the fork-twice trick to avoid having to reap zombies */
        child1 = fork();
        switch (child1) {
            case -1:                                /* error */
                break;

            case 0:                                 /* child1 */
                child2 = fork();

                switch (child2) {
                    int max_files, i;

                    case -1:                            /* error */
                        break;

                    case 0:                             /* child2 */
                        /* close all open files except for standard streams */
                        max_files = sysconf(_SC_OPEN_MAX);
                        for(i = 3; i < max_files; i++)
                            close(i);

                        /* ensure stdin is on /dev/null */
                        close(0);
                        open("/dev/null", O_RDONLY);

                        return startup_trigger(argc, argv, envp);

                    default:                            /* parent (child1) */
                        _exit(0);
                }
                break;

            default:                                /* parent */
              waitpid(child1, &status, 0);
        }
    }
    
    /* Main event loop */
    fprintf(stderr, "Waiting for startup parameters via Mach IPC.\n");
    kr = mach_msg_server(mach_startup_server, mxmsgsz, mp, 0);
    if (kr != KERN_SUCCESS) {
        fprintf(stderr, "%s.X11(mp): %s\n", LAUNCHD_ID_PREFIX, mach_error_string(kr));
        return EXIT_FAILURE;
    }
    
    return EXIT_SUCCESS;
}
Esempio n. 10
0
/*
 * Initialize and Run the default pager
 */
void
default_pager(void)
{
	int			i, id;
	static char		here[] = "default_pager";
	mach_msg_options_t 	server_options;
	default_pager_thread_t	dpt;
	default_pager_thread_t	**dpt_array;

	default_pager_thread_privileges();

	/*
	 * Wire down code, data, stack
	 */
	wire_all_memory();

	/*
	 * Give me space for the thread array and zero it.
	 */
	i = default_pager_internal_count + default_pager_external_count + 1;
	dpt_array = (default_pager_thread_t **)
	    kalloc(i * sizeof(default_pager_thread_t *));
	memset(dpt_array, 0, i * sizeof(default_pager_thread_t *));

	/* Setup my thread structure.  */
	id = 0;
	dpt.dpt_thread = cthread_self();
	dpt.dpt_buffer = 0;
	dpt.dpt_internal = FALSE;
	dpt.dpt_id = id++;
	dpt.dpt_initialized_p = TRUE;
	cthread_set_data(cthread_self(), (char *) &dpt);
	dpt_array[0] = &dpt;

	/*
	 * Now we create the threads that will actually
	 * manage objects.
	 */

	for (i = 0; i < default_pager_internal_count; i++) {
		dpt_array[id] = start_default_pager_thread(id, TRUE);
		id++;
	 }

	for (i = 0; i < default_pager_external_count; i++) {
		dpt_array[id] = start_default_pager_thread(id, FALSE);
		id++;
	}

	/* Is everybody ready?  */
	for (i = 0; i < id; i++)
	    while (!dpt_array[i])
		cthread_yield();

	/* Tell the bootstrap process to go ahead.  */
	bootstrap_completed(bootstrap_port, mach_task_self());

	/* Start servicing requests.  */
	server_options = MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_SEQNO);
	for (;;) {
		mach_msg_server(default_pager_demux_default,
				default_pager_msg_size,
				default_pager_default_set,
				server_options);
		Panic("default server");
	}
}