30
|
1 |
// heaputils.h
|
|
2 |
//
|
|
3 |
// Copyright (c) 2010 Accenture. All rights reserved.
|
|
4 |
// This component and the accompanying materials are made available
|
|
5 |
// under the terms of the "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 |
// Accenture - Initial contribution
|
|
11 |
//
|
|
12 |
|
|
13 |
|
|
14 |
#ifndef FSHELL_HEAP_UTILS_H
|
|
15 |
#define FSHELL_HEAP_UTILS_H
|
|
16 |
|
|
17 |
#include <e32cmn.h>
|
|
18 |
|
|
19 |
#ifdef __KERNEL_MODE__
|
|
20 |
class DThread;
|
|
21 |
class DChunk;
|
|
22 |
#else
|
|
23 |
class RMemoryAccess;
|
|
24 |
#endif // __KERNEL_MODE__
|
|
25 |
|
|
26 |
#if defined(STANDALONE_ALLOCHELPER) || defined(__KERNEL_MODE__)
|
|
27 |
#define HUIMPORT_C
|
|
28 |
#define HUCLASS(x) NONSHARABLE_CLASS(x)
|
|
29 |
#else
|
|
30 |
#define HUIMPORT_C IMPORT_C
|
|
31 |
#define HUCLASS(x) class x
|
|
32 |
#endif
|
|
33 |
|
|
34 |
namespace LtkUtils
|
|
35 |
{
|
|
36 |
|
|
37 |
class THeapInfo;
|
|
38 |
|
|
39 |
HUCLASS(RAllocatorHelper) // class RAllocatorHelper
|
|
40 |
{
|
|
41 |
public:
|
|
42 |
HUIMPORT_C RAllocatorHelper();
|
|
43 |
#ifdef __KERNEL_MODE__
|
|
44 |
TInt OpenKernelHeap();
|
|
45 |
#else
|
|
46 |
HUIMPORT_C TInt Open(RAllocator* aAllocator);
|
|
47 |
#endif
|
|
48 |
HUIMPORT_C TInt SetCellNestingLevel(TAny* aCell, TInt aNestingLevel);
|
|
49 |
HUIMPORT_C TInt GetCellNestingLevel(TAny* aCell, TInt& aNestingLevel);
|
|
50 |
HUIMPORT_C TInt AllocCountForCell(TAny* aCell) const;
|
|
51 |
HUIMPORT_C TLinAddr AllocatorAddress() const;
|
|
52 |
HUIMPORT_C TInt RefreshDetails();
|
|
53 |
|
|
54 |
HUIMPORT_C TInt CommittedSize();
|
|
55 |
HUIMPORT_C TInt AllocatedSize();
|
|
56 |
HUIMPORT_C TInt AllocationCount();
|
|
57 |
HUIMPORT_C TInt MaxCommittedSize();
|
|
58 |
HUIMPORT_C TInt MinCommittedSize();
|
|
59 |
HUIMPORT_C TInt CountUnusedPages();
|
|
60 |
HUIMPORT_C TInt CommittedFreeSpace();
|
|
61 |
|
|
62 |
enum TCellType
|
|
63 |
{
|
|
64 |
EAllocation, EFreeSpace, EBadness
|
|
65 |
};
|
|
66 |
|
|
67 |
enum TExtendedCellType
|
|
68 |
{
|
|
69 |
EAllocationMask = 0xFF,
|
|
70 |
EFreeMask = 0xFF00,
|
|
71 |
EBadnessMask = 0xFF000000,
|
|
72 |
|
|
73 |
EHeapAllocation = 1,
|
|
74 |
EDlaAllocation = 2,
|
|
75 |
EPageAllocation = 3,
|
|
76 |
ESlabAllocation = 4,
|
|
77 |
|
|
78 |
EHeapFreeCell = 0x0100,
|
|
79 |
EDlaFreeCell = 0x0200,
|
|
80 |
// There is nothing 'free' in the page allocator
|
|
81 |
ESlabFreeCell = 0x0300, // Used to track free cells in partially-filled slabs
|
|
82 |
ESlabFreeSlab = 0x0400, // Used to track entirely empty slabs (that don't have a specific cell size)
|
|
83 |
|
|
84 |
EHeapBadFreeCellAddress = 0x01000000,
|
|
85 |
EHeapBadFreeCellSize = 0x02000000,
|
|
86 |
EHeapBadAllocatedCellSize = 0x03000000,
|
|
87 |
EHeapBadAllocatedCellAddress = 0x04000000,
|
|
88 |
};
|
|
89 |
|
|
90 |
// TBool WalkFunc(TAny* aContext, TCellType aCellType, TLinAddr aCellPtr, TInt aCellLength)
|
|
91 |
// aCellPtr points to the start of the cell payload for allocated cells (unlike RHeap's walker, which points to the cell header)
|
|
92 |
// aCellLength is the payload length, ie what AllocLen(aCellPtr) would return
|
|
93 |
// return ETrue to continue walking, EFalse to stop the walk
|
|
94 |
typedef TBool (*TWalkFunc)(TAny*, TCellType, TLinAddr, TInt);
|
|
95 |
typedef TBool (*TWalkFunc2)(RAllocatorHelper&, TAny*, TCellType, TLinAddr, TInt);
|
|
96 |
typedef TBool (*TWalkFunc3)(RAllocatorHelper&, TAny*, TExtendedCellType, TLinAddr, TInt);
|
|
97 |
HUIMPORT_C TInt Walk(TWalkFunc aCallbackFn, TAny* aContext);
|
|
98 |
HUIMPORT_C TInt Walk(TWalkFunc2 aCallbackFn, TAny* aContext); // Like the other but the walk func gives you the RAllocatorHelper pointer too
|
|
99 |
HUIMPORT_C TInt Walk(TWalkFunc3 aCallbackFn, TAny* aContext); // Like the other but the walk func gives you more details about the allocation type
|
|
100 |
HUIMPORT_C TInt SizeForCellType(TExtendedCellType aType);
|
|
101 |
HUIMPORT_C TInt CountForCellType(TExtendedCellType aType);
|
|
102 |
HUIMPORT_C TBool AllocatorIsUdeb() const;
|
|
103 |
HUIMPORT_C const TDesC& Description() const;
|
|
104 |
HUIMPORT_C virtual void Close();
|
|
105 |
|
|
106 |
#ifdef __KERNEL_MODE__
|
|
107 |
virtual DChunk* OpenUnderlyingChunk(); // Must be in CS
|
|
108 |
enum TType
|
|
109 |
{
|
|
110 |
ETypeUnknown,
|
|
111 |
ETypeRHeap,
|
|
112 |
ETypeRHybridHeap,
|
|
113 |
};
|
|
114 |
TType GetType() const; // This is for information only, nothing should care about the return value
|
|
115 |
#endif
|
|
116 |
|
|
117 |
protected:
|
|
118 |
TInt FinishConstruction();
|
|
119 |
TInt IdentifyAllocatorType(TBool aAllocatorIsUdeb);
|
|
120 |
TInt OpenChunkHeap(TLinAddr aChunkBase, TInt aChunkMaxSize);
|
|
121 |
#ifndef __KERNEL_MODE__
|
|
122 |
static TInt EuserIsUdeb();
|
|
123 |
#endif
|
|
124 |
virtual TInt ReadData(TLinAddr aLocation, TAny* aResult, TInt aSize) const;
|
|
125 |
virtual TInt WriteData(TLinAddr aLocation, const TAny* aData, TInt aSize);
|
|
126 |
virtual TInt TryLock();
|
|
127 |
virtual void TryUnlock();
|
|
128 |
|
|
129 |
private:
|
|
130 |
TInt ReadWord(TLinAddr aLocation, TUint32& aResult) const;
|
|
131 |
TInt ReadByte(TLinAddr aLocation, TUint8& aResult) const;
|
|
132 |
TInt WriteWord(TLinAddr aLocation, TUint32 aWord);
|
|
133 |
TInt RefreshDetails(TUint aMask);
|
|
134 |
TInt DoRefreshDetails(TUint aMask);
|
|
135 |
TInt CheckValid(TUint aMask);
|
|
136 |
TInt DoWalk(TWalkFunc3 aCallbackFn, TAny* aContext);
|
|
137 |
TInt OldSkoolWalk(TWalkFunc3 aCallbackFn, TAny* aContext);
|
|
138 |
TInt NewHotnessWalk(TWalkFunc3 aCallbackFn, TAny* aContext);
|
|
139 |
static TBool DispatchClientWalkCallback(RAllocatorHelper& aHelper, TAny* aContext, TExtendedCellType aCellType, TLinAddr aCellPtr, TInt aCellLength);
|
|
140 |
static TBool WalkForStats(RAllocatorHelper& aSelf, TAny* aContext, TExtendedCellType aType, TLinAddr aCellPtr, TInt aCellLength);
|
|
141 |
TUint PageMapOperatorBrackets(unsigned ix, TInt& err) const;
|
|
142 |
TInt PageMapFind(TUint start, TUint bit, TInt& err);
|
|
143 |
TUint PageMapBits(unsigned ix, unsigned len, TInt& err);
|
|
144 |
TUint PagedDecode(TUint pos, TInt& err);
|
|
145 |
TInt TreeWalk(TUint32 aSlabRoot, TInt aSlabType, TWalkFunc3 aCallbackFn, TAny* aContext, TBool& shouldContinue);
|
|
146 |
protected:
|
|
147 |
TLinAddr iAllocatorAddress;
|
|
148 |
enum TAllocatorType
|
|
149 |
{
|
|
150 |
EUnknown,
|
|
151 |
EAllocator,
|
|
152 |
EUrelOldRHeap,
|
|
153 |
EUdebOldRHeap,
|
|
154 |
EUrelHybridHeap,
|
|
155 |
EUdebHybridHeap,
|
|
156 |
};
|
|
157 |
TAllocatorType iAllocatorType;
|
|
158 |
private:
|
|
159 |
THeapInfo* iInfo;
|
|
160 |
TUint iValidInfo;
|
|
161 |
TUint8* iTempSlabBitmap;
|
|
162 |
mutable TAny* iPageCache;
|
|
163 |
mutable TLinAddr iPageCacheAddr;
|
|
164 |
#ifdef __KERNEL_MODE__
|
|
165 |
DChunk* iChunk;
|
|
166 |
//TUint iSpare[0];
|
|
167 |
#else
|
|
168 |
TUint iSpare[1];
|
|
169 |
#endif
|
|
170 |
};
|
|
171 |
|
|
172 |
#ifdef __KERNEL_MODE__
|
|
173 |
|
|
174 |
class RKernelSideAllocatorHelper : public RAllocatorHelper
|
|
175 |
{
|
|
176 |
public:
|
|
177 |
RKernelSideAllocatorHelper();
|
|
178 |
TInt OpenUserHeap(TUint aThreadId, TLinAddr aAllocatorAddress, TBool aEuserIsUdeb);
|
|
179 |
virtual DChunk* OpenUnderlyingChunk(); // Must be in CS
|
|
180 |
virtual void Close();
|
|
181 |
|
|
182 |
protected:
|
|
183 |
virtual TInt ReadData(TLinAddr aLocation, TAny* aResult, TInt aSize) const;
|
|
184 |
virtual TInt WriteData(TLinAddr aLocation, const TAny* aData, TInt aSize);
|
|
185 |
virtual TInt TryLock();
|
|
186 |
virtual void TryUnlock();
|
|
187 |
private:
|
|
188 |
DThread* iThread;
|
|
189 |
};
|
|
190 |
|
|
191 |
#else
|
|
192 |
|
|
193 |
class RProxyAllocatorHelper : public RAllocatorHelper
|
|
194 |
{
|
|
195 |
public:
|
|
196 |
HUIMPORT_C RProxyAllocatorHelper();
|
|
197 |
HUIMPORT_C TInt Open(RMemoryAccess& aMem, TUint aThreadId);
|
|
198 |
HUIMPORT_C TInt OpenChunkHeap(RMemoryAccess& aMem, TAny* aDChunkPtr);
|
|
199 |
HUIMPORT_C virtual void Close();
|
|
200 |
|
|
201 |
protected:
|
|
202 |
virtual TInt ReadData(TLinAddr aLocation, TAny* aResult, TInt aSize) const;
|
|
203 |
virtual TInt WriteData(TLinAddr aLocation, const TAny* aData, TInt aSize);
|
|
204 |
virtual TInt TryLock();
|
|
205 |
virtual void TryUnlock();
|
|
206 |
|
|
207 |
private:
|
|
208 |
RMemoryAccess* iMemoryAccess;
|
|
209 |
TUint iThreadId;
|
|
210 |
};
|
|
211 |
|
|
212 |
#endif // __KERNEL_MODE__
|
|
213 |
|
|
214 |
} // namespace LtkUtils
|
|
215 |
|
|
216 |
#endif
|