|
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 // Contributors: |
|
13 // Adrian Issott (Nokia) - Updates for RHybridHeap v2 |
|
14 // |
|
15 |
|
16 #ifndef FSHELL_HEAP_OFFSETS_H |
|
17 #define FSHELL_HEAP_OFFSETS_H |
|
18 |
|
19 #include <e32def.h> |
|
20 |
|
21 #if defined(TEST_HYBRIDHEAP_V1_ASSERTS) || defined(TEST_HYBRIDHEAP_V2_ASSERTS) |
|
22 #define TEST_HYBRIDHEAP_COMMON_ASSERTS |
|
23 #endif |
|
24 |
|
25 #ifdef TEST_HYBRIDHEAP_COMMON_ASSERTS |
|
26 #define private public |
|
27 #include <e32def.h> |
|
28 #endif |
|
29 |
|
30 #ifdef TEST_HYBRIDHEAP_V2_ASSERTS |
|
31 #include <e32panic.h> |
|
32 #include <kernel/heap_hybrid.h> |
|
33 #include "common.h" |
|
34 #include "heap_priv_defs.h" |
|
35 #include "dla.h" |
|
36 #endif |
|
37 |
|
38 #ifdef TEST_HYBRIDHEAP_COMMON_ASSERTS |
|
39 #include "slab.h" |
|
40 #include "page_alloc.h" |
|
41 #endif |
|
42 |
|
43 #ifdef TEST_HYBRIDHEAP_V1_ASSERTS |
|
44 #include <kernel/heap_hybrid.h> |
|
45 #endif |
|
46 |
|
47 |
|
48 /* |
|
49 * This header provides offsets for use with three different types of heap algorithms: |
|
50 * i) The original RHeap implemenation |
|
51 * (RHeap v1) |
|
52 * ii) The first RHybridHeap implemenation |
|
53 * (RHeap v2 + RHybridHeap v1) |
|
54 * iii) The second / refactored RHybridHeap implementation |
|
55 * (RHeap v2 + RHybridHeap v2 + RDlAllocator + RPageAllocator + RSlabHeapAllocator) |
|
56 */ |
|
57 namespace LtkUtils |
|
58 { |
|
59 |
|
60 // |
|
61 // OFFSETS COMMON TO ALL THREE HEAP CLASSES |
|
62 // |
|
63 |
|
64 class RHackAllocator : public RAllocator |
|
65 { |
|
66 public: |
|
67 using RAllocator::iHandles; |
|
68 using RAllocator::iTotalAllocSize; |
|
69 using RAllocator::iCellCount; |
|
70 }; |
|
71 |
|
72 class RHackHeap : public RHeap |
|
73 { |
|
74 public: |
|
75 // Careful, only allowed to use things that are in the same place for versions 1 and 2 of RHeap |
|
76 using RHeap::iMaxLength; |
|
77 using RHeap::iChunkHandle; |
|
78 using RHeap::iLock; |
|
79 using RHeap::iBase; |
|
80 using RHeap::iAlign; |
|
81 using RHeap::iTop; |
|
82 }; |
|
83 |
|
84 const TInt KChunkSizeOffset = 30*4; |
|
85 |
|
86 // |
|
87 // OFFSETS COMMON TO BOTH RHYBRIDHEAP CLASSES |
|
88 // |
|
89 |
|
90 namespace HeapV1 |
|
91 { |
|
92 |
|
93 const TInt KUserInitialHeapMetaDataSize = 34*4; |
|
94 |
|
95 } // namespace HeapV1 |
|
96 |
|
97 // |
|
98 // OFFSETS COMMON TO BOTH RHYBRIDHEAP CLASSES |
|
99 // |
|
100 |
|
101 namespace HybridCom |
|
102 { |
|
103 |
|
104 const TInt KMallocStateTopSizeOffset = 3*4; |
|
105 const TInt KMallocStateTopOffset = 5*4; |
|
106 const TInt KMallocStateSegOffset = 105*4; |
|
107 const TInt KSlabParentOffset = 1*4; |
|
108 const TInt KSlabChild1Offset = 2*4; |
|
109 const TInt KSlabChild2Offset = 3*4; |
|
110 const TInt KSlabPayloadOffset = 4*4; |
|
111 const TInt KSlabsetSize = 4; |
|
112 //const TInt KDlOnlyOffset = 33*4; |
|
113 |
|
114 #define MAXSLABSIZE 56 |
|
115 #define SLABSHIFT 10 |
|
116 #define SLABSIZE (1 << SLABSHIFT) |
|
117 const TInt KMaxSlabPayload = SLABSIZE - KSlabPayloadOffset; |
|
118 |
|
119 #ifdef TEST_HYBRIDHEAP_COMMON_ASSERTS |
|
120 __ASSERT_COMPILE(_FOFF(RHybridHeap, iChunkSize) == KChunkSizeOffset); |
|
121 __ASSERT_COMPILE(sizeof(malloc_state) == 107*4); |
|
122 #endif |
|
123 |
|
124 } // namespace HybridCom |
|
125 |
|
126 // |
|
127 // OFFSETS SPECIFIC TO THE RHYBRIDHEAP V1 CLASSES |
|
128 // |
|
129 |
|
130 namespace HybridV1 |
|
131 { |
|
132 |
|
133 const TInt KUserPageMapOffset = 141*4; |
|
134 const TInt KMallocStateOffset = 34*4; // same for user and kernel heaps |
|
135 const TInt KUserSparePageOffset = 167*4; |
|
136 const TInt KUserPartialPageOffset = 165*4; |
|
137 const TInt KUserFullSlabOffset = 166*4; |
|
138 const TInt KUserSlabAllocOffset = 172*4; |
|
139 |
|
140 const TInt KUserInitialHeapMetaDataSize = 186*4; |
|
141 |
|
142 __ASSERT_COMPILE(HeapV1::KUserInitialHeapMetaDataSize < KUserInitialHeapMetaDataSize); |
|
143 |
|
144 #ifdef TEST_HYBRIDHEAP_V1_ASSERTS |
|
145 |
|
146 const TInt KUserHybridHeapSize = KUserInitialHeapMetaDataSize; |
|
147 |
|
148 #ifndef __KERNEL_MODE__ |
|
149 __ASSERT_COMPILE(sizeof(RHybridHeap) == KUserHybridHeapSize); |
|
150 __ASSERT_COMPILE(_FOFF(RHybridHeap, iPageMap) == KUserPageMapOffset); |
|
151 __ASSERT_COMPILE(_FOFF(RHybridHeap, iSparePage) == KUserSparePageOffset); |
|
152 __ASSERT_COMPILE(_FOFF(RHybridHeap, iPartialPage) == KUserPartialPageOffset); |
|
153 __ASSERT_COMPILE(_FOFF(RHybridHeap, iSlabAlloc) == KUserSlabAllocOffset); |
|
154 __ASSERT_COMPILE(_FOFF(slab, iParent) == HybridCom::KSlabParentOffset); |
|
155 __ASSERT_COMPILE(_FOFF(slab, iChild1) == HybridCom::KSlabChild1Offset); |
|
156 __ASSERT_COMPILE(_FOFF(slab, iChild2) == HybridCom::KSlabChild2Offset); |
|
157 __ASSERT_COMPILE(_FOFF(slab, iPayload) == HybridCom::KSlabPayloadOffset); |
|
158 __ASSERT_COMPILE(sizeof(slabset) == HybridCom::KSlabsetSize); |
|
159 #endif |
|
160 __ASSERT_COMPILE(_FOFF(RHybridHeap, iGlobalMallocState) == KMallocStateOffset); |
|
161 __ASSERT_COMPILE(_FOFF(malloc_state, iTopSize) == HybridCom::KMallocStateTopSizeOffset); |
|
162 __ASSERT_COMPILE(_FOFF(malloc_state, iTop) == HybridCom::KMallocStateTopOffset); |
|
163 __ASSERT_COMPILE(_FOFF(malloc_state, iSeg) == HybridCom::KMallocStateSegOffset); |
|
164 |
|
165 #endif |
|
166 |
|
167 } // namespace HybridV1 |
|
168 |
|
169 // |
|
170 // OFFSETS SPECIFIC TO THE RHYBRIDHEAP V2 CLASSES |
|
171 // |
|
172 |
|
173 namespace HybridV2 |
|
174 { |
|
175 |
|
176 const TInt KUserPageMapOffset = 153*4; |
|
177 const TInt KUserMallocStateOffset = 45*4; |
|
178 const TInt KKernelMallocStateOffset = 37*4; |
|
179 const TInt KUserSparePageOffset = 175*4; |
|
180 const TInt KUserPartialPageOffset = 173*4; |
|
181 const TInt KUserFullSlabOffset = 174*4; |
|
182 const TInt KUserSlabAllocOffset = 180*4; |
|
183 const TInt KSelfReferenceOffset = 34*4; // same for user and kernel heaps |
|
184 const TInt KUserInitialHeapMetaDataSize = 194 * 4; |
|
185 const TInt KKernelInitialHeapMetaDataSize = 144 * 4; |
|
186 |
|
187 __ASSERT_COMPILE(HeapV1::KUserInitialHeapMetaDataSize < KUserInitialHeapMetaDataSize); |
|
188 __ASSERT_COMPILE(HeapV1::KUserInitialHeapMetaDataSize < KKernelInitialHeapMetaDataSize); |
|
189 __ASSERT_COMPILE(KSelfReferenceOffset == HybridV1::KMallocStateOffset); |
|
190 |
|
191 #ifdef TEST_HYBRIDHEAP_V2_ASSERTS |
|
192 |
|
193 const TInt KUserHybridHeapSize = 44*4; |
|
194 const TInt KUserDlAllocatorOffset = KUserHybridHeapSize; |
|
195 const TInt KUserPageAllocatorOffset = 152 * 4; |
|
196 const TInt KUserSlabAllocatorOffset = 172 * 4; |
|
197 |
|
198 const TInt KKernelHybridHeapSize = 36*4; |
|
199 const TInt KKernelDlAllocatorOffset = KKernelHybridHeapSize; |
|
200 |
|
201 |
|
202 #ifndef __KERNEL_MODE__ |
|
203 __ASSERT_COMPILE(sizeof(RHybridHeap) == KUserHybridHeapSize); |
|
204 __ASSERT_COMPILE(sizeof(RDlAllocator) == KUserPageAllocatorOffset - KUserDlAllocatorOffset); |
|
205 __ASSERT_COMPILE(_FOFF(RDlAllocator, iDlaState) == KUserMallocStateOffset - KUserHybridHeapSize); |
|
206 __ASSERT_COMPILE(sizeof(RPageAllocator) == KUserSlabAllocatorOffset - KUserPageAllocatorOffset); |
|
207 __ASSERT_COMPILE(sizeof(RSlabHeapAllocator) == KUserInitialHeapMetaDataSize - KUserSlabAllocatorOffset); |
|
208 __ASSERT_COMPILE(sizeof(RHybridHeap) + sizeof(RDlAllocator) + sizeof(RPageAllocator) + sizeof(RSlabHeapAllocator) == KUserInitialHeapMetaDataSize); |
|
209 __ASSERT_COMPILE(_FOFF(RPageAllocator, iPageMap) == KUserPageMapOffset - KUserPageAllocatorOffset); |
|
210 __ASSERT_COMPILE(_FOFF(RSlabHeapAllocator, iSparePage) == KUserSparePageOffset - KUserSlabAllocatorOffset); |
|
211 __ASSERT_COMPILE(_FOFF(RSlabHeapAllocator, iPartialPage) == KUserPartialPageOffset - KUserSlabAllocatorOffset); |
|
212 __ASSERT_COMPILE(_FOFF(RSlabHeapAllocator, iSlabAlloc) == KUserSlabAllocOffset - KUserSlabAllocatorOffset); |
|
213 __ASSERT_COMPILE(_FOFF(TSlab, iParent) == HybridCom::KSlabParentOffset); |
|
214 __ASSERT_COMPILE(_FOFF(TSlab, iChild1) == HybridCom::KSlabChild1Offset); |
|
215 __ASSERT_COMPILE(_FOFF(TSlab, iChild2) == HybridCom::KSlabChild2Offset); |
|
216 __ASSERT_COMPILE(_FOFF(TSlab, iPayload) == HybridCom::KSlabPayloadOffset); |
|
217 __ASSERT_COMPILE(sizeof(TSlabSet) == HybridCom::KSlabsetSize); |
|
218 #endif |
|
219 __ASSERT_COMPILE(sizeof(RHybridHeap) == KKernelHybridHeapSize); |
|
220 __ASSERT_COMPILE(_FOFF(RDlAllocator, iDlaState) == KKernelMallocStateOffset - KKernelHybridHeapSize); |
|
221 __ASSERT_COMPILE(_FOFF(malloc_state, topsize) == HybridCom::KMallocStateTopSizeOffset); |
|
222 __ASSERT_COMPILE(_FOFF(malloc_state, top) == HybridCom::KMallocStateTopOffset); |
|
223 __ASSERT_COMPILE(_FOFF(malloc_state, seg) == HybridCom::KMallocStateSegOffset); |
|
224 |
|
225 #endif |
|
226 |
|
227 } // namespace HybridV2 |
|
228 |
|
229 } // namespace LtkUtils |
|
230 |
|
231 #endif // FSHELL_HEAP_OFFSETS_H |