51
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "MemSpyDriverLogChanClientServer.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <memspy/driver/memspydriverobjectsshared.h>
|
|
22 |
|
|
23 |
// Shared includes
|
|
24 |
#include "MemSpyDriverOpCodes.h"
|
|
25 |
#include "MemSpyDriverObjectsInternal.h"
|
|
26 |
|
|
27 |
// User includes
|
|
28 |
#include "MemSpyDriverUtils.h"
|
|
29 |
#include "MemSpyDriverOSAdaption.h"
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
DMemSpyDriverLogChanClientServer::DMemSpyDriverLogChanClientServer( DMemSpyDriverDevice& aDevice, DThread& aThread )
|
|
34 |
: DMemSpyDriverLogChanContainerBase( aDevice, aThread )
|
|
35 |
{
|
|
36 |
TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::DMemSpyDriverLogChanChunks() - this: 0x%08x", this ));
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer()
|
|
41 |
{
|
|
42 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer() - START - this: 0x%08x", this ));
|
|
43 |
|
|
44 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer() - END - this: 0x%08x", this ));
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
TInt DMemSpyDriverLogChanClientServer::Request( TInt aFunction, TAny* a1, TAny* a2 )
|
|
50 |
{
|
|
51 |
TInt r = DMemSpyDriverLogChanContainerBase::Request( aFunction, a1, a2 );
|
|
52 |
if ( r == KErrNone )
|
|
53 |
{
|
|
54 |
switch( aFunction )
|
|
55 |
{
|
|
56 |
case EMemSpyDriverOpCodeClientServerGetServerSessionHandles:
|
|
57 |
r = GetServerSessionHandles( (TMemSpyDriverInternalServerSessionHandleParams*) a1 );
|
|
58 |
break;
|
|
59 |
case EMemSpyDriverOpCodeClientServerGetServerSessionInfo:
|
|
60 |
r = GetServerSessionInfo( a1, (TMemSpyDriverServerSessionInfo*) a2 );
|
|
61 |
break;
|
|
62 |
|
|
63 |
default:
|
|
64 |
r = KErrNotSupported;
|
|
65 |
break;
|
|
66 |
}
|
|
67 |
}
|
|
68 |
//
|
|
69 |
return r;
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
TBool DMemSpyDriverLogChanClientServer::IsHandler( TInt aFunction ) const
|
|
74 |
{
|
|
75 |
return ( aFunction > EMemSpyDriverOpCodeClientServerBase && aFunction < EMemSpyDriverOpCodeClientServerEnd );
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
TInt DMemSpyDriverLogChanClientServer::GetServerSessionHandles( TMemSpyDriverInternalServerSessionHandleParams* aParams )
|
|
84 |
{
|
|
85 |
TMemSpyDriverInternalServerSessionHandleParams params;
|
|
86 |
TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverInternalServerSessionHandleParams) );
|
|
87 |
if ( r != KErrNone )
|
|
88 |
{
|
|
89 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - params read error: %d", r));
|
|
90 |
return r;
|
|
91 |
}
|
|
92 |
|
|
93 |
DMemSpyDriverOSAdaptionDServer& serverAdaption = OSAdaption().DServer();
|
|
94 |
|
|
95 |
const TInt maxCount = params.iMaxCount;
|
|
96 |
NKern::ThreadEnterCS();
|
|
97 |
|
|
98 |
DObject* serverHandle = (DObject*) params.iServerHandle;
|
|
99 |
DServer* server = static_cast<DServer*>(CheckedOpen(EMemSpyDriverContainerTypeServer, serverHandle));
|
|
100 |
if (server == NULL)
|
|
101 |
{
|
|
102 |
Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - server not found");
|
|
103 |
NKern::ThreadLeaveCS();
|
|
104 |
return KErrNotFound;
|
|
105 |
}
|
|
106 |
|
|
107 |
ResetTempHandles();
|
|
108 |
|
|
109 |
NKern::LockSystem(); // Iterating session queue requires system lock
|
|
110 |
// Iterate through this server's sessions, writing back session pointer (handle)
|
|
111 |
// to client
|
|
112 |
SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server );
|
|
113 |
SDblQueLink* anchor = &serverQueue.iA;
|
|
114 |
SDblQueLink* link = serverQueue.First();
|
|
115 |
while( link != anchor )
|
|
116 |
{
|
|
117 |
DSession* session = serverAdaption.GetSession( link );
|
|
118 |
|
|
119 |
// Found a match in the specified container. Write the object's handle (aka the object address)
|
|
120 |
// back to the client address space
|
|
121 |
if ( session )
|
|
122 |
{
|
|
123 |
AddTempHandle( session );
|
|
124 |
}
|
|
125 |
|
|
126 |
// Get next item
|
|
127 |
link = link->iNext;
|
|
128 |
}
|
|
129 |
NKern::UnlockSystem();
|
|
130 |
server->Close(NULL);
|
|
131 |
NKern::ThreadLeaveCS();
|
|
132 |
|
|
133 |
// This variable holds the number of handles that we have already
|
|
134 |
// written to the client-side.
|
|
135 |
TInt currentWriteIndex = 0;
|
|
136 |
const TInt handleCount = TempHandleCount();
|
|
137 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles - writing %d handles to client...", handleCount ) );
|
|
138 |
for( ; currentWriteIndex<handleCount && r == KErrNone && currentWriteIndex < maxCount; )
|
|
139 |
{
|
|
140 |
TAny* handle = TempHandleAt( currentWriteIndex );
|
|
141 |
r = Kern::ThreadRawWrite( &ClientThread(), params.iSessionHandles + currentWriteIndex, &handle, sizeof(TAny*) );
|
|
142 |
if (r == KErrNone)
|
|
143 |
{
|
|
144 |
++currentWriteIndex;
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
if ( r == KErrBadDescriptor )
|
|
149 |
{
|
|
150 |
MemSpyDriverUtils::PanicThread( ClientThread(), EPanicBadDescriptor );
|
|
151 |
}
|
|
152 |
else
|
|
153 |
{
|
|
154 |
const TInt finalWrite = Kern::ThreadRawWrite( &ClientThread(), params.iSessionCountPtr, ¤tWriteIndex, sizeof(TInt) );
|
|
155 |
if ( r == KErrNone )
|
|
156 |
{
|
|
157 |
r = finalWrite;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - r: %d", r));
|
|
163 |
return r;
|
|
164 |
}
|
|
165 |
|
|
166 |
|
|
167 |
TInt DMemSpyDriverLogChanClientServer::GetServerSessionInfo( TAny* aSessionHandle, TMemSpyDriverServerSessionInfo* aParams )
|
|
168 |
{
|
|
169 |
TMemSpyDriverServerSessionInfo params;
|
|
170 |
TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverServerSessionInfo) );
|
|
171 |
if ( r != KErrNone )
|
|
172 |
{
|
|
173 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - params read error: %d", r));
|
|
174 |
return r;
|
|
175 |
}
|
|
176 |
|
|
177 |
DMemSpyDriverOSAdaptionDSession& sessionAdaption = OSAdaption().DSession();
|
|
178 |
DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
|
|
179 |
DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
|
|
180 |
|
|
181 |
NKern::ThreadEnterCS();
|
|
182 |
|
|
183 |
DSession* session = (DSession*)CheckedOpen(EMemSpyDriverContainerTypeSession, (DObject*)aSessionHandle);
|
|
184 |
if (session == NULL )
|
|
185 |
{
|
|
186 |
Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - session not found");
|
|
187 |
NKern::ThreadLeaveCS();
|
|
188 |
return KErrNotFound;
|
|
189 |
}
|
|
190 |
|
|
191 |
session->FullName( params.iName );
|
|
192 |
|
|
193 |
// Get owner type and id
|
|
194 |
DObject* sessionOwner = sessionAdaption.GetOwner( *session );
|
|
195 |
if ( sessionOwner )
|
|
196 |
{
|
|
197 |
const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner );
|
|
198 |
if ( objectType == EProcess )
|
|
199 |
{
|
|
200 |
DProcess* sessionProcess = (DProcess*) sessionOwner;
|
|
201 |
//
|
|
202 |
params.iOwnerId = processAdaption.GetId( *sessionProcess );
|
|
203 |
params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess;
|
|
204 |
}
|
|
205 |
else if ( objectType == EThread )
|
|
206 |
{
|
|
207 |
DThread* sessionThread = (DThread*) sessionOwner;
|
|
208 |
//
|
|
209 |
params.iOwnerId = threadAdaption.GetId( *sessionThread );
|
|
210 |
params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
else
|
|
214 |
{
|
|
215 |
params.iOwnerId = -1;
|
|
216 |
params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone;
|
|
217 |
}
|
|
218 |
|
|
219 |
// Other attributes
|
|
220 |
params.iSessionType = sessionAdaption.GetSessionType( *session );
|
|
221 |
params.iAddress = (TUint8*)session;
|
|
222 |
session->Close(NULL);
|
|
223 |
NKern::ThreadLeaveCS();
|
|
224 |
r = Kern::ThreadRawWrite( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverServerSessionInfo) );
|
|
225 |
|
|
226 |
TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - r: %d", r));
|
|
227 |
return r;
|
|
228 |
}
|