processctl() PCTL_SPAWN cmd, scheduler embryo state, redirected pipes
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include "ps2kbproc/ps2kbproc.h"
|
||||
#include "termproc/termproc.h"
|
||||
#include "serialproc/serialproc.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
|
||||
#define PROC_REAPER_FREQ 30
|
||||
|
||||
@ -99,9 +100,10 @@ Proc *proc_spawnkern(void (*ent)(void), char *name) {
|
||||
proc->platformdata.trapframe.cs = 0x08;
|
||||
proc->platformdata.trapframe.rip = (uint64_t)ent;
|
||||
proc->platformdata.cr3 = hal_vmm_current_cr3();
|
||||
proc->state = PROC_READY;
|
||||
proc->state = PROC_EMBRYO;
|
||||
proc->pid = pids++;
|
||||
spinlock_init(&proc->bcast_pipes.spinlock);
|
||||
spinlock_init(&proc->pipes_spinlock);
|
||||
|
||||
return proc;
|
||||
}
|
||||
@ -165,9 +167,15 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
proc->platformdata.trapframe.rflags = 0x202;
|
||||
proc->platformdata.trapframe.cs = 0x18 | 0x3;
|
||||
proc->platformdata.trapframe.rip = aux.entry;
|
||||
proc->state = PROC_READY;
|
||||
proc->state = PROC_EMBRYO;
|
||||
proc->pid = pids++;
|
||||
spinlock_init(&proc->bcast_pipes.spinlock);
|
||||
spinlock_init(&proc->pipes_spinlock);
|
||||
|
||||
proc->pipes[0] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(proc->pipes[0], proc->pid);
|
||||
proc->pipes[1] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(proc->pipes[1], proc->pid);
|
||||
|
||||
return proc;
|
||||
}
|
||||
@ -184,7 +192,7 @@ Proc *proc_nextready(void) {
|
||||
if (proc == NULL) {
|
||||
proc = PROCS.procs;
|
||||
}
|
||||
if (proc->state != PROC_ZOMBIE) {
|
||||
if (proc->state == PROC_READY) {
|
||||
return proc;
|
||||
}
|
||||
proc = proc->next;
|
||||
@ -209,7 +217,7 @@ void proc_reaper(void) {
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
|
||||
if (zombie->pipes[i] != NULL) {
|
||||
if (zombie->pipes[i] != NULL && zombie->pipes[i]->ownerpid == zombie->pid) {
|
||||
dlfree(zombie->pipes[i]);
|
||||
ipc_pipefree(zombie->pipes[i]);
|
||||
zombie->pipes[i] = NULL;
|
||||
@ -255,7 +263,6 @@ void proc_sched(void *cpustate) {
|
||||
PROCS.current->platformdata.trapframe = *frame;
|
||||
|
||||
PROCS.current = proc_nextready();
|
||||
PROCS.current->state = PROC_RUNNING;
|
||||
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
@ -294,19 +301,25 @@ void proc_init(void) {
|
||||
kproc_init(proc_spawnkern(&kproc_fn, "kproc"));
|
||||
proc_register(KPROC);
|
||||
PROCS.current = KPROC;
|
||||
KPROC->state = PROC_READY;
|
||||
|
||||
ps2kbproc_init(proc_spawnkern(&ps2kbproc_fn, "ps2kbproc"));
|
||||
proc_register(PS2KBPROC);
|
||||
PS2KBPROC->state = PROC_READY;
|
||||
|
||||
termproc_init(proc_spawnkern(&termproc_fn, "termproc"));
|
||||
proc_register(TERMPROC);
|
||||
TERMPROC->state = PROC_READY;
|
||||
|
||||
serialproc_init(proc_spawnkern(&serialproc_fn, "serialproc"));
|
||||
proc_register(SERIALPROC);
|
||||
/* serialproc_init(proc_spawnkern(&serialproc_fn, "serialproc")); */
|
||||
/* proc_register(SERIALPROC); */
|
||||
|
||||
Proc *init = proc_spawnuser("base", "/bin/init");
|
||||
ipc_pipefree(init->pipes[0]);
|
||||
dlfree(init->pipes[0]);
|
||||
init->pipes[0] = TERMPROC->pipes[1];
|
||||
proc_register(init);
|
||||
init->state = PROC_READY;
|
||||
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
Reference in New Issue
Block a user