os/kernelhwsrv/kernel/eka/include/memmodel/epoc/flexible/memmodel.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32/include/memmodel/epoc/flexible/memmodel.h
sl@0
    15
// Flexible Memory Model header file
sl@0
    16
sl@0
    17
/**
sl@0
    18
 @file
sl@0
    19
 @internalComponent
sl@0
    20
*/
sl@0
    21
sl@0
    22
sl@0
    23
#ifndef __MEMMODEL_H__
sl@0
    24
#define __MEMMODEL_H__
sl@0
    25
sl@0
    26
#include <plat_priv.h>
sl@0
    27
#include <memmodel/epoc/mmubase/kblockmap.h>
sl@0
    28
#include <mmtypes.h>
sl@0
    29
#include <mmboot.h>
sl@0
    30
sl@0
    31
#ifdef __SMP__
sl@0
    32
// SubScheduler fields for each processor
sl@0
    33
#define	i_AliasLinAddr			iExtras[0]
sl@0
    34
#define	i_AliasPdePtr			iExtras[1]
sl@0
    35
#endif
sl@0
    36
sl@0
    37
/********************************************
sl@0
    38
 * Deterministic Scheduler Implementation
sl@0
    39
 ********************************************/
sl@0
    40
sl@0
    41
/**
sl@0
    42
@internalComponent
sl@0
    43
*/
sl@0
    44
#define TheCurrentAddressSpace			((DMemModelProcess*&)TheScheduler.iAddressSpace)
sl@0
    45
sl@0
    46
class DMemoryObject;
sl@0
    47
class DMemoryMapping;
sl@0
    48
sl@0
    49
/********************************************
sl@0
    50
 * Thread Control Block
sl@0
    51
 ********************************************/
sl@0
    52
sl@0
    53
class DMemModelProcess;
sl@0
    54
sl@0
    55
/**
sl@0
    56
@internalComponent
sl@0
    57
*/
sl@0
    58
class DMemModelThread : public DThread
sl@0
    59
	{
sl@0
    60
public:
sl@0
    61
	TInt Alias(TLinAddr aAddr, DMemModelProcess* aProcess, TInt aSize, TLinAddr& aAliasAddr, TUint& aAliasSize);
sl@0
    62
	void RemoveAlias();
sl@0
    63
	void RefreshAlias();
sl@0
    64
	virtual void DoExit1();
sl@0
    65
	static void RestoreAddressSpace();
sl@0
    66
 	virtual void BTracePrime(TInt aCategory);
sl@0
    67
protected:
sl@0
    68
	virtual void SetPaging(TUint& aCreateFlags);
sl@0
    69
private:
sl@0
    70
	void DoRemoveAlias(TLinAddr aAddr);
sl@0
    71
public:
sl@0
    72
	TLinAddr iAliasLinAddr;	// linear address to access aliased memory (0 means no alias is present).
sl@0
    73
	TPde* iAliasPdePtr;		// Address of PDE which has been modified to make aliased memory accessible.
sl@0
    74
	TPde iAliasPde;			// PDE to store at iAliasPdePtr.
sl@0
    75
	DMemModelProcess* iAliasProcess;		// The process whose memory is aliased.
sl@0
    76
	SDblQueLink iAliasLink;	// link to make TheMmu.iAliasList.
sl@0
    77
	TLinAddr iAliasTarget;	// linear address of the memory which has been aliased
sl@0
    78
	DMemoryMapping* iKernelStackMapping;
sl@0
    79
	DMemoryMapping* iUserStackMapping;
sl@0
    80
#ifdef __SMP__
sl@0
    81
	TInt iCpuRestoreCookie;
sl@0
    82
#endif
sl@0
    83
	};
sl@0
    84
sl@0
    85
sl@0
    86
/********************************************
sl@0
    87
 * Process Control Block
sl@0
    88
 ********************************************/
sl@0
    89
sl@0
    90
class DMemModelChunk;
sl@0
    91
class DMemModelCodeSegMemory;
sl@0
    92
class RAddressedContainer;
sl@0
    93
sl@0
    94
#ifdef INCLUDED_FROM_ASM
sl@0
    95
#define PRIVATE_EXCEPT_ASM public
sl@0
    96
#else
sl@0
    97
#define PRIVATE_EXCEPT_ASM private
sl@0
    98
#endif
sl@0
    99
sl@0
   100
sl@0
   101
/**
sl@0
   102
@internalComponent
sl@0
   103
*/
sl@0
   104
class DMemModelProcess : public DEpocProcess
sl@0
   105
	{
sl@0
   106
public:
sl@0
   107
	~DMemModelProcess();
sl@0
   108
private:
sl@0
   109
	void Destruct();
sl@0
   110
protected:
sl@0
   111
	virtual TInt AttachExistingCodeSeg(TProcessCreateInfo& aInfo);
sl@0
   112
	virtual TInt SetPaging(const TProcessCreateInfo& aInfo);
sl@0
   113
public:
sl@0
   114
	virtual TInt DoCreate(TBool aKernelProcess, TProcessCreateInfo& aInfo);
sl@0
   115
	virtual TInt NewChunk(DChunk*& aChunk, SChunkCreateInfo& aInfo, TLinAddr& aRunAddr);
sl@0
   116
	virtual TInt AddChunk(DChunk* aChunk,TBool aIsReadOnly);
sl@0
   117
	virtual TInt NewShPool(DShPool*& aPool, TShPoolCreateInfo& aInfo);
sl@0
   118
	virtual TInt CreateDataBssStackArea(TProcessCreateInfo& aInfo);
sl@0
   119
	virtual TInt MapCodeSeg(DCodeSeg* aCodeSeg);
sl@0
   120
	virtual void UnmapCodeSeg(DCodeSeg* aCodeSeg);
sl@0
   121
	virtual void RemoveDllData();
sl@0
   122
	virtual void FinalRelease();
sl@0
   123
	virtual void BTracePrime(TInt aCategory);
sl@0
   124
public:
sl@0
   125
	TInt DoAddChunk(DMemModelChunk* aChunk, TBool aIsReadOnly);
sl@0
   126
	TInt AllocateDataSectionBase(DMemModelChunk& aChunk, TUint& aBase);
sl@0
   127
	TUint8* DataSectionBase(DMemModelChunk* aChunk);
sl@0
   128
	void RemoveChunk(DMemModelChunk *aChunk);
sl@0
   129
	void DoRemoveChunk(TInt aIndex);
sl@0
   130
	TInt ChunkIndex(DMemModelChunk* aChunk);
sl@0
   131
	TUint ChunkInsertIndex(DMemModelChunk* aChunk);
sl@0
   132
	TInt CommitDllData(TLinAddr aBase, TInt aSize, DCodeSeg* aCodeSeg);
sl@0
   133
	void DecommitDllData(TLinAddr aBase, TInt aSize);
sl@0
   134
	TInt MapUserRamCode(DMemModelCodeSegMemory* aMemory);
sl@0
   135
	void UnmapUserRamCode(DMemModelCodeSegMemory* aMemory);
sl@0
   136
	inline TInt OsAsid()
sl@0
   137
		{__NK_ASSERT_DEBUG(	TheCurrentThread->iOwningProcess == this || // current thread's process so asid can't be freed.
sl@0
   138
							iOsAsid == (TInt)KKernelOsAsid ||	// kernel process so asid can't be freed.
sl@0
   139
							iContainerID != EProcess ||	// process not fully created yet so asid can't be freed.
sl@0
   140
							iOsAsidRefCount > 1);		// if none of the others are true then should have a reference 
sl@0
   141
														// to prevent asid being freed (this check isn't very 
sl@0
   142
														// robust but best we can do).
sl@0
   143
		return iOsAsid;
sl@0
   144
		};
sl@0
   145
sl@0
   146
	TInt TryOpenOsAsid();
sl@0
   147
	void CloseOsAsid();
sl@0
   148
	void AsyncCloseOsAsid();
sl@0
   149
public:
sl@0
   150
	struct SChunkInfo
sl@0
   151
		{
sl@0
   152
		DMemModelChunk* iChunk;
sl@0
   153
		DMemoryMapping* iMapping;
sl@0
   154
		TInt16 iAccessCount;
sl@0
   155
		TInt16 iIsReadOnly;
sl@0
   156
		};
sl@0
   157
sl@0
   158
	TInt iChunkCount;
sl@0
   159
	TInt iChunkAlloc;
sl@0
   160
	SChunkInfo* iChunks;
sl@0
   161
	RAddressedContainer* iSharedChunks;
sl@0
   162
	TPhysAddr iPageDir;
sl@0
   163
	DMemoryMapping* iDataBssMapping;
sl@0
   164
	/**
sl@0
   165
	Size of virtual memory allocated in process for EXE code, but which hasn't yet been been
sl@0
   166
	adopted by the codeseg memory mapping.
sl@0
   167
	*/
sl@0
   168
	TUint iCodeVirtualAllocSize;
sl@0
   169
	/**
sl@0
   170
	Address of virtual memory allocated in process for EXE code.
sl@0
   171
	*/
sl@0
   172
	TLinAddr iCodeVirtualAllocAddress;
sl@0
   173
sl@0
   174
PRIVATE_EXCEPT_ASM:
sl@0
   175
	TInt iOsAsid;		// This should only be accessed directly by the scheduler, 
sl@0
   176
						// in all other cases use either OsAsid() or TryOpenOsAsid().
sl@0
   177
private:
sl@0
   178
	TUint iOsAsidRefCount;
sl@0
   179
public:
sl@0
   180
	friend class Monitor;
sl@0
   181
	};
sl@0
   182
sl@0
   183
sl@0
   184
/********************************************
sl@0
   185
 * Chunk Control Block
sl@0
   186
 ********************************************/
sl@0
   187
sl@0
   188
/**
sl@0
   189
@internalComponent
sl@0
   190
*/
sl@0
   191
class DMemModelChunk : public DChunk
sl@0
   192
	{
sl@0
   193
public:
sl@0
   194
	/**
sl@0
   195
	@see DChunk::TChunkAttributes for generic attribute flags
sl@0
   196
	*/
sl@0
   197
	enum TMemModelChunkAttributes
sl@0
   198
		{
sl@0
   199
		EPrivate			=0x00000000, // need to be iOwningProcess in order to map or change chunk
sl@0
   200
		EPublic				=0x80000000, // not EPrivate
sl@0
   201
		ECode				=0x40000000, // contents are executable
sl@0
   202
		EMMChunkAttributesMask = EPrivate | EPublic | ECode,
sl@0
   203
		};
sl@0
   204
	
sl@0
   205
public:
sl@0
   206
	DMemModelChunk();
sl@0
   207
	~DMemModelChunk();
sl@0
   208
public:
sl@0
   209
	virtual TInt Close(TAny* aPtr);
sl@0
   210
	virtual TInt DoCreate(SChunkCreateInfo& aInfo);
sl@0
   211
	virtual TInt Adjust(TInt aNewSize);
sl@0
   212
	virtual TInt AdjustDoubleEnded(TInt aBottom, TInt aTop);
sl@0
   213
	virtual TInt CheckAccess();
sl@0
   214
	virtual TInt Commit(TInt aOffset, TInt aSize, TCommitType aCommitType=DChunk::ECommitDiscontiguous, TUint32* aExtraArg=0);
sl@0
   215
	virtual TInt Allocate(TInt aSize, TInt aGuard=0, TInt aAlign=0);
sl@0
   216
	virtual TInt Decommit(TInt aOffset, TInt aSize);
sl@0
   217
	virtual TInt Lock(TInt aOffset, TInt aSize);
sl@0
   218
	virtual TInt Unlock(TInt aOffset, TInt aSize);
sl@0
   219
	virtual TInt Address(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress);
sl@0
   220
	virtual TInt PhysicalAddress(TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aPhysicalAddress, TUint32* aPhysicalPageList=NULL);
sl@0
   221
	virtual void BTracePrime(TInt aCategory);
sl@0
   222
	virtual void Substitute(TInt aOffset, TPhysAddr aOldAddr, TPhysAddr aNewAddr);
sl@0
   223
	virtual TUint8* Base(DProcess* aProcess);
sl@0
   224
protected:
sl@0
   225
	virtual void SetPaging(TUint aCreateAtt);
sl@0
   226
public:
sl@0
   227
	void SetFixedAddress(TLinAddr aAddr, TInt aInitialSize);
sl@0
   228
	TInt SetAttributes(SChunkCreateInfo& aInfo);
sl@0
   229
	TInt DoCommit(TInt aOffset, TInt aSize, TCommitType aCommitType=DChunk::ECommitDiscontiguous, TUint32* aExtraArg=0);
sl@0
   230
	void DoDecommit(TInt aOffset, TInt aSize);
sl@0
   231
	TInt CheckRegion(TInt& aOffset, TInt& aSize);
sl@0
   232
public:
sl@0
   233
	TBitMapAllocator* iPageBitMap;		// NULL if not disconnected chunk
sl@0
   234
	TBitMapAllocator* iPermanentPageBitMap;
sl@0
   235
sl@0
   236
	/**
sl@0
   237
	The memory object containing this chunk's memory.
sl@0
   238
	*/
sl@0
   239
	DMemoryObject* iMemoryObject;
sl@0
   240
sl@0
   241
	/**
sl@0
   242
	For shared chunks and shared i/o buffers this is the mapping
sl@0
   243
	which maps #iMemoryObject into the kernel's address space.
sl@0
   244
	*/
sl@0
   245
	DMemoryMapping* iKernelMapping;
sl@0
   246
public:
sl@0
   247
	friend class Monitor;
sl@0
   248
	};
sl@0
   249
sl@0
   250
sl@0
   251
/**
sl@0
   252
@internalComponent
sl@0
   253
*/
sl@0
   254
class DMemModelChunkHw : public DPlatChunkHw
sl@0
   255
	{
sl@0
   256
public:
sl@0
   257
	virtual TInt Close(TAny* aPtr);
sl@0
   258
public:
sl@0
   259
	DMemoryObject* iMemoryObject;
sl@0
   260
	DMemoryMapping* iKernelMapping;
sl@0
   261
	};
sl@0
   262
sl@0
   263
sl@0
   264
	
sl@0
   265
/********************************************
sl@0
   266
 * Code segment
sl@0
   267
 ********************************************/
sl@0
   268
sl@0
   269
class TPagedCodeInfo;
sl@0
   270
sl@0
   271
/**
sl@0
   272
@internalComponent
sl@0
   273
*/
sl@0
   274
class DMemModelCodeSegMemory : public DEpocCodeSegMemory
sl@0
   275
	{
sl@0
   276
public:
sl@0
   277
	DMemModelCodeSegMemory(DEpocCodeSeg* aCodeSeg);
sl@0
   278
	~DMemModelCodeSegMemory();
sl@0
   279
	TInt Create(TCodeSegCreateInfo& aInfo, DMemModelProcess* aProcess);
sl@0
   280
	TInt Loaded(TCodeSegCreateInfo& aInfo);
sl@0
   281
	void Destroy();
sl@0
   282
public:
sl@0
   283
	/**
sl@0
   284
	The process loading this code segment.
sl@0
   285
	*/
sl@0
   286
	DMemModelProcess* iCreator;
sl@0
   287
sl@0
   288
	/**
sl@0
   289
	Kernel side copy of the codeseg's export directory or NULL.
sl@0
   290
	*/
sl@0
   291
	TLinAddr* iCopyOfExportDir;
sl@0
   292
sl@0
   293
	/**
sl@0
   294
	For demand paged codeseg's, pointer to saved copy of the data section.
sl@0
   295
	*/
sl@0
   296
	TAny* iDataSectionMemory;
sl@0
   297
sl@0
   298
	/**
sl@0
   299
	The memory object containing the memory for the codeseg.
sl@0
   300
	*/
sl@0
   301
	DMemoryObject* iCodeMemoryObject;
sl@0
   302
sl@0
   303
	/**
sl@0
   304
	A writable mapping which maps #iCodeMemoryObject into the loader
sl@0
   305
	process's memory so it can be accessed by the loader.
sl@0
   306
sl@0
   307
	This mapping is destroyed once #Loaded is called.
sl@0
   308
	*/
sl@0
   309
	DMemoryMapping* iCodeLoadMapping;
sl@0
   310
sl@0
   311
	/**
sl@0
   312
	For demand paged codeseg's, this is a writable mapping added to the
sl@0
   313
	loader process's address space which maps a memory object used to
sl@0
   314
	hold the initial contents of the codeseg's data section.
sl@0
   315
sl@0
   316
	This mapping, and it's memory object, is destroyed once #Loaded is called.
sl@0
   317
	*/
sl@0
   318
	DMemoryMapping* iDataLoadMapping;
sl@0
   319
sl@0
   320
	/**
sl@0
   321
	Size of any shared virtual memory allocated for the code.
sl@0
   322
	*/
sl@0
   323
	TUint iVirtualAllocCommonSize;
sl@0
   324
sl@0
   325
	/**
sl@0
   326
	For demand paged codeseg's, a pointer to the #TPagedCodeInfo
sl@0
   327
	used with #iCodeMemoryObject.
sl@0
   328
	*/
sl@0
   329
	TPagedCodeInfo* iPagedCodeInfo;
sl@0
   330
	};
sl@0
   331
sl@0
   332
sl@0
   333
/**
sl@0
   334
@internalComponent
sl@0
   335
*/
sl@0
   336
class DMemModelCodeSeg: public DEpocCodeSeg
sl@0
   337
	{
sl@0
   338
public:
sl@0
   339
	DMemModelCodeSeg();
sl@0
   340
	virtual ~DMemModelCodeSeg();
sl@0
   341
	virtual TInt DoCreateRam(TCodeSegCreateInfo& aInfo, DProcess* aProcess);
sl@0
   342
	virtual TInt DoCreateXIP(DProcess* aProcess);
sl@0
   343
	virtual TInt Loaded(TCodeSegCreateInfo& aInfo);
sl@0
   344
	virtual void ReadExportDir(TUint32* aDest);
sl@0
   345
	virtual TBool FindCheck(DProcess* aProcess);
sl@0
   346
	virtual TBool OpenCheck(DProcess* aProcess);
sl@0
   347
	inline DMemModelCodeSegMemory* Memory()
sl@0
   348
		{ return (DMemModelCodeSegMemory*)iMemory; }
sl@0
   349
	virtual void BTracePrime(TInt aCategory);
sl@0
   350
public:
sl@0
   351
	/**
sl@0
   352
	For kernel codesegs, the address of the memory allocated for its static data.
sl@0
   353
	*/
sl@0
   354
	TAny* iKernelData;
sl@0
   355
sl@0
   356
	/**
sl@0
   357
	The memory object containing the memory for this codeseg.
sl@0
   358
	*/
sl@0
   359
	DMemoryObject* iCodeMemoryObject;
sl@0
   360
sl@0
   361
	/**
sl@0
   362
	A writable mapping which maps #iCodeMemoryObject into the loader
sl@0
   363
	process's memory so it can be accessed by the loader.
sl@0
   364
sl@0
   365
	This mapping is destroyed once #Loaded is called.
sl@0
   366
	*/
sl@0
   367
	DMemoryMapping* iCodeLoadMapping;
sl@0
   368
sl@0
   369
	/**
sl@0
   370
	The read=only mapping used for kernel and global codesegs to map
sl@0
   371
	#iCodeMemoryObject into the global address region.
sl@0
   372
	*/
sl@0
   373
	DMemoryMapping* iCodeGlobalMapping;
sl@0
   374
sl@0
   375
	/**
sl@0
   376
	Base address of virtual memory allocated for the codeseg's static data.
sl@0
   377
	*/
sl@0
   378
	TLinAddr iDataAllocBase;	
sl@0
   379
sl@0
   380
	/**
sl@0
   381
	Size of virtual memory allocated for the codeseg's static data.
sl@0
   382
	*/
sl@0
   383
	TUint iDataAllocSize;
sl@0
   384
	};
sl@0
   385
sl@0
   386
sl@0
   387
/********************************************
sl@0
   388
 * Shared buffers and pools
sl@0
   389
 ********************************************/
sl@0
   390
sl@0
   391
#include <kernel/sshbuf.h>
sl@0
   392
sl@0
   393
class DShBufMapping;
sl@0
   394
sl@0
   395
sl@0
   396
class DMemModelNonAlignedShBuf : public DShBuf
sl@0
   397
	{
sl@0
   398
public:
sl@0
   399
	DMemModelNonAlignedShBuf(DShPool* aPool, TLinAddr aRelAddr);
sl@0
   400
	~DMemModelNonAlignedShBuf();
sl@0
   401
sl@0
   402
	TInt Close(TAny*);
sl@0
   403
	TInt AddToProcess(DProcess* aProcess, TUint aAttr);
sl@0
   404
sl@0
   405
protected:
sl@0
   406
	virtual TInt Pin(TPhysicalPinObject* aPinObject, TBool aReadOnly, TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour);
sl@0
   407
	virtual TInt Map(TUint, DProcess*, TLinAddr&);
sl@0
   408
	virtual TInt UnMap(DProcess*);
sl@0
   409
	virtual TUint8* Base(DProcess* aProcess);
sl@0
   410
	virtual TUint8* Base();
sl@0
   411
	};
sl@0
   412
sl@0
   413
sl@0
   414
class DMemModelAlignedShBuf : public DShBuf
sl@0
   415
	{
sl@0
   416
public:
sl@0
   417
	DMemModelAlignedShBuf(DShPool* aPool);
sl@0
   418
	virtual ~DMemModelAlignedShBuf();
sl@0
   419
sl@0
   420
	TInt Create();
sl@0
   421
	virtual TInt Construct();
sl@0
   422
sl@0
   423
	TInt Close(TAny*);
sl@0
   424
	TInt AddToProcess(DProcess* aProcess, TUint aAttr);
sl@0
   425
sl@0
   426
protected:
sl@0
   427
	TUint8* Base(DProcess* aProcess);
sl@0
   428
	TUint8* Base();
sl@0
   429
	TInt Map(TUint, DProcess*, TLinAddr&);
sl@0
   430
	TInt UnMap(DProcess*);
sl@0
   431
	TInt Pin(TPhysicalPinObject* aPinObject, TBool aReadOnly, TPhysAddr& Address, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour);
sl@0
   432
sl@0
   433
private:
sl@0
   434
	TInt FindMapping(DShBufMapping*&, DMemModelProcess*);
sl@0
   435
	DMemoryObject* iMemoryObject;
sl@0
   436
	DMemoryMapping* iKernelMapping;
sl@0
   437
	SDblQue iMappings;
sl@0
   438
	friend class DMemModelAlignedShPool;
sl@0
   439
	};
sl@0
   440
sl@0
   441
class DMemModelShPool : public DShPool
sl@0
   442
	{
sl@0
   443
public:
sl@0
   444
	DMemModelShPool();
sl@0
   445
	virtual ~DMemModelShPool();
sl@0
   446
protected:
sl@0
   447
	void DestroyClientResources(DProcess* aProcess);
sl@0
   448
	virtual TInt DestroyAllMappingsAndReservedHandles(DProcess* aProcess) = 0;
sl@0
   449
	};
sl@0
   450
sl@0
   451
class DMemModelAlignedShPoolClient : public DShPoolClient
sl@0
   452
	{
sl@0
   453
public:
sl@0
   454
	SDblQue iMappingFreeList;
sl@0
   455
	TInt iWindowSize;
sl@0
   456
	};
sl@0
   457
sl@0
   458
class DMemModelNonAlignedShPoolClient : public DShPoolClient
sl@0
   459
	{
sl@0
   460
public:
sl@0
   461
	DMemoryMapping* iMapping;
sl@0
   462
	};
sl@0
   463
sl@0
   464
class DShBufMapping;
sl@0
   465
sl@0
   466
class DMemModelAlignedShPool : public DMemModelShPool
sl@0
   467
	{
sl@0
   468
public:
sl@0
   469
	DMemModelAlignedShPool();
sl@0
   470
	virtual ~DMemModelAlignedShPool();
sl@0
   471
sl@0
   472
	TInt Close(TAny* aPtr);
sl@0
   473
	TInt CreateInitialBuffers();
sl@0
   474
	TInt SetBufferWindow(DProcess* aProcess, TInt aWindowSize);
sl@0
   475
	TInt AddToProcess(DProcess* aProcess, TUint aAttr);
sl@0
   476
	TInt Alloc(DShBuf*&);
sl@0
   477
sl@0
   478
private:
sl@0
   479
	TInt DoCreate(TShPoolCreateInfo& aInfo);
sl@0
   480
	TInt GrowPool();
sl@0
   481
	TInt ShrinkPool();
sl@0
   482
	TInt MappingNew(DShBufMapping*& aMapping, DMemModelProcess* aProcess);
sl@0
   483
	TInt GetFreeMapping(DShBufMapping*& aMapping, DMemModelAlignedShPoolClient* aClient);
sl@0
   484
	TInt ReleaseMapping(DShBufMapping*& aMapping, DMemModelAlignedShPoolClient* aClient);
sl@0
   485
	TInt UpdateMappingsAndReservedHandles(TInt aNoOfBuffers);
sl@0
   486
	TInt UpdateFreeList();
sl@0
   487
	void Free(DShBuf* aBuf);
sl@0
   488
	TInt CreateMappings(DMemModelAlignedShPoolClient* aClient, TInt aNoOfMappings, DMemModelProcess* aProcess);
sl@0
   489
	TInt DestroyAllMappingsAndReservedHandles(DProcess* aProcess);
sl@0
   490
	TInt DestroyMappings(DMemModelAlignedShPoolClient* aClient, TInt aNoOfMappings);
sl@0
   491
sl@0
   492
	TInt DeleteInitialBuffers();
sl@0
   493
sl@0
   494
	SDblQue iPendingList;
sl@0
   495
	DMemModelAlignedShBuf* iInitialBuffersArray;
sl@0
   496
sl@0
   497
	friend class DMemModelAlignedShBuf;
sl@0
   498
	};
sl@0
   499
sl@0
   500
class DMemModelNonAlignedShPool : public DMemModelShPool
sl@0
   501
	{
sl@0
   502
public:
sl@0
   503
	DMemModelNonAlignedShPool();
sl@0
   504
	virtual ~DMemModelNonAlignedShPool();
sl@0
   505
sl@0
   506
	TInt Close(TAny* aPtr);
sl@0
   507
sl@0
   508
	TInt DoInitFreeList();
sl@0
   509
	TUint8* Base(DProcess* aProcess);
sl@0
   510
sl@0
   511
	inline TUint8* Base()
sl@0
   512
		{
sl@0
   513
		return reinterpret_cast<TUint8*>(iBaseAddress);
sl@0
   514
		};
sl@0
   515
	TInt AddToProcess(DProcess* aProcess, TUint aAttr);
sl@0
   516
	TInt CreateInitialBuffers();
sl@0
   517
sl@0
   518
	TInt Alloc(DShBuf*&);
sl@0
   519
sl@0
   520
private:
sl@0
   521
	void Free(DShBuf* aBuf);
sl@0
   522
	TInt UpdateFreeList();
sl@0
   523
sl@0
   524
	TInt DoCreate(TShPoolCreateInfo& aInfo);
sl@0
   525
	void FreeBufferPages(TUint aOffset);
sl@0
   526
	TInt GrowPool();
sl@0
   527
	TInt ShrinkPool();
sl@0
   528
	TInt DeleteInitialBuffers();
sl@0
   529
	TInt DestroyAllMappingsAndReservedHandles(DProcess* aProcess);
sl@0
   530
sl@0
   531
private:
sl@0
   532
	TLinAddr iBaseAddress;
sl@0
   533
	DMemoryObject* iMemoryObject;		// the 'real' memory pool (in the kernel)
sl@0
   534
	DMemModelNonAlignedShBuf* iInitialBuffersArray;
sl@0
   535
	TBitMapAllocator* iBufMap;
sl@0
   536
	TBitMapAllocator* iPagesMap;
sl@0
   537
sl@0
   538
	friend class DMemModelNonAlignedShBuf;
sl@0
   539
	};
sl@0
   540
sl@0
   541
#endif