memspy/Driver/Kernel/Source/MemSpyDriverHeap.cpp
changeset 0 a03f92240627
child 15 ccab7f1f8266
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MemSpyDriverHeap.h"
       
    19 
       
    20 // System includes
       
    21 #include <kern_priv.h>
       
    22 
       
    23 // User includes
       
    24 #include "MemSpyDriverOSAdaption.h"
       
    25 #include "MemSpyDriverUtils.h"
       
    26 
       
    27 // Defines
       
    28 #define __NEXT_CELL(p)				((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+p->len))
       
    29 #define __NEXT_CELL2(p,l)			((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+l))
       
    30 
       
    31 
       
    32 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase()
       
    33     {
       
    34     Reset();
       
    35     }
       
    36 
       
    37 
       
    38 void RMemSpyDriverRHeapBase::Reset()
       
    39     {
       
    40 	iAccessCount = 0;
       
    41 	iHandleCount = 0;
       
    42 	iHandles = NULL;
       
    43 	iFlags = 0;
       
    44 	iCellCount = 0;
       
    45 	iTotalAllocSize = 0;
       
    46     
       
    47     iMinLength = 0;
       
    48 	iMaxLength = 0;
       
    49 	iOffset = 0;
       
    50 	iGrowBy = 0;
       
    51 	iChunkHandle = 0;
       
    52 	// iLock needs no initialisation due to default ctor
       
    53 	iBase = NULL;
       
    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 
       
   147 void RMemSpyDriverRHeapBase::PrintInfo()
       
   148     {
       
   149 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
       
   150     Kern::Printf(" " );
       
   151     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
       
   152     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
       
   153     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
       
   154     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iFlags:          0x%08x", iFlags );
       
   155     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iCellCount:      0x%08x", iCellCount );
       
   156     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iTotalAllocSize: 0x%08x", iTotalAllocSize );
       
   157 
       
   158     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iMinLength:      0x%08x", iMinLength );
       
   159     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iMaxLength:      0x%08x", iMaxLength );
       
   160     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iOffset:         0x%08x", iOffset);
       
   161     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iGrowBy:         0x%08x", iGrowBy);
       
   162     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iChunkHandle:    0x%08x", iChunkHandle);
       
   163     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iBase:           0x%08x", Base());
       
   164     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iTop:            0x%08x", iTop );
       
   165     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAlign:          0x%08x", iAlign);
       
   166     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iMinCell:        0x%08x", iMinCell);
       
   167     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iPageSize:       0x%08x", iPageSize);
       
   168     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iFree len:       0x%08x", iFree.len);
       
   169     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iFree next:      0x%08x", iFree.next);
       
   170     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iNestingLevel:   0x%08x", iNestingLevel);
       
   171     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
       
   172     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
       
   173     Kern::Printf(" " );
       
   174     Kern::Printf(" " );
       
   175 #endif
       
   176     }
       
   177 
       
   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 
       
   238 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
       
   239 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ), iClientToKernelDelta( 0 )
       
   240     {
       
   241     }
       
   242 
       
   243 
       
   244 void RMemSpyDriverRHeapReadFromCopy::Reset()
       
   245     {
       
   246     RMemSpyDriverRHeapBase::Reset();
       
   247 	//
       
   248     iChunk = NULL;
       
   249     iChunkAddress = 0;
       
   250     iChunkMappingAttributes = 0;
       
   251     iClientToKernelDelta = 0;
       
   252     }
       
   253 
       
   254 
       
   255 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
       
   256     {
       
   257     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x, aAddress: 0x%08x, clients heap base: 0x%08x, aChunk size: %8d", aChunk, aChunk->iBase, aAddress, Base(), aChunk->iSize ) );
       
   258 
       
   259     iChunk = aChunk;
       
   260     iChunkAddress = aAddress;
       
   261     iChunkMappingAttributes = aMappingAttributes;
       
   262 
       
   263     // 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,
       
   265     // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase
       
   266     iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
       
   267 
       
   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) );
       
   269     }
       
   270 
       
   271 
       
   272 void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
       
   273     {
       
   274     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
       
   275 
       
   276     NKern::ThreadEnterCS();
       
   277     if  ( iChunk != NULL )
       
   278         {
       
   279         Kern::ChunkClose( iChunk );
       
   280         iChunk = NULL;
       
   281         }
       
   282     NKern::ThreadLeaveCS();
       
   283 
       
   284     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
       
   285     }
       
   286 
       
   287 
       
   288 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
       
   289     {
       
   290     return *iChunk;
       
   291     }
       
   292 
       
   293 
       
   294 const DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk() const
       
   295     {
       
   296     return *iChunk;
       
   297     }
       
   298 
       
   299 
       
   300 TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
       
   301     {
       
   302     return iChunkAddress;
       
   303     }
       
   304 
       
   305 
       
   306 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
       
   307     {
       
   308     return iChunk != NULL;
       
   309     }
       
   310 
       
   311 
       
   312 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
       
   313     {
       
   314     return iClientToKernelDelta;
       
   315     }
       
   316 
       
   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 
       
   361 
       
   362 
       
   363 
       
   364 
       
   365 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
       
   366 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
       
   367     {
       
   368     }
       
   369 
       
   370 
       
   371 TInt RMemSpyDriverRHeapUser::ReadFromUserAllocator( DThread& aThread )
       
   372     {
       
   373     TBuf8<KRHeapMemberDataSize> memberData;
       
   374     memberData.SetMax();
       
   375 
       
   376     NKern::ThreadEnterCS();
       
   377     NKern::LockSystem();
       
   378     RAllocator* allocator = OSAdaption().DThread().GetAllocator( aThread );
       
   379     NKern::UnlockSystem();
       
   380   	NKern::ThreadLeaveCS();
       
   381 
       
   382     TUint8* memberDataAddress = (TUint8*) allocator + KRAllocatorAndRHeapMemberDataOffset;
       
   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 ) );
       
   384 
       
   385     const TInt error = Kern::ThreadRawRead( &aThread, memberDataAddress, (TAny*) memberData.Ptr(), KRHeapMemberDataSize );
       
   386     TRACE_DATA( MemSpyDriverUtils::DataDump("%lS", memberData.Ptr(), KRHeapMemberDataSize, KRHeapMemberDataSize ) );
       
   387 
       
   388     if  ( error == KErrNone )
       
   389         {
       
   390         TUint8* destinationAddress = reinterpret_cast< TUint8* >( this );
       
   391 
       
   392         // Skip over our vTable too...
       
   393         destinationAddress += KRAllocatorAndRHeapMemberDataOffset;
       
   394 
       
   395         // Now copy data into this object
       
   396         TPtr8 self( destinationAddress, KRHeapMemberDataSize, KRHeapMemberDataSize );
       
   397         self.Copy( memberData );
       
   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 
       
   424 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
       
   425 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
       
   426     {
       
   427     }
       
   428 
       
   429 
       
   430 void RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap( RHeapK& aKernelHeap )
       
   431     {
       
   432     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - START" ) );
       
   433 
       
   434     // Perform a copy operation in order to populate base class with a duplicate of the kernel's heap info.
       
   435     iKernelHeap = &aKernelHeap;
       
   436 
       
   437     // Source address
       
   438     TUint8* sourceAddress = (TUint8*) iKernelHeap + KRAllocatorAndRHeapMemberDataOffset;
       
   439     TUint8* destinationAddress = (TUint8*) this + KRAllocatorAndRHeapMemberDataOffset;
       
   440 
       
   441     // Copy 
       
   442     memcpy( destinationAddress, sourceAddress, KRHeapMemberDataSize );
       
   443 
       
   444     // And print info in debug builds for verification...
       
   445     PrintInfo();
       
   446 
       
   447     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
       
   448     }
       
   449 
       
   450 
       
   451 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
       
   452     {
       
   453     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
       
   454     iKernelHeap = NULL;
       
   455     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
       
   456     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
       
   457     }
       
   458 
       
   459 
       
   460 void RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
       
   461     {
       
   462     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
       
   463     //
       
   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 
       
   499 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
       
   500 :   iKernelHeap( NULL ), iChunk( NULL )
       
   501     {
       
   502     }
       
   503 
       
   504 
       
   505 void RMemSpyDriverRHeapKernelInPlace::SetKernelHeap( RHeapK& aKernelHeap )
       
   506     {
       
   507     iKernelHeap = &aKernelHeap;
       
   508     CopyMembersFromKernelHeap();
       
   509     }
       
   510 
       
   511 
       
   512 void RMemSpyDriverRHeapKernelInPlace::FailNext()
       
   513     {
       
   514     RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* heap = reinterpret_cast< RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* >( iKernelHeap );
       
   515     heap->FailNext();
       
   516     }
       
   517 
       
   518 
       
   519 void RMemSpyDriverRHeapKernelInPlace::Reset()
       
   520     {
       
   521     RMemSpyDriverRHeapBase::Reset();
       
   522 	//
       
   523     iChunk = NULL;
       
   524     }
       
   525 
       
   526 
       
   527 void RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr /*aAddress*/, TUint32 /*aMappingAttributes*/ )
       
   528     {
       
   529     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x", aChunk, aChunk->iBase ) );
       
   530     iChunk = aChunk;
       
   531     }
       
   532 
       
   533 
       
   534 void RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk()
       
   535     {
       
   536     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ));
       
   537     iChunk = NULL;
       
   538     iKernelHeap = NULL;
       
   539     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - END") );
       
   540     }
       
   541 
       
   542 
       
   543 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
       
   544     {
       
   545     return *iChunk;
       
   546     }
       
   547 
       
   548 
       
   549 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
       
   550     {
       
   551     return *iChunk;
       
   552     }
       
   553 
       
   554 
       
   555 TLinAddr RMemSpyDriverRHeapKernelInPlace::ChunkKernelAddress() const
       
   556     {
       
   557     const TLinAddr ret = reinterpret_cast< TLinAddr >( iChunk->iBase );
       
   558     return ret;
       
   559     }
       
   560 
       
   561 
       
   562 TBool RMemSpyDriverRHeapKernelInPlace::ChunkIsInitialised() const
       
   563     {
       
   564     return iChunk != NULL;
       
   565     }
       
   566 
       
   567 
       
   568 TUint RMemSpyDriverRHeapKernelInPlace::ClientToKernelDelta() const
       
   569     {
       
   570     // We're operating in kernel address space, there is no delta.
       
   571     return 0;
       
   572     }
       
   573 
       
   574 
       
   575 void RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap()
       
   576     {
       
   577     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap() - START" ) );
       
   578 
       
   579     // Perform a copy operation in order to populate base class with a duplicate of the kernel's heap info.
       
   580     RHeapK* kernelHeap = iKernelHeap;
       
   581 
       
   582     // Source address
       
   583     TUint8* sourceAddress = (TUint8*) kernelHeap + KRAllocatorAndRHeapMemberDataOffset;
       
   584     TUint8* destinationAddress = (TUint8*) this + KRAllocatorAndRHeapMemberDataOffset;
       
   585 
       
   586     // Copy 
       
   587     memcpy( destinationAddress, sourceAddress, KRHeapMemberDataSize );
       
   588 
       
   589     // And print info in debug builds for verification...
       
   590     PrintInfo();
       
   591 
       
   592     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::CopyMembersFromKernelHeap() - END" ) );
       
   593     }
       
   594 
       
   595 
       
   596 void RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
       
   597     {
       
   598     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
       
   599     //
       
   600     if  ( iKernelHeap )
       
   601         {
       
   602         const TUint32* pHeap = reinterpret_cast< TUint32* >( iKernelHeap );
       
   603         //
       
   604         TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
   605         TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
       
   606         rHeapMetaData.SetVTable( *pHeap );
       
   607         rHeapMetaData.SetClassSize( KRHeapObjectSize );
       
   608         //
       
   609         TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - RHeapK vtable is: 0x%08x", *pHeap ));
       
   610         }
       
   611     //
       
   612     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::GetHeapSpecificInfo() - END") );
       
   613     }
       
   614 
       
   615 
       
   616 
       
   617 
       
   618