From: Matthias Kruk Date: Wed, 6 May 2020 06:42:22 +0000 (+0900) Subject: kernel/core: Remove pid argument from process_create() X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=d061546096bf54eb5639c00e7b00261357e76a1c;p=corax kernel/core: Remove pid argument from process_create() --- diff --git a/kernel/core/main.c b/kernel/core/main.c index 4f94974..2b59083 100644 --- a/kernel/core/main.c +++ b/kernel/core/main.c @@ -245,13 +245,13 @@ int corax(void *mb_info, u32_t magic) initfs.ifs_entries[err].ife_limit); } - err = process_create(&proc, PID_ANY, 0, (void*)_idle); + err = process_create(&proc, 0, (void*)_idle); if(err < 0) { PANIC("Could not spawn idle process\n"); } - err = process_create(&proc, PID_ANY, 3, (void*)_init); + err = process_create(&proc, 3, (void*)_init); if(err < 0) { PANIC("Could not spawn init process\n"); diff --git a/kernel/core/process.c b/kernel/core/process.c index c22623b..5afdd8e 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -258,7 +258,7 @@ skip: 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; @@ -268,25 +268,8 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) 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; } @@ -304,10 +287,7 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) 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); @@ -334,8 +314,8 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) 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; @@ -346,17 +326,12 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) } /* 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; @@ -369,41 +344,49 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) 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) { @@ -416,9 +399,11 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) /* 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); @@ -691,7 +676,8 @@ int process_fork(int v) 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 */ diff --git a/kernel/include/process.h b/kernel/include/process.h index e2fda64..9198cb3 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -29,7 +29,7 @@ typedef struct process process_t; -int process_create(process_t**, pid_t, u32_t, void*); +int process_create(process_t**, u32_t, void*); int process_switch(process_t*); void process_lock(process_t*);