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 |
|
80 #if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP) |
|
81 Kern::Printf(" " ); |
|
82 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount: 0x%08x", iAccessCount ); |
|
83 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount: 0x%08x", iHandleCount ); |
|
84 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles: 0x%08x", iHandles ); |
|
85 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iFlags: 0x%08x", iFlags ); |
|
86 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iCellCount: 0x%08x", iCellCount ); |
|
87 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iTotalAllocSize: 0x%08x", iTotalAllocSize ); |
|
88 |
|
89 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinLength: 0x%08x", iMinLength ); |
|
90 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMaxLength: 0x%08x", iMaxLength ); |
|
91 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iOffset: 0x%08x", iOffset); |
|
92 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iGrowBy: 0x%08x", iGrowBy); |
|
93 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iChunkHandle: 0x%08x", iChunkHandle); |
|
94 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iBase: 0x%08x", Base()); |
|
95 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iTop: 0x%08x", iTop ); |
|
96 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAlign: 0x%08x", iAlign); |
|
97 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinCell: 0x%08x", iMinCell); |
|
98 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iPageSize: 0x%08x", iPageSize); |
|
99 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree len: 0x%08x", iFree.len); |
|
100 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree next: 0x%08x", iFree.next); |
|
101 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iNestingLevel: 0x%08x", iNestingLevel); |
|
102 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAllocCount: 0x%08x", iAllocCount); |
|
103 Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - size: %8d", Size() ); |
|
104 Kern::Printf(" " ); |
|
105 Kern::Printf(" " ); |
|
106 #endif |
|
107 */ |
|
108 } |
|
109 |
|
110 RMemSpyDriverRHeapReadFromCopy::RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
111 : iOSAdaption( aOSAdaption ), iChunk( NULL ), iChunkAddress( 0 ), iChunkMappingAttributes( 0 ) /*, iClientToKernelDelta( 0 )*/ |
|
112 { |
|
113 } |
|
114 |
|
115 |
|
116 void RMemSpyDriverRHeapReadFromCopy::Reset() |
|
117 { |
|
118 RMemSpyDriverRHeapBase::Reset(); |
|
119 // |
|
120 iChunk = NULL; |
|
121 iChunkAddress = 0; |
|
122 iChunkMappingAttributes = 0; |
|
123 //iClientToKernelDelta = 0; |
|
124 } |
|
125 |
|
126 |
|
127 void RMemSpyDriverRHeapReadFromCopy::AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ) |
|
128 { |
|
129 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 ) ); |
|
130 |
|
131 iChunk = aChunk; |
|
132 iChunkAddress = aAddress; |
|
133 iChunkMappingAttributes = aMappingAttributes; |
|
134 |
|
135 // Calculate start of real heap data (skipping over embedded RHeap object) |
|
136 // Since we must operate with kernel-side addressing into our cloned heap chunk, |
|
137 // we must use aAddress (the kernel address of the chunk) rather than aChunk->iBase |
|
138 //TOMSCI iClientToKernelDelta = ( (TUint8*) aAddress ) - ( Base() - KRHeapObjectSize ); |
|
139 |
|
140 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) ); |
|
141 } |
|
142 |
|
143 |
|
144 /*void RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() |
|
145 { |
|
146 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - START - iChunk: 0x%08x", iChunk ) ); |
|
147 |
|
148 NKern::ThreadEnterCS(); |
|
149 if ( iChunk != NULL ) |
|
150 { |
|
151 Kern::ChunkClose( iChunk ); |
|
152 iChunk = NULL; |
|
153 } |
|
154 NKern::ThreadLeaveCS(); |
|
155 |
|
156 TRACE_HEAP( Kern::Printf("RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk() - END") ); |
|
157 } |
|
158 */ |
|
159 |
|
160 DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk() |
|
161 { |
|
162 return *iChunk; |
|
163 } |
|
164 |
|
165 |
|
166 const DChunk& RMemSpyDriverRHeapReadFromCopy::Chunk() const |
|
167 { |
|
168 return *iChunk; |
|
169 } |
|
170 |
|
171 |
|
172 /*TLinAddr RMemSpyDriverRHeapReadFromCopy::ChunkKernelAddress() const |
|
173 { |
|
174 return iChunkAddress; |
|
175 } |
|
176 |
|
177 |
|
178 TBool RMemSpyDriverRHeapReadFromCopy::ChunkIsInitialised() const |
|
179 { |
|
180 return iChunk != NULL; |
|
181 } |
|
182 |
|
183 TUint RMemSpyDriverRHeapReadFromCopy::ClientToKernelDelta() const |
|
184 { |
|
185 return iClientToKernelDelta; |
|
186 } |
|
187 */ |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
194 : RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption) |
|
195 { |
|
196 } |
|
197 |
|
198 |
|
199 TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb) |
|
200 { |
|
201 TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread); |
|
202 NKern::ThreadEnterCS(); |
|
203 LtkUtils::RKernelSideAllocatorHelper* helper = new LtkUtils::RKernelSideAllocatorHelper; |
|
204 if (!helper) |
|
205 { |
|
206 NKern::ThreadLeaveCS(); |
|
207 return KErrNoMemory; |
|
208 } |
|
209 TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb); |
|
210 if (!err) |
|
211 { |
|
212 iChunk = helper->OpenUnderlyingChunk(); |
|
213 if (!iChunk) err = KErrNotFound; |
|
214 } |
|
215 if (err) |
|
216 { |
|
217 delete helper; |
|
218 } |
|
219 else |
|
220 { |
|
221 iHelper = helper; |
|
222 } |
|
223 NKern::ThreadLeaveCS(); |
|
224 return err; |
|
225 } |
|
226 |
|
227 RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ) |
|
228 : RMemSpyDriverRHeapReadFromCopy( aOSAdaption ) |
|
229 { |
|
230 } |
|
231 |
|
232 |
|
233 void RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap( RHeapK& aKernelHeap ) |
|
234 { |
|
235 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - START" ) ); |
|
236 |
|
237 // Perform a copy operation in order to populate base class with a duplicate of the kernel's heap info. |
|
238 iKernelHeap = &aKernelHeap; |
|
239 |
|
240 // Source address |
|
241 TUint8* sourceAddress = (TUint8*) iKernelHeap + KRAllocatorAndRHeapMemberDataOffset; |
|
242 TUint8* destinationAddress = (TUint8*) this + KRAllocatorAndRHeapMemberDataOffset; |
|
243 |
|
244 // Copy |
|
245 memcpy( destinationAddress, sourceAddress, KRHeapMemberDataSize ); |
|
246 |
|
247 // And print info in debug builds for verification... |
|
248 PrintInfo(); |
|
249 |
|
250 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::SetKernelHeap() - END" ) ); |
|
251 } |
|
252 |
|
253 |
|
254 /* |
|
255 void RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() |
|
256 { |
|
257 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - START - iKernelHeap: 0x%08x", iKernelHeap )); |
|
258 iKernelHeap = NULL; |
|
259 RMemSpyDriverRHeapReadFromCopy::DisassociateWithKernelChunk(); |
|
260 TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::DisassociateWithKernelChunk() - END") ); |
|
261 } |
|
262 */ |
|
263 |
|
264 void RMemSpyDriverRHeapKernelFromCopy::Close() |
|
265 { |
|
266 //TOMSCI TODO close the chunk |
|
267 } |
|
268 |
|
269 RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace() |
|
270 : iChunk(NULL) |
|
271 { |
|
272 } |
|
273 |
|
274 TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap() |
|
275 { |
|
276 NKern::ThreadEnterCS(); |
|
277 LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper; |
|
278 if (!helper) |
|
279 { |
|
280 NKern::ThreadLeaveCS(); |
|
281 return KErrNoMemory; |
|
282 } |
|
283 TInt err = helper->OpenKernelHeap(); |
|
284 if (!err) |
|
285 { |
|
286 iChunk = helper->OpenUnderlyingChunk(); |
|
287 if (!iChunk) err = KErrNotFound; |
|
288 } |
|
289 |
|
290 if (err) |
|
291 { |
|
292 delete helper; |
|
293 } |
|
294 else |
|
295 { |
|
296 iHelper = helper; |
|
297 } |
|
298 NKern::ThreadLeaveCS(); |
|
299 return err; |
|
300 } |
|
301 |
|
302 void RMemSpyDriverRHeapKernelInPlace::Close() |
|
303 { |
|
304 NKern::ThreadEnterCS(); |
|
305 iChunk->Close(NULL); |
|
306 iChunk = NULL; |
|
307 RMemSpyDriverRHeapBase::Close(); |
|
308 NKern::ThreadLeaveCS(); |
|
309 } |
|
310 |
|
311 DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() |
|
312 { |
|
313 return *iChunk; |
|
314 } |
|
315 |
|
316 |
|
317 const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const |
|
318 { |
|
319 return *iChunk; |
|
320 } |
|
321 |
|