kernel/eka/memmodel/epoc/flexible/mmu/mobject.cpp
changeset 90 947f0dc9f7a8
parent 33 0173bcd7697c
child 176 af6ec97d9189
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mobject.cpp	Tue Feb 02 01:24:03 2010 +0200
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mobject.cpp	Fri Apr 16 16:24:37 2010 +0300
@@ -506,9 +506,17 @@
 	if(self)
 		{
 		new (self) DPageTables(aMemory,numPts,aPteType);
+		// Add this page tables object to the memory object before we update any 
+		// page table entries. To ensure that if any of aMemory's pages with 
+		// corresponding page table entries in self are moved during Construct(), 
+		// DCoarseMemory::RemapPage() will be able to find the page table entries 
+		// to update via iPageTables.
+		__NK_ASSERT_DEBUG(!aMemory->iPageTables[aPteType]);
+		aMemory->iPageTables[aPteType] = self;
 		TInt r = self->Construct();
 		if(r!=KErrNone)
 			{
+			aMemory->iPageTables[aPteType] = 0;
 			self->Close();
 			self = 0;
 			}
@@ -579,7 +587,16 @@
 
 void DCoarseMemory::DPageTables::AsyncClose()
 	{
-	__NK_ASSERT_DEBUG(CheckAsyncCloseIsSafe());
+	__ASSERT_CRITICAL
+#ifdef _DEBUG
+	NFastMutex* fm = NKern::HeldFastMutex();
+	if(fm)
+		{
+		Kern::Printf("DCoarseMemory::DPageTables::[0x%08x]::AsyncClose() fast mutex violation %M",this,fm);
+		__NK_ASSERT_DEBUG(0);
+		}
+#endif
+
 	MmuLock::Lock();
 	if (__e32_atomic_tas_ord32(&iReferenceCount, 1, -1, 0) != 1)
 		{
@@ -1689,11 +1706,6 @@
 		{
 		// allocate a new one if required...
 		tables = DPageTables::New(this, iSizeInPages, aPteType);
-		if (tables)
-			{
-			__NK_ASSERT_DEBUG(!iPageTables[aPteType]);
-			iPageTables[aPteType] = tables;
-			}
 		}		
 
 	return tables;