First public contribution.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\memmodel\epoc\direct\memmodel.h
16 // WARNING: This file contains some APIs which are internal and are subject
17 // to change without notice. Such APIs should therefore not be used
18 // outside the Kernel and Hardware Services package.
21 #ifndef __MEMMODEL_H__
22 #define __MEMMODEL_H__
23 #include <plat_priv.h>
25 /********************************************
26 * Process Control Block
27 ********************************************/
34 class DMemModelProcess : public DEpocProcess
39 virtual TInt DoCreate(TBool aKernelProcess, TProcessCreateInfo& aInfo);
40 virtual TInt NewChunk(DChunk*& aChunk, SChunkCreateInfo& anInfo, TLinAddr& aRunAddr);
41 virtual TInt AddChunk(DChunk* aChunk,TBool isReadOnly);
42 virtual TInt NewShPool(DShPool*& aPool, TShPoolCreateInfo& aInfo);
43 virtual TInt CreateDataBssStackArea(TProcessCreateInfo& aInfo);
44 virtual TInt MapCodeSeg(DCodeSeg* aCodeSeg);
45 virtual void UnmapCodeSeg(DCodeSeg* aCodeSeg);
46 virtual void RemoveDllData();
47 virtual void FinalRelease();
52 /********************************************
54 ********************************************/
59 class DMemModelChunk : public DChunk
62 enum TMemModelChunkAttributes
66 EMMChunkAttributesMask = EPrivate,
72 // virtual TInt Close(TAny* aPtr);
73 virtual TInt DoCreate(SChunkCreateInfo& anInfo);
74 virtual TInt Adjust(TInt aNewSize);
75 virtual TInt AdjustDoubleEnded(TInt aBottom, TInt aTop);
76 virtual TInt CheckAccess();
77 virtual TInt Commit(TInt anOffset, TInt aSize, TCommitType aCommitType=DChunk::ECommitDiscontiguous, TUint32* aExtraArg=0);
78 virtual TInt Allocate(TInt aSize, TInt aGuard=0, TInt aAlign=0);
79 virtual TInt Decommit(TInt anOffset, TInt aSize);
80 virtual TInt Lock(TInt anOffset, TInt aSize);
81 virtual TInt Unlock(TInt anOffset, TInt aSize);
82 virtual TInt Address(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress);
83 virtual TInt PhysicalAddress(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aPhysicalAddress, TUint32* aPhysicalPageList=NULL);
84 virtual void BTracePrime(TInt aCategory);
85 virtual void Substitute(TInt aOffset, TPhysAddr aOldAddr, TPhysAddr aNewAddr);
86 virtual TUint8* Base(DProcess* aProcess);
87 inline TUint8* Base() const { return DChunk::Base(); }
89 void SetFixedAddress(TLinAddr anAddr, TInt aSize);
97 /********************************************
99 ********************************************/
104 class DMemModelCodeSegMemory : public DEpocCodeSegMemory
107 DMemModelCodeSegMemory(DEpocCodeSeg* aCodeSeg);
113 class DMemModelCodeSeg: public DEpocCodeSeg
117 virtual ~DMemModelCodeSeg();
118 virtual TInt DoCreateRam(TCodeSegCreateInfo& aInfo, DProcess* aProcess);
119 virtual TInt DoCreateXIP(DProcess* aProcess);
120 virtual TInt Loaded(TCodeSegCreateInfo& aInfo);
121 virtual void ReadExportDir(TUint32* aDest);
122 virtual TBool FindCheck(DProcess* aProcess);
123 virtual TBool OpenCheck(DProcess* aProcess);
126 TAny* iKernelData; // only for kernel modules
129 /********************************************
130 * Functions/Data defined in memory model
131 ********************************************/
141 ERamAllocCreateFailed=0,
142 ERamAllocMutexCreateFailed=1,
143 EFreeInvalidRegion=2,
144 ECodeSegCheckInconsistent=3,
145 ESecAllocCreateFailed=4,
146 EUnsupportedOperation=5,
149 static void Panic(TMemModelPanic aPanic);
152 static void StartCrashDebugger();
153 static void WaitRamAlloc();
154 static void SignalRamAlloc();
155 static TUint32 RoundToBlockSize(TUint32 aSize);
156 static void FreeRegion(TLinAddr aBase, TInt aSize);
157 static TInt AllocRegion(TLinAddr& aBase, TInt aSize, TInt aAlign=0);
158 static TInt ClaimRegion(TLinAddr aBase, TInt aSize);
159 static TInt AllocContiguousRegion(TLinAddr& aBase, TInt aSize, TInt aAlign=0);
160 static TInt BlockNumber(TPhysAddr aAddr);
162 static TLinAddr UserDataSectionBase;
163 static TLinAddr UserRomDataSectionEnd;
164 static TLinAddr UserDataSectionEnd;
165 static TLinAddr RomLinearBase;
166 static DMutex* RamAllocatorMutex;
167 static TBitMapAllocator* RamAllocator;
168 static TBitMapAllocator* SecondaryAllocator;
169 static TInt RamBlockSize;
170 static TInt RamBlockShift;
171 static TInt InitialFreeMemory;
172 static TBool AllocFailed;