author | hgs |
Fri, 23 Apr 2010 22:08:41 +0100 | |
changeset 121 | 661475905584 |
parent 90 | 947f0dc9f7a8 |
child 102 | ef2a444a7410 |
child 132 | e4a7b1cbe40c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
/** |
|
17 |
@file |
|
18 |
@internalComponent |
|
19 |
*/ |
|
20 |
||
21 |
#ifndef MMANAGER_H |
|
22 |
#define MMANAGER_H |
|
23 |
||
24 |
#include "mpagearray.h" |
|
25 |
||
26 |
||
27 |
class DMemoryObject; |
|
28 |
class DMemoryMappingBase; |
|
29 |
class DPageReadRequest; |
|
30 |
class DPageWriteRequest; |
|
31 |
||
32 |
/** |
|
33 |
An abstract interface for performing operations on a memory object, such as allocating |
|
34 |
or freeing memory. |
|
35 |
||
36 |
There are different concrete implementations of this class for memory being managed in |
|
37 |
different ways, e.g. demand paged versus unpaged memory. |
|
38 |
||
39 |
Any particular instance of a manager will only support a subset of the methods provided. |
|
40 |
The default implementations of these in this base class return KErrErrNotSupported. |
|
41 |
*/ |
|
42 |
class DMemoryManager : public DBase |
|
43 |
{ |
|
44 |
public: |
|
45 |
/** |
|
46 |
Create a new memory object for use with this manager. |
|
47 |
||
48 |
@param[out] aMemory On success this is set to the address of the created memory object. |
|
49 |
@param aSizeInPages Size of the memory object, in number of pages. |
|
50 |
@param aAttributes Bitmask of values from enum #TMemoryAttributes. |
|
51 |
@param aCreateFlags Bitmask of option flags from enum #TMemoryCreateFlags. |
|
52 |
||
53 |
@return KErrNone if successful, otherwise one of the system wide error codes. |
|
54 |
*/ |
|
55 |
virtual TInt New(DMemoryObject*& aMemory, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags); |
|
56 |
||
57 |
/** |
|
58 |
Remove all memory from a memory object and close a reference on it. |
|
59 |
||
60 |
If there are no longer any mappings to the memory, or other references, |
|
61 |
this will result in the memory object being destroyed. However whilst |
|
62 |
other references exist, cleanup of memory and other resources may be |
|
63 |
delayed indefinitely. |
|
64 |
||
65 |
@param aMemory A memory object associated with this manager. |
|
66 |
*/ |
|
67 |
virtual void Destruct(DMemoryObject* aMemory) =0; |
|
68 |
||
69 |
/** |
|
70 |
Allocate memory resources for a specified region of a memory object. |
|
71 |
||
72 |
Depending on the manager, this may involve allocating physical RAM pages or |
|
73 |
reserving space in a backing store. |
|
74 |
||
75 |
@param aMemory A memory object associated with this manager. |
|
76 |
@param aIndex Page index for the start of the region. |
|
77 |
@param aCount Number of pages in the region. |
|
78 |
||
79 |
@return KErrNone if successful, |
|
80 |
KErrAlreadyExists if any part of the region was already allocated, |
|
81 |
KErrNotSupported if the manager doesn't support this function, |
|
82 |
otherwise one of the system wide error codes. |
|
83 |
*/ |
|
84 |
virtual TInt Alloc(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
85 |
||
86 |
/** |
|
87 |
Allocate physically contiguous RAM for a specified region of a memory object. |
|
88 |
||
89 |
Important note, this function can unexpectedly fail with KErrAlreadyExists |
|
90 |
if any part of the the region previously contained allocated memory which |
|
91 |
had been freed but which was pinned. It is therefore not suitable for general |
|
92 |
use. |
|
93 |
||
94 |
@param aMemory A memory object associated with this manager. |
|
95 |
@param aIndex Page index for the start of the region. |
|
96 |
@param aCount Number of pages in the region. |
|
97 |
@param aAlign Log2 of the alignment (in bytes) that the address of the |
|
98 |
allocated physical RAM must have. |
|
99 |
@param[out] aPhysAddr On success, this is set to the start address of the |
|
100 |
allocated physical RAM. |
|
101 |
||
102 |
@return KErrNone if successful, |
|
103 |
KErrAlreadyExists if any part of the region was already allocated, |
|
104 |
KErrNotSupported if the manager doesn't support this function, |
|
105 |
otherwise one of the system wide error codes. |
|
106 |
*/ |
|
107 |
virtual TInt AllocContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TUint aAlign, TPhysAddr& aPhysAddr); |
|
108 |
||
109 |
/** |
|
110 |
Free any memory resources used for a specified region of a memory object. |
|
111 |
This is the inverse operation to #Alloc and #AllocContiguous. |
|
112 |
||
113 |
Depending on the manager, this may involve freeing space in a backing store |
|
114 |
as well as freeing any currently committed RAM. |
|
115 |
||
116 |
If part of the memory is currently pinned then resource freeing may be delayed |
|
117 |
indefinitely. |
|
118 |
||
119 |
@param aMemory A memory object associated with this manager. |
|
120 |
@param aIndex Page index for the start of the region. |
|
121 |
@param aCount Number of pages in the region. |
|
122 |
*/ |
|
123 |
virtual void Free(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
124 |
||
125 |
/** |
|
126 |
Wipe the entire memory contents of the memory object so they are in the |
|
127 |
same state as if the memory had been newly allocated with #Alloc. |
|
128 |
||
129 |
This doesn't allocate any new memory, just fills the existing contents |
|
130 |
with the appropriate wipe byte which is used with the memory object. |
|
131 |
||
132 |
@param aMemory A memory object associated with this manager. |
|
133 |
||
134 |
@see EMemoryCreateUseCustomWipeByte |
|
135 |
@see EMemoryCreateNoWipe |
|
136 |
||
137 |
@return KErrNone, if successful; |
|
138 |
otherwise KErrNotSupported, to indicate the memory object doesn't support this operation. |
|
139 |
*/ |
|
140 |
virtual TInt Wipe(DMemoryObject* aMemory); |
|
141 |
||
142 |
/** |
|
143 |
Add a specified set of physical memory pages to a region of a memory object. |
|
144 |
||
145 |
@param aMemory A memory object associated with this manager. |
|
146 |
@param aIndex Page index for the start of the region. |
|
147 |
@param aCount Number of pages in the region. |
|
148 |
@param aPages Pointer to array of pages to add. This must contain \a aCount |
|
149 |
number of physical page addresses which are each page aligned. |
|
150 |
||
151 |
@return KErrNone if successful, |
|
152 |
KErrAlreadyExists if any part of the region was already allocated, |
|
153 |
KErrNotSupported if the manager doesn't support this function, |
|
154 |
otherwise one of the system wide error codes. |
|
155 |
*/ |
|
156 |
virtual TInt AddPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr* aPages); |
|
157 |
||
158 |
/** |
|
159 |
Add a contiguous range of physical memory pages to a region of a memory object. |
|
160 |
||
161 |
@param aMemory A memory object associated with this manager. |
|
162 |
@param aIndex Page index for the start of the region. |
|
163 |
@param aCount Number of pages in the region. |
|
164 |
@param aPhysAddr The page aligned start address of the pages to be added. |
|
165 |
||
166 |
@return KErrNone if successful, |
|
167 |
KErrAlreadyExists if any part of the region was already allocated, |
|
168 |
KErrNotSupported if the manager doesn't support this function, |
|
169 |
otherwise one of the system wide error codes. |
|
170 |
*/ |
|
171 |
virtual TInt AddContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr aPhysAddr); |
|
172 |
||
173 |
/** |
|
174 |
Remove the memory pages from a specified region of a memory object. |
|
175 |
This is the inverse operation to #AddPages and #AddContiguous. |
|
176 |
||
177 |
@param aMemory A memory object associated with this manager. |
|
178 |
@param aIndex Page index for the start of the region. |
|
179 |
@param aCount Number of pages in the region. |
|
180 |
@param[out] aPages Pointer to an array of physical addresses which has a |
|
181 |
length of \a aCount. The contents of this will be set to |
|
182 |
the addresses of the pages which were removed by this |
|
183 |
function. The number of valid entries in this array is |
|
184 |
given by the return value of this function. |
|
185 |
aPages may be the null-pointer, to indicate that these |
|
186 |
page addresses aren't required by the caller. |
|
187 |
||
188 |
@return The number of pages successfully removed from the memory object. |
|
189 |
This gives the number of valid entries in the array \a aPages and is |
|
190 |
less-than or equal to \a aCount. |
|
191 |
*/ |
|
192 |
virtual TInt RemovePages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr* aPages); |
|
193 |
||
194 |
/** |
|
195 |
Mark the specified region of a memory object as discardable. |
|
196 |
The system may remove discardable pages from the memory object at any time, |
|
197 |
to be reused for other purposes. |
|
198 |
||
199 |
@param aMemory A memory object associated with this manager. |
|
200 |
@param aIndex Page index for the start of the region. |
|
201 |
@param aCount Number of pages in the region. |
|
202 |
||
203 |
@return KErrNone if successful, |
|
204 |
KErrNotSupported if the manager doesn't support this function, |
|
205 |
otherwise one of the system wide error codes. |
|
206 |
*/ |
|
207 |
virtual TInt AllowDiscard(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
208 |
||
209 |
/** |
|
210 |
Mark the specified region of a memory object as no longer discardable. |
|
211 |
This undoes the operation of #AllowDiscard. |
|
212 |
||
213 |
If any pages in the region are no longer present, then the operation will |
|
214 |
fail with KErrNotFound. In this case, the state of the pages in the region |
|
215 |
is indeterminate; they may be either still discardable, not discardable, or |
|
216 |
not present. |
|
217 |
||
218 |
@param aMemory A memory object associated with this manager. |
|
219 |
@param aIndex Page index for the start of the region. |
|
220 |
@param aCount Number of pages in the region. |
|
221 |
||
222 |
@return KErrNone if successful, |
|
223 |
KErrNotFound if any page in the region was no longer present, |
|
224 |
KErrNotSupported if the manager doesn't support this function, |
|
225 |
otherwise one of the system wide error codes. |
|
226 |
*/ |
|
227 |
virtual TInt DisallowDiscard(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
228 |
||
229 |
/** |
|
230 |
Remove a page of RAM from a memory object. |
|
231 |
||
232 |
This is only intended for use by #DPager::StealPage when it removes a page |
|
233 |
from the demand paging live list. |
|
234 |
||
235 |
@param aMemory A memory object associated with this manager. |
|
236 |
@param aPageInfo The page information structure of the page to be stolen. |
|
237 |
This must be owned by \a aMemory. |
|
238 |
||
239 |
@return KErrNone if successful, |
|
240 |
KErrInUse if the page became pinned or was subject to a page fault, |
|
241 |
KErrNotSupported if the manager doesn't support this function, |
|
242 |
otherwise one of the system wide error codes. |
|
243 |
||
244 |
@pre RamAllocLock held. |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
@pre If the page is dirty the PageCleaning lock must be held. |
0 | 246 |
@pre MmuLock held. |
247 |
*/ |
|
248 |
virtual TInt StealPage(DMemoryObject* aMemory, SPageInfo* aPageInfo); |
|
249 |
||
250 |
/** |
|
251 |
Restrict the access permissions for a page of RAM. |
|
252 |
||
253 |
This is only intended for use by #DPager::RestrictPage when it restricts |
|
254 |
access to a page in the demand paging live list. |
|
255 |
||
256 |
@param aMemory A memory object associated with this manager. |
|
257 |
@param aPageInfo The page information structure of the page to be restricted. |
|
258 |
This must be owned by \a aMemory. |
|
259 |
@param aRestriction The restriction type to apply. |
|
260 |
||
261 |
@return KErrNone if successful, |
|
262 |
KErrInUse if the page state changed, e.g. became pinned or was subject to a page fault, |
|
263 |
KErrNotSupported if the manager doesn't support this function, |
|
264 |
otherwise one of the system wide error codes. |
|
265 |
*/ |
|
266 |
virtual TInt RestrictPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TRestrictPagesType aRestriction); |
|
267 |
||
268 |
/** |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
Clean multiple pages of RAM by saving any modifications to it out to backing store. |
0 | 270 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
This function must only be called when there are no writable MMU mappings of the pages. |
0 | 272 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
The function takes an array of SPageInfo pointers indicating the pages to clean. On return, the |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
elements of this array are unchanged if the page was successfully cleaned, or set to NULL if |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
cleaning was abandoned (by the page being written to, for example). |
0 | 276 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
The pages passed must be sequential in their page colour (index & KPageColourMask). |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
Those pages that are successfully cleaned are marked as clean using SPageInfo::SetClean. |
0 | 280 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
This is intended for use by #StealPage and #CleanSomePages. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
@param aPageCount Number of pages to clean. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
@param aPageInfos Pointer to an array of aPageCount page info pointers. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
@param aBackground Whether the activity should be ignored when determining whether the |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
paging device is busy. |
0 | 287 |
|
288 |
@pre MmuLock held |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
@pre PageCleaning lock held |
0 | 290 |
@pre The memory page must not have any writeable MMU mappings. |
291 |
@post MmuLock held (but may have been released by this function) |
|
292 |
*/ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
virtual void CleanPages(TUint aPageCount, SPageInfo** aPageInfos, TBool aBackground); |
0 | 294 |
|
295 |
/** |
|
296 |
Process a page fault in memory associated with this manager. |
|
297 |
||
298 |
This is only intended for use by #DPager::HandlePageFault. |
|
299 |
||
300 |
@param aMemory A memory object associated with this manager whose memory was |
|
301 |
accessed by the page fault. |
|
302 |
@param aIndex Page index, within the memory, at which the page fault occurred. |
|
303 |
@param aMapping The memory mapping in which the page fault occurred. |
|
304 |
@param aMapInstanceCount The instance count of the mapping that took the page fault. |
|
305 |
@param aAccessPermissions Flags from enum #TMappingPermissions indicating the memory |
|
306 |
access permissions used by the page fault. E.g. the #EReadWrite |
|
307 |
flag will be set for a write access. |
|
308 |
||
309 |
@return KErrNone if the fault was handled successfully and the running program should |
|
310 |
restart at the faulting instruction. |
|
311 |
Otherwise, one of the system wide error codes indicating that the program generating |
|
312 |
the page fault attempted an invalid memory access. |
|
313 |
*/ |
|
314 |
virtual TInt HandleFault( DMemoryObject* aMemory, TUint aIndex, DMemoryMapping* aMapping, |
|
315 |
TUint aMapInstanceCount, TUint aAccessPermissions); |
|
316 |
||
317 |
/** |
|
318 |
Pin the region of a memory object covered by a specified memory mapping. |
|
319 |
||
320 |
This function should ensure that the memory pages covered by the mapping are |
|
321 |
present in the memory object and will not be removed again until an #Unpin |
|
322 |
operation is issued. Additionally, for demand paged memory, the pages |
|
323 |
must be mapped into \a aMapping using DMemoryMappingBase::PageIn. |
|
324 |
||
325 |
This function is only intended to be called via DMemoryMappingBase::DoPin |
|
326 |
which is itself called from DMemoryMappingBase::Attach. |
|
327 |
||
328 |
@param aMemory A memory object associated with this manager. |
|
329 |
@param aMapping A mapping with the DMemoryMappingBase::EPinned attribute which |
|
330 |
has been attached to \a aMemory. |
|
331 |
@param aPinArgs The resources to use for pinning. This must have sufficient replacement |
|
332 |
pages allocated to pin every page the mapping covers. Also, the |
|
333 |
value of \a aPinArgs.iReadOnly must be set to correspond to the |
|
334 |
mappings access permissions. |
|
335 |
||
336 |
@return KErrNone if successful, |
|
337 |
KErrNotFound if any part of the memory to be pinned was not present, |
|
338 |
otherwise one of the system wide error codes. |
|
339 |
*/ |
|
340 |
virtual TInt Pin(DMemoryObject* aMemory, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs) =0; |
|
341 |
||
342 |
/** |
|
343 |
Unpin the region of a memory object covered by a specified memory mapping. |
|
344 |
||
345 |
This reverses the action of #Pin and is only intended to be called from |
|
346 |
DMemoryMappingBase::Detach. |
|
347 |
||
348 |
Note, pinning is a reference counting operation, therefore pages must stay |
|
349 |
resident in memory (pinned) until the number of unpinning operations affecting |
|
350 |
them equals the number of pinning operations. |
|
351 |
||
352 |
@param aMemory A memory object associated with this manager. |
|
353 |
@param aMapping A mapping with the DMemoryMappingBase::EPinned attribute which |
|
354 |
has been attached to \a aMemory. |
|
355 |
@param aPinArgs The resources used for pinning. The replacement pages allocated |
|
356 |
to this will be increased for each page which was became completely |
|
357 |
unpinned. |
|
358 |
*/ |
|
359 |
virtual void Unpin(DMemoryObject* aMemory, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs) =0; |
|
360 |
||
361 |
/** |
|
362 |
@todo |
|
363 |
*/ |
|
364 |
virtual TInt MovePage(DMemoryObject* aMemory, SPageInfo* aOldPageInfo, TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest); |
|
365 |
||
366 |
/** |
|
367 |
Return the TZonePageType of the pages that the memory manager can allocate and free. |
|
368 |
*/ |
|
369 |
virtual TZonePageType PageType(); |
|
370 |
||
371 |
/** |
|
372 |
Bitmask representing the different cleanup operations which can be performed |
|
373 |
on a memory object. The operations are queued with #QueueCleanup and |
|
374 |
pending operations are stored in each memory object's DMemoryObject::iCleanupFlags. |
|
375 |
*/ |
|
376 |
enum TCleanupOperationFlag |
|
377 |
{ |
|
378 |
/** |
|
379 |
Execute #DoCleanupDecommitted. |
|
380 |
*/ |
|
381 |
ECleanupDecommitted = 1<<0, |
|
382 |
||
383 |
/** |
|
384 |
Internal flag which indicates that cleanup has been queued. |
|
385 |
*/ |
|
386 |
ECleanupIsQueued = 1u<<31 |
|
387 |
}; |
|
388 |
||
389 |
/** |
|
390 |
Queue a cleanup operation to run for a specified memory object. |
|
391 |
||
392 |
The operations are run from #CleanupFunction which is called |
|
393 |
from a #TMemoryCleanup callback. |
|
394 |
||
395 |
@param aMemory The memory object. |
|
396 |
@param aCleanupOp The operation to perform. |
|
397 |
*/ |
|
398 |
static void QueueCleanup(DMemoryObject* aMemory, TCleanupOperationFlag aCleanupOp); |
|
399 |
||
400 |
protected: |
|
401 |
||
402 |
/** |
|
403 |
Unmap and free the RAM pages used for a specified region of a memory object. |
|
404 |
||
405 |
Successfully freed pages are returned to the system's free RAM pool. |
|
406 |
However, pinned pages are placed in the decommitted state |
|
407 |
(RPageArray::EDecommitted) and remain allocated to the memory object. |
|
408 |
These decommitted pages may ultimately get freed by #FreeDecommitted |
|
409 |
or they may become re-allocated with #ReAllocDecommitted. |
|
410 |
||
411 |
@param aMemory A memory object associated with this manager. |
|
412 |
@param aIndex Page index for the start of the region. |
|
413 |
@param aCount Number of pages in the region. |
|
414 |
*/ |
|
415 |
static void DoFree(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
416 |
||
417 |
/** |
|
418 |
Re-allocate all decommitted but still present RAM pages in a region of a memory object. |
|
419 |
||
420 |
When pinned memory is freed from a memory object it is placed in the |
|
421 |
RPageArray::EDecommitted state. This function is called by #Alloc to place |
|
422 |
all such memory back into the committed state as if it had been newly allocated. |
|
423 |
||
424 |
@param aMemory A memory object associated with this manager. |
|
425 |
@param aIndex Page index for the start of the region. |
|
426 |
@param aCount Number of pages in the region. |
|
427 |
*/ |
|
428 |
static void ReAllocDecommitted(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
429 |
||
430 |
/** |
|
431 |
Attempt to free all decommitted but still present RAM pages in a region of a memory object. |
|
432 |
||
433 |
When pinned memory is freed from a memory object it is placed in the |
|
434 |
RPageArray::EDecommitted state. This function is called by #DoCleanupDecommitted |
|
435 |
to attempt to fully free this memory if it is no longer pinned. |
|
436 |
||
437 |
@param aMemory A memory object associated with this manager. |
|
438 |
@param aIndex Page index for the start of the region. |
|
439 |
@param aCount Number of pages in the region. |
|
440 |
*/ |
|
441 |
static void FreeDecommitted(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
442 |
||
443 |
/** |
|
444 |
Implementation factor for #FreeDecommitted and #DoFree. |
|
445 |
*/ |
|
446 |
static TInt FreePages(DMemoryObject* aMemory, RPageArray::TIter aPageList); |
|
447 |
||
448 |
/** |
|
449 |
Cleanup any decommitted memory associated with a memory object. |
|
450 |
||
451 |
This is called for memory objects which were queued for cleanup (#QueueCleanup) |
|
452 |
with the #ECleanupDecommitted operation. A manager class must override this method |
|
453 |
if it triggers this cleanup type - the default implementation faults in debug builds. |
|
454 |
||
455 |
@param aMemory The memory object requiring cleanup. |
|
456 |
*/ |
|
457 |
virtual void DoCleanupDecommitted(DMemoryObject* aMemory); |
|
458 |
||
459 |
private: |
|
460 |
/** |
|
461 |
Callback function which executes all pending operations queued with #QueueCleanup. |
|
462 |
*/ |
|
463 |
static void CleanupFunction(TAny*); |
|
464 |
||
465 |
/** |
|
466 |
Head of a singly linked list of memory objects which require a cleanup operation. |
|
467 |
Each object in the list is linked using its DMemoryObject::iCleanupNext member. |
|
468 |
@see #QueueCleanup |
|
469 |
*/ |
|
470 |
static DMemoryObject* iCleanupHead; |
|
471 |
||
472 |
/** |
|
473 |
Spinlock used during memory cleanup operations to protect object list (#iCleanupHead |
|
474 |
and DMemoryObject::iCleanupNext) and operation flags (DMemoryObject::iCleanupFlags). |
|
475 |
*/ |
|
476 |
static TSpinLock iCleanupLock; |
|
477 |
}; |
|
478 |
||
479 |
||
480 |
||
481 |
/** |
|
482 |
The bass class for memory managers implementing the different forms of demand paging. |
|
483 |
The provides the common functions required to 'page in' and 'page out' memory. |
|
484 |
*/ |
|
485 |
class DPagedMemoryManager : public DMemoryManager |
|
486 |
{ |
|
487 |
public: |
|
488 |
// from DMemoryManager... |
|
489 |
virtual TInt New(DMemoryObject*& aMemory, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags); |
|
490 |
virtual void Destruct(DMemoryObject* aMemory); |
|
491 |
virtual TInt MovePage(DMemoryObject* aMemory, SPageInfo* aOldPageInfo, TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest); |
|
492 |
virtual TInt StealPage(DMemoryObject* aMemory, SPageInfo* aPageInfo); |
|
493 |
virtual TInt RestrictPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TRestrictPagesType aRestriction); |
|
494 |
virtual TInt HandleFault( DMemoryObject* aMemory, TUint aIndex, DMemoryMapping* aMapping, |
|
495 |
TUint aMapInstanceCount, TUint aAccessPermissions); |
|
496 |
virtual TInt Pin(DMemoryObject* aMemory, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs); |
|
497 |
virtual void Unpin(DMemoryObject* aMemory, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs); |
|
498 |
||
499 |
/** |
|
500 |
Called by DPager::Init3 during third stage initialisation. |
|
501 |
*/ |
|
502 |
virtual void Init3() = 0; |
|
503 |
||
504 |
/** |
|
505 |
Called by Kern::InstallPagingDevice to notify memory managers when a paging device |
|
506 |
is installed. A manager requires use of these paging devices to access storage media |
|
507 |
where demand paged content is stored. |
|
508 |
*/ |
|
509 |
virtual TInt InstallPagingDevice(DPagingDevice* aDevice) = 0; |
|
510 |
||
511 |
protected: |
|
512 |
||
513 |
/** |
|
514 |
Acquire a request object suitable for issuing to #ReadPages to |
|
515 |
obtain the data content of a specified region of a memory object. |
|
516 |
||
517 |
Once the request object is finished with it must be released (DPagingRequest::Release). |
|
518 |
||
519 |
Typically this function is implemented by calling DPagingRequestPool::AcquirePageReadRequest |
|
520 |
on the request pool of the paging device appropriate to the memory object. |
|
521 |
||
522 |
@param[out] aRequest On success this is set to the address of the request object. |
|
523 |
@param aMemory A memory object associated with this manager. |
|
524 |
@param aIndex Page index for the start of the region. |
|
525 |
@param aCount Number of pages in the region. |
|
526 |
||
527 |
@return KErrNone if successful, |
|
528 |
otherwise one of the system wide error codes. |
|
529 |
*/ |
|
530 |
virtual TInt AcquirePageReadRequest(DPageReadRequest*& aRequest, DMemoryObject* aMemory, TUint aIndex, TUint aCount) = 0; |
|
531 |
||
532 |
/** |
|
533 |
Acquire a request object suitable for issuing to #WritePages to |
|
534 |
save the data content of a specified region of a memory object. |
|
535 |
||
536 |
Once the request object is finished with it must be released (DPagingRequest::Release). |
|
537 |
||
538 |
Typically this function is implemented by calling DPagingRequestPool::AcquirePageWriteRequest |
|
539 |
on the request pool of the paging device appropriate to the memory object. |
|
540 |
||
541 |
@param[out] aRequest On success this is set to the address of the request object. |
|
542 |
@param aMemory A memory object associated with this manager. |
|
543 |
@param aIndex Page index for the start of the region. |
|
544 |
@param aCount Number of pages in the region. |
|
545 |
||
546 |
@return KErrNone if successful, |
|
547 |
otherwise one of the system wide error codes. |
|
548 |
*/ |
|
549 |
virtual TInt AcquirePageWriteRequest(DPageWriteRequest*& aRequest, DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
550 |
||
551 |
/** |
|
552 |
Obtain the data content of a specified region of a memory object by reading it from |
|
553 |
storage media. |
|
554 |
||
555 |
The memory region must be the same as, or a subset of, the region used when obtaining |
|
556 |
the request object \a aRequest. |
|
557 |
||
558 |
@param aMemory A memory object associated with this manager. |
|
559 |
@param aIndex Page index for the start of the region. |
|
560 |
@param aCount Number of pages in the region. |
|
561 |
@param aPages Pointer to array of pages to read into. This must contain \a aCount |
|
562 |
number of physical page addresses which are each page aligned. |
|
563 |
@param aRequest A request object previously obtained with #AcquirePageReadRequest. |
|
564 |
||
565 |
@return KErrNone if successful, |
|
566 |
otherwise one of the system wide error codes. |
|
567 |
*/ |
|
568 |
virtual TInt ReadPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr* aPages, DPageReadRequest* aRequest) =0; |
|
569 |
||
570 |
/** |
|
571 |
Check if a region of a memory object has been allocated. E.g. that #Alloc |
|
572 |
has reserved backing store for the memory and this has has not yet been freed |
|
573 |
by #Free or #Destruct. |
|
574 |
||
575 |
@param aMemory A memory object associated with this manager. |
|
576 |
@param aIndex Page index for the start of the region. |
|
577 |
@param aCount Number of pages in the region. |
|
578 |
||
579 |
@return True if the whole region has allocated storage, false otherwise. |
|
580 |
||
581 |
@pre #MmuLock held. |
|
582 |
@post #MmuLock held and must not have been released by this function. |
|
583 |
*/ |
|
584 |
virtual TBool IsAllocated(DMemoryObject* aMemory, TUint aIndex, TUint aCount) =0; |
|
585 |
||
586 |
protected: |
|
587 |
/** |
|
588 |
Do the action of #Pin for a subregion of a memory mapping. |
|
589 |
This is an implementation factor used to implement #Pin. |
|
590 |
||
591 |
@param aMemory A memory object associated with this manager. |
|
592 |
@param aIndex Page index for the start of the region. |
|
593 |
@param aCount Number of pages in the region. |
|
594 |
@param aMapping A mapping with the DMemoryMappingBase::EPinned attribute which |
|
595 |
has been attached to \a aMemory. |
|
596 |
@param aPinArgs The resources to use for pinning. This must have sufficient replacement |
|
597 |
pages allocated to pin every page the mapping covers, and the |
|
598 |
value of \a aPinArgs.iReadOnly must be set to correspond to the |
|
599 |
mappings access permissions. |
|
600 |
||
601 |
@return KErrNone if successful, |
|
602 |
KErrNotFound if any part of the memory to be pinned was not present, |
|
603 |
otherwise one of the system wide error codes. |
|
604 |
*/ |
|
605 |
TInt DoPin(DMemoryObject* aMemory, TUint aIndex, TUint aCount, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs); |
|
606 |
||
607 |
/** |
|
608 |
Update a single page in a memory object during memory pinning handling. |
|
609 |
||
610 |
This includes assigning a new physical page of RAM to the memory object (optional) |
|
611 |
then updating the pages state to ensure that it is pinned i.e. doesn't take |
|
612 |
part in demand paging until unpinned again. |
|
613 |
||
614 |
This is called from #DoPin. |
|
615 |
||
616 |
@param aMemory A memory object associated with this manager. |
|
617 |
@param aIndex Page index, within the memory, for the page. |
|
618 |
@param aPageInfo The page information structure of the new physical page |
|
619 |
to assign to the \a aMemory. If there was an existing |
|
620 |
assigned page this new page is freed back to the paging |
|
621 |
system. Specifying a new page is optional, use the null-pointer |
|
622 |
to indicate its absence. |
|
623 |
@param aPageArrayEntry Reference to the page's page array entry in \a aMemory->iPages. |
|
624 |
@param aPinArgs The resources to use for pinning. This must a replacement |
|
625 |
pages allocated. |
|
626 |
||
627 |
@return 1 (one) if the new page was assigned to the memory object. |
|
628 |
@return 0 (zero) if a page already existed at the specified index. |
|
629 |
@return KErrNotFound if there no page could be assigned, either because |
|
630 |
none was given, or because memory is in the process of being |
|
631 |
decommitted from the memory object. |
|
632 |
||
633 |
@pre #MmuLock held. |
|
634 |
*/ |
|
635 |
virtual TInt PageInPinnedDone(DMemoryObject* aMemory, TUint aIndex, SPageInfo* aPageInfo, TPhysAddr* aPageArrayEntry, TPinArgs& aPinArgs); |
|
636 |
||
637 |
/** |
|
638 |
Implementation factor for #PageInDone and #PageInPinnedDone. |
|
639 |
||
640 |
@pre #MmuLock held. |
|
641 |
@post #MmuLock held and must not have been released by this function. |
|
642 |
*/ |
|
643 |
TInt DoPageInDone(DMemoryObject* aMemory, TUint aIndex, SPageInfo*& aPageInfo, TPhysAddr* aPageArrayEntry, TBool aPinning); |
|
644 |
||
645 |
/** |
|
646 |
Do the action of #Unpin for a subregion of a memory mapping. |
|
647 |
This is an implementation factor used to implement #Unpin. |
|
648 |
||
649 |
Must only be used for memory pages already successfully pinned. |
|
650 |
||
651 |
@param aMemory A memory object associated with this manager. |
|
652 |
@param aIndex Page index for the start of the region. |
|
653 |
@param aCount Number of pages in the region. |
|
654 |
@param aMapping A mapping with the DMemoryMappingBase::EPinned attribute which |
|
655 |
has been attached to \a aMemory. |
|
656 |
@param aPinArgs The resources used for pinning. The replacement pages allocated |
|
657 |
to this will be increased for each page which was became completely |
|
658 |
unpinned. |
|
659 |
*/ |
|
660 |
virtual void DoUnpin(DMemoryObject* aMemory, TUint aIndex, TUint aCount, DMemoryMappingBase* aMapping, TPinArgs& aPinArgs); |
|
661 |
||
662 |
// from DMemoryManager... |
|
663 |
virtual void DoCleanupDecommitted(DMemoryObject* aMemory); |
|
664 |
virtual TZonePageType PageType(); |
|
665 |
||
666 |
/** |
|
667 |
Decompress demand paged data. |
|
668 |
||
669 |
The compression types supported are: |
|
670 |
- Byte-Pair, specified with a compression type of |
|
671 |
SRomPageInfo::EBytePair or KUidCompressionBytePair. |
|
672 |
- No Compression, specified with a compression type of zero. |
|
673 |
||
674 |
@param aCompressionType The type of decompression to use. |
|
675 |
@param aDst The destination address of the decompressed data. |
|
676 |
@param aDstBytes The expected size of the data once it is decompressed. |
|
677 |
@param aSrc The address for the data to decompress. |
|
678 |
@param aSrcBytes The size of the data to decompress. |
|
679 |
||
680 |
@return The size of decompressed data in bytes or one of the system wide error codes. |
|
681 |
*/ |
|
682 |
TInt Decompress(TUint32 aCompressionType, TLinAddr aDst, TUint aDstBytes, TLinAddr aSrc, TUint aSrcBytes); |
|
683 |
||
684 |
private: |
|
685 |
/** |
|
686 |
Update a single page in a memory object during page fault handling. |
|
687 |
||
688 |
This includes assigning a new physical page of RAM to the memory object (optional) |
|
689 |
then updating the demand paging live list to reflect the fact that the memory page |
|
690 |
was newly accessed. |
|
691 |
||
692 |
This is called from #HandleFault. |
|
693 |
||
694 |
@param aMemory A memory object associated with this manager. |
|
695 |
@param aIndex Page index, within the memory, for the page. |
|
696 |
@param aPageInfo The page information structure of the new physical page |
|
697 |
to assign to the \a aMemory. If there was an existing |
|
698 |
assigned page this new page is freed back to the paging |
|
699 |
system. Specifying a new page is optional, use the null-pointer |
|
700 |
to indicate its absence. |
|
701 |
@param aPageArrayEntry Reference to the page's page array entry in \a aMemory->iPages. |
|
702 |
||
703 |
@return 1 (one) if the new page was assigned to the memory object. |
|
704 |
@return 0 (zero) if a page already existed at the specified index. |
|
705 |
@return KErrNotFound if there no page could be assigned, either because |
|
706 |
none was given, or because memory is in the process of being |
|
707 |
decommitted from the memory object. |
|
708 |
||
709 |
@pre #MmuLock held. |
|
710 |
*/ |
|
711 |
TInt PageInDone(DMemoryObject* aMemory, TUint aIndex, SPageInfo* aPageInfo, TPhysAddr* aPageArrayEntry); |
|
712 |
}; |
|
713 |
||
714 |
||
715 |
||
716 |
extern DMemoryManager* TheUnpagedMemoryManager; ///< The #DUnpagedMemoryManager |
|
717 |
extern DMemoryManager* TheMovableMemoryManager; ///< The #DMovableMemoryManager |
|
718 |
extern DMemoryManager* TheDiscardableMemoryManager; ///< The #DDiscardableMemoryManager |
|
719 |
extern DMemoryManager* TheHardwareMemoryManager; ///< The #DHardwareMemoryManager |
|
720 |
extern DPagedMemoryManager* TheRomMemoryManager; ///< The #DRomMemoryManager |
|
721 |
extern DPagedMemoryManager* TheDataPagedMemoryManager; ///< The #DDataPagedMemoryManager |
|
722 |
extern DPagedMemoryManager* TheCodePagedMemoryManager; ///< The #DCodePagedMemoryManager |
|
723 |
||
724 |
#endif |