memspy/Driver/User/Source/MemSpyDriverClient.cpp
changeset 0 a03f92240627
child 20 ca8a1b6995f6
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 <memspy/driver/memspydriverclient.h>
       
    19 
       
    20 // System includes
       
    21 #include <e32svr.h>
       
    22 
       
    23 // User includes
       
    24 #include "MemSpyDriverOpCodes.h"
       
    25 #include "RBuildQueryableHeap.h"
       
    26 #include <memspy/driver/memspydriverconstants.h>
       
    27 #include <memspy/driver/memspydriverobjectsshared.h>
       
    28 #include "MemSpyDriverStreamReaderImp.h"
       
    29 #include "MemSpyDriverObjectsInternal.h"
       
    30 
       
    31 // Constants
       
    32 const TInt KMemSpyClientBufferGrowSize = 0x1000 * 8; // 32kb
       
    33 
       
    34 // Forward declarations
       
    35 static void PrintHeapInfo( const TMemSpyHeapInfo& aInfo );
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 EXPORT_C TInt RMemSpyDriverClient::Open()
       
    41 	{
       
    42     TInt err = iBuffer.Create( KMemSpyClientBufferGrowSize );
       
    43     if  ( err == KErrNone )
       
    44         {
       
    45         err = User::LoadLogicalDevice( KMemSpyDriverDeviceName );
       
    46         if  ( err == KErrNone || err == KErrAlreadyExists )
       
    47 		    {
       
    48 		    err = DoCreate( KMemSpyDriverDeviceName, KMemSpyDriverVersion(), KNullUnit, NULL, NULL, EOwnerThread );
       
    49             if  ( err == KErrNone )
       
    50                 {
       
    51                 TUint heapVTable = RHeapVTable();
       
    52  	            err = DoControl( EMemSpyDriverOpCodeMiscSetRHeapVTable, (TAny*) heapVTable );
       
    53                 }
       
    54 		    }
       
    55         }
       
    56     //
       
    57     if ( err != KErrNone )
       
    58         {
       
    59         RDebug::Printf( "[MemSpy] RMemSpyDriverClient::Open() - END - err: %d", err );
       
    60         }
       
    61     //
       
    62 	return err;
       
    63 	}
       
    64 
       
    65 
       
    66 
       
    67 EXPORT_C void RMemSpyDriverClient::Close()
       
    68 	{
       
    69     RBusLogicalChannel::Close();
       
    70     const TInt err = User::FreeLogicalDevice( KMemSpyDriverDeviceName );
       
    71     //
       
    72     if ( err != KErrNone )
       
    73         {
       
    74         RDebug::Printf( "[MemSpy] RMemSpyDriverClient::Close() - free logical device error: %d", err );
       
    75         }
       
    76     //
       
    77     iBuffer.Close();
       
    78     (void) err;
       
    79 	}
       
    80 
       
    81 
       
    82 EXPORT_C void RMemSpyDriverClient::GetVersion( TVersion& aVersion )
       
    83     {
       
    84     TVersion v = KMemSpyDriverVersion();
       
    85     Mem::Copy( (TAny*)&aVersion, (TAny*)&v, sizeof( TVersion ) );
       
    86     }
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 
       
    93 
       
    94 
       
    95 
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 
       
   105 
       
   106 EXPORT_C TInt RMemSpyDriverClient::ReadMemory( TUint aTid, TLinAddr aSrc, TDes8& aDest )
       
   107 	{
       
   108 	TMemSpyDriverInternalReadMemParams params;
       
   109 	params.iTid = aTid;
       
   110 	params.iAddr = aSrc;
       
   111 	params.iDes = &aDest;
       
   112     aDest.Zero();
       
   113     //
       
   114 	TInt r = DoControl( EMemSpyDriverOpCodeRawMemoryRead, &params, NULL );
       
   115     if  ( r >= KErrNone )
       
   116         {
       
   117         aDest.SetLength( r );
       
   118         r = KErrNone;
       
   119         }
       
   120     //
       
   121     return r;
       
   122     }
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 
       
   133 
       
   134 
       
   135 
       
   136 
       
   137 EXPORT_C TInt RMemSpyDriverClient::GetCodeSegs( TAny** aHandleArray, TInt& aHandleCount, TBool aOnlyRamLoaded )
       
   138     {
       
   139 	TMemSpyDriverInternalCodeSnapshotParams params;
       
   140 	params.iFilter = aOnlyRamLoaded;
       
   141 	params.iHandles = aHandleArray;
       
   142 	params.iCountPtr = &aHandleCount;
       
   143 	params.iMaxCount = aHandleCount;
       
   144     //
       
   145     aHandleCount = 0;
       
   146     //
       
   147 	return DoControl( EMemSpyDriverOpCodeCodeSegsGetAll, &params, NULL );
       
   148     }
       
   149 
       
   150 
       
   151 EXPORT_C TInt RMemSpyDriverClient::GetCodeSegs( TUint aPid, TAny** aHandleArray, TInt& aHandleCount )
       
   152 	{
       
   153 	TMemSpyDriverInternalCodeSnapshotParams params;
       
   154 	params.iFilter = aPid;
       
   155 	params.iHandles = aHandleArray;
       
   156 	params.iCountPtr = &aHandleCount;
       
   157 	params.iMaxCount = aHandleCount;
       
   158     //
       
   159     aHandleCount = 0;
       
   160     //
       
   161 	return DoControl( EMemSpyDriverOpCodeCodeSegsGetCodeSegsForProcess, &params, NULL );
       
   162 	}
       
   163 
       
   164 
       
   165 EXPORT_C TInt RMemSpyDriverClient::GetCodeSegInfo( TAny* aHandle, TUint aPid, TMemSpyDriverCodeSegInfo& aInfo )
       
   166 	{
       
   167 	TMemSpyDriverInternalCodeSegParams params;
       
   168 	params.iPid = aPid;
       
   169 	params.iHandle = aHandle;
       
   170 	params.iInfoPointer = &aInfo;
       
   171     //
       
   172 	const TInt r = DoControl( EMemSpyDriverOpCodeCodeSegsGetCodeSegInfo, &params, NULL );
       
   173 	return r;
       
   174 	}
       
   175 
       
   176 
       
   177 
       
   178 
       
   179 
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 
       
   197 
       
   198 
       
   199 
       
   200 
       
   201 
       
   202 EXPORT_C TInt RMemSpyDriverClient::GetChunkHandles( TAny** aHandleArray, TInt& aHandleCount )
       
   203     {
       
   204 	TMemSpyDriverInternalChunkHandleParams params;
       
   205 	params.iId = 0;
       
   206 	params.iType = EMemSpyDriverPrivateObjectTypeAll;
       
   207 	params.iHandles = aHandleArray;
       
   208 	params.iCountPtr = &aHandleCount;
       
   209     params.iMaxCount = aHandleCount;
       
   210     //
       
   211     aHandleCount = 0;
       
   212 	//
       
   213 	const TInt err = DoControl( EMemSpyDriverOpCodeChunkGetHandles, &params, NULL );
       
   214     return err;
       
   215     }
       
   216 
       
   217 
       
   218 EXPORT_C TInt RMemSpyDriverClient::GetChunkInfo( TAny* aHandle, TMemSpyDriverChunkInfo& aInfo )
       
   219     {
       
   220 	TMemSpyDriverInternalChunkInfoParams params;
       
   221 	TBuf8<KMaxFullName> name;
       
   222 	params.iHandle = aHandle;
       
   223 	const TInt r = DoControl( EMemSpyDriverOpCodeChunkGetInfo, &params, NULL );
       
   224 	//
       
   225 	if  ( r == KErrNone )
       
   226 		{
       
   227         aInfo.iHandle = aHandle;
       
   228 		aInfo.iBaseAddress = params.iBaseAddress;
       
   229 		aInfo.iSize = params.iSize;
       
   230 		aInfo.iMaxSize = params.iMaxSize;
       
   231 		aInfo.iOwnerId = params.iOwnerId;
       
   232         aInfo.iType = params.iType;
       
   233         aInfo.iAttributes = params.iAttributes;
       
   234 		aInfo.iName.Copy( params.iName );
       
   235 		}
       
   236 	//
       
   237 	return r;
       
   238     }
       
   239 
       
   240 
       
   241 EXPORT_C TInt RMemSpyDriverClient::GetChunkInfo( TAny* aHandle, TMemSpyDriverChunkInfoWithoutName& aInfo )
       
   242     {
       
   243     TMemSpyDriverChunkInfo info;
       
   244     //
       
   245     const TInt r = GetChunkInfo( aHandle, info );
       
   246     if  ( r == KErrNone )
       
   247         {
       
   248         aInfo = info;
       
   249         }
       
   250     //
       
   251     return r;
       
   252     }
       
   253 
       
   254 
       
   255 EXPORT_C TInt RMemSpyDriverClient::GetChunkHandlesForProcess( TUint aPid, TAny** aHandleArray, TInt& aHandleCount )
       
   256     {
       
   257 	TMemSpyDriverInternalChunkHandleParams params;
       
   258 	params.iId = aPid;
       
   259 	params.iType = EMemSpyDriverPrivateObjectTypeProcess;
       
   260 	params.iHandles = aHandleArray;
       
   261 	params.iCountPtr = &aHandleCount;
       
   262 	params.iMaxCount = aHandleCount;
       
   263 	//
       
   264     aHandleCount = 0;
       
   265     //
       
   266 	return DoControl( EMemSpyDriverOpCodeChunkGetHandles, &params, NULL );
       
   267     }
       
   268 
       
   269 
       
   270 EXPORT_C TInt RMemSpyDriverClient::GetChunkHandlesForThread( TUint aTid, TAny** aHandleArray, TInt& aHandleCount )
       
   271     {
       
   272 	TMemSpyDriverInternalChunkHandleParams params;
       
   273 	params.iId = aTid;
       
   274 	params.iType = EMemSpyDriverPrivateObjectTypeThread;
       
   275 	params.iHandles = aHandleArray;
       
   276 	params.iCountPtr = &aHandleCount;
       
   277 	params.iMaxCount = aHandleCount;
       
   278 	//
       
   279     aHandleCount = 0;
       
   280     //
       
   281 	return DoControl( EMemSpyDriverOpCodeChunkGetHandles, &params, NULL );
       
   282     }
       
   283 
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 
       
   290 
       
   291 
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 
       
   302 
       
   303 
       
   304 EXPORT_C TInt RMemSpyDriverClient::GetThreadInfo( TUint aTid, TMemSpyDriverThreadInfo& aInfo )
       
   305 	{
       
   306 	TMemSpyDriverInternalThreadInfoParams params;
       
   307     params.iRHeapVTable = RHeapVTable();
       
   308     params.iDebugAllocator = DebugEUser();
       
   309     //
       
   310 	TInt r = DoControl( EMemSpyDriverOpCodeThreadAndProcessGetInfoThread, (TAny*)aTid, &params);
       
   311 	//
       
   312 	if  ( r == KErrNone )
       
   313 		{
       
   314         // Copy common properties
       
   315         Mem::Copy( &aInfo, &params, sizeof( TMemSpyDriverThreadInfoBase ) );
       
   316 
       
   317         // Copy name
       
   318         aInfo.iFullName.Copy( params.iFullName );
       
   319 
       
   320         // Get other basic properties via RThread
       
   321         RThread thread;
       
   322         r = OpenThread( aTid, thread );
       
   323         if ( r == KErrNone )
       
   324             {
       
   325             RProcess process;
       
   326             r = thread.Process( process );
       
   327             if ( r == KErrNone )
       
   328                 {
       
   329 	            aInfo.iPid = process.Id();
       
   330                 process.Close();
       
   331                 }
       
   332 
       
   333             aInfo.iThreadPriority = thread.Priority();
       
   334             aInfo.iExitReason = thread.ExitReason();
       
   335             aInfo.iExitType = thread.ExitType();
       
   336             aInfo.iExitCategory = thread.ExitCategory();
       
   337 
       
   338             thread.Close();
       
   339             }
       
   340         }
       
   341 
       
   342     return r;
       
   343 	}
       
   344 
       
   345 EXPORT_C TInt RMemSpyDriverClient::GetProcessInfo( TUint aPid, TMemSpyDriverProcessInfo& aInfo )
       
   346     {
       
   347 	TInt r = DoControl( EMemSpyDriverOpCodeThreadAndProcessGetInfoProcess, (TAny*)aPid, &aInfo);
       
   348     
       
   349     // Get other properties via RProcess.
       
   350     if  ( r == KErrNone )
       
   351         {
       
   352         RProcess process;
       
   353         r = OpenProcess( aPid, process );
       
   354         if  ( r == KErrNone )
       
   355             {
       
   356             aInfo.iUids = process.Type();
       
   357             aInfo.iPriority = process.Priority();
       
   358             //
       
   359             process.Close();
       
   360             }
       
   361         }
       
   362 
       
   363     return r;
       
   364     }
       
   365 
       
   366 
       
   367 EXPORT_C TInt RMemSpyDriverClient::ProcessThreadsSuspend( TUint aPid )
       
   368     {
       
   369 	return DoControl( EMemSpyDriverOpCodeThreadAndProcessSuspendAllThreads, (TAny*) aPid, NULL );
       
   370     }
       
   371 
       
   372 
       
   373 EXPORT_C TInt RMemSpyDriverClient::ProcessThreadsResume( TUint aPid )
       
   374     {
       
   375 	return DoControl( EMemSpyDriverOpCodeThreadAndProcessResumeAllThreads, (TAny*) aPid, NULL );
       
   376     }
       
   377 
       
   378 
       
   379 EXPORT_C TInt RMemSpyDriverClient::ThreadEnd( TUint aId, TExitType aType )
       
   380     {
       
   381     TInt err = KErrNone;
       
   382     //
       
   383     if  ( aType == EExitPending )
       
   384         {
       
   385         err = KErrArgument;
       
   386         }
       
   387     else
       
   388         {
       
   389         err = DoControl( EMemSpyDriverOpCodeThreadAndProcessEndThread, (TAny*) aId, (TAny*) aType );
       
   390         }
       
   391     //
       
   392     return err;
       
   393     }
       
   394 
       
   395 
       
   396 EXPORT_C TInt RMemSpyDriverClient::OpenThread( TUint aId, RThread& aThread )
       
   397     {
       
   398     TInt ret = KErrNone;
       
   399     aThread.Close();
       
   400     //
       
   401     const TInt err = DoControl( EMemSpyDriverOpCodeThreadAndProcessOpenThread, (TAny*) aId );
       
   402     if  ( err > 0 )
       
   403         {
       
   404         aThread.SetHandle( err );
       
   405         ret = KErrNone;
       
   406         }
       
   407     else
       
   408         {
       
   409         ret = err;
       
   410         }
       
   411     //
       
   412     return ret;
       
   413     }
       
   414 
       
   415 
       
   416 EXPORT_C TInt RMemSpyDriverClient::OpenProcess( TUint aId, RProcess& aProcess )
       
   417     {
       
   418     TInt ret = KErrNone;
       
   419     aProcess.Close();
       
   420     //
       
   421     const TInt err = DoControl( EMemSpyDriverOpCodeThreadAndProcessOpenProcess, (TAny*) aId );
       
   422     if  ( err > 0 )
       
   423         {
       
   424         aProcess.SetHandle( err );
       
   425         ret = KErrNone;
       
   426         }
       
   427     else
       
   428         {
       
   429         ret = err;
       
   430         }
       
   431     //
       
   432     return ret;
       
   433     }
       
   434 
       
   435 
       
   436 EXPORT_C void RMemSpyDriverClient::GetThreadsL( const TProcessId& aId, RArray<TThreadId>& aThreads )
       
   437     {
       
   438 	aThreads.Reset();
       
   439     //
       
   440     ResetStreamBuffer();
       
   441     const TInt err = DoControl( EMemSpyDriverOpCodeThreadAndProcessGetThreads, (TAny*) (TUint) aId, (TAny*) &iBuffer );
       
   442     User::LeaveIfError( err );
       
   443 
       
   444     // Open stream
       
   445     RMemSpyMemStreamReader stream = StreamOpenL();
       
   446     CleanupClosePushL( stream );
       
   447         
       
   448     // Extract thread ids
       
   449     const TInt threadCount = stream.ReadInt32L();
       
   450     for( TInt i=0; i<threadCount; i++ )
       
   451         {
       
   452         const TThreadId id( stream.ReadUint32L() );
       
   453         aThreads.AppendL( id );
       
   454         }
       
   455         
       
   456     // Tidy up
       
   457     CleanupStack::PopAndDestroy( &stream );
       
   458     }
       
   459 
       
   460 
       
   461 EXPORT_C TInt RMemSpyDriverClient::SetPriority( TUint aId, TThreadPriority aPriority )
       
   462     {
       
   463     // The kernel side API to set thread priority expects a value in the range of 0-63, i.e. an absolute
       
   464     // NThread priority. In order to support process-relative thread priorities, we'd need to duplicate
       
   465     // the kernel priority mapping tables - not a good idea - therefore we'll only support absolute values.
       
   466     TInt err = KErrNone;
       
   467     if  ( aPriority < EPriorityAbsoluteVeryLow )
       
   468         {
       
   469         err = KErrArgument;
       
   470         }
       
   471     else
       
   472         {
       
   473         err = DoControl( EMemSpyDriverOpCodeThreadAndProcessSetPriorityThread, (TAny*) aId, (TAny*) aPriority );
       
   474         }
       
   475     //
       
   476     return err;
       
   477     }
       
   478 
       
   479 
       
   480 
       
   481 
       
   482 
       
   483 
       
   484 
       
   485 
       
   486 
       
   487 
       
   488 
       
   489 
       
   490 
       
   491 
       
   492 
       
   493 EXPORT_C TInt RMemSpyDriverClient::GetHeapInfoUser( TMemSpyHeapInfo& aInfo, TUint aTid )
       
   494     {
       
   495     TMemSpyDriverInternalHeapRequestParameters params;
       
   496     //
       
   497     params.iTid = aTid;
       
   498     params.iRHeapVTable = RHeapVTable();
       
   499     params.iDebugAllocator = DebugEUser();
       
   500     params.iMasterInfo = &aInfo;
       
   501     //
       
   502 	TInt r = DoControl( EMemSpyDriverOpCodeHeapInfoGetUser, &params, NULL );
       
   503 	//
       
   504 	if  ( r == KErrNone )
       
   505     	{
       
   506         PrintHeapInfo( aInfo );
       
   507         
       
   508         // Need to do this on the user-side
       
   509         if  ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
       
   510             {
       
   511             TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
   512             TMemSpyHeapMetaDataRHeap& metaData = rHeapInfo.MetaData();
       
   513             metaData.SetVTable( RHeapVTable() );
       
   514             metaData.SetClassSize( sizeof( RHeap ) );
       
   515             }
       
   516         }
       
   517     else if ( r == KErrNotSupported )
       
   518         {
       
   519         aInfo.SetType( TMemSpyHeapInfo::ETypeUnknown );
       
   520         r = KErrNone;
       
   521         }
       
   522 	//
       
   523 	return r;
       
   524     }
       
   525 
       
   526 
       
   527 EXPORT_C TInt RMemSpyDriverClient::GetHeapInfoUser( TMemSpyHeapInfo& aInfo, TUint aTid, RArray< TMemSpyDriverFreeCell >& aFreeCells )
       
   528     {
       
   529     TMemSpyDriverInternalHeapRequestParameters params;
       
   530     //
       
   531     params.iTid = aTid;
       
   532     params.iRHeapVTable = RHeapVTable();
       
   533     params.iDebugAllocator = DebugEUser();
       
   534     params.iMasterInfo = &aInfo;
       
   535     params.iBuildFreeCellList = ETrue;
       
   536     //
       
   537     aFreeCells.Reset();
       
   538     ResetStreamBuffer();
       
   539 	TInt r = DoControl( EMemSpyDriverOpCodeHeapInfoGetUser, &params );
       
   540 	//
       
   541 	if  ( r >= KErrNone )
       
   542     	{
       
   543         PrintHeapInfo( aInfo );
       
   544         
       
   545         // Need to do this on the user-side
       
   546         if  ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
       
   547             {
       
   548             TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
   549             TMemSpyHeapMetaDataRHeap& metaData = rHeapInfo.MetaData();
       
   550             metaData.SetVTable( RHeapVTable() );
       
   551             metaData.SetClassSize( sizeof( RHeap ) );
       
   552             }
       
   553 
       
   554         // Resize transfer buffer to make room for free cells. We only make the buffer
       
   555         // bigger, not smaller.
       
   556         if  ( iBuffer.Size() < r )
       
   557             {
       
   558             r = iBuffer.ReAlloc( r );
       
   559             }
       
   560     
       
   561         // Now fetch the heap data
       
   562         if  ( r == KErrNone )
       
   563             {
       
   564             r = DoControl( EMemSpyDriverOpCodeHeapInfoFetchFreeCells, &iBuffer );
       
   565             if  ( r == KErrNone )
       
   566                 {
       
   567                 TRAP( r, ReadHeapInfoFreeCellsFromXferBufferL( aFreeCells ) );
       
   568                 }
       
   569             }
       
   570         }
       
   571     else if ( r == KErrNotSupported )
       
   572         {
       
   573         aInfo.SetType( TMemSpyHeapInfo::ETypeUnknown );
       
   574         r = KErrNone;
       
   575         }
       
   576 	//
       
   577 	return r;
       
   578     }
       
   579 
       
   580 
       
   581 EXPORT_C TInt RMemSpyDriverClient::GetHeapInfoKernel( TMemSpyHeapInfo& aInfo )
       
   582     {
       
   583     TMemSpyDriverInternalHeapRequestParameters params;
       
   584     params.iTid = KMemSpyDriverGetKernelHeapDataPseudoThreadId;
       
   585     params.iRHeapVTable = NULL;
       
   586     params.iMasterInfo = &aInfo;
       
   587 	TInt r = DoControl( EMemSpyDriverOpCodeHeapInfoGetKernel, &params, NULL );
       
   588 	//
       
   589 	if  ( r == KErrNone )
       
   590     	{
       
   591         PrintHeapInfo( aInfo );
       
   592         }
       
   593     else if ( r == KErrNotSupported )
       
   594         {
       
   595         aInfo.SetType( TMemSpyHeapInfo::ETypeUnknown );
       
   596         r = KErrNone;
       
   597         }
       
   598 	//
       
   599 	return r;
       
   600     }
       
   601 
       
   602 
       
   603 EXPORT_C TInt RMemSpyDriverClient::GetHeapInfoKernel( TMemSpyHeapInfo& aInfo, RArray< TMemSpyDriverFreeCell >& aFreeCells )
       
   604     {
       
   605     TMemSpyDriverInternalHeapRequestParameters params;
       
   606     params.iTid = KMemSpyDriverGetKernelHeapDataPseudoThreadId;
       
   607     params.iRHeapVTable = NULL;
       
   608     params.iMasterInfo = &aInfo;
       
   609     //
       
   610     aFreeCells.Reset();
       
   611     ResetStreamBuffer();
       
   612 	TInt r = DoControl( EMemSpyDriverOpCodeHeapInfoGetKernel, &params, (TAny*) &iBuffer );
       
   613 	//
       
   614 	if  ( r == KErrNone )
       
   615     	{
       
   616         PrintHeapInfo( aInfo );
       
   617         TRAP( r, ReadHeapInfoFreeCellsFromXferBufferL( aFreeCells ) );
       
   618         }
       
   619     else if ( r == KErrNotSupported )
       
   620         {
       
   621         aInfo.SetType( TMemSpyHeapInfo::ETypeUnknown );
       
   622         r = KErrNone;
       
   623         }
       
   624 	//
       
   625 	return r;
       
   626     }
       
   627 
       
   628 
       
   629 EXPORT_C TBool RMemSpyDriverClient::IsDebugKernel()
       
   630     {
       
   631     TBool isDebugKernel = EFalse;
       
   632     DoControl( EMemSpyDriverOpCodeHeapInfoGetIsDebugKernel, (TAny*) &isDebugKernel );
       
   633     return isDebugKernel;
       
   634     }
       
   635 
       
   636 
       
   637 
       
   638 
       
   639 
       
   640 
       
   641 
       
   642 
       
   643 
       
   644 
       
   645 
       
   646 
       
   647 
       
   648 
       
   649 
       
   650 
       
   651 
       
   652 
       
   653 
       
   654 
       
   655 
       
   656 
       
   657 EXPORT_C TInt RMemSpyDriverClient::GetHeapData( TUint aTid, TUint32 aFreeCellChecksum, TDes8& aDest, TUint& aReadAddress, TUint& aAmountRemaining )
       
   658     {
       
   659     TMemSpyDriverInternalHeapDataParams params;
       
   660     params.iTid = aTid;
       
   661     params.iRHeapVTable = RHeapVTable();
       
   662     params.iDebugAllocator = DebugEUser();
       
   663     params.iDes = &aDest;
       
   664     params.iChecksum = aFreeCellChecksum;
       
   665     params.iRemaining = -1;
       
   666     aDest.Zero();
       
   667     //
       
   668 	TInt r = DoControl( EMemSpyDriverOpCodeHeapDataGetUser, &params, NULL );
       
   669 	//
       
   670 	if  ( r >= KErrNone )
       
   671     	{
       
   672         aDest.SetLength( r );
       
   673         aReadAddress = params.iReadAddress;
       
   674     	aAmountRemaining = params.iRemaining;
       
   675         r = KErrNone;
       
   676     	}
       
   677 	//
       
   678 	return r;
       
   679     }
       
   680 
       
   681 
       
   682 EXPORT_C TInt RMemSpyDriverClient::GetHeapDataNext( TUint aTid, TDes8& aDest, TUint& aReadAddress, TUint& aAmountRemaining )
       
   683     {
       
   684     TMemSpyDriverInternalHeapDataParams params;
       
   685     params.iTid = aTid;
       
   686     params.iRHeapVTable = RHeapVTable();
       
   687     params.iDebugAllocator = DebugEUser();
       
   688     params.iDes = &aDest;
       
   689     params.iChecksum = 0;
       
   690     params.iRemaining = aAmountRemaining;
       
   691     aDest.Zero();
       
   692     //
       
   693 	TInt r = DoControl( EMemSpyDriverOpCodeHeapDataGetUser, &params, NULL );
       
   694 	//
       
   695 	if  ( r >= KErrNone )
       
   696     	{
       
   697         aDest.SetLength( r );
       
   698         aReadAddress = params.iReadAddress;
       
   699     	aAmountRemaining = params.iRemaining;
       
   700         r = KErrNone;
       
   701     	}
       
   702 	//
       
   703     return r;
       
   704     }
       
   705 
       
   706 
       
   707 
       
   708 EXPORT_C HBufC8* RMemSpyDriverClient::GetHeapDataKernelLC( TMemSpyHeapInfo& aInfo, RArray<TMemSpyDriverFreeCell>& aFreeCells )
       
   709     {
       
   710     HBufC8* data = NULL;
       
   711 
       
   712     // Going to fetch free cells via stream buffer...
       
   713     ResetStreamBuffer();
       
   714 
       
   715     // First pass is to preallocate buffer for kernel heap, and fetch metadata and free cells
       
   716     TInt sizeOrError = DoControl( EMemSpyDriverOpCodeHeapDataGetKernelInit, (TAny*) &aInfo, (TAny*) &iBuffer );
       
   717 	if  ( sizeOrError >= KErrNone )
       
   718     	{
       
   719         const TInt kernelHeapSize = sizeOrError;
       
   720         if  ( aInfo.Type() != TMemSpyHeapInfo::ETypeRHeap )
       
   721             {
       
   722             User::Leave( KErrNotSupported );
       
   723             }
       
   724         else
       
   725             {
       
   726             // Extract free cells
       
   727             ReadHeapInfoFreeCellsFromXferBufferL( aFreeCells );
       
   728 
       
   729             // It's okay to treat the heap info as an RHeap
       
   730             PrintHeapInfo( aInfo );
       
   731 
       
   732             // Allocate data sink and do fetch
       
   733             data = HBufC8::NewLC( kernelHeapSize );
       
   734             TPtr8 pBuffer( data->Des() );
       
   735 
       
   736 	        sizeOrError = DoControl( EMemSpyDriverOpCodeHeapDataGetKernelFetch, &pBuffer, NULL );
       
   737             }
       
   738         }
       
   739 
       
   740     User::LeaveIfError( sizeOrError );
       
   741     return data;
       
   742     }
       
   743 
       
   744 
       
   745 
       
   746 
       
   747 
       
   748 
       
   749 
       
   750 
       
   751 
       
   752 
       
   753 
       
   754 
       
   755 
       
   756 
       
   757 
       
   758 
       
   759 
       
   760 
       
   761 
       
   762 
       
   763 
       
   764 
       
   765 
       
   766 
       
   767 
       
   768 
       
   769 
       
   770 
       
   771 
       
   772 
       
   773 
       
   774 
       
   775 
       
   776 
       
   777 
       
   778 
       
   779 EXPORT_C TInt RMemSpyDriverClient::WalkHeapInit( TUint aTid )
       
   780     {
       
   781     TMemSpyDriverInternalWalkHeapParamsInit params;
       
   782     params.iTid = aTid;
       
   783     params.iRHeapVTable = RHeapVTable();
       
   784     params.iDebugAllocator = DebugEUser();
       
   785     //
       
   786 	const TInt r = DoControl( EMemSpyDriverOpCodeWalkHeapInit, &params, NULL );
       
   787 	return r;
       
   788     }
       
   789 
       
   790 
       
   791 EXPORT_C TInt RMemSpyDriverClient::WalkHeapNextCell( TUint aTid, TMemSpyDriverCellType& aCellType, TAny*& aCellAddress, TInt& aLength, TInt& aNestingLevel, TInt& aAllocNumber, TInt& aCellHeaderSize, TAny*& aCellPayloadAddress )
       
   792     {
       
   793     aCellType = EMemSpyDriverGoodAllocatedCell;
       
   794     aCellAddress = NULL;
       
   795     aLength = 0;
       
   796     aNestingLevel = 0;
       
   797     aAllocNumber = 0;
       
   798     aCellHeaderSize = 0;
       
   799     aCellPayloadAddress = NULL;
       
   800     //
       
   801     TMemSpyDriverInternalWalkHeapParamsCell params;
       
   802 	const TInt r = DoControl( EMemSpyDriverOpCodeWalkHeapNextCell, (TAny*) aTid, &params );
       
   803     //
       
   804 	if  ( r == KErrNone )
       
   805 	    {
       
   806         RBuildQueryableHeap* heap = static_cast< RBuildQueryableHeap* >( &User::Allocator() );
       
   807         //
       
   808         aCellType = (TMemSpyDriverCellType) params.iCellType;
       
   809         aCellAddress = params.iCellAddress;
       
   810         aLength = params.iLength;
       
   811         aNestingLevel = params.iNestingLevel;
       
   812         aAllocNumber = params.iAllocNumber;
       
   813         aCellHeaderSize = heap->CellHeaderSize( aCellType );
       
   814         aCellPayloadAddress = ((TUint8*) aCellAddress) + aCellHeaderSize;
       
   815         }
       
   816     //
       
   817    	return r;
       
   818     }
       
   819 
       
   820 
       
   821 EXPORT_C TInt RMemSpyDriverClient::WalkHeapReadCellData( TAny* aCellAddress, TDes8& aDest, TInt aReadLen )
       
   822     {
       
   823     TMemSpyDriverInternalWalkHeapCellDataReadParams params;
       
   824     params.iCellAddress = aCellAddress;
       
   825     params.iReadLen = aReadLen;
       
   826     params.iDes = &aDest;
       
   827     aDest.Zero();
       
   828     //
       
   829 	TInt r = DoControl( EMemSpyDriverOpCodeWalkHeapReadCellData, &params, NULL );
       
   830     if  ( r >= KErrNone )
       
   831         {
       
   832         aDest.SetLength( r );
       
   833         r = KErrNone;
       
   834         }
       
   835     //
       
   836 	return r;
       
   837     }
       
   838 
       
   839 
       
   840 EXPORT_C TInt RMemSpyDriverClient::WalkHeapGetCellInfo( TAny*& aCellAddress, TMemSpyDriverCellType& aCellType, TInt& aLength, TInt& aNestingLevel, TInt& aAllocNumber, TInt& aCellHeaderSize, TAny*& aCellPayloadAddress )
       
   841     {
       
   842     aCellType = EMemSpyDriverGoodAllocatedCell;
       
   843     aLength = 0;
       
   844     aNestingLevel = 0;
       
   845     aAllocNumber = 0;
       
   846     aCellHeaderSize = 0;
       
   847     aCellPayloadAddress = NULL;
       
   848     //
       
   849     TMemSpyDriverInternalWalkHeapParamsCell params;
       
   850 	const TInt r = DoControl( EMemSpyDriverOpCodeWalkHeapGetCellInfo, aCellAddress, &params );
       
   851     //
       
   852 	if  ( r == KErrNone )
       
   853 	    {
       
   854         RBuildQueryableHeap* heap = static_cast< RBuildQueryableHeap* >( &User::Allocator() );
       
   855         //
       
   856         aCellAddress = params.iCellAddress;
       
   857         aCellType = (TMemSpyDriverCellType) params.iCellType;
       
   858         aLength = params.iLength;
       
   859         aNestingLevel = params.iNestingLevel;
       
   860         aAllocNumber = params.iAllocNumber;
       
   861         aCellHeaderSize = heap->CellHeaderSize( aCellType );
       
   862         aCellPayloadAddress = ((TUint8*) aCellAddress) + aCellHeaderSize;
       
   863         }
       
   864     //
       
   865    	return r;
       
   866     }
       
   867 
       
   868 
       
   869 EXPORT_C void RMemSpyDriverClient::WalkHeapClose()
       
   870     {
       
   871 	DoControl( EMemSpyDriverOpCodeWalkHeapClose, NULL, NULL );
       
   872     }
       
   873 
       
   874 
       
   875 
       
   876 
       
   877 
       
   878 
       
   879 
       
   880 
       
   881 
       
   882 
       
   883 
       
   884 
       
   885 
       
   886 
       
   887 
       
   888 
       
   889 
       
   890 
       
   891 
       
   892 
       
   893 
       
   894 
       
   895 
       
   896 
       
   897 
       
   898 
       
   899 
       
   900 EXPORT_C TInt RMemSpyDriverClient::GetStackInfo( TUint aTid, TMemSpyDriverStackInfo& aInfo )
       
   901     {
       
   902     TMemSpyDriverStackInfo params;
       
   903 	const TInt r = DoControl( EMemSpyDriverOpCodeStackGetInfo, (TAny*)aTid, &params );
       
   904 	if  (r==KErrNone)
       
   905 		{
       
   906 		aInfo.iUserStackPointer = params.iUserStackPointer;
       
   907 		aInfo.iUserStackBase = params.iUserStackBase;
       
   908 		aInfo.iUserStackSize = params.iUserStackSize;
       
   909 		aInfo.iUserStackHighWatermark = params.iUserStackHighWatermark;
       
   910 		aInfo.iSupervisorStackPointer = params.iSupervisorStackPointer;
       
   911 		aInfo.iSupervisorStackBase = params.iSupervisorStackBase;
       
   912 		aInfo.iSupervisorStackSize = params.iSupervisorStackSize;
       
   913 		aInfo.iSupervisorStackHighWatermark = params.iSupervisorStackHighWatermark;
       
   914 		}
       
   915 	//
       
   916 	return r;
       
   917     }    
       
   918 
       
   919 
       
   920 EXPORT_C TInt RMemSpyDriverClient::GetStackData( TUint aTid, TDes8& aDest, TUint& aAmountRemaining, TMemSpyDriverDomainType aDomain, TBool aEntireStack )
       
   921     {
       
   922     TMemSpyDriverInternalStackDataParams params;
       
   923     params.iTid = aTid;
       
   924     params.iDes = &aDest;
       
   925     params.iDomain = aDomain;
       
   926     params.iEntireStack = aEntireStack;
       
   927     params.iRemaining = -1;
       
   928     aDest.Zero();
       
   929     //
       
   930 	TInt r = DoControl( EMemSpyDriverOpCodeStackGetData, &params, NULL );
       
   931 	//
       
   932 	if  ( r >= KErrNone )
       
   933     	{
       
   934         aDest.SetLength( r );
       
   935     	aAmountRemaining = params.iRemaining;
       
   936         r = KErrNone;
       
   937     	}
       
   938 	//
       
   939 	return r;
       
   940     }
       
   941 
       
   942 
       
   943 EXPORT_C TInt RMemSpyDriverClient::GetStackDataNext( TUint aTid, TDes8& aDest, TUint& aAmountRemaining, TMemSpyDriverDomainType aDomain, TBool aEntireStack )
       
   944     {
       
   945     TMemSpyDriverInternalStackDataParams params;
       
   946     params.iTid = aTid;
       
   947     params.iDes = &aDest;
       
   948     params.iDomain = aDomain;
       
   949     params.iEntireStack = aEntireStack;
       
   950     params.iRemaining = aAmountRemaining;
       
   951     //
       
   952 	TInt r = DoControl( EMemSpyDriverOpCodeStackGetData, &params, NULL );
       
   953 	//
       
   954 	if  ( r >= KErrNone )
       
   955     	{
       
   956         aDest.SetLength( r );
       
   957     	aAmountRemaining = params.iRemaining;
       
   958         r = KErrNone;
       
   959     	}
       
   960 	//
       
   961     return r;
       
   962     }
       
   963 
       
   964 
       
   965 
       
   966 
       
   967 
       
   968 
       
   969 
       
   970 
       
   971 
       
   972 
       
   973 
       
   974 
       
   975 
       
   976 
       
   977 
       
   978 
       
   979 
       
   980 
       
   981 
       
   982 
       
   983 
       
   984 
       
   985 
       
   986 
       
   987 
       
   988 
       
   989 
       
   990 
       
   991 
       
   992 
       
   993 
       
   994 
       
   995 
       
   996 
       
   997 
       
   998 
       
   999 
       
  1000 
       
  1001 
       
  1002 
       
  1003 
       
  1004 
       
  1005 
       
  1006 
       
  1007 
       
  1008 
       
  1009 
       
  1010 
       
  1011 
       
  1012 
       
  1013 
       
  1014 
       
  1015 
       
  1016 
       
  1017 
       
  1018 
       
  1019 
       
  1020 
       
  1021 
       
  1022 
       
  1023 
       
  1024 
       
  1025 
       
  1026 EXPORT_C TInt RMemSpyDriverClient::EventMonitorOpen( TUint& aHandle )
       
  1027     {
       
  1028     const TInt error = DoControl( EMemSpyDriverOpCodeEventMonitorOpen, (TAny*) &aHandle );
       
  1029     return error;
       
  1030     }
       
  1031 
       
  1032 
       
  1033 EXPORT_C TInt RMemSpyDriverClient::EventMonitorClose( TUint aHandle )
       
  1034     {
       
  1035     const TInt error = DoControl( EMemSpyDriverOpCodeEventMonitorClose, (TAny*) aHandle );
       
  1036     return error;
       
  1037     }
       
  1038 
       
  1039 
       
  1040 EXPORT_C void RMemSpyDriverClient::EventMonitorNotify( TUint aHandle, TRequestStatus& aStatus, TUint& aContext )
       
  1041     {
       
  1042     aStatus = KRequestPending;
       
  1043     //
       
  1044     TMemSpyDriverInternalEventMonitorParams params;
       
  1045     params.iHandle = aHandle;
       
  1046     params.iStatus = &aStatus;
       
  1047     params.iContext = (TAny*) &aContext;
       
  1048     //
       
  1049     const TInt err = DoControl( EMemSpyDriverOpCodeEventMonitorNotify, (TAny*) &params );
       
  1050     if  ( err != KErrNone )
       
  1051         {
       
  1052         TRequestStatus* status = &aStatus;
       
  1053         User::RequestComplete( status, err );
       
  1054         }
       
  1055     }
       
  1056 
       
  1057 
       
  1058 EXPORT_C void RMemSpyDriverClient::EventMonitorNotifyCancel( TUint aHandle )
       
  1059     {
       
  1060     const TInt error = DoControl( EMemSpyDriverOpCodeEventMonitorNotifyCancel, (TAny*) aHandle );
       
  1061     (void) error;
       
  1062     }
       
  1063 
       
  1064 
       
  1065 
       
  1066 
       
  1067 
       
  1068 
       
  1069 
       
  1070 
       
  1071 
       
  1072 
       
  1073 
       
  1074 
       
  1075 
       
  1076 
       
  1077 
       
  1078 
       
  1079 
       
  1080 
       
  1081 
       
  1082 EXPORT_C TInt RMemSpyDriverClient::ProcessInspectionOpen( TUint aPid )
       
  1083     {
       
  1084     const TInt error = DoControl( EMemSpyDriverOpCodeProcessInspectOpen, (TAny*) aPid );
       
  1085     return error;
       
  1086     }
       
  1087 
       
  1088 
       
  1089 EXPORT_C TInt RMemSpyDriverClient::ProcessInspectionClose( TUint aPid )
       
  1090     {
       
  1091     const TInt error = DoControl( EMemSpyDriverOpCodeProcessInspectClose, (TAny*) aPid );
       
  1092     return error;
       
  1093     }
       
  1094 
       
  1095 
       
  1096 EXPORT_C void RMemSpyDriverClient::ProcessInspectionRequestChanges( TUint aPid, TRequestStatus& aStatus, TMemSpyDriverProcessInspectionInfo& aInfo )
       
  1097     {
       
  1098     aInfo.iProcessId = aPid;
       
  1099     aStatus = KRequestPending;
       
  1100     const TInt err = DoControl( EMemSpyDriverOpCodeProcessInspectRequestChanges, (TAny*) &aStatus, (TAny*) &aInfo );
       
  1101     if  ( err != KErrNone )
       
  1102         {
       
  1103         TRequestStatus* status = &aStatus;
       
  1104         User::RequestComplete( status, err );
       
  1105         }
       
  1106     }
       
  1107 
       
  1108 
       
  1109 EXPORT_C void RMemSpyDriverClient::ProcessInspectionRequestChangesCancel( TUint aPid )
       
  1110     {
       
  1111     const TInt error = DoControl( EMemSpyDriverOpCodeProcessInspectRequestChangesCancel, (TAny*) aPid );
       
  1112     (void) error;
       
  1113     }
       
  1114 
       
  1115 
       
  1116 EXPORT_C void RMemSpyDriverClient::ProcessInspectionAutoStartItemsReset()
       
  1117     {
       
  1118     const TInt error = DoControl( EMemSpyDriverOpCodeProcessInspectAutoStartListReset );
       
  1119     (void) error;
       
  1120     }
       
  1121 
       
  1122 
       
  1123 EXPORT_C TInt RMemSpyDriverClient::ProcessInspectionAutoStartItemsAdd( TUint aSID )
       
  1124     {
       
  1125     const TInt error = DoControl( EMemSpyDriverOpCodeProcessInspectAutoStartListAdd, (TAny*) aSID );
       
  1126     return error;
       
  1127     }
       
  1128 
       
  1129 
       
  1130 
       
  1131 
       
  1132 
       
  1133 
       
  1134 
       
  1135 
       
  1136 
       
  1137 
       
  1138 
       
  1139 
       
  1140 
       
  1141 
       
  1142 
       
  1143 
       
  1144 
       
  1145 
       
  1146 
       
  1147 
       
  1148 
       
  1149 
       
  1150 EXPORT_C TInt RMemSpyDriverClient::GetContainerHandles( TMemSpyDriverContainerType aContainer, TAny** aHandleArray, TInt& aHandleCount )
       
  1151     {
       
  1152 	TMemSpyDriverInternalContainerHandleParams params;
       
  1153 	params.iTidOrPid = KMemSpyDriverEnumerateContainerHandles;
       
  1154 	params.iContainer = aContainer;
       
  1155 	params.iHandles = aHandleArray;
       
  1156 	params.iCountPtr = &aHandleCount;
       
  1157     params.iMaxCount = aHandleCount;
       
  1158     params.iHandleSource = EMemSpyDriverThreadOrProcessTypeThread; // Not used
       
  1159     //
       
  1160     aHandleCount = 0;
       
  1161 	//
       
  1162 	return DoControl( EMemSpyDriverOpCodeContainersGetHandles, &params, NULL );
       
  1163     }
       
  1164 
       
  1165 
       
  1166 EXPORT_C TInt RMemSpyDriverClient::GetThreadHandlesByType( TInt aTid, TMemSpyDriverContainerType aType, TAny** aHandleArray, TInt& aHandleCount )
       
  1167     {
       
  1168 	TMemSpyDriverInternalContainerHandleParams params;
       
  1169 	params.iTidOrPid = aTid;
       
  1170 	params.iContainer = aType;
       
  1171 	params.iHandles = aHandleArray;
       
  1172 	params.iCountPtr = &aHandleCount;
       
  1173     params.iMaxCount = aHandleCount;
       
  1174     params.iHandleSource = EMemSpyDriverThreadOrProcessTypeThread;
       
  1175 	//
       
  1176     aHandleCount = 0;
       
  1177     //
       
  1178 	return DoControl( EMemSpyDriverOpCodeContainersGetHandles, &params, NULL );
       
  1179     }
       
  1180 
       
  1181 
       
  1182 EXPORT_C TInt RMemSpyDriverClient::GetProcessHandlesByType( TInt aPid, TMemSpyDriverContainerType aType, TAny** aHandleArray, TInt& aHandleCount )
       
  1183     {
       
  1184 	TMemSpyDriverInternalContainerHandleParams params;
       
  1185 	params.iTidOrPid = aPid;
       
  1186 	params.iContainer = aType;
       
  1187 	params.iHandles = aHandleArray;
       
  1188 	params.iCountPtr = &aHandleCount;
       
  1189     params.iMaxCount = aHandleCount;
       
  1190     params.iHandleSource = EMemSpyDriverThreadOrProcessTypeProcess;
       
  1191 	//
       
  1192     aHandleCount = 0;
       
  1193     //
       
  1194 	return DoControl( EMemSpyDriverOpCodeContainersGetHandles, &params, NULL );
       
  1195     }
       
  1196 
       
  1197 
       
  1198 EXPORT_C TInt RMemSpyDriverClient::GetGenericHandleInfo( TInt aTid, TMemSpyDriverContainerType aType, TAny* aHandle, TMemSpyDriverHandleInfoGeneric& aParams )
       
  1199     {
       
  1200     aParams.iType = aType;
       
  1201     aParams.iHandle = aHandle;
       
  1202     //
       
  1203     const TInt r = DoControl( EMemSpyDriverOpCodeContainersGetHandleInfo, (TAny*) aTid, &aParams );
       
  1204     return r;
       
  1205     }
       
  1206 
       
  1207 
       
  1208 EXPORT_C TInt RMemSpyDriverClient::GetApproximateKernelObjectSize( TMemSpyDriverContainerType aType )
       
  1209     {
       
  1210     TInt size = 0;
       
  1211     const TInt error = DoControl( EMemSpyDriverOpCodeContainersGetApproxSize, (TAny*) aType, (TAny*) &size );
       
  1212     (void) error;
       
  1213     //
       
  1214     return size;
       
  1215     }
       
  1216 
       
  1217 
       
  1218 EXPORT_C TInt RMemSpyDriverClient::GetReferencesToMyThread( TUint aTid )
       
  1219     {
       
  1220     ResetStreamBuffer();
       
  1221 	return DoControl( EMemSpyDriverOpCodeContainersGetReferencesToMyThread, (TAny*) aTid, (TAny*) &iBuffer );
       
  1222     }
       
  1223 
       
  1224 
       
  1225 EXPORT_C TInt RMemSpyDriverClient::GetReferencesToMyProcess( TUint aPid )
       
  1226     {
       
  1227     ResetStreamBuffer();
       
  1228 	return DoControl( EMemSpyDriverOpCodeContainersGetReferencesToMyProcess, (TAny*) aPid, (TAny*) &iBuffer );
       
  1229     }
       
  1230 
       
  1231 
       
  1232 EXPORT_C TInt RMemSpyDriverClient::GetPAndSInfo( TAny* aHandle, TMemSpyDriverPAndSInfo& aInfo )
       
  1233     {
       
  1234     const TInt r = DoControl( EMemSpyDriverOpCodeContainersGetPAndSInfo, (TAny*) aHandle, &aInfo );
       
  1235     return r;
       
  1236     }
       
  1237 
       
  1238 
       
  1239 EXPORT_C TInt RMemSpyDriverClient::GetCondVarSuspendedThreads( TAny* aCondVarHandle, TAny** aThreadHandleArray, TInt& aThreadCount )
       
  1240     {
       
  1241     TMemSpyDriverInternalCondVarSuspendedThreadParams params;
       
  1242     params.iCondVarHandle = aCondVarHandle;
       
  1243     params.iThrHandles = aThreadHandleArray;
       
  1244     params.iThrCountPtr = &aThreadCount;
       
  1245     params.iMaxCount = aThreadCount;
       
  1246     //
       
  1247     aThreadCount = 0;
       
  1248     //
       
  1249     return DoControl( EMemSpyDriverOpCodeContainersGetCondVarSuspendedThreads, &params, NULL );
       
  1250     }
       
  1251 
       
  1252 
       
  1253 EXPORT_C TInt RMemSpyDriverClient::GetCondVarSuspendedThreadInfo( TAny* aHandle, TMemSpyDriverCondVarSuspendedThreadInfo& aParams )
       
  1254     {
       
  1255     return DoControl( EMemSpyDriverOpCodeContainersGetCondVarSuspendedThreadInfo, aHandle, &aParams );
       
  1256     }
       
  1257 
       
  1258 
       
  1259 
       
  1260 
       
  1261 
       
  1262 
       
  1263 
       
  1264 
       
  1265 
       
  1266 
       
  1267 
       
  1268 
       
  1269 
       
  1270 
       
  1271 
       
  1272 
       
  1273 
       
  1274 EXPORT_C TInt RMemSpyDriverClient::GetServerSessionHandles( TAny* aServerHandle, TAny** aSessionHandleArray, TInt& aSessionHandleCount )
       
  1275     {
       
  1276 	TMemSpyDriverInternalServerSessionHandleParams params;
       
  1277 	params.iServerHandle = aServerHandle;
       
  1278 	params.iSessionHandles = aSessionHandleArray;
       
  1279 	params.iSessionCountPtr = &aSessionHandleCount;
       
  1280     params.iMaxCount = aSessionHandleCount;
       
  1281     //
       
  1282     aSessionHandleCount = 0;
       
  1283 	//
       
  1284 	return DoControl( EMemSpyDriverOpCodeClientServerGetServerSessionHandles, &params, NULL );
       
  1285     }
       
  1286 
       
  1287 
       
  1288 EXPORT_C TInt RMemSpyDriverClient::GetServerSessionInfo( TAny* aSessionHandle, TMemSpyDriverServerSessionInfo& aParams )
       
  1289     {
       
  1290     return DoControl( EMemSpyDriverOpCodeClientServerGetServerSessionInfo, aSessionHandle, &aParams );
       
  1291     }
       
  1292 
       
  1293 
       
  1294 
       
  1295 
       
  1296 
       
  1297 
       
  1298 
       
  1299 
       
  1300 
       
  1301 
       
  1302 
       
  1303 EXPORT_C RMemSpyMemStreamReader RMemSpyDriverClient::StreamOpenL()
       
  1304     {
       
  1305     CMemSpyMemStreamReader* imp = new(ELeave) CMemSpyMemStreamReader( iBuffer );
       
  1306     RMemSpyMemStreamReader ret( imp );
       
  1307     CleanupClosePushL( ret ); 
       
  1308     imp->ConstructL();
       
  1309     CleanupStack::Pop( &ret );
       
  1310     return ret;
       
  1311     }
       
  1312 
       
  1313 
       
  1314 
       
  1315 
       
  1316 
       
  1317 
       
  1318 
       
  1319 
       
  1320 
       
  1321 
       
  1322 
       
  1323 
       
  1324 
       
  1325 EXPORT_C TMemSpyMemoryModelType RMemSpyDriverClient::MemoryModelType()
       
  1326     {
       
  1327     TMemSpyMemoryModelType ret = EMemSpyMemoryModelTypeUnknown;
       
  1328     //
       
  1329     const TInt err = DoControl( EMemSpyDriverOpCodeMiscGetMemoryModelType );
       
  1330     switch( err )
       
  1331         {
       
  1332     default:
       
  1333     case EMemSpyMemoryModelTypeUnknown:
       
  1334         ret = EMemSpyMemoryModelTypeUnknown;
       
  1335         break;
       
  1336     case EMemSpyMemoryModelTypeMoving:
       
  1337         ret = EMemSpyMemoryModelTypeMoving;
       
  1338         break;
       
  1339     case EMemSpyMemoryModelTypeMultiple:
       
  1340         ret = EMemSpyMemoryModelTypeMultiple;
       
  1341         break;
       
  1342     case EMemSpyMemoryModelTypeEmulator:
       
  1343         ret = EMemSpyMemoryModelTypeEmulator;
       
  1344         break;
       
  1345         }
       
  1346     //
       
  1347     return ret;
       
  1348     }
       
  1349 
       
  1350 
       
  1351 EXPORT_C TUint32 RMemSpyDriverClient::RoundToPageSize( TUint32 aValue )
       
  1352     {
       
  1353     TUint32 temp = aValue;
       
  1354     TAny* pValue = (TAny*) &temp;
       
  1355     DoControl( EMemSpyDriverOpCodeMiscGetRoundToPageSize, pValue );
       
  1356     return temp;
       
  1357     }
       
  1358 
       
  1359 
       
  1360 EXPORT_C TInt RMemSpyDriverClient::Impersonate( TUint32 aValue )
       
  1361     {
       
  1362     return DoControl( EMemSpyDriverOpCodeMiscImpersonate, (TAny*) aValue );
       
  1363     }
       
  1364 
       
  1365 
       
  1366 
       
  1367 
       
  1368 
       
  1369 
       
  1370 
       
  1371 
       
  1372 
       
  1373 
       
  1374 
       
  1375 
       
  1376 
       
  1377 
       
  1378 
       
  1379 
       
  1380 
       
  1381 
       
  1382 
       
  1383 
       
  1384 
       
  1385 
       
  1386 
       
  1387 
       
  1388 
       
  1389 
       
  1390 TUint RMemSpyDriverClient::RHeapVTable()
       
  1391     {
       
  1392     RHeap* heap = (RHeap*) &User::Allocator();
       
  1393     //
       
  1394     TUint* pHeap = (TUint*) heap;
       
  1395     const TUint heapVTable = *pHeap;
       
  1396     //
       
  1397     ////RDebug::Printf( "[MemSpy] RMemSpyDriverClient::RHeapVTable() - ret: 0x%08x", heapVTable );
       
  1398     return heapVTable;
       
  1399     }
       
  1400 
       
  1401 
       
  1402 TBool RMemSpyDriverClient::DebugEUser()
       
  1403     {
       
  1404     RHeap* heap = static_cast< RHeap* >( &User::Allocator() );
       
  1405     RBuildQueryableHeap* queryHeap = static_cast< RBuildQueryableHeap* >( heap );
       
  1406     const TBool isDebugEUser = queryHeap->IsDebugEUser();
       
  1407     return isDebugEUser;
       
  1408     }
       
  1409 
       
  1410 
       
  1411 void RMemSpyDriverClient::ResetStreamBuffer()
       
  1412     {
       
  1413     iBuffer.Zero();
       
  1414     }
       
  1415 
       
  1416 
       
  1417 void RMemSpyDriverClient::ReadHeapInfoFreeCellsFromXferBufferL( RArray<TMemSpyDriverFreeCell>& aFreeCells )
       
  1418     {
       
  1419     aFreeCells.Reset();
       
  1420 
       
  1421 #ifdef _DEBUG
       
  1422     RDebug::Printf( "[MemSpy] RMemSpyDriverClient::ReadHeapInfoFreeCellsFromXferBufferL() - buf len: %d", iBuffer.Length() );
       
  1423 #endif
       
  1424 
       
  1425     if  ( iBuffer.Length() )
       
  1426         {
       
  1427         RMemSpyMemStreamReader stream = StreamOpenL();
       
  1428         CleanupClosePushL( stream );
       
  1429 
       
  1430         const TInt count = stream.ReadInt32L();
       
  1431 #ifdef _DEBUG
       
  1432         RDebug::Printf( "[MemSpy] RMemSpyDriverClient::ReadHeapInfoFreeCellsFromXferBufferL() - count: %d", count );
       
  1433 #endif
       
  1434 
       
  1435         for( TInt i=0; i<count; i++ )
       
  1436             {
       
  1437             TMemSpyDriverFreeCell entry;
       
  1438             entry.iType = stream.ReadInt32L();
       
  1439             entry.iAddress = reinterpret_cast< TAny* >( stream.ReadUint32L() );
       
  1440             entry.iLength = stream.ReadInt32L();
       
  1441             aFreeCells.AppendL( entry );
       
  1442             }
       
  1443 
       
  1444         CleanupStack::PopAndDestroy( &stream );
       
  1445         }
       
  1446 
       
  1447     ResetStreamBuffer();
       
  1448     }
       
  1449 
       
  1450 
       
  1451 
       
  1452 
       
  1453 
       
  1454 
       
  1455 
       
  1456 
       
  1457 
       
  1458 
       
  1459 
       
  1460 
       
  1461 static void PrintHeapInfo( const TMemSpyHeapInfo& aInfo )
       
  1462     {
       
  1463 #if defined( _DEBUG ) && !defined( __WINS__ )
       
  1464     const TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
       
  1465     const TMemSpyHeapObjectDataRHeap& rHeapObjectData = rHeapInfo.ObjectData();
       
  1466     const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeapInfo.Statistics();
       
  1467     const TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
       
  1468 
       
  1469     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1470     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator                                      -");
       
  1471     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1472     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iAccessCount:       %d", rHeapObjectData.iAccessCount);
       
  1473     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iHandleCount:       %d", rHeapObjectData.iHandleCount);
       
  1474     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iHandles:           0x%08x", rHeapObjectData.iHandles);
       
  1475     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iFlags:             0x%08x", rHeapObjectData.iFlags);
       
  1476     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iCellCount:         %d", rHeapObjectData.iCellCount);
       
  1477     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RAllocator::iTotalAllocSize:    %d", rHeapObjectData.iTotalAllocSize);
       
  1478     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - ");
       
  1479 
       
  1480     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1481     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap                                           -");
       
  1482     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1483     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iMinLength:              %d", rHeapObjectData.iMinLength);
       
  1484     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iMaxLength:              %d", rHeapObjectData.iMaxLength);
       
  1485     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iOffset:                 %d", rHeapObjectData.iOffset);
       
  1486     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iGrowBy:                 %d", rHeapObjectData.iGrowBy);
       
  1487     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iChunkHandle:            0x%08x", rHeapObjectData.iChunkHandle);
       
  1488     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iBase:                   0x%08x", rHeapObjectData.iBase);
       
  1489     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iTop:                    0x%08x", rHeapObjectData.iTop);
       
  1490     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iAlign:                  %d", rHeapObjectData.iAlign);
       
  1491     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iMinCell:                %d", rHeapObjectData.iAlign);
       
  1492     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iPageSize:               %d", rHeapObjectData.iAlign);
       
  1493     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFree.next:              0x%08x", rHeapObjectData.iFree.next);
       
  1494     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFree.len:               %d", rHeapObjectData.iFree.len);
       
  1495     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iNestingLevel:           %d", rHeapObjectData.iNestingLevel);
       
  1496     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iAllocCount:             %d", rHeapObjectData.iAllocCount);
       
  1497     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFailType:               %d", rHeapObjectData.iFailType);
       
  1498     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFailRate:               %d", rHeapObjectData.iFailRate);
       
  1499     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFailed:                 %d", rHeapObjectData.iFailed);
       
  1500     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iFailAllocCount:         %d", rHeapObjectData.iFailAllocCount);
       
  1501     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iRand:                   %d", rHeapObjectData.iRand);
       
  1502     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - RHeap::iTestData:               0x%08x", rHeapObjectData.iTestData);
       
  1503     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - ");
       
  1504 
       
  1505     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1506     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - Stats (Free)                                    -");
       
  1507     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1508     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell count:                     %d", rHeapStats.StatsFree().TypeCount());
       
  1509     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell size:                      %d", rHeapStats.StatsFree().TypeSize());
       
  1510     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell largest:                   0x%08x", rHeapStats.StatsFree().LargestCellAddress());
       
  1511     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell largest size:              %d", rHeapStats.StatsFree().LargestCellSize());
       
  1512     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - slack:                          0x%08x", rHeapStats.StatsFree().SlackSpaceCellAddress());
       
  1513     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - slack size:                     %d", rHeapStats.StatsFree().SlackSpaceCellSize());
       
  1514     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - checksum:                       0x%08x", rHeapStats.StatsFree().Checksum());
       
  1515     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - ");
       
  1516 
       
  1517     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1518     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - Stats (Alloc)                                   -");
       
  1519     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1520     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell count:                     %d", rHeapStats.StatsAllocated().TypeCount());
       
  1521     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell size:                      %d", rHeapStats.StatsAllocated().TypeSize());
       
  1522     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell largest:                   0x%08x", rHeapStats.StatsAllocated().LargestCellAddress());
       
  1523     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell largest size:              %d", rHeapStats.StatsAllocated().LargestCellSize());
       
  1524     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - ");
       
  1525 
       
  1526     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1527     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - Stats (Common)                                  -");
       
  1528     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1529     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - total cell count:               %d", rHeapStats.StatsCommon().TotalCellCount());
       
  1530     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - ");
       
  1531 
       
  1532     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1533     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - Misc. Info                                      -");
       
  1534     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() ---------------------------------------------------");
       
  1535     const TPtrC chunkName( rHeapMetaData.ChunkName() );
       
  1536     RDebug::Print(_L("RMemSpyDriverClient::PrintHeapInfo() - chunk name:                     [%S]"), &chunkName );
       
  1537     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - chunk size:                     %d", rHeapMetaData.ChunkSize());
       
  1538     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - chunk handle:                   0x%08x", rHeapMetaData.ChunkHandle());
       
  1539     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - chunk base address:             0x%08x", rHeapMetaData.ChunkBaseAddress());
       
  1540     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - debug allocator:                %d", rHeapMetaData.IsDebugAllocator());
       
  1541     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - shared heap:                    %d", rHeapMetaData.IsSharedHeap() );
       
  1542     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - user thread:                    %d", rHeapMetaData.IsUserThread() );
       
  1543     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - thread id:                      %d", aInfo.Tid() );
       
  1544     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - process id:                     %d", aInfo.Pid() );
       
  1545     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell header size (free):        %d", rHeapMetaData.HeaderSizeFree());
       
  1546     RDebug::Printf("RMemSpyDriverClient::PrintHeapInfo() - cell header size (alloc):       %d", rHeapMetaData.HeaderSizeAllocated());
       
  1547 #else
       
  1548     (void) aInfo;
       
  1549 #endif
       
  1550     }
       
  1551