memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
   162         DProcess* process = (DProcess*) TempObject();
   162         DProcess* process = (DProcess*) TempObject();
   163 	    NKern::ThreadEnterCS();
   163 	    NKern::ThreadEnterCS();
   164 
   164 
   165 	    // Iterate through each handle in the process
   165 	    // Iterate through each handle in the process
   166 	    MemSpyObjectIx* processHandles = processAdaption.GetHandles( *process );
   166 	    MemSpyObjectIx* processHandles = processAdaption.GetHandles( *process );
   167 		MemSpyObjectIx_HandleLookupLock();
   167         MemSpyObjectIx_Wait( processHandles );
       
   168 
   168         const TInt processHandleCount = processHandles->Count();
   169         const TInt processHandleCount = processHandles->Count();
   169 		MemSpyObjectIx_HandleLookupUnlock();
       
   170 
       
   171 	    for( TInt processHandleIndex = 0; processHandleIndex<processHandleCount && r == KErrNone && currentWriteIndex < maxCount; processHandleIndex++ )
   170 	    for( TInt processHandleIndex = 0; processHandleIndex<processHandleCount && r == KErrNone && currentWriteIndex < maxCount; processHandleIndex++ )
   172     	    {
   171     	    {
   173     	    // Get a handle from the process container...
   172     	    // Get a handle from the process container...
   174             MemSpyObjectIx_HandleLookupLock();
   173             NKern::LockSystem();
   175 			if (processHandleIndex >= processHandles->Count()) break; // Count may have changed in the meantime
       
   176     	    DObject* object = (*processHandles)[ processHandleIndex ];
   174     	    DObject* object = (*processHandles)[ processHandleIndex ];
   177 			if (object && object->Open() != KErrNone) object = NULL;
   175             NKern::UnlockSystem();
   178 			MemSpyObjectIx_HandleLookupUnlock();
       
   179             
   176             
   180             if  ( object )
   177             if  ( object )
   181                 {
   178                 {
   182                 const TObjectType objectType = processAdaption.GetObjectType( *object );
   179                 const TObjectType objectType = processAdaption.GetObjectType( *object );
   183                 if ( objectType == EChunk )
   180                 if ( objectType == EChunk )
   188                     if  ( r == KErrNone )
   185                     if  ( r == KErrNone )
   189                         {
   186                         {
   190                         ++currentWriteIndex;
   187                         ++currentWriteIndex;
   191                         }
   188                         }
   192                     }
   189                     }
   193 				object->Close(NULL);
       
   194                 }
   190                 }
   195     	    }
   191     	    }
       
   192 
       
   193         MemSpyObjectIx_Signal( processHandles );
   196 
   194 
   197         // If we were asked for process-related chunks, also check the chunk container
   195         // If we were asked for process-related chunks, also check the chunk container
   198         // for entries which we don't have handles to, but do refer to our process
   196         // for entries which we don't have handles to, but do refer to our process
   199         // Need a listing of all chunks in the system. Let client filter duplicates.
   197         // Need a listing of all chunks in the system. Let client filter duplicates.
   200         DObjectCon* container = Kern::Containers()[ EChunk ];
   198         DObjectCon* container = Kern::Containers()[ EChunk ];
   276 		
   274 		
   277 	DObjectCon* container = Kern::Containers()[EChunk];
   275 	DObjectCon* container = Kern::Containers()[EChunk];
   278 	NKern::ThreadEnterCS();
   276 	NKern::ThreadEnterCS();
   279 
   277 
   280     container->Wait();
   278     container->Wait();
       
   279     NKern::LockSystem();
   281     const TInt count = container->Count();
   280     const TInt count = container->Count();
       
   281     NKern::UnlockSystem();
   282 
   282 
   283     DChunk* foundChunk = NULL;
   283     DChunk* foundChunk = NULL;
   284     
   284     
   285     for(TInt i=0; i<count; i++)
   285     for(TInt i=0; i<count; i++)
   286         {
   286         {
       
   287         NKern::LockSystem();
   287         DChunk* chunk = (DChunk*) (*container)[i];
   288         DChunk* chunk = (DChunk*) (*container)[i];
       
   289         NKern::UnlockSystem();
       
   290         //
   288         if  ( chunk == params.iHandle )
   291         if  ( chunk == params.iHandle )
   289             {
   292             {
   290             foundChunk = chunk;
   293             foundChunk = chunk;
   291             TRACE( PrintChunkInfo( *chunk ) );
   294             TRACE( PrintChunkInfo( *chunk ) );
   292 			r = foundChunk->Open();
       
   293             break;
   295             break;
   294             }
   296             }
   295         }
   297         }
   296 
   298 
   297     container->Signal();
   299     container->Signal();
       
   300 	NKern::ThreadLeaveCS();
   298 
   301 
   299     if  ( foundChunk == NULL )
   302     if  ( foundChunk == NULL )
   300         {
   303         {
   301     	Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkInfo() - END - KErrNotFound - couldnt find chunk");
   304     	Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkInfo() - END - KErrNotFound - couldnt find chunk");
   302 		NKern::ThreadLeaveCS();
       
   303         return KErrNotFound;
   305         return KErrNotFound;
   304         }
   306         }
   305 	if (r)
       
   306 		{
       
   307 		Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkInfo() - END - %d - Failed to open chunk", r);
       
   308 		NKern::ThreadLeaveCS();
       
   309 		return r;
       
   310 		}
       
   311 
   307 
   312     // Prepare return data
   308     // Prepare return data
   313     DMemSpyDriverOSAdaptionDChunk& chunkAdaption = OSAdaption().DChunk();
   309     DMemSpyDriverOSAdaptionDChunk& chunkAdaption = OSAdaption().DChunk();
   314     //
   310     //
   315     params.iBaseAddress = chunkAdaption.GetBase( *foundChunk );
   311     params.iBaseAddress = chunkAdaption.GetBase( *foundChunk );
   337         }
   333         }
   338 
   334 
   339     // Get type & attribs
   335     // Get type & attribs
   340     params.iType = IdentifyChunkType( *foundChunk );
   336     params.iType = IdentifyChunkType( *foundChunk );
   341     params.iAttributes = chunkAdaption.GetAttributes( *foundChunk );
   337     params.iAttributes = chunkAdaption.GetAttributes( *foundChunk );
   342 
       
   343 	// Finished with foundChunk
       
   344 	foundChunk->Close(NULL);
       
   345 	NKern::ThreadLeaveCS();
       
   346     
   338     
   347     // Write back to client
   339     // Write back to client
   348     r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverInternalChunkInfoParams) );
   340     r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverInternalChunkInfoParams) );
   349 	if  ( r == KErrBadDescriptor )
   341 	if  ( r == KErrBadDescriptor )
   350         {
   342         {
   476     const TInt size = chunkAdaption.GetSize( aChunk );
   468     const TInt size = chunkAdaption.GetSize( aChunk );
   477     TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - base: 0x%08x, size: %d, process: 0x%08x (%O)", base, size, process, process ) );
   469     TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - base: 0x%08x, size: %d, process: 0x%08x (%O)", base, size, process, process ) );
   478 
   470 
   479     if  ( process && size >= 4 )
   471     if  ( process && size >= 4 )
   480         {
   472         {
   481 		NKern::ThreadEnterCS();
       
   482         // Chunks are mapped into entire process so any thread within the process is enough...
   473         // Chunks are mapped into entire process so any thread within the process is enough...
   483         DThread* firstThread = processAdaption.OpenFirstThread( *process );
   474         DThread* firstThread = processAdaption.GetFirstThread( *process );
   484         TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - firstThread: 0x%08x (%O)", firstThread, firstThread ) );
   475         TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - firstThread: 0x%08x (%O)", firstThread, firstThread ) );
   485         if  ( firstThread != NULL )
   476         if  ( firstThread != NULL )
   486             {
   477             {
   487             TBuf8<4> allocatorVTableBuffer;
   478             TInt err = firstThread->Open();
   488             TInt err = Kern::ThreadRawRead( firstThread, base, (TUint8*) allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength() );
   479             TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - firstThread open result: %d", err ) );
   489             TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - read result of vtable data from requested thread is: %d", err ));
   480 
   490             //
       
   491             if  ( err == KErrNone )
   481             if  ( err == KErrNone )
   492                 {
   482                 {
   493                 TRACE( MemSpyDriverUtils::DataDump("possible chunk vtable data - %lS", allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength(), allocatorVTableBuffer.MaxLength() ) );
   483                 TBuf8<4> allocatorVTableBuffer;
   494                 allocatorVTableBuffer.SetLength( allocatorVTableBuffer.MaxLength() );
   484                 err = Kern::ThreadRawRead( firstThread, base, (TUint8*) allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength() );
   495                 
   485                 TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - read result of vtable data from requested thread is: %d", err ));
   496                 const TUint32 vtable =   allocatorVTableBuffer[0] +
   486                 //
   497                                         (allocatorVTableBuffer[1] << 8) + 
   487                 if  ( err == KErrNone )
   498                                         (allocatorVTableBuffer[2] << 16) + 
   488                     {
   499                                         (allocatorVTableBuffer[3] << 24);
   489                     TRACE( MemSpyDriverUtils::DataDump("possible chunk vtable data - %lS", allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength(), allocatorVTableBuffer.MaxLength() ) );
   500                 TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - [possible] vTable within chunk is: 0x%08x", vtable) );
   490                     allocatorVTableBuffer.SetLength( allocatorVTableBuffer.MaxLength() );
   501 
   491                     
   502                 // Check the v-table to work out if it really is an RHeap
   492                     const TUint32 vtable =   allocatorVTableBuffer[0] +
   503                 isHeap = ( vtable == rHeapVTable );
   493                                             (allocatorVTableBuffer[1] << 8) + 
   504                 TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - isHeap: %d", isHeap ) );
   494                                             (allocatorVTableBuffer[2] << 16) + 
       
   495                                             (allocatorVTableBuffer[3] << 24);
       
   496                     TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - [possible] vTable within chunk is: 0x%08x", vtable) );
       
   497 
       
   498                     // Check the v-table to work out if it really is an RHeap
       
   499                     isHeap = ( vtable == rHeapVTable );
       
   500                     TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - isHeap: %d", isHeap ) );
       
   501                     }
       
   502 
       
   503                 TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - closing first thread..." ) );
       
   504             	Kern::SafeClose( (DObject*&) firstThread, NULL );
   505                 }
   505                 }
   506 
   506             }
   507             TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - closing first thread..." ) );
       
   508             Kern::SafeClose( (DObject*&) firstThread, NULL );
       
   509             }
       
   510 		NKern::ThreadLeaveCS();
       
   511         }
   507         }
   512 
   508 
   513     /* We only want RHeap's at the moment
   509     /* We only want RHeap's at the moment
   514     if  ( !isHeap && aName == KMemSpyLitDollarHeap )
   510     if  ( !isHeap && aName == KMemSpyLitDollarHeap )
   515         {
   511         {