memspy/Driver/Kernel/Source/MemSpyDriverHeap.cpp
branchRCL_3
changeset 20 ca8a1b6995f6
parent 18 3406c99bc375
child 21 52e343bb8f80
equal deleted inserted replaced
19:07b41fa8d1dd 20:ca8a1b6995f6
    21 #include <kern_priv.h>
    21 #include <kern_priv.h>
    22 
    22 
    23 // User includes
    23 // User includes
    24 #include "MemSpyDriverOSAdaption.h"
    24 #include "MemSpyDriverOSAdaption.h"
    25 #include "MemSpyDriverUtils.h"
    25 #include "MemSpyDriverUtils.h"
    26 
    26 #include "heaputils.h"
    27 // Defines
    27 
    28 #define __NEXT_CELL(p)				((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+p->len))
       
    29 #define __NEXT_CELL2(p,l)			((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+l))
       
    30 
    28 
    31 
    29 
    32 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase()
    30 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase()
       
    31 	: iHelper(NULL)
    33     {
    32     {
    34     Reset();
    33     Reset();
    35     }
    34     }
    36 
    35 
       
    36 LtkUtils::RAllocatorHelper* RMemSpyDriverRHeapBase::Helper()
       
    37 	{
       
    38 	return iHelper;
       
    39 	}
       
    40 
       
    41 TMemSpyHeapInfo::THeapImplementationType RMemSpyDriverRHeapBase::GetTypeFromHelper() const
       
    42 	{
       
    43 	if (iHelper)
       
    44 		{
       
    45 		LtkUtils::RAllocatorHelper::TType type = iHelper->GetType();
       
    46 		switch (type)
       
    47 			{
       
    48 			case LtkUtils::RAllocatorHelper::ETypeRHeap:
       
    49 				return TMemSpyHeapInfo::ETypeRHeap;
       
    50 			case LtkUtils::RAllocatorHelper::ETypeRHybridHeap:
       
    51 				return TMemSpyHeapInfo::ETypeRHybridHeap;
       
    52 			case LtkUtils::RAllocatorHelper::ETypeUnknown:
       
    53 			default:
       
    54 				return TMemSpyHeapInfo::ETypeUnknown;
       
    55 			}
       
    56 		}
       
    57 	return TMemSpyHeapInfo::ETypeUnknown;
       
    58 	}
    37 
    59 
    38 void RMemSpyDriverRHeapBase::Reset()
    60 void RMemSpyDriverRHeapBase::Reset()
    39     {
    61     {
    40 	iAccessCount = 0;
    62 	Close();
    41 	iHandleCount = 0;
    63 	}
    42 	iHandles = NULL;
    64 
    43 	iFlags = 0;
    65 void RMemSpyDriverRHeapBase::Close()
    44 	iCellCount = 0;
    66 	{
    45 	iTotalAllocSize = 0;
    67 	if (iHelper)
    46     
    68 		{
    47     iMinLength = 0;
    69 	    NKern::ThreadEnterCS();
    48 	iMaxLength = 0;
    70 		iHelper->Close();
    49 	iOffset = 0;
    71 		delete iHelper;
    50 	iGrowBy = 0;
    72 		iHelper = NULL;
    51 	iChunkHandle = 0;
    73 		NKern::ThreadLeaveCS();
    52 	// iLock needs no initialisation due to default ctor
    74 		}
    53 	iBase = NULL;
    75     }
    54 	iTop = NULL;
       
    55 	iAlign = 0;
       
    56 	iMinCell = 0;
       
    57 	iPageSize = 0;
       
    58 	iFree.len = 0;
       
    59 	iFree.next = NULL;
       
    60 	iNestingLevel = 0;
       
    61 	iAllocCount = 0;
       
    62     iFailType = RAllocator::EReset;
       
    63 	iFailRate = 0;
       
    64 	iFailed = EFalse;
       
    65 	iFailAllocCount = 0;
       
    66 	iRand = 0;
       
    67 	iTestData = NULL;
       
    68     }
       
    69 
       
    70 
       
    71 TBool RMemSpyDriverRHeapBase::CheckCell( TAny* aCellAddress, TInt aLength ) const
       
    72 	{
       
    73 	const TLinAddr m = TLinAddr(iAlign - 1);
       
    74     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CheckCell() - cell: 0x%08x, len: %8d, iAlign: %d, m: %d", aCellAddress, aLength, iAlign, m) );
       
    75 
       
    76     TBool isValid = ETrue;
       
    77     //
       
    78     if ( isValid && (aLength & m) )
       
    79         {
       
    80     	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CheckCell() - ERROR - length is odd: %d, iAlign: %d, m: %d", aLength, iAlign, m) );
       
    81         isValid = EFalse;
       
    82         }
       
    83     if ( isValid && aLength < iMinCell )
       
    84         {
       
    85     	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CheckCell() - ERROR - length: %d, is less than min cell size (%d)", aLength, iMinCell) );
       
    86         isValid = EFalse;
       
    87         }
       
    88     if ( isValid && (TUint8*)aCellAddress < iBase )
       
    89         {
       
    90     	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CheckCell() - ERROR - cell address: 0x%08x, is before start address: 0x%08x", (TUint8*) aCellAddress, iBase) );
       
    91         isValid = EFalse;
       
    92         }
       
    93 
       
    94     if  ( isValid )
       
    95         {
       
    96         const TUint8* nextCell = (TUint8*)__NEXT_CELL2(aCellAddress, aLength);
       
    97         if  ( nextCell > iTop )
       
    98             {
       
    99         	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CheckCell() - ERROR - nextCell: 0x%08x is after the top of the heap: 0x%08x", nextCell, iTop) );
       
   100             isValid = EFalse;
       
   101             }
       
   102         }
       
   103     //
       
   104     return isValid;
       
   105 	}
       
   106 
       
   107 
       
   108 TInt RMemSpyDriverRHeapBase::AllocatedCellHeaderSize( TBool aDebugLibrary )
       
   109     {
       
   110     // Allocated cells are only 4 bytes in UREL, but 12 bytes in UDEB.
       
   111     TInt size = sizeof(SCell*);
       
   112     //
       
   113     if  ( aDebugLibrary )
       
   114         {
       
   115         size = sizeof(SDebugCell);
       
   116         }
       
   117     //
       
   118     return size;
       
   119     }
       
   120 
       
   121 
       
   122 TInt RMemSpyDriverRHeapBase::FreeCellHeaderSize()
       
   123     {
       
   124     // Free cells remain the same size in UREL and UDEB builds.
       
   125     const TInt size = sizeof(SCell);
       
   126     return size; 
       
   127     }
       
   128 
       
   129 
       
   130 TInt RMemSpyDriverRHeapBase::CellHeaderSize( const TMemSpyDriverInternalWalkHeapParamsCell& aCell, TBool aDebugLibrary )
       
   131     {
       
   132     TInt size = 0;
       
   133     //
       
   134     if  ( aCell.iCellType == EMemSpyDriverGoodAllocatedCell )
       
   135         {
       
   136         size = AllocatedCellHeaderSize( aDebugLibrary );
       
   137         }
       
   138     else if ( aCell.iCellType == EMemSpyDriverGoodFreeCell ) 
       
   139         {
       
   140         size = FreeCellHeaderSize();
       
   141         }
       
   142     //
       
   143     return size;
       
   144     }
       
   145 
       
   146 
    76 
   147 void RMemSpyDriverRHeapBase::PrintInfo()
    77 void RMemSpyDriverRHeapBase::PrintInfo()
   148     {
    78     {
       
    79 	/* TOMSCI TODO
   149 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
    80 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
   150     Kern::Printf(" " );
    81     Kern::Printf(" " );
   151     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
    82     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
   152     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
    83     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
   153     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
    84     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
   171     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   102     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   172     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   103     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   173     Kern::Printf(" " );
   104     Kern::Printf(" " );
   174     Kern::Printf(" " );
   105     Kern::Printf(" " );
   175 #endif
   106 #endif
   176     }
   107 	*/
   177 
   108     }
   178 
       
   179 void RMemSpyDriverRHeapBase::CopyObjectDataTo( TMemSpyHeapObjectDataRHeap& aData )
       
   180     {
       
   181     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CopyObjectDataTo() - START" ) );
       
   182 
       
   183     TUint8* sourceAddress = reinterpret_cast< TUint8* >( this );
       
   184     sourceAddress += KRAllocatorAndRHeapMemberDataOffset;
       
   185     memcpy( &aData, sourceAddress, KRHeapObjectSize );
       
   186 
       
   187     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapBase::CopyObjectDataTo() - END") );
       
   188     }
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 
       
   197 
       
   198 
       
   199 
       
   200 
       
   201 
       
   202 
       
   203 
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 
       
   209 
       
   210 
       
   211 
       
   212 
       
   213 
       
   214 
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 
       
   229 
       
   230 
       
   231 
       
   232 
       
   233 
       
   234 
       
   235 
       
   236 
       
   237 
   109 
   238 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   110 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   239 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ), iClientToKernelDelta( 0 )
   111 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ) /*, iClientToKernelDelta( 0 )*/
   240     {
   112     {
   241     }
   113     }
   242 
   114 
   243 
   115 
   244 void RMemSpyDriverRHeapReadFromCopy::Reset()
   116 void RMemSpyDriverRHeapReadFromCopy::Reset()
   246     RMemSpyDriverRHeapBase::Reset();
   118     RMemSpyDriverRHeapBase::Reset();
   247 	//
   119 	//
   248     iChunk = NULL;
   120     iChunk = NULL;
   249     iChunkAddress = 0;
   121     iChunkAddress = 0;
   250     iChunkMappingAttributes = 0;
   122     iChunkMappingAttributes = 0;
   251     iClientToKernelDelta = 0;
   123     //iClientToKernelDelta = 0;
   252     }
   124     }
   253 
   125 
   254 
   126 
   255 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   127 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   256     {
   128     {
   261     iChunkMappingAttributes = aMappingAttributes;
   133     iChunkMappingAttributes = aMappingAttributes;
   262 
   134 
   263     // Calculate start of real heap data (skipping over embedded RHeap object)
   135     // Calculate start of real heap data (skipping over embedded RHeap object)
   264     // Since we must operate with kernel-side addressing into our cloned heap chunk,
   136     // Since we must operate with kernel-side addressing into our cloned heap chunk,
   265     // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase
   137     // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase
   266     iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   138     //TOMSCI iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   267 
   139 
   268     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk() - END - delta between client's user-side base address (base: 0x%08x), kernel-side base address (base: 0x%08x), and kernel-side chunk (base: 0x%08x) is: 0x%08x", Base(), aChunk->iBase, aAddress, iClientToKernelDelta) );
   140     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk() - END - delta between client's user-side base address (base: 0x%08x), kernel-side base address (base: 0x%08x), and kernel-side chunk (base: 0x%08x) is: 0x%08x", Base(), aChunk->iBase, aAddress, iClientToKernelDelta) );
   269     }
   141     }
   270 
   142 
   271 
   143 
   272 void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   144 /*void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   273     {
   145     {
   274     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   146     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   275 
   147 
   276     NKern::ThreadEnterCS();
   148     NKern::ThreadEnterCS();
   277     if  ( iChunk != NULL )
   149     if  ( iChunk != NULL )
   281         }
   153         }
   282     NKern::ThreadLeaveCS();
   154     NKern::ThreadLeaveCS();
   283 
   155 
   284     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   156     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   285     }
   157     }
   286 
   158 */
   287 
   159 
   288 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   160 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   289     {
   161     {
   290     return *iChunk;
   162     return *iChunk;
   291     }
   163     }
   295     {
   167     {
   296     return *iChunk;
   168     return *iChunk;
   297     }
   169     }
   298 
   170 
   299 
   171 
   300 TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   172 /*TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   301     {
   173     {
   302     return iChunkAddress;
   174     return iChunkAddress;
   303     }
   175     }
   304 
   176 
   305 
   177 
   306 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   178 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   307     {
   179     {
   308     return iChunk != NULL;
   180     return iChunk != NULL;
   309     }
   181     }
   310 
   182 
   311 
       
   312 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   183 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   313     {
   184     {
   314     return iClientToKernelDelta;
   185     return iClientToKernelDelta;
   315     }
   186     }
   316 
   187 */
   317 
       
   318 
       
   319 
       
   320 
       
   321 
       
   322 
       
   323 
       
   324 
       
   325 
       
   326 
       
   327 
       
   328 
       
   329 
       
   330 
       
   331 
       
   332 
       
   333 
       
   334 
       
   335 
       
   336 
       
   337 
       
   338 
       
   339 
       
   340 
       
   341 
       
   342 
       
   343 
       
   344 
       
   345 
       
   346 
       
   347 
       
   348 
       
   349 
       
   350 
       
   351 
       
   352 
       
   353 
       
   354 
       
   355 
       
   356 
       
   357 
       
   358 
       
   359 
       
   360 
   188 
   361 
   189 
   362 
   190 
   363 
   191 
   364 
   192 
   365 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   193 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   366 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   194 	: RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption)
   367     {
   195     {
   368     }
   196     }
   369 
   197 
   370 
   198 
   371 TInt RMemSpyDriverRHeapUser::ReadFromUserAllocator( DThread& aThread )
   199 TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb)
   372     {
   200 	{
   373     TBuf8<KRHeapMemberDataSize> memberData;
   201 	TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread);
   374     memberData.SetMax();
   202 	NKern::ThreadEnterCS();
   375 
   203 	LtkUtils::RKernelSideAllocatorHelper* helper = new LtkUtils::RKernelSideAllocatorHelper;
   376     NKern::ThreadEnterCS();
   204 	if (!helper)
   377     NKern::LockSystem();
   205 		{
   378     RAllocator* allocator = OSAdaption().DThread().GetAllocator( aThread );
   206 		NKern::ThreadLeaveCS();
   379     NKern::UnlockSystem();
   207 		return KErrNoMemory;
   380   	NKern::ThreadLeaveCS();
   208 		}
   381 
   209 	TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb);
   382     TUint8* memberDataAddress = (TUint8*) allocator + KRAllocatorAndRHeapMemberDataOffset;
   210 	if (!err)
   383 	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapUser::ReadFromUserAllocator() - START - allocator addr: 0x%08x, therefore going to read %d bytes from address 0x%08x within client thread (0x%08x + %4d bytes)", allocator, KRHeapMemberDataSize, memberDataAddress, allocator, KRAllocatorAndRHeapMemberDataOffset ) );
   211 		{
   384 
   212 		iChunk = helper->OpenUnderlyingChunk();
   385     const TInt error = Kern::ThreadRawRead( &aThread, memberDataAddress, (TAny*) memberData.Ptr(), KRHeapMemberDataSize );
   213 		if (!iChunk) err = KErrNotFound;
   386     TRACE_DATA( MemSpyDriverUtils::DataDump("%lS", memberData.Ptr(), KRHeapMemberDataSize, KRHeapMemberDataSize ) );
   214 		}
   387 
   215 	if (err)
   388     if  ( error == KErrNone )
   216 		{
   389         {
   217 		delete helper;
   390         TUint8* destinationAddress = reinterpret_cast< TUint8* >( this );
   218 		}
   391 
   219 	else
   392         // Skip over our vTable too...
   220 		{
   393         destinationAddress += KRAllocatorAndRHeapMemberDataOffset;
   221 		iHelper = helper;
   394 
   222 		}
   395         // Now copy data into this object
   223 	NKern::ThreadLeaveCS();
   396         TPtr8 self( destinationAddress, KRHeapMemberDataSize, KRHeapMemberDataSize );
   224 	return err;
   397         self.Copy( memberData );
   225 	}
   398 
       
   399         PrintInfo();
       
   400         }
       
   401     else
       
   402         {
       
   403         }
       
   404 
       
   405 	TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapUser::ReadFromUserAllocator() - END - read error: %d", error ) );
       
   406     return error;
       
   407     }
       
   408 
       
   409 
       
   410 
       
   411 
       
   412 
       
   413 
       
   414 
       
   415 
       
   416 
       
   417 
       
   418 
       
   419 
       
   420 
       
   421 
       
   422 
       
   423 
   226 
   424 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   227 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   425 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   228 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   426     {
   229     {
   427     }
   230     }
   446 
   249 
   447     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   250     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   448     }
   251     }
   449 
   252 
   450 
   253 
       
   254 /*
   451 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   255 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   452     {
   256     {
   453     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   257     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   454     iKernelHeap = NULL;
   258     iKernelHeap = NULL;
   455     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   259     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   456     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   260     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   457     }
   261     }
   458 
   262 */
   459 
   263 
   460 void RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
   264 void RMemSpyDriverRHeapKernelFromCopy::Close()
   461     {
   265 	{
   462     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   266 	//TOMSCI TODO close the chunk
   463     //
   267 	}
   464     if  ( iKernelHeap )
       
   465         {
       
   466         const TUint32* pHeap = reinterpret_cast< TUint32* >( iKernelHeap );
       
   467         //
       
   468         TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
   469         TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
       
   470         rHeapMetaData.SetVTable( *pHeap );
       
   471         rHeapMetaData.SetClassSize( KRHeapObjectSize );
       
   472         //
       
   473         TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - RHeapK vtable is: 0x%08x", *pHeap ));
       
   474         }
       
   475     //
       
   476     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - END") );
       
   477     }
       
   478 
       
   479 
       
   480 
       
   481 
       
   482 
       
   483 
       
   484 
       
   485 
       
   486 
       
   487 
       
   488 
       
   489 
       
   490 
       
   491 
       
   492 
       
   493 
       
   494 
       
   495 
       
   496 
       
   497 
       
   498 
   268 
   499 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   269 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   500 :   iKernelHeap( NULL ), iChunk( NULL )
   270 	: iChunk(NULL)
   501     {
   271     {
   502     }
   272     }
   503 
   273 
   504 
   274 TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap()
   505 void RMemSpyDriverRHeapKernelInPlace::SetKernelHeap( RHeapK& aKernelHeap )
   275 	{
   506     {
   276 	NKern::ThreadEnterCS();
   507     iKernelHeap = &aKernelHeap;
   277 	LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper;
   508     CopyMembersFromKernelHeap();
   278 	if (!helper)
   509     }
   279 		{
   510 
   280 		NKern::ThreadLeaveCS();
   511 
   281 		return KErrNoMemory;
   512 void RMemSpyDriverRHeapKernelInPlace::FailNext()
   282 		}
   513     {
   283 	TInt err = helper->OpenKernelHeap();
   514 #ifndef __SYMBIAN_KERNEL_HYBRID_HEAP__
   284 	if (!err)
   515     RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* heap = reinterpret_cast< RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* >( iKernelHeap );
   285 		{
   516     heap->FailNext();
   286 		iChunk = helper->OpenUnderlyingChunk();
   517 #endif
   287 		if (!iChunk) err = KErrNotFound;
   518     }
   288 		}
   519 
   289 
   520 
   290 	if (err)
   521 void RMemSpyDriverRHeapKernelInPlace::Reset()
   291 		{
   522     {
   292 		delete helper;
   523     RMemSpyDriverRHeapBase::Reset();
   293 		}
   524 	//
   294 	else
   525     iChunk = NULL;
   295 		{
   526     }
   296 		iHelper = helper;
   527 
   297 		}
   528 
   298 	NKern::ThreadLeaveCS();
   529 void RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr /*aAddress*/, TUint32 /*aMappingAttributes*/ )
   299 	return err;
   530     {
   300 	}
   531     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x", aChunk, aChunk->iBase ) );
   301 
   532     iChunk = aChunk;
   302 void RMemSpyDriverRHeapKernelInPlace::Close()
   533     }
   303     {
   534 
   304 	NKern::ThreadEnterCS();
   535 
   305 	iChunk->Close(NULL);
   536 void RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk()
   306 	iChunk = NULL;
   537     {
   307 	RMemSpyDriverRHeapBase::Close();
   538     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ));
   308 	NKern::ThreadLeaveCS();
   539     iChunk = NULL;
   309     }
   540     iKernelHeap = NULL;
       
   541     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - END") );
       
   542     }
       
   543 
       
   544 
   310 
   545 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   311 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   546     {
   312     {
   547     return *iChunk;
   313     return *iChunk;
   548     }
   314     }
   551 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   317 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   552     {
   318     {
   553     return *iChunk;
   319     return *iChunk;
   554     }
   320     }
   555 
   321 
   556 
       
   557 TLinAddr RMemSpyDriverRHeapKernelInPlace::ChunkKernelAddress() const
       
   558     {
       
   559     const TLinAddr ret = reinterpret_cast< TLinAddr >( iChunk->iBase );
       
   560     return ret;
       
   561     }
       
   562 
       
   563 
       
   564 TBool RMemSpyDriverRHeapKernelInPlace::ChunkIsInitialised() const
       
   565     {
       
   566     return iChunk != NULL;
       
   567     }
       
   568 
       
   569 
       
   570 TUint RMemSpyDriverRHeapKernelInPlace::ClientToKernelDelta() const
       
   571     {
       
   572     // We're operating in kernel address space, there is no delta.
       
   573     return 0;
       
   574     }
       
   575 
       
   576 
       
   577 void RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap()
       
   578     {
       
   579     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap() - START" ) );
       
   580 
       
   581     // Perform a copy operation in order to populate base class with a duplicate of the kernel's heap info.
       
   582     RHeapK* kernelHeap = iKernelHeap;
       
   583 
       
   584     // Source address
       
   585     TUint8* sourceAddress = (TUint8*) kernelHeap + KRAllocatorAndRHeapMemberDataOffset;
       
   586     TUint8* destinationAddress = (TUint8*) this + KRAllocatorAndRHeapMemberDataOffset;
       
   587 
       
   588     // Copy 
       
   589     memcpy( destinationAddress, sourceAddress, KRHeapMemberDataSize );
       
   590 
       
   591     // And print info in debug builds for verification...
       
   592     PrintInfo();
       
   593 
       
   594     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap() - END" ) );
       
   595     }
       
   596 
       
   597 
       
   598 void RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
       
   599     {
       
   600     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
       
   601     //
       
   602     if  ( iKernelHeap )
       
   603         {
       
   604         const TUint32* pHeap = reinterpret_cast< TUint32* >( iKernelHeap );
       
   605         //
       
   606         TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
   607         TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
       
   608         rHeapMetaData.SetVTable( *pHeap );
       
   609         rHeapMetaData.SetClassSize( KRHeapObjectSize );
       
   610         //
       
   611         TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - RHeapK vtable is: 0x%08x", *pHeap ));
       
   612         }
       
   613     //
       
   614     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - END") );
       
   615     }
       
   616 
       
   617 
       
   618 
       
   619 
       
   620