-1

I am trying to implement fork call in os161 but after running kernel i get following error:

pseudo flow of my sys_fork function:

  1. create new address space, trap frame

  2. declare new thread pointer -- ptrthread -- i have not assigned memory here

  3. as_copy(source->destination)

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

  5. return pid()

pseudo forkentry:

1.new trapframe = trap frame arg of forkentry

  1. curthread->vmspace = addrspace arg of forkentry

  2. actvate(curthread->vmspace)

  3. set some vard in new trapframe

  4. mips_usermode....

when I run kernel following error occurs and kernel stops executing:

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)

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1079065
  • 2,085
  • 9
  • 30
  • 53

2 Answers2

0

I coded the fork syscall based on somewhat the same approach. You could have a look the following approach:

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

n3wcod3r
  • 114
  • 10
0

The error seems to be that the trapframe needs to be on the same stack as the new thread and not somewhere in the heap. The same is written in the comment just above the aforementioned assertion statement.

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.

So, you'll need to copy the trapframe from the heap onto the current thread's stack.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253