Interrupt 6 on fork

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
RobertF
Member
Member
Posts: 25
Joined: Tue Oct 18, 2011 12:55 am

Interrupt 6 on fork

Post 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?
RobertF
Member
Member
Posts: 25
Joined: Tue Oct 18, 2011 12:55 am

Re: Interrupt 6 on fork

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Interrupt 6 on fork

Post 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?
RobertF
Member
Member
Posts: 25
Joined: Tue Oct 18, 2011 12:55 am

Re: Interrupt 6 on fork

Post 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.
RobertF
Member
Member
Posts: 25
Joined: Tue Oct 18, 2011 12:55 am

Re: Interrupt 6 on fork

Post 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.
Post Reply