Quick Stack Question

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
TheUbu

Quick Stack Question

Post by TheUbu »

With paging on is it normal for the cpu to crash with out faulting if your stack grows into unmapped pages?


-Christopher
carbonBased

RE:Quick Stack Question

Post 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
TheUbu

RE:Quick Stack Question

Post 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
anton

RE:Quick Stack Question

Post 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, ...).
carbonBased

RE:Quick Stack Question

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