|
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 "MemSpyDriverHeap.h" |
|
19 |
|
20 // System includes |
|
21 #include <kern_priv.h> |
|
22 |
|
23 // User includes |
|
24 #include "MemSpyDriverOSAdaption.h" |
|
25 #include "MemSpyDriverUtils.h" |
|
26 #include "heaputils.h" |
|
27 |
|
28 |
|
29 |
|
30 RMemSpyDriverRHeapBase::RMemSpyDriverRHeapBase() |
|
31 : iHelper(NULL) |
|
32 { |
|
33 Reset(); |
|
34 } |
|
35 |
|
36 LtkUtils::RAllocatorHelper* RMemSpyDriverRHeapBase::Helper() |
|
37 { |
|
38 return iHelper; |
|
39 } |
|
40 |
|
41 TMemSpyHeapInfo::THeapImplementationType RMemSpyDriverRHeapBase::GetTypeFromHelper() const |
|
42 { |
|
43 if (iHelper) |
|
44 { |
|
45 LtkUtils::RAllocatorHelper::TType type = iHelper->GetType(); |
|
46 switch (type) |
|
47 { |
|
48 case LtkUtils::RAllocatorHelper::ETypeRHeap: |
|
49 return TMemSpyHeapInfo::ETypeRHeap; |
|
50 case LtkUtils::RAllocatorHelper::ETypeRHybridHeap: |
|
51 return TMemSpyHeapInfo::ETypeRHybridHeap; |
|
52 case LtkUtils::RAllocatorHelper::ETypeUnknown: |
|
53 default: |
|
54 return TMemSpyHeapInfo::ETypeUnknown; |
|
55 } |
|
56 } |
|
57 return TMemSpyHeapInfo::ETypeUnknown; |
|
58 } |
|
59 |
|
60 void RMemSpyDriverRHeapBase::Reset() |
|
61 { |
|
62 Close(); |
|
63 } |
|
64 |
|
65 void RMemSpyDriverRHeapBase::Close() |
|
66 { |
|
67 if (iHelper) |
|
68 { |
|
69 NKern::ThreadEnterCS(); |
|
70 iHelper->Close(); |
|
71 delete iHelper; |
|
72 iHelper = NULL; |
|
73 NKern::ThreadLeaveCS(); |
|
74 } |
|
75 } |
|
76 |
|
77 void RMemSpyDriverRHeapBase::PrintInfo() |
|
78 { |
|
79 /* TOMSCI TODO replace with tracing based on latest struct info. See DMemSpyDriverLogChanHeapBase::PrintHeapInfo |
|
80 * Alternatively just call DMemSpyDriverLogChanHeapBase::PrintHeapInfo() somehow? |
|
81 |
|
82 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP) |
|
83 Kern::Printf(" " ); |
|
84 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount: 0x%08x", iAccessCount ); |
|
85 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount: 0x%08x", iHandleCount ); |
|
86 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles: 0x%08x", iHandles ); |
|
87 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iFlags: 0x%08x", iFlags ); |
|
88 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iCellCount: 0x%08x", iCellCount ); |
|
89 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iTotalAllocSize: 0x%08x", iTotalAllocSize ); |
|
90 |
|
91 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinLength: 0x%08x", iMinLength ); |
|
92 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMaxLength: 0x%08x", iMaxLength ); |
|
93 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iOffset: 0x%08x", iOffset); |
|
94 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iGrowBy: 0x%08x", iGrowBy); |
|
95 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iChunkHandle: 0x%08x", iChunkHandle); |
|
96 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iBase: 0x%08x", Base()); |
|
97 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iTop: 0x%08x", iTop ); |
|
98 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAlign: 0x%08x", iAlign); |
|
99 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinCell: 0x%08x", iMinCell); |
|
100 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iPageSize: 0x%08x", iPageSize); |
|
101 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree len: 0x%08x", iFree.len); |
|
102 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree next: 0x%08x", iFree.next); |
|
103 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iNestingLevel: 0x%08x", iNestingLevel); |
|
104 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAllocCount: 0x%08x", iAllocCount); |
|
105 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - size: %8d", Size() ); |
|
106 Kern::Printf(" " ); |
|
107 Kern::Printf(" " ); |
|
108 #endif |
|
109 */ |
|
110 } |
|
111 |
|
112 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
113 : iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ) /*, iClientToKernelDelta( 0 )*/ |
|
114 { |
|
115 } |
|
116 |
|
117 |
|
118 void RMemSpyDriverRHeapReadFromCopy::Reset() |
|
119 { |
|
120 RMemSpyDriverRHeapBase::Reset(); |
|
121 // |
|
122 iChunk = NULL; |
|
123 iChunkAddress = 0; |
|
124 iChunkMappingAttributes = 0; |
|
125 //iClientToKernelDelta = 0; |
|
126 } |
|
127 |
|
128 |
|
129 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ) |
|
130 { |
|
131 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk() - START - aChunk: %O, aChunk base: 0x%08x, aAddress: 0x%08x, clients heap base: 0x%08x, aChunk size: %8d", aChunk, aChunk->iBase, aAddress, Base(), aChunk->iSize ) ); |
|
132 |
|
133 iChunk = aChunk; |
|
134 iChunkAddress = aAddress; |
|
135 iChunkMappingAttributes = aMappingAttributes; |
|
136 |
|
137 // Calculate start of real heap data (skipping over embedded RHeap object) |
|
138 // Since we must operate with kernel-side addressing into our cloned heap chunk, |
|
139 // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase |
|
140 //TOMSCI iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize ); |
|
141 |
|
142 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk() - END - delta between client's user-side base address (base: 0x%08x), kernel-side base address (base: 0x%08x), and kernel-side chunk (base: 0x%08x) is: 0x%08x", Base(), aChunk->iBase, aAddress, iClientToKernelDelta) ); |
|
143 } |
|
144 |
|
145 |
|
146 /*void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() |
|
147 { |
|
148 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) ); |
|
149 |
|
150 NKern::ThreadEnterCS(); |
|
151 if ( iChunk != NULL ) |
|
152 { |
|
153 Kern::ChunkClose( iChunk ); |
|
154 iChunk = NULL; |
|
155 } |
|
156 NKern::ThreadLeaveCS(); |
|
157 |
|
158 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") ); |
|
159 } |
|
160 */ |
|
161 |
|
162 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk() |
|
163 { |
|
164 return *iChunk; |
|
165 } |
|
166 |
|
167 |
|
168 const DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk() const |
|
169 { |
|
170 return *iChunk; |
|
171 } |
|
172 |
|
173 |
|
174 /*TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const |
|
175 { |
|
176 return iChunkAddress; |
|
177 } |
|
178 |
|
179 |
|
180 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const |
|
181 { |
|
182 return iChunk != NULL; |
|
183 } |
|
184 |
|
185 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const |
|
186 { |
|
187 return iClientToKernelDelta; |
|
188 } |
|
189 */ |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
196 : RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption) |
|
197 { |
|
198 } |
|
199 |
|
200 |
|
201 TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb) |
|
202 { |
|
203 TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread); |
|
204 NKern::ThreadEnterCS(); |
|
205 LtkUtils::RKernelSideAllocatorHelper* helper = new LtkUtils::RKernelSideAllocatorHelper; |
|
206 if (!helper) |
|
207 { |
|
208 NKern::ThreadLeaveCS(); |
|
209 return KErrNoMemory; |
|
210 } |
|
211 TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb); |
|
212 if (!err) |
|
213 { |
|
214 iChunk = helper->OpenUnderlyingChunk(); |
|
215 if (!iChunk) err = KErrNotFound; |
|
216 } |
|
217 if (err) |
|
218 { |
|
219 delete helper; |
|
220 } |
|
221 else |
|
222 { |
|
223 iHelper = helper; |
|
224 } |
|
225 NKern::ThreadLeaveCS(); |
|
226 return err; |
|
227 } |
|
228 |
|
229 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
230 : RMemSpyDriverRHeapReadFromCopy( aOSAdaption ) |
|
231 { |
|
232 } |
|
233 |
|
234 |
|
235 void RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap( RHeapK& aKernelHeap ) |
|
236 { |
|
237 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - START" ) ); |
|
238 |
|
239 // Perform a copy operation in order to populate base class with a duplicate of the kernel's heap info. |
|
240 iKernelHeap = &aKernelHeap; |
|
241 |
|
242 // Source address |
|
243 TUint8* sourceAddress = (TUint8*) iKernelHeap + KRAllocatorAndRHeapMemberDataOffset; |
|
244 TUint8* destinationAddress = (TUint8*) this + KRAllocatorAndRHeapMemberDataOffset; |
|
245 |
|
246 // Copy |
|
247 memcpy( destinationAddress, sourceAddress, KRHeapMemberDataSize ); |
|
248 |
|
249 // And print info in debug builds for verification... |
|
250 PrintInfo(); |
|
251 |
|
252 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) ); |
|
253 } |
|
254 |
|
255 |
|
256 /* |
|
257 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() |
|
258 { |
|
259 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap )); |
|
260 iKernelHeap = NULL; |
|
261 RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk(); |
|
262 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") ); |
|
263 } |
|
264 */ |
|
265 |
|
266 void RMemSpyDriverRHeapKernelFromCopy::Close() |
|
267 { |
|
268 //TOMSCI TODO close the chunk |
|
269 } |
|
270 |
|
271 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace() |
|
272 : iChunk(NULL) |
|
273 { |
|
274 } |
|
275 |
|
276 TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap() |
|
277 { |
|
278 NKern::ThreadEnterCS(); |
|
279 LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper; |
|
280 if (!helper) |
|
281 { |
|
282 NKern::ThreadLeaveCS(); |
|
283 return KErrNoMemory; |
|
284 } |
|
285 TInt err = helper->OpenKernelHeap(); |
|
286 if (!err) |
|
287 { |
|
288 iChunk = helper->OpenUnderlyingChunk(); |
|
289 if (!iChunk) err = KErrNotFound; |
|
290 } |
|
291 |
|
292 if (err) |
|
293 { |
|
294 delete helper; |
|
295 } |
|
296 else |
|
297 { |
|
298 iHelper = helper; |
|
299 } |
|
300 NKern::ThreadLeaveCS(); |
|
301 return err; |
|
302 } |
|
303 |
|
304 void RMemSpyDriverRHeapKernelInPlace::Close() |
|
305 { |
|
306 NKern::ThreadEnterCS(); |
|
307 iChunk->Close(NULL); |
|
308 iChunk = NULL; |
|
309 RMemSpyDriverRHeapBase::Close(); |
|
310 NKern::ThreadLeaveCS(); |
|
311 } |
|
312 |
|
313 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() |
|
314 { |
|
315 return *iChunk; |
|
316 } |
|
317 |
|
318 |
|
319 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const |
|
320 { |
|
321 return *iChunk; |
|
322 } |
|
323 |