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
refactor: mount system reworked
[lunaix-os.git]
/
lunaix-os
/
kernel
/
sched.c
diff --git
a/lunaix-os/kernel/sched.c
b/lunaix-os/kernel/sched.c
index 12deb174e7c90cc3fe5b6bd07055075d21f6e3ad..f8f00d40a094d62c31976cd4d54ef577673ba6de 100644
(file)
--- a/
lunaix-os/kernel/sched.c
+++ b/
lunaix-os/kernel/sched.c
@@
-6,6
+6,7
@@
#include <lunaix/mm/kalloc.h>
#include <lunaix/mm/pmm.h>
#include <lunaix/mm/kalloc.h>
#include <lunaix/mm/pmm.h>
+#include <lunaix/mm/valloc.h>
#include <lunaix/mm/vmm.h>
#include <lunaix/process.h>
#include <lunaix/sched.h>
#include <lunaix/mm/vmm.h>
#include <lunaix/process.h>
#include <lunaix/sched.h>
@@
-59,7
+60,8
@@
run(struct proc_info* proc)
apic_done_servicing();
asm volatile("pushl %0\n"
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
}
int
@@
-143,6
+145,12
@@
redo:
run(next);
}
run(next);
}
+void
+sched_yieldk()
+{
+ cpu_int(LUNAIX_SCHED);
+}
+
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
{
if (!seconds) {
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
{
if (!seconds) {
@@
-201,6
+209,11
@@
__DEFINE_LXSYSCALL3(pid_t, waitpid, pid_t, pid, int*, status, int, options)
return _wait(pid, status, options);
}
return _wait(pid, status, options);
}
+__DEFINE_LXSYSCALL(int, geterrno)
+{
+ return __current->k_status;
+}
+
pid_t
_wait(pid_t wpid, int* status, int options)
{
pid_t
_wait(pid_t wpid, int* status, int options)
{
@@
-212,7
+225,6
@@
_wait(pid_t wpid, int* status, int options)
}
wpid = wpid ? wpid : -__current->pgid;
}
wpid = wpid ? wpid : -__current->pgid;
- cpu_enable_interrupt();
repeat:
llist_for_each(proc, n, &__current->children, siblings)
{
repeat:
llist_for_each(proc, n, &__current->children, siblings)
{
@@
-231,13
+243,14
@@
repeat:
return 0;
}
// 放弃当前的运行机会
return 0;
}
// 放弃当前的运行机会
- sched_yield();
+ sched_yield
k
();
goto repeat;
done:
goto repeat;
done:
- cpu_disable_interrupt();
status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
- *status = proc->exit_code | status_flags;
+ if (status) {
+ *status = proc->exit_code | status_flags;
+ }
return destroy_process(proc->pid);
}
return destroy_process(proc->pid);
}
@@
-264,8
+277,9
@@
alloc_process()
proc->pid = i;
proc->created = clock_systime();
proc->pgid = proc->pid;
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->mm.regions
.head
);
llist_init_head(&proc->children);
llist_init_head(&proc->grp_member);
llist_init_head(&proc->sleep.sleepers);
llist_init_head(&proc->children);
llist_init_head(&proc->grp_member);
llist_init_head(&proc->sleep.sleepers);
@@
-279,7
+293,7
@@
commit_process(struct proc_info* process)
assert(process == &sched_ctx._procs[process->pid]);
if (process->state != PS_CREATED) {
assert(process == &sched_ctx._procs[process->pid]);
if (process->state != PS_CREATED) {
- __current->k_status =
LXINV
L;
+ __current->k_status =
EINVA
L;
return;
}
return;
}
@@
-302,17
+316,25
@@
destroy_process(pid_t pid)
{
int index = pid;
if (index <= 0 || index > sched_ctx.ptable_len) {
{
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);
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)
{
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)
{
-
lx
free(pos);
+
v
free(pos);
}
vmm_mount_pd(PD_MOUNT_1, proc->page_table);
}
vmm_mount_pd(PD_MOUNT_1, proc->page_table);