|
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 "MemSpyDriverInspectedProcessManager.h" |
|
19 |
|
20 // User includes |
|
21 #include "MemSpyDriverUtils.h" |
|
22 #include "MemSpyDriverDevice.h" |
|
23 #include "MemSpyDriverInspectedProcess.h" |
|
24 |
|
25 |
|
26 DMemSpyInspectedProcessManager::DMemSpyInspectedProcessManager() |
|
27 { |
|
28 } |
|
29 |
|
30 |
|
31 DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() |
|
32 { |
|
33 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - START")); |
|
34 NKern::ThreadEnterCS(); |
|
35 |
|
36 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - cancelling event monitor...")); |
|
37 EventMonitor().RequestEventsCancel( *this ); |
|
38 |
|
39 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - freeing all inspected processes...")); |
|
40 FreeAllInspectedProcesses(); |
|
41 |
|
42 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - closing auto-start SID list...")); |
|
43 iAutoStartSIDs.Close(); |
|
44 |
|
45 if ( iDevice ) |
|
46 { |
|
47 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - closing iDevice" )); |
|
48 iDevice->Close(NULL); |
|
49 } |
|
50 |
|
51 NKern::ThreadLeaveCS(); |
|
52 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::~DMemSpyInspectedProcessManager() - END")); |
|
53 } |
|
54 |
|
55 |
|
56 TInt DMemSpyInspectedProcessManager::Create( DMemSpyDriverDevice* aDevice ) |
|
57 { |
|
58 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::Create() - START" ) ); |
|
59 // |
|
60 TInt error = aDevice->Open(); |
|
61 if ( error == KErrNone ) |
|
62 { |
|
63 iDevice = aDevice; |
|
64 |
|
65 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::Create() - requesting events..." ) ); |
|
66 EventMonitor().RequestEvents( *this ); |
|
67 } |
|
68 // |
|
69 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::Create() - END - error: %d", error ) ); |
|
70 return error; |
|
71 } |
|
72 |
|
73 |
|
74 TInt DMemSpyInspectedProcessManager::ProcessOpen( DProcess* aProcess ) |
|
75 { |
|
76 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessOpen() - START - aProcess: 0x%08x (%O)", aProcess, aProcess ) ); |
|
77 NKern::ThreadEnterCS(); |
|
78 TInt error = KErrNotFound; |
|
79 // |
|
80 DMemSpyInspectedProcess* object = InspectedProcessByProcessId( aProcess->iId ); |
|
81 if ( object == NULL ) |
|
82 { |
|
83 object = new DMemSpyInspectedProcess( *iDevice ); |
|
84 // |
|
85 if ( object == NULL ) |
|
86 { |
|
87 error = KErrNoMemory; |
|
88 } |
|
89 else |
|
90 { |
|
91 error = object->Open( aProcess ); |
|
92 // |
|
93 if ( error == KErrNone ) |
|
94 { |
|
95 iMonitoredProcesses.Add( &object->iPMLink ); |
|
96 } |
|
97 else |
|
98 { |
|
99 delete object; |
|
100 } |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 error = KErrNone; |
|
106 } |
|
107 // |
|
108 NKern::ThreadLeaveCS(); |
|
109 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessOpen() - END - aProcess: 0x%08x, error: %d", aProcess, error ) ); |
|
110 return error; |
|
111 } |
|
112 |
|
113 |
|
114 TInt DMemSpyInspectedProcessManager::ProcessClose( DProcess* aProcess ) |
|
115 { |
|
116 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessClose() - START - aProcess: 0x%08x (%O)", aProcess, aProcess ) ); |
|
117 TInt error = KErrNotFound; |
|
118 // |
|
119 DMemSpyInspectedProcess* object = InspectedProcessByProcessId( aProcess->iId ); |
|
120 if ( object != NULL ) |
|
121 { |
|
122 NKern::ThreadEnterCS(); |
|
123 object->iPMLink.Deque(); |
|
124 delete object; |
|
125 NKern::ThreadLeaveCS(); |
|
126 error = KErrNone; |
|
127 } |
|
128 // |
|
129 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessClose() - END - aProcess: 0x%08x, error: %d", aProcess, error ) ); |
|
130 return error; |
|
131 } |
|
132 |
|
133 |
|
134 TInt DMemSpyInspectedProcessManager::ProcessCount() const |
|
135 { |
|
136 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessCount() - START" ) ); |
|
137 TInt ret = 0; |
|
138 // |
|
139 const SDblQueLink* const anchor = &iMonitoredProcesses.iA; |
|
140 for (SDblQueLink* link = iMonitoredProcesses.First(); link != anchor; link = link->iNext ) |
|
141 { |
|
142 ++ret; |
|
143 } |
|
144 // |
|
145 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::ProcessCount() - END - count: %d", ret ) ); |
|
146 return ret; |
|
147 } |
|
148 |
|
149 |
|
150 DMemSpyInspectedProcess* DMemSpyInspectedProcessManager::InspectedProcessByProcessId( TUint aProcessId ) |
|
151 { |
|
152 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::InspectedProcessByProcessId() - START - aProcessId: 0x%08x", aProcessId ) ); |
|
153 DMemSpyInspectedProcess* ret = 0; |
|
154 // |
|
155 const SDblQueLink* const anchor = &iMonitoredProcesses.iA; |
|
156 for (SDblQueLink* link = iMonitoredProcesses.First(); link != anchor; link = link->iNext ) |
|
157 { |
|
158 DMemSpyInspectedProcess* object = _LOFF( link, DMemSpyInspectedProcess, iPMLink ); |
|
159 // |
|
160 if ( object->ProcessId() == aProcessId ) |
|
161 { |
|
162 ret = object; |
|
163 break; |
|
164 } |
|
165 } |
|
166 // |
|
167 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::InspectedProcessByProcessId() - END - aProcessId: 0x%08x, ret: 0x%08x", aProcessId, ret ) ); |
|
168 return ret; |
|
169 } |
|
170 |
|
171 |
|
172 void DMemSpyInspectedProcessManager::AutoStartListReset() |
|
173 { |
|
174 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::AutoStartListReset() - START") ); |
|
175 NKern::ThreadEnterCS(); |
|
176 |
|
177 iAutoStartSIDs.Reset(); |
|
178 |
|
179 NKern::ThreadLeaveCS(); |
|
180 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::AutoStartListReset() - END") ); |
|
181 } |
|
182 |
|
183 |
|
184 TInt DMemSpyInspectedProcessManager::AutoStartListAdd( TUint aSID ) |
|
185 { |
|
186 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::AutoStartListAdd() - START - aSID: 0x%08x", aSID ) ); |
|
187 // |
|
188 NKern::ThreadEnterCS(); |
|
189 const TInt error = iAutoStartSIDs.Append( aSID ); |
|
190 NKern::ThreadLeaveCS(); |
|
191 // |
|
192 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::AutoStartListAdd() - END - error: %d", error ) ); |
|
193 return error; |
|
194 } |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 void DMemSpyInspectedProcessManager::FreeAllInspectedProcesses() |
|
202 { |
|
203 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::FreeAllInspectedProcesses() - START") ); |
|
204 |
|
205 SDblQueLink* link = iMonitoredProcesses.GetFirst(); |
|
206 while( link ) |
|
207 { |
|
208 DMemSpyInspectedProcess* object = _LOFF( link, DMemSpyInspectedProcess, iPMLink ); |
|
209 if ( object ) |
|
210 { |
|
211 delete object; |
|
212 } |
|
213 |
|
214 link = iMonitoredProcesses.GetFirst(); |
|
215 } |
|
216 |
|
217 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::FreeAllInspectedProcesses() - END") ); |
|
218 } |
|
219 |
|
220 |
|
221 DMemSpyEventMonitor& DMemSpyInspectedProcessManager::EventMonitor() |
|
222 { |
|
223 return iDevice->EventMonitor(); |
|
224 } |
|
225 |
|
226 |
|
227 TUint DMemSpyInspectedProcessManager::EMTypeMask() const |
|
228 { |
|
229 return EMemSpyEventProcessAdd; |
|
230 } |
|
231 |
|
232 |
|
233 void DMemSpyInspectedProcessManager::EMHandleProcessAdd( DProcess& aProcess ) |
|
234 { |
|
235 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::EMHandleProcessAdd() - START - aProcess: 0x%08x %O", &aProcess, &aProcess ) ); |
|
236 |
|
237 const TUint uid3 = aProcess.iUids.iUid[ 2 ].iUid; |
|
238 const TInt findResult = iAutoStartSIDs.Find( uid3 ); |
|
239 |
|
240 #ifdef _DEBUG |
|
241 const TUint uid1 = aProcess.iUids.iUid[ 0 ].iUid; |
|
242 const TUint uid2 = aProcess.iUids.iUid[ 1 ].iUid; |
|
243 Kern::Printf("DMemSpyInspectedProcessManager::EMHandleProcessAdd() - uids[ 0x%08x / 0x%08x / 0x%08x ], findResult: %d", uid1, uid2, uid3, findResult ); |
|
244 #endif |
|
245 // |
|
246 if ( findResult != KErrNotFound ) |
|
247 { |
|
248 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::EMHandleProcessAdd() - AUTO-START FOR PROCESS %O DETECTED", &aProcess ) ); |
|
249 const TInt error = ProcessOpen( &aProcess ); |
|
250 (void) error; |
|
251 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::EMHandleProcessAdd() - auto-start error: %d", error ) ); |
|
252 } |
|
253 // |
|
254 TRACE( Kern::Printf("DMemSpyInspectedProcessManager::EMHandleProcessAdd() - END" ) ); |
|
255 } |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |