OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 2:23 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Paging on the x86: My Mapping Isn't Working!
PostPosted: Sat Aug 29, 2009 4:19 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Hi everyone!

I've been stuck for a while trying to figure out why some code I have isn't working. The basic idea of things is that we get a page fault when trying to read a MemoryMappedFile. This traps, and ideally the relevant section of the file would be read into memory. This works well, but I've run into a roadblock now that makes little sense. There's a deterministic error that occurs on the second application load. execve() wipes all previous (non-anonymous) memory mapped files from memory, so there's a set of unmappings performed in the address space. These pages are now free to allocate, so the new application gets given the old application's region (it's smaller).

This is all well and good. The read traps, and the mapping function gets called. This detects two things: first, the page table isn't present (and allocates it), and then that the page to be mapped isn't present (so maps it). Normally this works flawlessly, but in this one case, no amount of TLB flushes, flag manipulation or checks can actually get the page mapped - I will always get a page fault.

My biggest problem is that this only occurs on my Windows development environment: nobody else on the team has this problem, and I don't see it if I use a Linux virtual machine as a host. Yet it will do it on Bochs and QEMU, without fail.

Any ideas?

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: Paging on the x86: My Mapping Isn't Working!
PostPosted: Sun Aug 30, 2009 12:56 am 
Offline
Member
Member

Joined: Wed Jul 25, 2007 8:45 am
Posts: 391
Location: London, UK
In your x86 paging code, you have page tables permanently mapped in (by pointing a PDE to the page directory). In X86VirtualAddressSpace::revertToKernelAddressSpace, you clear out old pages and page tables, however when you clear the page directory entry to remove a page table, you don't invalidate the TLB entry for the virtual address that maps that page table in, so later if a new page table is mapped in, the TLB entry for the virtual page table address may still point to the old page table that was mapped there.

Seeing this makes it seem pretty certain that this is the problem:
Code:
/// \note I'm now getting a page fault during execve (MemoryMappedFile::trap) that occurs only
///       when these lines are kept in. I've left them here because they're correct. - Matt
// PhysicalMemoryManager::instance().freePage(PAGE_GET_PHYSICAL_ADDRESS(pageDirectoryEntry));
// *pageDirectoryEntry = 0;

_________________
http://alex-smith.me.uk


Top
 Profile  
 
 Post subject: Re: Paging on the x86: My Mapping Isn't Working!
PostPosted: Sun Aug 30, 2009 5:12 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
That's the problem, thanks AlexExtreme!

I guess that's what happens when you look at a problem for too long - you begin missing the blatantly obvious answers :(

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 154 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group