diff -r ca8a1b6995f6 -r 52e343bb8f80 memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp --- a/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp Tue Aug 31 16:45:49 2010 +0300 +++ b/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp Wed Sep 01 12:37:10 2010 +0100 @@ -96,8 +96,8 @@ NKern::ThreadEnterCS(); DObject* serverHandle = (DObject*) params.iServerHandle; - DServer* server = static_cast(CheckedOpen(EMemSpyDriverContainerTypeServer, serverHandle)); - if (server == NULL) + serverHandle = CheckIfObjectIsInContainer( EMemSpyDriverContainerTypeServer, serverHandle ); + if ( serverHandle == NULL ) { Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - server not found"); NKern::ThreadLeaveCS(); @@ -106,29 +106,47 @@ ResetTempHandles(); - NKern::LockSystem(); // Iterating session queue requires system lock - // Iterate through this server's sessions, writing back session pointer (handle) - // to client - SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server ); - SDblQueLink* anchor = &serverQueue.iA; - SDblQueLink* link = serverQueue.First(); - while( link != anchor ) + DServer* server = (DServer*) serverHandle; + NKern::LockSystem(); + + r = server->Open(); + if ( r == KErrNone ) { - DSession* session = serverAdaption.GetSession( link ); + // Iterate through this server's sessions, writing back session pointer (handle) + // to client + SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server ); + SDblQueLink* anchor = &serverQueue.iA; + SDblQueLink* link = serverQueue.First(); + while( link != anchor ) + { + DSession* session = serverAdaption.GetSession( link ); - // Found a match in the specified container. Write the object's handle (aka the object address) - // back to the client address space - if ( session ) - { - AddTempHandle( session ); + // Found a match in the specified container. Write the object's handle (aka the object address) + // back to the client address space + if ( session ) + { + AddTempHandle( session ); + } + + // Get next item + link = link->iNext; } - // Get next item - link = link->iNext; + NKern::ThreadEnterCS(); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - in CS..." )); + // + Kern::SafeClose( (DObject*&) server, NULL ); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - done safe close..." )); + // + NKern::ThreadLeaveCS(); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - left CS" )); } + else + { + Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles - error: %d opening server", r); + } + NKern::UnlockSystem(); - server->Close(NULL); - NKern::ThreadLeaveCS(); // This variable holds the number of handles that we have already // written to the client-side. @@ -158,6 +176,7 @@ } } + NKern::ThreadLeaveCS(); TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - r: %d", r)); return r; @@ -180,48 +199,74 @@ NKern::ThreadEnterCS(); - DSession* session = (DSession*)CheckedOpen(EMemSpyDriverContainerTypeSession, (DObject*)aSessionHandle); - if (session == NULL ) + DObject* sessionHandle = (DObject*) aSessionHandle; + sessionHandle = CheckIfObjectIsInContainer( EMemSpyDriverContainerTypeSession, sessionHandle ); + if ( sessionHandle == NULL ) { Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - session not found"); NKern::ThreadLeaveCS(); return KErrNotFound; } + DSession* session = (DSession*) sessionHandle; session->FullName( params.iName ); - // Get owner type and id - DObject* sessionOwner = sessionAdaption.GetOwner( *session ); - if ( sessionOwner ) + NKern::LockSystem(); + r = session->Open(); + if ( r == KErrNone ) { - const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner ); - if ( objectType == EProcess ) + // Get owner type and id + DObject* sessionOwner = sessionAdaption.GetOwner( *session ); + if ( sessionOwner ) { - DProcess* sessionProcess = (DProcess*) sessionOwner; - // - params.iOwnerId = processAdaption.GetId( *sessionProcess ); - params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess; + const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner ); + if ( objectType == EProcess ) + { + DProcess* sessionProcess = (DProcess*) sessionOwner; + // + params.iOwnerId = processAdaption.GetId( *sessionProcess ); + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess; + } + else if ( objectType == EThread ) + { + DThread* sessionThread = (DThread*) sessionOwner; + // + params.iOwnerId = threadAdaption.GetId( *sessionThread ); + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread; + } } - else if ( objectType == EThread ) + else { - DThread* sessionThread = (DThread*) sessionOwner; - // - params.iOwnerId = threadAdaption.GetId( *sessionThread ); - params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread; + params.iOwnerId = -1; + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone; } + + // Other attributes + params.iSessionType = sessionAdaption.GetSessionType( *session ); + params.iAddress = (TUint8*)session; + + NKern::ThreadEnterCS(); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - in CS..." )); + // + Kern::SafeClose( (DObject*&) session, NULL ); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - done safe close..." )); + // + NKern::ThreadLeaveCS(); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - left CS" )); } else { - params.iOwnerId = -1; - params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone; + Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo - error: %d opening server", r); } - // Other attributes - params.iSessionType = sessionAdaption.GetSessionType( *session ); - params.iAddress = (TUint8*)session; - session->Close(NULL); + NKern::UnlockSystem(); + + if ( r == KErrNone ) + { + r = Kern::ThreadRawWrite( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverServerSessionInfo) ); + } + NKern::ThreadLeaveCS(); - r = Kern::ThreadRawWrite( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverServerSessionInfo) ); TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - r: %d", r)); return r;