|
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 #ifndef MEMSPYDRIVERHEAP_H |
|
19 #define MEMSPYDRIVERHEAP_H |
|
20 |
|
21 // System includes |
|
22 #include <e32cmn.h> |
|
23 #include <kern_priv.h> |
|
24 #include <memspy/driver/memspydriverobjectsshared.h> |
|
25 #include <memspy/driver/memspydriverenumerationsshared.h> |
|
26 |
|
27 // User includes |
|
28 #include "MemSpyDriverObjectsInternal.h" |
|
29 |
|
30 // Constants |
|
31 const TUint KRHeapObjectSize = 0x74; |
|
32 const TUint KRAllocatorAndRHeapMemberDataOffset = 4; // 4 bytes past start of allocator address, i.e. skipping the vtable |
|
33 const TUint KRHeapMemberDataSize = KRHeapObjectSize - KRAllocatorAndRHeapMemberDataOffset; |
|
34 |
|
35 // Classes referenced |
|
36 class DMemSpyDriverOSAdaption; |
|
37 |
|
38 |
|
39 /** |
|
40 * Essentially a mirror of RAllocator and RHeap's layout. |
|
41 */ |
|
42 class RMemSpyDriverRHeapBase |
|
43 { |
|
44 public: |
|
45 struct SCell |
|
46 { |
|
47 TInt len; |
|
48 SCell* next; |
|
49 }; |
|
50 |
|
51 struct SDebugCell |
|
52 { |
|
53 TInt len; |
|
54 TInt nestingLevel; |
|
55 TInt allocCount; |
|
56 }; |
|
57 |
|
58 struct _s_align {char c; double d;}; |
|
59 |
|
60 struct SHeapCellInfo { RHeap* iHeap; TInt iTotalAlloc; TInt iTotalAllocSize; TInt iTotalFree; TInt iLevelAlloc; SDebugCell* iStranded; }; |
|
61 |
|
62 enum {ECellAlignment = sizeof(_s_align)-sizeof(double)}; |
|
63 enum {EFreeCellSize = sizeof(SCell)}; |
|
64 enum TDebugOp {EWalk=128}; |
|
65 enum TCellType |
|
66 {EGoodAllocatedCell, EGoodFreeCell, EBadAllocatedCellSize, EBadAllocatedCellAddress, |
|
67 EBadFreeCellAddress, EBadFreeCellSize}; |
|
68 |
|
69 enum TDebugHeapId {EUser=0, EKernel=1}; |
|
70 |
|
71 protected: |
|
72 RMemSpyDriverRHeapBase(); |
|
73 |
|
74 public: // Inlines |
|
75 inline TUint8* Base() const { return iBase; } |
|
76 inline TInt Size() const { return iTop - iBase; } |
|
77 inline TInt MaxLength() const { return iMaxLength; } |
|
78 |
|
79 public: // API |
|
80 void PrintInfo(); |
|
81 void CopyObjectDataTo( TMemSpyHeapObjectDataRHeap& aData ); |
|
82 |
|
83 public: // Virtual API |
|
84 virtual void Reset(); |
|
85 virtual void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ) = 0; |
|
86 virtual void DisassociateWithKernelChunk() = 0; |
|
87 virtual DChunk& Chunk() = 0; |
|
88 virtual const DChunk& Chunk() const = 0; |
|
89 virtual TLinAddr ChunkKernelAddress() const = 0; |
|
90 virtual TBool ChunkIsInitialised() const = 0; |
|
91 virtual TUint ClientToKernelDelta() const = 0; |
|
92 virtual void GetHeapSpecificInfo( TMemSpyHeapInfo& /*aInfo*/ ) const { } |
|
93 |
|
94 public: // Utilities |
|
95 TBool CheckCell( TAny* aCellAddress, TInt aLength ) const; |
|
96 static TInt AllocatedCellHeaderSize( TBool aDebugLibrary ); |
|
97 static TInt FreeCellHeaderSize(); |
|
98 static TInt CellHeaderSize( const TMemSpyDriverInternalWalkHeapParamsCell& aCell, TBool aDebugEUser ); |
|
99 |
|
100 public: // From RAllocator |
|
101 TInt iAccessCount; |
|
102 TInt iHandleCount; |
|
103 TInt* iHandles; |
|
104 TUint32 iFlags; |
|
105 TInt iCellCount; |
|
106 TInt iTotalAllocSize; |
|
107 |
|
108 public: // From RHeap |
|
109 TInt iMinLength; |
|
110 TInt iMaxLength; |
|
111 TInt iOffset; |
|
112 TInt iGrowBy; |
|
113 TInt iChunkHandle; |
|
114 RFastLock iLock; |
|
115 TUint8* iBase; |
|
116 TUint8* iTop; |
|
117 TInt iAlign; |
|
118 TInt iMinCell; |
|
119 TInt iPageSize; |
|
120 SCell iFree; |
|
121 TInt iNestingLevel; |
|
122 TInt iAllocCount; |
|
123 RAllocator::TAllocFail iFailType; |
|
124 TInt iFailRate; |
|
125 TBool iFailed; |
|
126 TInt iFailAllocCount; |
|
127 TInt iRand; |
|
128 TAny* iTestData; |
|
129 }; |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 class RMemSpyDriverRHeapReadFromCopy : public RMemSpyDriverRHeapBase |
|
135 { |
|
136 protected: |
|
137 RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ); |
|
138 |
|
139 public: // New API |
|
140 TInt ReadFromUserAllocator( DThread& aThread ); |
|
141 |
|
142 public: // From RMemSpyDriverRHeapBase |
|
143 void Reset(); |
|
144 void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ); |
|
145 void DisassociateWithKernelChunk(); |
|
146 DChunk& Chunk(); |
|
147 const DChunk& Chunk() const; |
|
148 TLinAddr ChunkKernelAddress() const; |
|
149 TBool ChunkIsInitialised() const; |
|
150 TUint ClientToKernelDelta() const; |
|
151 |
|
152 protected: |
|
153 inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; } |
|
154 |
|
155 private: |
|
156 DMemSpyDriverOSAdaption& iOSAdaption; |
|
157 |
|
158 // Copy of the client's heap data |
|
159 DChunk* iChunk; |
|
160 TLinAddr iChunkAddress; |
|
161 TUint32 iChunkMappingAttributes; |
|
162 |
|
163 // Calculated delta between client's address space values and actual kernel |
|
164 // address of the heap chunk. |
|
165 TUint iClientToKernelDelta; |
|
166 }; |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 class RMemSpyDriverRHeapUser : public RMemSpyDriverRHeapReadFromCopy |
|
175 { |
|
176 public: |
|
177 RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption ); |
|
178 |
|
179 public: // New API |
|
180 TInt ReadFromUserAllocator( DThread& aThread ); |
|
181 }; |
|
182 |
|
183 |
|
184 |
|
185 class RMemSpyDriverRHeapKernelFromCopy : public RMemSpyDriverRHeapReadFromCopy |
|
186 { |
|
187 public: |
|
188 RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ); |
|
189 |
|
190 public: // API |
|
191 void SetKernelHeap( RHeapK& aKernelHeap ); |
|
192 |
|
193 public: // From RMemSpyDriverRHeapBase |
|
194 void DisassociateWithKernelChunk(); |
|
195 void GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const; |
|
196 |
|
197 private: |
|
198 RHeapK* iKernelHeap; |
|
199 }; |
|
200 |
|
201 |
|
202 |
|
203 class RMemSpyDriverRHeapKernelInPlace : public RMemSpyDriverRHeapBase |
|
204 { |
|
205 public: |
|
206 RMemSpyDriverRHeapKernelInPlace(); |
|
207 |
|
208 public: // API |
|
209 void FailNext(); |
|
210 void SetKernelHeap( RHeapK& aKernelHeap ); |
|
211 |
|
212 public: // From RMemSpyDriverRHeapBase |
|
213 void Reset(); |
|
214 void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ); |
|
215 void DisassociateWithKernelChunk(); |
|
216 DChunk& Chunk(); |
|
217 const DChunk& Chunk() const; |
|
218 TLinAddr ChunkKernelAddress() const; |
|
219 TBool ChunkIsInitialised() const; |
|
220 TUint ClientToKernelDelta() const; |
|
221 void GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const; |
|
222 |
|
223 private: // Internal methods |
|
224 void CopyMembersFromKernelHeap(); |
|
225 |
|
226 private: // Internal class |
|
227 |
|
228 /** |
|
229 * Used when opening the kernel heap |
|
230 */ |
|
231 class RHeapKExtended : public RHeapK |
|
232 { |
|
233 public: |
|
234 inline void FailNext() |
|
235 { |
|
236 SetFailType( RAllocator::EFailNext ); |
|
237 SetFailRate( 1 ); |
|
238 ResetFailed(); |
|
239 ResetFailAllocCount(); |
|
240 } |
|
241 inline void SetFailType( TAllocFail aType ) { iFailType = aType; } |
|
242 inline void SetFailRate( TInt aRate ) { iFailRate = aRate; } |
|
243 inline void ResetFailed() { iFailed = EFalse; } |
|
244 inline void ResetFailAllocCount() { iFailAllocCount = 0; } |
|
245 }; |
|
246 |
|
247 private: |
|
248 RHeapK* iKernelHeap; |
|
249 DChunk* iChunk; |
|
250 }; |
|
251 |
|
252 |
|
253 #endif |