memspy/Driver/Kernel/Source/MemSpyDriverHeap.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
    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 replace with tracing based on latest struct info. See DMemSpyDriverLogChanHeapBase::PrintHeapInfo
       
    80 	 * Alternatively just call DMemSpyDriverLogChanHeapBase::PrintHeapInfo() somehow?
       
    81 	 
       
    82 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
   149 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
    83     Kern::Printf(" " );
   150     Kern::Printf(" " );
    84     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
   151     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount:    0x%08x", iAccessCount );
    85     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
   152     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount:    0x%08x", iHandleCount );
    86     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
   153     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles:        0x%08x", iHandles );
   104     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   171     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      iAllocCount:     0x%08x", iAllocCount);
   105     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   172     Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap -      size:              %8d",  Size() );
   106     Kern::Printf(" " );
   173     Kern::Printf(" " );
   107     Kern::Printf(" " );
   174     Kern::Printf(" " );
   108 #endif
   175 #endif
   109 	*/
   176     }
   110     }
   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 
   111 
   237 
   112 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   238 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   113 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ) /*, iClientToKernelDelta( 0 )*/
   239 :   iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ), iClientToKernelDelta( 0 )
   114     {
   240     {
   115     }
   241     }
   116 
   242 
   117 
   243 
   118 void RMemSpyDriverRHeapReadFromCopy::Reset()
   244 void RMemSpyDriverRHeapReadFromCopy::Reset()
   120     RMemSpyDriverRHeapBase::Reset();
   246     RMemSpyDriverRHeapBase::Reset();
   121 	//
   247 	//
   122     iChunk = NULL;
   248     iChunk = NULL;
   123     iChunkAddress = 0;
   249     iChunkAddress = 0;
   124     iChunkMappingAttributes = 0;
   250     iChunkMappingAttributes = 0;
   125     //iClientToKernelDelta = 0;
   251     iClientToKernelDelta = 0;
   126     }
   252     }
   127 
   253 
   128 
   254 
   129 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   255 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes )
   130     {
   256     {
   135     iChunkMappingAttributes = aMappingAttributes;
   261     iChunkMappingAttributes = aMappingAttributes;
   136 
   262 
   137     // Calculate start of real heap data (skipping over embedded RHeap object)
   263     // Calculate start of real heap data (skipping over embedded RHeap object)
   138     // 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,
   139     // 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
   140     //TOMSCI iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   266     iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize );
   141 
   267 
   142     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) );
   143     }
   269     }
   144 
   270 
   145 
   271 
   146 /*void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   272 void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk()
   147     {
   273     {
   148     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   274     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) );
   149 
   275 
   150     NKern::ThreadEnterCS();
   276     NKern::ThreadEnterCS();
   151     if  ( iChunk != NULL )
   277     if  ( iChunk != NULL )
   155         }
   281         }
   156     NKern::ThreadLeaveCS();
   282     NKern::ThreadLeaveCS();
   157 
   283 
   158     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   284     TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") );
   159     }
   285     }
   160 */
   286 
   161 
   287 
   162 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   288 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk()
   163     {
   289     {
   164     return *iChunk;
   290     return *iChunk;
   165     }
   291     }
   169     {
   295     {
   170     return *iChunk;
   296     return *iChunk;
   171     }
   297     }
   172 
   298 
   173 
   299 
   174 /*TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   300 TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const
   175     {
   301     {
   176     return iChunkAddress;
   302     return iChunkAddress;
   177     }
   303     }
   178 
   304 
   179 
   305 
   180 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   306 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const
   181     {
   307     {
   182     return iChunk != NULL;
   308     return iChunk != NULL;
   183     }
   309     }
   184 
   310 
       
   311 
   185 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   312 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const
   186     {
   313     {
   187     return iClientToKernelDelta;
   314     return iClientToKernelDelta;
   188     }
   315     }
   189 */
   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 
   190 
   360 
   191 
   361 
   192 
   362 
   193 
   363 
   194 
   364 
   195 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   365 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
   196 	: RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption)
   366 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   197     {
   367     {
   198     }
   368     }
   199 
   369 
   200 
   370 
   201 TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb)
   371 TInt RMemSpyDriverRHeapUser::ReadFromUserAllocator( DThread& aThread )
   202 	{
   372     {
   203 	TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread);
   373     TBuf8<KRHeapMemberDataSize> memberData;
   204 	NKern::ThreadEnterCS();
   374     memberData.SetMax();
   205 	LtkUtils::RKernelSideAllocatorHelper* helper = new LtkUtils::RKernelSideAllocatorHelper;
   375 
   206 	if (!helper)
   376     NKern::ThreadEnterCS();
   207 		{
   377     NKern::LockSystem();
   208 		NKern::ThreadLeaveCS();
   378     RAllocator* allocator = OSAdaption().DThread().GetAllocator( aThread );
   209 		return KErrNoMemory;
   379     NKern::UnlockSystem();
   210 		}
   380   	NKern::ThreadLeaveCS();
   211 	TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb);
   381 
   212 	if (!err)
   382     TUint8* memberDataAddress = (TUint8*) allocator + KRAllocatorAndRHeapMemberDataOffset;
   213 		{
   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 ) );
   214 		iChunk = helper->OpenUnderlyingChunk();
   384 
   215 		if (!iChunk) err = KErrNotFound;
   385     const TInt error = Kern::ThreadRawRead( &aThread, memberDataAddress, (TAny*) memberData.Ptr(), KRHeapMemberDataSize );
   216 		}
   386     TRACE_DATA( MemSpyDriverUtils::DataDump("%lS", memberData.Ptr(), KRHeapMemberDataSize, KRHeapMemberDataSize ) );
   217 	if (err)
   387 
   218 		{
   388     if  ( error == KErrNone )
   219 		delete helper;
   389         {
   220 		}
   390         TUint8* destinationAddress = reinterpret_cast< TUint8* >( this );
   221 	else
   391 
   222 		{
   392         // Skip over our vTable too...
   223 		iHelper = helper;
   393         destinationAddress += KRAllocatorAndRHeapMemberDataOffset;
   224 		}
   394 
   225 	NKern::ThreadLeaveCS();
   395         // Now copy data into this object
   226 	return err;
   396         TPtr8 self( destinationAddress, KRHeapMemberDataSize, KRHeapMemberDataSize );
   227 	}
   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 
   228 
   423 
   229 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   424 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
   230 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   425 :   RMemSpyDriverRHeapReadFromCopy( aOSAdaption )
   231     {
   426     {
   232     }
   427     }
   251 
   446 
   252     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   447     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) );
   253     }
   448     }
   254 
   449 
   255 
   450 
   256 /*
       
   257 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   451 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk()
   258     {
   452     {
   259     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   453     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   260     iKernelHeap = NULL;
   454     iKernelHeap = NULL;
   261     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   455     RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk();
   262     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   456     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") );
   263     }
   457     }
   264 */
   458 
   265 
   459 
   266 void RMemSpyDriverRHeapKernelFromCopy::Close()
   460 void RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const
   267 	{
   461     {
   268 	//TOMSCI TODO close the chunk
   462     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::GetHeapSpecificInfo() - START - iKernelHeap: 0x%08x", iKernelHeap ));
   269 	}
   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 
   270 
   498 
   271 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   499 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace()
   272 	: iChunk(NULL)
   500 :   iKernelHeap( NULL ), iChunk( NULL )
   273     {
   501     {
   274     }
   502     }
   275 
   503 
   276 TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap()
   504 
   277 	{
   505 void RMemSpyDriverRHeapKernelInPlace::SetKernelHeap( RHeapK& aKernelHeap )
   278 	NKern::ThreadEnterCS();
   506     {
   279 	LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper;
   507     iKernelHeap = &aKernelHeap;
   280 	if (!helper)
   508     CopyMembersFromKernelHeap();
   281 		{
   509     }
   282 		NKern::ThreadLeaveCS();
   510 
   283 		return KErrNoMemory;
   511 
   284 		}
   512 void RMemSpyDriverRHeapKernelInPlace::FailNext()
   285 	TInt err = helper->OpenKernelHeap();
   513     {
   286 	if (!err)
   514 #ifndef __SYMBIAN_KERNEL_HYBRID_HEAP__
   287 		{
   515     RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* heap = reinterpret_cast< RMemSpyDriverRHeapKernelInPlace::RHeapKExtended* >( iKernelHeap );
   288 		iChunk = helper->OpenUnderlyingChunk();
   516     heap->FailNext();
   289 		if (!iChunk) err = KErrNotFound;
   517 #endif
   290 		}
   518     }
   291 
   519 
   292 	if (err)
   520 
   293 		{
   521 void RMemSpyDriverRHeapKernelInPlace::Reset()
   294 		delete helper;
   522     {
   295 		}
   523     RMemSpyDriverRHeapBase::Reset();
   296 	else
   524 	//
   297 		{
   525     iChunk = NULL;
   298 		iHelper = helper;
   526     }
   299 		}
   527 
   300 	NKern::ThreadLeaveCS();
   528 
   301 	return err;
   529 void RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr /*aAddress*/, TUint32 /*aMappingAttributes*/ )
   302 	}
   530     {
   303 
   531     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x", aChunk, aChunk->iBase ) );
   304 void RMemSpyDriverRHeapKernelInPlace::Close()
   532     iChunk = aChunk;
   305     {
   533     }
   306 	NKern::ThreadEnterCS();
   534 
   307 	iChunk->Close(NULL);
   535 
   308 	iChunk = NULL;
   536 void RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk()
   309 	RMemSpyDriverRHeapBase::Close();
   537     {
   310 	NKern::ThreadLeaveCS();
   538     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ));
   311     }
   539     iChunk = NULL;
       
   540     iKernelHeap = NULL;
       
   541     TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelInPlace::DisassociateWithKernelChunk() - END") );
       
   542     }
       
   543 
   312 
   544 
   313 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   545 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
   314     {
   546     {
   315     return *iChunk;
   547     return *iChunk;
   316     }
   548     }
   319 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   551 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
   320     {
   552     {
   321     return *iChunk;
   553     return *iChunk;
   322     }
   554     }
   323 
   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