Hi,
I'm a bit confused about stack faults and their handling; I have setup kernel VM with its own heap and stack. I initially decided that I'd start with a single page for the stack and as the need arises add more to it. This, I thought, should be done by catching faults. But what i don't understand is, what is the kind of fault that occurs ? Is it page fault when esp goes beyond the page or is it stack fault. And be it any of the two, how can I handle them ? I mean the interrupt needs to save the values into a stack right ?.. but the stack just faulted :-\. Is this what is referred to as a double fault ? Are there any ways to handle it, or better any method to grow stack as needed ?
Thanks
Stack fault handling
Re:Stack fault handling
For a stack access on a non-mapped page, it should be the stack fault. For a stack access beyond the segment limit, I think it's a GPF, although I cannot be sure (could be stack fault as well). Why don't you try it?seraph9 wrote: But what i don't understand is, what is the kind of fault that occurs ?
If you handle it in a decent way, then you don't get a second stack fault. If you handle the stack fault by pushing values, you're doing something wrong. On IA32, use some mechanism to swap stacks (f.i. use a TSS or Task Gate), on AMD64, use a different stack (access with PCD, PAT, and PWT bits).And be it any of the two, how can I handle them ? I mean the interrupt needs to save the values into a stack right ?.. but the stack just faulted :-\. Is this what is referred to as a double fault ? Are there any ways to handle it, or better any method to grow stack as needed ?
When a stack fault happens in user space, the stack is first switched to kernel space and then the values are pushed. If you fault in kernel space, you're screwed (unless you thought of that beforehand).
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Stack fault handling
the best way i've found to handle this situation is to make the stack fault used (i.e. setting a stack segment that has a limit that will *not* let you go to the page fault. As segmentation is applied first and *then* paging, you'll get a stack fault and not a page fault if the two were possible.
The stack fault handler has then to be a *trap gate*, which will make the fault handled in a new task with a fresh stack.
In the case of a *user* mode stack, you can simply have a page fault, as the fault will be handled on the *system* stack defined by SS0:ESP0
The stack fault handler has then to be a *trap gate*, which will make the fault handled in a new task with a fresh stack.
In the case of a *user* mode stack, you can simply have a page fault, as the fault will be handled on the *system* stack defined by SS0:ESP0