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