X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/874b3b5a74d815aa91f325e5573052a3c8ce1d39..a5338b60e111972364a8bc6f07011c6defd213d2:/lunaix-os/kernel/sched.c diff --git a/lunaix-os/kernel/sched.c b/lunaix-os/kernel/sched.c index 5081ccf..be99525 100644 --- a/lunaix-os/kernel/sched.c +++ b/lunaix-os/kernel/sched.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -59,7 +60,8 @@ run(struct proc_info* proc) apic_done_servicing(); asm volatile("pushl %0\n" - "jmp switch_to\n" ::"r"(proc)); // kernel/asm/x86/interrupt.S + "jmp switch_to\n" ::"r"(proc) + : "memory"); // kernel/asm/x86/interrupt.S } int @@ -201,6 +203,11 @@ __DEFINE_LXSYSCALL3(pid_t, waitpid, pid_t, pid, int*, status, int, options) return _wait(pid, status, options); } +__DEFINE_LXSYSCALL(int, geterrno) +{ + return __current->k_status; +} + pid_t _wait(pid_t wpid, int* status, int options) { @@ -266,6 +273,7 @@ alloc_process() proc->pid = i; proc->created = clock_systime(); proc->pgid = proc->pid; + proc->fdtable = vzalloc(sizeof(struct v_fdtable)); llist_init_head(&proc->mm.regions); llist_init_head(&proc->children); @@ -281,7 +289,7 @@ commit_process(struct proc_info* process) assert(process == &sched_ctx._procs[process->pid]); if (process->state != PS_CREATED) { - __current->k_status = LXINVL; + __current->k_status = EINVAL; return; } @@ -304,13 +312,21 @@ destroy_process(pid_t pid) { int index = pid; if (index <= 0 || index > sched_ctx.ptable_len) { - __current->k_status = LXINVLDPID; + __current->k_status = EINVAL; return; } struct proc_info* proc = &sched_ctx._procs[index]; proc->state = PS_DESTROY; llist_delete(&proc->siblings); + for (size_t i = 0; i < VFS_MAX_FD; i++) { + struct v_fd* fd = proc->fdtable->fds[i]; + if (fd) + vfs_close(fd->file); + } + + vfree(proc->fdtable); + struct mm_region *pos, *n; llist_for_each(pos, n, &proc->mm.regions.head, head) {