Eino T
Eino T

Reputation: 141

Restarting instruction after page fault

I'm developing an operating system in C and I'm struggling on paging. I'm testing my kernel heap in a loop by allocating memory and outputting the low level memory allocation output that handles physical and virtual page allocation.

When PDE 0, everything works great for pages 0-1023 but as soon as the allocation moves to PDE 1, a page fault is raised with the present flag set, and sometimes the rw flag too if I start allocating from a different physical address.

Do I need to get the faulting address from cr2 and map it back to the PDE and page it belongs to and then set or the address with 3? After that I need to restart the instruction but how do I do that? Any suggestions?

Upvotes: 3

Views: 2651

Answers (1)

SecurityMatt
SecurityMatt

Reputation: 6743

Page Fault is a fault exception, which means your page-fault handler is called directly by the processor as if an interrupt occurred.

After you have serviced the page-fault and would like to go back to the caller, you need to return from the fault via the IRET instruction. This will return the code-segment, eflags register and EIP (and potentially the user-mode SS and ESP if the fault was from ring 3) back to the instruction that triggered the fault.

Upvotes: 4

Related Questions