Page 1 of 1

page fault caused by instruction fetch

Posted: Wed Jan 15, 2014 11:11 pm
by loki2441
Hi All,
If there is one page fault, the page fault handler will get the error code
osdevwiki wrote: 31 4 0
+-----+-...-+-----+-----+-----+-----+-----+-----+
| Reserved | I/D | RSVD| U/S | W/R | P |
+-----+-...-+-----+-----+-----+-----+-----+-----+
P: When set, the fault was caused by a protection violation.
When not set, it was caused by a non-present page.
W/R: When set, write access caused the fault; otherwise read access.
U/S: When set, the fault occurred in user mode; otherwise in supervisor mode.
RSVD: When set, one or more page directory entries contain reserved bits which are set to 1.
This only applies when the PSE or PAE flags in CR4 are set to 1.
I/D: When set, the fault was caused by an instruction fetch.
This only applies when the No-Execute bit is supported and enabled.
I am a very curious about how the instruction fetch page fault is generated? I would really appreciate it if someone could give me a example.
And also how this kind of page fault will be handled? Thanks for your time!

Best Wishes,
Yaohui Hu

Re: page fault caused by instruction fetch

Posted: Thu Jan 16, 2014 12:44 am
by Brendan
Hi,
loki2441 wrote:I am a very curious about how the instruction fetch page fault is generated? I would really appreciate it if someone could give me a example.
It's generated the same as any other page fault (e.g. the access wasn't allowed by the page's attributes). An example would be attempting to execute code in a page that has the "execute disable" bit set.
loki2441 wrote:And also how this kind of page fault will be handled?
It'd be handled the same as any other page fault. Specifically:
  • determine if the access should have been allowed:
    • If it should've been allowed, fix stuff so that the access will work (e.g. load the page from swap space or memory mapped file) and return (retry the instruction that caused the exception)
    • If it shouldn't be allowed (e.g. the code that was running crashed), pass control to some sort of crash handler (which might do "blue screen of death", or terminate the process, or send a signal to the process, or do a core dump, or whatever).

Cheers,

Brendan