Page 1 of 1
Interrupt 6 on fork
Posted: Fri Mar 09, 2012 12:29 am
by RobertF
When I attempt to fork, the child process throws interrupt 6 after returning to the calling function. After a bit of debugging, I believe the problem is in the stack:
If I copy the stack to a new location during fork, it will work (although it will not fork again)
If I take the code from fork and copy it into the calling function, it will work.
Currently my fork clones the current directory. I thought this would copy over the stack, but seeing as I still get interrupt 6 regardless of whether I clone the current directory or not, it appears I'm looking in the wrong place.
Any pointers on how to fix this? Do I need to provide any more information?
Re: Interrupt 6 on fork
Posted: Sat Mar 10, 2012 1:11 am
by RobertF
berkus wrote:A clone of current directory would point into the same place for the stack, wouldn't it?
I assumed so, but even if I don't clone the current directory I still have the same problem. Perhaps it's not the stack, then.
Re: Interrupt 6 on fork
Posted: Mon Mar 12, 2012 4:06 am
by JamesM
RobertF wrote:When I attempt to fork, the child process throws interrupt 6 after returning to the calling function. After a bit of debugging, I believe the problem is in the stack:
If I copy the stack to a new location during fork, it will work (although it will not fork again)
If I take the code from fork and copy it into the calling function, it will work.
Currently my fork clones the current directory. I thought this would copy over the stack, but seeing as I still get interrupt 6 regardless of whether I clone the current directory or not, it appears I'm looking in the wrong place.
Any pointers on how to fix this? Do I need to provide any more information?
Am I reading this correctly and you have two threads using the same stack?
Re: Interrupt 6 on fork
Posted: Mon Mar 12, 2012 6:48 am
by RobertF
JamesM wrote:Am I reading this correctly and you have two threads using the same stack?
The new thread takes the esp and ebp from the parent thread, but I'm not physically copying the parent's stack to the childs.
Also, my fork had a while loop at the end; removing this caused interrupt 13 instead of interrupt 6. I've also found that if I use GRUB's stack instead of setting one up before I call the kernel's main, I'll page fault instead of generating any interrupts.
Re: Interrupt 6 on fork
Posted: Wed Mar 14, 2012 7:53 am
by RobertF
Turns out I was cloning the page directory incorrectly (as berkus hinted)—doesn't mean I fixed this yet, but it's a lot more satisfying to have a problem and know where it is rather than being completely baffled by it.