git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: memory leakage in file descriptor allocation
[lunaix-os.git]
/
lunaix-os
/
kernel
/
process
/
sched.c
diff --git
a/lunaix-os/kernel/process/sched.c
b/lunaix-os/kernel/process/sched.c
index 0a9cea2f9643b5c16a904ae5f2fe32daa1276b10..c2a24261dde6c7dc92eba8285b37368209c9a457 100644
(file)
--- a/
lunaix-os/kernel/process/sched.c
+++ b/
lunaix-os/kernel/process/sched.c
@@
-4,6
+4,7
@@
#include <hal/apic.h>
#include <hal/cpu.h>
#include <hal/apic.h>
#include <hal/cpu.h>
+#include <lunaix/fs/taskfs.h>
#include <lunaix/mm/cake.h>
#include <lunaix/mm/kalloc.h>
#include <lunaix/mm/pmm.h>
#include <lunaix/mm/cake.h>
#include <lunaix/mm/kalloc.h>
#include <lunaix/mm/pmm.h>
@@
-171,7
+172,8
@@
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
__current->intr_ctx.registers.eax = seconds;
llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
__current->intr_ctx.registers.eax = seconds;
- __current->state = PS_BLOCKED;
+
+ block_current();
schedule();
}
schedule();
}
@@
-281,6
+283,8
@@
alloc_process()
proc->created = clock_systime();
proc->pgid = proc->pid;
proc->fdtable = vzalloc(sizeof(struct v_fdtable));
proc->created = clock_systime();
proc->pgid = proc->pid;
proc->fdtable = vzalloc(sizeof(struct v_fdtable));
+ proc->fxstate =
+ vzalloc_dma(512); // FXSAVE需要十六位对齐地址,使用DMA块(128位对齐)
llist_init_head(&proc->mm.regions.head);
llist_init_head(&proc->tasks);
llist_init_head(&proc->mm.regions.head);
llist_init_head(&proc->tasks);
@@
-335,17
+339,22
@@
destroy_process(pid_t pid)
llist_delete(&proc->tasks);
llist_delete(&proc->sleep.sleepers);
llist_delete(&proc->tasks);
llist_delete(&proc->sleep.sleepers);
+ taskfs_invalidate(pid);
+
if (proc->cwd) {
vfs_unref_dnode(proc->cwd);
}
for (size_t i = 0; i < VFS_MAX_FD; i++) {
struct v_fd* fd = proc->fdtable->fds[i];
if (proc->cwd) {
vfs_unref_dnode(proc->cwd);
}
for (size_t i = 0; i < VFS_MAX_FD; i++) {
struct v_fd* fd = proc->fdtable->fds[i];
- if (fd)
+ if (fd)
{
vfs_pclose(fd->file, pid);
vfs_pclose(fd->file, pid);
+ vfs_free_fd(fd);
+ }
}
vfree(proc->fdtable);
}
vfree(proc->fdtable);
+ vfree_dma(proc->fxstate);
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)