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: corner case for x87 context restore on execve
[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 5789927f27cf79b24ad4e4e84d3677675ab0dd98..acf04b72111d6136cf77fbcc2a0e2fa329346bc9 100644
(file)
--- a/
lunaix-os/kernel/process/sched.c
+++ b/
lunaix-os/kernel/process/sched.c
@@
-1,5
+1,5
@@
+#include <arch/abi.h>
#include <arch/x86/interrupts.h>
#include <arch/x86/interrupts.h>
-#include <arch/x86/tss.h>
#include <hal/apic.h>
#include <hal/cpu.h>
#include <hal/apic.h>
#include <hal/cpu.h>
@@
-63,6
+63,8
@@
sched_init_dummy()
struct exec_param* execp =
(void*)dummy_stack + DUMMY_STACK_SIZE - sizeof(struct exec_param);
struct exec_param* execp =
(void*)dummy_stack + DUMMY_STACK_SIZE - sizeof(struct exec_param);
+ isr_param* isrp = (void*)execp - sizeof(isr_param);
+
*execp = (struct exec_param){
.cs = KCODE_SEG,
.eflags = cpu_reflags() | 0x0200,
*execp = (struct exec_param){
.cs = KCODE_SEG,
.eflags = cpu_reflags() | 0x0200,
@@
-70,13
+72,15
@@
sched_init_dummy()
.ss = KDATA_SEG,
};
.ss = KDATA_SEG,
};
+ *isrp = (isr_param){ .registers = { .ds = KDATA_SEG,
+ .es = KDATA_SEG,
+ .fs = KDATA_SEG,
+ .gs = KDATA_SEG },
+ .execp = execp };
+
// memset to 0
dummy_proc = (struct proc_info){};
// memset to 0
dummy_proc = (struct proc_info){};
- dummy_proc.intr_ctx = (isr_param){ .registers = { .ds = KDATA_SEG,
- .es = KDATA_SEG,
- .fs = KDATA_SEG,
- .gs = KDATA_SEG },
- .execp = execp };
+ dummy_proc.intr_ctx = isrp;
dummy_proc.page_table = cpu_rcr3();
dummy_proc.state = PS_READY;
dummy_proc.page_table = cpu_rcr3();
dummy_proc.state = PS_READY;
@@
-99,7
+103,6
@@
run(struct proc_info* proc)
由于这中间没有进行地址空间的交换,所以第二次跳转使用的是同一个内核栈,而之前默认tss.esp0的值是永远指向最顶部
这样一来就有可能会覆盖更早的上下文信息(比如嵌套的信号捕获函数)
*/
由于这中间没有进行地址空间的交换,所以第二次跳转使用的是同一个内核栈,而之前默认tss.esp0的值是永远指向最顶部
这样一来就有可能会覆盖更早的上下文信息(比如嵌套的信号捕获函数)
*/
- tss_update_esp(proc->intr_ctx.esp);
apic_done_servicing();
apic_done_servicing();
@@
-139,7
+142,7
@@
check_sleepers()
time_t now = clock_systime();
llist_for_each(pos, n, &leader->sleep.sleepers, sleep.sleepers)
{
time_t now = clock_systime();
llist_for_each(pos, n, &leader->sleep.sleepers, sleep.sleepers)
{
- if (
PROC_TERMINATED(pos->state
)) {
+ if (
proc_terminated(pos
)) {
goto del;
}
goto del;
}
@@
-226,7
+229,7
@@
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
}
llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
}
-
__current->intr_ctx.registers.eax = seconds
;
+
store_retval(seconds)
;
block_current();
schedule();
block_current();
schedule();
@@
-340,8
+343,6
@@
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);
llist_init_head(&proc->tasks);
llist_init_head(&proc->mm.regions);
llist_init_head(&proc->tasks);
@@
-412,7
+413,6
@@
destroy_process(pid_t pid)
}
vfree(proc->fdtable);
}
vfree(proc->fdtable);
- vfree_dma(proc->fxstate);
vmm_mount_pd(VMS_MOUNT_1, proc->page_table);
vmm_mount_pd(VMS_MOUNT_1, proc->page_table);
@@
-463,5
+463,5
@@
orphaned_proc(pid_t pid)
// 如果其父进程的状态是terminated 或 destroy中的一种
// 或者其父进程是在该进程之后创建的,那么该进程为孤儿进程
// 如果其父进程的状态是terminated 或 destroy中的一种
// 或者其父进程是在该进程之后创建的,那么该进程为孤儿进程
- return
PROC_TERMINATED(parent->state
) || parent->created > proc->created;
+ return
proc_terminated(parent
) || parent->created > proc->created;
}
\ No newline at end of file
}
\ No newline at end of file