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.
Hi.
I am trying to unmapping a virtual page, as written in wiki, I set pt[ptindex] to null, but when I try to access this page, the system crashes.
That's why I have to put a virtual address with the present flag there.
mrjbom wrote:I am trying to unmapping a virtual page, as written in wiki, I set pt[ptindex] to null, but when I try to access this page, the system crashes.
What do you expect to happen when you try to access an address that you have unmapped? It's not crashing, it's Page Faulting; if this causes a crash this is a limitation of your operating system.
Oh, I guess I got the job logic wrong. I expected that if the PRESENT flag is not present, then trying to access the page will lead to access to the physical page and I will not have any problems.
Sorry, stupid question.
mrjbom wrote:Oh, I guess I got the job logic wrong. I expected that if the PRESENT flag is not present, then trying to access the page will lead to access to the physical page and I will not have any problems.
And which physical page did you expect to be accessed? How would the processor / MMU know which page to access?
mrjbom wrote:Oh, I guess I got the job logic wrong. I expected that if the PRESENT flag is not present, then trying to access the page will lead to access to the physical page and I will not have any problems.
And which physical page did you expect to be accessed? How would the processor / MMU know which page to access?
I think he was thinking that if the PTE for a given linear address has the present bit set, then the address is translated per the PTE, and if the present bit is not set, then no translation is performed and the linear address is used directly as a physical address.
@mrjbom:
The entire point of the present flag is to allow the OS to detect if a program has attempted to access memory that has not been assigned to it. When a program (or the OS itself) tries to access a page with the present flag unset, an interrupt fires and control is passed to the OS (as long as the OS has set up a handler for the page fault exception). The OS can then decide what action to take. If the program wasn't supposed to have access to that memory at all, the appropriate action is generally to terminate the program. If the program was supposed to have access to that memory, but the system had swapped that page to disk because there wasn't enough RAM, the appropriate action is to load that page back into RAM (potentially swapping something else out to make room, depending on whether the system is still low on memory). If the OS hasn't set up a page fault handler, then a double fault will result when the CPU attempts to do the page fault, and if a double fault handler hasn't been set up, then there will be a triple fault and the system will reboot.
The CPU can't access pages marked not present. If it could, that would be very bad indeed. You should read more about paging in the Intel manuals, and there is a (fairly) good tutorial here.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg