memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
--- a/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp	Wed Sep 15 13:53:27 2010 +0300
+++ b/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanChunks.cpp	Wed Oct 13 16:17:58 2010 +0300
@@ -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<processHandleCount && r == KErrNone && currentWriteIndex < maxCount; processHandleIndex++ )
     	    {
     	    // Get a handle from the process container...
-            MemSpyObjectIx_HandleLookupLock();
-			if (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; i<count; i++)
         {
+        NKern::LockSystem();
         DChunk* chunk = (DChunk*) (*container)[i];
+        NKern::UnlockSystem();
+        //
         if  ( chunk == params.iHandle )
             {
             foundChunk = chunk;
             TRACE( PrintChunkInfo( *chunk ) );
-			r = foundChunk->Open();
             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, &params, 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