return(ret_val);
}
-int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry)
+int process_create(process_t **dst, u32_t ppl, void *entry)
{
int ret_val;
process_t *proc;
proc = NULL;
ctask = task_get_current();
- /* was a specific pid requested? */
- if(pid != PID_ANY) {
- /* may only request pids in [2..100] */
-
- if(pid < 2 || pid >= 100) {
- ret_val = -EINVAL;
- goto cleanup;
- }
-
- /* check if pid is already taken */
- if(process_lookup(pid)) {
- ret_val = -EALREADY;
- goto cleanup;
- }
- }
-
- if(entry == PROC_ENTRY_FORK ||
- entry == PROC_ENTRY_VFORK) {
- /* inherit the ppl from the current task, in the case of fork and vfork */
+ if(entry == PROC_ENTRY_FORK || entry == PROC_ENTRY_VFORK) {
+ /* (v)forked processes inherit the parent's privilege level */
ppl = ctask->t_privl;
}
goto cleanup;
}
- /*
- * The new page directory contains only the kernel regions.
- */
-
+ /* the new page directory contains only the kernel regions */
pdbr = pg_dir_get_pdbr(proc->p_pgdir);
kstack = pg_dir_get_kstack(proc->p_pgdir);
ustack = pg_dir_get_ustack(proc->p_pgdir);
proc->p_tasks[0]->t_rslice = ctask->t_tslice;
} else {
/*
- * This only happens when process_create() is called before the
- * scheduler is invoked for the first time.
+ * This only happens when process_create() is called
+ * before the scheduler is invoked for the first time.
*/
proc->p_uid = 0;
proc->p_gid = 0;
}
/* set the default signal handlers */
- memcpy(proc->p_sighandler, _sig_dfl, sizeof(proc->p_sighandler));
+ memcpy(proc->p_sighandler, _sig_dfl,
+ sizeof(proc->p_sighandler));
proc->p_privl = ppl;
proc->p_sigpending = -1;
-
- if(pid == PID_ANY) {
- /* no specific pid requested */
- proc->p_id = _next_pid++;
- } else {
- proc->p_id = pid;
- }
+ proc->p_id = _next_pid++;
proc->p_tasks[0]->t_kstack = kstack;
proc->p_tasks[0]->t_proc = proc;
custack = pg_dir_get_ustack(cproc->p_pgdir);
/*
- * The address space of the new process doesn't contain any memory segments
- * but those relevant for the kernel. If the process is a fork, clone all non-kernel
- * memory segments that are present in the parent's page directory. If it is a vfork,
- * directly map the segments into this address space.
+ * The address space of the new process doesn't contain
+ * any memory segments except for those relevant to the
+ * kernel. If the new process is a fork, clone all
+ * non-kernel memory segments that are present in the
+ * parent's page directory. If it is a vfork, directly
+ * map the segments into this address space.
*/
pg_dir_foreach_region(cproc->p_pgdir,
- entry == PROC_ENTRY_FORK ? _fork_region : _vfork_region,
- proc->p_pgdir);
+ entry == PROC_ENTRY_FORK ?
+ _fork_region : _vfork_region,
+ proc->p_pgdir);
/*
- * In the case of fork() and vfork() we have to get the address that the
- * interrupt is supposed to return to. The stack that the address was pushed
- * onto is located at ctask->t_kstack. Instead of pulling the address from
- * where we believe it should be on the stack, we'll just copy the entire stack
- * and make the child process return to userspace the same way we do.
- * The task_prepare_fork function will actually do all of this work: it will
- * adjust the stack pointers for the new task, copy the kernel stack, and
- * otherwise prepare it to start execution through task_switch.
+ * In the case of fork() and vfork() we have to get the
+ * address that the interrupt is supposed to return to.
+ * The stack that the address was pushed onto is located
+ * at ctask->t_kstack. Instead of pulling the address
+ * from where we believe it should be on the stack,
+ * we'll just copy the entire stack and make the child
+ * process return to userspace the same way we do.
+ * The task_prepare_fork function will actually do all
+ * of this work: it will adjust the stack pointers for
+ * the new task, copy the kernel stack, and otherwise
+ * prepare it to start execution through task_switch.
*/
proc->p_tasks[0]->t_state = TASK_STATE_FORKED;
proc->p_tasks[0]->t_pgdir = (u32_t)pdbr;
- process_memcpy_ptop(proc, ustack,
- cproc, custack,
- CONFIG_USER_STACK_SIZE);
+ process_memcpy_ptop(proc, ustack, cproc, custack,
+ CONFIG_USER_STACK_SIZE);
/*
- * The child process will start with the instruction that is following the
- * task_prepare_fork call. In the case of the parent, task_prepare_fork will
- * return zero, in case of the child, the return value will be 0xf00f00ff, but
- * the function that the child will be returning from is actually task_switch.
- * Since any registers besides esp, ebp, and eax will be in an undefined state
- * for the child process, we should not touch anything else and just return
- * to user-space asap.
+ * The child process will start with the instruction
+ * that is following the task_prepare_fork call. In the
+ * case of the parent, task_prepare_fork will return
+ * zero, in case of the child, the return value will be
+ * 0xf00f00ff, but the function that the child will be
+ * returning from is actually task_switch. Since any
+ * registers except for esp, ebp, and eax will be in an
+ * undefined state for the child process, we should not
+ * touch anything else and just return to user-space
+ * as soon as possible.
*/
if(task_prepare_fork(proc->p_tasks[0]) == 0xf00f00ff) {
/* the parent continues as usual */
} else {
- task_prepare(proc->p_tasks[0], (u32_t)pdbr, (u32_t)entry,
- (u32_t)kstack + CONFIG_KERNEL_STACK_SIZE,
- (u32_t)ustack + CONFIG_USER_STACK_SIZE, ppl);
+ task_prepare(proc->p_tasks[0], (u32_t)pdbr,
+ (u32_t)entry,
+ (u32_t)kstack + CONFIG_KERNEL_STACK_SIZE,
+ (u32_t)ustack + CONFIG_USER_STACK_SIZE,
+ ppl);
}
ret_val = NQ(proc);
if(proc) {
process_t *nproc;
- ret_val = process_create(&nproc, PID_ANY, proc->p_privl, PROC_ENTRY_FORK);
+ ret_val = process_create(&nproc, proc->p_privl,
+ PROC_ENTRY_FORK);
if(!ret_val && nproc) {
/* this is the parent */