在os161中实现fork系统调用

时间:2014-04-07 19:33:14

标签: fork os161

我正在尝试在os161中实现fork调用但是在运行内核后我得到以下错误:

我的sys_fork函数的伪流程:

  1. 创建新的地址空间,陷阱框架

  2. 声明新线程指针 - ptrthread - 我没有在此处分配内存

  3. as_copy(源 - >目的地)

  4. thread fork(name,new trapframe,(unsigned long)ptrthread-> vmspace,forkentry function,ptrthread)

  5. 返回pid()

  6. 伪伪造:

    1.new trapframe = trap frame for arken of forkentry

    1. curthread-> vmspace = forkentry的addrspace arg

    2. actvate(curthread-> vmspace)

    3. 在新的陷阱框架中设置一些vard

    4. ... mips_usermode

    5. 当我运行内核后发生错误并且内核停止执行:

      sys161: System/161 release 1.14, compiled Aug 24 2011 10:55:58 OS/161 base system version 1.11 Copyright (c) 2000, 2001, 2002, 2003 President and Fellows of Harvard College. All rights rescheduler: Dropping thread <boot/menu>. panic: Assertion failed: SAME_STACK(curkstack-1, (vaddr_t)tf), at ../../arch/mips/mips/trap.c:220 (mips_trap) sys161: 930837 cycles (827682k, 0u, 103155i) sys161: 130 irqs 20 exns 0r/0w disk 0r/279w console 0r/0w/1m emufs 0r/0w net sys161: Elapsed real time: 0.087962 seconds (10.5823 mhz) sys161: Elapsed virtual time: 0.037233480 seconds (25 mhz)

2 个答案:

答案 0 :(得分:0)

我基于相同的方法编写了fork系统调用。 您可以看看以下方法:

https://github.com/prathammalik/OS161/blob/master/kern/syscall/psyscall.c

答案 1 :(得分:0)

错误似乎是陷阱帧需要与新线程位于同一堆栈上,而不是堆中的某个位置。在上述断言语句上方的注释中也是如此。

It's necessary for the trap frame used here to be on the current thread's own stack. It cannot correctly be on either another thread's stack or in the kernel heap.

因此,您需要将陷阱帧从堆复制到当前线程的堆栈中。