diff options
author | Marvin Borner | 2021-06-08 21:13:33 +0200 |
---|---|---|
committer | Marvin Borner | 2021-06-08 21:13:33 +0200 |
commit | 24ce56cccb6f179f8c6ed9ad82e6afb871aabf80 (patch) | |
tree | ec3283601331b6def7218c7b39386d6bb25bcd5b /kernel | |
parent | f7890c4b16b5d817db286119ac0a88630c3a1cf9 (diff) |
Process exit improvements
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/int.c | 6 | ||||
-rw-r--r-- | kernel/features/mm.c | 6 | ||||
-rw-r--r-- | kernel/features/proc.c | 12 | ||||
-rw-r--r-- | kernel/features/syscall.c | 4 | ||||
-rw-r--r-- | kernel/inc/proc.h | 2 |
5 files changed, 17 insertions, 13 deletions
diff --git a/kernel/drivers/int.c b/kernel/drivers/int.c index 39462fa..f6a5134 100644 --- a/kernel/drivers/int.c +++ b/kernel/drivers/int.c @@ -109,12 +109,16 @@ static void int_trap_handler(struct int_frame *frame) frame->eip, frame->eip - proc->entry); printf("\t\t-> Process: [entry: %x, kstack: %x, esp %x, ustack: %x]\n", proc->entry, proc->stack.kernel, frame->esp, proc->stack.user); + faulting--; - proc_exit(proc, 1); + proc_exit(1); } else { + print_trace(); while (1) __asm__ volatile("cli\nhlt"); } + + assert_not_reached(); } /** diff --git a/kernel/features/mm.c b/kernel/features/mm.c index 0137256..736a5a4 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -75,7 +75,7 @@ static void page_fault_handler(u32 esp) // Check error code const char *type = (frame->err_code & 1) ? "present" : "non-present"; const char *operation = (frame->err_code & 2) ? "write" : "read"; - const char *super = (frame->err_code & 4) ? "User" : "Super"; + const char *super = (frame->err_code & 4) ? "user" : "super"; // Check cr2 address (virtual and physical) u32 vaddr; @@ -86,8 +86,8 @@ static void page_fault_handler(u32 esp) // Print! - printf("%s process tried to %s a %s page at [vaddr=%x; paddr=%x]\n", super, operation, type, - vaddr, paddr); + printf("Process in %s-state tried to %s a %s page at [vaddr=%x; paddr=%x]\n", super, + operation, type, vaddr, paddr); if (proc && vaddr > proc->stack.user_ptr - PROC_STACK_SIZE - PAGE_SIZE && vaddr < proc->stack.user_ptr + PAGE_SIZE) diff --git a/kernel/features/proc.c b/kernel/features/proc.c index b686823..70e3666 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -156,9 +156,10 @@ void proc_state(struct proc *proc, enum proc_state state) // else: Nothing to do! } -void proc_exit(struct proc *proc, s32 status) +void proc_exit(s32 status) { - assert(proc != idle_proc->data); + struct proc *proc = proc_current(); + assert(proc && proc != idle_proc->data); struct node *running = list_first_data(proc_list_running, proc); if (!running || !list_remove(proc_list_running, running)) { @@ -166,10 +167,9 @@ void proc_exit(struct proc *proc, s32 status) assert(blocked && list_remove(proc_list_blocked, blocked)); } - if (current->data == proc) { - memory_switch_dir(virtual_kernel_dir()); - current = NULL; - } + // Force switch to other process + memory_switch_dir(virtual_kernel_dir()); + current = NULL; printf("Process %s (%d) exited with status %d (%s)\n", proc->name[0] ? proc->name : "UNKNOWN", proc->pid, status, diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 93355db..6e43caa 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -89,14 +89,14 @@ static u32 syscall_handler(u32 esp) struct proc *proc = proc_make(PROC_PRIV_NONE); frame->eax = (u32)elf_load(path, proc); if (frame->eax != EOK) - proc_exit(proc, -frame->eax); + panic("NOT IMPLEMENTED\n"); // TODO: Implement exec path/etc verify else proc_yield(); break; } case SYS_EXIT: { frame->eax = EOK; - proc_exit(proc_current(), (s32)frame->ebx); + proc_exit((s32)frame->ebx); break; } case SYS_YIELD: { diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index b8310d1..b2e5c8b 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -60,7 +60,7 @@ struct proc *proc_current(void); u8 proc_super(void); u8 proc_idle(void); struct proc *proc_from_pid(u32 pid); -void proc_exit(struct proc *proc, s32 status) NONNULL; +void proc_exit(s32 status); void proc_yield(void); void proc_set_quantum(struct proc *proc, u32 value) NONNULL; void proc_reset_quantum(struct proc *proc) NONNULL; |