1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/memmodel/emul/win32/memmodel.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,313 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\include\memmodel\emul\win32\memmodel.h
1.18 +//
1.19 +// WARNING: This file contains some APIs which are internal and are subject
1.20 +// to change without notice. Such APIs should therefore not be used
1.21 +// outside the Kernel and Hardware Services package.
1.22 +//
1.23 +
1.24 +/**
1.25 + @file
1.26 + @internalComponent
1.27 +*/
1.28 +
1.29 +#ifndef __WIN32_MEM_H__
1.30 +#define __WIN32_MEM_H__
1.31 +#include <win32.h>
1.32 +#include <plat_priv.h>
1.33 +#include <kernel/sshbuf.h>
1.34 +
1.35 +const TInt KRamChunkSize=0x10000;
1.36 +const TInt KRamChunkShift=16;
1.37 +const TInt KRamPageSize=0x1000;
1.38 +const TInt KRamPageShift=12;
1.39 +
1.40 +/********************************************
1.41 + * Thread Control Block
1.42 + ********************************************/
1.43 +
1.44 +class DWin32Thread : public DThread
1.45 + {
1.46 +public:
1.47 + ~DWin32Thread();
1.48 + virtual TInt Context(TDes8& aDes);
1.49 + virtual TInt SetupContext(SThreadCreateInfo& anInfo);
1.50 + virtual void DoExit2();
1.51 + };
1.52 +
1.53 +/********************************************
1.54 + * Process Control Block
1.55 + ********************************************/
1.56 +class DWin32CodeSeg;
1.57 +class DWin32Chunk;
1.58 +struct SProcessDllDataBlock;
1.59 +class DWin32Process : public DProcess
1.60 + {
1.61 +public:
1.62 + DWin32Process();
1.63 + ~DWin32Process();
1.64 +public:
1.65 + virtual TInt DoCreate(TBool aKernelProcess, TProcessCreateInfo& aInfo);
1.66 + virtual TInt NewChunk(DChunk*& aChunk, SChunkCreateInfo& aInfo, TLinAddr& aRunAddr);
1.67 + virtual TInt AddChunk(DChunk* aChunk,TBool isReadOnly);
1.68 + virtual TInt NewShPool(DShPool*& aPool, TShPoolCreateInfo& aInfo);
1.69 + virtual TInt CreateDataBssStackArea(TProcessCreateInfo& aInfo);
1.70 + virtual TInt GetNewThread(DThread*& aThread, SThreadCreateInfo& anInfo);
1.71 + virtual TInt AttachExistingCodeSeg(TProcessCreateInfo& aInfo);
1.72 + virtual TInt MapCodeSeg(DCodeSeg* aCodeSeg);
1.73 + virtual void UnmapCodeSeg(DCodeSeg* aCodeSeg);
1.74 + virtual void RemoveDllData();
1.75 + virtual void FinalRelease();
1.76 + virtual void Release();
1.77 + void CallRuntimeHook(TWin32RuntimeReason aReason);
1.78 +public:
1.79 + TWin32RuntimeHook iWin32RuntimeHook;
1.80 + RArray<SProcessDllDataBlock> iDllData;
1.81 + };
1.82 +
1.83 +/******************************************************************
1.84 + * structure to keep static data in code segments within a process
1.85 + ******************************************************************/
1.86 +struct SProcessDllDataBlock
1.87 + {
1.88 + DWin32CodeSeg* iCodeSeg;
1.89 + TAny* iDataCopy; // copy of .data
1.90 + TAny* iBssCopy; // copy of .bss
1.91 + };
1.92 +
1.93 +/********************************************
1.94 + * Chunk Control Block
1.95 + ********************************************/
1.96 +class DWin32Chunk : public DChunk
1.97 + {
1.98 +public:
1.99 + enum TMemModelChunkAttributes
1.100 + {
1.101 + EPrivate=0x10000000,
1.102 +
1.103 + EMMChunkAttributesMask = EPrivate,
1.104 + };
1.105 +
1.106 +public:
1.107 + ~DWin32Chunk();
1.108 +public:
1.109 + virtual TInt DoCreate(SChunkCreateInfo& aInfo);
1.110 + virtual TInt Adjust(TInt aNewSize);
1.111 + virtual TInt AdjustDoubleEnded(TInt aBottom, TInt aTop);
1.112 + virtual TInt CheckAccess();
1.113 + virtual TInt Commit(TInt anOffset, TInt aSize, TCommitType aCommitType=DChunk::ECommitDiscontiguous, TUint32* aExtraArg=0);
1.114 + virtual TInt Allocate(TInt aSize, TInt aGuard=0, TInt aAlign=0);
1.115 + virtual TInt Decommit(TInt anOffset, TInt aSize);
1.116 + virtual TInt Lock(TInt anOffset, TInt aSize);
1.117 + virtual TInt Unlock(TInt anOffset, TInt aSize);
1.118 + virtual TInt Address(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress);
1.119 + virtual TInt PhysicalAddress(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aPhysicalAddress, TUint32* aPhysicalPageList=NULL);
1.120 + virtual void BTracePrime(TInt aCategory);
1.121 + virtual void Substitute(TInt aOffset, TPhysAddr aOldAddr, TPhysAddr aNewAddr);
1.122 + virtual TUint8* Base(DProcess* aProcess);
1.123 + inline TUint8* Base() const { return DChunk::Base(); }
1.124 +private:
1.125 + TInt DoCommit(TInt aOffset, TInt aSize);
1.126 + void DoDecommit(TInt aOffset, TInt aSize);
1.127 +public:
1.128 + TBitMapAllocator* iPageBitMap;
1.129 + TBitMapAllocator* iUnlockedPageBitMap;
1.130 + TBitMapAllocator* iPermanentPageBitMap;
1.131 + };
1.132 +
1.133 +/********************************************
1.134 + * Code segment
1.135 + ********************************************/
1.136 +class DModuleList;
1.137 +class DWin32CodeSeg: public DCodeSeg
1.138 + {
1.139 +public:
1.140 + DWin32CodeSeg();
1.141 + virtual ~DWin32CodeSeg();
1.142 + TInt ProcessImports(DProcess* aProcess);
1.143 + TInt CreateAlreadyLoaded(HMODULE aModule, TInt aDepCount);
1.144 + TInt RegisterCodeSeg(HMODULE aModule);
1.145 + TInt CopyDataBss();
1.146 +public:
1.147 + virtual TLibraryFunction Lookup(TInt aOrdinal);
1.148 + virtual TInt GetMemoryInfo(TModuleMemoryInfo& aInfo, DProcess* aProcess);
1.149 + virtual TInt DoCreate(TCodeSegCreateInfo& aInfo, DProcess* aProcess);
1.150 + virtual TInt Loaded(TCodeSegCreateInfo& aInfo);
1.151 + virtual void InitData();
1.152 + virtual void ReadExportDir(TUint32* aDest);
1.153 + virtual TBool FindCheck(DProcess* aProcess);
1.154 + virtual TBool OpenCheck(DProcess* aProcess);
1.155 + virtual void Info(TCodeSegCreateInfo& aInfo);
1.156 +public:
1.157 + HINSTANCE iWinInstance;
1.158 + HMODULE iModuleHandle;
1.159 + wchar_t* iModuleFile;
1.160 + TBool iAlwaysLoaded; // TRUE for variant or extension
1.161 + DModuleList* iModuleList;
1.162 + TAny* iDataCopy; // copy of .data
1.163 + TInt iRealDataSize;
1.164 + TInt iRealBssSize;
1.165 + TLinAddr iDataDest; // load address of .data
1.166 + TLinAddr iBssDest; // load address of .bss
1.167 + TInt iCodeSegId; // unique ID, incremented each time a code segment is loaded
1.168 + DWin32Process* iLiveProcess;// process who's static data is currently loaded in the codeseg
1.169 + };
1.170 +
1.171 +struct SWin32Module
1.172 + {
1.173 + TLinAddr iWin32ModuleHandle;
1.174 + DWin32CodeSeg* iCodeSeg;
1.175 + };
1.176 +
1.177 +
1.178 +/********************************************
1.179 + * Functions/Data defined in memory model
1.180 + ********************************************/
1.181 +
1.182 +class MM
1.183 + {
1.184 +public:
1.185 + enum TMemModelPanic
1.186 + {
1.187 + EKernelHeapReserveFailed = 0,
1.188 + EKernelHeapCommitFailed = 1,
1.189 + ERamAllocMutexCreateFailed = 2,
1.190 + EInvalidChunkCreate = 3,
1.191 + EInvalidSharedModule = 4,
1.192 + ECompileDepLists=5,
1.193 + EWin32RuntimeError=6,
1.194 + ENotSupportedOnEmulator=7,
1.195 + EWsdBadReserve=8,
1.196 + EWsdDllNotInProcess=9,
1.197 + };
1.198 +
1.199 + static void Panic(TMemModelPanic aPanic);
1.200 +public:
1.201 + static void Init1();
1.202 + static void Wait();
1.203 + static void Signal();
1.204 + static TUint32 RoundToPageSize(TUint32 aSize);
1.205 + static TUint32 RoundToChunkSize(TUint32 aSize);
1.206 + static TInt RegisterModule(HMODULE aModule);
1.207 + static TInt Commit(TLinAddr aBase, TInt aSize, TInt aClearByte, TBool aExecute);
1.208 + static TInt Decommit(TLinAddr aBase, TInt aSize);
1.209 + static void CheckMemoryCounters();
1.210 + static void DoProcessSwitch(TAny* aAddressSpace);
1.211 + static TAny* CurrentAddress(DThread* aThread, const TAny* aPtr, TInt aSize, TBool aWrite, TBool& aLocked);
1.212 +public:
1.213 + static TAny* KernelHeapAddress;
1.214 + static DMutex* RamAllocatorMutex;
1.215 + static TInt RamChunkSize;
1.216 + static TInt RamChunkShift;
1.217 + static TInt RamPageSize;
1.218 + static TInt RamPageShift;
1.219 + static TInt FreeMemory; // number of bytes in the system free memory
1.220 + static TInt CacheMemory; // number of bytes of memory being used for cache chunks (RChunk::Unlock)
1.221 + static TInt ReclaimedCacheMemory; // number of bytes of memory removed from CacheMemory in order to satisfy memory allocation
1.222 + static TInt InitialFreeMemory;
1.223 + static TBool AllocFailed;
1.224 + static RArray<SWin32Module> Win32Modules;
1.225 + static TInt NextCodeSegId;
1.226 + };
1.227 +
1.228 +
1.229 +/********************************************
1.230 + * Shared buffers and pools
1.231 + ********************************************/
1.232 +
1.233 +class DWin32ShBuf : public DShBuf
1.234 + {
1.235 +public:
1.236 + DWin32ShBuf(DShPool* aPool, TLinAddr aRelAddr);
1.237 + ~DWin32ShBuf();
1.238 +
1.239 + TInt AddToProcess(DProcess* aProcess, TUint aAttr);
1.240 +
1.241 + TInt Close(TAny* aPtr);
1.242 +
1.243 +protected:
1.244 + virtual TInt Map(TUint, DProcess*, TLinAddr&);
1.245 + virtual TInt UnMap(DProcess*);
1.246 + virtual TUint8* Base(DProcess* aProcess);
1.247 + virtual TUint8* Base();
1.248 +
1.249 +private:
1.250 + TBool iMapped;
1.251 + };
1.252 +
1.253 +
1.254 +class DWin32ShPool : public DShPool
1.255 + {
1.256 +public:
1.257 + DWin32ShPool();
1.258 + virtual ~DWin32ShPool();
1.259 +
1.260 + TInt Close(TAny* aPtr);
1.261 + TInt AddToProcess(DProcess* aProcess, TUint aAttr);
1.262 + TInt Alloc(DShBuf*&);
1.263 +
1.264 +protected:
1.265 + TInt DoCreate(TShPoolCreateInfo& aInfo);
1.266 + TInt AddToFreeList(TInt aOffset);
1.267 + TInt CreateInitialBuffers();
1.268 + TInt DeleteInitialBuffers();
1.269 + TInt DestroyHandles(DProcess* aProcess);
1.270 + void DestroyClientResources(DProcess* aProcess);
1.271 +
1.272 + void Free(DShBuf* aBuf);
1.273 + TInt UpdateFreeList();
1.274 +
1.275 + TUint8* Base();
1.276 + TUint8* Base(DProcess* aProcess);
1.277 + TBool IsOpen(DProcess* aProcess);
1.278 +
1.279 + TBitMapAllocator* iBufMap;
1.280 + DWin32ShBuf* iInitialBuffersArray;
1.281 + TUint8* iWin32MemoryBase;
1.282 + TInt iWin32MemorySize;
1.283 + friend class DWin32ShBuf;
1.284 + };
1.285 +
1.286 +
1.287 +class DWin32AlignedShPool : public DWin32ShPool
1.288 + {
1.289 +public:
1.290 + DWin32AlignedShPool();
1.291 + virtual ~DWin32AlignedShPool();
1.292 + TInt SetBufferWindow(DProcess* aProcess, TInt aWindowSize);
1.293 +
1.294 +private:
1.295 + TInt DoCreate(TShPoolCreateInfo& aInfo);
1.296 + TInt GrowPool();
1.297 + TInt ShrinkPool();
1.298 + };
1.299 +
1.300 +
1.301 +class DWin32NonAlignedShPool : public DWin32ShPool
1.302 + {
1.303 +public:
1.304 + DWin32NonAlignedShPool();
1.305 + virtual ~DWin32NonAlignedShPool();
1.306 +
1.307 +private:
1.308 + TInt DoCreate(TShPoolCreateInfo& aInfo);
1.309 + void FreeBufferPages(TUint aOffset);
1.310 + TInt GrowPool();
1.311 + TInt ShrinkPool();
1.312 +
1.313 + TBitMapAllocator* iPagesMap;
1.314 + };
1.315 +
1.316 +#endif // __WIN32_MEM_H__