author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
14 |
// kernel\eka\common\alloc.cpp |
0 | 15 |
// |
16 |
// |
|
17 |
||
18 |
#include "common.h" |
|
19 |
#include <e32atomics.h> |
|
20 |
||
21 |
||
22 |
#ifndef __KERNEL_MODE__ |
|
23 |
/** |
|
24 |
Opens this heap for shared access. |
|
25 |
||
26 |
Opening the heap increases the heap's access count by one. |
|
27 |
||
28 |
@return KErrNone if successful; |
|
29 |
KErrGeneral, if the original valeu of the access count |
|
30 |
was not positive. |
|
31 |
*/ |
|
32 |
EXPORT_C TInt RAllocator::Open() |
|
33 |
{ |
|
34 |
TInt c = __e32_atomic_tas_ord32(&iAccessCount, 1, 1, 0); |
|
35 |
return (c>0) ? KErrNone : KErrGeneral; |
|
36 |
} |
|
37 |
||
38 |
||
39 |
||
40 |
||
41 |
/** |
|
42 |
Closes this shared heap. |
|
43 |
||
44 |
Closing the heap decreases the heap's access count by one. |
|
45 |
||
46 |
@panic USER 57 if the access count has already reached zero. |
|
47 |
*/ |
|
48 |
EXPORT_C void RAllocator::Close() |
|
49 |
{ |
|
50 |
TInt count = __e32_atomic_tas_ord32(&iAccessCount, 1, -1, 0); |
|
51 |
__ASSERT_ALWAYS(count>0, Panic(EAllocatorClosedTooManyTimes)); |
|
52 |
if (count==1) |
|
53 |
DoClose(); |
|
54 |
} |
|
55 |
||
56 |
||
57 |
||
58 |
/** |
|
59 |
@internalComponent |
|
60 |
*/ |
|
61 |
EXPORT_C void RAllocator::DoClose() |
|
62 |
{ |
|
63 |
__ASSERT_ALWAYS(TUint32(iHandleCount)<=TUint32(EMaxHandles), Panic(EAllocatorBadHandleCount)); |
|
64 |
TInt handle[EMaxHandles]; |
|
65 |
TInt c = iHandleCount; |
|
66 |
wordmove(handle, iHandles, c*sizeof(TInt)); |
|
67 |
memclr(iHandles, c*sizeof(TInt)); |
|
68 |
TInt* pH = handle; |
|
69 |
TInt* pE = pH + c; |
|
70 |
while (pH<pE) |
|
71 |
{ |
|
72 |
RHandleBase h; |
|
73 |
h.SetHandle(*pH++); |
|
74 |
h.Close(); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
||
79 |
||
80 |
||
81 |
/** |
|
82 |
Allocates a cell of specified size from the heap, and clears |
|
83 |
it to binary zeroes. |
|
84 |
||
85 |
If there is insufficient memory available on the heap from which to |
|
86 |
allocate a cell of the required size, the function returns NULL. |
|
87 |
||
88 |
The resulting size of the allocated cell may be rounded up to a value greater |
|
89 |
than aSize, but is guaranteed to be not less than aSize. |
|
90 |
||
91 |
@param aSize The size of the cell to be allocated from the current thread's |
|
92 |
heap. |
|
93 |
||
94 |
@return A pointer to the allocated cell. NULL, if there is insufficient memory |
|
95 |
available. |
|
96 |
||
97 |
@panic USER 47 if the maximum unsigned value of aSize is greater |
|
98 |
than or equal to KMaxTInt/2. For example, |
|
99 |
calling Alloc(-1) raises this panic. |
|
100 |
*/ |
|
101 |
EXPORT_C TAny* RAllocator::AllocZ(TInt aSize) |
|
102 |
{ |
|
103 |
TAny* p = Alloc(aSize); |
|
104 |
if (p) |
|
105 |
Mem::FillZ(p, aSize); |
|
106 |
return p; |
|
107 |
} |
|
108 |
||
109 |
||
110 |
||
111 |
||
112 |
/** |
|
113 |
Allocates a cell of specified size from the heap, clears it to |
|
114 |
binary zeroes, and leaves if there is insufficient memory in the heap. |
|
115 |
||
116 |
The resulting size of the allocated cell may be rounded up to a value greater |
|
117 |
than aSize, but is guaranteed to be not less than aSize. |
|
118 |
||
119 |
@param aSize The size of the cell to be allocated from the heap. |
|
120 |
||
121 |
@return A pointer to the allocated cell. |
|
122 |
||
123 |
@panic USER 47 if the maximum unsigned value of aSize is greater |
|
124 |
than or equal to KMaxTInt/2. For example, |
|
125 |
calling Alloc(-1) raises this panic. |
|
126 |
*/ |
|
127 |
EXPORT_C TAny* RAllocator::AllocZL(TInt aSize) |
|
128 |
{ |
|
129 |
TAny* p = AllocL(aSize); |
|
130 |
Mem::FillZ(p, aSize); |
|
131 |
return p; |
|
132 |
} |
|
133 |
||
134 |
||
135 |
||
136 |
||
137 |
/** |
|
138 |
Allocates a cell of specified size from the heap, and leaves |
|
139 |
if there is insufficient memory in the heap. |
|
140 |
||
141 |
The resulting size of the allocated cell may be rounded up to a value greater |
|
142 |
than aSize, but is guaranteed to be not less than aSize. |
|
143 |
||
144 |
@param aSize The size of the cell to be allocated from the heap. |
|
145 |
||
146 |
@return A pointer to the allocated cell. |
|
147 |
||
148 |
@panic USER 47 if the maximum unsigned value of aSize is greater |
|
149 |
than or equal to KMaxTInt/2. For example, |
|
150 |
calling Alloc(-1) raises this panic. |
|
151 |
*/ |
|
152 |
EXPORT_C TAny* RAllocator::AllocL(TInt aSize) |
|
153 |
{ |
|
154 |
TAny* p = Alloc(aSize); |
|
155 |
if (!p) |
|
156 |
User::LeaveNoMemory(); |
|
157 |
return p; |
|
158 |
} |
|
159 |
||
160 |
||
161 |
||
162 |
||
163 |
/** |
|
164 |
Allocates a cell of specified size from the heap, and, |
|
165 |
if successful, places a pointer to the cell onto the cleanup stack. |
|
166 |
||
167 |
The function leaves if there is insufficient memory in the heap. |
|
168 |
||
169 |
The resulting size of the allocated cell may be rounded up to a value greater |
|
170 |
than aSize, but is guaranteed to be not less than aSize. |
|
171 |
||
172 |
@param aSize The size of the cell to be allocated from the heap. |
|
173 |
||
174 |
@return A pointer to the allocated cell. |
|
175 |
||
176 |
@panic USER 47 if the maximum unsigned value of aSize is greater |
|
177 |
than or equal to KMaxTInt/2. For example, |
|
178 |
calling Alloc(-1) raises this panic. |
|
179 |
*/ |
|
180 |
EXPORT_C TAny* RAllocator::AllocLC(TInt aSize) |
|
181 |
{ |
|
182 |
TAny* p = AllocL(aSize); |
|
183 |
CleanupStack::PushL(p); |
|
184 |
return p; |
|
185 |
} |
|
186 |
||
187 |
||
188 |
||
189 |
||
190 |
/** |
|
191 |
Frees the specified cell, returns it to the heap, and resets |
|
192 |
the pointer to NULL. |
|
193 |
||
194 |
@param aCell A reference to a pointer to a valid cell to be freed. If NULL |
|
195 |
this function call will be ignored. |
|
196 |
||
197 |
@panic USER 42 if aCell is not NULL and does not point to a valid cell. |
|
198 |
*/ |
|
199 |
EXPORT_C void RAllocator::FreeZ(TAny*& aCell) |
|
200 |
{ |
|
201 |
Free(aCell); |
|
202 |
aCell = NULL; |
|
203 |
} |
|
204 |
||
205 |
||
206 |
||
207 |
||
208 |
/** |
|
209 |
Increases or decreases the size of an existing cell, and leaves |
|
210 |
if there is insufficient memory in the heap. |
|
211 |
||
212 |
If the cell is being decreased in size, then it is guaranteed not to move, |
|
213 |
and the function returns the pointer originally passed in aCell. Note that the |
|
214 |
length of the cell will be the same if the difference between the old size |
|
215 |
and the new size is smaller than the minimum cell size. |
|
216 |
||
217 |
If the cell is being increased in size, i.e. aSize is bigger than its |
|
218 |
current size, then the function tries to grow the cell in place. |
|
219 |
If successful, then the function returns the pointer originally |
|
220 |
passed in aCell. If unsuccessful, then: |
|
221 |
||
222 |
1. if the cell cannot be moved, i.e. aMode has the ENeverMove bit set, then |
|
223 |
the function leaves. |
|
224 |
2. if the cell can be moved, i.e. aMode does not have the ENeverMove bit set, |
|
225 |
then the function tries to allocate a new replacement cell, and, if |
|
226 |
successful, returns a pointer to the new cell; if unsuccessful, it |
|
227 |
leaves. |
|
228 |
||
229 |
Note that in debug mode, the function leaves if the cell cannot be grown |
|
230 |
in place, regardless of whether the ENeverMove bit is set. |
|
231 |
||
232 |
If the reallocated cell is at a different location from the original cell, then |
|
233 |
the content of the original cell is copied to the reallocated cell. |
|
234 |
||
235 |
Note the following general points: |
|
236 |
||
237 |
1. If reallocation fails, the content of the original cell is preserved. |
|
238 |
||
239 |
2. The resulting size of the re-allocated cell may be rounded up to a value |
|
240 |
greater than aSize, but is guaranteed to be not less than aSize. |
|
241 |
||
242 |
@param aCell A pointer to the cell to be reallocated. This may be NULL. |
|
243 |
||
244 |
@param aSize The new size of the cell. This may be bigger or smaller than the |
|
245 |
size of the original cell. |
|
246 |
||
247 |
@param aMode Flags controlling the reallocation. The only bit which has any |
|
248 |
effect on this function is that defined by the enumeration |
|
249 |
ENeverMove of the enum RAllocator::TReAllocMode. |
|
250 |
If this is set, then any successful reallocation guarantees not |
|
251 |
to have changed the start address of the cell. |
|
252 |
By default, this parameter is zero. |
|
253 |
||
254 |
@return A pointer to the reallocated cell. This may be the same as the original |
|
255 |
pointer supplied through aCell. |
|
256 |
||
257 |
@panic USER 42, if aCell is not NULL, and does not point to a valid cell. |
|
258 |
@panic USER 47, if the maximum unsigned value of aSize is greater |
|
259 |
than or equal to KMaxTInt/2. For example, |
|
260 |
calling ReAlloc(someptr,-1) raises this panic. |
|
261 |
||
262 |
@see RAllocator::TReAllocMode |
|
263 |
*/ |
|
264 |
EXPORT_C TAny* RAllocator::ReAllocL(TAny* aCell, TInt aSize, TInt aMode) |
|
265 |
{ |
|
266 |
TAny* p = ReAlloc(aCell, aSize, aMode); |
|
267 |
if (!p) |
|
268 |
User::LeaveNoMemory(); |
|
269 |
return p; |
|
270 |
} |
|
271 |
||
272 |
||
273 |
||
274 |
||
275 |
/** |
|
276 |
Gets the total number of cells allocated on the heap. |
|
277 |
||
278 |
@return The number of cells allocated on the heap. |
|
279 |
*/ |
|
280 |
EXPORT_C TInt RAllocator::Count() const |
|
281 |
{ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
TInt totalAllocSize; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
return ((RAllocator*)this)->AllocSize(totalAllocSize); |
0 | 284 |
} |
285 |
||
286 |
||
287 |
||
288 |
||
289 |
/** |
|
290 |
Gets the the total number of cells allocated, and the number of free cells, |
|
291 |
on the heap. |
|
292 |
||
293 |
@param aFreeCount On return, contains the number of free cells |
|
294 |
on the heap. |
|
295 |
||
296 |
@return The number of cells allocated on the heap. |
|
297 |
*/ |
|
298 |
EXPORT_C TInt RAllocator::Count(TInt& aFreeCount) const |
|
299 |
{ |
|
300 |
return ((RAllocator*)this)->DebugFunction(ECount, &aFreeCount); |
|
301 |
} |
|
302 |
#endif |
|
303 |
||
304 |
||
305 |
||
306 |
||
307 |
/** |
|
308 |
Checks the validity of the heap. |
|
309 |
||
310 |
The function walks through the list of allocated cells and the list of |
|
311 |
free cells checking that this heap is consistent and complete. |
|
312 |
||
313 |
@panic USER 47 if any corruption is found, specifically a bad allocated |
|
314 |
heap cell size. |
|
315 |
@panic USER 48 if any corruption is found, specifically a bad allocated |
|
316 |
heap cell address. |
|
317 |
@panic USER 49 if any corruption is found, specifically a bad free heap |
|
318 |
cell address. |
|
319 |
*/ |
|
320 |
UEXPORT_C void RAllocator::Check() const |
|
321 |
{ |
|
322 |
((RAllocator*)this)->DebugFunction(ECheck); |
|
323 |
} |
|
324 |
||
325 |
||
326 |
||
327 |
||
328 |
/** |
|
329 |
Marks the start of heap cell checking for this heap. |
|
330 |
||
331 |
If earlier calls to __DbgMarkStart() have been made, then this call |
|
332 |
to __DbgMarkStart() marks the start of a new nested level of |
|
333 |
heap cell checking. |
|
334 |
||
335 |
Every call to __DbgMarkStart() should be matched by a later call |
|
336 |
to __DbgMarkEnd() to verify that the number of heap cells allocated, |
|
337 |
at the current nested level, is as expected. This expected number of heap cells |
|
338 |
is passed to __DbgMarkEnd() as a parameter; however, the most common expected |
|
339 |
number is zero, reflecting the fact that most developers check that all memory |
|
340 |
allocated since a previous call to __DbgMarkStart() has been freed. |
|
341 |
||
342 |
@see RAllocator::__DbgMarkEnd() |
|
343 |
*/ |
|
344 |
UEXPORT_C void RAllocator::__DbgMarkStart() |
|
345 |
{ |
|
346 |
DebugFunction(EMarkStart); |
|
347 |
} |
|
348 |
||
349 |
||
350 |
||
351 |
||
352 |
/** |
|
353 |
Marks the end of heap cell checking at the current nested level for this heap. |
|
354 |
||
355 |
A call to this function should match an earlier call to __DbgMarkStart(). |
|
356 |
If there are more calls to this function than calls to __DbgMarkStart(), |
|
357 |
then this function raises a USER 51 panic. |
|
358 |
||
359 |
The function checks that the number of heap cells allocated, at the current |
|
360 |
nested level, is aCount. The most common value for aCount is zero, reflecting |
|
361 |
the fact that most developers check that all memory allocated since a previous |
|
362 |
call to __DbgMarkStart() has been freed. |
|
363 |
||
364 |
If the check fails, the function returns a pointer to the first orphaned |
|
365 |
heap cell. |
|
366 |
||
367 |
@param aCount The number of allocated heap cells expected. |
|
368 |
||
369 |
@return A pointer to the first orphaned heap cell, if verification fails; |
|
370 |
zero otherwise. |
|
371 |
||
372 |
@see RAllocator::__DbgMarkStart() |
|
373 |
*/ |
|
374 |
UEXPORT_C TUint32 RAllocator::__DbgMarkEnd(TInt aCount) |
|
375 |
{ |
|
376 |
return DebugFunction(EMarkEnd, (TAny*)aCount); |
|
377 |
} |
|
378 |
||
379 |
||
380 |
||
381 |
||
382 |
/** |
|
383 |
Checks the current number of allocated heap cells for this heap. |
|
384 |
||
385 |
If aCountAll is true, the function checks that the total number of allocated |
|
386 |
cells on this heap is the same as aCount. If aCountAll is false, then |
|
387 |
the function checks that the number of allocated cells at the current nested |
|
388 |
level is the same as aCount. |
|
389 |
||
390 |
If checking fails, the function raises a panic; |
|
391 |
information about the failure is put into the panic category; |
|
392 |
this takes the form: |
|
393 |
||
394 |
ALLOC COUNT\\rExpected aaa\\rAllocated bbb\\rLn: ccc ddddd |
|
395 |
||
396 |
where |
|
397 |
||
398 |
1. aaaa is the value aCount |
|
399 |
||
400 |
2. bbbb is the number of allocated heap cells |
|
401 |
||
402 |
3. ccc is a line number, copied from aLineNum |
|
403 |
||
404 |
4. ddddd is a file name, copied from the descriptor aFileName |
|
405 |
||
406 |
Note that the panic number is 1. |
|
407 |
||
408 |
@param aCountAll If true, the function checks that the total number of |
|
409 |
allocated cells on this heap is the same as aCount. |
|
410 |
If false, the function checks that the number of allocated |
|
411 |
cells at the current nested level is the same as aCount. |
|
412 |
@param aCount The expected number of allocated cells. |
|
413 |
@param aFileName A filename; this is displayed as part of the panic |
|
414 |
category if the check fails. |
|
415 |
@param aLineNum A line number; this is displayed as part of the panic category |
|
416 |
if the check fails. |
|
417 |
||
418 |
@return KErrNone, if successful; otherwise one of the other system wide error codes. |
|
419 |
*/ |
|
420 |
UEXPORT_C TInt RAllocator::__DbgMarkCheck(TBool aCountAll, TInt aCount, const TDesC8& aFileName, TInt aLineNum) |
|
421 |
{ |
|
422 |
SCheckInfo info; |
|
423 |
info.iAll = aCountAll; |
|
424 |
info.iCount = aCount; |
|
425 |
info.iFileName = &aFileName; |
|
426 |
info.iLineNum = aLineNum; |
|
427 |
return DebugFunction(ECheck, &info); |
|
428 |
} |
|
429 |
||
430 |
||
431 |
||
432 |
||
433 |
/** |
|
434 |
Simulates a heap allocation failure for this heap. |
|
435 |
||
436 |
The failure occurs on subsequent calls to new or any of the functions which |
|
437 |
allocate memory from this heap. |
|
438 |
||
439 |
The timing of the allocation failure depends on the type of |
|
440 |
allocation failure requested, i.e. on the value of aType. |
|
441 |
||
442 |
The simulation of heap allocation failure is cancelled |
|
443 |
if aType is given the value RAllocator::ENone. |
|
444 |
||
445 |
Notes: |
|
446 |
||
447 |
1. If the failure type is RAllocator::EFailNext, the next attempt to allocate from |
|
448 |
this heap fails; however, no further failures will occur. |
|
449 |
||
450 |
2. For failure types RAllocator::EFailNext and RAllocator::ENone, set aRate to 1. |
|
451 |
||
452 |
@param aType An enumeration which indicates how to simulate heap |
|
453 |
allocation failure. |
|
454 |
@param aRate The rate of failure; when aType is RAllocator::EDeterministic, |
|
455 |
heap allocation fails every aRate attempts |
|
456 |
*/ |
|
457 |
UEXPORT_C void RAllocator::__DbgSetAllocFail(TAllocFail aType, TInt aRate) |
|
458 |
{ |
|
459 |
DebugFunction(ESetFail, (TAny*)aType, (TAny*)aRate); |
|
460 |
} |
|
461 |
||
462 |
||
463 |
/** |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
Obtains the current heap failure simulation type. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
After calling __DbgSetAllocFail(), this function may be called to retrieve the |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
value set. This is useful primarily for test code that doesn't know if a heap |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
has been set to fail and needs to check. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
@return RAllocator::ENone if heap is not in failure simulation mode; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
Otherwise one of the other RAllocator::TAllocFail enumerations |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
*/ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
UEXPORT_C RAllocator::TAllocFail RAllocator::__DbgGetAllocFail() |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
return((TAllocFail) DebugFunction(EGetFail)); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
/** |
0 | 480 |
Simulates a burst of heap allocation failures for this heap. |
481 |
||
482 |
The failure occurs for aBurst allocations attempt via subsequent calls |
|
483 |
to new or any of the functions which allocate memory from this heap. |
|
484 |
||
485 |
The timing of the allocation failure depends on the type of |
|
486 |
allocation failure requested, i.e. on the value of aType. |
|
487 |
||
488 |
The simulation of heap allocation failure is cancelled |
|
489 |
if aType is given the value RAllocator::ENone. |
|
490 |
||
491 |
Notes: |
|
492 |
||
493 |
1. If the failure type is RAllocator::EFailNext or RAllocator::EBurstFailNext, |
|
494 |
the next one or aBurst attempts to allocate from this heap will fail; |
|
495 |
however, no further failures will occur. |
|
496 |
||
497 |
2. For failure types RAllocator::EFailNext and RAllocator::ENone, set aRate to 1. |
|
498 |
||
499 |
@param aType An enumeration which indicates how to simulate heap |
|
500 |
allocation failure. |
|
501 |
@param aRate The rate of failure; when aType is RAllocator::EDeterministic, |
|
502 |
heap allocation fails every aRate attempts. |
|
503 |
@param aBurst The number of consecutive heap allocations that will fail each |
|
504 |
time the allocations should fail. |
|
505 |
||
506 |
@see RAllocator::TAllocFail |
|
507 |
*/ |
|
508 |
UEXPORT_C void RAllocator::__DbgSetBurstAllocFail(TAllocFail aType, TUint aRate, TUint aBurst) |
|
509 |
{ |
|
510 |
SRAllocatorBurstFail burstFail; |
|
511 |
burstFail.iRate = aRate; |
|
512 |
burstFail.iBurst = aBurst; |
|
513 |
DebugFunction(ESetBurstFail, (TAny*)aType, (TAny*)&burstFail); |
|
514 |
} |
|
515 |
||
516 |
/** |
|
517 |
Returns the number of heap allocation failures the current debug allocator fail |
|
518 |
function has caused so far. |
|
519 |
||
520 |
This is intended to only be used with fail types RAllocator::EFailNext, |
|
521 |
RAllocator::EBurstFailNext, RAllocator::EDeterministic and |
|
522 |
RAllocator::EBurstDeterministic. The return value is unreliable for |
|
523 |
all other fail types. |
|
524 |
||
525 |
@return The number of heap allocation failures the current debug fail |
|
526 |
function has caused. |
|
527 |
||
528 |
@see RAllocator::TAllocFail |
|
529 |
*/ |
|
530 |
UEXPORT_C TUint RAllocator::__DbgCheckFailure() |
|
531 |
{ |
|
532 |
return DebugFunction(ECheckFailure); |
|
533 |
} |
|
534 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
/** |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
Gets the current size of the heap. |
0 | 537 |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
This is the total number of bytes committed by the host chunk, less the number |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
of bytes used by the heap's metadata (the internal structures used for keeping |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
track of allocated and free memory). |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
542 |
Size = (Rounded committed size - size of heap metadata). |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
@return The size of the heap, in bytes. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
*/ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
UEXPORT_C TInt RAllocator::Size() const |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
return ((RAllocator*)this)->DebugFunction(EGetSize); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
/** |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
@return The maximum length to which the heap can grow. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
@publishedAll |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
@released |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
*/ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
UEXPORT_C TInt RAllocator::MaxLength() const |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
return ((RAllocator*)this)->DebugFunction(EGetMaxLength); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
/** |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
Gets a pointer to the start of the heap. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
Note that this function exists mainly for compatibility reasons. In a modern |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
heap implementation such as that present in Symbian it is not appropriate to |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
concern oneself with details such as the address of the start of the heap, as |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
it is not as meaningful as it was in older heap implementations. In fact, the |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
"base" might not even be the base of the heap at all! |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
In other words, you can call this but it's not guaranteed to point to the start |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
572 |
of the heap (and in fact it never really was, even in legacy implementations). |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
573 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
@return A pointer to the base of the heap. Maybe. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
*/ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
576 |
UEXPORT_C TUint8* RAllocator::Base() const |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
TUint8* base; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
579 |
((RAllocator*)this)->DebugFunction(EGetBase, &base); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
return base; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
UEXPORT_C TInt RAllocator::Align(TInt a) const |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
return ((RAllocator*)this)->DebugFunction(EAlignInteger, (TAny*)a); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
UEXPORT_C TAny* RAllocator::Align(TAny* a) const |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
589 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
TAny* result; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
591 |
((RAllocator*)this)->DebugFunction(EAlignAddr, a, &result); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
return result; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
|
0 | 595 |
UEXPORT_C TInt RAllocator::Extension_(TUint, TAny*& a0, TAny*) |
596 |
{ |
|
597 |
a0 = NULL; |
|
598 |
return KErrExtensionNotSupported; |
|
599 |
} |