51
|
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;
|
62
|
52 |
case LtkUtils::RAllocatorHelper::ETypeRHybridHeapV2:
|
|
53 |
return TMemSpyHeapInfo::ETypeRHybridHeapV2;
|
|
54 |
case LtkUtils::RAllocatorHelper::ETypeUnknown:
|
51
|
55 |
default:
|
|
56 |
return TMemSpyHeapInfo::ETypeUnknown;
|
|
57 |
}
|
|
58 |
}
|
|
59 |
return TMemSpyHeapInfo::ETypeUnknown;
|
|
60 |
}
|
|
61 |
|
|
62 |
void RMemSpyDriverRHeapBase::Reset()
|
|
63 |
{
|
|
64 |
Close();
|
|
65 |
}
|
|
66 |
|
|
67 |
void RMemSpyDriverRHeapBase::Close()
|
|
68 |
{
|
|
69 |
if (iHelper)
|
|
70 |
{
|
|
71 |
NKern::ThreadEnterCS();
|
|
72 |
iHelper->Close();
|
|
73 |
delete iHelper;
|
|
74 |
iHelper = NULL;
|
|
75 |
NKern::ThreadLeaveCS();
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
void RMemSpyDriverRHeapBase::PrintInfo()
|
|
80 |
{
|
|
81 |
/* TOMSCI TODO replace with tracing based on latest struct info. See DMemSpyDriverLogChanHeapBase::PrintHeapInfo
|
|
82 |
* Alternatively just call DMemSpyDriverLogChanHeapBase::PrintHeapInfo() somehow?
|
|
83 |
|
|
84 |
#if defined(TRACE_TYPE_KERNELHEAP) || defined(TRACE_TYPE_USERHEAP)
|
|
85 |
Kern::Printf(" " );
|
|
86 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iAccessCount: 0x%08x", iAccessCount );
|
|
87 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandleCount: 0x%08x", iHandleCount );
|
|
88 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iHandles: 0x%08x", iHandles );
|
|
89 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iFlags: 0x%08x", iFlags );
|
|
90 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iCellCount: 0x%08x", iCellCount );
|
|
91 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RAllocator - iTotalAllocSize: 0x%08x", iTotalAllocSize );
|
|
92 |
|
|
93 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinLength: 0x%08x", iMinLength );
|
|
94 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMaxLength: 0x%08x", iMaxLength );
|
|
95 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iOffset: 0x%08x", iOffset);
|
|
96 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iGrowBy: 0x%08x", iGrowBy);
|
|
97 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iChunkHandle: 0x%08x", iChunkHandle);
|
|
98 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iBase: 0x%08x", Base());
|
|
99 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iTop: 0x%08x", iTop );
|
|
100 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAlign: 0x%08x", iAlign);
|
|
101 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iMinCell: 0x%08x", iMinCell);
|
|
102 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iPageSize: 0x%08x", iPageSize);
|
|
103 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree len: 0x%08x", iFree.len);
|
|
104 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iFree next: 0x%08x", iFree.next);
|
|
105 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iNestingLevel: 0x%08x", iNestingLevel);
|
|
106 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - iAllocCount: 0x%08x", iAllocCount);
|
|
107 |
Kern::Printf("RMemSpyDriverRHeapBase::PrintInfo - RHeap - size: %8d", Size() );
|
|
108 |
Kern::Printf(" " );
|
|
109 |
Kern::Printf(" " );
|
|
110 |
#endif
|
|
111 |
*/
|
|
112 |
}
|
|
113 |
|
52
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
RMemSpyDriverRHeapUser::RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption )
|
|
118 |
: RMemSpyDriverRHeapBase(), iOSAdaption(aOSAdaption)
|
51
|
119 |
{
|
|
120 |
}
|
|
121 |
|
|
122 |
|
52
|
123 |
TInt RMemSpyDriverRHeapUser::OpenUserHeap(DThread& aThread, TBool aEuserUdeb)
|
|
124 |
{
|
|
125 |
TLinAddr allocatorAddr = (TLinAddr)OSAdaption().DThread().GetAllocator(aThread);
|
|
126 |
NKern::ThreadEnterCS();
|
|
127 |
LtkUtils::RUserAllocatorHelper* helper = new LtkUtils::RUserAllocatorHelper;
|
|
128 |
if (!helper)
|
|
129 |
{
|
|
130 |
NKern::ThreadLeaveCS();
|
|
131 |
return KErrNoMemory;
|
|
132 |
}
|
|
133 |
TInt err = helper->OpenUserHeap(OSAdaption().DThread().GetId(aThread), allocatorAddr, aEuserUdeb);
|
|
134 |
if (!err)
|
|
135 |
{
|
|
136 |
iChunk = helper->OpenUnderlyingChunk();
|
|
137 |
if (!iChunk) err = KErrNotFound;
|
|
138 |
}
|
|
139 |
if (err)
|
|
140 |
{
|
|
141 |
delete helper;
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
|
145 |
iHelper = helper;
|
|
146 |
}
|
|
147 |
NKern::ThreadLeaveCS();
|
|
148 |
return err;
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
RMemSpyDriverRHeapKernelFromCopy::RMemSpyDriverRHeapKernelFromCopy( DMemSpyDriverOSAdaption& aOSAdaption )
|
|
153 |
: iOSAdaption( aOSAdaption ), iChunk( NULL )
|
|
154 |
{
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
void RMemSpyDriverRHeapKernelFromCopy::Reset()
|
51
|
159 |
{
|
|
160 |
RMemSpyDriverRHeapBase::Reset();
|
|
161 |
//
|
|
162 |
iChunk = NULL;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
52
|
166 |
TInt RMemSpyDriverRHeapKernelFromCopy::AssociateWithKernelChunk( DChunk* aKernelChunk, DChunk* aCopiedChunk, TLinAddr aCopiedChunkBase, TInt aOffset )
|
51
|
167 |
{
|
52
|
168 |
TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::AssociateWithKernelChunk() - START - aChunk: 0x%08x, aOffset: %d",
|
|
169 |
aCopiedChunk, aOffset) );
|
|
170 |
|
|
171 |
iChunk = aCopiedChunk;
|
|
172 |
iChunkBase = aCopiedChunkBase;
|
51
|
173 |
|
|
174 |
NKern::ThreadEnterCS();
|
52
|
175 |
TInt ret = KErrNone;
|
|
176 |
LtkUtils::RKernelCopyAllocatorHelper* helper = new LtkUtils::RKernelCopyAllocatorHelper();
|
|
177 |
if (helper)
|
51
|
178 |
{
|
52
|
179 |
helper->OpenCopiedHeap(aKernelChunk, aCopiedChunk, aOffset);
|
|
180 |
iHelper = helper;
|
|
181 |
}
|
|
182 |
else
|
|
183 |
{
|
|
184 |
ret = KErrNoMemory;
|
51
|
185 |
}
|
|
186 |
NKern::ThreadLeaveCS();
|
52
|
187 |
|
|
188 |
TRACE_KH( Kern::Printf("RMemSpyDriverRHeapKernelFromCopy::AssociateWithKernelChunk() - END") );
|
|
189 |
return ret;
|
51
|
190 |
}
|
|
191 |
|
52
|
192 |
DChunk& RMemSpyDriverRHeapKernelFromCopy::Chunk()
|
51
|
193 |
{
|
|
194 |
return *iChunk;
|
|
195 |
}
|
|
196 |
|
|
197 |
|
52
|
198 |
const DChunk& RMemSpyDriverRHeapKernelFromCopy::Chunk() const
|
51
|
199 |
{
|
52
|
200 |
return *iChunk;
|
51
|
201 |
}
|
|
202 |
|
|
203 |
void RMemSpyDriverRHeapKernelFromCopy::Close()
|
|
204 |
{
|
52
|
205 |
if ( iChunk != NULL )
|
|
206 |
{
|
|
207 |
NKern::ThreadEnterCS();
|
|
208 |
Kern::ChunkClose( iChunk );
|
|
209 |
iChunk = NULL;
|
|
210 |
NKern::ThreadLeaveCS();
|
|
211 |
}
|
|
212 |
RMemSpyDriverRHeapBase::Close();
|
51
|
213 |
}
|
|
214 |
|
52
|
215 |
TBool RMemSpyDriverRHeapKernelFromCopy::IsOpen()
|
|
216 |
{
|
|
217 |
return (iChunk != NULL);
|
|
218 |
}
|
|
219 |
|
|
220 |
RMemSpyDriverRHeapKernelInPlace::RMemSpyDriverRHeapKernelInPlace( DMemSpyDriverOSAdaption& aOSAdaption )
|
|
221 |
: iOSAdaption( aOSAdaption ), iChunk( NULL )
|
51
|
222 |
{
|
|
223 |
}
|
|
224 |
|
|
225 |
TInt RMemSpyDriverRHeapKernelInPlace::OpenKernelHeap()
|
|
226 |
{
|
|
227 |
NKern::ThreadEnterCS();
|
|
228 |
LtkUtils::RAllocatorHelper* helper = new LtkUtils::RAllocatorHelper;
|
|
229 |
if (!helper)
|
|
230 |
{
|
|
231 |
NKern::ThreadLeaveCS();
|
|
232 |
return KErrNoMemory;
|
|
233 |
}
|
|
234 |
TInt err = helper->OpenKernelHeap();
|
|
235 |
if (!err)
|
|
236 |
{
|
|
237 |
iChunk = helper->OpenUnderlyingChunk();
|
|
238 |
if (!iChunk) err = KErrNotFound;
|
|
239 |
}
|
|
240 |
|
|
241 |
if (err)
|
|
242 |
{
|
|
243 |
delete helper;
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
iHelper = helper;
|
|
248 |
}
|
|
249 |
NKern::ThreadLeaveCS();
|
|
250 |
return err;
|
|
251 |
}
|
|
252 |
|
|
253 |
void RMemSpyDriverRHeapKernelInPlace::Close()
|
|
254 |
{
|
|
255 |
NKern::ThreadEnterCS();
|
|
256 |
iChunk->Close(NULL);
|
|
257 |
iChunk = NULL;
|
|
258 |
RMemSpyDriverRHeapBase::Close();
|
|
259 |
NKern::ThreadLeaveCS();
|
|
260 |
}
|
|
261 |
|
|
262 |
DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk()
|
|
263 |
{
|
|
264 |
return *iChunk;
|
|
265 |
}
|
|
266 |
|
|
267 |
|
|
268 |
const DChunk& RMemSpyDriverRHeapKernelInPlace::Chunk() const
|
|
269 |
{
|
|
270 |
return *iChunk;
|
|
271 |
}
|
|
272 |
|