author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 28 | 5b5d147c7838 |
child 44 | 3e88ff8f41d5 |
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 MM_H |
|
22 |
#define MM_H |
|
23 |
||
24 |
#include <mmtypes.h> |
|
25 |
#include <platform.h> |
|
26 |
||
27 |
||
28 |
class DMemoryObject; |
|
29 |
class DMemoryMapping; |
|
30 |
class DMemModelThread; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
31 |
class DMemModelProcess; |
0 | 32 |
class DPhysicalPinMapping; |
33 |
||
34 |
/** |
|
35 |
Memory object types for MM::MemoryNew which indicates how the |
|
36 |
contents of a memory object are to be managed. |
|
37 |
*/ |
|
38 |
enum TMemoryObjectType |
|
39 |
{ |
|
40 |
/** |
|
41 |
Memory object for containing memory mapped hardware devices or special |
|
42 |
purpose memory for which the physical addresses are fixed. The contents of |
|
43 |
these type of objects are manipulated with the functions: |
|
44 |
- MM::MemoryAddPages |
|
45 |
- MM::MemoryAddContiguous |
|
46 |
- MM::MemoryRemovePages |
|
47 |
*/ |
|
48 |
EMemoryObjectHardware = 0, |
|
49 |
||
50 |
/** |
|
51 |
Memory object containing normal program memory (RAM) which is allocated from a |
|
52 |
system wide pool. The contents of these type of objects are manipulated with |
|
53 |
the functions: |
|
54 |
- MM::MemoryAlloc |
|
55 |
- MM::MemoryAllocContiguous |
|
56 |
- MM::MemoryFree |
|
57 |
*/ |
|
58 |
EMemoryObjectUnpaged = 1, |
|
59 |
||
60 |
/** |
|
61 |
Memory object containing normal program memory (RAM) which is allocated from a |
|
62 |
system wide pool. This is the same basic management as EMemoryObjectUnpaged however |
|
63 |
RAM defragmentation activity may substituted physical RAM pages with others and |
|
64 |
this process may cause transient page faults which make this memory not suitable |
|
65 |
for most kernel-side usage. |
|
66 |
||
67 |
The contents of these type of objects are manipulated with the functions: |
|
68 |
- MM::MemoryAlloc |
|
69 |
- MM::MemoryAllocContiguous |
|
70 |
- MM::MemoryFree |
|
71 |
*/ |
|
72 |
EMemoryObjectMovable = 2, |
|
73 |
||
74 |
/** |
|
75 |
Memory object containing normal program memory (RAM) which is demand paged |
|
76 |
from a backing store. The contents of these type of objects are manipulated |
|
77 |
with the functions. |
|
78 |
- MM::MemoryAlloc |
|
79 |
- MM::MemoryFree |
|
80 |
*/ |
|
81 |
EMemoryObjectPaged = 3, |
|
82 |
||
83 |
/** |
|
84 |
Memory object containing normal program memory (RAM) in the same way as |
|
85 |
EMemoryObjectMovable but with the additional option of marking pages as |
|
86 |
'discardable'. Discardable pages may be reclaimed (remove) by the system at |
|
87 |
any time, this state is controlled using the functions: |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
- MM::MemoryAlloc |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
- MM::MemoryAllocContiguous |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
- MM::MemoryFree |
0 | 91 |
- MM::MemoryAllowDiscard |
92 |
- MM::MemoryDisallowDiscard |
|
93 |
*/ |
|
94 |
EMemoryObjectDiscardable = 4 |
|
95 |
}; |
|
96 |
||
97 |
||
98 |
/** |
|
99 |
Bitmask of flags to specify options to MM:MemoryNew. |
|
100 |
*/ |
|
101 |
enum TMemoryCreateFlags |
|
102 |
{ |
|
103 |
/** |
|
104 |
Default value which has all flags false. |
|
105 |
*/ |
|
106 |
EMemoryCreateDefault = 0, |
|
107 |
||
108 |
/** |
|
109 |
Memory allocated for the memory object contents does not need wiping. |
|
110 |
IMPORTANT, memory is normally wiped for security purposes, this attribute |
|
111 |
should only be used when the old contents of any memory allocated can not |
|
112 |
be read by any process without TCB capability. |
|
113 |
*/ |
|
114 |
EMemoryCreateNoWipe = 1<<0, |
|
115 |
||
116 |
/** |
|
117 |
Use the custom wipe byte value when wiping memory, rather than the default value. |
|
118 |
@see EMemoryCreateUseCustomWipeByte |
|
119 |
*/ |
|
120 |
EMemoryCreateUseCustomWipeByte = 1<<1, |
|
121 |
||
122 |
/** |
|
123 |
Pre-create all resources the memory object needs so that operations on it |
|
124 |
can not fail due to low memory conditions. This excludes any explicit |
|
125 |
allocation of memory pages for use as the objects contents. |
|
126 |
*/ |
|
127 |
EMemoryCreateReserveAllResources = 1<<2, |
|
128 |
||
129 |
/** |
|
130 |
Memory object contents are not allowed to be pinned. |
|
131 |
*/ |
|
132 |
EMemoryCreateDisallowPinning = 1<<3, |
|
133 |
||
134 |
/** |
|
135 |
Memory object contents are read-only. Mappings with write permissions are |
|
136 |
not allowed. |
|
137 |
*/ |
|
138 |
EMemoryCreateReadOnly = 1<<4, |
|
139 |
||
140 |
/** |
|
141 |
Memory object contents may be executed. Mappings with execute permissions |
|
142 |
are allowed. |
|
143 |
*/ |
|
144 |
EMemoryCreateAllowExecution = 1<<5, |
|
145 |
||
146 |
/** |
|
147 |
Bit position for the least significant bit of an 8 bit value to use for |
|
148 |
wiping newly allocated memory. |
|
149 |
@see EMemoryCreateUseCustomWipeByte |
|
150 |
@see EMemoryCreateNoWipe |
|
151 |
*/ |
|
152 |
EMemoryCreateWipeByteShift = 8, |
|
153 |
||
154 |
// for selected internal use only... |
|
155 |
||
156 |
/** |
|
157 |
The TMemoryObjectType specified is actually a pointer to the DMemoryManager to use. |
|
158 |
*/ |
|
159 |
EMemoryCreateCustomManager = 1<<30, |
|
160 |
||
161 |
/** |
|
162 |
Memory object contents are to be demand paged. |
|
163 |
*/ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
164 |
EMemoryCreateDemandPaged = 1U<<31 |
0 | 165 |
}; |
166 |
||
167 |
||
168 |
/** |
|
169 |
Attributes that the memory in a memory object has. |
|
170 |
||
171 |
These govern how the MMU and caching systems treat the memory. The following |
|
172 |
terms have meanings as specified in the ARM Architecture Reference Manual - see |
|
173 |
the section 'Memory types and attributes and the Memory order model'. |
|
174 |
||
175 |
- Memory types 'normal', 'device' and 'strongly-ordered'. |
|
176 |
- 'Shareable' attribute. |
|
177 |
*/ |
|
178 |
enum TMemoryAttributes |
|
179 |
{ |
|
180 |
// memory types (copy of TMemoryType)... |
|
181 |
||
182 |
EMemoryAttributeStronglyOrdered = EMemAttStronglyOrdered, |
|
183 |
EMemoryAttributeDevice = EMemAttDevice, |
|
184 |
EMemoryAttributeNormalUncached = EMemAttNormalUncached, |
|
185 |
EMemoryAttributeNormalCached = EMemAttNormalCached, |
|
186 |
EMemoryAttributeKernelInternal4 = EMemAttKernelInternal4, |
|
187 |
EMemoryAttributePlatformSpecific5 = EMemAttPlatformSpecific5, |
|
188 |
EMemoryAttributePlatformSpecific6 = EMemAttPlatformSpecific6, |
|
189 |
EMemoryAttributePlatformSpecific7 = EMemAttPlatformSpecific7, |
|
190 |
||
191 |
/** |
|
192 |
Bitmask to extract TMemoryType value from this enum. E.g. |
|
193 |
@code |
|
194 |
TMemoryAttributes attr; |
|
195 |
TMemoryType type = (TMemoryType)(attr&EMemoryAttributeTypeMask); |
|
196 |
@endcode |
|
197 |
*/ |
|
198 |
EMemoryAttributeTypeMask = KMemoryTypeMask, |
|
199 |
||
200 |
/** |
|
201 |
Set if memory is Shareable. |
|
202 |
*/ |
|
203 |
EMemoryAttributeShareable = 0x08, |
|
204 |
||
205 |
/** |
|
206 |
Legacy (and little-used/unused?) ARM attribute. |
|
207 |
*/ |
|
208 |
EMemoryAttributeUseECC = 0x10, |
|
209 |
||
210 |
||
211 |
/** |
|
212 |
Number of bits required to store memory attribute value. |
|
213 |
@internalComponent |
|
214 |
*/ |
|
215 |
EMemoryAttributeShift = 5, |
|
216 |
||
217 |
/** |
|
218 |
Bitmask for all significant attribute bits. |
|
219 |
@internalComponent |
|
220 |
*/ |
|
221 |
EMemoryAttributeMask = (1<<EMemoryAttributeShift)-1, |
|
222 |
||
223 |
// pseudo attributes... |
|
224 |
||
225 |
/** |
|
226 |
Indicates the Shareable attribute should be the default value for the system. |
|
227 |
See macro __CPU_USE_SHARED_MEMORY |
|
228 |
*/ |
|
229 |
EMemoryAttributeDefaultShareable = 0x80000000, |
|
230 |
||
231 |
// popular combinations... |
|
232 |
||
233 |
/** |
|
234 |
Normal program memory for use by software. |
|
235 |
*/ |
|
236 |
EMemoryAttributeStandard = EMemoryAttributeNormalCached|EMemoryAttributeDefaultShareable |
|
237 |
}; |
|
238 |
||
239 |
||
240 |
/** |
|
241 |
Access permissions applied to Memory Mappings. |
|
242 |
*/ |
|
243 |
enum TMappingPermissions |
|
244 |
{ |
|
245 |
EUser = 1<<0, ///< Unprivileged (user mode) access allowed. |
|
246 |
EReadWrite = 1<<1, ///< Memory contents may be modified |
|
247 |
EExecute = 1<<2, ///< Memory contents may be executed as code. |
|
248 |
||
249 |
// popular combinations... |
|
250 |
EUserReadOnly = EUser, |
|
251 |
EUserReadWrite = EUser|EReadWrite, |
|
252 |
EUserExecute = EUser|EExecute, |
|
253 |
ESupervisorReadOnly = 0, |
|
254 |
ESupervisorReadWrite = EReadWrite, |
|
255 |
ESupervisorExecute = EExecute |
|
256 |
}; |
|
257 |
||
258 |
||
259 |
/** |
|
260 |
Bitmask of flags to specify options to MM::MappingNew. |
|
261 |
*/ |
|
262 |
enum TMappingCreateFlags |
|
263 |
{ |
|
264 |
/** |
|
265 |
Default value which has all flags false. |
|
266 |
*/ |
|
267 |
EMappingCreateDefault = 0, |
|
268 |
||
269 |
/** |
|
270 |
Allocate the specified virtual address. |
|
271 |
*/ |
|
272 |
EMappingCreateExactVirtual = 1<<0, |
|
273 |
||
274 |
/** |
|
275 |
Pre-create all resources (like page tables) that the memory mapping |
|
276 |
needs so that operations on it can not fail due to low memory conditions. |
|
277 |
*/ |
|
278 |
EMappingCreateReserveAllResources = 1<<1, |
|
279 |
||
280 |
// for selected internal use only... |
|
281 |
||
282 |
/** |
|
283 |
Flag memory as being demand paged. |
|
284 |
Exclusive with EMappingCreatePinning and EMappingCreateReserveAllResources. |
|
285 |
@internalTechnology |
|
286 |
*/ |
|
287 |
EMappingCreateDemandPaged = 1<<27, |
|
288 |
||
289 |
/** |
|
290 |
Flag memory as requiring a common address across all address spaces, also |
|
291 |
implies EMappingCreateExactVirtual. |
|
292 |
@internalTechnology |
|
293 |
*/ |
|
294 |
EMappingCreateCommonVirtual = 1<<28, |
|
295 |
||
296 |
/** |
|
297 |
Allocate virtual address in the global region which it to be used for |
|
298 |
user-mode access. (KGlobalMemoryBase<=address<KUserMemoryLimit). |
|
299 |
@internalTechnology |
|
300 |
*/ |
|
301 |
EMappingCreateUserGlobalVirtual = 1<<29, |
|
302 |
||
303 |
/** |
|
304 |
Don't allocate any virtual memory in the address space, use the specified |
|
305 |
address and assume ownership of this. |
|
306 |
@internalTechnology |
|
307 |
*/ |
|
308 |
EMappingCreateAdoptVirtual = 1<<30, |
|
309 |
||
310 |
/** |
|
311 |
Don't allocate any virtual memory in the address space, just used the |
|
312 |
specified address. |
|
313 |
@internalTechnology |
|
314 |
*/ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
315 |
EMappingCreateFixedVirtual = 1U<<31 |
0 | 316 |
}; |
317 |
||
318 |
||
319 |
class DMemModelChunk; |
|
320 |
class TPagedCodeInfo; |
|
321 |
||
322 |
/** |
|
323 |
Static interface to the Flexible Memory Model implementation |
|
324 |
for use by the Symbian OS aware part of the memory model codebase. |
|
325 |
*/ |
|
326 |
class MM |
|
327 |
{ |
|
328 |
public: |
|
329 |
// |
|
330 |
// Memory Object functions |
|
331 |
// |
|
332 |
||
333 |
/** |
|
334 |
Create a new memory object. |
|
335 |
||
336 |
A memory object is a sparse array of memory pages to which memory mappings |
|
337 |
may be attached. All pages in the array are managed using the same methods |
|
338 |
(see TMemoryObjectType) and have the same attributes (see TMemoryAttributes). |
|
339 |
||
340 |
On creation it contains no pages. |
|
341 |
||
342 |
@param[out] aMemory Pointer reference which on success is set to the address |
|
343 |
of the created memory object. |
|
344 |
@param aType Value from TMemoryObjectType which indicates how the |
|
345 |
contents of the memory object are to be managed. |
|
346 |
@param aPageCount Size of the memory object, in number of pages. |
|
347 |
@param aCreateFlags Bitmask of option flags from enum TMemoryCreateFlags. |
|
348 |
@param aAttributes Bitmask of values from enum TMemoryAttributes. |
|
349 |
||
350 |
@return KErrNone, if successful; |
|
351 |
otherwise another of the system wide error codes. |
|
352 |
*/ |
|
353 |
static TInt MemoryNew(DMemoryObject*& aMemory, TMemoryObjectType aType, TUint aPageCount, TMemoryCreateFlags aCreateFlags=EMemoryCreateDefault, TMemoryAttributes aAttributes=EMemoryAttributeStandard); |
|
354 |
||
355 |
/** |
|
356 |
Assign a mutex which will be used to serialise explicit modifications to the |
|
357 |
specified memory object. |
|
358 |
||
359 |
If a lock hasn't been specified for a particular object, it will make use of |
|
360 |
one allocated dynamically allocated from a shared pool; this mutex will be of 'order' |
|
361 |
#KMutexOrdMemoryObject. |
|
362 |
||
363 |
@see MemoryObjectLock. |
|
364 |
*/ |
|
365 |
static void MemorySetLock(DMemoryObject* aMemory, DMutex* aLock); |
|
366 |
||
367 |
/** |
|
368 |
Wait on the specified memory object's lock mutex. |
|
369 |
*/ |
|
370 |
static void MemoryLock(DMemoryObject* aMemory); |
|
371 |
||
372 |
/** |
|
373 |
Signal the specified memory object's lock mutex. |
|
374 |
*/ |
|
375 |
static void MemoryUnlock(DMemoryObject* aMemory); |
|
376 |
||
377 |
/** |
|
378 |
Remove all memory from a memory object and close a reference on it. |
|
379 |
||
380 |
If there are no longer any mappings to the memory, or other references, |
|
381 |
this will result in the memory object being destroyed. However whilst |
|
382 |
other references exist, cleanup of memory and other resources may be |
|
383 |
delayed indefinitely. |
|
384 |
||
385 |
This function acquires and releases the memory objects lock. |
|
386 |
See MM::MemorySetLock. |
|
387 |
||
388 |
@param aMemory Pointer reference to memory object to be destroyed. |
|
389 |
On return from the function this is set to the null-pointer. |
|
390 |
No action is performed if the reference was already the |
|
391 |
null-pointer on entry to this function. |
|
392 |
*/ |
|
393 |
static void MemoryDestroy(DMemoryObject*& aMemory); |
|
394 |
||
395 |
/** |
|
396 |
Allocate memory for a specified region within a memory object. |
|
397 |
Memory is allocated as appropriate for the object type, e.g. |
|
398 |
For Unpaged objects, from the system RAM pool; for Paged objects, in the |
|
399 |
backing store. |
|
400 |
||
401 |
This function acquires and releases the memory objects lock. |
|
402 |
See MM::MemorySetLock. |
|
403 |
||
404 |
Supported for memory object types: |
|
405 |
- EMemoryObjectUnpaged |
|
406 |
- EMemoryObjectMovable |
|
407 |
- EMemoryObjectPaged |
|
408 |
- EMemoryObjectDiscardable |
|
409 |
||
410 |
@param aMemory The memory object. |
|
411 |
@param aIndex Page index for start of the region. |
|
412 |
@param aCount Number of pages in the region. |
|
413 |
||
414 |
@return KErrNone, if successful; |
|
415 |
KErrAlreadyExists, if any part of the region was already allocated; |
|
416 |
KErrArgument, if the region exceeds the bounds of the memory object; |
|
417 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
418 |
otherwise another of the system wide error codes. |
|
419 |
*/ |
|
420 |
static TInt MemoryAlloc(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
421 |
||
422 |
/** |
|
423 |
Allocate memory for a specified region within a memory object. |
|
424 |
The allocated memory will have contiguous physical addresses. |
|
425 |
||
426 |
This function acquires and releases the memory objects lock. |
|
427 |
See MM::MemorySetLock. |
|
428 |
||
429 |
Important note, this function can unexpectedly fail with KErrAlreadyExists |
|
430 |
if any part of the the region previously contained allocated memory which |
|
431 |
had been freed but which was pinned. It is therefore not suitable for general |
|
432 |
use. |
|
433 |
||
434 |
Supported for memory object types: |
|
435 |
- EMemoryObjectUnpaged |
|
436 |
- EMemoryObjectDiscardable |
|
437 |
||
438 |
@param aMemory The memory object. |
|
439 |
@param aIndex Page index for start of the region. |
|
440 |
@param aCount Number of pages in the region. |
|
441 |
@param aAlign Log2 of the alignment (in bytes) that the address of the allocated physical RAM must have. |
|
442 |
@param[out] aPhysAddr On success, this is set to the start address of the allocated physical RAM. |
|
443 |
||
444 |
@return KErrNone, if successful; |
|
445 |
KErrAlreadyExists, if any part of the region was already allocated; |
|
446 |
KErrArgument, if the region exceeds the bounds of the memory object; |
|
447 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
448 |
otherwise another of the system wide error codes. |
|
449 |
*/ |
|
450 |
static TInt MemoryAllocContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TUint aAlign, TPhysAddr& aPhysAddr); |
|
451 |
||
452 |
/** |
|
453 |
Free (unallocate) memory for a specified region within a memory object. |
|
454 |
This is the inverse operation to MemoryAlloc and MemoryAllocContiguous. |
|
455 |
||
456 |
This function acquires and releases the memory objects lock. |
|
457 |
See MM::MemorySetLock. |
|
458 |
||
459 |
Supported for memory object types: |
|
460 |
- EMemoryObjectUnpaged |
|
461 |
- EMemoryObjectMovable |
|
462 |
- EMemoryObjectPaged |
|
463 |
- EMemoryObjectDiscardable |
|
464 |
||
465 |
@param aMemory The memory object. |
|
466 |
@param aIndex Page index for start of the region. |
|
467 |
@param aCount Number of pages in the region. |
|
468 |
*/ |
|
469 |
static void MemoryFree(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
470 |
||
471 |
/** |
|
472 |
Add the specified pages to a region in a memory object. |
|
473 |
||
474 |
This function acquires and releases the memory objects lock. |
|
475 |
See MM::MemorySetLock. |
|
476 |
||
477 |
Supported for memory object types: |
|
478 |
- EMemoryObjectHardware |
|
479 |
||
480 |
@param aMemory The memory object. |
|
481 |
@param aIndex Page index for start of the region. |
|
482 |
@param aCount Number of pages in the region. |
|
483 |
@param aPages Pointer to array of pages to add. This must contain \a aCount |
|
484 |
number of physical page addresses which are page aligned. |
|
485 |
||
486 |
@return KErrNone, if successful; |
|
487 |
KErrAlreadyExists, if any part of the region already contains pages; |
|
488 |
KErrArgument, if the region exceeds the bounds of the memory object; |
|
489 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
490 |
otherwise another of the system wide error codes. |
|
491 |
*/ |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
static TInt MemoryAddPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, const TPhysAddr* aPages); |
0 | 493 |
|
494 |
/** |
|
495 |
Add a contiguous range of pages to a region in a memory object. |
|
496 |
||
497 |
This function acquires and releases the memory objects lock. |
|
498 |
See MM::MemorySetLock. |
|
499 |
||
500 |
Supported for memory object types: |
|
501 |
- EMemoryObjectHardware |
|
502 |
||
503 |
@param aMemory The memory object. |
|
504 |
@param aIndex Page index for start of the region. |
|
505 |
@param aCount Number of pages in the region. |
|
506 |
@param aPhysAddr The page aligned start address of the pages to be added. |
|
507 |
||
508 |
@return KErrNone, if successful; |
|
509 |
KErrAlreadyExists, if any part of the region already contains pages; |
|
510 |
KErrArgument, if the region exceeds the bounds of the memory object; |
|
511 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
512 |
otherwise another of the system wide error codes. |
|
513 |
*/ |
|
514 |
static TInt MemoryAddContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr aPhysAddr); |
|
515 |
||
516 |
/** |
|
517 |
Remove pages from a region in a memory object. |
|
518 |
||
519 |
This is the inverse operation to MemoryAdd and MemoryAddContiguous. |
|
520 |
||
521 |
This function acquires and releases the memory objects lock. |
|
522 |
See MM::MemorySetLock. |
|
523 |
||
524 |
Supported for memory object types: |
|
525 |
- EMemoryObjectHardware |
|
526 |
||
527 |
@param aMemory The memory object. |
|
528 |
@param aIndex Page index for start of the region. |
|
529 |
@param aCount Number of pages in the region. |
|
530 |
@param[out] aPages Pointer to an array of physical addresses which has a |
|
531 |
length of \a aCount. The contents of this will be set to |
|
532 |
the addresses of the pages which were removed by this |
|
533 |
function. The number of valid entries in this array is |
|
534 |
given by the return value of this function. |
|
535 |
aPages may be the null-pointer, to indicate that these |
|
536 |
page addresses aren't required by the caller. |
|
537 |
||
538 |
@return The number of pages successfully removed from the memory object. |
|
539 |
This gives the number of valid entries in the array \a aPages and is |
|
540 |
less-than or equal to \a aCount. |
|
541 |
*/ |
|
542 |
static TUint MemoryRemovePages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr* aPages); |
|
543 |
||
544 |
/** |
|
545 |
Mark a region in a memory object as discardable. |
|
546 |
||
547 |
The system may remove discardable pages from the memory object at any time, |
|
548 |
to be reused for other purposes. |
|
549 |
||
550 |
This function acquires and releases the memory objects lock. |
|
551 |
See MM::MemorySetLock. |
|
552 |
||
553 |
Supported for memory object types: |
|
554 |
- EMemoryObjectDiscardable |
|
555 |
||
556 |
@see MemoryDisallowDiscard |
|
557 |
||
558 |
@param aMemory The memory object. |
|
559 |
@param aIndex Page index for start of the region. |
|
560 |
@param aCount Number of pages in the region. |
|
561 |
||
562 |
@return KErrNone, if successful; |
|
563 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
564 |
otherwise another of the system wide error codes. |
|
565 |
||
566 |
*/ |
|
567 |
static TInt MemoryAllowDiscard(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
568 |
||
569 |
/** |
|
570 |
Mark a region in a memory object as no longer discardable. |
|
571 |
This undoes the operation of MemoryAllowDiscard. |
|
572 |
||
573 |
If any pages in the region are no longer present, then the operation will |
|
574 |
fail with KErrNotFound. In this case, the state of the pages in the region |
|
575 |
is indeterminate; they may be either still discardable, not discardable, or |
|
576 |
not present. |
|
577 |
||
578 |
Supported for memory object types: |
|
579 |
- EMemoryObjectDiscardable |
|
580 |
||
581 |
@see MemoryAllowDiscard |
|
582 |
||
583 |
@param aMemory The memory object. |
|
584 |
@param aIndex Page index for start of the region. |
|
585 |
@param aCount Number of pages in the region. |
|
586 |
||
587 |
@return KErrNone, if successful; |
|
588 |
KErrNotFound, if any page in the region was no longer present; |
|
589 |
KErrNotSupported, if the memory object doesn't support this operation; |
|
590 |
otherwise another of the system wide error codes. |
|
591 |
*/ |
|
592 |
static TInt MemoryDisallowDiscard(DMemoryObject* aMemory, TUint aIndex, TUint aCount); |
|
593 |
||
594 |
/** |
|
595 |
This function only exists to support DMemModelChunk::PhysicalAddress and may be removed. |
|
596 |
DO NOT USE. |
|
597 |
*/ |
|
598 |
static TInt MemoryPhysAddr(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TPhysAddr& aPhysicalAddress, TPhysAddr* aPhysicalPageList); |
|
599 |
||
600 |
/** |
|
601 |
Prime BTrace for a memory object - internal use only. |
|
602 |
*/ |
|
603 |
static void MemoryBTracePrime(DMemoryObject* aMemory); |
|
604 |
||
605 |
/** |
|
606 |
Close a memory object. |
|
607 |
||
608 |
This should be called on the memory object returned by #MappingGetAndOpenMemory. |
|
609 |
*/ |
|
610 |
static void MemoryClose(DMemoryObject* aMemory); |
|
611 |
||
612 |
/** |
|
613 |
Return true if aMemory has any mappings associated with it. |
|
614 |
*/ |
|
615 |
static TBool MemoryIsNotMapped(DMemoryObject* aMemory); |
|
616 |
||
617 |
/** |
|
618 |
Wipe the entire memory contents of the memory object so they are in the |
|
619 |
same state as if the memory had been newly allocated with #MemoryAlloc. |
|
620 |
||
621 |
This is useful for situations where a memory object is being re-purposed and |
|
622 |
confidentiality requires that the old memory contents are not disclosed. |
|
623 |
For this reason, the function asserts that the memory object has no mappings. |
|
624 |
||
625 |
@see EMemoryCreateUseCustomWipeByte |
|
626 |
@see EMemoryCreateNoWipe |
|
627 |
||
628 |
@return KErrNone, if successful; |
|
629 |
otherwise KErrNotSupported, to indicate the memory object doesn't support this operation. |
|
630 |
*/ |
|
631 |
static TInt MemoryWipe(DMemoryObject* aMemory); |
|
632 |
||
633 |
/** |
|
634 |
Set the memory object to be read only, i.e. to no longer allow writable mappings. |
|
635 |
||
636 |
NOTE - This can't be undone, page moving will break if a memory object is made |
|
637 |
writable again. |
|
638 |
||
639 |
@param aMemory The memory object to update. |
|
640 |
@return KErrNone on success, KErrInUse if the memory object has writable mappings |
|
641 |
KErrNotSupported if the objects manager doesn't support this. |
|
642 |
*/ |
|
643 |
static TInt MemorySetReadOnly(DMemoryObject* aMemory); |
|
644 |
||
645 |
/** |
|
646 |
Pins physical memory associated with the memory object and returns the physical |
|
647 |
memory characteristics, e.g. address, map attributes and colour |
|
648 |
||
649 |
@param aMemory The memory object. |
|
650 |
@param aPinObject The physical pin mapping. |
|
651 |
@param aIndex Page index for start of the region. |
|
652 |
@param aCount Number of pages in the region. |
|
653 |
@param aReadOnly Indicates whether memory should be pinned as read only. |
|
654 |
@param aAddress[out] The value is the physical address of the first page |
|
655 |
in the region. |
|
656 |
@param aPages[out] If not zero, this points to an array of TPhysAddr |
|
657 |
objects. On success, this array will be filled |
|
658 |
with the addresses of the physical pages which |
|
659 |
contain the specified region. If aPages is |
|
660 |
zero, then the function will fail with |
|
661 |
KErrNotFound if the specified region is not |
|
662 |
physically contiguous. |
|
663 |
@param aMapAttr[out] Memory attributes defined by TMappingAttributes2. |
|
664 |
@param aColour[out] The mapping colour of the first physical page. |
|
665 |
||
666 |
||
667 |
@return The number of pages successfully removed from the memory object. |
|
668 |
This gives the number of entries in the array aPages and is |
|
669 |
less-than or equal to aCount. |
|
670 |
*/ |
|
671 |
||
672 |
static TInt PinPhysicalMemory(DMemoryObject* aMemory, DPhysicalPinMapping* aPinObject, TUint aIndex, |
|
673 |
TUint aCount, TBool aReadOnly, TPhysAddr& aAddress, TPhysAddr* aPages, |
|
674 |
TUint32& aMapAttr, TUint& aColour); |
|
675 |
||
676 |
// |
|
677 |
// Memory Mapping functions |
|
678 |
// |
|
679 |
||
680 |
/** |
|
681 |
Create a new memory mapping for a specific memory object. |
|
682 |
||
683 |
A memory mapping represents the MMU resources required to make a region of a |
|
684 |
memory object accessible to software within a single address space (process). |
|
685 |
Each mapping has an associated set of access permissions (see |
|
686 |
#TMappingPermissions). |
|
687 |
||
688 |
@param[out] aMapping Pointer reference which on success is set to the address |
|
689 |
of the created memory mapping. |
|
690 |
@param aMemory The memory object with which the mapping is associated. |
|
691 |
@param aPermissions Bitmask of values from enum #TMappingPermissions which |
|
692 |
give the access permissions for this mapping. |
|
693 |
@param aOsAsid The identifier for the address space in which this |
|
694 |
mapping is to appear. |
|
695 |
@param aFlags Bitmask of option flags from enum #TMappingCreateFlags |
|
696 |
@param aAddr Optional virtual address at which the memory mapped |
|
697 |
by this mapping is to appear within the specified |
|
698 |
address space. |
|
699 |
@param aIndex Optional start page index within \a aMemory for this |
|
700 |
mapping. |
|
701 |
@param aCount Optional page count for size of mapping. A value of |
|
702 |
the maximum integer indicates that the mapping is to |
|
703 |
extend to the end of the memory object. |
|
704 |
||
705 |
@return KErrNone, if successful; |
|
706 |
otherwise another of the system wide error codes. |
|
707 |
*/ |
|
708 |
static TInt MappingNew(DMemoryMapping*& aMapping, DMemoryObject* aMemory, TMappingPermissions aPermissions, TInt aOsAsid, TMappingCreateFlags aFlags=EMappingCreateDefault, TLinAddr aAddr=0, TUint aIndex=0, TUint aCount=~0u); |
|
709 |
||
710 |
/** |
|
711 |
Create a new memory mapping with is not associated with any memory object. |
|
712 |
||
713 |
This mapping may be used and reused with different memory objects by using |
|
714 |
the #MappingMap and #MappingUnmap methods. |
|
715 |
||
716 |
@param[out] aMapping Pointer reference which on success is set to the address |
|
717 |
of the created memory mapping. |
|
718 |
@param aCount Page count for size of mapping. |
|
719 |
@param aOsAsid The identifier for the address space in which this |
|
720 |
mapping is to appear. |
|
721 |
@param aFlags Bitmask of option flags from enum #TMappingCreateFlags |
|
722 |
@param aAddr Optional virtual address at which the mapping is to |
|
723 |
appear within the specified address space. |
|
724 |
@param aColourOffset The byte offset within a memory object's memory which this mapping |
|
725 |
is to start. This is used to adjust virtual memory allocation to |
|
726 |
meet page colouring restrictions. If this value is not known leave |
|
727 |
this argument unspecified; however, it must be specified if \a aAddr |
|
728 |
is specified. |
|
729 |
||
730 |
@return KErrNone, if successful; |
|
731 |
otherwise another of the system wide error codes. |
|
732 |
*/ |
|
733 |
static TInt MappingNew(DMemoryMapping*& aMapping, TUint aCount, TInt aOsAsid, TMappingCreateFlags aFlags=EMappingCreateDefault, TLinAddr aAddr=0, TLinAddr aColourOffset=~0); |
|
734 |
||
735 |
/** |
|
736 |
Apply a memory mapping to a memory object. |
|
737 |
||
738 |
@param aMapping The memory mapping to be used to map \a aMemory. |
|
739 |
@param aPermissions Bitmask of values from enum #TMappingPermissions which |
|
740 |
give the access permissions for this mapping. |
|
741 |
@param aMemory The memory object with which the mapping is to be associated. |
|
742 |
@param aIndex Optional start page index within aMemory for this |
|
743 |
mapping. |
|
744 |
@param aCount Optional page count for size of mapping. A value of |
|
745 |
the maximum integer indicates that the mapping is to |
|
746 |
extend to the end of the memory object. |
|
747 |
||
748 |
@return KErrNone, if successful; |
|
749 |
otherwise another of the system wide error codes. |
|
750 |
*/ |
|
751 |
static TInt MappingMap(DMemoryMapping* aMapping, TMappingPermissions aPermissions, DMemoryObject* aMemory, TUint aIndex=0, TUint aCount=~0u); |
|
752 |
||
753 |
/** |
|
754 |
Remove a mapping from the memory object with which it is associated. |
|
755 |
*/ |
|
756 |
static void MappingUnmap(DMemoryMapping* aMapping); |
|
757 |
||
758 |
/** |
|
759 |
Remove a memory mapping from its associated address space and close a |
|
760 |
reference on it. |
|
761 |
||
762 |
If there are no longer any other references, this will result in the memory |
|
763 |
object being destroyed, |
|
764 |
||
765 |
@param aMapping Pointer reference to memory mapping to be destroyed. |
|
766 |
On return from the function this is set to the null-pointer. |
|
767 |
No action is performed if the reference was already the |
|
768 |
null-pointer on entry to this function. |
|
769 |
*/ |
|
770 |
static void MappingDestroy(DMemoryMapping*& aMapping); |
|
771 |
||
772 |
/** |
|
773 |
Remove a memory mapping from its associated address space and close a |
|
774 |
reference on it. |
|
775 |
||
776 |
The mapping is found based on the virtual address region within which it |
|
777 |
maps memory. The caller must that such a mapping exists and that it will not |
|
778 |
be unmapped by another thread. |
|
779 |
||
780 |
@param aAddr Virtual address which lies within the region covered by the |
|
781 |
memory mapping. |
|
782 |
@param aOsAsid Address space in which the mapping appears. |
|
783 |
*/ |
|
784 |
static void MappingDestroy(TLinAddr aAddr, TInt aOsAsid); |
|
785 |
||
786 |
/** |
|
787 |
Perform the action of #MappingDestroy on a memory mapping then #MemoryDestroy |
|
788 |
on its associated memory object. |
|
789 |
||
790 |
This function acquires and releases the memory objects lock. |
|
791 |
See MM::MemorySetLock. |
|
792 |
||
793 |
NOTE - This should not be used on mappings that are reused as the mapping's |
|
794 |
instance count is not checked. |
|
795 |
||
796 |
@param aMapping Pointer reference to memory mapping to be destroyed. |
|
797 |
On return from the function this is set to the null-pointer. |
|
798 |
No action is performed if the reference was already the |
|
799 |
null-pointer on entry to this function. |
|
800 |
*/ |
|
801 |
static void MappingAndMemoryDestroy(DMemoryMapping*& aMapping); |
|
802 |
||
803 |
/** |
|
804 |
Perform the action of #MappingDestroy on a memory mapping then #MemoryDestroy |
|
805 |
on its associated memory object. |
|
806 |
||
807 |
The mapping is found based on the virtual address region within which it |
|
808 |
maps memory. The caller must that such a mapping exists and that it will not |
|
809 |
be unmapped by another thread. |
|
810 |
||
811 |
This function acquires and releases the memory objects lock. |
|
812 |
See MM::MemorySetLock. |
|
813 |
||
814 |
NOTE - This should not be used on mappings that are reused as the mapping's |
|
815 |
instance count is not checked. |
|
816 |
||
817 |
@param aAddr Virtual address which lies within the region covered by the |
|
818 |
memory mapping. |
|
819 |
@param aOsAsid Address space in which the mapping appears. |
|
820 |
*/ |
|
821 |
static void MappingAndMemoryDestroy(TLinAddr aAddr, TInt aOsAsid); |
|
822 |
||
823 |
/** |
|
824 |
Return the virtual address at which the memory mapped by a memory mapping |
|
825 |
starts. |
|
826 |
||
827 |
@param aMapping A memory mapping. |
|
828 |
||
829 |
@return The base address. |
|
830 |
*/ |
|
831 |
static TLinAddr MappingBase(DMemoryMapping* aMapping); |
|
832 |
||
833 |
/** |
|
834 |
Return the OS Address Space ID (OS ASID) of the address space the mapping is within. |
|
835 |
||
836 |
@param aMapping A memory mapping. |
|
837 |
||
838 |
@return OS Address Space ID (OS ASID). |
|
839 |
*/ |
|
840 |
static TInt MappingOsAsid(DMemoryMapping* aMapping); |
|
841 |
||
842 |
/** |
|
843 |
Open the memory object mapped by a mapping and return it. |
|
844 |
||
845 |
The memory object can be closed again by calling #MemoryClose. |
|
846 |
||
847 |
NOTE - This should not be used on mappings that are reused as the mapping's |
|
848 |
instance count is not checked. |
|
849 |
||
850 |
@param aMapping A memory mapping. |
|
851 |
||
852 |
@return The memory object, or NULL. |
|
853 |
*/ |
|
854 |
static DMemoryObject* MappingGetAndOpenMemory(DMemoryMapping* aMapping); |
|
855 |
||
856 |
/** |
|
857 |
Close a mapping |
|
858 |
||
859 |
@param aMapping A memory mapping. |
|
860 |
*/ |
|
861 |
static void MappingClose(DMemoryMapping* aMapping); |
|
862 |
||
863 |
/** |
|
864 |
Find and open the mapping that maps a virtual address in the address space of the specified |
|
865 |
thread. |
|
866 |
||
867 |
The caller must close the mapping when it has finished using it. |
|
868 |
||
869 |
@param aThread The thread whose address space is to be searched. |
|
870 |
@param aAddr The virtual address for which the mapping is to be found. |
|
871 |
@param aSize The size, in bytes, of the region at aAddr. |
|
872 |
@param aOffsetInMapping A reference which is set to the offset, in bytes, into the |
|
873 |
mapping of the start address. |
|
874 |
@param aInstanceCount The instance count of the found mapping. |
|
875 |
||
876 |
@return The mapping, or NULL if no mapping was found. |
|
877 |
||
878 |
@pre Calling thread must be in a critical section. |
|
879 |
*/ |
|
880 |
static DMemoryMapping* FindMappingInThread( DMemModelThread* aThread, TLinAddr aAddr, TUint aSize, |
|
881 |
TUint& aOffsetInMapping, TUint& aInstanceCount); |
|
882 |
||
883 |
/** |
|
884 |
Find and open the mapping that maps a virtual address in the address space of the specified |
|
885 |
process. |
|
886 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
887 |
The caller must close the mapping when it has finished using it. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
888 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
889 |
@param aProcess The process whose address space is to be searched. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
890 |
@param aAddr The virtual address for which the mapping is to be found. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
891 |
@param aSize The size, in bytes, of the region at aAddr. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
892 |
@param aOffsetInMapping A reference which is set to the offset, in bytes, into the |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
893 |
mapping of the start address. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
894 |
@param aInstanceCount The instance count of the found mapping. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
895 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
896 |
@return The mapping, or NULL if no mapping was found. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
897 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
898 |
@pre Calling thread must be in a critical section. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
899 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
900 |
static DMemoryMapping* FindMappingInProcess(DMemModelProcess* aProcess, TLinAddr aAddr, TUint aSize, |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
901 |
TUint& aOffsetInMapping, TUint& aInstanceCount); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
902 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
903 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
904 |
Find and open the mapping that maps a virtual address in the address space of the specified |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
905 |
process. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
906 |
|
0 | 907 |
The caller must close the mapping when it has finished using it. The caller must ensure that |
908 |
the process can't be destroyed while calling this method. |
|
909 |
||
910 |
@param aOsAsid The identifier for the address space in which the mapping appears. |
|
911 |
@param aAddr The virtual address for which the mapping is to be found. |
|
912 |
@param aSize The size, in bytes, of the region at aAddr. |
|
913 |
@param aOffsetInMapping A reference which is set to the offset, in bytes, into the |
|
914 |
mapping of the start address. |
|
915 |
@param aInstanceCount The instance count of the found mapping. |
|
916 |
||
917 |
@return The mapping, or NULL if no mapping was found. |
|
918 |
||
919 |
@pre Calling thread must be in a critical section. |
|
920 |
*/ |
|
921 |
static DMemoryMapping* FindMappingInAddressSpace( TUint aOsAsid, TLinAddr aAddr, TUint aSize, |
|
922 |
TUint& aOffsetInMapping, TUint& aInstanceCount); |
|
923 |
||
924 |
||
925 |
// |
|
926 |
// Conversion utilities |
|
927 |
// |
|
928 |
||
929 |
/** |
|
930 |
Round a size in bytes up to the next integer multiple of the page size. |
|
931 |
||
932 |
@param aSize A size in bytes. |
|
933 |
||
934 |
@return The rounded size. |
|
935 |
*/ |
|
936 |
static TUint RoundToPageSize(TUint aSize); |
|
937 |
||
938 |
/** |
|
939 |
Round a size in bytes up to the next integer multiple of the page size |
|
940 |
then convert it into a page count by dividing it by the page size. |
|
941 |
||
942 |
@param aSize A size in bytes. |
|
943 |
||
944 |
@return The rounded page count. |
|
945 |
*/ |
|
946 |
static TUint RoundToPageCount(TUint aSize); |
|
947 |
||
948 |
/** |
|
949 |
Round a bit shift value representing the log2 of a size in bytes, up to |
|
950 |
a shift value representing the log2 of a size in pages. |
|
951 |
||
952 |
@param aShift log2 of a size in bytes. |
|
953 |
||
954 |
@return aShift-KPageShift, or zero if aShift<=KPageShift. |
|
955 |
*/ |
|
956 |
static TUint RoundToPageShift(TUint aShift); |
|
957 |
||
958 |
/** |
|
959 |
Convert a size in bytes to a size in pages. |
|
960 |
||
961 |
@param aBytes A size in bytes. |
|
962 |
||
963 |
@return aBytes/KPageSize. |
|
964 |
||
965 |
@panic MemModel #EBadBytesToPages if aBytes is not an integer multiple of |
|
966 |
the page size. |
|
967 |
*/ |
|
968 |
static TUint BytesToPages(TUint aBytes); |
|
969 |
||
970 |
/** |
|
971 |
Construct a #TMappingPermissions value base on individual permission flags. |
|
972 |
||
973 |
@param aUser True to allow unprivileged (user mode) access. |
|
974 |
@param aWrite True to allow memory contents to be modified. |
|
975 |
@param aExecute True to allow memory contents to be executed as code. |
|
976 |
||
977 |
@return Permissions expressed as an #TMappingPermissions value. |
|
978 |
*/ |
|
979 |
static TMappingPermissions MappingPermissions(TBool aUser, TBool aWrite, TBool aExecute); |
|
980 |
||
981 |
/** |
|
982 |
Extract the mapping permissions from a TMappingAttributes2 |
|
983 |
(or TMappingAttributes) value. |
|
984 |
||
985 |
@param[out] aPermissions If successful, mapping permissions extracted from aLegacyAttributes. |
|
986 |
@param aLegacyAttributes A legacy combined permission/attribute value. |
|
987 |
||
988 |
@return KErrNone, if successful; |
|
989 |
otherwise another of the system wide error codes. |
|
990 |
*/ |
|
991 |
static TInt MappingPermissions(TMappingPermissions& aPermissions, TMappingAttributes2 aLegacyAttributes); |
|
992 |
||
993 |
/** |
|
994 |
Extract the memory attributes from a TMappingAttributes2 |
|
995 |
(or TMappingAttributes) value. |
|
996 |
||
997 |
@param[out] aAttributes If successful, memory attributes extracted from \a aLegacyAttributes. |
|
998 |
@param aLegacyAttributes A legacy combined permission/attribute value. |
|
999 |
||
1000 |
@return KErrNone, if successful; |
|
1001 |
otherwise another of the system wide error codes. |
|
1002 |
*/ |
|
1003 |
static TInt MemoryAttributes(TMemoryAttributes& aAttributes, TMappingAttributes2 aLegacyAttributes); |
|
1004 |
||
1005 |
/** |
|
1006 |
Construct a legacy combined permission/memory-type value based on a |
|
1007 |
#TMemoryAttributes and #TMappingPermissions value. |
|
1008 |
||
1009 |
@param aAttributes A memory attributes value. |
|
1010 |
@param aPermissions A mapping permissions value. |
|
1011 |
||
1012 |
@return A TMappingAttributes2 value combining \a aAttributes and \a aPermissions. |
|
1013 |
*/ |
|
1014 |
static TMappingAttributes2 LegacyMappingAttributes(TMemoryAttributes aAttributes, TMappingPermissions aPermissions); |
|
1015 |
||
1016 |
// |
|
1017 |
// Code paging |
|
1018 |
// |
|
1019 |
||
1020 |
/** |
|
1021 |
Create a new memory object which will contain demand paged code. |
|
1022 |
||
1023 |
@param[out] aMemory Pointer reference which on success is set to the address |
|
1024 |
of the created memory object. |
|
1025 |
@param aPageCount Size of the memory object, in number of pages. |
|
1026 |
@param aInfo Pointer reference which on success it set to a #TPagedCodeInfo |
|
1027 |
object which should be initialised with information required |
|
1028 |
for demand paging the code. (Call #PagedCodeLoaded when this is done.) |
|
1029 |
||
1030 |
@return KErrNone, if successful; |
|
1031 |
otherwise another of the system wide error codes. |
|
1032 |
*/ |
|
1033 |
static TInt PagedCodeNew(DMemoryObject*& aMemory, TUint aPageCount, TPagedCodeInfo*& aInfo); |
|
1034 |
||
1035 |
/** |
|
1036 |
Call this to indicate that a memory object created with #PagedCodeNew has had its |
|
1037 |
#TPagedCodeInfo object initialised. |
|
1038 |
||
1039 |
@param aMemory The memory object. |
|
1040 |
@param aLoadAddress An address at which \a aMemory is mapped with write permissions. |
|
1041 |
*/ |
|
1042 |
static void PagedCodeLoaded(DMemoryObject* aMemory, TLinAddr aLoadAddress); |
|
1043 |
||
1044 |
// |
|
1045 |
// Misc |
|
1046 |
// |
|
1047 |
||
1048 |
// Initialisation... |
|
1049 |
static void Init1(); |
|
1050 |
static void Init2(); |
|
1051 |
static void Init3(); |
|
1052 |
static TInt InitFixedKernelMemory(DMemoryObject*& aMemory, TLinAddr aStart, TLinAddr aEnd, TUint aInitSize, TMemoryObjectType aType, TMemoryCreateFlags aMemoryCreateFlags, TMemoryAttributes aMemoryAttributes, TMappingCreateFlags aMappingCreateFlags); |
|
1053 |
static TInt MemoryClaimInitialPages(DMemoryObject* aMemory, TLinAddr aBase, TUint aSize, TMappingPermissions aPermissions, TBool aAllowGaps=false, TBool aAllowNonRamPages=false); |
|
1054 |
||
1055 |
// IPC helpers... |
|
1056 |
static void ValidateLocalIpcAddress(TLinAddr aAddr, TUint aSize, TBool aWrite); |
|
1057 |
#ifndef __SMP__ |
|
1058 |
static void IpcAliasPde(TPde*& aPdePtr, TUint aOsAsid); |
|
1059 |
#endif |
|
1060 |
static void UserPermissionFault(TLinAddr aAddr, TBool aWrite); |
|
1061 |
||
1062 |
// Address space... |
|
1063 |
static TInt AddressSpaceAlloc(TPhysAddr& aPageDirectory); |
|
1064 |
static void AddressSpaceFree(TUint aOsAsid); |
|
1065 |
static void AsyncAddressSpaceFree(TUint aOsAsid); |
|
1066 |
static TInt VirtualAllocCommon(TLinAddr& aLinAddr, TUint aSize, TBool aDemandPaged); |
|
1067 |
static void VirtualFreeCommon(TLinAddr aLinAddr, TUint aSize); |
|
1068 |
static TInt VirtualAlloc(TInt aOsAsid, TLinAddr& aLinAddr, TUint aSize, TBool aDemandPaged); |
|
1069 |
static void VirtualFree(TInt aOsAsid, TLinAddr aLinAddr, TUint aSize); |
|
1070 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1071 |
#ifdef _DEBUG |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1072 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1073 |
Force a region of paged memory to be paged out. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1074 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1075 |
If the memory is not paged this call has no effect. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1076 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1077 |
@return KErrNone, or KErrBadDescriptor if a single mapping containing the region could not be |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1078 |
found. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1079 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1080 |
static TInt FlushRegion(DMemModelProcess*, TLinAddr aStartAddress, TUint aSize); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1081 |
#endif |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1082 |
|
0 | 1083 |
/** |
1084 |
Enumeration of panic values for category "MemModel". |
|
1085 |
*/ |
|
1086 |
enum TMemModelPanic |
|
1087 |
{ |
|
1088 |
EFsRegisterThread, |
|
1089 |
EProcessDestructChunksRemaining, |
|
1090 |
ECommitInvalidDllDataAddress, |
|
1091 |
ECodeSegLoadedNotCreator, |
|
1092 |
ETempMappingAlreadyInUse, |
|
1093 |
EUnsupportedOperation, |
|
1094 |
EBadBytesToPages, |
|
1095 |
ECodeSegSetReadOnlyFailure, |
|
1096 |
EProcessDestructOsAsidRemaining, |
|
1097 |
}; |
|
1098 |
static void Panic(TMemModelPanic aPanic); |
|
1099 |
}; |
|
1100 |
||
1101 |
||
1102 |
||
1103 |
template <class T> |
|
1104 |
FORCE_INLINE void FlagSet(T& a,const T b) |
|
1105 |
{ a = (T)(a|b); } |
|
1106 |
||
1107 |
template <class T> |
|
1108 |
FORCE_INLINE void FlagSet(T& a,const T b,const T c) |
|
1109 |
{ a = (T)(a|b|c); } |
|
1110 |
||
1111 |
template <class T> |
|
1112 |
FORCE_INLINE void FlagSet(T& a,const T b,const T c,const T d) |
|
1113 |
{ a = (T)(a|b|c|d); } |
|
1114 |
||
1115 |
template <class T> |
|
1116 |
FORCE_INLINE void FlagClear(T& a,const T b) |
|
1117 |
{ a = (T)(a&~b); } |
|
1118 |
||
1119 |
template <class T> |
|
1120 |
FORCE_INLINE void FlagClear(T& a,const T b,const T c) |
|
1121 |
{ a = (T)(a&~b&~c); } |
|
1122 |
||
1123 |
template <class T> |
|
1124 |
FORCE_INLINE void FlagClear(T& a,const T b,const T c,const T d) |
|
1125 |
{ a = (T)(a&~b&~c&~d); } |
|
1126 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1127 |
/// Utility function to calculate the minimum of two unsigned integers |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1128 |
FORCE_INLINE TUint MinU(TUint a, TUint b) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1129 |
{ return a <= b ? a : b; } |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1130 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1131 |
/// Utility function to calculate the maximum of two unsigned integers |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1132 |
FORCE_INLINE TUint MaxU(TUint a, TUint b) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1133 |
{ return a >= b ? a : b; } |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1134 |
|
0 | 1135 |
|
1136 |
#include <memmodel/epoc/mmubase/kblockmap.h> |
|
1137 |
||
1138 |
/** |
|
1139 |
Structure containing the information about a demand paged code segment |
|
1140 |
which is required to load and fixup its code section. |
|
1141 |
*/ |
|
1142 |
class TPagedCodeInfo |
|
1143 |
{ |
|
1144 |
public: |
|
1145 |
~TPagedCodeInfo(); |
|
1146 |
TInt ReadBlockMap(const TCodeSegCreateInfo& aInfo); |
|
1147 |
TInt ReadFixupTables(const TCodeSegCreateInfo& aInfo); |
|
1148 |
void ApplyFixups(TLinAddr aBuffer, TUint iIndex); |
|
1149 |
public: |
|
1150 |
TBool iLoaded; ///< True once initial loading has finished and paging should start applying fixups. |
|
1151 |
TUint iCodeRelocTableSize; ///< Size, in bytes, of #iCodeRelocTable. |
|
1152 |
TUint8* iCodeRelocTable; ///< Code relocation information. |
|
1153 |
TUint iImportFixupTableSize; ///< Size, in bytes, of #iImportFixupTable. |
|
1154 |
TUint8* iImportFixupTable; ///< Import fixup information. |
|
1155 |
TUint32 iCodeDelta; ///< Delta to apply to relocate words referring to the code section. |
|
1156 |
TUint32 iDataDelta; ///< Delta to apply to relocate words referring to the data section. |
|
1157 |
||
1158 |
TUint iCodeSize; ///< Size, in bytes, of the code section. |
|
1159 |
TUint32 iCompressionType; ///< Compression scheme in use, (KUidCompressionBytePair or KFormatNotCompressed). |
|
1160 |
TInt32* iCodePageOffsets; ///< Array of compressed page offsets within the file. |
|
1161 |
TInt iCodeLocalDrive; ///< Local drive number. |
|
1162 |
TInt iCodeStartInFile; ///< Offset of (possibly compressed) code from start of file. |
|
1163 |
TBlockMap iBlockMap; ///< Kernel-side representation of block map. |
|
1164 |
}; |
|
1165 |
||
1166 |
||
1167 |
||
1168 |
/** |
|
1169 |
A pool of DMutex objects that can be dynamically assigned for use. |
|
1170 |
||
1171 |
This is intended as a memory saving alternative to having each object in a class of objects |
|
1172 |
owning their own mutex for locking purposes and provides a concurrency improvement over using |
|
1173 |
a single global lock. |
|
1174 |
*/ |
|
1175 |
class DMutexPool : public DBase |
|
1176 |
{ |
|
1177 |
public: |
|
1178 |
/** |
|
1179 |
@param aCount Number of mutexes to allocated in the pool. |
|
1180 |
Must be smaller than #EMaxPoolSize. |
|
1181 |
@param aName Base name for mutexes. Each mutex in the pool has a number appended to this base name. |
|
1182 |
@param aOrder A value representing the order of the mutex with respect to deadlock prevention. |
|
1183 |
*/ |
|
1184 |
TInt Create(TUint aCount, const TDesC* aName, TUint aOrder); |
|
1185 |
||
1186 |
~DMutexPool(); |
|
1187 |
||
1188 |
/** |
|
1189 |
Wait on the mutex specified by \a aMutexRef. |
|
1190 |
||
1191 |
If \a aMutexRef contains the null pointer then a member of this pool is selected and waited on, |
|
1192 |
and \a aMutexRef is set to a cookie value identifying that mutex; this cookie has its least |
|
1193 |
significant bit set to distinguish it from a normal DMutex pointer. Subsequent concurrent |
|
1194 |
Wait operations will use the same pool mutex; possibly modifying the value of the cookie. |
|
1195 |
*/ |
|
1196 |
void Wait(DMutex*& aMutexRef); |
|
1197 |
||
1198 |
/** |
|
1199 |
Signal the mutex specified by \a aMutexRef. |
|
1200 |
||
1201 |
If mutex is identified as one from this pool then the value of \a aMutexRef will be modified |
|
1202 |
and if there are no pending Wait operations it will be set to the null pointer to indicate |
|
1203 |
that no mutex is assigned. |
|
1204 |
*/ |
|
1205 |
void Signal(DMutex*& aMutexRef); |
|
1206 |
||
1207 |
/** |
|
1208 |
Return true if the mutex specified by \a aMutexRef is held by the current thread. |
|
1209 |
*/ |
|
1210 |
TBool IsHeld(DMutex*& aMutexRef); |
|
1211 |
||
1212 |
enum |
|
1213 |
{ |
|
1214 |
/** Maximum number of mutexes allowed in a pool. */ |
|
1215 |
EMaxPoolSize = 64 |
|
1216 |
}; |
|
1217 |
||
1218 |
private: |
|
1219 |
/** Structure for storing information about each member of the pool. */ |
|
1220 |
struct SMember |
|
1221 |
{ |
|
1222 |
DMutex* iMutex; ///< The mutex |
|
1223 |
TUint iUseCount; ///< Number of times this mutex has been used |
|
1224 |
}; |
|
1225 |
TUint iCount; ///< Number of mutexes in pool. (Number of entries in iMembers). |
|
1226 |
TUint iNext; ///< Index of next pool mutex to use. |
|
1227 |
SMember* iMembers; ///< Info about each memory of pool. |
|
1228 |
}; |
|
1229 |
||
1230 |
||
1231 |
#endif |