memspy/Driver/Kernel/Source/MemSpyDriverInspectedProcess.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
--- a/memspy/Driver/Kernel/Source/MemSpyDriverInspectedProcess.cpp	Tue Aug 31 16:45:49 2010 +0300
+++ b/memspy/Driver/Kernel/Source/MemSpyDriverInspectedProcess.cpp	Wed Sep 01 12:37:10 2010 +0100
@@ -78,7 +78,6 @@
 
 TInt DMemSpyInspectedProcess::Open( DProcess* aProcess )
     {
-	__ASSERT_CRITICAL;
     TRACE( Kern::Printf("DMemSpyInspectedProcess::Open() - START - this: 0x%08x, aProcess: 0x%08x (%O)", this, aProcess, aProcess ));
 
     TInt error = KErrNone;
@@ -129,7 +128,7 @@
 
 TInt DMemSpyInspectedProcess::NotifyOnChange( DThread* aThread, TRequestStatus* aRequestStatus, TMemSpyDriverProcessInspectionInfo* aInfo )
     {
-	Lock();
+	Kern::MutexWait( *iLock );
 
     TInt err = KErrInUse;
     const TBool notificationQueued = NotifyOnChangeQueued();
@@ -159,7 +158,9 @@
 			CompleteClientsRequest( KErrNone, &cachedChange->iInfo );
 			
 			// Discard cached entry
+            NKern::ThreadEnterCS();
 			delete cachedChange;
+            NKern::ThreadLeaveCS();
 			}
         else if ( iAmDead )
             {
@@ -173,14 +174,14 @@
 	//
     TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChange() - END - this: 0x%08x, err: %d", this, err ) );
 
-	Unlock();
+	Kern::MutexSignal( *iLock );
     return err;
     }
 
 
 TInt DMemSpyInspectedProcess::NotifyOnChangeCancel()
     {
-	Lock();
+	Kern::MutexWait( *iLock );
     TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeCancel() - START - this: 0x%08x, queued: %d, iChangeObserverThread: 0x%08x, iChangeObserverRS: 0x%08x", this, NotifyOnChangeQueued(), iChangeObserverThread, iChangeObserverRS ) );
     //
     if  ( NotifyOnChangeQueued() )
@@ -193,7 +194,7 @@
         }
 	//
     TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeCancel() - END - this: 0x%08x", this ) );
-	Unlock();
+	Kern::MutexSignal( *iLock );
 
     return KErrNone;
     }
@@ -203,9 +204,9 @@
     {
     TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeQueued() - START - this: 0x%08x", this ) );
     //
-	Lock();
+	Kern::MutexWait( *iLock );
     const TBool queued = ( iChangeObserverRS != NULL );
-	Unlock();
+	Kern::MutexSignal( *iLock );
     //
     TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeQueued() - END - this: 0x%08x, queued: %d", this, queued ) );
     return queued;
@@ -448,9 +449,10 @@
     const TUint procId = iDevice.OSAdaption().DProcess().GetId( aProcess );
     if  ( procId == iProcessId )
         {
-	    Lock();
+	    Kern::MutexWait( *iLock );
 
         TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessUpdated() - START - this: 0x%08x, iProcess: 0x%08x (%O)", this, iProcess, iProcess ) );
+	    NKern::ThreadEnterCS();
 
         // Mark all tracked chunks as dirty whilst we work out
         // what is and isn't mapped into the process
@@ -474,9 +476,10 @@
             CompleteClientsRequest( KErrNone, &iInfoCurrent );
             }
 
+        NKern::ThreadLeaveCS();
         TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessUpdated() - END - this: 0x%08x", this ) );
 
-        Unlock();
+        Kern::MutexSignal( *iLock );
         }
     }
 
@@ -488,9 +491,10 @@
 
     if  ( pid == iProcessId )
         {
-	    Lock();
+	    Kern::MutexWait( *iLock );
 
         TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessRemoved() - START - this: 0x%08x", this ) );
+	    NKern::ThreadEnterCS();
 
         // We will implement a multi phased approach to the process being removed.
         //
@@ -525,9 +529,10 @@
         // Stop listening to events since we've drained everything now...
         iAmDead = ETrue;
 
+        NKern::ThreadLeaveCS();
         TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessRemoved() - END - this: 0x%08x", this ) );
 
-        Unlock();
+        Kern::MutexSignal( *iLock );
         }
     }
 
@@ -595,7 +600,7 @@
 
 void DMemSpyInspectedProcess::EMHandleThreadChanged( DThread& /*aThread*/ )
     {
-	Lock();
+	Kern::MutexWait( *iLock );
 
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadChanged() - START - this: 0x%08x", this ) );
 
@@ -603,6 +608,7 @@
     // We must be careful to only access the members of aThread that still
     // exist as if it is being destroyed, the object may be in an intermediate
     // state.
+	NKern::ThreadEnterCS();
 
     // All we are really interested in is recalculating the stack usage
     // for the process... 
@@ -611,17 +617,19 @@
     // Always inform observer about new results.
     CompleteClientsRequest( KErrNone, &iInfoCurrent );
 
+    NKern::ThreadLeaveCS();
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadChanged() - END - this: 0x%08x", this ) );
 
-    Unlock();
+    Kern::MutexSignal( *iLock );
     }
 
 
 void DMemSpyInspectedProcess::EMHandleChunkAdd( DChunk& aChunk )
     {
-	Lock();
+	Kern::MutexWait( *iLock );
 
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - START - this: 0x%08x, aChunk: 0x%08x (%O)", this, &aChunk, &aChunk ) );
+	NKern::ThreadEnterCS();
 
     // Is this chunk related to our process somehow?
     if  ( IsChunkRelevantToOurProcess( aChunk ) )
@@ -648,17 +656,19 @@
             }
         }
 
+    NKern::ThreadLeaveCS();
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - END - this: 0x%08x", this ) );
 
-    Unlock();
+    Kern::MutexSignal( *iLock );
     }
 
 
 void DMemSpyInspectedProcess::EMHandleChunkUpdated( DChunk& aChunk )
     {
-	Lock();
+	Kern::MutexWait( *iLock );
 
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - START - this: 0x%08x, aChunk: 0x%08x [S: %8d] (%O)", this, &aChunk, aChunk.Size(), &aChunk ) );
+	NKern::ThreadEnterCS();
 
     // Is this chunk mapped into our process?
     TMemSpyTrackedChunk* trackedEntry = TrackedChunkByHandle( &aChunk );
@@ -702,17 +712,19 @@
             }
         }
 
+    NKern::ThreadLeaveCS();
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - END - this: 0x%08x", this ) );
 
-    Unlock();
+    Kern::MutexSignal( *iLock );
     }
 
 
 void DMemSpyInspectedProcess::EMHandleChunkDeleted( DChunk& aChunk )
     {
-	Lock();
+	Kern::MutexWait( *iLock );
 
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkDeleted() - START - this: 0x%08x", this ) );
+	NKern::ThreadEnterCS();
 
     // Is this chunk mapped into our process?
     TMemSpyTrackedChunk* trackedEntry = TrackedChunkByHandle( &aChunk );
@@ -730,9 +742,10 @@
             }
         }
 
+    NKern::ThreadLeaveCS();
     TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkDeleted() - END - this: 0x%08x", this ) );
 
-    Unlock();
+    Kern::MutexSignal( *iLock );
     }
 
 
@@ -871,7 +884,6 @@
         TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - firstThread: 0x%08x (%O)", firstThread, firstThread ) );
         if  ( firstThread != NULL )
             {
-			NKern::ThreadEnterCS();
             TInt err = firstThread->Open();
             TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - firstThread open result: %d", err ) );
 
@@ -900,7 +912,6 @@
                 TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - closing first thread..." ) );
             	Kern::SafeClose( (DObject*&) firstThread, NULL );
                 }
-			NKern::ThreadLeaveCS();
             }
         }
     //
@@ -1105,7 +1116,6 @@
 
 void DMemSpyInspectedProcess::FindChunks( DProcess& aProcess )
     {
-	__ASSERT_CRITICAL;
     TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - START - this: 0x%08x", this ) );
   
     DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
@@ -1115,11 +1125,9 @@
     if  ( processAdaption.IsHandleIndexValid( aProcess ) )
         {
 	    MemSpyObjectIx* processHandles = processAdaption.GetHandles( aProcess );
-		
-		MemSpyObjectIx_HandleLookupLock();
+        MemSpyObjectIx_Wait( processHandles );
+
         const TInt count = processHandles->Count();
-		MemSpyObjectIx_HandleLookupUnlock();
-
         TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - got: %d handles...", count ) );
 
 	    for( TInt i=0; i<count; i++ )
@@ -1127,11 +1135,9 @@
             TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - checking handle index: %2d", i ) );
 
     	    // Get a handle from the process container...
-            MemSpyObjectIx_HandleLookupLock();
-			if (i >= processHandles->Count()) break; // Count may have changed in the meantime
+            NKern::LockSystem();
     	    DObject* object = (*processHandles)[ i ];
-			if (object && object->Open() != KErrNone) object = NULL;
-			MemSpyObjectIx_HandleLookupUnlock();
+            NKern::UnlockSystem();
 
             const TObjectType objectType = ( object ? chunkAdaption.GetObjectType( *object ) : EObjectTypeAny );
             TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - object: 0x%08x, type: %2d (%O)", object, objectType, object ) );
@@ -1173,8 +1179,9 @@
                         }
                     }
                 }
-			if (object) object->Close(NULL);
     	    }
+
+        MemSpyObjectIx_Signal( processHandles );
         }
 
     TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - END - this: 0x%08x", this ) );
@@ -1228,17 +1235,6 @@
     }
 
 
-void DMemSpyInspectedProcess::Lock() const
-	{
-	NKern::ThreadEnterCS();
-	Kern::MutexWait(*iLock);
-	}
-
-void DMemSpyInspectedProcess::Unlock() const
-	{
-	Kern::MutexSignal(*iLock);
-	NKern::ThreadLeaveCS();
-	}