diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-04-27 00:49:08 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-04-27 00:49:08 +0000 |
commit | 0e2acbe54e5800621692c2f6e9e9590aa369e165 (patch) | |
tree | 51cdf68ea3afba323ffbdae65e11e524ce841324 | |
parent | 106eacf796dc15d1256aa92ee4ded216d0e6f29c (diff) |
fix proc issues to get weenix to halt cleanly. very sad
-rw-r--r-- | kernel/drivers/disk/sata.c | 1 | ||||
-rw-r--r-- | kernel/proc/proc.c | 51 |
2 files changed, 28 insertions, 24 deletions
diff --git a/kernel/drivers/disk/sata.c b/kernel/drivers/disk/sata.c index d5ca117..8ba61ae 100644 --- a/kernel/drivers/disk/sata.c +++ b/kernel/drivers/disk/sata.c @@ -177,6 +177,7 @@ long ahci_do_operation(hba_port_t *port, ssize_t lba, uint16_t count, void *buf, port->px_ci |= (1 << command_slot); /* Sleep until the command has been serviced. */ + dbg(DBG_S5FS, "ahci_do_operation: returning %ld\n", (long)curthr->kt_retval); KASSERT(!curthr->kt_retval); dbg(DBG_DISK, diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index 945d17e..eab6556 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -187,6 +187,19 @@ proc_t *proc_create(const char *name) return NULL; } + proc->p_pid = proc_pid; + list_init(&proc->p_threads); + list_init(&proc->p_children); + proc->p_pproc = curproc; + + list_init(&proc->p_threads); + list_init(&proc->p_children); + + proc->p_status = 0; + proc->p_state = PROC_RUNNING; // TODO: check if this is correct + + sched_queue_init(&proc->p_wait); + pml4_t *pml4 = pt_create(); if (pml4 == NULL) { @@ -195,17 +208,14 @@ proc_t *proc_create(const char *name) } // if successful building memory, fill the struct - proc->p_pid = proc_pid; strncpy(proc->p_name, name, PROC_NAME_LEN); + proc->p_name[PROC_NAME_LEN - 1] = '\0'; proc->p_pml4 = pml4; - proc->p_state = PROC_RUNNING; // TODO: check if this is correct - proc->p_status = 0; - list_init(&proc->p_threads); - list_init(&proc->p_children); list_link_init(&proc->p_child_link); list_link_init(&proc->p_list_link); - sched_queue_init(&proc->p_wait); + list_insert_tail(&curproc->p_children, &proc->p_child_link); + list_insert_tail(&proc_list, &proc->p_list_link); if (proc_pid == PID_INIT) { @@ -213,11 +223,6 @@ proc_t *proc_create(const char *name) proc_initproc = proc; } - proc->p_pproc = proc_initproc; - list_insert_tail(&curproc->p_children, &proc->p_child_link); - list_insert_tail(&proc_list, &proc->p_list_link); - dbg(DBG_PROC, "SUCESSFULLY created PROCESS name=%s & pid =%d\n", name, proc_pid); - #ifdef __VFS__ // clone and ref the files from curproc for (int fd = 0; fd < NFILES; fd++) @@ -274,11 +279,11 @@ void proc_cleanup(long status) } #endif - if (curproc->p_pid == PID_INIT) { // if it's init proc, shutdown weenix initproc_finish(); + return; } // if it's not init proc, reparent child processes to parent proc @@ -287,13 +292,12 @@ void proc_cleanup(long status) panic("parent process not found in proc_pleanup"); } - list_link_t *link; list_iterate(&curproc->p_children, child, proc_t, p_child_link) { // remove & insert to init process - list_insert_tail(&curproc->p_pproc->p_children, &child->p_child_link); - list_remove(&child->p_child_link); child->p_pproc = proc_initproc; + list_remove(&child->p_child_link); + list_insert_tail(&curproc->p_pproc->p_children, &child->p_child_link); } // update state and status @@ -301,7 +305,7 @@ void proc_cleanup(long status) // if (curthr->kt_cancelled) { // curproc->p_status = curthr->kt_retval; // } else { - curproc->p_status = status; + curproc->p_status = status; // } } @@ -326,6 +330,7 @@ void proc_thread_exiting(void *retval) proc_cleanup((long)retval); curthr->kt_state = KT_EXITED; + curthr->kt_retval = retval; sched_broadcast_on(&curproc->p_pproc->p_wait); sched_switch(0); } @@ -339,13 +344,9 @@ void proc_thread_exiting(void *retval) void proc_kill(proc_t *proc, long status) { // NOT_YET_IMPLEMENTED("PROCS: proc_kill"); - dbg(DBG_PROC, "proc_kill called on proc with pid=%d\n", proc->p_pid); - KASSERT(proc != curproc && "proc_kill called on curproc"); - list_iterate(&proc->p_threads, thr, kthread_t, kt_plink) { - dbg(DBG_PROC, "cancelling thread on proc with pid=%d with status=%ld\n", proc->p_pid, status); kthread_cancel(thr, (void *)status); } } @@ -362,10 +363,13 @@ void proc_kill(proc_t *proc, long status) void proc_kill_all() { // NOT_YET_IMPLEMENTED("PROCS: proc_kill_all"); - - list_iterate(&proc_list, p, proc_t, p_list_link) + list_iterate(&proc_list, p, proc_t, p_list_link) { - if (p->p_pid != curproc->p_pid && p->p_pid != PID_IDLE) + if ( + p->p_pid != curproc->p_pid + && + p->p_pproc->p_pid != PID_IDLE + ) { proc_kill(p, -1); } @@ -493,7 +497,6 @@ pid_t do_waitpid(pid_t pid, int *status, int options) while(1) { - proc_t *child; list_iterate(&curproc->p_children, child, proc_t, p_child_link) { if (child->p_state == PROC_DEAD) |