mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: exit
This commit is contained in:
@@ -16,7 +16,8 @@ extern syscall_fstat
|
||||
extern syscall_fork
|
||||
extern syscall_execve
|
||||
extern syscall_waitpid
|
||||
func_count equ 15
|
||||
extern syscall_exit
|
||||
func_count equ 16
|
||||
|
||||
|
||||
func_table:
|
||||
@@ -35,6 +36,7 @@ func_table:
|
||||
dq syscall_fork
|
||||
dq syscall_execve
|
||||
dq syscall_waitpid
|
||||
dq syscall_exit
|
||||
section .text
|
||||
global asm_syscall_entry
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <kernel/sched.h>
|
||||
#include <arch/cls.h>
|
||||
#include <arch/spinlock.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/alloc.h>
|
||||
|
||||
void syscall_exit(int status){
|
||||
proc_t* proc = arch_getcls()->thread->proc;
|
||||
|
||||
spinlock_acquire(&proc->lock);
|
||||
|
||||
// TODO make all other threads exit
|
||||
|
||||
free(proc->threads);
|
||||
|
||||
for(uintmax_t fd = 0; fd < proc->fdtable.fdcount; ++ fd)
|
||||
fd_free(&proc->fdtable, fd);
|
||||
|
||||
|
||||
|
||||
proc->state = PROC_STATE_ZOMBIE;
|
||||
proc->status = status;
|
||||
|
||||
vfs_close(proc->root);
|
||||
vfs_close(proc->cwd);
|
||||
|
||||
proc_t* init = sched_getinit();
|
||||
|
||||
spinlock_acquire(&init->lock);
|
||||
|
||||
proc_t* child = proc->child;
|
||||
proc_t* firstchild = child;
|
||||
|
||||
while(child){
|
||||
spinlock_acquire(&child->lock);
|
||||
child->parent = init;
|
||||
if(!child->sibling){
|
||||
child->sibling = init->child;
|
||||
init->child = firstchild;
|
||||
}
|
||||
spinlock_release(&child->lock);
|
||||
child = child->sibling;
|
||||
}
|
||||
|
||||
spinlock_release(&init->lock);
|
||||
spinlock_release(&proc->lock);
|
||||
|
||||
event_signal(&proc->parent->childevent, true);
|
||||
|
||||
sched_dequeue();
|
||||
|
||||
__builtin_unreachable();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user