Page Fault Handling
Page Fault Handling
So I setup a page-fault handler, but after the page-fault occurs and my handler runs a GPF occurs. Is this happening because the page isn't properly mapped?
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Page Fault Handling
Does the GPF occur during or after the handler? If it's during, you probably have some problem with reloading the process image, where an incorrect segment descriptor (caused by trying to reload from the wrong area of memory) can cause a GPF. It could be other things, but it most likely has nothing to do with paging, otherwise you would get another page fault.
Re: Page Fault Handling
Well I added some lines of the code that look like this:
If the page hadn't been mapped correctly, another page fault would occur when trying to write 0xdeadbeef. When I tested the page-fault handler with those extra lines, "All mapped" was printed out, so I don't think it's a problem with whether or not the page is mapped or any code within the page mapping function.
Code: Select all
p = page;
*p = 0xdeadbeef;
put("All mapped.");
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Page Fault Handling
Did you take care of the error code after a PF? If not, your stack is corrupt and you'd indeed get a GPF the moment you try to return
Re: Page Fault Handling
What do you mean take care of the error code?
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: Page Fault Handling
IIRC when the CPU generates a page fault it pushes what happened on the stack, as well as putting where it happened in CR2. If you don't handle cleaning up this error code (most tutorial IRQ handlers do without explaining too well) then the error code throws off the stack and you get either the wrong return address or a corrupt stack after return (I can't remember which at the moment).
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Re: Page Fault Handling
Do you mean to add 4 to esp so that it points to EIP and not the error code? If so, that didn't work.
Re: Page Fault Handling
Fixed...request lock.
-
- Member
- Posts: 153
- Joined: Sun Jan 07, 2007 9:40 am
- Contact:
Re: Page Fault Handling
yes, pop the error code from the stack before returning.oib111 wrote:Do you mean to add 4 to esp so that it points to EIP and not the error code? If so, that didn't work.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Page Fault Handling
Would you mind telling us how you fixed it, so that others who stumble across the same problem can find a solution rather than a dead-end?oib111 wrote:Fixed...request lock.
Re: Page Fault Handling
Popped the error code off the stack. It wasn't working before for some other reasons, that aren't really worth mentioning. Just silly coding mistakes.