if paging exception occurs in kernel. prompt and halt?
if paging exception occurs in kernel. prompt and halt?
How to design the paging exception handler?
Re: if paging exception occurs in kernel. prompt and halt?
AFAIK, the page-fault handler can be called for a number of reasons. If it is called because a "page is not present", you should check if the page that is missing might be swapped to disk and retrieve it if necessary. If the page isn't on disk and isn't present, or some other error occurred, you could just turn off interrupts (if they aren't off), provide a register dump (the address causing the page fault is in CR2, I believe) and halt the entire kernel (like any ISR).
I have no way to swap pages to disk at the moment, so I just panic if a page-fault occurs (dump contents of registers and information regarding the page-fault).
I have no way to swap pages to disk at the moment, so I just panic if a page-fault occurs (dump contents of registers and information regarding the page-fault).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: if paging exception occurs in kernel. prompt and halt?
Hi,
You also have to deal with the situations where you have allocated the virtual space to a process (via sbrk), but have not allocated the physical page yet, in which case you need to call your page frame allocator, or the case where a stack extends beyond its current limit.
If a PFE occurs because a process has tried to access memory outside its memory space, terminate that process and create a log / display an error message. There is no reason why this should affect any other process (unless it's your kernel or a server that page faults).
Cheers,
Adam
You also have to deal with the situations where you have allocated the virtual space to a process (via sbrk), but have not allocated the physical page yet, in which case you need to call your page frame allocator, or the case where a stack extends beyond its current limit.
If a PFE occurs because a process has tried to access memory outside its memory space, terminate that process and create a log / display an error message. There is no reason why this should affect any other process (unless it's your kernel or a server that page faults).
Cheers,
Adam
Re: if paging exception occurs in kernel. prompt and halt?
What should you prompt for? Abort, retry, ignore? When page fault occurs you must either fix the fault and continue or stop (reboot or bluescreen), it's no use returning from page fault if the problem is not handled (for example by reading the page from swapfile).
Unless you're kernel itself has swappable pages you've already lost if it happens in the kernel. If the fault is from syscall argument supplied from userspace process you may be better of checking the validity of the arguments and swap the virtual memory in before accessing it (the kernel can know this anyway). The alternative is to have a page fault handler that checks if the page is in the calling process memory space (and if not make sure the syscall returns with proper error code), this is not what I recommend since it's very hard for the kernel page fault handler to know from where the error originates (if it's because of syscall arguments or because of kernel internals) and take the proper action.
Simply put: keep the kernel in memory and don't access memory that isn't paged in.
Unless you're kernel itself has swappable pages you've already lost if it happens in the kernel. If the fault is from syscall argument supplied from userspace process you may be better of checking the validity of the arguments and swap the virtual memory in before accessing it (the kernel can know this anyway). The alternative is to have a page fault handler that checks if the page is in the calling process memory space (and if not make sure the syscall returns with proper error code), this is not what I recommend since it's very hard for the kernel page fault handler to know from where the error originates (if it's because of syscall arguments or because of kernel internals) and take the proper action.
Simply put: keep the kernel in memory and don't access memory that isn't paged in.
Re: if paging exception occurs in kernel. prompt and halt?
OK, so if it's a bad kernel, I should halt the system.
Re: if paging exception occurs in kernel. prompt and halt?
If a #PF occurs, the exception handler should determine the cause of the page fault and fix it in some way. ie; if the page is swapped out, swap it back in. If the process accesses a page outside of the allocated heap terminate the process with an error.
When the system is in its early stages (not necessarily a "bad kernel") it is easiest to just make it halt the system As the system matures you would generally want to write it to handle the page faults as needed.
When the system is in its early stages (not necessarily a "bad kernel") it is easiest to just make it halt the system As the system matures you would generally want to write it to handle the page faults as needed.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}