diff -r ca8a1b6995f6 -r 52e343bb8f80 memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp --- a/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp Tue Aug 31 16:45:49 2010 +0300 +++ b/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp Wed Sep 01 12:37:10 2010 +0100 @@ -164,18 +164,15 @@ // Iterate through each handle in the process MemSpyObjectIx* processHandles = processAdaption.GetHandles( *process ); - MemSpyObjectIx_HandleLookupLock(); + MemSpyObjectIx_Wait( processHandles ); + const TInt processHandleCount = processHandles->Count(); - MemSpyObjectIx_HandleLookupUnlock(); - for( TInt processHandleIndex = 0; processHandleIndex= processHandles->Count()) break; // Count may have changed in the meantime + NKern::LockSystem(); DObject* object = (*processHandles)[ processHandleIndex ]; - if (object && object->Open() != KErrNone) object = NULL; - MemSpyObjectIx_HandleLookupUnlock(); + NKern::UnlockSystem(); if ( object ) { @@ -190,10 +187,11 @@ ++currentWriteIndex; } } - object->Close(NULL); } } + MemSpyObjectIx_Signal( processHandles ); + // If we were asked for process-related chunks, also check the chunk container // for entries which we don't have handles to, but do refer to our process // Need a listing of all chunks in the system. Let client filter duplicates. @@ -278,36 +276,34 @@ NKern::ThreadEnterCS(); container->Wait(); + NKern::LockSystem(); const TInt count = container->Count(); + NKern::UnlockSystem(); DChunk* foundChunk = NULL; for(TInt i=0; iOpen(); break; } } container->Signal(); + NKern::ThreadLeaveCS(); if ( foundChunk == NULL ) { Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkInfo() - END - KErrNotFound - couldnt find chunk"); - NKern::ThreadLeaveCS(); return KErrNotFound; } - if (r) - { - Kern::Printf("DMemSpyDriverLogChanChunks::GetChunkInfo() - END - %d - Failed to open chunk", r); - NKern::ThreadLeaveCS(); - return r; - } // Prepare return data DMemSpyDriverOSAdaptionDChunk& chunkAdaption = OSAdaption().DChunk(); @@ -339,10 +335,6 @@ // Get type & attribs params.iType = IdentifyChunkType( *foundChunk ); params.iAttributes = chunkAdaption.GetAttributes( *foundChunk ); - - // Finished with foundChunk - foundChunk->Close(NULL); - NKern::ThreadLeaveCS(); // Write back to client r = Kern::ThreadRawWrite( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverInternalChunkInfoParams) ); @@ -478,36 +470,40 @@ if ( process && size >= 4 ) { - NKern::ThreadEnterCS(); // Chunks are mapped into entire process so any thread within the process is enough... - DThread* firstThread = processAdaption.OpenFirstThread( *process ); + DThread* firstThread = processAdaption.GetFirstThread( *process ); TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - firstThread: 0x%08x (%O)", firstThread, firstThread ) ); if ( firstThread != NULL ) { - TBuf8<4> allocatorVTableBuffer; - TInt err = Kern::ThreadRawRead( firstThread, base, (TUint8*) allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength() ); - TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - read result of vtable data from requested thread is: %d", err )); - // + TInt err = firstThread->Open(); + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - firstThread open result: %d", err ) ); + if ( err == KErrNone ) { - TRACE( MemSpyDriverUtils::DataDump("possible chunk vtable data - %lS", allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength(), allocatorVTableBuffer.MaxLength() ) ); - allocatorVTableBuffer.SetLength( allocatorVTableBuffer.MaxLength() ); - - const TUint32 vtable = allocatorVTableBuffer[0] + - (allocatorVTableBuffer[1] << 8) + - (allocatorVTableBuffer[2] << 16) + - (allocatorVTableBuffer[3] << 24); - TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - [possible] vTable within chunk is: 0x%08x", vtable) ); + TBuf8<4> allocatorVTableBuffer; + err = Kern::ThreadRawRead( firstThread, base, (TUint8*) allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength() ); + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - read result of vtable data from requested thread is: %d", err )); + // + if ( err == KErrNone ) + { + TRACE( MemSpyDriverUtils::DataDump("possible chunk vtable data - %lS", allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength(), allocatorVTableBuffer.MaxLength() ) ); + allocatorVTableBuffer.SetLength( allocatorVTableBuffer.MaxLength() ); + + const TUint32 vtable = allocatorVTableBuffer[0] + + (allocatorVTableBuffer[1] << 8) + + (allocatorVTableBuffer[2] << 16) + + (allocatorVTableBuffer[3] << 24); + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk - [possible] vTable within chunk is: 0x%08x", vtable) ); - // Check the v-table to work out if it really is an RHeap - isHeap = ( vtable == rHeapVTable ); - TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - isHeap: %d", isHeap ) ); - } + // Check the v-table to work out if it really is an RHeap + isHeap = ( vtable == rHeapVTable ); + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - isHeap: %d", isHeap ) ); + } - TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - closing first thread..." ) ); - Kern::SafeClose( (DObject*&) firstThread, NULL ); + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::IsHeapChunk() - closing first thread..." ) ); + Kern::SafeClose( (DObject*&) firstThread, NULL ); + } } - NKern::ThreadLeaveCS(); } /* We only want RHeap's at the moment