9 // Nokia Corporation - initial contribution. |
9 // Nokia Corporation - initial contribution. |
10 // |
10 // |
11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
14 // e32\common\alloc.cpp |
14 // kernel\eka\common\alloc.cpp |
15 // |
15 // |
16 // |
16 // |
17 |
17 |
18 #include "common.h" |
18 #include "common.h" |
19 #include <e32atomics.h> |
19 #include <e32atomics.h> |
20 |
|
21 |
20 |
22 |
21 |
23 #ifndef __KERNEL_MODE__ |
22 #ifndef __KERNEL_MODE__ |
24 /** |
23 /** |
25 Opens this heap for shared access. |
24 Opens this heap for shared access. |
459 DebugFunction(ESetFail, (TAny*)aType, (TAny*)aRate); |
459 DebugFunction(ESetFail, (TAny*)aType, (TAny*)aRate); |
460 } |
460 } |
461 |
461 |
462 |
462 |
463 /** |
463 /** |
|
464 Obtains the current heap failure simulation type. |
|
465 |
|
466 After calling __DbgSetAllocFail(), this function may be called to retrieve the |
|
467 value set. This is useful primarily for test code that doesn't know if a heap |
|
468 has been set to fail and needs to check. |
|
469 |
|
470 @return RAllocator::ENone if heap is not in failure simulation mode; |
|
471 Otherwise one of the other RAllocator::TAllocFail enumerations |
|
472 */ |
|
473 UEXPORT_C RAllocator::TAllocFail RAllocator::__DbgGetAllocFail() |
|
474 { |
|
475 return((TAllocFail) DebugFunction(EGetFail)); |
|
476 } |
|
477 |
|
478 |
|
479 /** |
464 Simulates a burst of heap allocation failures for this heap. |
480 Simulates a burst of heap allocation failures for this heap. |
465 |
481 |
466 The failure occurs for aBurst allocations attempt via subsequent calls |
482 The failure occurs for aBurst allocations attempt via subsequent calls |
467 to new or any of the functions which allocate memory from this heap. |
483 to new or any of the functions which allocate memory from this heap. |
468 |
484 |
514 UEXPORT_C TUint RAllocator::__DbgCheckFailure() |
530 UEXPORT_C TUint RAllocator::__DbgCheckFailure() |
515 { |
531 { |
516 return DebugFunction(ECheckFailure); |
532 return DebugFunction(ECheckFailure); |
517 } |
533 } |
518 |
534 |
519 |
535 /** |
|
536 Gets the current size of the heap. |
|
537 |
|
538 This is the total number of bytes committed by the host chunk, less the number |
|
539 of bytes used by the heap's metadata (the internal structures used for keeping |
|
540 track of allocated and free memory). |
|
541 |
|
542 Size = (Rounded committed size - size of heap metadata). |
|
543 |
|
544 @return The size of the heap, in bytes. |
|
545 */ |
|
546 UEXPORT_C TInt RAllocator::Size() const |
|
547 { |
|
548 return ((RAllocator*)this)->DebugFunction(EGetSize); |
|
549 } |
|
550 |
|
551 /** |
|
552 @return The maximum length to which the heap can grow. |
|
553 |
|
554 @publishedAll |
|
555 @released |
|
556 */ |
|
557 UEXPORT_C TInt RAllocator::MaxLength() const |
|
558 { |
|
559 return ((RAllocator*)this)->DebugFunction(EGetMaxLength); |
|
560 } |
|
561 |
|
562 /** |
|
563 Gets a pointer to the start of the heap. |
|
564 |
|
565 Note that this function exists mainly for compatibility reasons. In a modern |
|
566 heap implementation such as that present in Symbian it is not appropriate to |
|
567 concern oneself with details such as the address of the start of the heap, as |
|
568 it is not as meaningful as it was in older heap implementations. In fact, the |
|
569 "base" might not even be the base of the heap at all! |
|
570 |
|
571 In other words, you can call this but it's not guaranteed to point to the start |
|
572 of the heap (and in fact it never really was, even in legacy implementations). |
|
573 |
|
574 @return A pointer to the base of the heap. Maybe. |
|
575 */ |
|
576 UEXPORT_C TUint8* RAllocator::Base() const |
|
577 { |
|
578 TUint8* base; |
|
579 ((RAllocator*)this)->DebugFunction(EGetBase, &base); |
|
580 return base; |
|
581 } |
|
582 |
|
583 UEXPORT_C TInt RAllocator::Align(TInt a) const |
|
584 { |
|
585 return ((RAllocator*)this)->DebugFunction(EAlignInteger, (TAny*)a); |
|
586 } |
|
587 |
|
588 UEXPORT_C TAny* RAllocator::Align(TAny* a) const |
|
589 { |
|
590 TAny* result; |
|
591 ((RAllocator*)this)->DebugFunction(EAlignAddr, a, &result); |
|
592 return result; |
|
593 } |
|
594 |
520 UEXPORT_C TInt RAllocator::Extension_(TUint, TAny*& a0, TAny*) |
595 UEXPORT_C TInt RAllocator::Extension_(TUint, TAny*& a0, TAny*) |
521 { |
596 { |
522 a0 = NULL; |
597 a0 = NULL; |
523 return KErrExtensionNotSupported; |
598 return KErrExtensionNotSupported; |
524 } |
599 } |