diff -r 000000000000 -r a41df078684a kernel/eka/memmodel/epoc/flexible/mmu/mm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel/eka/memmodel/epoc/flexible/mmu/mm.h Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,1187 @@ +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/** + @file + @internalComponent +*/ + +#ifndef MM_H +#define MM_H + +#include +#include + + +class DMemoryObject; +class DMemoryMapping; +class DMemModelThread; +class DPhysicalPinMapping; + +/** +Memory object types for MM::MemoryNew which indicates how the +contents of a memory object are to be managed. +*/ +enum TMemoryObjectType + { + /** + Memory object for containing memory mapped hardware devices or special + purpose memory for which the physical addresses are fixed. The contents of + these type of objects are manipulated with the functions: + - MM::MemoryAddPages + - MM::MemoryAddContiguous + - MM::MemoryRemovePages + */ + EMemoryObjectHardware = 0, + + /** + Memory object containing normal program memory (RAM) which is allocated from a + system wide pool. The contents of these type of objects are manipulated with + the functions: + - MM::MemoryAlloc + - MM::MemoryAllocContiguous + - MM::MemoryFree + */ + EMemoryObjectUnpaged = 1, + + /** + Memory object containing normal program memory (RAM) which is allocated from a + system wide pool. This is the same basic management as EMemoryObjectUnpaged however + RAM defragmentation activity may substituted physical RAM pages with others and + this process may cause transient page faults which make this memory not suitable + for most kernel-side usage. + + The contents of these type of objects are manipulated with the functions: + - MM::MemoryAlloc + - MM::MemoryAllocContiguous + - MM::MemoryFree + */ + EMemoryObjectMovable = 2, + + /** + Memory object containing normal program memory (RAM) which is demand paged + from a backing store. The contents of these type of objects are manipulated + with the functions. + - MM::MemoryAlloc + - MM::MemoryFree + */ + EMemoryObjectPaged = 3, + + /** + Memory object containing normal program memory (RAM) in the same way as + EMemoryObjectMovable but with the additional option of marking pages as + 'discardable'. Discardable pages may be reclaimed (remove) by the system at + any time, this state is controlled using the functions: + - MM::MemoryAllowDiscard + - MM::MemoryDisallowDiscard + */ + EMemoryObjectDiscardable = 4 + }; + + +/** +Bitmask of flags to specify options to MM:MemoryNew. +*/ +enum TMemoryCreateFlags + { + /** + Default value which has all flags false. + */ + EMemoryCreateDefault = 0, + + /** + Memory allocated for the memory object contents does not need wiping. + IMPORTANT, memory is normally wiped for security purposes, this attribute + should only be used when the old contents of any memory allocated can not + be read by any process without TCB capability. + */ + EMemoryCreateNoWipe = 1<<0, + + /** + Use the custom wipe byte value when wiping memory, rather than the default value. + @see EMemoryCreateUseCustomWipeByte + */ + EMemoryCreateUseCustomWipeByte = 1<<1, + + /** + Pre-create all resources the memory object needs so that operations on it + can not fail due to low memory conditions. This excludes any explicit + allocation of memory pages for use as the objects contents. + */ + EMemoryCreateReserveAllResources = 1<<2, + + /** + Memory object contents are not allowed to be pinned. + */ + EMemoryCreateDisallowPinning = 1<<3, + + /** + Memory object contents are read-only. Mappings with write permissions are + not allowed. + */ + EMemoryCreateReadOnly = 1<<4, + + /** + Memory object contents may be executed. Mappings with execute permissions + are allowed. + */ + EMemoryCreateAllowExecution = 1<<5, + + /** + Bit position for the least significant bit of an 8 bit value to use for + wiping newly allocated memory. + @see EMemoryCreateUseCustomWipeByte + @see EMemoryCreateNoWipe + */ + EMemoryCreateWipeByteShift = 8, + + // for selected internal use only... + + /** + The TMemoryObjectType specified is actually a pointer to the DMemoryManager to use. + */ + EMemoryCreateCustomManager = 1<<30, + + /** + Memory object contents are to be demand paged. + */ + EMemoryCreateDemandPaged = 1<<31 + }; + + +/** +Attributes that the memory in a memory object has. + +These govern how the MMU and caching systems treat the memory. The following +terms have meanings as specified in the ARM Architecture Reference Manual - see +the section 'Memory types and attributes and the Memory order model'. + +- Memory types 'normal', 'device' and 'strongly-ordered'. +- 'Shareable' attribute. +*/ +enum TMemoryAttributes + { + // memory types (copy of TMemoryType)... + + EMemoryAttributeStronglyOrdered = EMemAttStronglyOrdered, + EMemoryAttributeDevice = EMemAttDevice, + EMemoryAttributeNormalUncached = EMemAttNormalUncached, + EMemoryAttributeNormalCached = EMemAttNormalCached, + EMemoryAttributeKernelInternal4 = EMemAttKernelInternal4, + EMemoryAttributePlatformSpecific5 = EMemAttPlatformSpecific5, + EMemoryAttributePlatformSpecific6 = EMemAttPlatformSpecific6, + EMemoryAttributePlatformSpecific7 = EMemAttPlatformSpecific7, + + /** + Bitmask to extract TMemoryType value from this enum. E.g. + @code + TMemoryAttributes attr; + TMemoryType type = (TMemoryType)(attr&EMemoryAttributeTypeMask); + @endcode + */ + EMemoryAttributeTypeMask = KMemoryTypeMask, + + /** + Set if memory is Shareable. + */ + EMemoryAttributeShareable = 0x08, + + /** + Legacy (and little-used/unused?) ARM attribute. + */ + EMemoryAttributeUseECC = 0x10, + + + /** + Number of bits required to store memory attribute value. + @internalComponent + */ + EMemoryAttributeShift = 5, + + /** + Bitmask for all significant attribute bits. + @internalComponent + */ + EMemoryAttributeMask = (1< +FORCE_INLINE void FlagSet(T& a,const T b) + { a = (T)(a|b); } + +template +FORCE_INLINE void FlagSet(T& a,const T b,const T c) + { a = (T)(a|b|c); } + +template +FORCE_INLINE void FlagSet(T& a,const T b,const T c,const T d) + { a = (T)(a|b|c|d); } + +template +FORCE_INLINE void FlagClear(T& a,const T b) + { a = (T)(a&~b); } + +template +FORCE_INLINE void FlagClear(T& a,const T b,const T c) + { a = (T)(a&~b&~c); } + +template +FORCE_INLINE void FlagClear(T& a,const T b,const T c,const T d) + { a = (T)(a&~b&~c&~d); } + + +#include + +/** +Structure containing the information about a demand paged code segment +which is required to load and fixup its code section. +*/ +class TPagedCodeInfo + { +public: + ~TPagedCodeInfo(); + TInt ReadBlockMap(const TCodeSegCreateInfo& aInfo); + TInt ReadFixupTables(const TCodeSegCreateInfo& aInfo); + void ApplyFixups(TLinAddr aBuffer, TUint iIndex); +public: + TBool iLoaded; ///< True once initial loading has finished and paging should start applying fixups. + TUint iCodeRelocTableSize; ///< Size, in bytes, of #iCodeRelocTable. + TUint8* iCodeRelocTable; ///< Code relocation information. + TUint iImportFixupTableSize; ///< Size, in bytes, of #iImportFixupTable. + TUint8* iImportFixupTable; ///< Import fixup information. + TUint32 iCodeDelta; ///< Delta to apply to relocate words referring to the code section. + TUint32 iDataDelta; ///< Delta to apply to relocate words referring to the data section. + + TUint iCodeSize; ///< Size, in bytes, of the code section. + TUint32 iCompressionType; ///< Compression scheme in use, (KUidCompressionBytePair or KFormatNotCompressed). + TInt32* iCodePageOffsets; ///< Array of compressed page offsets within the file. + TInt iCodeLocalDrive; ///< Local drive number. + TInt iCodeStartInFile; ///< Offset of (possibly compressed) code from start of file. + TBlockMap iBlockMap; ///< Kernel-side representation of block map. + }; + + + +/** +A pool of DMutex objects that can be dynamically assigned for use. + +This is intended as a memory saving alternative to having each object in a class of objects +owning their own mutex for locking purposes and provides a concurrency improvement over using +a single global lock. +*/ +class DMutexPool : public DBase + { +public: + /** + @param aCount Number of mutexes to allocated in the pool. + Must be smaller than #EMaxPoolSize. + @param aName Base name for mutexes. Each mutex in the pool has a number appended to this base name. + @param aOrder A value representing the order of the mutex with respect to deadlock prevention. + */ + TInt Create(TUint aCount, const TDesC* aName, TUint aOrder); + + ~DMutexPool(); + + /** + Wait on the mutex specified by \a aMutexRef. + + If \a aMutexRef contains the null pointer then a member of this pool is selected and waited on, + and \a aMutexRef is set to a cookie value identifying that mutex; this cookie has its least + significant bit set to distinguish it from a normal DMutex pointer. Subsequent concurrent + Wait operations will use the same pool mutex; possibly modifying the value of the cookie. + */ + void Wait(DMutex*& aMutexRef); + + /** + Signal the mutex specified by \a aMutexRef. + + If mutex is identified as one from this pool then the value of \a aMutexRef will be modified + and if there are no pending Wait operations it will be set to the null pointer to indicate + that no mutex is assigned. + */ + void Signal(DMutex*& aMutexRef); + + /** + Return true if the mutex specified by \a aMutexRef is held by the current thread. + */ + TBool IsHeld(DMutex*& aMutexRef); + + enum + { + /** Maximum number of mutexes allowed in a pool. */ + EMaxPoolSize = 64 + }; + +private: + /** Structure for storing information about each member of the pool. */ + struct SMember + { + DMutex* iMutex; ///< The mutex + TUint iUseCount; ///< Number of times this mutex has been used + }; + TUint iCount; ///< Number of mutexes in pool. (Number of entries in iMembers). + TUint iNext; ///< Index of next pool mutex to use. + SMember* iMembers; ///< Info about each memory of pool. + }; + + +#endif