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 "MemSpyDriverLogChanBase.h" |
|
19 |
|
20 // System includes |
|
21 #include <u32hal.h> |
|
22 #include <kernel.h> |
|
23 #include <memspy/driver/memspydriverobjectsshared.h> |
|
24 |
|
25 // Shared includes |
|
26 #include "MemSpyDriverOpCodes.h" |
|
27 #include "MemSpyDriverObjectsInternal.h" |
|
28 |
|
29 // User includes |
|
30 #include "MemSpyDriverUtils.h" |
|
31 #include "MemSpyDriverDevice.h" |
|
32 #include "MemSpyDriverOSAdaption.h" |
|
33 #include "MemSpyDriverXferBuffer.h" |
|
34 |
|
35 |
|
36 |
|
37 DMemSpyDriverLogChanBase::DMemSpyDriverLogChanBase( DMemSpyDriverDevice& aDevice, DThread& aThread ) |
|
38 : iDevice( aDevice ), iClientThread( aThread ) |
|
39 { |
|
40 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::DMemSpyDriverLogChanBase() - this: 0x%08x", this )); |
|
41 } |
|
42 |
|
43 |
|
44 DMemSpyDriverLogChanBase::~DMemSpyDriverLogChanBase() |
|
45 { |
|
46 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::~DMemSpyDriverLogChanBase() - START - this: 0x%08x", this )); |
|
47 |
|
48 NKern::ThreadEnterCS(); |
|
49 |
|
50 if ( iTempObj != NULL ) |
|
51 { |
|
52 Kern::SafeClose( iTempObj, NULL ); |
|
53 } |
|
54 |
|
55 delete iXferBuffer; |
|
56 |
|
57 NKern::ThreadLeaveCS(); |
|
58 |
|
59 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::~DMemSpyDriverLogChanBase() - END - this: 0x%08x", this )); |
|
60 } |
|
61 |
|
62 |
|
63 TInt DMemSpyDriverLogChanBase::BaseConstruct( TInt aTransferBufferSize ) |
|
64 { |
|
65 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::BaseConstruct() - START - this: 0x%08x, aTransferBufferSize: %d", this, aTransferBufferSize )); |
|
66 TInt ret = KErrNone; |
|
67 // |
|
68 if ( aTransferBufferSize != 0 ) |
|
69 { |
|
70 iXferBuffer = new DMemSpyDriverXferBuffer( iDevice, iClientThread ); |
|
71 if ( !iXferBuffer ) |
|
72 { |
|
73 ret = KErrNoMemory; |
|
74 } |
|
75 else |
|
76 { |
|
77 ret = iXferBuffer->Construct( aTransferBufferSize ); |
|
78 if ( ret != KErrNone ) |
|
79 { |
|
80 delete iXferBuffer; |
|
81 iXferBuffer = NULL; |
|
82 } |
|
83 } |
|
84 } |
|
85 // |
|
86 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::BaseConstruct() - END - this: 0x%08x, aTransferBufferSize: %d, size: %d", this, aTransferBufferSize, iXferBuffer ? iXferBuffer->Size() : 0 )); |
|
87 return ret; |
|
88 } |
|
89 |
|
90 |
|
91 TInt DMemSpyDriverLogChanBase::Construct() |
|
92 { |
|
93 const TInt baseErr = BaseConstruct(); |
|
94 return baseErr; |
|
95 } |
|
96 |
|
97 |
|
98 TInt DMemSpyDriverLogChanBase::Request( TInt /*aFunction*/, TAny* /*a1*/, TAny* /*a2*/ ) |
|
99 { |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 DMemSpyDriverDevice& DMemSpyDriverLogChanBase::MemSpyDevice() |
|
110 { |
|
111 return iDevice; |
|
112 } |
|
113 |
|
114 |
|
115 DMemSpySuspensionManager& DMemSpyDriverLogChanBase::SuspensionManager() |
|
116 { |
|
117 return MemSpyDevice().SuspensionManager(); |
|
118 } |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 TInt DMemSpyDriverLogChanBase::OpenTempObject( TUint aId, TObjectType aType, TBool aAllowDeadObjects ) |
|
130 { |
|
131 __ASSERT_DEBUG( aType == EProcess || aType == EThread, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
132 __ASSERT_DEBUG( !iTempObj, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
133 |
|
134 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - START - aId: %d, aType: %d, aAllowDeadObjects: %d", aId, aType, aAllowDeadObjects )); |
|
135 DObjectCon* pC = Kern::Containers()[ aType ]; |
|
136 NKern::ThreadEnterCS(); |
|
137 pC->Wait(); |
|
138 iTempObj = (aType == EProcess) ? (DObject*) Kern::ProcessFromId( aId ) : (DObject*) Kern::ThreadFromId( aId ); |
|
139 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - kernel obj from id returned: 0x%08x %O", iTempObj, iTempObj )); |
|
140 // |
|
141 TBool openedOkay = EFalse; |
|
142 TInt r = KErrNone; |
|
143 // |
|
144 if ( iTempObj ) |
|
145 { |
|
146 r = iTempObj->Open(); |
|
147 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - open returned: %d", r )); |
|
148 // |
|
149 if ( r == KErrNone ) |
|
150 { |
|
151 openedOkay = ETrue; |
|
152 if ( aType == EProcess ) |
|
153 { |
|
154 // Check the process is still alive |
|
155 DProcess* process = (DProcess*) iTempObj; |
|
156 const TExitType exitType = OSAdaption().DProcess().GetExitType( *process ); |
|
157 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - process exitType: %d", exitType )); |
|
158 |
|
159 if ( !aAllowDeadObjects && exitType != EExitPending ) |
|
160 { |
|
161 r = KErrDied; |
|
162 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - PROCESS IS DEAD!" )); |
|
163 } |
|
164 } |
|
165 else if ( aType == EThread ) |
|
166 { |
|
167 // Check the thread is still alive |
|
168 DThread* thread = (DThread*) iTempObj; |
|
169 const TExitType exitType = OSAdaption().DThread().GetExitType( *thread ); |
|
170 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - thread exitType: %d", exitType )); |
|
171 |
|
172 if ( !aAllowDeadObjects && exitType != EExitPending ) |
|
173 { |
|
174 r = KErrDied; |
|
175 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - THREAD IS DEAD!" )); |
|
176 } |
|
177 } |
|
178 } |
|
179 |
|
180 } |
|
181 else if ( !iTempObj ) |
|
182 { |
|
183 r = KErrNotFound; |
|
184 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - ENTITY NOT FOUND!" )); |
|
185 } |
|
186 // |
|
187 pC->Signal(); |
|
188 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - signalled container..." )); |
|
189 NKern::ThreadLeaveCS(); |
|
190 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - left CS..." )); |
|
191 // |
|
192 if ( r != KErrNone && iTempObj ) |
|
193 { |
|
194 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - ERROR CASE - closing temp object (r: %d, openedOkay: %d)...", r, openedOkay )); |
|
195 // |
|
196 if ( openedOkay ) |
|
197 { |
|
198 CloseTempObject(); |
|
199 } |
|
200 else |
|
201 { |
|
202 NKern::SafeSwap( NULL, (TAny*&) iTempObj ); |
|
203 } |
|
204 // |
|
205 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - ERROR CASE - closed temp object" )); |
|
206 } |
|
207 // |
|
208 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenTempObject() - END - r: %d", r )); |
|
209 return r; |
|
210 } |
|
211 |
|
212 |
|
213 void DMemSpyDriverLogChanBase::CloseTempObject() |
|
214 { |
|
215 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::CloseTempObject() - START - iTempObj: 0x%08x %O", iTempObj, iTempObj )); |
|
216 |
|
217 __ASSERT_DEBUG( iTempObj, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
218 if ( iTempObj ) |
|
219 { |
|
220 NKern::ThreadEnterCS(); |
|
221 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::CloseTempObject() - in CS..." )); |
|
222 // |
|
223 Kern::SafeClose( iTempObj, NULL ); |
|
224 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::CloseTempObject() - done safe close..." )); |
|
225 // |
|
226 NKern::ThreadLeaveCS(); |
|
227 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::CloseTempObject() - left CS" )); |
|
228 } |
|
229 |
|
230 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::CloseTempObject() - END" )); |
|
231 } |
|
232 |
|
233 |
|
234 DThread& DMemSpyDriverLogChanBase::TempObjectAsThread() |
|
235 { |
|
236 __ASSERT_DEBUG( iTempObj, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
237 DThread* ret = (DThread*) iTempObj; |
|
238 return *ret; |
|
239 } |
|
240 |
|
241 |
|
242 DProcess& DMemSpyDriverLogChanBase::TempObjectAsProcess() |
|
243 { |
|
244 __ASSERT_DEBUG( iTempObj, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
245 DProcess* ret = (DProcess*) iTempObj; |
|
246 return *ret; |
|
247 } |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 RMemSpyMemStreamWriter DMemSpyDriverLogChanBase::OpenXferStream() |
|
265 { |
|
266 __ASSERT_ALWAYS( iXferBuffer, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
267 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - this: 0x%08x, xferSize: %d", this, iXferBuffer->Size() ) ); |
|
268 RMemSpyMemStreamWriter ret( *iXferBuffer ); |
|
269 return ret; |
|
270 } |
|
271 |
|
272 |
|
273 TInt DMemSpyDriverLogChanBase::OpenXferStream( RMemSpyMemStreamWriter& aWriter, TInt aRequiredSize ) |
|
274 { |
|
275 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - START - this: 0x%08x, xferSize: %d, aRequiredSize: %d", this, iXferBuffer->Size(), aRequiredSize ) ); |
|
276 __ASSERT_ALWAYS( iXferBuffer, MemSpyDriverUtils::Fault( __LINE__ ) ); |
|
277 |
|
278 TInt err = KErrNone; |
|
279 |
|
280 // Never make the buffer smaller - but we will make it bigger if needs be. |
|
281 if ( aRequiredSize > iXferBuffer->Size() ) |
|
282 { |
|
283 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - Need to grow Xfer buffer..." )); |
|
284 err = iXferBuffer->EnsureCapacity( aRequiredSize ); |
|
285 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - grow result: %d", err )); |
|
286 } |
|
287 // |
|
288 if ( err == KErrNone ) |
|
289 { |
|
290 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - creating writer... with xfer buffer size: %d", iXferBuffer->Size() )); |
|
291 aWriter = RMemSpyMemStreamWriter( *iXferBuffer ); |
|
292 } |
|
293 // |
|
294 TRACE( Kern::Printf("DMemSpyDriverLogChanBase::OpenXferStream() - END - this: 0x%08x, xferSize: %d, aRequiredSize: %d", this, iXferBuffer->Size(), aRequiredSize ) ); |
|
295 return err; |
|
296 } |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 DMemSpyDriverOSAdaption& DMemSpyDriverLogChanBase::OSAdaption() |
|
303 { |
|
304 return iDevice.OSAdaption(); |
|
305 } |
|
306 |
|