/** * Create a new task * @author Ivan Gualandri * @version 1.0 * @param task_name The name of the task * @param start_function the entry point of the task. */ pid_t new_task(char *task_name, void (*start_function)()){ asm("cli"); task_t *new_task; table_address_t local_table; unsigned int new_pid = request_pid(); new_task = (task_t*)kmalloc(sizeof(task_t)); strcpy(new_task->name, task_name); new_task->next = NULL; new_task->start_function = start_function; new_task->cur_quants=0; new_task->pid = new_pid; new_task->eip = (unsigned int)start_function; new_task->esp = (unsigned int)kmalloc(STACK_SIZE) + STACK_SIZE-100; new_task->tty = tty_get_current(); dbg_bochs_print(new_task->esp); new_task->status = NEW; new_task->registers = (task_register_t*)new_task->esp; new_tss(new_task->registers, start_function); local_table = map_kernel(); new_task->pdir = local_table.page_dir; new_task->ptable = local_table.page_table; //new_task->pdir = 0; //new_task->ptable = 0; enqueue_task(new_task->pid, new_task); //(task_list.current)->cur_quants = MAX_TICKS; asm("sti"); return new_pid; }
/** * Create a new task * @author Ivan Gualandri * @version 1.0 * @param task_name The name of the task * @param start_function the entry point of the task. */ pid_t new_task(char *task_name, void (*start_function)()){ asm("cli"); task_t new_task; table_address_t local_table; unsigned int new_pid = request_pid(); strcpy(new_task.name, task_name); new_task.start_function = start_function; new_task.pid = new_pid; new_task.eip = (unsigned int)start_function; new_task.esp = (unsigned int) kmalloc(STACK_SIZE) + STACK_SIZE - 100; new_task.state = READY; new_task.registers = (task_register_t*)new_task.esp; new_tss(new_task.registers, start_function); local_table = map_kernel(); new_task.pdir = local_table.page_dir; new_task.ptable = local_table.page_table; add_task(new_task.pid, &new_task); asm("sti"); return new_pid; }
int main(int argc, char **argv, char **envp) { int envpc; kern_return_t kr; mach_port_t mp; string_array_t newenvp; string_array_t newargv; size_t i; int launchd_fd; string_t handoff_socket_filename; sig_t handler; if(argc == 2 && !strcmp(argv[1], "-version")) { fprintf(stderr, "X.org Release 7.5\n"); fprintf(stderr, "X.Org X Server %s\n", XSERVER_VERSION); fprintf(stderr, "Build Date: %s\n", BUILD_DATE); return EXIT_SUCCESS; } if(getenv("X11_PREFS_DOMAIN")) server_bootstrap_name = getenv("X11_PREFS_DOMAIN"); /* We don't have a mechanism in place to handle this interrupt driven * server-start notification, so just send the signal now, so xinit doesn't * time out waiting for it and will just poll for the server. */ handler = signal(SIGUSR1, SIG_IGN); if(handler == SIG_IGN) kill(getppid(), SIGUSR1); signal(SIGUSR1, handler); /* Pass on SIGs to X11.app */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); /* Get the $DISPLAY FD */ launchd_fd = launchd_display_fd(); kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp); if(kr != KERN_SUCCESS) { pid_t child; fprintf(stderr, "Xquartz: Unable to locate waiting server: %s\n", server_bootstrap_name); set_x11_path(); /* This forking is ugly and will be cleaned up later */ child = fork(); if(child == -1) { fprintf(stderr, "Xquartz: Could not fork: %s\n", strerror(errno)); return EXIT_FAILURE; } if(child == 0) { char *_argv[3]; _argv[0] = x11_path; _argv[1] = "--listenonly"; _argv[2] = NULL; fprintf(stderr, "Xquartz: Starting X server: %s --listenonly\n", x11_path); return execvp(x11_path, _argv); } /* Try connecting for 10 seconds */ for(i=0; i < 80; i++) { usleep(250000); kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp); if(kr == KERN_SUCCESS) break; } if(kr != KERN_SUCCESS) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 fprintf(stderr, "Xquartz: bootstrap_look_up(): %s\n", bootstrap_strerror(kr)); #else fprintf(stderr, "Xquartz: bootstrap_look_up(): %ul\n", (unsigned long)kr); #endif return EXIT_FAILURE; } } /* Get X11.app's pid */ request_pid(mp, &x11app_pid); /* Handoff the $DISPLAY FD */ if(launchd_fd != -1) { size_t try, try_max; int handoff_fd = -1; for(try=0, try_max=5; try < try_max; try++) { if(request_fd_handoff_socket(mp, handoff_socket_filename) != KERN_SUCCESS) { fprintf(stderr, "Xquartz: Failed to request a socket from the server to send the $DISPLAY fd over (try %d of %d)\n", (int)try+1, (int)try_max); continue; } handoff_fd = connect_to_socket(handoff_socket_filename); if(handoff_fd == -1) { fprintf(stderr, "Xquartz: Failed to connect to socket (try %d of %d)\n", (int)try+1, (int)try_max); continue; } #ifdef DEBUG fprintf(stderr, "Xquartz: Handoff connection established (try %d of %d) on fd %d, \"%s\". Sending message.\n", (int)try+1, (int)try_max, handoff_fd, handoff_socket_filename); #endif send_fd_handoff(handoff_fd, launchd_fd); close(handoff_fd); break; } } /* Count envp */ for(envpc=0; envp[envpc]; envpc++); /* We have fixed-size string lengths due to limitations in IPC, * so we need to copy our argv and envp. */ newargv = (string_array_t)malloc(argc * sizeof(string_t)); newenvp = (string_array_t)malloc(envpc * sizeof(string_t)); if(!newargv || !newenvp) { fprintf(stderr, "Xquartz: Memory allocation failure\n"); return EXIT_FAILURE; } for(i=0; i < argc; i++) { strlcpy(newargv[i], argv[i], STRING_T_SIZE); } for(i=0; i < envpc; i++) { strlcpy(newenvp[i], envp[i], STRING_T_SIZE); } kr = start_x11_server(mp, newargv, argc, newenvp, envpc); free(newargv); free(newenvp); if (kr != KERN_SUCCESS) { fprintf(stderr, "Xquartz: start_x11_server: %s\n", mach_error_string(kr)); return EXIT_FAILURE; } return EXIT_SUCCESS; }