Reputation: 115
I need to implement virtual memory for one school project and I'm confused about something. If page fault occurs while working with stack (simple push for example), how and where am I going to save return address if I cannot push?
Upvotes: 2
Views: 2771
Reputation: 14107
Here's what our development team did when faced with this same problem ...
We designed our in-house OS such that the page fault handler was not allowed to generate a page fault. Thus, the stack to which the page fault exception stack frame was pushed absolutely had to be guaranteed to be present in memory. Furthermore, any routine used by the page fault handler also by necessity had to be present in memory, as otherwise that could cause a page fault thereby violating the design.
Upvotes: 1
Reputation: 47690
That's a very good question. Page faults cause an interrupt and how does that interrupt know where to return if it cannot preserve the return address?
On x86 architecture, TSS (task state segment) contains different stack pointers for different privilege levels. So if your user mode process runs out of stack, CPU privilege level is lowered and an exception is raised. That means as soon as you switch to the new privilege level, OS can start to use the new stack which resides in kernel memory and isn't subject to stack limits of the user process.
Upvotes: 4