Page 1 of 1

Quick Stack Question

Posted: Wed Aug 14, 2002 11:00 pm
by TheUbu
With paging on is it normal for the cpu to crash with out faulting if your stack grows into unmapped pages?


-Christopher

RE:Quick Stack Question

Posted: Wed Aug 14, 2002 11:00 pm
by carbonBased
Yes.

Think of it this way, you've accessed a inaccessable stack page... you've run out of stack space.  So, the processor issues a page fault.  But, most OSs handle a page fault as a standard interrupt gate or trap, which doesn't change ss or esp, right?

But, an interrupt needs a return address... where's that address go?  On the stack... but you don't have any stack... you've run out.

So, the processor then issues a double fault... same deal, need a return address, but no stack, and so the processor goes right on to a triple fault, and there's your reboot.

There's a few ways to handle this; allocate more stack, or make your page fault (or, perhaps more useful, your double fault) exception a task gate, which will allow you to load new ss and esp values.

Cheers,
Jeff

RE:Quick Stack Question

Posted: Thu Aug 15, 2002 11:00 pm
by TheUbu
Jeff,
istopher
Thanks :)

I have been beating my brain for a few days so I have just been ignoring the problem. I'm going to try that out see if it works because my "hack" to get around that was been to police the sp but that is costly in terms of overhead.



-Christopher

RE:Quick Stack Question

Posted: Thu Aug 29, 2002 11:00 pm
by anton
"make your page fault (or, perhaps more useful, your double fault) exception a task gate"-that's not the only way,
You can also use a call gate, which changes the run level. In this case it will use the stack of the new run level(if old<=new, ...).

RE:Quick Stack Question

Posted: Sun Sep 01, 2002 11:00 pm
by carbonBased
> You can also use a call gate, which changes the run level. In this case it
> will use the stack of the new run level(if old<=new, ...).

Yes, but then you'll always be leaving out one privelege level.  Any privelege level could exceed the stack allocated for it.  I suppose if you can _garauntee_ that the OS (at level 0) wont, then making the exception handler p0 as well would be acceptable (but could cause problems if your drivers are also at p0... I wouldn't trust 'em :)

Jeff