memspy/Driver/Kernel/Source/MemSpyDriverHeap.cpp
branchRCL_3
changeset 44 52e343bb8f80
parent 43 ca8a1b6995f6
child 49 7fdc9a71d314
equal deleted inserted replaced
43:ca8a1b6995f6 44:52e343bb8f80
    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 #include "heaputils.h"
    26 
    27 
    27 // Defines
       
    28 #define __NEXT_CELL(p)				((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+p->len))
       
    29 #define __NEXT_CELL2(p,l)			((RMemSpyDriverRHeapBase::SCell*)(((TUint8*)p)+l))
    28 
    30 
    29 
    31 
    30 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase()
    32 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase()
    31 	: iHelper(NULL)
       
    32     {
    33     {
    33     Reset();
    34     Reset();
    34     }
    35     }
    35 
    36 
    36 LtkUtils::RAllocatorHelper* RMemSpyDriverRHeapBase::Helper()
    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
    37 	{
    72 	{
    38 	return iHelper;
    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;
    39 	}
   105 	}
    40 
   106 
    41 TMemSpyHeapInfo::THeapImplementationType RMemSpyDriverRHeapBase::GetTypeFromHelper() const
   107 
    42 	{
   108 TInt RMemSpyDriverRHeapBase::AllocatedCellHeaderSize( TBool aDebugLibrary )
    43 	if (iHelper)
   109     {
    44 		{
   110     // Allocated cells are only 4 bytes in UREL, but 12 bytes in UDEB.
    45 		LtkUtils::RAllocatorHelper::TType type = iHelper->GetType();
   111     TInt size = sizeof(SCell*);
    46 		switch (type)
   112     //
    47 			{
   113     if  ( aDebugLibrary )
    48 			case LtkUtils::RAllocatorHelper::ETypeRHeap:
   114         {
    49 				return TMemSpyHeapInfo::ETypeRHeap;
   115         size = sizeof(SDebugCell);
    50 			case LtkUtils::RAllocatorHelper::ETypeRHybridHeap:
   116         }
    51 				return TMemSpyHeapInfo::ETypeRHybridHeap;
   117     //
    52 			case LtkUtils::RAllocatorHelper::ETypeUnknown:
   118     return size;
    53 			default:
   119     }
    54 				return TMemSpyHeapInfo::ETypeUnknown;
   120 
    55 			}
   121 
    56 		}
   122 TInt RMemSpyDriverRHeapBase::FreeCellHeaderSize()
    57 	return TMemSpyHeapInfo::ETypeUnknown;
   123     {
    58 	}
   124     // Free cells remain the same size in UREL and UDEB builds.
    59 
   125     const TInt size = sizeof(SCell);
    60 void RMemSpyDriverRHeapBase::Reset()
   126     return size; 
    61     {
   127     }
    62 	Close();
   128 
    63 	}
   129 
    64 
   130 TInt RMemSpyDriverRHeapBase::CellHeaderSize( const TMemSpyDriverInternalWalkHeapParamsCell& aCell, TBool aDebugLibrary )
    65 void RMemSpyDriverRHeapBase::Close()
   131     {
    66 	{
   132     TInt size = 0;
    67 	if (iHelper)
   133     //
    68 		{
   134     if  ( aCell.iCellType == EMemSpyDriverGoodAllocatedCell )
    69 	    NKern::ThreadEnterCS();
   135         {
    70 		iHelper->Close();
   136         size = AllocatedCellHeaderSize( aDebugLibrary );
    71 		delete iHelper;
   137         }
    72 		iHelper = NULL;
   138     else if ( aCell.iCellType == EMemSpyDriverGoodFreeCell ) 
    73 		NKern::ThreadLeaveCS();
   139         {
    74 		}
   140         size = FreeCellHeaderSize();
    75     }
   141         }
       
   142     //
       
   143     return size;
       
   144     }
       
   145 
    76 
   146 
    77 void RMemSpyDriverRHeapBase::PrintInfo()
   147 void RMemSpyDriverRHeapBase::PrintInfo()
    78     {
   148     {
    79 	/* TOMSCI TODO
       
    80 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
   149 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
    81     Kern::Printf(" " );
   150     Kern::Printf(" " );
    82     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
   151     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
    83     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
   152     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
    84     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
   153     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
   102     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   171     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   103     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   172     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   104     Kern::Printf(" " );
   173     Kern::Printf(" " );
   105     Kern::Printf(" " );
   174     Kern::Printf(" " );
   106 #endif
   175 #endif
   107 	*/
   176     }
   108     }
   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 
   109 
   237 
   110 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   238 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   111 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ) /*, iClientToKernelDelta( 0 )*/
   239 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ), iClientToKernelDelta( 0 )
   112     {
   240     {
   113     }
   241     }
   114 
   242 
   115 
   243 
   116 void RMemSpyDriverRHeapReadFromCopy::Reset()
   244 void RMemSpyDriverRHeapReadFromCopy::Reset()
   118     RMemSpyDriverRHeapBase::Reset();
   246     RMemSpyDriverRHeapBase::Reset();
   119 	//
   247 	//
   120     iChunk = NULL;
   248     iChunk = NULL;
   121     iChunkAddress = 0;
   249     iChunkAddress = 0;
   122     iChunkMappingAttributes = 0;
   250     iChunkMappingAttributes = 0;
   123     //iClientToKernelDelta = 0;
   251     iClientToKernelDelta = 0;
   124     }
   252     }
   125 
   253 
   126 
   254 
   127 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   255 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   128     {
   256     {
   133     iChunkMappingAttributes = aMappingAttributes;
   261     iChunkMappingAttributes = aMappingAttributes;
   134 
   262 
   135     // Calculate start of real heap data (skipping over embedded RHeap object)
   263     // Calculate start of real heap data (skipping over embedded RHeap object)
   136     // Since we must operate with kernel-side addressing into our cloned heap chunk,
   264     // Since we must operate with kernel-side addressing into our cloned heap chunk,
   137     // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase
   265     // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase
   138     //TOMSCI iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   266     iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   139 
   267 
   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) );
   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) );
   141     }
   269     }
   142 
   270 
   143 
   271 
   144 /*void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   272 void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   145     {
   273     {
   146     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   274     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   147 
   275 
   148     NKern::ThreadEnterCS();
   276     NKern::ThreadEnterCS();
   149     if  ( iChunk != NULL )
   277     if  ( iChunk != NULL )
   153         }
   281         }
   154     NKern::ThreadLeaveCS();
   282     NKern::ThreadLeaveCS();
   155 
   283 
   156     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   284     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   157     }
   285     }
   158 */
   286 
   159 
   287 
   160 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   288 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   161     {
   289     {
   162     return *iChunk;
   290     return *iChunk;
   163     }
   291     }
   167     {
   295     {
   168     return *iChunk;
   296     return *iChunk;
   169     }
   297     }
   170 
   298 
   171 
   299 
   172 /*TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   300 TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   173     {
   301     {
   174     return iChunkAddress;
   302     return iChunkAddress;
   175     }
   303     }
   176 
   304 
   177 
   305 
   178 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   306 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   179     {
   307     {
   180     return iChunk != NULL;
   308     return iChunk != NULL;
   181     }
   309     }
   182 
   310 
       
   311 
   183 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   312 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   184     {
   313     {
   185     return iClientToKernelDelta;
   314     return iClientToKernelDelta;
   186     }
   315     }
   187 */
   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 
   188 
   360 
   189 
   361 
   190 
   362 
   191 
   363 
   192 
   364 
   193 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   365 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   194 	: RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption)
   366 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   195     {
   367     {
   196     }
   368     }
   197 
   369 
   198 
   370 
   199 TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb)
   371 TInt RMemSpyDriverRHeapUser::ReadFromUserAllocator( DThread& aThread )
   200 	{
   372     {
   201 	TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread);
   373     TBuf8<KRHeapMemberDataSize> memberData;
   202 	NKern::ThreadEnterCS();
   374     memberData.SetMax();
   203 	LtkUtils::RKernelSideAllocatorHelper* helper = new LtkUtils::RKernelSideAllocatorHelper;
   375 
   204 	if (!helper)
   376     NKern::ThreadEnterCS();
   205 		{
   377     NKern::LockSystem();
   206 		NKern::ThreadLeaveCS();
   378     RAllocator* allocator = OSAdaption().DThread().GetAllocator( aThread );
   207 		return KErrNoMemory;
   379     NKern::UnlockSystem();
   208 		}
   380   	NKern::ThreadLeaveCS();
   209 	TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb);
   381 
   210 	if (!err)
   382     TUint8* memberDataAddress = (TUint8*) allocator + KRAllocatorAndRHeapMemberDataOffset;
   211 		{
   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 ) );
   212 		iChunk = helper->OpenUnderlyingChunk();
   384 
   213 		if (!iChunk) err = KErrNotFound;
   385     const TInt error = Kern::ThreadRawRead( &aThread, memberDataAddress, (TAny*) memberData.Ptr(), KRHeapMemberDataSize );
   214 		}
   386     TRACE_DATA( MemSpyDriverUtils::DataDump("%lS", memberData.Ptr(), KRHeapMemberDataSize, KRHeapMemberDataSize ) );
   215 	if (err)
   387 
   216 		{
   388     if  ( error == KErrNone )
   217 		delete helper;
   389         {
   218 		}
   390         TUint8* destinationAddress = reinterpret_cast< TUint8* >( this );
   219 	else
   391 
   220 		{
   392         // Skip over our vTable too...
   221 		iHelper = helper;
   393         destinationAddress += KRAllocatorAndRHeapMemberDataOffset;
   222 		}
   394 
   223 	NKern::ThreadLeaveCS();
   395         // Now copy data into this object
   224 	return err;
   396         TPtr8 self( destinationAddress, KRHeapMemberDataSize, KRHeapMemberDataSize );
   225 	}
   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 
   226 
   423 
   227 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   424 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   228 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   425 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   229     {
   426     {
   230     }
   427     }
   249 
   446 
   250     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   447     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   251     }
   448     }
   252 
   449 
   253 
   450 
   254 /*
       
   255 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   451 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   256     {
   452     {
   257     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   453     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   258     iKernelHeap = NULL;
   454     iKernelHeap = NULL;
   259     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   455     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   260     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   456     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   261     }
   457     }
   262 */
   458 
   263 
   459 
   264 void RMemSpyDriverRHeapKernelFromCopy::Close()
   460 void RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
   265 	{
   461     {
   266 	//TOMSCI TODO close the chunk
   462     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   267 	}
   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 
   268 
   498 
   269 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   499 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   270 	: iChunk(NULL)
   500 :   iKernelHeap( NULL ), iChunk( NULL )
   271     {
   501     {
   272     }
   502     }
   273 
   503 
   274 TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap()
   504 
   275 	{
   505 void RMemSpyDriverRHeapKernelInPlace::SetKernelHeap( RHeapK& aKernelHeap )
   276 	NKern::ThreadEnterCS();
   506     {
   277 	LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper;
   507     iKernelHeap = &aKernelHeap;
   278 	if (!helper)
   508     CopyMembersFromKernelHeap();
   279 		{
   509     }
   280 		NKern::ThreadLeaveCS();
   510 
   281 		return KErrNoMemory;
   511 
   282 		}
   512 void RMemSpyDriverRHeapKernelInPlace::FailNext()
   283 	TInt err = helper->OpenKernelHeap();
   513     {
   284 	if (!err)
   514 #ifndef __SYMBIAN_KERNEL_HYBRID_HEAP__
   285 		{
   515     RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* heap = reinterpret_cast< RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* >( iKernelHeap );
   286 		iChunk = helper->OpenUnderlyingChunk();
   516     heap->FailNext();
   287 		if (!iChunk) err = KErrNotFound;
   517 #endif
   288 		}
   518     }
   289 
   519 
   290 	if (err)
   520 
   291 		{
   521 void RMemSpyDriverRHeapKernelInPlace::Reset()
   292 		delete helper;
   522     {
   293 		}
   523     RMemSpyDriverRHeapBase::Reset();
   294 	else
   524 	//
   295 		{
   525     iChunk = NULL;
   296 		iHelper = helper;
   526     }
   297 		}
   527 
   298 	NKern::ThreadLeaveCS();
   528 
   299 	return err;
   529 void RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr /*aAddress*/, TUint32 /*aMappingAttributes*/ )
   300 	}
   530     {
   301 
   531     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x", aChunk, aChunk->iBase ) );
   302 void RMemSpyDriverRHeapKernelInPlace::Close()
   532     iChunk = aChunk;
   303     {
   533     }
   304 	NKern::ThreadEnterCS();
   534 
   305 	iChunk->Close(NULL);
   535 
   306 	iChunk = NULL;
   536 void RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk()
   307 	RMemSpyDriverRHeapBase::Close();
   537     {
   308 	NKern::ThreadLeaveCS();
   538     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ));
   309     }
   539     iChunk = NULL;
       
   540     iKernelHeap = NULL;
       
   541     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - END") );
       
   542     }
       
   543 
   310 
   544 
   311 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   545 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   312     {
   546     {
   313     return *iChunk;
   547     return *iChunk;
   314     }
   548     }
   317 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   551 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   318     {
   552     {
   319     return *iChunk;
   553     return *iChunk;
   320     }
   554     }
   321 
   555 
       
   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