Page Fault Handling

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
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Page Fault Handling

Post by oib111 »

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?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Page Fault Handling

Post by NickJohnson »

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.
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Page Fault Handling

Post by oib111 »

Well I added some lines of the code that look like this:

Code: Select all

p = page;
*p = 0xdeadbeef;
put("All mapped.");
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.
User avatar
Combuster
Member
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

Post by Combuster »

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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Page Fault Handling

Post by oib111 »

What do you mean take care of the error code?
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Page Fault Handling

Post by Firestryke31 »

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?
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Page Fault Handling

Post by oib111 »

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.
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Page Fault Handling

Post by oib111 »

Fixed...request lock.
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: Page Fault Handling

Post by tantrikwizard »

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.
yes, pop the error code from the stack before returning.
pcmattman
Member
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

Post by pcmattman »

oib111 wrote:Fixed...request lock.
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
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Page Fault Handling

Post by oib111 »

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