From: AceVest Date: Thu, 31 Jul 2014 15:20:11 +0000 (+0800) Subject: fix write protection bug when fork X-Git-Tag: 0.3.0~5 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=523942d07ca683682551e66dc7fe4f15dbf636dc;p=kernel.git fix write protection bug when fork --- diff --git a/kernel/exec.c b/kernel/exec.c index d6ffd26..8732ff9 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -67,8 +67,6 @@ int sysc_exec(const char *path, char *const argv[]) assert(strncmp(ELFMAG, ehdr->e_ident, sizeof(ELFMAG)-1) == 0); printk("Elf Entry: %08x\n", ehdr->e_entry); - - int i, j; for(i=0; ie_phnum; ++i) { @@ -109,6 +107,7 @@ int sysc_exec(const char *path, char *const argv[]) } } + load_cr3(current); disable_irq(); @@ -127,7 +126,7 @@ int sysc_exec(const char *path, char *const argv[]) #endif regs->eip = (unsigned long)ehdr->e_entry; regs->edx = regs->eip; - regs->ecx = (0xC0000000 - 16); + regs->ecx = KRNLADDR; //(0xC0000000 - 16); //kfree(buf); diff --git a/kernel/fork.c b/kernel/fork.c index 57d67bc..968b75f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -94,6 +94,8 @@ int do_fork(pt_regs_t *regs, unsigned long flags) } //} + load_cr3(current); + tsk->pid = get_next_pid(); tsk->ppid = current->pid; diff --git a/kernel/innerint.c b/kernel/innerint.c index 77feb17..7e064e8 100644 --- a/kernel/innerint.c +++ b/kernel/innerint.c @@ -104,7 +104,7 @@ US RW P - Description asm("movl %%cr2,%%eax":"=a"(addr)); - printk("do page fault errcode %x addr %08x [%08x]\n", errcode, addr, current); + //printk("do page fault errcode %x addr %08x [%08x]\n", errcode, addr, current); //assert(errcode != 2 && errcode != 6); diff --git a/kernel/sched.c b/kernel/sched.c index d5626e0..381c098 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -183,7 +183,6 @@ unsigned long schedule() if(prev != next) { - printd("[s:%08x]\n", next); context_switch(prev, next); } } diff --git a/lib/libc.S b/lib/libc.S index f4e14e2..ea20738 100644 --- a/lib/libc.S +++ b/lib/libc.S @@ -24,9 +24,9 @@ loop: jmp loop */ - pushl $0 # env - pushl $0 # argv - pushl $1 # argc + + pushl $0xAAAAAAAA + pushl $0x11111111 call main diff --git a/lib/syscall.c b/lib/syscall.c index 7ca1420..c4a2276 100644 --- a/lib/syscall.c +++ b/lib/syscall.c @@ -18,35 +18,35 @@ "sysenter;" \ "1:" -static int __syscall0(int nr) +static int __volatile__ __syscall0(int nr) { int __sysc_ret__ = 0; asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr)); return __sysc_ret__; } -static int __syscall1(int nr, unsigned long a) +static int __volatile__ __syscall1(int nr, unsigned long a) { int __sysc_ret__ = 0; asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a)); return __sysc_ret__; } -static int __syscall2(int nr, unsigned long a, unsigned long b) +static int __volatile__ __syscall2(int nr, unsigned long a, unsigned long b) { int __sysc_ret__ = 0; asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b)); return __sysc_ret__; } -static int __syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) +static int __volatile__ __syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) { int __sysc_ret__ = 0; asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c)); return __sysc_ret__; } -static int __syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) +static int __volatile__ __syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) { int __sysc_ret__ = 0; asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c), "S"(d));