kernel/eka/memmodel/epoc/flexible/mmu/mobject.cpp
changeset 90 947f0dc9f7a8
parent 33 0173bcd7697c
child 176 af6ec97d9189
equal deleted inserted replaced
52:2d65c2f76d7b 90:947f0dc9f7a8
   504 	TUint numPts = aNumPages>>(KChunkShift-KPageShift);
   504 	TUint numPts = aNumPages>>(KChunkShift-KPageShift);
   505 	DPageTables* self = (DPageTables*)Kern::AllocZ(sizeof(DPageTables)+(numPts-1)*sizeof(TPte*));
   505 	DPageTables* self = (DPageTables*)Kern::AllocZ(sizeof(DPageTables)+(numPts-1)*sizeof(TPte*));
   506 	if(self)
   506 	if(self)
   507 		{
   507 		{
   508 		new (self) DPageTables(aMemory,numPts,aPteType);
   508 		new (self) DPageTables(aMemory,numPts,aPteType);
       
   509 		// Add this page tables object to the memory object before we update any 
       
   510 		// page table entries. To ensure that if any of aMemory's pages with 
       
   511 		// corresponding page table entries in self are moved during Construct(), 
       
   512 		// DCoarseMemory::RemapPage() will be able to find the page table entries 
       
   513 		// to update via iPageTables.
       
   514 		__NK_ASSERT_DEBUG(!aMemory->iPageTables[aPteType]);
       
   515 		aMemory->iPageTables[aPteType] = self;
   509 		TInt r = self->Construct();
   516 		TInt r = self->Construct();
   510 		if(r!=KErrNone)
   517 		if(r!=KErrNone)
   511 			{
   518 			{
       
   519 			aMemory->iPageTables[aPteType] = 0;
   512 			self->Close();
   520 			self->Close();
   513 			self = 0;
   521 			self = 0;
   514 			}
   522 			}
   515 		}
   523 		}
   516 	TRACE2(("DCoarseMemory::DPageTables::New(0x%08x,0x%x,0x%08x) returns 0x%08x",aMemory, aNumPages, aPteType, self));
   524 	TRACE2(("DCoarseMemory::DPageTables::New(0x%08x,0x%x,0x%08x) returns 0x%08x",aMemory, aNumPages, aPteType, self));
   577 	}
   585 	}
   578 
   586 
   579 
   587 
   580 void DCoarseMemory::DPageTables::AsyncClose()
   588 void DCoarseMemory::DPageTables::AsyncClose()
   581 	{
   589 	{
   582 	__NK_ASSERT_DEBUG(CheckAsyncCloseIsSafe());
   590 	__ASSERT_CRITICAL
       
   591 #ifdef _DEBUG
       
   592 	NFastMutex* fm = NKern::HeldFastMutex();
       
   593 	if(fm)
       
   594 		{
       
   595 		Kern::Printf("DCoarseMemory::DPageTables::[0x%08x]::AsyncClose() fast mutex violation %M",this,fm);
       
   596 		__NK_ASSERT_DEBUG(0);
       
   597 		}
       
   598 #endif
       
   599 
   583 	MmuLock::Lock();
   600 	MmuLock::Lock();
   584 	if (__e32_atomic_tas_ord32(&iReferenceCount, 1, -1, 0) != 1)
   601 	if (__e32_atomic_tas_ord32(&iReferenceCount, 1, -1, 0) != 1)
   585 		{
   602 		{
   586 		MmuLock::Unlock();
   603 		MmuLock::Unlock();
   587 		return;
   604 		return;
  1687 
  1704 
  1688 	if(!tables)
  1705 	if(!tables)
  1689 		{
  1706 		{
  1690 		// allocate a new one if required...
  1707 		// allocate a new one if required...
  1691 		tables = DPageTables::New(this, iSizeInPages, aPteType);
  1708 		tables = DPageTables::New(this, iSizeInPages, aPteType);
  1692 		if (tables)
       
  1693 			{
       
  1694 			__NK_ASSERT_DEBUG(!iPageTables[aPteType]);
       
  1695 			iPageTables[aPteType] = tables;
       
  1696 			}
       
  1697 		}		
  1709 		}		
  1698 
  1710 
  1699 	return tables;
  1711 	return tables;
  1700 	}
  1712 	}
  1701 
  1713