26 |
26 |
27 // User includes |
27 // User includes |
28 #include "MemSpyDriverObjectsInternal.h" |
28 #include "MemSpyDriverObjectsInternal.h" |
29 |
29 |
30 // Constants |
30 // Constants |
|
31 // We shouldn't be using any of these any more! -Tomsci |
31 const TUint KRHeapObjectSize = 0x74; |
32 const TUint KRHeapObjectSize = 0x74; |
32 const TUint KRAllocatorAndRHeapMemberDataOffset = 4; // 4 bytes past start of allocator address, i.e. skipping the vtable |
33 const TUint KRAllocatorAndRHeapMemberDataOffset = 4; // 4 bytes past start of allocator address, i.e. skipping the vtable |
33 const TUint KRHeapMemberDataSize = KRHeapObjectSize - KRAllocatorAndRHeapMemberDataOffset; |
34 const TUint KRHeapMemberDataSize = KRHeapObjectSize - KRAllocatorAndRHeapMemberDataOffset; |
34 |
35 |
35 // Classes referenced |
36 // Classes referenced |
36 class DMemSpyDriverOSAdaption; |
37 class DMemSpyDriverOSAdaption; |
37 |
38 namespace LtkUtils |
|
39 { |
|
40 class RAllocatorHelper; |
|
41 } |
38 |
42 |
39 /** |
43 /** |
40 * Essentially a mirror of RAllocator and RHeap's layout. |
44 * Essentially a mirror of RAllocator and RHeap's layout. |
41 */ |
45 */ |
42 class RMemSpyDriverRHeapBase |
46 class RMemSpyDriverRHeapBase |
43 { |
47 { |
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: |
48 protected: |
72 RMemSpyDriverRHeapBase(); |
49 RMemSpyDriverRHeapBase(); |
73 |
50 |
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 |
51 public: // API |
80 void PrintInfo(); |
52 void PrintInfo(); |
81 void CopyObjectDataTo( TMemSpyHeapObjectDataRHeap& aData ); |
53 LtkUtils::RAllocatorHelper* Helper(); |
|
54 TMemSpyHeapInfo::THeapImplementationType GetTypeFromHelper() const; |
82 |
55 |
83 public: // Virtual API |
56 public: // Virtual API |
84 virtual void Reset(); |
57 virtual void Reset(); |
85 virtual void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ) = 0; |
58 virtual void Close(); |
86 virtual void DisassociateWithKernelChunk() = 0; |
|
87 virtual DChunk& Chunk() = 0; |
59 virtual DChunk& Chunk() = 0; |
88 virtual const DChunk& Chunk() const = 0; |
60 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 |
61 |
94 public: // Utilities |
62 protected: |
95 TBool CheckCell( TAny* aCellAddress, TInt aLength ) const; |
63 LtkUtils::RAllocatorHelper* iHelper; |
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 }; |
64 }; |
130 |
65 |
131 |
66 |
132 |
67 |
133 |
68 |
135 { |
70 { |
136 protected: |
71 protected: |
137 RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ); |
72 RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption ); |
138 |
73 |
139 public: // New API |
74 public: // New API |
140 TInt ReadFromUserAllocator( DThread& aThread ); |
75 void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ); |
141 |
76 |
142 public: // From RMemSpyDriverRHeapBase |
77 public: // From RMemSpyDriverRHeapBase |
143 void Reset(); |
78 void Reset(); |
144 void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ); |
|
145 void DisassociateWithKernelChunk(); |
|
146 DChunk& Chunk(); |
79 DChunk& Chunk(); |
147 const DChunk& Chunk() const; |
80 const DChunk& Chunk() const; |
148 TLinAddr ChunkKernelAddress() const; |
|
149 TBool ChunkIsInitialised() const; |
|
150 TUint ClientToKernelDelta() const; |
|
151 |
81 |
152 protected: |
82 protected: |
153 inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; } |
83 inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; } |
154 |
84 |
155 private: |
85 private: |
160 TLinAddr iChunkAddress; |
90 TLinAddr iChunkAddress; |
161 TUint32 iChunkMappingAttributes; |
91 TUint32 iChunkMappingAttributes; |
162 |
92 |
163 // Calculated delta between client's address space values and actual kernel |
93 // Calculated delta between client's address space values and actual kernel |
164 // address of the heap chunk. |
94 // address of the heap chunk. |
165 TUint iClientToKernelDelta; |
95 //TUint iClientToKernelDelta; |
166 }; |
96 }; |
167 |
97 |
168 |
98 |
169 |
99 |
170 |
100 |
171 |
101 |
172 |
102 |
173 |
103 |
174 class RMemSpyDriverRHeapUser : public RMemSpyDriverRHeapReadFromCopy |
104 class RMemSpyDriverRHeapUser : public RMemSpyDriverRHeapBase |
175 { |
105 { |
176 public: |
106 public: |
177 RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption ); |
107 RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption ); |
|
108 TInt OpenUserHeap(DThread& aThread, TBool aEuserUdeb); |
178 |
109 |
179 public: // New API |
110 DChunk& Chunk() { return *iChunk; } |
180 TInt ReadFromUserAllocator( DThread& aThread ); |
111 const DChunk& Chunk() const { return *iChunk; } |
|
112 |
|
113 private: |
|
114 inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; } |
|
115 |
|
116 private: |
|
117 DMemSpyDriverOSAdaption& iOSAdaption; |
|
118 DChunk* iChunk; |
181 }; |
119 }; |
182 |
120 |
183 |
121 |
184 |
122 |
185 class RMemSpyDriverRHeapKernelFromCopy : public RMemSpyDriverRHeapReadFromCopy |
123 class RMemSpyDriverRHeapKernelFromCopy : public RMemSpyDriverRHeapReadFromCopy |
202 |
140 |
203 class RMemSpyDriverRHeapKernelInPlace : public RMemSpyDriverRHeapBase |
141 class RMemSpyDriverRHeapKernelInPlace : public RMemSpyDriverRHeapBase |
204 { |
142 { |
205 public: |
143 public: |
206 RMemSpyDriverRHeapKernelInPlace(); |
144 RMemSpyDriverRHeapKernelInPlace(); |
|
145 TInt OpenKernelHeap(); |
207 |
146 |
208 public: // API |
|
209 void FailNext(); |
|
210 void SetKernelHeap( RHeapK& aKernelHeap ); |
|
211 |
147 |
212 public: // From RMemSpyDriverRHeapBase |
148 public: // From RMemSpyDriverRHeapBase |
213 void Reset(); |
149 void Close(); |
214 void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ); |
150 |
215 void DisassociateWithKernelChunk(); |
|
216 DChunk& Chunk(); |
151 DChunk& Chunk(); |
217 const DChunk& Chunk() const; |
152 const DChunk& Chunk() const; |
218 TLinAddr ChunkKernelAddress() const; |
|
219 TBool ChunkIsInitialised() const; |
|
220 TUint ClientToKernelDelta() const; |
|
221 void GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const; |
|
222 |
153 |
223 private: // Internal methods |
154 // Only important member data is the base class's RAllocatorHelper |
224 void CopyMembersFromKernelHeap(); |
155 // We do cache the chunk though |
225 |
|
226 private: // Internal class |
|
227 |
|
228 /** |
|
229 * Used when opening the kernel heap |
|
230 */ |
|
231 #ifndef __SYMBIAN_KERNEL_HYBRID_HEAP__ |
|
232 class RHeapKExtended : public RHeapK |
|
233 { |
|
234 public: |
|
235 inline void FailNext() |
|
236 { |
|
237 SetFailType( RAllocator::EFailNext ); |
|
238 SetFailRate( 1 ); |
|
239 ResetFailed(); |
|
240 ResetFailAllocCount(); |
|
241 } |
|
242 inline void SetFailType( TAllocFail aType ) { iFailType = aType; } |
|
243 inline void SetFailRate( TInt aRate ) { iFailRate = aRate; } |
|
244 inline void ResetFailed() { iFailed = EFalse; } |
|
245 inline void ResetFailAllocCount() { iFailAllocCount = 0; } |
|
246 }; |
|
247 #endif |
|
248 private: |
156 private: |
249 RHeapK* iKernelHeap; |
157 DChunk* iChunk; |
250 DChunk* iChunk; |
|
251 }; |
158 }; |
252 |
159 |
253 |
160 |
254 #endif |
161 #endif |