【问题标题】:implementation of fork system call in os161os161中fork系统调用的实现
【发布时间】:2014-04-07 19:33:14
【问题描述】:

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

我的 sys_fork 函数的伪流程:

  1. 创建新地址空间,陷阱帧

  2. 声明新的线程指针——ptrthread——我这里没有分配内存

  3. as_copy(source->destination)

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

  5. 返回 pid()

伪分叉:

1.new trapframe = forkentry 的陷阱帧 arg

  1. curthread->vmspace = forkentry 的 addrspace arg

  2. actvate(curthread->vmspace)

  3. 在新的陷帧中设置一些变量

  4. mips_usermode....

当我运行内核时出现以下错误并且内核停止执行:

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)

【问题讨论】:

  • 什么代码?这将有助于查看实际代码。
  • 嘿安德鲁...对不起..但我无法粘贴实际代码...
  • 我不确定您希望我们如何帮助您。

标签: fork os161


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    错误似乎是陷阱帧需要与新线程在同一个堆栈上,而不是在堆中的某个位置。上述断言声明上方的注释中也写了同样的内容。

    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.

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-02
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2016-12-14
      • 2012-09-28
      相关资源
      最近更新 更多