memspy/Driver/Kernel/Include/MemSpyDriverHeap.h
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
    26 
    26 
    27 // User includes
    27 // User includes
    28 #include "MemSpyDriverObjectsInternal.h"
    28 #include "MemSpyDriverObjectsInternal.h"
    29 
    29 
    30 // Constants
    30 // Constants
    31 // We shouldn't be using any of these any more! -Tomsci
       
    32 const TUint KRHeapObjectSize = 0x74;
    31 const TUint KRHeapObjectSize = 0x74;
    33 const TUint KRAllocatorAndRHeapMemberDataOffset = 4; // 4 bytes past start of allocator address, i.e. skipping the vtable
    32 const TUint KRAllocatorAndRHeapMemberDataOffset = 4; // 4 bytes past start of allocator address, i.e. skipping the vtable
    34 const TUint KRHeapMemberDataSize = KRHeapObjectSize - KRAllocatorAndRHeapMemberDataOffset;
    33 const TUint KRHeapMemberDataSize = KRHeapObjectSize - KRAllocatorAndRHeapMemberDataOffset;
    35 
    34 
    36 // Classes referenced
    35 // Classes referenced
    37 class DMemSpyDriverOSAdaption;
    36 class DMemSpyDriverOSAdaption;
    38 namespace LtkUtils
    37 
    39 	{
       
    40 	class RAllocatorHelper;
       
    41 	}
       
    42 
    38 
    43 /**
    39 /**
    44  * Essentially a mirror of RAllocator and RHeap's layout.
    40  * Essentially a mirror of RAllocator and RHeap's layout.
    45  */
    41  */
    46 class RMemSpyDriverRHeapBase
    42 class RMemSpyDriverRHeapBase
    47 	{
    43 	{
       
    44 public:
       
    45 	struct SCell
       
    46         {
       
    47         TInt len; 
       
    48         SCell* next;
       
    49         };
       
    50 
       
    51     struct SDebugCell
       
    52         {
       
    53         TInt len;
       
    54         TInt nestingLevel;
       
    55         TInt allocCount;
       
    56         };
       
    57 
       
    58     struct _s_align {char c; double d;};
       
    59 
       
    60     struct SHeapCellInfo { RHeap* iHeap; TInt iTotalAlloc;	TInt iTotalAllocSize; TInt iTotalFree; TInt iLevelAlloc; SDebugCell* iStranded; };
       
    61 	
       
    62     enum {ECellAlignment = sizeof(_s_align)-sizeof(double)};
       
    63 	enum {EFreeCellSize = sizeof(SCell)};
       
    64 	enum TDebugOp {EWalk=128};
       
    65 	enum TCellType
       
    66 		{EGoodAllocatedCell, EGoodFreeCell, EBadAllocatedCellSize, EBadAllocatedCellAddress,
       
    67 		EBadFreeCellAddress, EBadFreeCellSize};
       
    68 	
       
    69     enum TDebugHeapId {EUser=0, EKernel=1};
       
    70 
    48 protected:
    71 protected:
    49     RMemSpyDriverRHeapBase();
    72     RMemSpyDriverRHeapBase();
    50 
    73 
       
    74 public: // Inlines
       
    75     inline TUint8* Base() const { return iBase; }
       
    76     inline TInt Size() const { return iTop - iBase; }
       
    77     inline TInt MaxLength() const { return iMaxLength; }
       
    78 
    51 public: // API
    79 public: // API
    52     void PrintInfo();
    80     void PrintInfo();
    53 	LtkUtils::RAllocatorHelper* Helper();
    81     void CopyObjectDataTo( TMemSpyHeapObjectDataRHeap& aData );
    54 	TMemSpyHeapInfo::THeapImplementationType GetTypeFromHelper() const;
       
    55 
    82 
    56 public: // Virtual API
    83 public: // Virtual API
    57     virtual void Reset();
    84     virtual void Reset();
    58 	virtual void Close();
    85     virtual void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes ) = 0;
       
    86     virtual void DisassociateWithKernelChunk() = 0;
    59     virtual DChunk& Chunk() = 0;
    87     virtual DChunk& Chunk() = 0;
    60     virtual const DChunk& Chunk() const = 0;
    88     virtual const DChunk& Chunk() const = 0;
    61 
    89     virtual TLinAddr ChunkKernelAddress() const = 0;
    62 protected:
    90     virtual TBool ChunkIsInitialised() const = 0;
    63 	LtkUtils::RAllocatorHelper* iHelper;
    91     virtual TUint ClientToKernelDelta() const = 0;
       
    92     virtual void GetHeapSpecificInfo( TMemSpyHeapInfo& /*aInfo*/ ) const { }
       
    93 
       
    94 public: // Utilities
       
    95     TBool CheckCell( TAny* aCellAddress, TInt aLength ) const;
       
    96     static TInt AllocatedCellHeaderSize( TBool aDebugLibrary );
       
    97     static TInt FreeCellHeaderSize();
       
    98     static TInt CellHeaderSize( const TMemSpyDriverInternalWalkHeapParamsCell& aCell, TBool aDebugEUser );
       
    99 
       
   100 public: // From RAllocator
       
   101 	TInt iAccessCount;
       
   102 	TInt iHandleCount;
       
   103 	TInt* iHandles;
       
   104 	TUint32 iFlags;
       
   105 	TInt iCellCount;
       
   106 	TInt iTotalAllocSize;
       
   107 
       
   108 public: // From RHeap
       
   109 	TInt iMinLength;
       
   110 	TInt iMaxLength;
       
   111 	TInt iOffset;
       
   112 	TInt iGrowBy;
       
   113 	TInt iChunkHandle;
       
   114 	RFastLock iLock;
       
   115 	TUint8* iBase;
       
   116 	TUint8* iTop;
       
   117 	TInt iAlign;
       
   118 	TInt iMinCell;
       
   119 	TInt iPageSize;
       
   120 	SCell iFree;
       
   121 	TInt iNestingLevel;
       
   122 	TInt iAllocCount;
       
   123     RAllocator::TAllocFail iFailType;
       
   124 	TInt iFailRate;
       
   125 	TBool iFailed;
       
   126 	TInt iFailAllocCount;
       
   127 	TInt iRand;
       
   128 	TAny* iTestData;
    64     };
   129     };
    65 
   130 
    66 
   131 
    67 
   132 
    68 
   133 
    70 	{
   135 	{
    71 protected:
   136 protected:
    72     RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption );
   137     RMemSpyDriverRHeapReadFromCopy( DMemSpyDriverOSAdaption& aOSAdaption );
    73 
   138 
    74 public: // New API
   139 public: // New API
    75     void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes );
   140     TInt ReadFromUserAllocator( DThread& aThread );
    76 
   141 
    77 public: // From RMemSpyDriverRHeapBase
   142 public: // From RMemSpyDriverRHeapBase
    78     void Reset();
   143     void Reset();
       
   144     void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes );
       
   145     void DisassociateWithKernelChunk();
    79     DChunk& Chunk();
   146     DChunk& Chunk();
    80     const DChunk& Chunk() const;
   147     const DChunk& Chunk() const;
       
   148     TLinAddr ChunkKernelAddress() const;
       
   149     TBool ChunkIsInitialised() const;
       
   150     TUint ClientToKernelDelta() const;
    81 
   151 
    82 protected:
   152 protected:
    83     inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; }
   153     inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; }
    84 
   154 
    85 private:
   155 private:
    90     TLinAddr iChunkAddress;
   160     TLinAddr iChunkAddress;
    91     TUint32 iChunkMappingAttributes;
   161     TUint32 iChunkMappingAttributes;
    92 
   162 
    93     // Calculated delta between client's address space values and actual kernel
   163     // Calculated delta between client's address space values and actual kernel
    94     // address of the heap chunk.
   164     // address of the heap chunk.
    95     //TUint iClientToKernelDelta;
   165     TUint iClientToKernelDelta;
    96     };
   166     };
    97 
   167 
    98 
   168 
    99 
   169 
   100 
   170 
   101 
   171 
   102 
   172 
   103 
   173 
   104 class RMemSpyDriverRHeapUser : public RMemSpyDriverRHeapBase
   174 class RMemSpyDriverRHeapUser : public RMemSpyDriverRHeapReadFromCopy
   105 	{
   175 	{
   106 public:
   176 public:
   107     RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption );
   177     RMemSpyDriverRHeapUser( DMemSpyDriverOSAdaption& aOSAdaption );
   108 	TInt OpenUserHeap(DThread& aThread, TBool aEuserUdeb);
   178 
   109 
   179 public: // New API
   110 	DChunk& Chunk() { return *iChunk; }
   180     TInt ReadFromUserAllocator( DThread& aThread );
   111 	const DChunk& Chunk() const { return *iChunk; }
       
   112 
       
   113 private:
       
   114     inline DMemSpyDriverOSAdaption& OSAdaption() { return iOSAdaption; }
       
   115 
       
   116 private:
       
   117     DMemSpyDriverOSAdaption& iOSAdaption;
       
   118 	DChunk* iChunk;
       
   119     };
   181     };
   120 
   182 
   121 
   183 
   122 
   184 
   123 class RMemSpyDriverRHeapKernelFromCopy : public RMemSpyDriverRHeapReadFromCopy
   185 class RMemSpyDriverRHeapKernelFromCopy : public RMemSpyDriverRHeapReadFromCopy
   127     
   189     
   128 public: // API
   190 public: // API
   129     void SetKernelHeap( RHeapK& aKernelHeap );
   191     void SetKernelHeap( RHeapK& aKernelHeap );
   130 
   192 
   131 public: // From RMemSpyDriverRHeapBase
   193 public: // From RMemSpyDriverRHeapBase
   132     //void DisassociateWithKernelChunk();
   194     void DisassociateWithKernelChunk();
   133 	void Close();
   195     void GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const;
   134 
   196 
   135 private:
   197 private:
   136     RHeapK* iKernelHeap;
   198     RHeapK* iKernelHeap;
   137     };
   199     };
   138 
   200 
   140 
   202 
   141 class RMemSpyDriverRHeapKernelInPlace : public RMemSpyDriverRHeapBase
   203 class RMemSpyDriverRHeapKernelInPlace : public RMemSpyDriverRHeapBase
   142     {
   204     {
   143 public:
   205 public:
   144     RMemSpyDriverRHeapKernelInPlace();
   206     RMemSpyDriverRHeapKernelInPlace();
   145 	TInt OpenKernelHeap();
       
   146     
   207     
       
   208 public: // API
       
   209     void FailNext();
       
   210     void SetKernelHeap( RHeapK& aKernelHeap );
   147 
   211 
   148 public: // From RMemSpyDriverRHeapBase
   212 public: // From RMemSpyDriverRHeapBase
   149     void Close();
   213     void Reset();
   150 
   214     void AssociateWithKernelChunk( DChunk* aChunk, TLinAddr aAddress, TUint32 aMappingAttributes );
       
   215     void DisassociateWithKernelChunk();
   151     DChunk& Chunk();
   216     DChunk& Chunk();
   152     const DChunk& Chunk() const;
   217     const DChunk& Chunk() const;
   153 
   218     TLinAddr ChunkKernelAddress() const;
   154 	// Only important member data is the base class's RAllocatorHelper
   219     TBool ChunkIsInitialised() const;
   155 	// We do cache the chunk though
   220     TUint ClientToKernelDelta() const;
       
   221     void GetHeapSpecificInfo( TMemSpyHeapInfo& aInfo ) const;
       
   222 
       
   223 private: // Internal methods
       
   224     void CopyMembersFromKernelHeap();
       
   225 
       
   226 private: // Internal class
       
   227 
       
   228     /**
       
   229      * Used when opening the kernel heap
       
   230      */
       
   231 #ifndef __SYMBIAN_KERNEL_HYBRID_HEAP__
       
   232     class RHeapKExtended : public RHeapK
       
   233         {
       
   234     public:
       
   235         inline void FailNext()
       
   236             {
       
   237             SetFailType( RAllocator::EFailNext );
       
   238             SetFailRate( 1 );
       
   239             ResetFailed();
       
   240             ResetFailAllocCount();
       
   241             }
       
   242         inline void SetFailType( TAllocFail aType ) { iFailType = aType; }
       
   243         inline void SetFailRate( TInt aRate ) { iFailRate = aRate; }
       
   244         inline void ResetFailed() { iFailed = EFalse; }
       
   245         inline void ResetFailAllocCount() { iFailAllocCount = 0; }
       
   246         };
       
   247 #endif
   156 private:
   248 private:
   157 	DChunk* iChunk;
   249     RHeapK* iKernelHeap;
       
   250     DChunk* iChunk;
   158     };
   251     };
   159 
   252 
   160 	
   253 	
   161 #endif
   254 #endif