author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 25 May 2010 14:09:55 +0300 | |
branch | RCL_3 |
changeset 28 | 5b5d147c7838 |
parent 21 | e7d2d738d3c2 |
child 42 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-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 |
// e32\kernel\sutils.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <kernel/kern_priv.h> |
|
19 |
#include "execs.h" |
|
20 |
#include <e32panic.h> |
|
21 |
_LIT(KLitDfcThread,"DfcThread"); |
|
22 |
||
23 |
extern const SNThreadHandlers EpocThreadHandlers; |
|
24 |
||
25 |
||
26 |
||
27 |
/** |
|
28 |
Adds a HAL entry handling function for the specified group of HAL entries. |
|
29 |
||
30 |
@param aId The HAL group attribute that this function handles, as defined by |
|
31 |
one of the THalFunctionGroup enumerators. |
|
32 |
@param aFunc Pointer to the handler function |
|
33 |
@param aPtr Pointer which is passed to the handler function when it is |
|
34 |
called. This is usually a pointer to an object which handles |
|
35 |
the HAL attribute. |
|
36 |
||
37 |
@return KErrNone, if successful; KErrArgument if aId is EHalGroupKernel, EHalGroupVariant or EHalGroupPower, |
|
38 |
or aId is greater than or equal to KMaxHalGroups; KErrInUse, if a handler is already registered. |
|
39 |
||
40 |
@pre Interrupts must be enabled. |
|
41 |
@pre Kernel must be unlocked. |
|
42 |
@pre No fast mutex can be held. |
|
43 |
@pre Call in a thread context. |
|
44 |
@pre Suitable for use in a device driver. |
|
45 |
||
46 |
@see THalFunctionGroup |
|
47 |
@see KMaxHalGroups |
|
48 |
*/ |
|
49 |
EXPORT_C TInt Kern::AddHalEntry(TInt aId, THalFunc aFunc, TAny* aPtr) |
|
50 |
{ |
|
51 |
return Kern::AddHalEntry(aId, aFunc, aPtr, 0); |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
Adds a HAL entry handling function for the specified group of HAL entries. |
|
56 |
||
57 |
@param aId The HAL group attribute that this function handles, as defined by |
|
58 |
one of the THalFunctionGroup enumerators. |
|
59 |
@param aFunc Pointer to the handler function |
|
60 |
@param aPtr Pointer which is passed to the handler function when it is |
|
61 |
called. This is usually a pointer to an object which handles |
|
62 |
the HAL attribute. |
|
63 |
@param aDeviceNumber |
|
64 |
The device number (eg. screen number). |
|
65 |
||
66 |
@return KErrNone, if successful; KErrArgument if aId is EHalGroupKernel, EHalGroupVariant or EHalGroupPower, |
|
67 |
or aId is greater than or equal to KMaxHalGroups; KErrInUse, if a handler is already registered. |
|
68 |
||
69 |
@pre Calling thread must be in a critical section |
|
70 |
@pre Interrupts must be enabled. |
|
71 |
@pre Kernel must be unlocked. |
|
72 |
@pre No fast mutex can be held. |
|
73 |
@pre Call in a thread context. |
|
74 |
@pre Suitable for use in a device driver. |
|
75 |
||
76 |
@see THalFunctionGroup |
|
77 |
@see KMaxHalGroups |
|
78 |
*/ |
|
79 |
EXPORT_C TInt Kern::AddHalEntry(TInt aId, THalFunc aFunc, TAny* aPtr, TInt aDeviceNumber) |
|
80 |
{ |
|
81 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::AddHalEntry(TInt aId, THalFunc aFunc, TAny* aPtr, TInt aDeviceNumber)"); |
|
82 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("Kern::AddHalEntry %d %08x %08x",aId,aFunc,aPtr)); |
|
83 |
if (aId==(TInt)EHalGroupKernel || aId==(TInt)EHalGroupVariant || aId==(TInt)EHalGroupPower || aId>=KMaxHalGroups || (TUint)aDeviceNumber>=(TUint)KMaxHalEntries) |
|
84 |
return KErrArgument; |
|
85 |
TInt r=KErrInUse; |
|
86 |
if (aDeviceNumber>0) |
|
87 |
{ |
|
88 |
TBool delete_entry = EFalse; |
|
89 |
NKern::LockSystem(); |
|
90 |
SHalEntry2* p = &K::HalEntryArray[aId]; |
|
91 |
SHalEntry* extended_entry = p->iExtendedEntries; |
|
92 |
if(!extended_entry) |
|
93 |
{ |
|
94 |
NKern::UnlockSystem(); |
|
95 |
extended_entry = (SHalEntry*)Kern::AllocZ((KMaxHalEntries-1)*sizeof(SHalEntry)); |
|
96 |
if(!extended_entry) |
|
97 |
return KErrNoMemory; |
|
98 |
NKern::LockSystem(); |
|
99 |
if(!p->iExtendedEntries) |
|
100 |
p->iExtendedEntries = extended_entry; |
|
101 |
else |
|
102 |
delete_entry = ETrue; |
|
103 |
} |
|
104 |
if(!extended_entry[aDeviceNumber-1].iFunction) |
|
105 |
{ |
|
106 |
extended_entry[aDeviceNumber-1].iFunction = aFunc; |
|
107 |
extended_entry[aDeviceNumber-1].iPtr = aPtr; |
|
108 |
r = KErrNone; |
|
109 |
} |
|
110 |
NKern::UnlockSystem(); |
|
111 |
if(delete_entry) |
|
112 |
Kern::Free(extended_entry); |
|
113 |
} |
|
114 |
else |
|
115 |
{ |
|
116 |
NKern::LockSystem(); |
|
117 |
SHalEntry2& e=K::HalEntryArray[aId]; |
|
118 |
if (!e.iFunction) |
|
119 |
{ |
|
120 |
e.iFunction=aFunc; |
|
121 |
e.iPtr=aPtr; |
|
122 |
r=KErrNone; |
|
123 |
} |
|
124 |
NKern::UnlockSystem(); |
|
125 |
} |
|
126 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("Kern::AddHalEntry returns %d",r)); |
|
127 |
return r; |
|
128 |
} |
|
129 |
||
130 |
||
131 |
||
132 |
/** |
|
133 |
Removes a HAL entry handling function for the specified group of HAL entries. |
|
134 |
||
135 |
@param aId The HAL group attribute, as defined by one of the THalFunctionGroup |
|
136 |
enumerators, for which the handler function is to be removed. |
|
137 |
||
138 |
@return KErrNone, if successful; KErrArgument if aId is EHalGroupKernel, |
|
139 |
EHalGroupVariant or EHalGroupMedia, or aId is greater than |
|
140 |
or equal KMaxHalGroups. |
|
141 |
||
142 |
@pre Interrupts must be enabled. |
|
143 |
@pre Kernel must be unlocked. |
|
144 |
@pre No fast mutex can be held. |
|
145 |
@pre Call in a thread context. |
|
146 |
@pre Can be used in a device driver. |
|
147 |
||
148 |
@see THalFunctionGroup |
|
149 |
@see KMaxHalGroups |
|
150 |
*/ |
|
151 |
EXPORT_C TInt Kern::RemoveHalEntry(TInt aId) |
|
152 |
{ |
|
153 |
return Kern::RemoveHalEntry(aId,0); |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
Removes a HAL entry handling function for the specified group of HAL entries. |
|
158 |
||
159 |
@param aId The HAL group attribute, as defined by one of the THalFunctionGroup |
|
160 |
enumerators, for which the handler function is to be removed. |
|
161 |
@param aDeviceNumber The device number (eg. screen number) |
|
162 |
||
163 |
@return KErrNone, if successful; KErrArgument if aId is EHalGroupKernel, |
|
164 |
EHalGroupVariant or EHalGroupMedia, or aId is greater than |
|
165 |
or equal KMaxHalGroups. |
|
166 |
||
167 |
@pre Interrupts must be enabled. |
|
168 |
@pre Kernel must be unlocked. |
|
169 |
@pre No fast mutex can be held. |
|
170 |
@pre Call in a thread context. |
|
171 |
@pre Can be used in a device driver. |
|
172 |
||
173 |
@see THalFunctionGroup |
|
174 |
@see KMaxHalGroups |
|
175 |
*/ |
|
176 |
EXPORT_C TInt Kern::RemoveHalEntry(TInt aId, TInt aDeviceNumber) |
|
177 |
{ |
|
178 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::RemoveHalEntry(TInt aId, TInt aDeviceNumber)"); |
|
179 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("Kern::RemoveHalEntry %d %d",aId,aDeviceNumber)); |
|
180 |
if (aId<(TInt)EHalGroupPower || aId>=KMaxHalGroups || (TUint)aDeviceNumber>=(TUint)KMaxHalEntries) |
|
181 |
return KErrArgument; |
|
182 |
NKern::LockSystem(); |
|
183 |
SHalEntry2* pE=&K::HalEntryArray[aId]; |
|
184 |
if(aDeviceNumber>0) |
|
185 |
{ |
|
186 |
SHalEntry* pBase=pE->iExtendedEntries; |
|
187 |
if(pBase) |
|
188 |
{ |
|
189 |
pBase[aDeviceNumber-1].iFunction=NULL; |
|
190 |
pBase[aDeviceNumber-1].iPtr=NULL; |
|
191 |
} |
|
192 |
} |
|
193 |
else |
|
194 |
{ |
|
195 |
pE->iFunction=NULL; |
|
196 |
pE->iPtr=NULL; |
|
197 |
} |
|
198 |
NKern::UnlockSystem(); |
|
199 |
return KErrNone; |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
Gets the HAL entry handling function for the specified group of HAL entries. |
|
204 |
||
205 |
@param aId The HAL group attribute, as defined by one of the THalFunctionGroup |
|
206 |
enumerators, for which the handler function is required. |
|
207 |
||
208 |
@return A pointer to handler information containing the handler function; NULL |
|
209 |
if aId is negative or is greater than or equal to KMaxHalGroups, or no |
|
210 |
handler function can be found. |
|
211 |
||
212 |
@pre Interrupts must be enabled. |
|
213 |
@pre Kernel must be unlocked. |
|
214 |
@pre No fast mutex can be held. |
|
215 |
@pre Call in a thread context. |
|
216 |
@pre Can be used in a device driver. |
|
217 |
||
218 |
@see THalFunctionGroup |
|
219 |
@see KMaxHalGroups |
|
220 |
*/ |
|
221 |
EXPORT_C SHalEntry* Kern::FindHalEntry(TInt aId) |
|
222 |
{ |
|
223 |
return Kern::FindHalEntry(aId,0); |
|
224 |
} |
|
225 |
||
226 |
||
227 |
/** |
|
228 |
Gets the HAL entry handling function for the specified group of HAL entries. |
|
229 |
||
230 |
@param aId The HAL group attribute, as defined by one of the THalFunctionGroup |
|
231 |
enumerators, for which the handler function is required. |
|
232 |
@param aDeviceNumber The device number (eg. screen number) |
|
233 |
||
234 |
@return A pointer to handler information containing the handler function; NULL |
|
235 |
if aId is negative or is greater than or equal to KMaxHalGroups, or no |
|
236 |
handler function can be found. |
|
237 |
||
238 |
@pre Interrupts must be enabled. |
|
239 |
@pre Kernel must be unlocked. |
|
240 |
@pre No fast mutex can be held. |
|
241 |
@pre Call in a thread context. |
|
242 |
@pre Can be used in a device driver. |
|
243 |
||
244 |
@see THalFunctionGroup |
|
245 |
@see KMaxHalGroups |
|
246 |
*/ |
|
247 |
EXPORT_C SHalEntry* Kern::FindHalEntry(TInt aId, TInt aDeviceNumber) |
|
248 |
{ |
|
249 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::FindHalEntry(TInt aId, TInt aDeviceNumber)"); |
|
250 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("Kern::FindHalEntry %d %d",aId,aDeviceNumber)); |
|
251 |
if (aId<0 || aId>=KMaxHalGroups || TUint(aDeviceNumber)>=TUint(KMaxHalEntries)) |
|
252 |
return NULL; |
|
253 |
SHalEntry2* p=&K::HalEntryArray[0]+aId; |
|
254 |
SHalEntry* pBase=(SHalEntry*)p; |
|
255 |
if(aDeviceNumber>0) |
|
256 |
{ |
|
257 |
if(p->iExtendedEntries) |
|
258 |
pBase=p->iExtendedEntries + (aDeviceNumber-1); |
|
259 |
} |
|
260 |
if(!pBase->iFunction) |
|
261 |
return NULL; |
|
262 |
return pBase; |
|
263 |
} |
|
264 |
||
265 |
||
266 |
||
267 |
||
268 |
/** |
|
269 |
Returns the active debug mask obtained by logically ANDing the global debug mask |
|
270 |
in the super page with the per-thread debug mask in the current DThread object. |
|
271 |
||
272 |
If the current thread is not a symbian OS thread the global debug mask is used. |
|
273 |
||
274 |
Only supports the first 32 global debug trace bits. |
|
275 |
||
276 |
@return The debug mask. |
|
277 |
*/ |
|
278 |
EXPORT_C TInt KDebugMask() |
|
279 |
{ |
|
280 |
TInt m=TheSuperPage().iDebugMask[0]; |
|
281 |
NThread* nt = NCurrentThread(); |
|
282 |
if (nt && nt->iHandlers==&EpocThreadHandlers) |
|
283 |
m &= TheCurrentThread->iDebugMask; |
|
284 |
return m; |
|
285 |
} |
|
286 |
||
287 |
||
288 |
||
289 |
/** |
|
290 |
Returns the state (ETrue or EFalse) of given bit in the active debug mask |
|
291 |
which is obtained by logically ANDing the global debug mask in the super page |
|
292 |
with the per-thread debug mask in the current DThread object. |
|
293 |
||
294 |
If the current thread is not a symbian OS thread the global debug mask is used. |
|
295 |
||
296 |
@return The state of the debug mask bit number. |
|
297 |
*/ |
|
298 |
||
299 |
EXPORT_C TBool KDebugNum(TInt aBitNum) |
|
300 |
{ |
|
301 |
TInt m = 0; |
|
302 |
||
303 |
// special case for KALWAYS |
|
304 |
if (aBitNum == KALWAYS) |
|
305 |
{ |
|
306 |
m = TheSuperPage().iDebugMask[0] || |
|
307 |
TheSuperPage().iDebugMask[1] || |
|
308 |
TheSuperPage().iDebugMask[2] || |
|
309 |
TheSuperPage().iDebugMask[3] || |
|
310 |
TheSuperPage().iDebugMask[4] || |
|
311 |
TheSuperPage().iDebugMask[5] || |
|
312 |
TheSuperPage().iDebugMask[6] || |
|
313 |
TheSuperPage().iDebugMask[7]; |
|
314 |
} |
|
315 |
else if ( (aBitNum > KMAXTRACE) || (aBitNum < 0) ) |
|
316 |
m = 0; |
|
317 |
else |
|
318 |
{ |
|
319 |
TInt index = aBitNum >> 5; |
|
320 |
m = TheSuperPage().iDebugMask[index]; |
|
321 |
m &= 1 << (aBitNum & 31); |
|
322 |
if (!index) |
|
323 |
{ |
|
324 |
// if index is zero then AND in the per thread debug mask |
|
325 |
NThread* nt = K::Initialising ? 0 : NCurrentThread(); |
|
326 |
if (nt && nt->iHandlers==&EpocThreadHandlers) |
|
327 |
m &= TheCurrentThread->iDebugMask; |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
return (m != 0); |
|
332 |
} |
|
333 |
||
334 |
||
335 |
/** |
|
336 |
Prints a formatted string on the debug port. |
|
337 |
||
338 |
The function uses Kern::AppendFormat() to do the formatting. |
|
339 |
||
340 |
Although it is safe to call this function from an ISR, it polls the output |
|
341 |
serial port and may take a long time to complete, invalidating any |
|
342 |
real-time guarantee. |
|
343 |
||
344 |
If called from an ISR, it is possible for output text to be intermingled |
|
345 |
with other output text if one set of output interrupts or preempts another. |
|
346 |
||
347 |
Some of the formatting options may not work inside an ISR. |
|
348 |
||
349 |
Be careful not to use a string that is too long to fit onto the stack. |
|
350 |
||
351 |
@param aFmt The format string. This must not be longer than 256 characters. |
|
352 |
@param ... A variable number of arguments to be converted to text as dictated |
|
353 |
by the format string. |
|
354 |
||
355 |
@pre Calling thread can either be in a critical section or not. |
|
356 |
@pre Interrupts must be enabled. |
|
357 |
@pre Kernel must be unlocked |
|
358 |
@pre Call in any context. |
|
359 |
@pre Suitable for use in a device driver |
|
360 |
||
361 |
@see Kern::AppendFormat() |
|
362 |
*/ |
|
363 |
||
364 |
EXPORT_C void Kern::Printf(const char* aFmt, ...) |
|
365 |
{ |
|
366 |
TBuf8<256> printBuf; |
|
367 |
VA_LIST list; |
|
368 |
VA_START(list,aFmt); |
|
369 |
Kern::AppendFormat(printBuf,aFmt,list); |
|
370 |
K::TextTrace(printBuf,EKernelTrace); |
|
371 |
} |
|
372 |
||
373 |
void AppendNumBuf(TDes8& aDes, const TDesC8& aNum, TInt width, char fill) |
|
374 |
{ |
|
375 |
TInt l=aNum.Length(); |
|
376 |
for (; l<width; ++l) |
|
377 |
aDes.Append(TChar(fill)); |
|
378 |
aDes.Append(aNum); |
|
379 |
} |
|
380 |
||
381 |
||
382 |
||
383 |
||
384 |
/** |
|
385 |
Formats and appends text to the specified narrow descriptor without making any |
|
386 |
executive calls. |
|
387 |
||
388 |
The function takes a format string and a variable number of arguments. The |
|
389 |
format specifiers in the format string are used to interpret and the arguments. |
|
390 |
||
391 |
Format directives have the following syntax: |
|
392 |
@code |
|
393 |
<format-directive> ::= |
|
394 |
"%" [<padding-character>] [<field-width>] [<long-flag>] <conversion-specifier> |
|
395 |
@endcode |
|
396 |
||
397 |
If a field width is specified and the width of the formatted field is less |
|
398 |
than this width, then the field is padded with the padding character. |
|
399 |
The only supported padding characters are ' ' (default) and '0'. |
|
400 |
||
401 |
The long flag specifier ('l') modifies the semantic of the conversion |
|
402 |
specifier as explained below. |
|
403 |
||
404 |
The possible values for the conversion specifiers, the long flag and the way in |
|
405 |
which arguments are interpreted, are as follows: |
|
406 |
@code |
|
407 |
d Interpret the argument as a TInt decimal representation |
|
408 |
ld NOT SUPPORTED - use lx instead |
|
409 |
u Interpret the argument as a TUint decimal representation |
|
410 |
lu NOT SUPPORTED - use lx instead |
|
411 |
x Interpret the argument as a TUint hexadecimal representation |
|
412 |
X As above |
|
413 |
lx Interpret the argument as a Uint64 hexadecimal representation |
|
414 |
lX As above |
|
415 |
c Interpret the argument as a character |
|
416 |
s Interpret the argument as a pointer to narrow C string |
|
417 |
ls Interpret the argument as a pointer to narrow C string |
|
418 |
S Interpret the argument as a pointer to narrow descriptor or NULL |
|
419 |
lS NOT SUPPORTED - use S instead |
|
420 |
O Interpret the argument as a pointer to DObject or NULL |
|
421 |
Generates the object full name or 'NULL' |
|
422 |
o Interpret the argument as a pointer to DObject or NULL |
|
423 |
Generates the object name or 'NULL' |
|
424 |
M Interpret the argument as a pointer to a fast mutex or NULL |
|
425 |
Generates the name, if this is a well-known fast mutex, address otherwise |
|
426 |
m Interpret the argument as a pointer to a fast semaphore or NULL |
|
427 |
Generates the owning thread name, if this is a well-known fast semaphore, address otherwise |
|
428 |
T Interpret the argument as a pointer to a nanothread or NULL |
|
429 |
Generates the full name, if this is a Symbian OS thread, address otherwise |
|
430 |
C Interpret the argument as a pointer to a DCodeSeg or NULL |
|
431 |
Generates the filename and module version number |
|
432 |
G Interpret the argument as a pointer to a nanothread group or NULL |
|
433 |
Generates the full name if this corresponds to a Symbian OS process, address otherwise |
|
434 |
@endcode |
|
435 |
||
436 |
The function can be called from the interrupt context, but extreme caution is advised as it |
|
437 |
may require a lot of stack space and interrupt stacks are very small. |
|
438 |
||
439 |
@param aDes Narrow descriptor that must be big-enough to hold result |
|
440 |
@param aFmt The format string |
|
441 |
@param aList A variable number of arguments to be converted to text as dictated by the format string |
|
442 |
||
443 |
@pre Calling thread can be either in a critical section or not. |
|
444 |
@pre Interrupts must be enabled. |
|
445 |
@pre Kernel must be unlocked |
|
446 |
@pre Call in any context. |
|
447 |
@pre Suitable for use in a device driver |
|
448 |
||
449 |
@panic The set of panics that can be raised when appending data to descriptors. |
|
450 |
||
451 |
@see TDes8 |
|
452 |
*/ |
|
453 |
EXPORT_C void Kern::AppendFormat(TDes8& aDes, const char* aFmt, VA_LIST aList) |
|
454 |
{ |
|
455 |
||
456 |
#define NEXT_FMT(c,p) if (((c)=*(p)++)==0) return |
|
457 |
_LIT8(NullDescriptor,"(null)"); |
|
458 |
_LIT8(KLitNULL,"NULL"); |
|
459 |
_LIT8(KLitSysLock,"SysLock"); |
|
460 |
_LIT8(KLitObjLock,"ObjLock"); |
|
461 |
_LIT8(KLitMsgLock,"MsgLock"); |
|
462 |
_LIT8(KLitLogonLock,"LogonLock"); |
|
463 |
_LIT8(KLitMiscNtfMgrLock,"MiscNtfMgrLock"); |
|
464 |
||
465 |
TBuf8<24> NumBuf; |
|
466 |
FOREVER |
|
467 |
{ |
|
468 |
char c; |
|
469 |
NEXT_FMT(c,aFmt); |
|
470 |
if (c=='%') |
|
471 |
{ |
|
472 |
char fill=' '; |
|
473 |
TInt width=0; |
|
474 |
TBool long_arg=EFalse; |
|
475 |
TBool ok=ETrue; |
|
476 |
NEXT_FMT(c,aFmt); |
|
477 |
if (c=='0') |
|
478 |
{ |
|
479 |
fill='0'; |
|
480 |
NEXT_FMT(c,aFmt); |
|
481 |
} |
|
482 |
while(c>='0' && c<='9') |
|
483 |
{ |
|
484 |
width=width*10+c-'0'; |
|
485 |
NEXT_FMT(c,aFmt); |
|
486 |
} |
|
487 |
if (c=='l') |
|
488 |
{ |
|
489 |
long_arg=ETrue; |
|
490 |
NEXT_FMT(c,aFmt); |
|
491 |
} |
|
492 |
switch(c) |
|
493 |
{ |
|
494 |
case 'd': |
|
495 |
{ |
|
496 |
if (long_arg) |
|
497 |
ok=EFalse; |
|
498 |
else |
|
499 |
{ |
|
500 |
TInt val=VA_ARG(aList,TInt); |
|
501 |
NumBuf.Num(val); |
|
502 |
AppendNumBuf(aDes,NumBuf,width,fill); |
|
503 |
} |
|
504 |
break; |
|
505 |
} |
|
506 |
case 'u': |
|
507 |
{ |
|
508 |
if (long_arg) |
|
509 |
ok=EFalse; |
|
510 |
else |
|
511 |
{ |
|
512 |
TUint val=VA_ARG(aList,TUint); |
|
513 |
NumBuf.Num(val,EDecimal); |
|
514 |
AppendNumBuf(aDes,NumBuf,width,fill); |
|
515 |
} |
|
516 |
break; |
|
517 |
} |
|
518 |
case 'x': |
|
519 |
case 'X': |
|
520 |
{ |
|
521 |
if (long_arg) |
|
522 |
{ |
|
523 |
Uint64 val=VA_ARG(aList,Uint64); |
|
524 |
TUint vl=(TUint)val; |
|
525 |
TUint vh=(TUint)(val>>32); |
|
526 |
if (vh) |
|
527 |
{ |
|
528 |
NumBuf.Num(vh,EHex); |
|
529 |
NumBuf.AppendNumFixedWidth(vl,EHex,8); |
|
530 |
} |
|
531 |
else |
|
532 |
{ |
|
533 |
NumBuf.Num(vl,EHex); |
|
534 |
} |
|
535 |
} |
|
536 |
else |
|
537 |
{ |
|
538 |
TUint val=VA_ARG(aList,TUint); |
|
539 |
NumBuf.Num(val,EHex); |
|
540 |
} |
|
541 |
AppendNumBuf(aDes,NumBuf,width,fill); |
|
542 |
break; |
|
543 |
} |
|
544 |
case 'S': |
|
545 |
case 's': |
|
546 |
{ |
|
547 |
TPtrC8 ptrc8; |
|
548 |
const TDesC *pS=VA_ARG(aList,const TDesC*); |
|
549 |
if (c=='s') |
|
550 |
{ |
|
551 |
ptrc8.Set((const TUint8*)pS), pS=(const TDesC*)&ptrc8; |
|
552 |
} |
|
553 |
if (pS) |
|
554 |
{ |
|
555 |
AppendNumBuf(aDes,*(const TDesC8*)pS,width,fill); |
|
556 |
} |
|
557 |
else |
|
558 |
aDes.Append(NullDescriptor); |
|
559 |
break; |
|
560 |
} |
|
561 |
case 'O': |
|
562 |
{ |
|
563 |
DObject* pO=VA_ARG(aList,DObject*); |
|
564 |
if (pO) |
|
565 |
pO->TraceAppendFullName(aDes,ETrue); |
|
566 |
else |
|
567 |
aDes.Append(KLitNULL); |
|
568 |
break; |
|
569 |
} |
|
570 |
case 'o': |
|
571 |
{ |
|
572 |
DObject* pO=VA_ARG(aList,DObject*); |
|
573 |
if (pO) |
|
574 |
pO->TraceAppendName(aDes,ETrue); |
|
575 |
else |
|
576 |
aDes.Append(KLitNULL); |
|
577 |
break; |
|
578 |
} |
|
579 |
case 'M': // fast mutex |
|
580 |
{ |
|
581 |
NFastMutex* pM=VA_ARG(aList,NFastMutex*); |
|
582 |
if (!pM) |
|
583 |
aDes.Append(KLitNULL); |
|
584 |
else if (pM==&TheScheduler.iLock) |
|
585 |
aDes.Append(KLitSysLock); |
|
586 |
else if (pM==&DObject::Lock) |
|
587 |
aDes.Append(KLitObjLock); |
|
588 |
else if (pM==&TMessageQue::MsgLock) |
|
589 |
aDes.Append(KLitMsgLock); |
|
590 |
else if (pM==&TLogon::LogonLock) |
|
591 |
aDes.Append(KLitLogonLock); |
|
592 |
else if (pM==&K::TheMiscNotifierMgr.iLock) |
|
593 |
aDes.Append(KLitMiscNtfMgrLock); |
|
594 |
else |
|
595 |
aDes.AppendNumFixedWidth((TUint)pM,EHex,8); |
|
596 |
break; |
|
597 |
} |
|
598 |
case 'm': // fast semaphore |
|
599 |
{ |
|
600 |
NFastSemaphore* pS=VA_ARG(aList,NFastSemaphore*); |
|
601 |
if (!pS) |
|
602 |
aDes.Append(KLitNULL); |
|
603 |
else |
|
604 |
{ |
|
605 |
// following commented out because pointers may end up referencing non-existent memory... |
|
606 |
/* |
|
607 |
DThread* pT1=_LOFF(pS,DThread,iNThread.iRequestSemaphore); |
|
608 |
DThread* pT2=_LOFF(pS,DThread,iKernMsg.iSem); |
|
609 |
if (pT1->iNThread.iHandlers==&EpocThreadHandlers) |
|
610 |
pT1->TraceAppendFullName(aDes,ETrue); |
|
611 |
else if (pT2->iNThread.iHandlers==&EpocThreadHandlers) |
|
612 |
pT2->TraceAppendFullName(aDes,ETrue); |
|
613 |
else |
|
614 |
*/ aDes.AppendNumFixedWidth((TUint)pS,EHex,8); |
|
615 |
} |
|
616 |
break; |
|
617 |
} |
|
618 |
case 'T': // NKERN thread |
|
619 |
{ |
|
620 |
NThread* pN=VA_ARG(aList,NThread*); |
|
621 |
if (!pN) |
|
622 |
aDes.Append(KLitNULL); |
|
623 |
else if (pN->iHandlers==&EpocThreadHandlers) |
|
624 |
{ |
|
625 |
DThread* pT=_LOFF(pN,DThread,iNThread); |
|
626 |
pT->TraceAppendFullName(aDes,ETrue); |
|
627 |
} |
|
628 |
else |
|
629 |
aDes.AppendNumFixedWidth((TUint)pN,EHex,8); |
|
630 |
break; |
|
631 |
} |
|
632 |
case 'C': |
|
633 |
{ |
|
634 |
DCodeSeg* pO=VA_ARG(aList,DCodeSeg*); |
|
635 |
if (pO) |
|
636 |
pO->TraceAppendFullName(aDes); |
|
637 |
else |
|
638 |
aDes.Append(KLitNULL); |
|
639 |
break; |
|
640 |
} |
|
641 |
#ifdef __SMP__ |
|
642 |
case 'G': // NKERN thread group |
|
643 |
{ |
|
644 |
NThreadGroup* pG=VA_ARG(aList,NThreadGroup*); |
|
645 |
if (!pG) |
|
646 |
aDes.Append(KLitNULL); |
|
647 |
// else if (pN->iHandlers==&EpocThreadHandlers) |
|
648 |
// { |
|
649 |
// DThread* pT=_LOFF(pN,DThread,iNThread); |
|
650 |
// pT->TraceAppendFullName(aDes,ETrue); |
|
651 |
// } |
|
652 |
else |
|
653 |
aDes.AppendNumFixedWidth((TUint)pG,EHex,8); |
|
654 |
break; |
|
655 |
} |
|
656 |
#endif |
|
657 |
case 'c': |
|
658 |
c=(char)VA_ARG(aList,TUint); |
|
659 |
// fall through |
|
660 |
default: |
|
661 |
ok=EFalse; |
|
662 |
break; |
|
663 |
} |
|
664 |
if (ok) |
|
665 |
continue; |
|
666 |
} |
|
667 |
aDes.Append(TChar(c)); |
|
668 |
} |
|
669 |
} |
|
670 |
||
671 |
#if 0 |
|
672 |
void DumpMemoryLine(TLinAddr a) |
|
673 |
{ |
|
674 |
const TUint8* p = (const TUint8*)a; |
|
675 |
TUint8 c[16]; |
|
676 |
TInt i; |
|
677 |
for (i=0; i<16; ++i) |
|
678 |
{ |
|
679 |
TUint8 x = p[i]; |
|
680 |
if (x<0x21 || x>0x7e) |
|
681 |
x = 0x2e; |
|
682 |
c[i] = (TUint8)x; |
|
683 |
} |
|
684 |
Kern::Printf("%08x: %02x %02x %02x %02x %02x %02x %02x %02x " |
|
685 |
"%02x %02x %02x %02x %02x %02x %02x %02x " |
|
686 |
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", |
|
687 |
a, p[ 0], p[ 1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7], |
|
688 |
p[ 8], p[ 9], p[10], p[11], p[12], p[13], p[14], p[15], |
|
689 |
c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], |
|
690 |
c[ 8], c[ 9], c[10], c[11], c[12], c[13], c[14], c[15] |
|
691 |
); |
|
692 |
} |
|
693 |
||
694 |
void DumpMemory(const char* aTitle, TLinAddr aStart, TLinAddr aSize) |
|
695 |
{ |
|
696 |
Kern::Printf(aTitle); |
|
697 |
while (aSize) |
|
698 |
{ |
|
699 |
DumpMemoryLine(aStart); |
|
700 |
aStart += 16; |
|
701 |
if (aSize>=16) |
|
702 |
aSize -= 16; |
|
703 |
else |
|
704 |
aSize = 0; |
|
705 |
} |
|
706 |
} |
|
707 |
#endif |
|
708 |
||
709 |
extern "C" { |
|
710 |
/** |
|
711 |
Faults the system, noting file name and line number. |
|
712 |
||
713 |
Used from nanokernel code and in various __ASSERT macros. |
|
714 |
||
715 |
@param file The file name as a C string (__FILE__). |
|
716 |
@param line The line number (__LINE__). |
|
717 |
||
718 |
@see Kern::Fault() |
|
719 |
*/ |
|
720 |
EXPORT_C void NKFault(const char* file, TInt line) |
|
721 |
{ |
|
722 |
Kern::Fault(file,line); |
|
723 |
} |
|
724 |
} |
|
725 |
||
726 |
||
727 |
||
728 |
||
729 |
/** |
|
730 |
Faults the system. |
|
731 |
||
732 |
This will start the Crash Debugger if it is present, |
|
733 |
otherwise the system is rebooted by calling Kern::Restart(0). |
|
734 |
||
735 |
@param aCat A pointer to a zero terminated string containing the category |
|
736 |
of the fault. |
|
737 |
@param aFault The fault number. |
|
738 |
||
739 |
@pre Call in any context. |
|
740 |
@pre Kernel can be locked or unlocked. |
|
741 |
@pre Interrupts can either be enabled or disabled. |
|
742 |
@pre Any kind of lock can be held. |
|
743 |
||
744 |
@see Kern::Restart() |
|
745 |
*/ |
|
746 |
EXPORT_C void Kern::Fault(const char* aCat, TInt aFault) |
|
747 |
{ |
|
748 |
TPtrC8 cat((const TUint8*)aCat); |
|
749 |
Kern::Printf("FAULT: %S 0x%08x (%d) ",&cat,aFault,aFault); |
|
750 |
||
751 |
// Disables interrupts |
|
752 |
// Doesn't return |
|
753 |
NKern::NotifyCrash(&cat, aFault); |
|
754 |
} |
|
755 |
||
756 |
||
757 |
void K::DoFault(const TAny* aCat, TInt aFault) |
|
758 |
{ |
|
759 |
BTrace::Control(BTrace::ECtrlSystemCrashed); |
|
760 |
A::StartCrashDebugger(aCat, aFault); |
|
761 |
TheSuperPage().iKernelFault=aFault; |
|
762 |
||
763 |
// bodge the first 8 bytes of the name into the code and data |
|
764 |
if (aFault!=K::ESystemException) |
|
765 |
{ |
|
766 |
const TDesC8* cat = (const TDesC8*)aCat; |
|
767 |
TInt csz = cat->Size(); |
|
768 |
TExcInfo& xinf=TheSuperPage().iKernelExcInfo; |
|
769 |
xinf.iCodeAddress=0; |
|
770 |
xinf.iDataAddress=0; |
|
771 |
memcpy((TUint8*)&xinf.iCodeAddress,cat->Ptr(),Min(csz,8)); |
|
772 |
} |
|
773 |
||
774 |
Kern::Restart(0); |
|
775 |
} |
|
776 |
||
777 |
||
778 |
||
779 |
||
780 |
/** |
|
781 |
Gets the address of the low priority DFC queue. |
|
782 |
||
783 |
@return A pointer to the low priority DFC queue. |
|
784 |
||
785 |
@pre Call in any context. |
|
786 |
*/ |
|
787 |
EXPORT_C TDfcQue* Kern::DfcQue0() |
|
788 |
{ |
|
789 |
return K::DfcQ0; |
|
790 |
} |
|
791 |
||
792 |
||
793 |
||
794 |
||
795 |
/** |
|
796 |
Gets the address of the high priority DFC queue. |
|
797 |
||
798 |
This is the one used for the nanokernel timer DFC. In the absence of |
|
799 |
a personality layer this will usually be the highest priority thread |
|
800 |
in the system. |
|
801 |
||
802 |
@return A pointer to the high priority DFC queue. |
|
803 |
||
804 |
@pre Call in any context. |
|
805 |
*/ |
|
806 |
EXPORT_C TDfcQue* Kern::DfcQue1() |
|
807 |
{ |
|
808 |
return K::DfcQ1; |
|
809 |
} |
|
810 |
||
811 |
||
812 |
||
813 |
||
814 |
/** |
|
815 |
Gets the address of the supervisor thread DFC queue. |
|
816 |
||
817 |
@return A pointer to the supervisor thread DFC queue. |
|
818 |
||
819 |
@pre Call in any context. |
|
820 |
*/ |
|
821 |
EXPORT_C TDfcQue* Kern::SvMsgQue() |
|
822 |
{ |
|
823 |
return K::SvMsgQ; |
|
824 |
} |
|
825 |
||
826 |
||
827 |
||
828 |
||
829 |
/** |
|
830 |
Creates a new DFC queue. |
|
831 |
||
832 |
The function allocates a TDfcQue object on the heap and initialises it with |
|
833 |
the provided parameters. |
|
834 |
||
835 |
The thread created for the queue will have its real time state enabled. If |
|
836 |
this is not the desired behaviour then TDynamicDfcQue::SetRealtimeState() can |
|
837 |
be used to disable the real time state of the thread. |
|
838 |
||
839 |
@param aDfcQ A reference to a pointer which, on successful return, is set |
|
840 |
to point to the new DFC queue. On failure, the pointer is set |
|
841 |
to NULL. |
|
842 |
||
843 |
@param aPriority The thread priority for the queue. |
|
844 |
||
845 |
@param aName A pointer to a name for the queue thread. If NULL, |
|
846 |
a unique name of the form 'DfcThreadNNN' is generated for the |
|
847 |
queue. |
|
848 |
||
849 |
@return KErrNone, if successful, otherwise one of the other system-wide error |
|
850 |
codes. |
|
851 |
||
852 |
@pre Calling thread must be in a critical section. |
|
853 |
@pre Interrupts must be enabled. |
|
854 |
@pre Kernel must be unlocked. |
|
855 |
@pre No fast mutex can be held. |
|
856 |
@pre Call in a thread context. |
|
857 |
@pre Can be used in a device driver. |
|
858 |
||
859 |
@see Kern::DfcQInit() |
|
860 |
@see TDynamicDfcQue::SetRealtimeState() |
|
861 |
*/ |
|
862 |
EXPORT_C TInt Kern::DfcQCreate(TDfcQue*& aDfcQ, TInt aPriority, const TDesC* aName) |
|
863 |
{ |
|
864 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DfcQCreate"); |
|
865 |
TInt r=KErrNoMemory; |
|
866 |
TDfcQue* pQ=new TDfcQue; |
|
867 |
aDfcQ=pQ; |
|
868 |
if (pQ) |
|
869 |
{ |
|
870 |
r=Kern::DfcQInit(pQ,aPriority,aName); |
|
871 |
if (r!=KErrNone) |
|
872 |
{ |
|
873 |
delete pQ; |
|
874 |
aDfcQ=NULL; |
|
875 |
} |
|
876 |
} |
|
877 |
return r; |
|
878 |
} |
|
879 |
||
880 |
||
881 |
||
882 |
||
883 |
/** |
|
884 |
Creates a new dynamic DFC queue. |
|
885 |
||
886 |
The function allocates a TDynamicDfcQue object on the heap and initialises it |
|
887 |
with the provided parameters. |
|
888 |
||
889 |
The thread created for the queue will have its real time state enabled. If |
|
890 |
this is not the desired behaviour then TDynamicDfcQue::SetRealtimeState() can |
|
891 |
be used to disable the real time state of the thread. |
|
892 |
||
893 |
@param aDfcQ A reference to a pointer which, on successful return, is set |
|
894 |
to point to the new DFC queue. On failure, the pointer is set |
|
895 |
to NULL. |
|
896 |
||
897 |
@param aPriority The thread priority for the queue. |
|
898 |
||
899 |
@param aBaseName The base name for the queue thread. A 9 character string will |
|
900 |
be appended to this name to create a unique thread name, |
|
901 |
therefore the base name must not exceed 71 characters. |
|
902 |
||
903 |
@return KErrNone, if successful, otherwise one of the other system-wide error |
|
904 |
codes. |
|
905 |
||
906 |
@pre Calling thread must be in a critical section. |
|
907 |
@pre Interrupts must be enabled. |
|
908 |
@pre Kernel must be unlocked. |
|
909 |
@pre No fast mutex can be held. |
|
910 |
@pre Call in a thread context. |
|
911 |
@pre Can be used in a device driver. |
|
912 |
||
913 |
@see Kern::DfcQInit() |
|
914 |
@see TDynamicDfcQue::SetRealtimeState() |
|
915 |
*/ |
|
916 |
EXPORT_C TInt Kern::DynamicDfcQCreate(TDynamicDfcQue*& aDfcQ, TInt aPriority, const TDesC& aBaseName) |
|
917 |
{ |
|
918 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DynamicDfcQCreate"); |
|
919 |
aDfcQ = NULL; |
|
920 |
TDynamicDfcQue* pQ=new TDynamicDfcQue; |
|
921 |
if (!pQ) |
|
922 |
return KErrNoMemory; |
|
923 |
||
924 |
TInt r; |
|
925 |
do |
|
926 |
{ |
|
927 |
// Generate successive IDs using linear congruential random number generator |
|
928 |
TUint32 original_qid; |
|
929 |
TUint32 qid; |
|
930 |
do { |
|
931 |
original_qid = K::DynamicDfcQId; |
|
932 |
qid = original_qid * 69069 + 1; |
|
933 |
} while (!__e32_atomic_cas_rlx32(&K::DynamicDfcQId, &original_qid, qid)); |
|
934 |
TKName name(aBaseName); |
|
935 |
name.Append('-'); |
|
936 |
name.AppendNum(qid, EHex); |
|
937 |
r = Kern::DfcQInit(pQ,aPriority,&name); |
|
938 |
} |
|
939 |
while (r == KErrAlreadyExists); |
|
940 |
||
941 |
if (r!=KErrNone) |
|
942 |
delete pQ; |
|
943 |
else |
|
944 |
aDfcQ = pQ; |
|
945 |
||
946 |
return r; |
|
947 |
} |
|
948 |
||
949 |
||
950 |
||
951 |
||
952 |
void DynamicDfcQKillFunction(TAny* aDfcQ) |
|
953 |
{ |
|
954 |
Kern::SetThreadPriority(KDefaultExitPriority); |
|
955 |
delete (TDfcQue*)aDfcQ; |
|
956 |
Kern::Exit(0); |
|
957 |
} |
|
958 |
||
959 |
||
960 |
||
961 |
||
962 |
TDynamicDfcQue::TDynamicDfcQue() |
|
963 |
: iKillDfc(DynamicDfcQKillFunction, this, this, 0) |
|
964 |
{ |
|
965 |
} |
|
966 |
||
967 |
||
968 |
||
969 |
/** |
|
970 |
Destroys the DFC queue. |
|
971 |
||
972 |
The function destroys the DFC queue, killing the DFC thread and deleting the TDynamicDfcQue |
|
973 |
object itself. |
|
974 |
||
975 |
@pre Calling thread must be in a critical section. |
|
976 |
@pre Interrupts must be enabled. |
|
977 |
@pre Kernel must be unlocked. |
|
978 |
@pre No fast mutex can be held. |
|
979 |
@pre Call in a thread context. |
|
980 |
@pre Can be used in a device driver. |
|
981 |
||
982 |
@see Kern::DfcQCreate() |
|
983 |
@see Kern::DfcQInit() |
|
984 |
*/ |
|
985 |
EXPORT_C void TDynamicDfcQue::Destroy() |
|
986 |
{ |
|
987 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TDynamicDfcQue::Destroy"); |
|
988 |
iKillDfc.Enque(); |
|
989 |
} |
|
990 |
||
991 |
||
992 |
||
993 |
/** |
|
994 |
Sets the realtime state for the thread that runs the DFC queue. |
|
995 |
||
996 |
@param aNewState The new realtime state for the thread. |
|
997 |
||
998 |
@pre No fast mutex can be held. |
|
999 |
@pre Call in a thread context. |
|
1000 |
@pre Kernel must be unlocked |
|
1001 |
@pre Interrupts enabled |
|
1002 |
@pre Can be used in a device driver. |
|
1003 |
*/ |
|
1004 |
EXPORT_C void TDynamicDfcQue::SetRealtimeState(TThreadRealtimeState aNewState) |
|
1005 |
{ |
|
1006 |
_LOFF(iThread,DThread,iNThread)->SetRealtimeState(aNewState); |
|
1007 |
} |
|
1008 |
||
1009 |
||
1010 |
||
1011 |
||
1012 |
_LIT(KLitKernCommon, "KERN-COMMON"); |
|
1013 |
void Panic(TCdtPanic aPanic) |
|
1014 |
{ |
|
1015 |
Kern::PanicCurrentThread(KLitKernCommon, aPanic); |
|
1016 |
} |
|
1017 |
||
1018 |
void K::Fault(K::TFault aFault) |
|
1019 |
{ |
|
1020 |
Kern::Fault("KERN",aFault); |
|
1021 |
} |
|
1022 |
||
1023 |
||
1024 |
||
1025 |
||
1026 |
/** |
|
1027 |
Waits for a request to complete. |
|
1028 |
||
1029 |
@param aStatus The status of the request to wait for. |
|
1030 |
*/ |
|
1031 |
EXPORT_C void Kern::WaitForRequest(TRequestStatus& aStatus) |
|
1032 |
{ |
|
1033 |
TInt i=-1; |
|
1034 |
do |
|
1035 |
{ |
|
1036 |
++i; |
|
1037 |
NKern::WaitForAnyRequest(); |
|
1038 |
} while (aStatus==KRequestPending); |
|
1039 |
if (i) |
|
1040 |
ExecHandler::RequestSignal(i); |
|
1041 |
} |
|
1042 |
||
1043 |
||
1044 |
/** |
|
1045 |
Allocates a block of the specified size on the kernel heap and zero-fills it. |
|
1046 |
||
1047 |
@param aSize The size of the buffer to be allocated, in bytes. This must be |
|
1048 |
positive and must be less than the value of |
|
1049 |
@code |
|
1050 |
KMaxTInt/2 |
|
1051 |
@endcode |
|
1052 |
otherwise the allocation request fails. |
|
1053 |
||
1054 |
@return A pointer to the allocated buffer, if successful; NULL if the |
|
1055 |
allocation request fails. |
|
1056 |
||
1057 |
@pre Calling thread must be in a critical section. |
|
1058 |
@pre Interrupts must be enabled. |
|
1059 |
@pre Kernel must be unlocked. |
|
1060 |
@pre No fast mutex can be held. |
|
1061 |
@pre Call in a thread context. |
|
1062 |
@pre Can be used in a device driver. |
|
1063 |
*/ |
|
1064 |
EXPORT_C TAny* Kern::Alloc(TInt aSize) |
|
1065 |
{ |
|
1066 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::Alloc"); |
|
1067 |
if ((TUint)aSize < KMaxTInt/2) |
|
1068 |
return K::Allocator->Alloc(aSize); |
|
1069 |
return NULL; |
|
1070 |
} |
|
1071 |
||
1072 |
||
1073 |
||
1074 |
||
1075 |
/** |
|
1076 |
Allocates a block of the specified size on the kernel heap and zero-fills it. |
|
1077 |
||
1078 |
@deprecated |
|
1079 |
||
1080 |
Calling this function has the same effect as calling Kern::Alloc(). |
|
1081 |
||
1082 |
@param aSize The size of the buffer to be allocated, in bytes. This must be |
|
1083 |
positive and must be less than the value of |
|
1084 |
@code |
|
1085 |
KMaxTInt/2 |
|
1086 |
@endcode |
|
1087 |
otherwise the allocation request fails. |
|
1088 |
||
1089 |
@return A pointer to the allocated buffer, if successful; NULL if the |
|
1090 |
allocation request fails. |
|
1091 |
||
1092 |
@pre Calling thread must be in a critical section. |
|
1093 |
@pre Interrupts must be enabled. |
|
1094 |
@pre Kernel must be unlocked. |
|
1095 |
@pre No fast mutex can be held. |
|
1096 |
@pre Call in a thread context. |
|
1097 |
@pre Can be used in a device driver. |
|
1098 |
||
1099 |
@see Kern::Alloc() |
|
1100 |
*/ |
|
1101 |
EXPORT_C TAny* Kern::AllocZ(TInt aSize) |
|
1102 |
{ |
|
1103 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::AllocZ"); |
|
1104 |
return Kern::Alloc(aSize); |
|
1105 |
} |
|
1106 |
||
1107 |
||
1108 |
||
1109 |
||
1110 |
/** |
|
1111 |
Frees a block of memory back to the kernel heap. |
|
1112 |
||
1113 |
The pointer passed must point to a valid allocated kernel heap cell, which |
|
1114 |
will be the case if it was previously allocated using Kern::Alloc() or |
|
1115 |
Kern::AllocZ(). |
|
1116 |
||
1117 |
@param aPtr A pointer to the buffer to be freed. |
|
1118 |
||
1119 |
@pre Calling thread must be in a critical section. |
|
1120 |
@pre Interrupts must be enabled. |
|
1121 |
@pre Kernel must be unlocked. |
|
1122 |
@pre No fast mutex can be held. |
|
1123 |
@pre Call in a thread context. |
|
1124 |
@pre Can be used in a device driver. |
|
1125 |
||
1126 |
@see Kern::Alloc() |
|
1127 |
@see Kern::AllocZ() |
|
1128 |
*/ |
|
1129 |
EXPORT_C void Kern::Free(TAny* aPtr) |
|
1130 |
{ |
|
1131 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::Free"); |
|
1132 |
K::Allocator->Free(aPtr); |
|
1133 |
} |
|
1134 |
||
1135 |
||
1136 |
||
1137 |
||
1138 |
/** |
|
1139 |
Reallocates a buffer. |
|
1140 |
||
1141 |
The buffer is assumed to have been previously allocated using Kern::Alloc() or |
|
1142 |
Kern::AllocZ(). |
|
1143 |
||
1144 |
If the new requested size is bigger than the current size, then the function |
|
1145 |
tries to grow the currently allocated buffer, and if that fails, allocates a new |
|
1146 |
buffer by calling Kern::Alloc(), copies the content of the old buffer into the |
|
1147 |
new buffer, and frees the old buffer. Any newly committed memory is |
|
1148 |
zero-filled. If the allocation mode is ENeverMove, the currently allocated |
|
1149 |
buffer cannot be grown, and the function returns NULL instead. |
|
1150 |
||
1151 |
If the new requested size is less than the current size, then the function |
|
1152 |
shrinks the allocated buffer, and, if the remainder is large enough, creates a |
|
1153 |
new free cell. |
|
1154 |
||
1155 |
If the pointer passed to this function is NULL, then it behaves like |
|
1156 |
Kern::Alloc(). However, if the allocation mode is ENeverMove, then it just |
|
1157 |
returns NULL. |
|
1158 |
||
1159 |
@param aPtr A pointer to the existing buffer that is to be reallocated. |
|
1160 |
||
1161 |
@param aSize The new requested size of the buffer, in bytes. |
|
1162 |
||
1163 |
@param aMode The allocation mode. It specifies how the buffer should be |
|
1164 |
reallocated. It can take one of the values ENeverMove and |
|
1165 |
EAllowMoveOnShrink. |
|
1166 |
||
1167 |
@return Pointer to the reallocated buffer or NULL if the re-allocation request |
|
1168 |
fails. |
|
1169 |
||
1170 |
@pre Calling thread must be in a critical section. |
|
1171 |
@pre Interrupts must be enabled. |
|
1172 |
@pre Kernel must be unlocked. |
|
1173 |
@pre No fast mutex can be held. |
|
1174 |
@pre Call in a thread context. |
|
1175 |
@pre Can be used in a device driver. |
|
1176 |
||
1177 |
@post Calling thread is in a critical section. |
|
1178 |
||
1179 |
@see Kern::Alloc() |
|
1180 |
@see ENeverMove |
|
1181 |
@see EAllowMoveOnShrink |
|
1182 |
*/ |
|
1183 |
EXPORT_C TAny* Kern::ReAlloc(TAny* aPtr, TInt aSize, TInt aMode) |
|
1184 |
{ |
|
1185 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ReAlloc"); |
|
1186 |
return K::Allocator->ReAlloc(aPtr, aSize, aMode); |
|
1187 |
} |
|
1188 |
||
1189 |
||
1190 |
||
1191 |
||
1192 |
/** |
|
1193 |
Safely reallocates a buffer. |
|
1194 |
||
1195 |
The buffer is assumed to have been previously allocated using Kern::Alloc() or |
|
1196 |
Kern::AllocZ(). |
|
1197 |
||
1198 |
If the new requested size is zero, the function frees the pointer and sets it |
|
1199 |
to NULL. |
|
1200 |
||
1201 |
If the new requested size is bigger than the old size, then the function tries |
|
1202 |
to grow the currently allocated buffer using Kern::ReAlloc() specifiying the |
|
1203 |
ENeverMove allocation mode. If this fails, it does the following sequence of |
|
1204 |
operations: it calls Kern::Alloc() to allocate a new larger size buffer, copies |
|
1205 |
the content of the old buffer into the new buffer (zero filling the extra space |
|
1206 |
in the new buffer), acquires the system lock, sets aPtr to point to the new |
|
1207 |
buffer, releases the system lock and finally frees the original buffer. |
|
1208 |
||
1209 |
If the new requested size is less than the old size, the function shrinks the |
|
1210 |
buffer but does not move it. |
|
1211 |
||
1212 |
This function is intended to allow the implementation of a dynamically growing |
|
1213 |
array which can be indexed and read very efficiently by holding only the |
|
1214 |
system lock, while modification of the array is protected by a heavyweight mutex. |
|
1215 |
||
1216 |
@param aPtr A reference to a pointer to the buffer to be reallocated. |
|
1217 |
@param aOldSize The size of the currently allocated buffer. |
|
1218 |
@param aNewSize The new requested size of the buffer. |
|
1219 |
||
1220 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory. |
|
1221 |
||
1222 |
@pre Calling thread must be in a critical section. |
|
1223 |
@pre Interrupts must be enabled. |
|
1224 |
@pre Kernel must be unlocked. |
|
1225 |
@pre No fast mutex can be held. |
|
1226 |
@pre Call in a thread context. |
|
1227 |
@pre Can be used in a device driver. |
|
1228 |
||
1229 |
@post Calling thread is in a critical section. |
|
1230 |
||
1231 |
@see Kern::ReAlloc() |
|
1232 |
@see Kern::Alloc() |
|
1233 |
*/ |
|
1234 |
EXPORT_C TInt Kern::SafeReAlloc(TAny*& aPtr, TInt aOldSize, TInt aNewSize) |
|
1235 |
{ |
|
1236 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::SafeReAlloc"); |
|
1237 |
if (aNewSize > aOldSize) |
|
1238 |
{ |
|
1239 |
#ifdef _DEBUG |
|
1240 |
// we can't rely of simulated OOM in the kernel allocator because if |
|
1241 |
// ReAlloc fails (and swallows simulated OOM) then the following Alloc will succeed... |
|
1242 |
if(K::CheckForSimulatedAllocFail()) |
|
1243 |
return KErrNoMemory; |
|
1244 |
#endif |
|
1245 |
TAny* p = ReAlloc(aPtr, aNewSize, RAllocator::ENeverMove); |
|
1246 |
if (p) |
|
1247 |
return KErrNone; // grow in place succeeded, no need to move |
|
1248 |
TAny* pNew = Alloc(aNewSize); // otherwise allocate bigger block |
|
1249 |
if (!pNew) |
|
1250 |
return KErrNoMemory; |
|
1251 |
TAny* pOld = aPtr; |
|
1252 |
memcpy(pNew, pOld, aOldSize); // copy current contents |
|
1253 |
#ifdef _DEBUG |
|
1254 |
if (pOld) |
|
1255 |
K::Allocator->DebugFunction(RAllocator::ECopyDebugInfo, pOld, pNew); |
|
1256 |
#endif |
|
1257 |
NKern::LockSystem(); |
|
1258 |
aPtr = pNew; |
|
1259 |
NKern::UnlockSystem(); |
|
1260 |
Free(pOld); // free old block |
|
1261 |
} |
|
1262 |
else if (aNewSize < aOldSize) |
|
1263 |
{ |
|
1264 |
if (aNewSize > 0) |
|
1265 |
aPtr = ReAlloc(aPtr, aNewSize, 0); // can't fail |
|
1266 |
else |
|
1267 |
{ |
|
1268 |
NKern::LockSystem(); |
|
1269 |
TAny* pOld = aPtr; |
|
1270 |
aPtr = NULL; |
|
1271 |
NKern::UnlockSystem(); |
|
1272 |
Free(pOld); |
|
1273 |
} |
|
1274 |
} |
|
1275 |
return KErrNone; |
|
1276 |
} |
|
1277 |
||
1278 |
||
1279 |
||
1280 |
||
1281 |
/** |
|
1282 |
Walks the kernel heap to validate its consistency. If the heap is inconsistent, |
|
1283 |
the kernel will panic with an appropriate panic code. |
|
1284 |
||
1285 |
@pre Calling thread must be in a critical section. |
|
1286 |
@pre Interrupts must be enabled. |
|
1287 |
@pre Kernel must be unlocked. |
|
1288 |
@pre No fast mutex can be held. |
|
1289 |
@pre Call in a thread context. |
|
1290 |
@pre Can be used in a device driver. |
|
1291 |
*/ |
|
1292 |
EXPORT_C void Kern::ValidateHeap() |
|
1293 |
{ |
|
1294 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ValidateHeap"); |
|
1295 |
K::Allocator->Check(); |
|
1296 |
} |
|
1297 |
||
1298 |
||
1299 |
||
1300 |
||
1301 |
/** |
|
1302 |
Atomically swaps the pointer to the kernel-side reference counted object with a |
|
1303 |
NULL value, and then closes the object. |
|
1304 |
||
1305 |
@param aObj A reference to a pointer to a kernel-side reference counted object |
|
1306 |
that is to be closed; it is safe to pass a NULL value. |
|
1307 |
@param aPtr A pointer that is passed as a parameter to DObject::Close(). |
|
1308 |
||
1309 |
@pre Calling thread must be in a critical section |
|
1310 |
@pre Interrupts must be enabled. |
|
1311 |
@pre Kernel must be unlocked. |
|
1312 |
@pre No fast mutex can be held. |
|
1313 |
@pre Call in a thread context. |
|
1314 |
@pre Can be used in a device driver. |
|
1315 |
||
1316 |
@post aObj is NULL. |
|
1317 |
||
1318 |
@see DObject::Close() |
|
1319 |
*/ |
|
1320 |
EXPORT_C void Kern::SafeClose(DObject*& aObj, TAny* aPtr) |
|
1321 |
{ |
|
1322 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::SafeClose"); |
|
1323 |
DObject* pO = (DObject*)__e32_atomic_swp_ord_ptr(&aObj, 0); |
|
1324 |
if (pO) |
|
1325 |
pO->Close(aPtr); |
|
1326 |
} |
|
1327 |
||
1328 |
||
1329 |
TInt K::MakeHandle(TOwnerType aType, DObject* anObject) |
|
1330 |
{ |
|
1331 |
TInt h; |
|
1332 |
TInt r=TheCurrentThread->MakeHandle(aType,anObject,h); |
|
1333 |
if(r==KErrNone) |
|
1334 |
return h; |
|
1335 |
else |
|
1336 |
return r; |
|
1337 |
} |
|
1338 |
||
1339 |
TInt K::MakeHandle(TOwnerType aType, DObject* anObject, TUint aAttr) |
|
1340 |
{ |
|
1341 |
TInt h; |
|
1342 |
TInt r=TheCurrentThread->MakeHandle(aType,anObject,h,aAttr); |
|
1343 |
if(r==KErrNone) |
|
1344 |
return h; |
|
1345 |
else |
|
1346 |
return r; |
|
1347 |
} |
|
1348 |
||
1349 |
TInt K::MakeHandleAndOpen(TOwnerType aType, DObject* anObject, TInt& aHandle) |
|
1350 |
{ |
|
1351 |
return TheCurrentThread->MakeHandleAndOpen(aType,anObject,aHandle); |
|
1352 |
} |
|
1353 |
||
1354 |
TInt K::MakeHandleAndOpen(TOwnerType aType, DObject* anObject, TInt& aHandle, TUint aAttr) |
|
1355 |
{ |
|
1356 |
return TheCurrentThread->MakeHandleAndOpen(aType,anObject,aHandle, aAttr); |
|
1357 |
} |
|
1358 |
||
1359 |
TInt K::HandleClose(TInt aHandle) |
|
1360 |
{ |
|
1361 |
return TheCurrentThread->HandleClose(aHandle); |
|
1362 |
} |
|
1363 |
||
1364 |
TInt DThread::MakeHandle(TOwnerType aType, DObject* aObj, TInt& aHandle) |
|
1365 |
{ |
|
1366 |
TInt r=MakeHandleAndOpen(aType, aObj, aHandle); |
|
1367 |
if (r==KErrNone) |
|
1368 |
aObj->Close(NULL); // NULL to balance access count but leave attached to process |
|
1369 |
return r; |
|
1370 |
} |
|
1371 |
||
1372 |
TInt DThread::MakeHandle(TOwnerType aType, DObject* aObj, TInt& aHandle, TUint aAttr) |
|
1373 |
{ |
|
1374 |
TInt r=MakeHandleAndOpen(aType, aObj, aHandle, aAttr); |
|
1375 |
if (r==KErrNone) |
|
1376 |
aObj->Close(NULL); // NULL to balance access count but leave attached to process |
|
1377 |
return r; |
|
1378 |
} |
|
1379 |
||
1380 |
TInt DThread::MakeHandleAndOpen(TOwnerType aType, DObject* aObj, TInt& aHandle) |
|
1381 |
{ |
|
1382 |
return MakeHandleAndOpen(aType, aObj, aHandle, 0); |
|
1383 |
} |
|
1384 |
||
1385 |
TInt DThread::MakeHandleAndOpen(TOwnerType aType, DObject* aObj, TInt& aHandle, TUint aAttr) |
|
1386 |
{ |
|
1387 |
TInt r = aObj->Open(); |
|
1388 |
if (r==KErrNone) |
|
1389 |
{ |
|
1390 |
r = aObj->RequestUserHandle(this, aType, aAttr); |
|
1391 |
if (r==KErrNone) |
|
1392 |
{ |
|
1393 |
if (aType==EOwnerThread) |
|
1394 |
{ |
|
1395 |
__KTRACE_OPT(KEXEC,Kern::Printf("Making handle from thread %O to object %O", this, aObj)); |
|
1396 |
||
1397 |
r = iHandles.Add(aObj, aAttr); |
|
1398 |
if (r >= 0) |
|
1399 |
{ |
|
1400 |
aHandle = r | KHandleFlagLocal; |
|
1401 |
r = KErrNone; |
|
1402 |
} |
|
1403 |
} |
|
1404 |
else |
|
1405 |
{ |
|
1406 |
__KTRACE_OPT(KEXEC,Kern::Printf("Making handle from process %O to object %O", iOwningProcess, aObj)); |
|
1407 |
||
1408 |
r = iOwningProcess->iHandles.Add(aObj, aAttr); |
|
1409 |
if (r >= 0) |
|
1410 |
{ |
|
1411 |
aHandle = r; |
|
1412 |
r = KErrNone; |
|
1413 |
} |
|
1414 |
} |
|
1415 |
} |
|
1416 |
if (r==KErrNone) |
|
1417 |
{ |
|
1418 |
// It is assumed that: |
|
1419 |
// 1. AddToProcess() can only fail the first time the object is added to the process |
|
1420 |
// 2. Close(iOwningProcess) is equivalent to Close(NULL) if the object has not been |
|
1421 |
// added to the process. |
|
1422 |
r=aObj->AddToProcess(iOwningProcess, aAttr); |
|
1423 |
if (r!=KErrNone) |
|
1424 |
{ |
|
1425 |
// Add to process failed - try to remove handle |
|
1426 |
// If thread/process is exiting this might fail, but the handle will be closed |
|
1427 |
// by the exit handler. In either case this balances the Open() above. |
|
1428 |
HandleClose(aHandle); |
|
1429 |
aHandle=0; |
|
1430 |
} |
|
1431 |
} |
|
1432 |
else |
|
1433 |
aObj->Close(NULL); // NULL since we did not add to process |
|
1434 |
} |
|
1435 |
return r; |
|
1436 |
} |
|
1437 |
||
1438 |
/** |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1439 |
Makes a thread-owned handle to a kernel object and increments the access count |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1440 |
on the object. |
0 | 1441 |
|
1442 |
@param aThread The thread to own the handle. |
|
1443 |
If this is NULL, the current thread is used. |
|
1444 |
||
1445 |
@param aObject The object to which the handle will refer. |
|
1446 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1447 |
@return The created handle (a value >=0), if successful; |
0 | 1448 |
otherwise one of the other system wide error codes, (a value <0). |
1449 |
||
1450 |
@pre Calling thread must be in a critical section |
|
1451 |
@pre Interrupts must be enabled. |
|
1452 |
@pre Kernel must be unlocked. |
|
1453 |
@pre No fast mutex can be held. |
|
1454 |
@pre Call in a thread context. |
|
1455 |
@pre Can be used in a device driver. |
|
1456 |
*/ |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1457 |
|
0 | 1458 |
EXPORT_C TInt Kern::MakeHandleAndOpen(DThread* aThread, DObject* aObject) |
1459 |
{ |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1460 |
return MakeHandleAndOpen(aThread, aObject, EOwnerThread); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1461 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1462 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1463 |
/** |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1464 |
Makes a handle to a kernel object and increments the access count on the object. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1465 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1466 |
The handle can be owned by either a thread or a process. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1467 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1468 |
@param aThread The thread to own the handle, if the handle is to be owned by a |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1469 |
thread. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1470 |
A thread owned by the process to own the handle, if the handle |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1471 |
is to be owned by a process. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1472 |
If this is NULL, the current thread is used. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1473 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1474 |
@param aObject The object to which the handle will refer. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1475 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1476 |
@param aType An enumeration whose enumerators define the ownership of this |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1477 |
handle. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1478 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1479 |
@return The created handle (a value >=0), if successful; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1480 |
otherwise one of the other system wide error codes, (a value <0). |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1481 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1482 |
@pre Calling thread must be in a critical section |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1483 |
@pre Interrupts must be enabled. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1484 |
@pre Kernel must be unlocked. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1485 |
@pre No fast mutex can be held. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1486 |
@pre Call in a thread context. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1487 |
@pre Can be used in a device driver. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1488 |
*/ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1489 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1490 |
EXPORT_C TInt Kern::MakeHandleAndOpen(DThread* aThread, DObject* aObject, TOwnerType aType) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1491 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1492 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::MakeHandleAndOpen"); |
0 | 1493 |
if (!aThread) |
1494 |
aThread = TheCurrentThread; |
|
1495 |
TInt h; |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1496 |
TInt r = aThread->MakeHandleAndOpen(aType, aObject, h); |
0 | 1497 |
return (r == KErrNone) ? h : r; |
1498 |
} |
|
1499 |
||
1500 |
||
1501 |
TInt DThread::HandleClose(TInt aHandle) |
|
1502 |
{ |
|
1503 |
// Ignore attempts to close special or null handles |
|
1504 |
// or handles with the 'no close' bit set. |
|
1505 |
if (aHandle<=0 || (aHandle & KHandleNoClose)) |
|
1506 |
return KErrNone; |
|
1507 |
TInt r=KErrNone; |
|
1508 |
DObject* pO=NULL; |
|
1509 |
if (aHandle&KHandleFlagLocal) |
|
1510 |
{ |
|
1511 |
TUint32 attr; // Receives the attributes of the removed handle... |
|
1512 |
aHandle&=~KHandleFlagLocal; |
|
1513 |
r=iHandles.Remove(aHandle,pO,attr); |
|
1514 |
} |
|
1515 |
else |
|
1516 |
{ |
|
1517 |
TUint32 attr; // Receives the attributes of the removed handle... |
|
1518 |
r=iOwningProcess->iHandles.Remove(aHandle,pO,attr); |
|
1519 |
} |
|
1520 |
if (r==KErrNone) |
|
1521 |
r=pO->Close(iOwningProcess)&DObject::EObjectUnmapped; |
|
1522 |
return r; |
|
1523 |
} |
|
1524 |
||
1525 |
/** |
|
1526 |
Discard a handle to a kernel object and decrements the access count on the object. |
|
1527 |
||
1528 |
@param aThread The thread which owns the handle. If this is NULL, the current thread is used. |
|
1529 |
@param aObject The handle to close. |
|
1530 |
||
1531 |
@return KErrNone, if successful; otherwise one of the other system wide error codes. |
|
1532 |
||
1533 |
@pre Calling thread must be in a critical section |
|
1534 |
@pre Interrupts must be enabled. |
|
1535 |
@pre Kernel must be unlocked. |
|
1536 |
@pre No fast mutex can be held. |
|
1537 |
@pre Call in a thread context. |
|
1538 |
||
1539 |
*/ |
|
1540 |
EXPORT_C TInt Kern::CloseHandle(DThread* aThread, TInt aHandle) |
|
1541 |
{ |
|
1542 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CloseHandle"); |
|
1543 |
if (!aThread) |
|
1544 |
aThread = TheCurrentThread; |
|
1545 |
return aThread->HandleClose(aHandle); |
|
1546 |
} |
|
1547 |
||
1548 |
||
1549 |
TInt DThread::OpenFindHandle(TOwnerType aType, const TFindHandle& aFindHandle, TInt& aHandle) |
|
1550 |
{ |
|
1551 |
__KTRACE_OPT(KEXEC,Kern::Printf("DThread::OpenFindHandle")); |
|
1552 |
TInt r=KErrNone; |
|
1553 |
DObjectCon* pC=K::ContainerFromFindHandle(aFindHandle); |
|
1554 |
if (!pC) |
|
1555 |
return KErrBadHandle; |
|
1556 |
pC->Wait(); |
|
1557 |
DObject* pO=pC->At(aFindHandle); |
|
1558 |
if (pO) |
|
1559 |
r=pO->Open(); |
|
1560 |
pC->Signal(); |
|
1561 |
if (!pO) |
|
1562 |
return KErrNotFound; |
|
1563 |
if (r!=KErrNone) |
|
1564 |
return KErrBadHandle; |
|
1565 |
__KTRACE_OPT(KEXEC,Kern::Printf("Object %O found",pO)); |
|
1566 |
if ((pO->Protection()!=DObject::EGlobal) && (TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecProcessIsolation)) |
|
1567 |
{ |
|
1568 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1569 |
r = PlatSec::ProcessIsolationFail(__PLATSEC_DIAGNOSTIC_STRING("Checked by RHandleBase::Open(const TFindHandleBase)")); |
|
1570 |
#else //__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1571 |
r = PlatSec::EmitDiagnostic(); |
|
1572 |
#endif // !__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1573 |
} |
|
1574 |
if (r==KErrNone) |
|
1575 |
r=MakeHandle(aType,pO,aHandle); |
|
1576 |
if (r!=KErrNone) |
|
1577 |
pO->Close(NULL); |
|
1578 |
return r; |
|
1579 |
} |
|
1580 |
||
1581 |
TInt DThread::OpenObject(TOwnerType aType, const TDesC& aName, TInt& aHandle, DObject*& anObj, TInt aObjType) |
|
1582 |
{ |
|
1583 |
__KTRACE_OPT(KEXEC,Kern::Printf("DThread::OpenObject %lS",&aName)); |
|
1584 |
anObj=NULL; |
|
1585 |
TInt r=Kern::ValidateFullName(aName); |
|
1586 |
if (r!=KErrNone) |
|
1587 |
return r; |
|
1588 |
DObject* pO=NULL; |
|
1589 |
r=K::Containers[aObjType]->OpenByFullName(pO,aName); |
|
1590 |
if (r!=KErrNone) |
|
1591 |
return r; |
|
1592 |
__KTRACE_OPT(KEXEC,Kern::Printf("Object %O found", pO)); |
|
1593 |
anObj=pO; |
|
1594 |
r=MakeHandle(aType,pO,aHandle); |
|
1595 |
if (r!=KErrNone) |
|
1596 |
pO->Close(NULL); // NULL because chunk not added to process |
|
1597 |
return r; |
|
1598 |
} |
|
1599 |
||
1600 |
#ifndef __HANDLES_MACHINE_CODED__ |
|
1601 |
/** Translate a user handle relative to a specific thread. |
|
1602 |
||
1603 |
The handle may refer to type of kernel object. |
|
1604 |
||
1605 |
@param aHandle The handle to translate. |
|
1606 |
||
1607 |
@return A pointer to the kernel object to which the handle refers; |
|
1608 |
NULL if the handle is invalid. |
|
1609 |
||
1610 |
@pre System lock must be held. |
|
1611 |
*/ |
|
1612 |
EXPORT_C DObject* DThread::ObjectFromHandle(TInt aHandle) |
|
1613 |
{ |
|
1614 |
CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED,"DThread::ObjectFromHandle(TInt aHandle)"); |
|
1615 |
if (aHandle<0) |
|
1616 |
{ |
|
1617 |
aHandle &= ~KHandleNoClose; |
|
1618 |
if (aHandle==(KCurrentThreadHandle&~KHandleNoClose)) |
|
1619 |
return TheCurrentThread; |
|
1620 |
if (aHandle==(KCurrentProcessHandle&~KHandleNoClose)) |
|
1621 |
return TheCurrentThread->iOwningProcess; |
|
1622 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
1623 |
TUint32 h = aHandle; |
|
1624 |
if (h < 0x88000000u) |
|
1625 |
{ |
|
1626 |
h = (h & 0x00007FFFu) | ((h & 0x07FF0000u) >> 1); |
|
1627 |
h = TUint32(K::MsgInfo.iBase) + (h << 2); |
|
1628 |
RMessageK* m = RMessageK::MessageK(h, this); |
|
1629 |
if (!m || m->iFunction == RMessage2::EDisConnect) |
|
1630 |
return NULL; |
|
1631 |
return m->iClient; |
|
1632 |
} |
|
1633 |
#endif |
|
1634 |
return NULL; |
|
1635 |
} |
|
1636 |
DObject* pO=NULL; |
|
1637 |
if (aHandle&KHandleFlagLocal) |
|
1638 |
{ |
|
1639 |
pO=iHandles.At(aHandle&~KHandleFlagLocal); |
|
1640 |
} |
|
1641 |
else |
|
1642 |
{ |
|
1643 |
pO=iOwningProcess->iHandles.At(aHandle); |
|
1644 |
} |
|
1645 |
return pO; |
|
1646 |
} |
|
1647 |
||
1648 |
/** |
|
1649 |
Translates a user handle relative to a specific thread. |
|
1650 |
||
1651 |
The handle must refer to a specific type of kernel object. |
|
1652 |
||
1653 |
@param aHandle The handle to translate. |
|
1654 |
@param aType The type of kernel object to which the handle must refer. |
|
1655 |
This should be a member of the TObjectType enumeration. |
|
1656 |
||
1657 |
@return A pointer to the kernel object to which the handle refers. |
|
1658 |
NULL if the handle is invalid or refers to the wrong type of object. |
|
1659 |
||
1660 |
@pre System lock must be held. |
|
1661 |
*/ |
|
1662 |
EXPORT_C DObject* DThread::ObjectFromHandle(TInt aHandle, TInt aType) |
|
1663 |
{ |
|
1664 |
CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED,"DThread::ObjectFromHandle(TInt aHandle, TInt aType)"); |
|
1665 |
TUint attr = 0; |
|
1666 |
return ObjectFromHandle(aHandle, aType, attr); |
|
1667 |
} |
|
1668 |
||
1669 |
EXPORT_C DObject* DThread::ObjectFromHandle(TInt aHandle, TInt aType, TUint& aAttr) |
|
1670 |
{ |
|
1671 |
CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED,"DThread::ObjectFromHandle(TInt aHandle, TInt aType)"); |
|
1672 |
if (aHandle<0) |
|
1673 |
{ |
|
1674 |
aHandle &= ~KHandleNoClose; |
|
1675 |
if (aHandle==(KCurrentThreadHandle&~KHandleNoClose) && aType==EThread) |
|
1676 |
return TheCurrentThread; |
|
1677 |
if (aHandle==(KCurrentProcessHandle&~KHandleNoClose) && aType==EProcess) |
|
1678 |
return TheCurrentThread->iOwningProcess; |
|
1679 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
1680 |
TUint32 h = aHandle; |
|
1681 |
if (aType==EThread && h < 0x88000000u) |
|
1682 |
{ |
|
1683 |
h = (h & 0x00007FFFu) | ((h & 0x07FF0000u) >> 1); |
|
1684 |
h = TUint32(K::MsgInfo.iBase) + (h << 2); |
|
1685 |
RMessageK* m = RMessageK::MessageK(h, this); |
|
1686 |
if (!m || m->iFunction == RMessage2::EDisConnect) |
|
1687 |
return NULL; |
|
1688 |
return m->iClient; |
|
1689 |
} |
|
1690 |
#endif |
|
1691 |
return NULL; |
|
1692 |
} |
|
1693 |
DObject* pO=NULL; |
|
1694 |
||
1695 |
if (aHandle&KHandleFlagLocal) |
|
1696 |
{ |
|
1697 |
pO=iHandles.At(aHandle&~KHandleFlagLocal,aType+1, (TUint32*)&aAttr); |
|
1698 |
} |
|
1699 |
else |
|
1700 |
{ |
|
1701 |
pO=iOwningProcess->iHandles.At(aHandle,aType+1, (TUint32*)&aAttr); |
|
1702 |
} |
|
1703 |
return pO; |
|
1704 |
} |
|
1705 |
||
1706 |
DObject* K::ObjectFromHandle(TInt aHandle) |
|
1707 |
// |
|
1708 |
// Look up an object in the current thread/process handles array |
|
1709 |
// Panic on bad handle |
|
1710 |
// Enter and leave with system lock held |
|
1711 |
// |
|
1712 |
{ |
|
1713 |
DObject* pO=TheCurrentThread->ObjectFromHandle(aHandle); |
|
1714 |
if (!pO) |
|
1715 |
K::PanicCurrentThread(EBadHandle); |
|
1716 |
return pO; |
|
1717 |
} |
|
1718 |
||
1719 |
DObject* K::ObjectFromHandle(TInt aHandle, TInt aType) |
|
1720 |
// |
|
1721 |
// Look up an object of specific type in the current thread/process handles array |
|
1722 |
// Panic on bad handle |
|
1723 |
// Enter and leave with system lock held |
|
1724 |
// |
|
1725 |
{ |
|
1726 |
DObject* pO=TheCurrentThread->ObjectFromHandle(aHandle,aType); |
|
1727 |
if (!pO) |
|
1728 |
K::PanicCurrentThread(EBadHandle); |
|
1729 |
return pO; |
|
1730 |
} |
|
1731 |
||
1732 |
DObject* K::ObjectFromHandle(TInt aHandle, TInt aType, TUint& aAttr) |
|
1733 |
// |
|
1734 |
// Look up an object of specific type in the current thread/process handles array |
|
1735 |
// Panic on bad handle |
|
1736 |
// Enter and leave with system lock held |
|
1737 |
// |
|
1738 |
{ |
|
1739 |
DObject* pO=TheCurrentThread->ObjectFromHandle(aHandle,aType,aAttr); |
|
1740 |
if (!pO) |
|
1741 |
K::PanicCurrentThread(EBadHandle); |
|
1742 |
return pO; |
|
1743 |
} |
|
1744 |
||
1745 |
||
1746 |
||
1747 |
/** |
|
1748 |
Returns the kernel object that the given handle refers. |
|
1749 |
||
1750 |
The handle passed is looked up in the thread's handles collection if the handle is local or |
|
1751 |
in the thread's owner process' collection otherwise. If aHandle is negative or not found in |
|
1752 |
the thread's or process' collection then NULL is returned. |
|
1753 |
Two special handle values KCurrentThreadHandle and KCurrentProcessHandle can be used to get |
|
1754 |
a pointer to the current thread and the current process. |
|
1755 |
||
1756 |
aType is used to ensure that the object referred by the handle is of desired type. |
|
1757 |
If the type of the object referred by aHandle is different from aType then NULL is returned. |
|
1758 |
If aType is negative, the type of the object is ignored and no type checking is done. |
|
1759 |
If aType is positive and greater than the maximum number of object types (ENumObjectTypes) |
|
1760 |
the kernel will fault. |
|
1761 |
||
1762 |
@param aThread The thread that owns the handle passed. |
|
1763 |
@param aHandle Handle to the object to be returned. |
|
1764 |
@param aType TObjectType parameter specifying the type of the object referred by the handle. |
|
1765 |
||
1766 |
@return Pointer to the DObject referred by the handle or NULL if the handle is not |
|
1767 |
found in the thread's handles collection. |
|
1768 |
||
1769 |
@pre System must be locked |
|
1770 |
@pre Interrupts must be enabled. |
|
1771 |
@pre Kernel must be unlocked. |
|
1772 |
@pre Can be used in a device driver. |
|
1773 |
||
1774 |
@see TObjectType |
|
1775 |
@see DThread::ObjectFromHandle() |
|
1776 |
*/ |
|
1777 |
EXPORT_C DObject* Kern::ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType) |
|
1778 |
{ |
|
1779 |
CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED|MASK_KERNEL_UNLOCKED|MASK_INTERRUPTS_ENABLED, |
|
1780 |
"Kern::ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType)"); |
|
1781 |
if (aType>=0) |
|
1782 |
{ |
|
1783 |
if (aType<ENumObjectTypes) |
|
1784 |
return aThread->ObjectFromHandle(aHandle,aType); |
|
1785 |
K::Fault(K::EBadObjectType); |
|
1786 |
} |
|
1787 |
return aThread->ObjectFromHandle(aHandle); |
|
1788 |
} |
|
1789 |
||
1790 |
/** |
|
1791 |
Returns the kernel object that the given handle refers. |
|
1792 |
||
1793 |
The handle passed is looked up in the thread's handles collection if the handle is local or |
|
1794 |
in the thread's owner process' collection otherwise. If aHandle is negative or not found in |
|
1795 |
the thread's or process' collection then NULL is returned. |
|
1796 |
Two special handle values KCurrentThreadHandle and KCurrentProcessHandle can be used to get |
|
1797 |
a pointer to the current thread and the current process. |
|
1798 |
||
1799 |
aType is used to ensure that the object referred by the handle is of desired type. |
|
1800 |
If the type of the object referred by aHandle is different from aType then NULL is returned. |
|
1801 |
If aType is negative, the type of the object is ignored and no type checking is done. |
|
1802 |
If aType is positive and greater than the maximum number of object types (ENumObjectTypes) |
|
1803 |
the kernel will fault. |
|
1804 |
||
1805 |
@param aThread The thread that owns the handle passed. |
|
1806 |
@param aHandle Handle to the object to be returned. |
|
1807 |
@param aType TObjectType parameter specifying the type of the object referred by the handle. |
|
1808 |
@param aAttr Returns the attributes for this object. |
|
1809 |
||
1810 |
@return Pointer to the DObject referred by the handle or NULL if the handle is not |
|
1811 |
found in the thread's handles collection. |
|
1812 |
||
1813 |
@pre System must be locked |
|
1814 |
@pre Interrupts must be enabled. |
|
1815 |
@pre Kernel must be unlocked. |
|
1816 |
@pre Can be used in a device driver. |
|
1817 |
||
1818 |
@see TObjectType |
|
1819 |
@see DThread::ObjectFromHandle() |
|
1820 |
*/ |
|
1821 |
EXPORT_C DObject* Kern::ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType, TUint& aAttr) |
|
1822 |
{ |
|
1823 |
CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED|MASK_KERNEL_UNLOCKED|MASK_INTERRUPTS_ENABLED, |
|
1824 |
"Kern::ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType)"); |
|
1825 |
if (aType>=0) |
|
1826 |
{ |
|
1827 |
if (aType<ENumObjectTypes) |
|
1828 |
return aThread->ObjectFromHandle(aHandle,aType, aAttr); |
|
1829 |
K::Fault(K::EBadObjectType); |
|
1830 |
} |
|
1831 |
return aThread->ObjectFromHandle(aHandle, 0, aAttr); |
|
1832 |
} |
|
1833 |
#endif |
|
1834 |
||
1835 |
TInt K::OpenObjectFromHandle(TInt aHandle, DObject*& anObject) |
|
1836 |
// |
|
1837 |
// Look up a handle and open the object. |
|
1838 |
// Enter and return with no fast mutexes held. |
|
1839 |
// If successful, calling thread is placed into critical section. |
|
1840 |
// Return KErrBadHandle if handle bad, KErrNone if OK |
|
1841 |
// |
|
1842 |
{ |
|
1843 |
DThread& t=*TheCurrentThread; |
|
1844 |
TInt r=KErrBadHandle; |
|
1845 |
NKern::ThreadEnterCS(); |
|
1846 |
NKern::LockSystem(); |
|
1847 |
DObject* pO=t.ObjectFromHandle(aHandle); |
|
1848 |
if (pO) |
|
1849 |
r=pO->Open(); |
|
1850 |
NKern::UnlockSystem(); |
|
1851 |
if (r!=KErrNone) |
|
1852 |
{ |
|
1853 |
anObject=NULL; |
|
1854 |
NKern::ThreadLeaveCS(); |
|
1855 |
} |
|
1856 |
else |
|
1857 |
anObject=pO; |
|
1858 |
return r; |
|
1859 |
} |
|
1860 |
||
1861 |
||
1862 |
||
1863 |
||
1864 |
/** |
|
1865 |
Gets a pointer to the thread corresponding to the specified thread Id value. |
|
1866 |
||
1867 |
The caller must ensure that the returned DThread instance is not closed |
|
1868 |
asynchronously by another thread. |
|
1869 |
||
1870 |
@param aId The thread id. |
|
1871 |
||
1872 |
@return A pointer to the thread, or NULL if not found. |
|
1873 |
||
1874 |
@pre Calling thread must be in a critical section. |
|
1875 |
@pre Interrupts must be enabled. |
|
1876 |
@pre Kernel must be unlocked. |
|
1877 |
@pre Thread container mutex must be held. |
|
1878 |
@pre Call in a thread context. |
|
1879 |
@pre No fast mutex must be held |
|
1880 |
@pre Can be used in a device driver. |
|
1881 |
||
1882 |
@post Thread container mutex is held. |
|
1883 |
@post Calling thread is in a critical section. |
|
1884 |
*/ |
|
1885 |
EXPORT_C DThread* Kern::ThreadFromId(TUint aId) |
|
1886 |
{ |
|
1887 |
DObjectCon& threads=*K::Containers[EThread]; |
|
1888 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ThreadFromId"); |
|
1889 |
__ASSERT_WITH_MESSAGE_MUTEX(threads.Lock(),"Thread container mutex must be held","Kern::ThreadFromId"); |
|
1890 |
TInt c=threads.Count(); |
|
1891 |
TInt i; |
|
1892 |
for (i=0; i<c; i++) |
|
1893 |
{ |
|
1894 |
DThread* pT=(DThread*)threads[i]; |
|
1895 |
if (pT->iId==aId) |
|
1896 |
return pT; |
|
1897 |
} |
|
1898 |
return NULL; |
|
1899 |
} |
|
1900 |
||
1901 |
||
1902 |
||
1903 |
||
1904 |
/** |
|
1905 |
Gets a pointer to the process corresponding to the specified process Id value. |
|
1906 |
||
1907 |
The caller must ensure that the returned DProcess instance is not deleted |
|
1908 |
asynchronously by another thread. |
|
1909 |
||
1910 |
@param aId The process id. |
|
1911 |
@return A pointer to the process, or NULL if not found. |
|
1912 |
||
1913 |
@pre Calling thread must be in a critical section. |
|
1914 |
@pre Interrupts must be enabled. |
|
1915 |
@pre Kernel must be unlocked. |
|
1916 |
@pre Process container mutex must be held. |
|
1917 |
@pre Call in a thread context. |
|
1918 |
@pre No fast mutex must be held |
|
1919 |
@pre Can be used in a device driver. |
|
1920 |
||
1921 |
@post Process container mutex is held. |
|
1922 |
@post Calling thread is in a critical section. |
|
1923 |
*/ |
|
1924 |
EXPORT_C DProcess* Kern::ProcessFromId(TUint aId) |
|
1925 |
{ |
|
1926 |
DObjectCon& processes=*K::Containers[EProcess]; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1927 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ProcessFromId"); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1928 |
__ASSERT_WITH_MESSAGE_MUTEX(processes.Lock(),"Process container mutex must be held","Kern::ProcessFromId"); |
0 | 1929 |
//end of preconditions check |
1930 |
TInt c=processes.Count(); |
|
1931 |
TInt i; |
|
1932 |
for (i=0; i<c; i++) |
|
1933 |
{ |
|
1934 |
DProcess* pP=(DProcess*)processes[i]; |
|
1935 |
if (pP->iId==aId) |
|
1936 |
return pP; |
|
1937 |
} |
|
1938 |
return NULL; |
|
1939 |
} |
|
1940 |
||
1941 |
TBool K::IsInKernelHeap(const TAny* aPtr, TInt aSize) |
|
1942 |
// |
|
1943 |
// Check if an address range lies within the kernel heap chunk |
|
1944 |
// |
|
1945 |
{ |
|
1946 |
TLinAddr a=(TLinAddr)aPtr; |
|
1947 |
TLinAddr base=(TLinAddr)K::HeapInfo.iBase; |
|
1948 |
TInt max=K::HeapInfo.iMaxSize; |
|
1949 |
return (a>=base && TInt(a-base+aSize)<=max); |
|
1950 |
} |
|
1951 |
||
1952 |
GLDEF_C TInt CalcKernelHeapUsed() |
|
1953 |
{ |
|
1954 |
return ((RHeapK*)K::Allocator)->TotalAllocSize(); |
|
1955 |
} |
|
1956 |
||
1957 |
||
1958 |
||
1959 |
||
1960 |
/** |
|
1961 |
Copies data from a source descriptor in kernel memory, to a target descriptor |
|
1962 |
in user memory, in a way that enables forward and backward compatibility. |
|
1963 |
||
1964 |
If the length of the source data is longer that the maximum length of the |
|
1965 |
target descriptor then the number of bytes copied is limited to the maximum |
|
1966 |
length of the target descriptor. |
|
1967 |
||
1968 |
If the length of the source data is smaller that the maximum length of the |
|
1969 |
target descriptor then the target descriptor is padded with zeros. |
|
1970 |
||
1971 |
If the current thread is a user thread (i.e. if the mode in spsr_svc |
|
1972 |
is 'User'), then data is written using user mode privileges. |
|
1973 |
||
1974 |
@param aDestU The target descriptor in user memory. |
|
1975 |
@param aSrcK The source descriptor in kernel memory. |
|
1976 |
||
1977 |
@panic KERN-EXEC 33, if aDestU is not a writable descriptor type. |
|
1978 |
||
1979 |
@pre Do not call from User thread if in a critical section. |
|
1980 |
@pre Interrupts must be enabled. |
|
1981 |
@pre Kernel must be unlocked. |
|
1982 |
@pre No fast mutex can be held. |
|
1983 |
@pre Call in a thread context. |
|
1984 |
@pre Can be used in a device driver. |
|
1985 |
||
1986 |
@post The length of aDestU is equal to the number of bytes copied, excluding |
|
1987 |
any padding. |
|
1988 |
@post If aDestU is a TPtr type then its maximum length is equal its new length. |
|
1989 |
*/ |
|
1990 |
EXPORT_C void Kern::InfoCopy(TDes8& aDestU, const TDesC8& aSrcK) |
|
1991 |
{ |
|
1992 |
CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_THREAD_STANDARD,"Kern::InfoCopy(TDes8& aDestU, const TDesC8& aSrcK)"); |
|
1993 |
Kern::InfoCopy(aDestU,aSrcK.Ptr(),aSrcK.Length()); |
|
1994 |
} |
|
1995 |
||
1996 |
||
1997 |
||
1998 |
||
1999 |
/** |
|
2000 |
Copies data from kernel memory to a target descriptor in user memory, |
|
2001 |
in a way that enables forward and backward compatibility. |
|
2002 |
||
2003 |
If the length of the source data is longer that the maximum length of the |
|
2004 |
target descriptor then the number of bytes copied is limited to the maximum |
|
2005 |
length of the target descriptor. |
|
2006 |
||
2007 |
If the length of the source data is smaller that the maximum length of the |
|
2008 |
target descriptor then the target descriptor is padded with zeros. |
|
2009 |
||
2010 |
If the current thread is a user thread (i.e. if the mode in spsr_svc |
|
2011 |
is 'User'), then data is written using user mode privileges. |
|
2012 |
||
2013 |
@param aDestU The target descriptor in user memory. |
|
2014 |
@param aPtrK Address of the first byte of data to be copied in kernel memory. |
|
2015 |
@param aLengthK Length of data to be copied. |
|
2016 |
||
2017 |
@panic KERN-EXEC 33, the target descriptor is not writable. |
|
2018 |
||
2019 |
@pre Do not call from User thread if in a critical section. |
|
2020 |
@pre Interrupts must be enabled. |
|
2021 |
@pre Kernel must be unlocked. |
|
2022 |
@pre No fast mutex can be held. |
|
2023 |
@pre Call in a thread context. |
|
2024 |
@pre Can be used in a device driver. |
|
2025 |
||
2026 |
@post The length of aDestU is equal to the number of bytes copied, excluding |
|
2027 |
any padding. |
|
2028 |
@post If aDestU is a TPtr type then its maximum length is equal its new length. |
|
2029 |
*/ |
|
2030 |
EXPORT_C void Kern::InfoCopy(TDes8& aDestU, const TUint8* aPtrK, TInt aLengthK) |
|
2031 |
{ |
|
2032 |
CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_THREAD_STANDARD,"Kern::InfoCopy(TDes8& aDestU, const TUint8* aPtrK, TInt aLengthK)"); |
|
2033 |
TInt userLen; |
|
2034 |
TInt userMax; |
|
2035 |
TUint8* userPtr=(TUint8*)Kern::KUDesInfo(aDestU,userLen,userMax); |
|
2036 |
if (userMax<0) |
|
2037 |
K::PanicKernExec(EKUDesInfoInvalidType); |
|
2038 |
TInt copyLength=Min(aLengthK,userMax); |
|
2039 |
if (aLengthK<userMax) |
|
2040 |
kumemset(userPtr+aLengthK,0,userMax-aLengthK); |
|
2041 |
TPtrC8 kptr(aPtrK,copyLength); |
|
2042 |
Kern::KUDesPut(aDestU,kptr); |
|
2043 |
} |
|
2044 |
||
2045 |
||
2046 |
||
2047 |
||
2048 |
/** |
|
2049 |
Gets the power model. |
|
2050 |
||
2051 |
@return A pointer to the power model object. |
|
2052 |
||
2053 |
@pre Call in any context. |
|
2054 |
*/ |
|
2055 |
EXPORT_C DPowerModel* Kern::PowerModel() |
|
2056 |
{ |
|
2057 |
return K::PowerModel; |
|
2058 |
} |
|
2059 |
||
2060 |
||
2061 |
||
2062 |
||
2063 |
/** |
|
2064 |
Gets the status of the power supply. |
|
2065 |
||
2066 |
@return The status of the power supply. EGood, if there is no power model. |
|
2067 |
||
2068 |
@pre Calling thread can be either in a critical section or not. |
|
2069 |
@pre Interrupts must be enabled. |
|
2070 |
@pre Kernel must be unlocked. |
|
2071 |
@pre No fast mutex can be held. |
|
2072 |
@pre Call in a thread context. |
|
2073 |
@pre Can be used in a device driver. |
|
2074 |
*/ |
|
2075 |
EXPORT_C TSupplyStatus Kern::MachinePowerStatus() |
|
2076 |
{ |
|
2077 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::MachinePowerStatus"); |
|
2078 |
if(K::PowerModel) |
|
2079 |
return K::PowerModel->MachinePowerStatus(); |
|
2080 |
// If no power model... |
|
2081 |
return EGood; |
|
2082 |
} |
|
2083 |
||
2084 |
||
2085 |
||
2086 |
||
2087 |
/** |
|
2088 |
Changes the priority of the specified thread or the current thread. |
|
2089 |
||
2090 |
@param aPriority The new priority to be set. |
|
2091 |
@param aThread The thread that is to have its priority set. If NULL, the |
|
2092 |
thread is the current thread. |
|
2093 |
||
2094 |
@return KErrNone, if successful; KErrArgument, if the priority value is |
|
2095 |
negative or greater than or equal to KNumPriorities. |
|
2096 |
||
2097 |
@pre Calling thread can be either in a critical section or not. |
|
2098 |
@pre Interrupts must be enabled. |
|
2099 |
@pre Kernel must be unlocked. |
|
2100 |
@pre No fast mutex can be held. |
|
2101 |
@pre Call in a thread context. |
|
2102 |
@pre Can be used in a device driver. |
|
2103 |
||
2104 |
@see DThread::SetThreadPriority() |
|
2105 |
@see KNumPriorities |
|
2106 |
*/ |
|
2107 |
EXPORT_C TInt Kern::SetThreadPriority(TInt aPriority, DThread* aThread) |
|
2108 |
{ |
|
2109 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::SetThreadPriority"); |
|
2110 |
if (!aThread) |
|
2111 |
aThread=TheCurrentThread; |
|
2112 |
__KTRACE_OPT(KEXEC,Kern::Printf("Kern::SetThreadPriority %d %O",aPriority,aThread)); |
|
2113 |
if (aPriority<0 || aPriority>=KNumPriorities) |
|
2114 |
return KErrArgument; |
|
2115 |
NKern::LockSystem(); |
|
2116 |
aThread->SetThreadPriority(aPriority); |
|
2117 |
NKern::UnlockSystem(); |
|
2118 |
return KErrNone; |
|
2119 |
} |
|
2120 |
||
2121 |
||
2122 |
||
2123 |
||
2124 |
/** |
|
2125 |
Gets the device's superpage. |
|
2126 |
||
2127 |
@return A reference to the device's superpage. |
|
2128 |
||
2129 |
@pre Call in any context. |
|
2130 |
*/ |
|
2131 |
EXPORT_C TSuperPage& Kern::SuperPage() |
|
2132 |
{ |
|
2133 |
return *(TSuperPage*)SuperPageAddress; |
|
2134 |
} |
|
2135 |
||
2136 |
||
2137 |
||
2138 |
||
2139 |
/** |
|
2140 |
Gets the device's configuration information. |
|
2141 |
||
2142 |
@return A reference to the device configuration information. |
|
2143 |
||
2144 |
@pre Call in any context. |
|
2145 |
*/ |
|
2146 |
EXPORT_C TMachineConfig& Kern::MachineConfig() |
|
2147 |
{ |
|
2148 |
return *K::MachineConfig; |
|
2149 |
} |
|
2150 |
||
2151 |
||
2152 |
||
2153 |
||
2154 |
/** |
|
2155 |
Suspends execution of the specified thread. |
|
2156 |
||
2157 |
If the thread is running a critical section, suspension will be deferred until |
|
2158 |
it leaves the critical section. |
|
2159 |
||
2160 |
@param aThread The thread to be suspended. |
|
2161 |
@param aCount Specifies how many times this thread should be suspended. It |
|
2162 |
will require the same number of calls to ThreadResume() to undo |
|
2163 |
the result of this call to ThreadSuspend(). |
|
2164 |
||
2165 |
@pre Calling thread can be either in a critical section or not. |
|
2166 |
@pre Interrupts must be enabled. |
|
2167 |
@pre Kernel must be unlocked. |
|
2168 |
@pre No fast mutex can be held. |
|
2169 |
@pre Call in a thread context. |
|
2170 |
@pre Can be used in a device driver. |
|
2171 |
||
2172 |
@see DThread::Suspend() |
|
2173 |
*/ |
|
2174 |
EXPORT_C void Kern::ThreadSuspend(DThread& aThread, TInt aCount) |
|
2175 |
{ |
|
2176 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::ThreadSuspend"); |
|
2177 |
NKern::LockSystem(); |
|
2178 |
aThread.Suspend(aCount); |
|
2179 |
NKern::UnlockSystem(); |
|
2180 |
} |
|
2181 |
||
2182 |
||
2183 |
||
2184 |
||
2185 |
/** |
|
2186 |
Resumes execution of the specified thread. |
|
2187 |
||
2188 |
Calling Resume() does not mean that the thread becomes runnable. Instead it |
|
2189 |
increments the thread's suspend count. When the count reaches 0, the thread |
|
2190 |
is made runnable (in case it's not blocked). |
|
2191 |
||
2192 |
@param aThread The thread to be resumed. |
|
2193 |
||
2194 |
@pre Calling thread can be either in a critical section or not. |
|
2195 |
@pre Interrupts must be enabled. |
|
2196 |
@pre Kernel must be unlocked. |
|
2197 |
@pre No fast mutex can be held. |
|
2198 |
@pre Call in a thread context. |
|
2199 |
@pre Can be used in a device driver. |
|
2200 |
||
2201 |
@see DThread::Resume() |
|
2202 |
*/ |
|
2203 |
EXPORT_C void Kern::ThreadResume(DThread& aThread) |
|
2204 |
{ |
|
2205 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::ThreadResume"); |
|
2206 |
NKern::LockSystem(); |
|
2207 |
aThread.Resume(); |
|
2208 |
NKern::UnlockSystem(); |
|
2209 |
} |
|
2210 |
||
2211 |
||
2212 |
||
2213 |
||
2214 |
/** |
|
2215 |
Waits on the specified mutex. |
|
2216 |
||
2217 |
If the calling thread is a user thread, it must be in a critical section while |
|
2218 |
it holds the mutex to prevent deadlocks (thread suspended while holding mutex), inconsistent |
|
2219 |
states (thread killed while data protected by mutex in inconsistent state) |
|
2220 |
and resource leaks (thread killed before taking ownership of some |
|
2221 |
resource). |
|
2222 |
||
2223 |
@param aMutex Mutex to wait on. |
|
2224 |
||
2225 |
@return KErrNone, if successful, otherwise one of the other system-wide error |
|
2226 |
codes. |
|
2227 |
||
2228 |
@pre Calling thread must be in a critical section. |
|
2229 |
@pre Interrupts must be enabled. |
|
2230 |
@pre Kernel must be unlocked. |
|
2231 |
@pre No fast mutex can be held. |
|
2232 |
@pre Call in a thread context. |
|
2233 |
@pre Can be used in a device driver. |
|
2234 |
*/ |
|
2235 |
EXPORT_C TInt Kern::MutexWait(DMutex& aMutex) |
|
2236 |
{ |
|
2237 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::MutexWait"); |
|
2238 |
NKern::LockSystem(); |
|
2239 |
TInt r=aMutex.Wait(); |
|
2240 |
NKern::UnlockSystem(); |
|
2241 |
return r; |
|
2242 |
} |
|
2243 |
||
2244 |
||
2245 |
||
2246 |
||
2247 |
/** |
|
2248 |
Signals the specified mutex. |
|
2249 |
||
2250 |
If the calling thread is a user thread, it must be in a critical section. |
|
2251 |
||
2252 |
@param aMutex Mutex to signal |
|
2253 |
||
2254 |
@pre Calling thread must be in a critical section. |
|
2255 |
@pre Interrupts must be enabled. |
|
2256 |
@pre Kernel must be unlocked. |
|
2257 |
@pre No fast mutex can be held. |
|
2258 |
@pre Call in a thread context. |
|
2259 |
@pre Can be used in a device driver. |
|
2260 |
*/ |
|
2261 |
EXPORT_C void Kern::MutexSignal(DMutex& aMutex) |
|
2262 |
{ |
|
2263 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::MutexSignal"); |
|
2264 |
NKern::LockSystem(); |
|
2265 |
aMutex.Signal(); |
|
2266 |
} |
|
2267 |
||
2268 |
||
2269 |
||
2270 |
||
2271 |
/** |
|
2272 |
Creates a kernel mutex object with the specified name. |
|
2273 |
||
2274 |
On return, the kernel mutex object is not visible and has no owner. |
|
2275 |
||
2276 |
@param aMutex A reference to a DMutex pointer. |
|
2277 |
On successful return from this function, the pointer is set |
|
2278 |
to the address of the created DMutex object. |
|
2279 |
@param aName The name of the mutex. |
|
2280 |
@param aOrder A value representing the order of the mutex with respect to deadlock prevention. |
|
2281 |
||
2282 |
@pre Calling thread must be in a critical section. |
|
2283 |
@pre Interrupts must be enabled. |
|
2284 |
@pre Kernel must be unlocked. |
|
2285 |
@pre No fast mutex can be held. |
|
2286 |
@pre Call in a thread context. |
|
2287 |
@pre Can be used in a device driver. |
|
2288 |
||
2289 |
@post On successful return, aMutex contains a pointer to the newly created |
|
2290 |
DMutex object. |
|
2291 |
||
2292 |
@return KErrNone, if successful, otherwise one of the other system-wide |
|
2293 |
error codes. |
|
2294 |
*/ |
|
2295 |
EXPORT_C TInt Kern::MutexCreate(DMutex*& aMutex, const TDesC& aName, TUint aOrder) |
|
2296 |
{ |
|
2297 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::MutexCreate"); |
|
2298 |
return K::MutexCreate(aMutex, aName, NULL, EFalse, aOrder); |
|
2299 |
} |
|
2300 |
||
2301 |
||
2302 |
/** |
|
2303 |
Waits on the specified semaphore. |
|
2304 |
||
2305 |
@param aSem Semaphore to wait on |
|
2306 |
@param aNTicks Maximum number of nanokernel ticks to wait before timing out |
|
2307 |
the operation. Zero means wait forever. If this parameter is |
|
2308 |
not specified it defaults to 0. |
|
2309 |
||
2310 |
@return KErrNone, if successful; |
|
2311 |
KErrTimedOut, if the maximum wait time was exceeded before the |
|
2312 |
semaphore was signalled; |
|
2313 |
KErrGeneral, if the semaphore was deleted. |
|
2314 |
||
2315 |
@pre Interrupts must be enabled. |
|
2316 |
@pre Kernel must be unlocked. |
|
2317 |
@pre No fast mutex can be held. |
|
2318 |
@pre Call in a thread context. |
|
2319 |
@pre Can be used in a device driver. |
|
2320 |
*/ |
|
2321 |
EXPORT_C TInt Kern::SemaphoreWait(DSemaphore& aSem, TInt aNTicks) |
|
2322 |
{ |
|
2323 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::SemaphoreWait"); |
|
2324 |
NKern::LockSystem(); |
|
2325 |
return aSem.Wait(aNTicks); |
|
2326 |
} |
|
2327 |
||
2328 |
||
2329 |
||
2330 |
||
2331 |
/** |
|
2332 |
Signals the specified semaphore. |
|
2333 |
||
2334 |
@param aSem Semaphore to signal. |
|
2335 |
||
2336 |
@pre Interrupts must be enabled. |
|
2337 |
@pre Kernel must be unlocked. |
|
2338 |
@pre No fast mutex can be held. |
|
2339 |
@pre Call in a thread context. |
|
2340 |
@pre Can be used in a device driver. |
|
2341 |
*/ |
|
2342 |
EXPORT_C void Kern::SemaphoreSignal(DSemaphore& aSem) |
|
2343 |
{ |
|
2344 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::SemaphoreSignal"); |
|
2345 |
NKern::LockSystem(); |
|
2346 |
aSem.Signal(); |
|
2347 |
} |
|
2348 |
||
2349 |
||
2350 |
||
2351 |
/** |
|
2352 |
Creates a semaphore with the specified name. |
|
2353 |
||
2354 |
Note that, on return, the semaphore is not visible, and has no owner. |
|
2355 |
||
2356 |
@param aSem A reference to a pointer to a semaphore. |
|
2357 |
@param aName The name of the semaphore. |
|
2358 |
@param aInitialCount The count with which the semaphore should start. |
|
2359 |
||
2360 |
@pre Calling thread must be in a critical section. |
|
2361 |
@pre Interrupts must be enabled. |
|
2362 |
@pre Kernel must be unlocked. |
|
2363 |
@pre No fast mutex can be held. |
|
2364 |
@pre Call in a thread context. |
|
2365 |
@pre Can be used in a device driver. |
|
2366 |
||
2367 |
@post On successful return, aSem contains a pointer to the newly created |
|
2368 |
semaphore. |
|
2369 |
||
2370 |
@return KErrNone, if successful, otherwise one of the other system-wide |
|
2371 |
error codes. |
|
2372 |
*/ |
|
2373 |
EXPORT_C TInt Kern::SemaphoreCreate(DSemaphore*& aSem, const TDesC& aName, TInt aInitialCount) |
|
2374 |
{ |
|
2375 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::SemaphoreCreate"); |
|
2376 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Kern::SemaphoreCreate %lS init %d", &aName, aInitialCount)); |
|
2377 |
TInt r = KErrNoMemory; |
|
2378 |
DSemaphore* pS = new DSemaphore; |
|
2379 |
if (pS) |
|
2380 |
{ |
|
2381 |
r = pS->Create(NULL, &aName, aInitialCount, EFalse); |
|
2382 |
if (r==KErrNone) |
|
2383 |
aSem = pS; |
|
2384 |
else |
|
2385 |
pS->Close(NULL); |
|
2386 |
} |
|
2387 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Kern::SemaphoreCreate returns %d", r)); |
|
2388 |
return r; |
|
2389 |
} |
|
2390 |
||
2391 |
||
2392 |
||
2393 |
TUint K::CheckFreeMemoryLevel(TInt aInitial, TInt aFinal, TBool aFailed) |
|
2394 |
{ |
|
2395 |
NKern::LockSystem(); |
|
2396 |
TInt low=K::MemoryLowThreshold; |
|
2397 |
TInt good=K::MemoryGoodThreshold; |
|
2398 |
NKern::UnlockSystem(); |
|
2399 |
TUint changes=0; |
|
2400 |
if (aFinal<low && aInitial>=low) |
|
2401 |
changes |= (EChangesFreeMemory | EChangesLowMemory); |
|
2402 |
if (aFinal>=good && aInitial<good) |
|
2403 |
changes |= EChangesFreeMemory; |
|
2404 |
if (aFailed) |
|
2405 |
changes |= EChangesOutOfMemory; |
|
2406 |
if (changes) |
|
2407 |
{ |
|
2408 |
// asynchronously notify changes |
|
2409 |
Kern::AsyncNotifyChanges(changes); |
|
2410 |
} |
|
2411 |
return changes; |
|
2412 |
} |
|
2413 |
||
2414 |
||
2415 |
TBool K::CheckForSimulatedAllocFail() |
|
2416 |
{ |
|
2417 |
#ifdef _DEBUG |
|
2418 |
if(K::Allocator) |
|
2419 |
return ((RHeapK*)K::Allocator)->CheckForSimulatedAllocFail(); |
|
2420 |
#endif |
|
2421 |
return EFalse; |
|
2422 |
} |
|
2423 |
||
2424 |
||
2425 |
/** |
|
2426 |
Gets the current Symbian OS thread. |
|
2427 |
||
2428 |
Note that if this function is called from an ISR or an IDFC, then it returns |
|
2429 |
a reference to the interrupted thread. |
|
2430 |
Note also that this function assumes that the current thread is a Symbian OS |
|
2431 |
thread. The result will not be sensible if it is a raw nanokernel thread. |
|
2432 |
||
2433 |
@return A reference to the current thread. |
|
2434 |
||
2435 |
@pre Call in a thread context. |
|
2436 |
*/ |
|
2437 |
EXPORT_C DThread& Kern::CurrentThread() |
|
2438 |
{ |
|
2439 |
CHECK_PRECONDITIONS(MASK_NOT_ISR|MASK_NOT_IDFC,"Kern::CurrentThread()"); |
|
2440 |
return *TheCurrentThread; |
|
2441 |
} |
|
2442 |
||
2443 |
||
2444 |
||
2445 |
||
2446 |
/** |
|
2447 |
Gets the current process. |
|
2448 |
||
2449 |
The current process is that to which the current thread belongs. |
|
2450 |
||
2451 |
Note that if this function is called from an ISR or an IDFC, then the |
|
2452 |
associated thread is the interrupted thread. |
|
2453 |
Note also that this function assumes that the current thread is a Symbian OS |
|
2454 |
thread. The result will not be sensible if it is a raw nanokernel thread. |
|
2455 |
||
2456 |
@return A reference to the current process. |
|
2457 |
||
2458 |
@pre Call in a thread context. |
|
2459 |
||
2460 |
@see Kern::CurrentThread() |
|
2461 |
*/ |
|
2462 |
EXPORT_C DProcess& Kern::CurrentProcess() |
|
2463 |
{ |
|
2464 |
CHECK_PRECONDITIONS(MASK_NOT_ISR|MASK_NOT_IDFC,"Kern::CurrentProcess()"); |
|
2465 |
return *TheCurrentThread->iOwningProcess; |
|
2466 |
} |
|
2467 |
||
2468 |
||
2469 |
DThread* K::ThreadEnterCS() |
|
2470 |
{ |
|
2471 |
NKern::ThreadEnterCS(); |
|
2472 |
NKern::UnlockSystem(); |
|
2473 |
return TheCurrentThread; |
|
2474 |
} |
|
2475 |
||
2476 |
DThread* K::ThreadLeaveCS() |
|
2477 |
{ |
|
2478 |
NKern::LockSystem(); |
|
2479 |
NKern::ThreadLeaveCS(); |
|
2480 |
return TheCurrentThread; |
|
2481 |
} |
|
2482 |
||
2483 |
DObject* K::ThreadEnterCS(TInt aHandle, TInt aType) |
|
2484 |
// |
|
2485 |
// Enter a thread critical section, translate a handle and open the object |
|
2486 |
// Return a pointer to the object |
|
2487 |
// Enter with system locked, leave with system unlocked |
|
2488 |
// |
|
2489 |
{ |
|
2490 |
DObject* pO=NULL; |
|
2491 |
if (aType>=0) |
|
2492 |
pO=TheCurrentThread->ObjectFromHandle(aHandle,aType); |
|
2493 |
else |
|
2494 |
pO=TheCurrentThread->ObjectFromHandle(aHandle); |
|
2495 |
if (!pO || pO->Open()) |
|
2496 |
K::PanicCurrentThread(EBadHandle); |
|
2497 |
NKern::ThreadEnterCS(); |
|
2498 |
NKern::UnlockSystem(); |
|
2499 |
return pO; |
|
2500 |
} |
|
2501 |
||
2502 |
TUint32 K::KernelConfigFlags() |
|
2503 |
{ |
|
2504 |
TUint32 flags = TheSuperPage().KernelConfigFlags(); |
|
2505 |
if(TEST_DEBUG_MASK_BIT(KTESTLATENCY)) |
|
2506 |
flags &= ~EKernelConfigPlatSecDiagnostics; |
|
2507 |
||
2508 |
TBool codePagingSupported = K::MemModelAttributes & EMemModelAttrCodePaging; |
|
2509 |
if (!codePagingSupported) |
|
2510 |
flags = (flags & ~EKernelConfigCodePagingPolicyMask) | EKernelConfigCodePagingPolicyNoPaging; |
|
2511 |
||
2512 |
TBool dataPagingSupported = K::MemModelAttributes & EMemModelAttrDataPaging; |
|
2513 |
if (!dataPagingSupported) |
|
2514 |
flags = (flags & ~EKernelConfigDataPagingPolicyMask) | EKernelConfigDataPagingPolicyNoPaging; |
|
2515 |
||
2516 |
return flags; |
|
2517 |
} |
|
2518 |
||
2519 |
void signal_sem(TAny* aPtr) |
|
2520 |
{ |
|
2521 |
NKern::FSSignal((NFastSemaphore*)aPtr); |
|
2522 |
} |
|
2523 |
||
2524 |
TInt WaitForIdle(TInt aTimeoutMilliseconds) |
|
2525 |
{ |
|
2526 |
NFastSemaphore s(0); |
|
2527 |
TDfc idler(&signal_sem, &s, Kern::SvMsgQue(), 0); // supervisor thread, priority 0, so will run after destroyed DFC |
|
2528 |
NTimer timer(&signal_sem, &s); |
|
2529 |
idler.QueueOnIdle(); |
|
2530 |
timer.OneShot(NKern::TimerTicks(aTimeoutMilliseconds), ETrue); // runs in DFCThread1 |
|
2531 |
NKern::FSWait(&s); // wait for either idle DFC or timer |
|
2532 |
TBool timeout = idler.Cancel(); // cancel idler, return TRUE if it hadn't run |
|
2533 |
TBool tmc = timer.Cancel(); // cancel timer, return TRUE if it hadn't expired |
|
2534 |
if (!timeout && !tmc) |
|
2535 |
NKern::FSWait(&s); // both the DFC and the timer went off - wait for the second one |
|
2536 |
if (timeout) |
|
2537 |
return KErrTimedOut; |
|
2538 |
return KErrNone; |
|
2539 |
} |
|
2540 |
||
2541 |
TInt K::KernelHal(TInt aFunction, TAny* a1, TAny* /*a2*/) |
|
2542 |
{ |
|
2543 |
TInt r=KErrNone; |
|
2544 |
switch (aFunction) |
|
2545 |
{ |
|
2546 |
case EKernelHalMemoryInfo: |
|
2547 |
{ |
|
2548 |
TMemoryInfoV1Buf infoBuf; |
|
2549 |
TMemoryInfoV1& info=infoBuf(); |
|
2550 |
info.iTotalRamInBytes=TheSuperPage().iTotalRamSize; |
|
2551 |
info.iTotalRomInBytes=TheSuperPage().iTotalRomSize; |
|
2552 |
info.iMaxFreeRamInBytes=K::MaxFreeRam; |
|
2553 |
NKern::LockSystem(); |
|
2554 |
info.iFreeRamInBytes=Kern::FreeRamInBytes(); |
|
2555 |
info.iInternalDiskRamInBytes=TheSuperPage().iRamDriveSize; |
|
2556 |
NKern::UnlockSystem(); |
|
2557 |
info.iRomIsReprogrammable=ETrue; |
|
2558 |
Kern::InfoCopy(*(TDes8*)a1,infoBuf); |
|
2559 |
break; |
|
2560 |
} |
|
2561 |
/* Deprecated in 6.0 ?? |
|
2562 |
case EKernelHalRomInfo: |
|
2563 |
{ |
|
2564 |
TRomInfoV1Buf infoBuf; |
|
2565 |
TRomInfoV1& info=infoBuf(); |
|
2566 |
memcpy(&info,&TheSuperPage().iRomConfig[0],sizeof(TRomInfoV1)); |
|
2567 |
Kern::InfoCopy(*(TDes8*)a1,infoBuf); |
|
2568 |
break; |
|
2569 |
} |
|
2570 |
*/ |
|
2571 |
case EKernelHalStartupReason: |
|
2572 |
kumemput32(a1,&TheSuperPage().iStartupReason,sizeof(TMachineStartupType)); |
|
2573 |
break; |
|
2574 |
case EKernelHalFaultReason: |
|
2575 |
kumemput32(a1,&TheSuperPage().iKernelFault,sizeof(TInt)); |
|
2576 |
break; |
|
2577 |
case EKernelHalExceptionId: |
|
2578 |
kumemput32(a1,&TheSuperPage().iKernelExcId,sizeof(TInt)); |
|
2579 |
break; |
|
2580 |
case EKernelHalExceptionInfo: |
|
2581 |
kumemput32(a1,&TheSuperPage().iKernelExcInfo,sizeof(TExcInfo)); |
|
2582 |
break; |
|
2583 |
case EKernelHalCpuInfo: |
|
2584 |
r=KErrNotSupported; |
|
2585 |
break; |
|
2586 |
case EKernelHalPageSizeInBytes: |
|
2587 |
{ |
|
2588 |
TInt pageSize=M::PageSizeInBytes(); |
|
2589 |
kumemput32(a1,&pageSize,sizeof(TInt)); |
|
2590 |
break; |
|
2591 |
} |
|
2592 |
case EKernelHalTickPeriod: |
|
2593 |
{ |
|
2594 |
kumemput32(a1,&K::TickQ->iTickPeriod,sizeof(TInt)); |
|
2595 |
break; |
|
2596 |
} |
|
2597 |
case EKernelHalNTickPeriod: |
|
2598 |
{ |
|
2599 |
TInt period=NTickPeriod(); |
|
2600 |
kumemput32(a1,&period,sizeof(TInt)); |
|
2601 |
break; |
|
2602 |
} |
|
2603 |
case EKernelHalFastCounterFrequency: |
|
2604 |
{ |
|
2605 |
TInt freq=NKern::FastCounterFrequency(); |
|
2606 |
kumemput32(a1,&freq,sizeof(TInt)); |
|
2607 |
break; |
|
2608 |
} |
|
2609 |
case EKernelHalMemModelInfo: |
|
2610 |
r=(TInt)K::MemModelAttributes; |
|
2611 |
break; |
|
2612 |
case EKernelHalHardwareFloatingPoint: |
|
2613 |
TUint32 types; |
|
2614 |
r=K::FloatingPointTypes(types); |
|
2615 |
kumemput32(a1,&types,sizeof(TUint32)); |
|
2616 |
break; |
|
2617 |
||
2618 |
case EKernelHalGetNonsecureClockOffset: |
|
2619 |
kumemput32(a1, &K::NonSecureOffsetSeconds, sizeof(K::NonSecureOffsetSeconds)); |
|
2620 |
break; |
|
2621 |
case EKernelHalSetNonsecureClockOffset: |
|
2622 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by KernelHal function"))) |
|
2623 |
r=KErrPermissionDenied; |
|
2624 |
else |
|
2625 |
{ |
|
2626 |
// Only allow the nonsecure offset to be set *once* (i.e. by halsettings.exe during startup). |
|
2627 |
// Subsequent updates to this value are of course done through setting the |
|
2628 |
// nonsecure system time. |
|
2629 |
if (K::SecureClockStatus & ESecureClockOffsetPresent) |
|
2630 |
r = KErrGeneral; |
|
2631 |
else |
|
2632 |
{ |
|
2633 |
// Update the nonsecure offset not by writing it directly, but by using the |
|
2634 |
// time-setting API. This will also cause the software clock to be updated |
|
2635 |
// with the offset, while leaving the hardware clock untouched. |
|
2636 |
TTimeK t = Kern::SystemTime(); |
|
2637 |
K::SecureClockStatus |= ESecureClockOffsetPresent; |
|
2638 |
TInt64 offset = (TInt)a1; |
|
2639 |
offset *= 1000000; |
|
2640 |
t += offset; |
|
2641 |
NKern::ThreadEnterCS(); |
|
2642 |
Kern::SetSystemTime(t, 0); |
|
2643 |
NKern::ThreadLeaveCS(); |
|
2644 |
} |
|
2645 |
} |
|
2646 |
break; |
|
2647 |
#ifdef __SMP__ |
|
2648 |
case EKernelHalSmpSupported: |
|
2649 |
r = KErrNone; |
|
2650 |
break; |
|
2651 |
#endif |
|
2652 |
case EKernelHalNumLogicalCpus: |
|
2653 |
#ifdef __SMP__ |
|
2654 |
r = NKern::NumberOfCpus(); |
|
2655 |
#else |
|
2656 |
r = 1; |
|
2657 |
#endif |
|
2658 |
break; |
|
2659 |
case EKernelHalSupervisorBarrier: |
|
2660 |
{ |
|
2661 |
NKern::ThreadEnterCS(); |
|
2662 |
r = KErrNone; |
|
2663 |
TInt timeout = (TInt)a1; |
|
2664 |
if (timeout>0) |
|
2665 |
{ |
|
2666 |
r = WaitForIdle(timeout); |
|
2667 |
} |
|
2668 |
if (r==KErrNone) |
|
2669 |
{ |
|
2670 |
TMessageBase& m=Kern::Message(); |
|
2671 |
m.SendReceive(&K::SvBarrierQ); |
|
2672 |
} |
|
2673 |
NKern::ThreadLeaveCS(); |
|
2674 |
break; |
|
2675 |
} |
|
2676 |
case EKernelHalFloatingPointSystemId: |
|
2677 |
TUint32 sysid; |
|
2678 |
r=K::FloatingPointSystemId(sysid); |
|
2679 |
kumemput32(a1,&sysid,sizeof(TUint32)); |
|
2680 |
break; |
|
2681 |
||
2682 |
case EKernelHalLockThreadToCpu: |
|
2683 |
{ |
|
2684 |
#ifdef __SMP__ |
|
2685 |
TUint32 cpuId = (TUint32)a1; |
|
2686 |
if (cpuId < (TUint32)NKern::NumberOfCpus()) |
|
2687 |
{ |
|
2688 |
NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), cpuId); |
|
2689 |
r = KErrNone; |
|
2690 |
} |
|
2691 |
else |
|
2692 |
{ |
|
2693 |
r = KErrArgument; |
|
2694 |
} |
|
2695 |
#else |
|
2696 |
r = KErrNone; |
|
2697 |
#endif |
|
2698 |
break; |
|
2699 |
} |
|
2700 |
||
2701 |
case EKernelHalConfigFlags: |
|
2702 |
// return bottom 31 bits of config flags so as not to signal an error |
|
2703 |
r=K::KernelConfigFlags() & 0x7fffffff; |
|
2704 |
break; |
|
2705 |
||
2706 |
default: |
|
2707 |
r=KErrNotSupported; |
|
2708 |
break; |
|
2709 |
} |
|
2710 |
return r; |
|
2711 |
} |
|
2712 |
||
2713 |
void K::CheckKernelUnlocked() |
|
2714 |
{ |
|
2715 |
if (NKern::KernelLocked() || NKern::HeldFastMutex()) |
|
2716 |
K::Fault(K::EPanicWhileKernelLocked); |
|
2717 |
} |
|
2718 |
||
2719 |
void K::CheckFileServerAccess() |
|
2720 |
{ |
|
2721 |
DProcess* pP=&Kern::CurrentProcess(); |
|
2722 |
if (pP!=K::TheKernelProcess && pP!=K::TheFileServerProcess) |
|
2723 |
K::PanicKernExec(EAccessDenied); |
|
2724 |
} |
|
2725 |
||
2726 |
void K::SetMachineConfiguration(const TDesC8& aConfig) |
|
2727 |
// |
|
2728 |
// Set the platform dependant machine configuration. |
|
2729 |
// NOTE: We assume the machine configuration is small enough |
|
2730 |
// that it can be copied with the kernel locked without adversely |
|
2731 |
// affecting real-time performance. On EIGER this means about 2K. |
|
2732 |
// LATER: This 2K has been reduced to 512 bytes, which could be getting a bit tight here. |
|
2733 |
// |
|
2734 |
{ |
|
2735 |
TPtr8 c(A::MachineConfiguration()); |
|
2736 |
NKern::LockSystem(); |
|
2737 |
c=aConfig; |
|
2738 |
NKern::UnlockSystem(); |
|
2739 |
} |
|
2740 |
||
2741 |
||
2742 |
||
2743 |
||
2744 |
/** |
|
2745 |
Initialises a new DFC queue. |
|
2746 |
||
2747 |
The function creates and starts a kernel thread to process the supplied DFC |
|
2748 |
queue. On successful completion, the queue is ready to start processing DFCs. |
|
2749 |
||
2750 |
The thread created for the queue will have its real time state enabled. If |
|
2751 |
this is not the desired behaviour then TDynamicDfcQue::SetRealtimeState() can |
|
2752 |
be used to disable the real time state of the thread. |
|
2753 |
||
2754 |
@param aDfcQ A pointer to the DFC queue to be initialised. |
|
2755 |
@param aPriority The thread priority for the queue. |
|
2756 |
@param aName A pointer to a descriptor containing the name for the queue |
|
2757 |
thread. If NULL (the default), a uniqiue name of the form |
|
2758 |
'DfcThreadNNN' is generated for the queue, where NNN |
|
2759 |
represents three numeric characters. |
|
2760 |
||
2761 |
@return KErrNone, if successful, otherwise one of the other system-wide |
|
2762 |
error codes. |
|
2763 |
||
2764 |
@pre Calling thread must be in a critical section. |
|
2765 |
@pre Interrupts must be enabled. |
|
2766 |
@pre Kernel must be unlocked. |
|
2767 |
@pre No fast mutex can be held. |
|
2768 |
@pre Call in a thread context. |
|
2769 |
@pre Can be used in a device driver. |
|
2770 |
||
2771 |
@see Kern::DfcQCreate() |
|
2772 |
@see TDynamicDfcQue::SetRealtimeState() |
|
2773 |
*/ |
|
2774 |
EXPORT_C TInt Kern::DfcQInit(TDfcQue* aDfcQ, TInt aPriority, const TDesC* aName) |
|
2775 |
{ |
|
2776 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DfcQInit"); |
|
2777 |
__KTRACE_OPT(KDFC,Kern::Printf("Kern::DfcQInit %d at %08x",aPriority,aDfcQ)); |
|
2778 |
SThreadCreateInfo info; |
|
2779 |
info.iType=EThreadSupervisor; |
|
2780 |
info.iFunction=(TThreadFunction)TDfcQue::ThreadFunction; |
|
2781 |
info.iPtr=aDfcQ; |
|
2782 |
info.iSupervisorStack=NULL; |
|
2783 |
info.iSupervisorStackSize=0; // zero means use default value |
|
2784 |
info.iInitialThreadPriority=aPriority; |
|
2785 |
if (aName) |
|
2786 |
info.iName.Set(*aName); |
|
2787 |
else |
|
2788 |
{ |
|
2789 |
TBuf<16> n(KLitDfcThread()); |
|
2790 |
n.AppendNum((TInt)__e32_atomic_add_ord32(&K::DfcQId, 1)); |
|
2791 |
info.iName.Set(n); |
|
2792 |
} |
|
2793 |
info.iTotalSize = sizeof(info); |
|
2794 |
TInt r=Kern::ThreadCreate(info); |
|
2795 |
if (r==KErrNone) |
|
2796 |
{ |
|
2797 |
DThread* pT=(DThread*)info.iHandle; |
|
2798 |
__KTRACE_OPT(KDFC,Kern::Printf("TDfcQue thread %O at %08x",pT,pT)); |
|
2799 |
aDfcQ->iThread=&pT->iNThread; |
|
2800 |
#ifndef __DFC_THREADS_NOT_REALTIME |
|
2801 |
// Dfc threads are real time by default when data paging is enabled. |
|
2802 |
TUint dataPolicy = TheSuperPage().KernelConfigFlags() & EKernelConfigDataPagingPolicyMask; |
|
2803 |
if (dataPolicy != EKernelConfigDataPagingPolicyNoPaging) |
|
2804 |
pT->SetRealtimeState(ERealtimeStateOn); |
|
2805 |
#endif |
|
2806 |
Kern::ThreadResume(*pT); |
|
2807 |
} |
|
2808 |
return r; |
|
2809 |
} |
|
2810 |
||
2811 |
||
2812 |
||
2813 |
||
2814 |
/** |
|
2815 |
Performs a polling operation at specified regular intervals, for a specified |
|
2816 |
maximum number of attempts. |
|
2817 |
||
2818 |
The polling operation is performed by the specified function. The function is |
|
2819 |
called repeatedly at each interval until it either returns true, or the maximum |
|
2820 |
number of attempts has been reached. |
|
2821 |
||
2822 |
@param aFunction The function implementing the polling operation. |
|
2823 |
@param aPtr An argument passed to the polling function. |
|
2824 |
@param aPollPeriodMs The interval between successive attempts at calling the |
|
2825 |
polling function, in milliseconds. Note that the the time |
|
2826 |
period is converted into ticks, and may be rounded up to |
|
2827 |
give an integral number of ticks. |
|
2828 |
@param aMaxPoll The maximum number of attempts at calling the polling |
|
2829 |
function before timing out. |
|
2830 |
||
2831 |
@return KErrNone, if the polling function returns true; |
|
2832 |
KErrBadPower, if the device's power status is no longer good; |
|
2833 |
KErrTimedOut, if the maximum number of attempts has been reached. |
|
2834 |
||
2835 |
@pre Interrupts must be enabled. |
|
2836 |
@pre Kernel must be unlocked. |
|
2837 |
@pre No fast mutex can be held. |
|
2838 |
@pre Call in a thread context. |
|
2839 |
@pre Can be used in a device driver. |
|
2840 |
*/ |
|
2841 |
EXPORT_C TInt Kern::PollingWait(TPollFunction aFunction, TAny* aPtr, TInt aPollPeriodMs, TInt aMaxPoll) |
|
2842 |
{ |
|
2843 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::PollingWait"); |
|
2844 |
TInt ticks=NKern::TimerTicks(aPollPeriodMs); |
|
2845 |
FOREVER |
|
2846 |
{ |
|
2847 |
if ((*aFunction)(aPtr)) |
|
2848 |
return KErrNone; |
|
2849 |
if (!Kern::PowerGood()) |
|
2850 |
return KErrBadPower; |
|
2851 |
if (--aMaxPoll==0) |
|
2852 |
return KErrTimedOut; |
|
2853 |
NKern::Sleep(ticks); |
|
2854 |
} |
|
2855 |
} |
|
2856 |
||
2857 |
TUint32 K::CompressKHeapPtr(const TAny* aPtr) |
|
2858 |
{ |
|
2859 |
TUint32 r=(TUint32(aPtr)-TUint32(K::HeapInfo.iBase))>>2; |
|
2860 |
__ASSERT_DEBUG(r<(1u<<26),K::Fault(K::EInvalidKernHeapCPtr)); |
|
2861 |
return r; |
|
2862 |
} |
|
2863 |
||
2864 |
const TAny* K::RestoreKHeapPtr(TUint32 aCPtr) |
|
2865 |
{ |
|
2866 |
__ASSERT_DEBUG(aCPtr<(1u<<26),K::Fault(K::EInvalidKernHeapCPtr)); |
|
2867 |
return (const TAny*)(TUint32(K::HeapInfo.iBase)+(aCPtr<<2)); |
|
2868 |
} |
|
2869 |
||
2870 |
TUint K::NewId() |
|
2871 |
{ |
|
2872 |
TUint id = __e32_atomic_add_ord32(&K::NextId, 1); |
|
2873 |
if(id==~0u) |
|
2874 |
K::Fault(K::EOutOfIds); |
|
2875 |
return id; |
|
2876 |
} |
|
2877 |
||
2878 |
/** |
|
2879 |
@pre No fast mutex can be held. |
|
2880 |
@pre Call in a thread context. |
|
2881 |
@pre Kernel must be unlocked |
|
2882 |
@pre interrupts enabled |
|
2883 |
*/ |
|
2884 |
EXPORT_C void Kern::CodeSegGetMemoryInfo(DCodeSeg& aCodeSeg, TModuleMemoryInfo& aInfo, DProcess* aProcess) |
|
2885 |
{ |
|
2886 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::CodeSegGetMemoryInfo"); |
|
2887 |
aCodeSeg.GetMemoryInfo(aInfo, aProcess); |
|
2888 |
} |
|
2889 |
||
2890 |
/** |
|
2891 |
Discovers the DThread associated with an NThread. |
|
2892 |
||
2893 |
@param aNThread The NThread who's counterpart DThread is to be found. |
|
2894 |
||
2895 |
@return A DThread or NULL if there is no counterpart DThread. |
|
2896 |
*/ |
|
2897 |
EXPORT_C DThread* Kern::NThreadToDThread(NThread* aNThread) |
|
2898 |
{ |
|
2899 |
if (aNThread && aNThread->iHandlers==&EpocThreadHandlers) |
|
2900 |
return _LOFF(aNThread,DThread, iNThread); |
|
2901 |
else |
|
2902 |
return NULL; |
|
2903 |
} |
|
2904 |
||
2905 |
EXPORT_C TKernelHookFn Kern::SetHook(TKernelHookType aType, TKernelHookFn aFunction, TBool aOveride /*=EFalse*/) |
|
2906 |
{ |
|
2907 |
if((TUint)aType>=ENumKernelHooks) |
|
2908 |
K::Fault(K::EBadKernelHookType); |
|
2909 |
TKernelHookFn oldFn = (TKernelHookFn)__e32_atomic_swp_ord_ptr(&K::KernelHooks[aType], aFunction); |
|
2910 |
if(oldFn && !aOveride) |
|
2911 |
K::Fault(K::EKernelHookAlreadySet); |
|
2912 |
return oldFn; |
|
2913 |
} |
|
2914 |
||
2915 |
/** |
|
2916 |
Wait for a length of time specified in nanoseconds. |
|
2917 |
||
2918 |
This function is typically implemented using a busy-wait, so should only be |
|
2919 |
called to wait for short periods. |
|
2920 |
||
2921 |
@param aInterval The length of time to wait in nanoseconds. |
|
2922 |
*/ |
|
2923 |
EXPORT_C void Kern::NanoWait(TUint32 aInterval) |
|
2924 |
{ |
|
2925 |
K::NanoWaitHandler()(aInterval); |
|
2926 |
} |
|
2927 |
||
2928 |
extern "C" void nanowait(TUint32 aInterval) |
|
2929 |
{ |
|
2930 |
Kern::NanoWait(aInterval); |
|
2931 |
} |
|
2932 |
||
2933 |
||
2934 |
/** |
|
2935 |
Checks of kernel preconditions. |
|
2936 |
If some precondition is not met and the appropriate macro is defined, this function will print information about broken precondition |
|
2937 |
to debug output and fault the system |
|
2938 |
||
2939 |
@param aConditionMask 32-bit bitmask specifying which particular preconditions should be checked |
|
2940 |
@param aFunction Title of the calling function |
|
2941 |
*/ |
|
2942 |
#ifdef _DEBUG |
|
2943 |
#if (defined (__KERNEL_APIS_CONTEXT_CHECKS_WARNING__)||defined (__KERNEL_APIS_CONTEXT_CHECKS_FAULT__)) |
|
2944 |
extern "C" TInt CheckPreconditions(TUint32 aConditionMask, const char* aFunction, TLinAddr aAddr) |
|
2945 |
{ |
|
2946 |
if (K::Initialising || NKern::Crashed()) |
|
2947 |
return KErrNone; |
|
2948 |
||
2949 |
TUint32 m = aConditionMask; |
|
2950 |
NThread* nt = 0; |
|
2951 |
DThread* t = 0; |
|
2952 |
NKern::TContext ctx = (NKern::TContext)NKern::CurrentContext(); |
|
2953 |
if (ctx == NKern::EThread) |
|
2954 |
{ |
|
2955 |
nt = NKern::CurrentThread(); |
|
2956 |
t = Kern::NThreadToDThread(nt); |
|
2957 |
} |
|
2958 |
if (m & MASK_NO_FAST_MUTEX) |
|
2959 |
{ |
|
2960 |
if (!nt || !NKern::HeldFastMutex()) |
|
2961 |
m &= ~MASK_NO_FAST_MUTEX; |
|
2962 |
} |
|
2963 |
if (m & MASK_NO_CRITICAL) |
|
2964 |
{ |
|
2965 |
if (t && t->iThreadType==EThreadUser && nt->iCsCount==0) |
|
2966 |
m &= ~MASK_NO_CRITICAL; |
|
2967 |
else if (!nt || nt->iCsCount==0) |
|
2968 |
m &= ~MASK_NO_CRITICAL; |
|
2969 |
} |
|
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2970 |
if (m & (MASK_CRITICAL|MASK_NO_KILL_OR_SUSPEND)) |
0 | 2971 |
{ |
2972 |
if (t && (t->iThreadType!=EThreadUser || nt->iCsCount>0)) |
|
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2973 |
m &= ~(MASK_CRITICAL|MASK_NO_KILL_OR_SUSPEND); |
0 | 2974 |
else if (!nt || nt->iCsCount>0) |
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2975 |
m &= ~(MASK_CRITICAL|MASK_NO_KILL_OR_SUSPEND); |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2976 |
} |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2977 |
if (m & MASK_NO_KILL_OR_SUSPEND) |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2978 |
{ |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2979 |
if (!nt || NKern::KernelLocked() || NKern::HeldFastMutex()) |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
2980 |
m &= ~MASK_NO_KILL_OR_SUSPEND; |
0 | 2981 |
} |
2982 |
if (m & MASK_KERNEL_LOCKED) |
|
2983 |
{ |
|
2984 |
if (NKern::KernelLocked()) |
|
2985 |
m &= ~MASK_KERNEL_LOCKED; |
|
2986 |
} |
|
2987 |
if (m & MASK_KERNEL_UNLOCKED) |
|
2988 |
{ |
|
2989 |
if (!NKern::KernelLocked()) |
|
2990 |
m &= ~MASK_KERNEL_UNLOCKED; |
|
2991 |
} |
|
2992 |
if (m & MASK_KERNEL_LOCKED_ONCE) |
|
2993 |
{ |
|
2994 |
if (NKern::KernelLocked(1)) |
|
2995 |
m &= ~MASK_KERNEL_LOCKED_ONCE; |
|
2996 |
} |
|
2997 |
if (m & MASK_INTERRUPTS_ENABLED) |
|
2998 |
{ |
|
2999 |
if (InterruptsStatus(ETrue)) |
|
3000 |
m &= ~MASK_INTERRUPTS_ENABLED; |
|
3001 |
} |
|
3002 |
if (m & MASK_INTERRUPTS_DISABLED) |
|
3003 |
{ |
|
3004 |
if (InterruptsStatus(EFalse)) |
|
3005 |
m &= ~MASK_INTERRUPTS_DISABLED; |
|
3006 |
} |
|
3007 |
if (m & MASK_SYSTEM_LOCKED) |
|
3008 |
{ |
|
3009 |
if (TheScheduler.iLock.HeldByCurrentThread()) |
|
3010 |
m &= ~MASK_SYSTEM_LOCKED; |
|
3011 |
} |
|
3012 |
if (m & MASK_NOT_THREAD) |
|
3013 |
{ |
|
3014 |
if (ctx!=NKern::EThread) |
|
3015 |
m &= ~MASK_NOT_THREAD; |
|
3016 |
} |
|
3017 |
if (m & MASK_NOT_ISR) |
|
3018 |
{ |
|
3019 |
if (ctx!=NKern::EInterrupt) |
|
3020 |
m &= ~MASK_NOT_ISR; |
|
3021 |
} |
|
3022 |
if (m & MASK_NOT_IDFC) |
|
3023 |
{ |
|
3024 |
if (ctx!=NKern::EIDFC) |
|
3025 |
m &= ~MASK_NOT_IDFC; |
|
3026 |
} |
|
3027 |
if (m & MASK_NO_CRITICAL_IF_USER) |
|
3028 |
{ |
|
3029 |
if (t && (t->iThreadType!=EThreadUser || nt->iCsCount==0)) |
|
3030 |
m &= ~MASK_NO_CRITICAL_IF_USER; |
|
3031 |
else if (!nt || nt->iCsCount==0) |
|
3032 |
m &= ~MASK_NO_CRITICAL_IF_USER; |
|
3033 |
} |
|
3034 |
if (m & MASK_NO_RESCHED) |
|
3035 |
{ |
|
3036 |
if (!nt || NKern::KernelLocked()) |
|
3037 |
m &= ~MASK_NO_RESCHED; |
|
3038 |
} |
|
3039 |
if (!m) |
|
3040 |
return KErrNone; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3041 |
if (aFunction && aAddr) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3042 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3043 |
Kern::Printf("In function %s called from %08x :-", aFunction, aAddr); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3044 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3045 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3046 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3047 |
if (aFunction) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3048 |
Kern::Printf("In function %s :-", aFunction); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3049 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3050 |
Kern::Printf("At address %08x :-", aAddr); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3051 |
} |
0 | 3052 |
if (m & MASK_NO_FAST_MUTEX) |
3053 |
Kern::Printf("Assertion failed: No fast mutex must be held"); |
|
3054 |
if (m & MASK_NO_CRITICAL) |
|
3055 |
Kern::Printf("Assertion failed: Calling thread must not be in critical section"); |
|
3056 |
if (m & MASK_CRITICAL) |
|
3057 |
Kern::Printf("Assertion failed: Calling thread must be in critical section"); |
|
3058 |
if (m & MASK_KERNEL_LOCKED) |
|
3059 |
Kern::Printf("Assertion failed: Kernel must be locked"); |
|
3060 |
if (m & MASK_KERNEL_UNLOCKED) |
|
3061 |
Kern::Printf("Assertion failed: Kernel must not be locked"); |
|
3062 |
if (m & MASK_KERNEL_LOCKED_ONCE) |
|
3063 |
Kern::Printf("Assertion failed: Kernel must be locked exactly once"); |
|
3064 |
if (m & MASK_INTERRUPTS_ENABLED) |
|
3065 |
Kern::Printf("Assertion failed: Interrupts must be enabled"); |
|
3066 |
if (m & MASK_INTERRUPTS_DISABLED) |
|
3067 |
Kern::Printf("Assertion failed: Interrupts must be disabled"); |
|
3068 |
if (m & MASK_SYSTEM_LOCKED) |
|
3069 |
Kern::Printf("Assertion failed: System lock must be held"); |
|
3070 |
if (m & MASK_NOT_THREAD) |
|
3071 |
Kern::Printf("Assertion failed: Don't call in thread context"); |
|
3072 |
if (m & MASK_NOT_ISR) |
|
3073 |
Kern::Printf("Assertion failed: Don't call in ISR context"); |
|
3074 |
if (m & MASK_NOT_IDFC) |
|
3075 |
Kern::Printf("Assertion failed: Don't call in IDFC context"); |
|
3076 |
if (m & MASK_NO_CRITICAL_IF_USER) |
|
3077 |
Kern::Printf("Assertion failed: Don't call from user thread in critical section"); |
|
3078 |
if (m & MASK_ALWAYS_FAIL) |
|
3079 |
Kern::Printf("Assertion failed"); |
|
3080 |
if (m & MASK_NO_RESCHED) |
|
3081 |
Kern::Printf("Assertion failed: Don't call from thread with kernel unlocked"); |
|
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
3082 |
if (m & MASK_NO_KILL_OR_SUSPEND) |
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
3083 |
Kern::Printf("Assertion failed: Must not be suspended or killed here"); |
0 | 3084 |
|
3085 |
#ifdef __KERNEL_APIS_CONTEXT_CHECKS_FAULT__ |
|
3086 |
if (aFunction) |
|
3087 |
Kern::Fault(aFunction, 0); |
|
3088 |
return KErrGeneral; |
|
3089 |
#else |
|
3090 |
return KErrNone; |
|
3091 |
#endif//__KERNEL_APIS_CONTEXT_CHECKS_FAULT__ |
|
3092 |
} |
|
3093 |
#endif//__KERNEL_APIS_CONTEXT_CHECKS_WARNING__||__KERNEL_APIS_CONTEXT_CHECKS_FAULT__ |
|
3094 |
#endif |
|
3095 |
||
3096 |
||
3097 |
/** |
|
3098 |
Set the behaviour of text tracing. (Kern::Printf, RDebug::Print etc.) |
|
3099 |
||
3100 |
For example, to disable text trace output to serial port, use: |
|
3101 |
@code |
|
3102 |
Kern::SetTextTraceMode(Kern::ESerialOutNever,Kern::ESerialOutMask); |
|
3103 |
@endcode |
|
3104 |
||
3105 |
To query the current behaviour: |
|
3106 |
@code |
|
3107 |
TUint textTraceMode = Kern::SetTextTraceMode(0,0); |
|
3108 |
@endcode |
|
3109 |
||
3110 |
@param aMode Values formed from enum TTextTraceMode. |
|
3111 |
@param aMask Bitmask indicating which flags are to be modified. |
|
3112 |
@return The text trace mode in operation before this function was called. |
|
3113 |
||
3114 |
@publishedPartner |
|
3115 |
*/ |
|
3116 |
EXPORT_C TUint Kern::SetTextTraceMode(TUint aMode, TUint aMask) |
|
3117 |
{ |
|
3118 |
return __e32_atomic_axo_ord32(&K::TextTraceMode, ~aMask, aMode&aMask); |
|
3119 |
} |
|
3120 |
||
3121 |
||
3122 |
void K::TextTrace(const TDesC8& aText, TTraceSource aTraceSource, TBool aNewLine) |
|
3123 |
{ |
|
3124 |
TBool crashed = NKern::Crashed(); |
|
3125 |
const TUint8* ptr = aText.Ptr(); |
|
3126 |
TInt size = aText.Size(); |
|
3127 |
||
3128 |
// Handle BTrace first... |
|
3129 |
TUint category; |
|
3130 |
switch(aTraceSource) |
|
3131 |
{ |
|
3132 |
case EUserTrace: |
|
3133 |
category = BTrace::ERDebugPrintf; |
|
3134 |
break; |
|
3135 |
case EKernelTrace: |
|
3136 |
category = BTrace::EKernPrintf; |
|
3137 |
break; |
|
3138 |
case EPlatSecTrace: |
|
3139 |
category = BTrace::EPlatsecPrintf; |
|
3140 |
break; |
|
3141 |
default: |
|
3142 |
category = ~0u; |
|
3143 |
break; |
|
3144 |
} |
|
3145 |
TInt result = 0; |
|
3146 |
if(category!=~0u) |
|
3147 |
{ |
|
3148 |
TUint threadId = KNullThreadId; |
|
3149 |
if(!K::Initialising && NKern::CurrentContext()==NKern::EThread) |
|
3150 |
{ |
|
3151 |
NThread* n = NKern::CurrentThread(); |
|
3152 |
if(n) |
|
3153 |
{ |
|
3154 |
DThread* t = Kern::NThreadToDThread(n); |
|
3155 |
if(t) |
|
3156 |
threadId = t->iId; |
|
3157 |
} |
|
3158 |
} |
|
3159 |
result = BTraceContextBig(category,0,threadId,ptr,size); |
|
3160 |
} |
|
3161 |
||
3162 |
NThread* csThread = 0; |
|
3163 |
if (!K::Initialising && NKern::CurrentContext() == NKern::EThread && !NKern::KernelLocked() && !crashed && InterruptsStatus(ETrue)) |
|
3164 |
{ |
|
3165 |
csThread = NCurrentThread(); |
|
3166 |
NKern::_ThreadEnterCS(); |
|
3167 |
} |
|
3168 |
||
3169 |
if(!result) |
|
3170 |
if(K::TraceHandler()) |
|
3171 |
result = K::TraceHandler()(aText, aTraceSource); |
|
3172 |
||
3173 |
TUint mode = K::TextTraceMode; |
|
3174 |
if(mode!=Kern::ESerialOutNever) |
|
3175 |
if(mode==Kern::ESerialOutAlways || !result) |
|
3176 |
A::DebugPrint(ptr,size,aNewLine); |
|
3177 |
||
3178 |
if (csThread) |
|
3179 |
NKern::_ThreadLeaveCS(); |
|
3180 |
} |
|
3181 |
||
3182 |
#if defined(_DEBUG) && !defined(__SMP__) |
|
3183 |
TInt KCrazySchedulerEnabled() |
|
3184 |
{ |
|
3185 |
return TheSuperPage().KernelConfigFlags() & EKernelConfigCrazyScheduling; |
|
3186 |
} |
|
3187 |
#endif |
|
3188 |
||
3189 |
/* |
|
3190 |
TClientRequest states and synchronization |
|
3191 |
||
3192 |
TClientRequest objects are synchronized based on atomic updates to the iStatus |
|
3193 |
member using __e32_atomic_xxx_yyy_ptr() operations. |
|
3194 |
||
3195 |
The contents of the iStatus member are made up of a TRequestStatus pointer in |
|
3196 |
bit 2-31 and two flag bits in bits 0 and 1. |
|
3197 |
||
3198 |
The object can be in the following states indicated by the value in iStatus: |
|
3199 |
||
3200 |
State: Pointer: Bit 1: Bit 0: |
|
3201 |
--------------------------------- |
|
3202 |
FREE zero 0 0 |
|
3203 |
READY non-zero 0 0 |
|
3204 |
INUSE non-zero 1 0 |
|
3205 |
CLOSING non-zero 1 1 |
|
3206 |
DEAD any 0 1 |
|
3207 |
||
3208 |
The following state transitions are possible: |
|
3209 |
||
3210 |
Start state: Operation: End state: |
|
3211 |
------------------------------------ |
|
3212 |
FREE Reset FREE |
|
3213 |
Close DEAD |
|
3214 |
SetStatus READY |
|
3215 |
||
3216 |
READY Reset FREE |
|
3217 |
Close DEAD |
|
3218 |
Queue INUSE |
|
3219 |
||
3220 |
INUSE Callback FREE |
|
3221 |
Close CLOSING |
|
3222 |
||
3223 |
CLOSING Callback DEAD |
|
3224 |
||
3225 |
When the object enters the DEAD state, it is deleted. |
|
3226 |
*/ |
|
3227 |
||
3228 |
inline void IgnorePrintf(...) { } |
|
3229 |
||
3230 |
#define CLIENT_REQUEST_DEBUG IgnorePrintf |
|
3231 |
//#define CLIENT_REQUEST_DEBUG Kern::Printf |
|
3232 |
||
3233 |
/** |
|
3234 |
Create a TClientRequest object. |
|
3235 |
||
3236 |
The object is initially in the EFree state. |
|
3237 |
||
3238 |
@param aRequestPtr A reference to the TClientRequest pointer which is to be set |
|
3239 |
to the newly created object. |
|
3240 |
||
3241 |
@return KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
3242 |
||
3243 |
@see TClientRequest::State() |
|
3244 |
||
3245 |
@publishedPartner |
|
3246 |
@released |
|
3247 |
*/ |
|
3248 |
EXPORT_C TInt Kern::CreateClientRequest(TClientRequest*& aRequestPtr) |
|
3249 |
{ |
|
3250 |
TClientRequest* self = (TClientRequest*)Kern::Alloc(sizeof(TClientRequest)); |
|
3251 |
if (!self) |
|
3252 |
return KErrNoMemory; |
|
3253 |
new (self) TClientRequest; |
|
3254 |
T_UintPtr zero = 0; |
|
3255 |
if (!__e32_atomic_cas_ord_ptr(&aRequestPtr, &zero, self)) |
|
3256 |
{ |
|
3257 |
self->Close(); |
|
3258 |
return KErrInUse; |
|
3259 |
} |
|
3260 |
return KErrNone; |
|
3261 |
} |
|
3262 |
||
3263 |
/** |
|
3264 |
@prototype |
|
3265 |
@internalTechnology |
|
3266 |
*/ |
|
3267 |
EXPORT_C TInt Kern::CreateClientDataRequestBase(TClientDataRequestBase*& aRequestPtr, TInt aSize) |
|
3268 |
{ |
|
3269 |
TClientDataRequestBase* self = (TClientDataRequestBase*)Kern::Alloc(sizeof(TClientDataRequestBase) + aSize); |
|
3270 |
if (!self) |
|
3271 |
return KErrNoMemory; |
|
3272 |
new (self) TClientDataRequestBase(aSize); |
|
3273 |
T_UintPtr zero = 0; |
|
3274 |
if (!__e32_atomic_cas_ord_ptr(&aRequestPtr, &zero, self)) |
|
3275 |
{ |
|
3276 |
self->Close(); |
|
3277 |
return KErrInUse; |
|
3278 |
} |
|
3279 |
return KErrNone; |
|
3280 |
} |
|
3281 |
||
3282 |
/** |
|
3283 |
@prototype |
|
3284 |
@internalTechnology |
|
3285 |
*/ |
|
3286 |
EXPORT_C TInt Kern::CreateClientDataRequestBase2(TClientDataRequestBase2*& aRequestPtr, TInt aSize1, TInt aSize2) |
|
3287 |
{ |
|
3288 |
TInt size = _ALIGN_UP(sizeof(TClientDataRequestBase2), 8) + _ALIGN_UP(aSize1, 8) + aSize2; |
|
3289 |
TClientDataRequestBase2* self = (TClientDataRequestBase2*)Kern::Alloc(size); |
|
3290 |
if (!self) |
|
3291 |
return KErrNoMemory; |
|
3292 |
new (self) TClientDataRequestBase2(aSize1, aSize2); |
|
3293 |
T_UintPtr zero = 0; |
|
3294 |
if (!__e32_atomic_cas_ord_ptr(&aRequestPtr, &zero, self)) |
|
3295 |
{ |
|
3296 |
self->Close(); |
|
3297 |
return KErrInUse; |
|
3298 |
} |
|
3299 |
return KErrNone; |
|
3300 |
} |
|
3301 |
||
3302 |
/** |
|
3303 |
Destroy a TClientRequest object. |
|
3304 |
||
3305 |
The pointer to the object is set to NULL. |
|
3306 |
||
3307 |
@param aRequestPtr A reference to the TClientRequest pointer to free. |
|
3308 |
||
3309 |
@pre Calling thread must be in a critical section. |
|
3310 |
@pre Interrupts must be enabled. |
|
3311 |
@pre Kernel must be unlocked. |
|
3312 |
@pre No fast mutex can be held. |
|
3313 |
@pre Call in a thread context. |
|
3314 |
@pre Can be used in a device driver. |
|
3315 |
||
3316 |
@publishedPartner |
|
3317 |
@released |
|
3318 |
*/ |
|
3319 |
EXPORT_C void Kern::DestroyClientRequest(TClientRequest*& aRequestPtr) |
|
3320 |
{ |
|
3321 |
TClientRequest* request = (TClientRequest*)__e32_atomic_swp_rel_ptr(&aRequestPtr, 0); |
|
3322 |
if (request) |
|
3323 |
request->Close(); |
|
3324 |
} |
|
3325 |
||
3326 |
TClientRequest::TClientRequest(TUserModeCallbackFunc aCallback) |
|
3327 |
: TUserModeCallback(aCallback), |
|
3328 |
iStatus(0), |
|
3329 |
iResult(KRequestPending) |
|
3330 |
{ |
|
3331 |
} |
|
3332 |
||
3333 |
void TClientRequest::Close() |
|
3334 |
{ |
|
3335 |
CLIENT_REQUEST_DEBUG("%08x TClientRequest::Close", this); |
|
3336 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TClientRequest::Close"); |
|
3337 |
T_UintPtr status = (T_UintPtr)__e32_atomic_ior_ord_ptr(&iStatus, KClientRequestFlagClosing); |
|
3338 |
CLIENT_REQUEST_DEBUG(" state == %d", GetState(status)); |
|
3339 |
__ASSERT_DEBUG(GetState(status) <= EInUse, K::Fault(K::EClientRequestCloseInWrongState)); |
|
3340 |
if (!(status & KClientRequestFlagInUse)) |
|
3341 |
Kern::AsyncFree(this); // must call async version since current thread may be exiting here |
|
3342 |
} |
|
3343 |
||
3344 |
/** |
|
3345 |
Indicates whether the request is ready to be queued, in other words whether SetState() has been called on it. |
|
3346 |
||
3347 |
Note that this method is not synchronised. If multiple threads are accessing this object (except by |
|
3348 |
calling Kern::QueueRequestComplete), then some form of external synchronisation is required. |
|
3349 |
||
3350 |
@publishedPartner |
|
3351 |
@released |
|
3352 |
*/ |
|
3353 |
EXPORT_C TBool TClientRequest::IsReady() |
|
3354 |
{ |
|
3355 |
T_UintPtr status = iStatus; // sample volatile value |
|
3356 |
return status && !(status & KClientRequestFlagMask); |
|
3357 |
} |
|
3358 |
||
3359 |
TClientRequest::~TClientRequest() |
|
3360 |
{ |
|
3361 |
// This should never be called because we use Kern::Free to free the object after calling |
|
3362 |
// Close(). If this is called it means someone deleted a derived object without calling |
|
3363 |
// Close(). |
|
3364 |
CLIENT_REQUEST_DEBUG("%08x TClientRequest::~TClientRequest", this); |
|
3365 |
K::Fault(K::EClientRequestDeletedNotClosed); |
|
3366 |
} |
|
3367 |
||
3368 |
/** |
|
3369 |
Get the current state of this object. |
|
3370 |
||
3371 |
A TClientRequest object can be in one of three states, described by the TClientRequest::TState |
|
3372 |
enumeration. These are: |
|
3373 |
- EFree: The initial state |
|
3374 |
- EReady: The object has been set up with the TRequestStatus pointer of a client request, and is |
|
3375 |
ready to be queued for completion. |
|
3376 |
- EInUse: The object has been queued for completion, but this has not yet occurred. |
|
3377 |
- EClosing: The object has been queued for completion and then had Close() called on it, but |
|
3378 |
completion has not yet occured. |
|
3379 |
||
3380 |
@return The state of the object. |
|
3381 |
*/ |
|
3382 |
TClientRequest::TState TClientRequest::State() |
|
3383 |
{ |
|
3384 |
return GetState(iStatus); |
|
3385 |
} |
|
3386 |
||
3387 |
TClientRequest::TState TClientRequest::GetState(T_UintPtr aStatus) |
|
3388 |
{ |
|
3389 |
if (aStatus == 0) |
|
3390 |
return EFree; |
|
3391 |
switch (aStatus & KClientRequestFlagMask) |
|
3392 |
{ |
|
3393 |
case 0: |
|
3394 |
return EReady; |
|
3395 |
case KClientRequestFlagInUse: |
|
3396 |
return EInUse; |
|
3397 |
case KClientRequestFlagInUse | KClientRequestFlagClosing: |
|
3398 |
return EClosing; |
|
3399 |
} |
|
3400 |
return EBad; |
|
3401 |
} |
|
3402 |
||
3403 |
/** |
|
3404 |
Set the client's TRequestStatus pointer. |
|
3405 |
||
3406 |
This method should be called when the client initiates an asynchronous request. |
|
3407 |
If the object was initially in the EFree state this method puts it into the |
|
3408 |
EReady state, otherwise it does nothing. |
|
3409 |
||
3410 |
@return KErrNone if the object state has been transitioned from EFree to EReady |
|
3411 |
KErrInUse if the object was not initially in the EFree state |
|
3412 |
||
3413 |
@publishedPartner |
|
3414 |
@released |
|
3415 |
*/ |
|
3416 |
EXPORT_C TInt TClientRequest::SetStatus(TRequestStatus* aStatus) |
|
3417 |
{ |
|
3418 |
CLIENT_REQUEST_DEBUG("%08x TClientRequest::SetStatus", this); |
|
3419 |
// Return an error if the status pointer is bad. Don't fault the kernel as this would allow a |
|
3420 |
// user thread to crash the system. |
|
3421 |
if (((T_UintPtr)aStatus & KClientRequestFlagMask) != 0 || (T_UintPtr)aStatus == KClientRequestNullStatus) |
|
3422 |
return KErrArgument; |
|
3423 |
T_UintPtr newStatus = aStatus ? (T_UintPtr)aStatus : KClientRequestNullStatus; |
|
3424 |
T_UintPtr zero = 0; |
|
3425 |
return __e32_atomic_cas_ord_ptr(&iStatus, &zero, newStatus) ? KErrNone : KErrInUse; // acq? |
|
3426 |
} |
|
3427 |
||
3428 |
/** |
|
3429 |
Get the client's TRequestStatus pointer. |
|
3430 |
||
3431 |
@return The client's TRequestStatus pointer. |
|
3432 |
||
3433 |
@publishedPartner |
|
3434 |
@released |
|
3435 |
*/ |
|
3436 |
EXPORT_C TRequestStatus* TClientRequest::StatusPtr() |
|
3437 |
{ |
|
3438 |
return (TRequestStatus*)(iStatus & ~KClientRequestFlagMask); |
|
3439 |
} |
|
3440 |
||
3441 |
/** |
|
3442 |
Queue the request for completion. |
|
3443 |
||
3444 |
If the object is not in the EReady state, this method does nothing. Otherwise the client thread is |
|
3445 |
signalled immediately, and the object left in the EInUse state. When the client thread next runs, |
|
3446 |
the reason code is written back to it and the object is left in the EFree state. |
|
3447 |
||
3448 |
This method is only synchronised with respect to itself. Multiple threads can call this method |
|
3449 |
concurrently and only one will complete the request. |
|
3450 |
||
3451 |
@param aThread The client thread to which to write the reason code. |
|
3452 |
@param aRequest The client request object. |
|
3453 |
@param aReason The reason code with which to complete the request. |
|
3454 |
||
3455 |
@pre Call in a thread context. |
|
3456 |
@pre Kernel must be unlocked |
|
3457 |
@pre Interrupts enabled |
|
3458 |
||
3459 |
@publishedPartner |
|
3460 |
@released |
|
3461 |
*/ |
|
3462 |
EXPORT_C void Kern::QueueRequestComplete(DThread* aThread, TClientRequest* aRequest, TInt aReason) |
|
3463 |
{ |
|
3464 |
CLIENT_REQUEST_DEBUG("%08x Kern::QueueRequestComplete %T %d", aRequest, aThread, aReason); |
|
3465 |
CHECK_PRECONDITIONS(MASK_KERNEL_UNLOCKED | MASK_INTERRUPTS_ENABLED | MASK_NOT_ISR | MASK_NOT_IDFC, "Kern::QueueRequestComplete"); |
|
3466 |
if (aRequest->StartComplete(aThread, aReason)) |
|
3467 |
aRequest->EndComplete(aThread); |
|
3468 |
} |
|
3469 |
||
3470 |
TBool TClientRequest::StartComplete(DThread* aThread, TInt aReason) |
|
3471 |
{ |
|
3472 |
NKern::ThreadEnterCS(); |
|
3473 |
T_UintPtr status = iStatus; |
|
3474 |
do { |
|
3475 |
if (!status || (status & KClientRequestFlagMask)) |
|
3476 |
{ |
|
3477 |
CLIENT_REQUEST_DEBUG("status %08x request not ready", status); |
|
3478 |
NKern::ThreadLeaveCS(); |
|
3479 |
return EFalse; |
|
3480 |
} |
|
3481 |
} while (!__e32_atomic_cas_ord_ptr(&iStatus, &status, status | KClientRequestFlagInUse)); |
|
3482 |
iResult = aReason; |
|
3483 |
(void)aThread; |
|
3484 |
#ifdef BTRACE_REQUESTS |
|
3485 |
BTraceContext12(BTrace::ERequests,BTrace::ERequestComplete,&aThread->iNThread,iStatus,aReason); |
|
3486 |
#endif |
|
3487 |
return ETrue; |
|
3488 |
} |
|
3489 |
||
3490 |
void TClientRequest::EndComplete(DThread* aThread) |
|
3491 |
{ |
|
3492 |
TInt r = NKern::QueueUserModeCallback(&aThread->iNThread, this); |
|
3493 |
if (r == KErrNone) |
|
3494 |
{ |
|
3495 |
if (iStatus != (KClientRequestNullStatus | KClientRequestFlagInUse)) |
|
3496 |
NKern::ThreadRequestSignal(&aThread->iNThread); |
|
3497 |
} |
|
3498 |
else |
|
3499 |
{ |
|
3500 |
__NK_ASSERT_DEBUG(r == KErrDied); |
|
3501 |
// Thread was exiting, queue it for cleanup by attaching it to |
|
3502 |
// the supervisor thread and queueing a DFC to deal with it |
|
3503 |
CLIENT_REQUEST_DEBUG(" queue callback failed, queueing for cleanup"); |
|
3504 |
NKern::QueueUserModeCallback(K::SvMsgQ->iThread, this); |
|
3505 |
DeadClientCleanupDfc.Enque(); |
|
3506 |
} |
|
3507 |
NKern::ThreadLeaveCS(); |
|
3508 |
} |
|
3509 |
||
3510 |
void TClientRequest::DoDeadClientCleanup(TAny*) |
|
3511 |
{ |
|
3512 |
NKern::CancelUserModeCallbacks(); |
|
3513 |
} |
|
3514 |
||
3515 |
/** |
|
3516 |
Reset this object to its initial state so that it can be re-used. |
|
3517 |
||
3518 |
The request pointer is cleared and the state of the object is set to EFree. |
|
3519 |
||
3520 |
This method may only be called when the object is in the EFree or EReady states. |
|
3521 |
||
3522 |
Note that this method is not synchronized. If multiple threads are accessing |
|
3523 |
this object (except by calling Kern::QueueRequestComplete), then some form of |
|
3524 |
external synchronisation is required. |
|
3525 |
||
3526 |
@publishedPartner |
|
3527 |
@released |
|
3528 |
*/ |
|
3529 |
EXPORT_C void TClientRequest::Reset() |
|
3530 |
{ |
|
3531 |
CLIENT_REQUEST_DEBUG("%08x TClientRequest::Reset", this); |
|
3532 |
T_UintPtr oldStatus = (T_UintPtr)__e32_atomic_swp_ord_ptr(&iStatus, 0); |
|
3533 |
CLIENT_REQUEST_DEBUG("oldStatus == %08x", oldStatus); |
|
3534 |
__ASSERT_DEBUG(GetState(oldStatus) <= EReady, K::Fault(K::EClientRequestResetInWrongState)); |
|
3535 |
} |
|
3536 |
||
3537 |
#ifndef __CLIENT_REQUEST_MACHINE_CODED__ |
|
3538 |
||
3539 |
void TClientRequest::CallbackFunc(TAny* aData, TUserModeCallbackReason aReason) |
|
3540 |
{ |
|
3541 |
TClientRequest* req = (TClientRequest*)aData; |
|
3542 |
CLIENT_REQUEST_DEBUG("%08x TClientRequest::CallbackFunc", req); |
|
3543 |
TInt result = req->iResult; |
|
3544 |
||
3545 |
// Ensure request object can be reused before write to user-space takes place |
|
3546 |
T_UintPtr statusPtr = req->MakeFree() & ~KClientRequestFlagMask; |
|
3547 |
||
3548 |
if (aReason == EUserModeCallbackRun && statusPtr != KClientRequestNullStatus) |
|
3549 |
K::USafeWrite((TAny*)statusPtr, &result, sizeof(result)); |
|
3550 |
} |
|
3551 |
||
3552 |
#endif |
|
3553 |
||
3554 |
T_UintPtr TClientRequest::MakeFree() |
|
3555 |
{ |
|
3556 |
// Move callback to the free state, deleting it if necessary |
|
3557 |
CHECK_PRECONDITIONS(MASK_CRITICAL,"TClientRequest::MakeFree"); // needed for Kern::AsyncFree |
|
3558 |
iResult = KRequestPending; |
|
3559 |
T_UintPtr oldStatus = (T_UintPtr)__e32_atomic_and_ord_ptr(&iStatus, KClientRequestFlagClosing); |
|
3560 |
CLIENT_REQUEST_DEBUG("MakeFree %08x oldStatus %08x", this, oldStatus); |
|
3561 |
__ASSERT_DEBUG(GetState(oldStatus)==EInUse || GetState(oldStatus)==EClosing, K::Fault(K::EClientRequestCallbackInWrongState)); |
|
3562 |
if (oldStatus & KClientRequestFlagClosing) |
|
3563 |
Kern::AsyncFree(this); // must call async version since current thread may be exiting here |
|
3564 |
return oldStatus; |
|
3565 |
} |
|
3566 |
||
3567 |
TClientDataRequestBase::TClientDataRequestBase(TInt aBufferSize) : |
|
3568 |
TClientRequest(CallbackFunc), |
|
3569 |
iSize(aBufferSize) |
|
3570 |
{ |
|
3571 |
} |
|
3572 |
||
3573 |
void TClientDataRequestBase::CallbackFunc(TAny* aData, TUserModeCallbackReason aReason) |
|
3574 |
{ |
|
3575 |
TClientDataRequestBase* req = (TClientDataRequestBase*)aData; |
|
3576 |
||
3577 |
#ifdef _DEBUG |
|
3578 |
TState state = GetState(req->iStatus); |
|
3579 |
__ASSERT_DEBUG(state == EInUse || state == EClosing, K::Fault(K::EClientRequestCallbackInWrongState)); |
|
3580 |
#endif |
|
3581 |
||
3582 |
if (aReason == EUserModeCallbackRun) |
|
3583 |
K::USafeWrite(req->iDestPtr, req->Buffer(), req->iSize); |
|
3584 |
||
3585 |
TClientRequest::CallbackFunc(aData, aReason); |
|
3586 |
} |
|
3587 |
||
3588 |
TClientDataRequestBase2::TClientDataRequestBase2(TInt aBufferSize1, TInt aBufferSize2) : |
|
3589 |
TClientRequest(CallbackFunc), |
|
3590 |
iSize1(aBufferSize1), |
|
3591 |
iSize2(aBufferSize2) |
|
3592 |
{ |
|
3593 |
} |
|
3594 |
||
3595 |
void TClientDataRequestBase2::CallbackFunc(TAny* aData, TUserModeCallbackReason aReason) |
|
3596 |
{ |
|
3597 |
TClientDataRequestBase2* req = (TClientDataRequestBase2*)aData; |
|
3598 |
||
3599 |
#ifdef _DEBUG |
|
3600 |
TState state = GetState(req->iStatus); |
|
3601 |
__ASSERT_DEBUG(state == EInUse || state == EClosing, K::Fault(K::EClientRequestCallbackInWrongState)); |
|
3602 |
#endif |
|
3603 |
||
3604 |
if (aReason == EUserModeCallbackRun) |
|
3605 |
{ |
|
3606 |
K::USafeWrite(req->iDestPtr1, req->Buffer1(), req->iSize1); |
|
3607 |
K::USafeWrite(req->iDestPtr2, req->Buffer2(), req->iSize2); |
|
3608 |
} |
|
3609 |
||
3610 |
TClientRequest::CallbackFunc(aData, aReason); |
|
3611 |
} |
|
3612 |
||
3613 |
// TClientBuffer implementation |
|
3614 |
||
3615 |
#ifndef __MARM__ |
|
3616 |
||
3617 |
/** |
|
3618 |
Read the header of a user-side descriptor in the current process, parse it, and populate a |
|
3619 |
TDesHeader with the result. |
|
3620 |
||
3621 |
@param aDesPtr The descriptor for which information is to be fetched. |
|
3622 |
@param aOut On return, set to the parsed contents of the descriptor header. |
|
3623 |
||
3624 |
@return KErrNone if successful, or one of the system-wide error codes. |
|
3625 |
||
3626 |
@pre Interrupts must be enabled. |
|
3627 |
@pre Kernel must be unlocked. |
|
3628 |
@pre No fast mutex can be held. |
|
3629 |
@pre Call in a thread context. |
|
3630 |
@pre Can be used in a device driver. |
|
3631 |
*/ |
|
3632 |
TInt K::USafeReadAndParseDesHeader(TAny* aDesPtr, TDesHeader& aOut) |
|
3633 |
{ |
|
3634 |
CHECK_PAGING_SAFE; |
|
3635 |
static const TUint8 LengthLookup[16]={4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0}; |
|
3636 |
TRawDesHeader header; |
|
3637 |
const TUint32* pS=(const TUint32*)aDesPtr; |
|
3638 |
if (!pS || (TInt(pS)&3)!=0) |
|
3639 |
return KErrBadDescriptor; |
|
3640 |
if (K::USafeRead(pS,&header[0],sizeof(TUint32))) |
|
3641 |
return KErrBadDescriptor; |
|
3642 |
TInt type=header[0]>>KShiftDesType8; |
|
3643 |
TInt l=LengthLookup[type]; |
|
3644 |
if (l==0) |
|
3645 |
return KErrBadDescriptor; |
|
3646 |
if (l>(TInt)sizeof(TUint32) && K::USafeRead(pS+1,&header[1],l-sizeof(TUint32))) |
|
3647 |
return KErrBadDescriptor; |
|
3648 |
return K::ParseDesHeader(aDesPtr, header, aOut); |
|
3649 |
} |
|
3650 |
||
3651 |
#endif |
|
3652 |
||
3653 |
// Parse a descriptor header, return KErrBadDescriptor if there's an error |
|
3654 |
// Note that this can parse a header in-place (i.e. when &aIn == &aOut) |
|
3655 |
TInt K::ParseDesHeader(const TAny* aDes, const TRawDesHeader& aIn, TDesHeader& aOut) |
|
3656 |
{ |
|
3657 |
TUint type = aIn[0] >> KShiftDesType; |
|
3658 |
TUint len = aIn[0] & KMaskDesLength; |
|
3659 |
TUint max = (TUint)TDesHeader::KConstMaxLength; |
|
3660 |
TLinAddr p; |
|
3661 |
switch (type) |
|
3662 |
{ |
|
3663 |
case EBufC: p=(TLinAddr)aDes+sizeof(TDesC); break; |
|
3664 |
case EPtrC: p=(TLinAddr)aIn[1]; break; |
|
3665 |
case EPtr: p=(TLinAddr)aIn[2]; max=(TInt)aIn[1]; break; |
|
3666 |
case EBuf: p=(TLinAddr)aDes+sizeof(TDes); max=(TInt)aIn[1]; break; |
|
3667 |
case EBufCPtr: p=(TLinAddr)aIn[2]+sizeof(TDesC); max=(TInt)aIn[1]; break; |
|
3668 |
default: |
|
3669 |
return KErrBadDescriptor; |
|
3670 |
} |
|
3671 |
if (len>max || (type == EBufCPtr && ((TUint)p & 3) != 0)) |
|
3672 |
return KErrBadDescriptor; |
|
3673 |
aOut.Set(aIn[0], p, max); |
|
3674 |
return KErrNone; |
|
3675 |
} |
|
3676 |
||
3677 |
/** |
|
3678 |
Create a TClientBuffer object. |
|
3679 |
||
3680 |
The object is not initially populated with information about a buffer, and the IsSet() method will |
|
3681 |
return false. |
|
3682 |
*/ |
|
3683 |
EXPORT_C TClientBuffer::TClientBuffer() : |
|
3684 |
iPtr(0) |
|
3685 |
{ |
|
3686 |
} |
|
3687 |
||
3688 |
/** |
|
3689 |
Indicates whether this object has been set by calling either SetFromDescriptor() or SetFromBuffer(). |
|
3690 |
||
3691 |
@return Whether the object has been set. |
|
3692 |
*/ |
|
3693 |
EXPORT_C TBool TClientBuffer::IsSet() const |
|
3694 |
{ |
|
3695 |
return iPtr != 0; |
|
3696 |
} |
|
3697 |
||
3698 |
/** |
|
3699 |
Reset this object to its initial state. |
|
3700 |
||
3701 |
Calling IsSet() will subsequently return false. |
|
3702 |
||
3703 |
@publishedPartner |
|
3704 |
@released |
|
3705 |
*/ |
|
3706 |
EXPORT_C void TClientBuffer::Reset() |
|
3707 |
{ |
|
3708 |
iPtr = 0; |
|
3709 |
} |
|
3710 |
||
3711 |
/** |
|
3712 |
Set this object to refer to a client descriptor. |
|
3713 |
||
3714 |
@param aDesPtr A pointer to the client's descriptor (in user memory). |
|
3715 |
@param aClientThread This should normally be NULL to indicate the current thread, although a |
|
3716 |
different thread can be specified. |
|
3717 |
||
3718 |
The descriptor (including the header) is expected to reside in user memory. The header is read in the process of populating this object. |
|
3719 |
||
3720 |
Calling IsSet() will subsequently return true. |
|
3721 |
||
3722 |
@publishedPartner |
|
3723 |
@released |
|
3724 |
*/ |
|
3725 |
EXPORT_C TInt TClientBuffer::SetFromDescriptor(TAny* aDesPtr, DThread* aClientThread) |
|
3726 |
{ |
|
3727 |
iPtr = (TUint32)aDesPtr; |
|
3728 |
__NK_ASSERT_ALWAYS((iPtr & 3) == 0); |
|
3729 |
TInt r; |
|
3730 |
if (aClientThread) |
|
3731 |
{ |
|
3732 |
#ifndef __MEMMODEL_FLEXIBLE__ |
|
3733 |
NKern::LockSystem(); |
|
3734 |
#endif |
|
3735 |
r = aClientThread->ReadAndParseDesHeader(aDesPtr, iHeader); |
|
3736 |
#ifndef __MEMMODEL_FLEXIBLE__ |
|
3737 |
NKern::UnlockSystem(); |
|
3738 |
#endif |
|
3739 |
} |
|
3740 |
else |
|
3741 |
r = K::USafeReadAndParseDesHeader(aDesPtr, iHeader); |
|
3742 |
return r; |
|
3743 |
} |
|
3744 |
||
3745 |
/** |
|
3746 |
Set this object to refer to a client buffer specified by start address and length. |
|
3747 |
||
3748 |
@param aStartAddr The start address of the buffer (in user memory) |
|
3749 |
@param aLength The length of the buffer in bytes. |
|
3750 |
@param aWriteable Whether the buffer should be written to by kernel-side code. |
|
3751 |
||
3752 |
The buffer is expected to reside in user memory. |
|
3753 |
||
3754 |
Calling IsSet() will subsequently return true. |
|
3755 |
||
3756 |
@publishedPartner |
|
3757 |
@released |
|
3758 |
*/ |
|
3759 |
EXPORT_C void TClientBuffer::SetFromBuffer(TLinAddr aStartAddr, TInt aLength, TBool aWriteable) |
|
3760 |
{ |
|
3761 |
iPtr = EIsBuffer; |
|
3762 |
if (aWriteable) |
|
3763 |
iHeader.Set(EPtr << KShiftDesType8, aStartAddr, aLength); |
|
3764 |
else |
|
3765 |
iHeader.Set((EPtrC << KShiftDesType8) | aLength, aStartAddr); |
|
3766 |
} |
|
3767 |
||
3768 |
/** |
|
3769 |
Indicates whether the client descriptor is writeable, as opposed to constant. |
|
3770 |
||
3771 |
@return Whether the client descriptor is writeable. |
|
3772 |
||
3773 |
@publishedPartner |
|
3774 |
@released |
|
3775 |
*/ |
|
3776 |
EXPORT_C TBool TClientBuffer::IsWriteable() const |
|
3777 |
{ |
|
3778 |
return iHeader.IsWriteable(); |
|
3779 |
} |
|
3780 |
||
3781 |
/** |
|
3782 |
Get the length of the client's descriptor. |
|
3783 |
||
3784 |
@return The length of the descriptor |
|
3785 |
||
3786 |
@publishedPartner |
|
3787 |
@released |
|
3788 |
*/ |
|
3789 |
EXPORT_C TInt TClientBuffer::Length() const |
|
3790 |
{ |
|
3791 |
return iHeader.Length(); |
|
3792 |
} |
|
3793 |
||
3794 |
/** |
|
3795 |
Get the maximum length of the client's writeable descriptor. |
|
3796 |
||
3797 |
@return The length of the descriptor on sucess, otherwise one of the system-wide error codes. |
|
3798 |
||
3799 |
@publishedPartner |
|
3800 |
@released |
|
3801 |
*/ |
|
3802 |
EXPORT_C TInt TClientBuffer::MaxLength() const |
|
3803 |
{ |
|
3804 |
return iHeader.MaxLength(); |
|
3805 |
} |
|
3806 |
||
3807 |
TAny* TClientBuffer::DesPtr() const |
|
3808 |
{ |
|
3809 |
return (TAny*)(iPtr & ~3); |
|
3810 |
} |
|
3811 |
||
3812 |
TAny* TClientBuffer::DataPtr() const |
|
3813 |
{ |
|
3814 |
return (TAny*)iHeader.DataPtr(); |
|
3815 |
} |
|
3816 |
||
3817 |
/** |
|
3818 |
Update the client's descriptor header to reflect the length of data written to the buffer. |
|
3819 |
||
3820 |
@param aClientThread This should normally be NULL to indicate the current thread, although a |
|
3821 |
different thread can be specified. |
|
3822 |
||
3823 |
This method should be called (usually in the context of the client thread) after the buffer has been |
|
3824 |
written to using Kern::ThreadBufWrite(). |
|
3825 |
||
3826 |
If this object was not set by calling SetFromDescriptor(), this method does nothing. |
|
3827 |
||
3828 |
@return KErrNone if successful, or KErrBadDescriptor if there was an exception while updating the length. |
|
3829 |
||
3830 |
@publishedPartner |
|
3831 |
@released |
|
3832 |
*/ |
|
3833 |
EXPORT_C TInt TClientBuffer::UpdateDescriptorLength(DThread* aClientThread) |
|
3834 |
{ |
|
3835 |
TInt r = KErrNone; |
|
3836 |
||
3837 |
if ((iPtr & EIsBuffer) == 0 && IsWriteable()) |
|
3838 |
{ |
|
3839 |
if (aClientThread) |
|
3840 |
r = Kern::ThreadRawWrite(aClientThread, (TAny*)iPtr, &iHeader.TypeAndLength(), sizeof(TUint32)); |
|
3841 |
else |
|
3842 |
{ |
|
3843 |
TAny* excAddr = K::USafeWrite((TAny*)iPtr, &iHeader.TypeAndLength(), sizeof(TUint32)); |
|
3844 |
if (excAddr != NULL) |
|
3845 |
r = KErrBadDescriptor; |
|
3846 |
} |
|
3847 |
if (r == KErrNone && iHeader.Type() == EBufCPtr) |
|
3848 |
{ |
|
3849 |
TInt len = iHeader.Length(); |
|
3850 |
TUint8* pL = (TUint8*)(iHeader.DataPtr() - sizeof(TDesC)); |
|
3851 |
if (aClientThread) |
|
3852 |
r = Kern::ThreadRawWrite(aClientThread, (TAny*)pL, &len, sizeof(TUint32)); |
|
3853 |
else |
|
3854 |
{ |
|
3855 |
TAny* excAddr = K::USafeWrite((TAny*)pL, &len, sizeof(TUint32)); |
|
3856 |
if (excAddr != NULL) |
|
3857 |
r = KErrBadDescriptor; |
|
3858 |
} |
|
3859 |
} |
|
3860 |
} |
|
3861 |
return r; |
|
3862 |
} |
|
3863 |
||
3864 |
// Implementation of TClientBufferRequest |
|
3865 |
||
3866 |
NFastMutex TClientBufferRequest::Lock; |
|
3867 |
||
3868 |
TClientBufferRequest::TClientBufferRequest(TUint aFlags) : |
|
3869 |
TClientRequest(TClientBufferRequest::CallbackFunc), |
|
3870 |
iFlags(aFlags) |
|
3871 |
{ |
|
3872 |
} |
|
3873 |
||
3874 |
TInt TClientBufferRequest::AllocateBufferData() |
|
3875 |
{ |
|
3876 |
// allocate data for one buffer and add it to the end of the list |
|
3877 |
SBufferData* item = new SBufferData; |
|
3878 |
if (item == NULL) |
|
3879 |
return KErrNoMemory; |
|
3880 |
if (iFlags & EPinVirtual) |
|
3881 |
{ |
|
3882 |
TInt r = Kern::CreateVirtualPinObject(item->iPinObject); |
|
3883 |
if (r != KErrNone) |
|
3884 |
{ |
|
3885 |
delete item; |
|
3886 |
return r; |
|
3887 |
} |
|
3888 |
} |
|
3889 |
iBufferList.Add(item); |
|
3890 |
return KErrNone; |
|
3891 |
} |
|
3892 |
||
3893 |
TInt TClientBufferRequest::Construct(TInt aInitialBuffers) |
|
3894 |
{ |
|
3895 |
TInt r = KErrNone; |
|
3896 |
for (TInt i = 0 ; r == KErrNone && i < aInitialBuffers ; ++i) |
|
3897 |
r = AllocateBufferData(); |
|
3898 |
return r; |
|
3899 |
} |
|
3900 |
||
3901 |
/** |
|
3902 |
Create a TClientBufferRequest object. |
|
3903 |
||
3904 |
@param aInitialBuffers The number of buffer slots to allocate initially. |
|
3905 |
@param aFlags Indicates whether buffers should have their virtual memory pinned. |
|
3906 |
||
3907 |
@publishedPartner |
|
3908 |
@released |
|
3909 |
*/ |
|
3910 |
EXPORT_C TInt Kern::CreateClientBufferRequest(TClientBufferRequest*& aRequestPtr, TUint aInitialBuffers, TUint aFlags) |
|
3911 |
{ |
|
3912 |
TClientBufferRequest* self = (TClientBufferRequest*)Kern::Alloc(sizeof(TClientBufferRequest)); |
|
3913 |
if (!self) |
|
3914 |
return KErrNoMemory; |
|
3915 |
new (self) TClientBufferRequest(aFlags); |
|
3916 |
TInt r = self->Construct(aInitialBuffers); |
|
3917 |
T_UintPtr zero = 0; |
|
3918 |
if (r == KErrNone && !__e32_atomic_cas_ord_ptr(&aRequestPtr, &zero, self)) |
|
3919 |
r = KErrInUse; |
|
3920 |
if (r != KErrNone) |
|
3921 |
self->Close(); |
|
3922 |
return r; |
|
3923 |
} |
|
3924 |
||
3925 |
void TClientBufferRequest::Close() |
|
3926 |
{ |
|
3927 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TClientBufferRequest::Close"); |
|
3928 |
T_UintPtr status = (T_UintPtr)__e32_atomic_ior_ord_ptr(&iStatus, KClientRequestFlagClosing); |
|
3929 |
__ASSERT_DEBUG(GetState(status) <= EInUse, K::Fault(K::EClientRequestCloseInWrongState)); |
|
3930 |
if (!(status & KClientRequestFlagInUse)) |
|
3931 |
{ |
|
3932 |
SBufferData* item; |
|
3933 |
while(item = (SBufferData*)iBufferList.GetFirst(), item != NULL) |
|
3934 |
{ |
|
3935 |
Kern::DestroyVirtualPinObject(item->iPinObject); // todo |
|
3936 |
Kern::AsyncFree(item); |
|
3937 |
} |
|
3938 |
Kern::AsyncFree(this); // must call async version since current thread may be exiting here |
|
3939 |
} |
|
3940 |
} |
|
3941 |
||
3942 |
/** |
|
3943 |
Destroy a TClientBufferRequest object. |
|
3944 |
||
3945 |
@publishedPartner |
|
3946 |
@released |
|
3947 |
*/ |
|
3948 |
EXPORT_C void Kern::DestroyClientBufferRequest(TClientBufferRequest*& aRequestPtr) |
|
3949 |
{ |
|
3950 |
TClientBufferRequest* request = (TClientBufferRequest*)__e32_atomic_swp_rel_ptr(&aRequestPtr, 0); |
|
3951 |
if (request) |
|
3952 |
request->Close(); |
|
3953 |
} |
|
3954 |
||
3955 |
#define iMState iWaitLink.iSpare1 |
|
3956 |
||
3957 |
/** |
|
3958 |
Start the setup process and set the client's TRequestStatus pointer. |
|
3959 |
||
3960 |
This method should be called first when the client initiates an asynchronous request, in the context |
|
3961 |
of the client thread. |
|
3962 |
||
3963 |
After calling this, the driver can call AddBuffer the appropriate number of times. |
|
3964 |
||
3965 |
@return KErrNone if successful, or KErrInUse if the object has already been setup. |
|
3966 |
||
3967 |
@publishedPartner |
|
3968 |
@released |
|
3969 |
*/ |
|
3970 |
EXPORT_C TInt TClientBufferRequest::StartSetup(TRequestStatus* aStatus) |
|
3971 |
{ |
|
3972 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"TClientBufferRequest::StartSetup"); |
|
3973 |
NKern::FMWait(&Lock); |
|
3974 |
TInt r = TClientRequest::SetStatus(aStatus); |
|
3975 |
if (r == KErrNone) |
|
3976 |
{ |
|
3977 |
__NK_ASSERT_DEBUG(iSetupThread == NULL || iSetupThread->iMState == DThread::EDead); |
|
3978 |
if (iSetupThread) |
|
3979 |
iSetupThread->Close(NULL); |
|
3980 |
iSetupThread = TheCurrentThread; |
|
3981 |
iSetupThread->Open(); |
|
3982 |
} |
|
3983 |
NKern::FMSignal(&Lock); |
|
3984 |
return r; |
|
3985 |
} |
|
3986 |
||
3987 |
TClientBufferRequest::SBufferData* TClientBufferRequest::StartAddBuffer() |
|
3988 |
{ |
|
3989 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"TClientBufferRequest::AddBuffer"); |
|
3990 |
if (iSetupThread != TheCurrentThread) |
|
3991 |
K::Fault(K::EBufferRequestAddInWrongState); |
|
3992 |
TInt r = KErrNone; |
|
3993 |
if (((SBufferData*)iBufferList.Last())->iBuffer.IsSet()) |
|
3994 |
{ |
|
3995 |
r = AllocateBufferData(); |
|
3996 |
if (r != KErrNone) |
|
3997 |
{ |
|
3998 |
Reset(); |
|
3999 |
return NULL; |
|
4000 |
} |
|
4001 |
} |
|
4002 |
SBufferData* data = (SBufferData*)iBufferList.Last(); |
|
4003 |
__NK_ASSERT_DEBUG(!data->iBuffer.IsSet()); |
|
4004 |
return data; |
|
4005 |
} |
|
4006 |
||
4007 |
TInt TClientBufferRequest::EndAddBuffer(TClientBuffer*& aBufOut, SBufferData* aData) |
|
4008 |
{ |
|
4009 |
if (iFlags & EPinVirtual) |
|
4010 |
{ |
|
4011 |
TInt r = Kern::PinVirtualMemory(aData->iPinObject, aData->iBuffer); |
|
4012 |
if (r != KErrNone) |
|
4013 |
{ |
|
4014 |
Reset(); |
|
4015 |
aData->iBuffer.Reset(); |
|
4016 |
aBufOut = 0; |
|
4017 |
return r; |
|
4018 |
} |
|
4019 |
} |
|
4020 |
iBufferList.Rotate(); |
|
4021 |
aBufOut = &aData->iBuffer; |
|
4022 |
return KErrNone; |
|
4023 |
} |
|
4024 |
||
4025 |
/** |
|
4026 |
Associate a user-side descriptor with this request, and optionally pin it. |
|
4027 |
||
4028 |
This method should be called after StartSetup when the client initiates an asynchronous request, in |
|
4029 |
the context of the client thread. If StartSetup has not been called, this method panics. |
|
4030 |
||
4031 |
This method can be called multiple times. |
|
4032 |
||
4033 |
The descriptor header is read into the kernel from the current process' address space, and if |
|
4034 |
requested the memory is pinned. |
|
4035 |
||
4036 |
@return On success, a pointer to a TClientBuffer, which should be used to write to the descriptor. |
|
4037 |
NULL if there was not enough memory to complete the operation. |
|
4038 |
||
4039 |
@publishedPartner |
|
4040 |
@released |
|
4041 |
*/ |
|
4042 |
EXPORT_C TInt TClientBufferRequest::AddBuffer(TClientBuffer*& aBufOut, TAny* aDesPtr) |
|
4043 |
{ |
|
4044 |
SBufferData* data = StartAddBuffer(); |
|
4045 |
if (data == NULL) |
|
4046 |
return KErrNoMemory; |
|
4047 |
data->iBuffer.SetFromDescriptor(aDesPtr); |
|
4048 |
return EndAddBuffer(aBufOut, data); |
|
4049 |
} |
|
4050 |
||
4051 |
/** |
|
4052 |
Associate a user-side memory buffer with this request, and optionally pin it. |
|
4053 |
||
4054 |
This method should be called after StartSetup when the client initiates an asynchronous request, in |
|
4055 |
the context of the client thread. If StartSetup has not been called, this method faults the kernel. |
|
4056 |
||
4057 |
This method can be called multiple times. |
|
4058 |
||
4059 |
If requested, the memory is pinned. |
|
4060 |
||
4061 |
@return On success, a pointer to a TClientBuffer, which can be used to write to the buffer. |
|
4062 |
NULL if there was not enough memory to complete the operation. |
|
4063 |
||
4064 |
@publishedPartner |
|
4065 |
@released |
|
4066 |
*/ |
|
4067 |
EXPORT_C TInt TClientBufferRequest::AddBuffer(TClientBuffer*& aBufOut, TLinAddr aStartAddr, TInt aLength, TBool aWriteable) |
|
4068 |
{ |
|
4069 |
SBufferData* data = StartAddBuffer(); |
|
4070 |
if (data == NULL) |
|
4071 |
return KErrNoMemory; |
|
4072 |
data->iBuffer.SetFromBuffer(aStartAddr, aLength, aWriteable); |
|
4073 |
return EndAddBuffer(aBufOut, data); |
|
4074 |
} |
|
4075 |
||
4076 |
/** |
|
4077 |
Complete the setup process. |
|
4078 |
||
4079 |
This method should always be called if the setup process has completed successfully, after any calls |
|
4080 |
to AddBuffer. It is not necessary to call this if StartSetup or AddBuffer return an error. |
|
4081 |
||
4082 |
This should always be called in the context of the client thread. |
|
4083 |
||
4084 |
@publishedPartner |
|
4085 |
@released |
|
4086 |
*/ |
|
4087 |
EXPORT_C void TClientBufferRequest::EndSetup() |
|
4088 |
{ |
|
4089 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"TClientBufferRequest::EndSetup"); |
|
4090 |
NKern::FMWait(&Lock); |
|
4091 |
if (iSetupThread != TheCurrentThread) |
|
4092 |
K::Fault(K::EBufferRequestEndSetupInWrongState); |
|
4093 |
DThread* thread = iSetupThread; |
|
4094 |
iSetupThread = NULL; |
|
4095 |
NKern::ThreadEnterCS(); |
|
4096 |
NKern::FMSignal(&Lock); |
|
4097 |
thread->Close(NULL); |
|
4098 |
NKern::ThreadLeaveCS(); |
|
4099 |
} |
|
4100 |
||
4101 |
/** |
|
4102 |
Reset this object to allow it be reused, without completing the client request. |
|
4103 |
||
4104 |
This may be called at any time. It must be called in the context of the client thread. |
|
4105 |
||
4106 |
@publishedPartner |
|
4107 |
@released |
|
4108 |
*/ |
|
4109 |
EXPORT_C void TClientBufferRequest::Reset() |
|
4110 |
{ |
|
4111 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"TClientBufferRequest::Reset"); |
|
4112 |
NKern::FMWait(&Lock); |
|
4113 |
TBool inSetup = iSetupThread != NULL; |
|
4114 |
if (inSetup && iSetupThread != TheCurrentThread) |
|
4115 |
K::Fault(K::EBufferRequestResetInWrongState); |
|
4116 |
if (!inSetup) |
|
4117 |
{ |
|
4118 |
TClientRequest::Reset(); |
|
4119 |
NKern::FMSignal(&Lock); |
|
4120 |
return; |
|
4121 |
} |
|
4122 |
NKern::FMSignal(&Lock); |
|
4123 |
SDblQueLink* link = iBufferList.First(); |
|
4124 |
while (link != &iBufferList.iA) |
|
4125 |
{ |
|
4126 |
SBufferData* data = (SBufferData*)link; |
|
4127 |
data->iBuffer.Reset(); |
|
4128 |
if (iFlags & TClientBufferRequest::EPinVirtual) |
|
4129 |
Kern::UnpinVirtualMemory(data->iPinObject); |
|
4130 |
link = data->iNext; |
|
4131 |
} |
|
4132 |
NKern::FMWait(&Lock); |
|
4133 |
TClientRequest::Reset(); |
|
4134 |
DThread* thread = iSetupThread; |
|
4135 |
iSetupThread = NULL; |
|
4136 |
NKern::ThreadEnterCS(); |
|
4137 |
NKern::FMSignal(&Lock); |
|
4138 |
thread->Close(NULL); |
|
4139 |
NKern::ThreadLeaveCS(); |
|
4140 |
} |
|
4141 |
||
4142 |
/** |
|
4143 |
Queue the request for completion. |
|
4144 |
||
4145 |
If the object has not been setup by calling StartSetup/AddBuffer/EndSetup, this method does nothing. |
|
4146 |
Otherwise, if unpins any memory that was pinned by calling AddBuffer, and causes the client's |
|
4147 |
TRequestStatus and any writeable descriptor lengths to be written back to the client thread when it |
|
4148 |
next runs. |
|
4149 |
||
4150 |
This method is not synchronised, and therefore should only ever be called from the context of a |
|
4151 |
single thread (for example a DFC queue thread). Alternatively, an external synchonisation mechanism |
|
4152 |
such as a mutex can be used. |
|
4153 |
||
4154 |
@prototype |
|
4155 |
@internalTechnology |
|
4156 |
*/ |
|
4157 |
EXPORT_C void Kern::QueueBufferRequestComplete(DThread* aThread, TClientBufferRequest* aRequest, TInt aReason) |
|
4158 |
{ |
|
4159 |
aRequest->QueueComplete(aThread, aReason); |
|
4160 |
} |
|
4161 |
||
4162 |
void TClientBufferRequest::QueueComplete(DThread* aThread, TInt aReason) |
|
4163 |
{ |
|
4164 |
NKern::FMWait(&Lock); |
|
4165 |
TBool ready = iSetupThread == NULL && TClientRequest::StartComplete(aThread, aReason); |
|
4166 |
NKern::FMSignal(&Lock); |
|
4167 |
if (!ready) |
|
4168 |
return; |
|
4169 |
if (iFlags & TClientBufferRequest::EPinVirtual) |
|
4170 |
{ |
|
4171 |
SDblQueLink* link = iBufferList.First(); |
|
4172 |
while (link != &iBufferList.iA) |
|
4173 |
{ |
|
4174 |
TClientBufferRequest::SBufferData* data = (TClientBufferRequest::SBufferData*)link; |
|
4175 |
Kern::UnpinVirtualMemory(data->iPinObject); |
|
4176 |
link = data->iNext; |
|
4177 |
} |
|
4178 |
} |
|
4179 |
EndComplete(aThread); |
|
4180 |
} |
|
4181 |
||
4182 |
void TClientBufferRequest::CallbackFunc(TAny* aData, TUserModeCallbackReason aReason) |
|
4183 |
{ |
|
4184 |
TClientBufferRequest* self = (TClientBufferRequest*)aData; |
|
4185 |
||
4186 |
TState state = GetState(self->iStatus); |
|
4187 |
__ASSERT_DEBUG(state == EInUse || state == EClosing, K::Fault(K::EClientRequestCallbackInWrongState)); |
|
4188 |
||
4189 |
if (aReason == EUserModeCallbackRun) |
|
4190 |
{ |
|
4191 |
SDblQueLink* link = self->iBufferList.First(); |
|
4192 |
while (link != &self->iBufferList.iA) |
|
4193 |
{ |
|
4194 |
SBufferData* data = (SBufferData*)link; |
|
4195 |
if (data->iBuffer.IsSet()) |
|
4196 |
{ |
|
4197 |
if (self->iFlags & TClientBufferRequest::EPinVirtual) |
|
4198 |
data->iBuffer.UpdateDescriptorLength(); // ignore error here |
|
4199 |
data->iBuffer.Reset(); |
|
4200 |
} |
|
4201 |
link = data->iNext; |
|
4202 |
} |
|
4203 |
} |
|
4204 |
||
4205 |
if (state == EClosing) |
|
4206 |
{ |
|
4207 |
SBufferData* item; |
|
4208 |
while(item = (SBufferData*)(self->iBufferList.GetFirst()), item != NULL) |
|
4209 |
{ |
|
4210 |
Kern::DestroyVirtualPinObject(item->iPinObject); |
|
4211 |
Kern::AsyncFree(item); |
|
4212 |
} |
|
4213 |
} |
|
4214 |
||
4215 |
TClientRequest::CallbackFunc(aData, aReason); |
|
4216 |
} |
|
4217 |
||
4218 |
// Implementation of kernel pin APIs |
|
4219 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4220 |
/** |
0 | 4221 |
Create an object which can be used to pin virtual memory. |
4222 |
||
4223 |
@param aPinObject A reference to a pointer which is set to the newly-created object on success. |
|
4224 |
||
4225 |
@return KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
4226 |
||
4227 |
@pre Calling thread must be in a critical section |
|
4228 |
@pre Interrupts must be enabled. |
|
4229 |
@pre Kernel must be unlocked. |
|
4230 |
@pre No fast mutex can be held. |
|
4231 |
@pre Call in a thread context. |
|
4232 |
@pre Suitable for use in a device driver. |
|
4233 |
||
4234 |
@see Kern::DestroyVirtualPinObject() |
|
4235 |
||
4236 |
@prototype |
|
4237 |
*/ |
|
4238 |
EXPORT_C TInt Kern::CreateVirtualPinObject(TVirtualPinObject*& aPinObject) |
|
4239 |
{ |
|
4240 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CreateVirtualPinObject"); |
|
4241 |
return M::CreateVirtualPinObject(aPinObject); |
|
4242 |
} |
|
4243 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4244 |
/** |
0 | 4245 |
Pin an area of virtual memory. |
4246 |
||
4247 |
The act of pinning virtual memory means that the memory in the specified virtual address range is |
|
4248 |
guaranteed to remain in system RAM while it is pinned, unless it is decommited. The actual physical |
|
4249 |
RAM used is not guaranteed to stay the same however, as it could be replaced in the process of RAM |
|
4250 |
defragmentation. |
|
4251 |
||
4252 |
This operation is provided to enable device drivers to pin client memory in the context of the |
|
4253 |
client thread, so that when it is accessed from a different thread later on (for example from a DFC |
|
4254 |
thread) there is no possibility of taking page faults. |
|
4255 |
||
4256 |
Note that this operation may fail with KErrNoMemory. |
|
4257 |
||
4258 |
@param aPinObject A virtual pin object previously created by calling Kern::CreateVirtualPinObject(). |
|
4259 |
@param aStart The start address of the memory to pin. |
|
4260 |
@param aSize The size of the memory to pin in bytes. |
|
4261 |
@param aThread The thread that owns the memory to pin, or NULL to use the current thread. |
|
4262 |
||
4263 |
@return KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
4264 |
||
4265 |
@pre Interrupts must be enabled. |
|
4266 |
@pre Kernel must be unlocked. |
|
4267 |
@pre No fast mutex can be held. |
|
4268 |
@pre Call in a thread context. |
|
4269 |
@pre Can be used in a device driver. |
|
4270 |
||
4271 |
@see Kern::UnpinVirtualMemory() |
|
4272 |
||
4273 |
@prototype |
|
4274 |
*/ |
|
4275 |
EXPORT_C TInt Kern::PinVirtualMemory(TVirtualPinObject* aPinObject, TLinAddr aStart, TUint aSize, DThread* aThread) |
|
4276 |
{ |
|
4277 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::PinVirtualMemory"); |
|
4278 |
if (aThread == NULL) |
|
4279 |
aThread = TheCurrentThread; |
|
4280 |
if (aSize == 0) |
|
4281 |
return KErrNone; |
|
4282 |
NKern::ThreadEnterCS(); |
|
4283 |
TInt r = M::PinVirtualMemory(aPinObject, aStart, aSize, aThread); |
|
4284 |
NKern::ThreadLeaveCS(); |
|
4285 |
return r; |
|
4286 |
} |
|
4287 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4288 |
/** |
0 | 4289 |
Pin an area of virtual memory. |
4290 |
||
4291 |
The act of pinning virtual memory means that the memory in the specified virtual address range is |
|
4292 |
guaranteed to remain in system RAM while it is pinned, unless it is decommited. The actual phyiscal |
|
4293 |
RAM used is not guaranteed to stay the same however, as it could be replaced in the process of RAM |
|
4294 |
defragmentation. |
|
4295 |
||
4296 |
This operation is provided to enable device drivers to pin client memory in the context of the |
|
4297 |
client thread, so that when it is accessed from a different thread later on (for example from a DFC |
|
4298 |
thread) there is no possibility of taking page faults. |
|
4299 |
||
4300 |
Note that this operation may fail with KErrNoMemory. |
|
4301 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4302 |
Note - Instances of TVirtualPinObject are not protected from concurrent operations being performed |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4303 |
with them by separate threads i.e. it is the responsibility of the creator of a TVirtualPinObject |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4304 |
instance to ensure that it will not be pinned, unpinned or destroyed by more than one thread at a time. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4305 |
|
0 | 4306 |
@param aPinObject A virtual pin object previously created by calling Kern::CreateVirtualPinObject(). |
4307 |
@param aDes A TClientBuffer object representing a client descriptor to pin. |
|
4308 |
@param aThread The thread that owns the memory to pin, or NULL to use the current thread. |
|
4309 |
||
4310 |
@return KErrNone, if successful, otherwse one of the other system-wide error codes. |
|
4311 |
||
4312 |
@pre Interrupts must be enabled. |
|
4313 |
@pre Kernel must be unlocked. |
|
4314 |
@pre No fast mutex can be held. |
|
4315 |
@pre Call in a thread context. |
|
4316 |
@pre Can be used in a device driver. |
|
4317 |
||
4318 |
@see Kern::UnpinVirtualMemory() |
|
4319 |
||
4320 |
@prototype |
|
4321 |
*/ |
|
4322 |
EXPORT_C TInt Kern::PinVirtualMemory(TVirtualPinObject* aPinObject, const TClientBuffer& aDes, DThread* aThread) |
|
4323 |
{ |
|
4324 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::PinVirtualMemory"); |
|
4325 |
if (aThread == NULL) |
|
4326 |
aThread = TheCurrentThread; |
|
4327 |
TInt length = aDes.IsWriteable() ? aDes.MaxLength() : aDes.Length(); |
|
4328 |
if (length < 0) |
|
4329 |
return length; |
|
4330 |
if (length == 0) |
|
4331 |
return KErrNone; |
|
4332 |
NKern::ThreadEnterCS(); |
|
4333 |
TInt r = M::PinVirtualMemory(aPinObject, (TLinAddr)aDes.DataPtr(), length, aThread); |
|
4334 |
NKern::ThreadLeaveCS(); |
|
4335 |
return r; |
|
4336 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4337 |
/** |
0 | 4338 |
Create a pin object and then pin an area of virtual memory in the current address space. If |
4339 |
an error occurs then no pin object will exist |
|
4340 |
||
4341 |
The act of pinning virtual memory means that the memory in the specified virtual address range is |
|
4342 |
guaranteed to remain in system RAM while it is pinned, unless it is decommited. The actual physical |
|
4343 |
RAM used is not guaranteed to stay the same however, as it could be replaced in the process of RAM |
|
4344 |
defragmentation. |
|
4345 |
||
4346 |
This operation is provided to enable device drivers to pin client memory in the context of the |
|
4347 |
client thread, so that when it is accessed from a different thread later on (for example from a DFC |
|
4348 |
thread) there is no possibility of taking page faults. |
|
4349 |
||
4350 |
Note that this operation may fail with KErrNoMemory. |
|
4351 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4352 |
Note - Instances of TVirtualPinObject are not protected from concurrent operations being performed |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4353 |
with them by separate threads i.e. it is the responsibility of the creator of a TVirtualPinObject |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4354 |
instance to ensure that it will not be pinned, unpinned or destroyed by more than one thread at a time. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4355 |
|
0 | 4356 |
@param aPinObject A reference to a pointer which is set to the newly-created object on success. |
4357 |
@param aStart The start address of the memory to pin. |
|
4358 |
@param aSize The size of the memory to pin in bytes. |
|
4359 |
||
4360 |
@return KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
4361 |
||
4362 |
@pre Calling thread must be in a critical section |
|
4363 |
@pre Interrupts must be enabled. |
|
4364 |
@pre Kernel must be unlocked. |
|
4365 |
@pre No fast mutex can be held. |
|
4366 |
@pre Call in a thread context. |
|
4367 |
@pre Can be used in a device driver. |
|
4368 |
||
4369 |
@see Kern::UnpinVirtualMemory() |
|
4370 |
@see Kern::DestroyVirtualPinObject() |
|
4371 |
||
4372 |
@prototype |
|
4373 |
*/ |
|
4374 |
EXPORT_C TInt Kern::CreateAndPinVirtualMemory(TVirtualPinObject*& aPinObject, TLinAddr aStart, TUint aSize) |
|
4375 |
{ |
|
4376 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CreateAndPinVirtualMemory"); |
|
4377 |
return M::CreateAndPinVirtualMemory(aPinObject, aStart, aSize); |
|
4378 |
} |
|
4379 |
||
4380 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4381 |
/** |
0 | 4382 |
Unpin an area of memory previously pinned by calling Kern::PinVirtualMemory(). |
4383 |
||
4384 |
@param aPinObject The virtual pin object used to pin the memory. |
|
4385 |
||
4386 |
@pre Interrupts must be enabled. |
|
4387 |
@pre Kernel must be unlocked. |
|
4388 |
@pre No fast mutex can be held. |
|
4389 |
@pre Call in a thread context. |
|
4390 |
@pre Can be used in a device driver. |
|
4391 |
||
4392 |
@see Kern::PinVirtualMemory() |
|
4393 |
||
4394 |
@prototype |
|
4395 |
*/ |
|
4396 |
EXPORT_C void Kern::UnpinVirtualMemory(TVirtualPinObject* aPinObject) |
|
4397 |
{ |
|
4398 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::UnpinVirtualMemory"); |
|
4399 |
NKern::ThreadEnterCS(); |
|
4400 |
M::UnpinVirtualMemory(aPinObject); |
|
4401 |
NKern::ThreadLeaveCS(); |
|
4402 |
} |
|
4403 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4404 |
/** |
0 | 4405 |
Dispose of a virtual pin object which is no longer required. |
4406 |
||
4407 |
Any memory pinned by the object is unpinned first. |
|
4408 |
||
4409 |
@param aPinObject A reference to a pointer to the pin object to destroy. |
|
4410 |
This pointer will be set to NULL on return. |
|
4411 |
||
4412 |
@pre Calling thread must be in a critical section |
|
4413 |
@pre Interrupts must be enabled. |
|
4414 |
@pre Kernel must be unlocked. |
|
4415 |
@pre No fast mutex can be held. |
|
4416 |
@pre Call in a thread context. |
|
4417 |
@pre Suitable for use in a device driver. |
|
4418 |
||
4419 |
@see Kern::CreateVirtualPinObject() |
|
4420 |
||
4421 |
@prototype |
|
4422 |
*/ |
|
4423 |
EXPORT_C void Kern::DestroyVirtualPinObject(TVirtualPinObject*& aPinObject) |
|
4424 |
{ |
|
4425 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DestroyVirtualPinObject"); |
|
4426 |
M::DestroyVirtualPinObject(aPinObject); |
|
4427 |
} |
|
4428 |
||
4429 |
/** |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4430 |
Creates an object which is used to pin physical memory. Supported by Kernel running flexible memory model. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4431 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4432 |
Note - Instances of TPhysicalPinObject are not protected from concurrent operations being performed |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4433 |
with them by separate threads i.e. it is the responsibility of the creator of a TPhysicalPinObject |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4434 |
instance to ensure that it will not be pinned, unpinned or destroyed by more than one thread at a time. |
0 | 4435 |
|
4436 |
@param aPinObject A reference to a pointer which is set to the newly-created object on success. |
|
4437 |
||
4438 |
@return KErrNotSupported on memory models other then flexible. |
|
4439 |
KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
4440 |
||
4441 |
@pre Calling thread must be in a critical section |
|
4442 |
@pre Interrupts must be enabled. |
|
4443 |
@pre Kernel must be unlocked. |
|
4444 |
@pre No fast mutex can be held. |
|
4445 |
@pre Call in a thread context. |
|
4446 |
@pre Suitable for use in a device driver. |
|
4447 |
||
4448 |
@see Kern::DestroyPhysicalPinObject() |
|
4449 |
||
4450 |
@prototype |
|
4451 |
*/ |
|
4452 |
EXPORT_C TInt Kern::CreatePhysicalPinObject(TPhysicalPinObject*& aPinObject) |
|
4453 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4454 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CreatePhysicalPinObject"); |
0 | 4455 |
return M::CreatePhysicalPinObject(aPinObject); |
4456 |
} |
|
4457 |
||
4458 |
/** |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4459 |
Pins an area of physical memory. Supported by Kernel running flexible memory model. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4460 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4461 |
The physical memory to pin is defined by its existing virtual mapping (by aStart, aSize & aThread parameters). |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4462 |
On return, aAddress will hold physical address (if memory is mapped contigiously) and aPages |
0 | 4463 |
area will be populated with the list of physical pages of the mapping. aColour will hold the mapping colour |
4464 |
of the first physical page in the mapping. |
|
4465 |
||
4466 |
This operation is provided to enable device drivers to operate DMA transfers on memory which is not mapped to |
|
4467 |
Kernel address space (but to user client's, instead). |
|
4468 |
||
4469 |
The act of pinning physical memory means that it is guaranteed to be excluded from RAM defragmentation. |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4470 |
However, it can still be the subject of demand paging. Physically pinned memory is also guaranteed not to be |
0 | 4471 |
reused for some other purpose - even if the process owning the memory decommits it or terminates. |
4472 |
||
4473 |
Note that this operation may fail with KErrNoMemory. |
|
4474 |
||
4475 |
@param aPinObject A physical pin object previously created by calling Kern::CreatePhysicalPinObject(). |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4476 |
@param aStart Virtual address of memory to pin. |
0 | 4477 |
@param aSize The length (in bytes) of memory to pin. |
4478 |
@param aThread The thread that owns the memory to pin, or NULL to use the current thread. |
|
4479 |
@param aReadOnlyMemory Set to ETrue if the content of physical memory is not going to change while being |
|
4480 |
pinned, e.g. if it is DMA copied into H/W. Set to EFalse otherwise. |
|
4481 |
Setting this argument to ETrue will improve the performance when/if memory is paged out. |
|
4482 |
@param aAddress On success, this value is set to one of two values: |
|
4483 |
- If the specified region is physically contiguous, the value is the |
|
4484 |
physical address of the first byte in the region. |
|
4485 |
- If the region is discontiguous, the value is set to KPhysAddrInvalid. |
|
4486 |
@param aPages Points to area of TPhysAddr which will on exit hold the addresses of the physical pages contained |
|
4487 |
in the specified region. The array must be large enough to hold the whole list of pages in the region. |
|
4488 |
If aPageList is zero , then the function will fail with KErrNotFound if the specified region |
|
4489 |
is not physically contiguous. |
|
4490 |
@param aMapAttr On success, this is set to the mmu mapping attributes used for the memory. This |
|
4491 |
is a value constructed from the bit masks in the enumeration TMappingAttributes. The typical |
|
4492 |
use for this value is to use it as an argument to to Kernel's Sync Physical Memory interface. |
|
4493 |
||
4494 |
@param aColour On exit, holds the mapping colour of the first physical page in the mapping. Device drivers |
|
4495 |
have no use of this value but to pass to Kernel's Sync Physical Memory interface. |
|
4496 |
||
4497 |
@return KErrNotSupported on memory models other then flexible. |
|
4498 |
KErrNone, if successful, otherwise one of the other system-wide error codes. |
|
4499 |
||
4500 |
@pre Interrupts must be enabled. |
|
4501 |
@pre Kernel must be unlocked. |
|
4502 |
@pre No fast mutex can be held. |
|
4503 |
@pre Call in a thread context. |
|
4504 |
@pre Can be used in a device driver. |
|
4505 |
||
4506 |
@see Kern::UnpinPhysicalMemory() |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4507 |
@see Cache::SyncPhysicalMemoryBeforeDmaWrite() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4508 |
@see Cache::SyncPhysicalMemoryBeforeDmaRead() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4509 |
@see Cache::SyncPhysicalMemoryAfterDmaRead() |
0 | 4510 |
@prototype |
4511 |
*/ |
|
4512 |
EXPORT_C TInt Kern::PinPhysicalMemory(TPhysicalPinObject* aPinObject, TLinAddr aStart, TUint aSize, TBool aReadOnlyMemory, |
|
4513 |
TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour, DThread* aThread) |
|
4514 |
{ |
|
4515 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::PinPhysicalMemory"); |
|
4516 |
if (aThread == NULL) |
|
4517 |
aThread = TheCurrentThread; |
|
4518 |
if (aSize == 0) |
|
4519 |
return KErrNone; |
|
4520 |
NKern::ThreadEnterCS(); |
|
4521 |
TInt r = M::PinPhysicalMemory(aPinObject, aStart, aSize, aReadOnlyMemory, aAddress, aPages, aMapAttr, aColour, aThread); |
|
4522 |
NKern::ThreadLeaveCS(); |
|
4523 |
return r; |
|
4524 |
} |
|
4525 |
||
4526 |
/** |
|
4527 |
Unpins an area of physical memory previously pinned by calling Kern::PinPhysicalMemory(). |
|
4528 |
||
4529 |
@param aPinObject The physical pin object used to pin the memory. |
|
4530 |
||
4531 |
@pre Interrupts must be enabled. |
|
4532 |
@pre Kernel must be unlocked. |
|
4533 |
@pre No fast mutex can be held. |
|
4534 |
@pre Call in a thread context. |
|
4535 |
@pre Can be used in a device driver. |
|
4536 |
||
4537 |
@return KErrNotSupported on memory models other then flexible. |
|
4538 |
KErrNone, on flexible memory model. |
|
4539 |
||
4540 |
@see Kern::PinPhysicalMemory() |
|
4541 |
||
4542 |
@prototype |
|
4543 |
*/ |
|
4544 |
EXPORT_C TInt Kern::UnpinPhysicalMemory(TPhysicalPinObject* aPinObject) |
|
4545 |
{ |
|
4546 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::UnpinPhysicalMemory"); |
|
4547 |
NKern::ThreadEnterCS(); |
|
4548 |
M::UnpinPhysicalMemory(aPinObject); |
|
4549 |
NKern::ThreadLeaveCS(); |
|
4550 |
return KErrNone; |
|
4551 |
} |
|
4552 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4553 |
/** |
0 | 4554 |
Dispose of a physical pin object which is no longer required. |
4555 |
||
4556 |
Any memory pinned by the object is unpinned first. |
|
4557 |
||
4558 |
@param aPinObject A reference to a pointer to the pin object to destroy. |
|
4559 |
This pointer will be set to NULL on return. |
|
4560 |
||
4561 |
@pre Calling thread must be in a critical section |
|
4562 |
@pre Interrupts must be enabled. |
|
4563 |
@pre Kernel must be unlocked. |
|
4564 |
@pre No fast mutex can be held. |
|
4565 |
@pre Call in a thread context. |
|
4566 |
@pre Suitable for use in a device driver. |
|
4567 |
||
4568 |
@return KErrNotSupported on memory models other then flexible. |
|
4569 |
KErrNone, on flexible memory model. |
|
4570 |
||
4571 |
@see Kern::CreatePhysicalPinObject() |
|
4572 |
||
4573 |
@prototype |
|
4574 |
*/ |
|
4575 |
EXPORT_C TInt Kern::DestroyPhysicalPinObject(TPhysicalPinObject*& aPinObject) |
|
4576 |
{ |
|
4577 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DestroyPhysicalPinObject"); |
|
4578 |
M::DestroyPhysicalPinObject(aPinObject); |
|
4579 |
return KErrNone; |
|
4580 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4581 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4582 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4583 |
/** |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4584 |
Creates an object which is used to map user side memory in the kernel address space |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4585 |
and also physically pin the memory. Supported by Kernel running the flexible memory model. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4586 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4587 |
When the map object will only be used to map non-demand paged memory aMaxReserveSize can be used |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4588 |
to pre-reserve the resources that would be required for Kern::MapAndPinMemory(). This will |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4589 |
prevent Kern::MapAndPinMemory() failing due to low memory and will reduce the time to execute |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4590 |
Kern::MapAndPinMemory() but only when the mapping object is used to map non-demand paged memory. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4591 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4592 |
Note - Instances of TKernelMapObject are not protected from concurrent operations being performed |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4593 |
with them by separate threads i.e. it is the responsibility of the creator of a TKernelMapObject |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4594 |
instance to ensure that it will not be mapped, unmapped or destroyed by more than one thread at a time. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4595 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4596 |
@param aMapObject A reference to a pointer which is set to the newly created object on success. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4597 |
@param aMaxReserveSize When set to zero (the default) the resources required to map memory will be |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4598 |
allocated when Kern::MapAndPinMemory() is invoked with the newly created map |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4599 |
object. When not set to zero all resources required for the mapping object |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4600 |
to map up to aMaxReserveSize bytes will be reserved when creating the mapping |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4601 |
object. When the mapping object is used to map non-demand paged memory, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4602 |
this will prevent Kern::MapAndPinMemory() from returning KErrNoMemory |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4603 |
when invoked with the mapping object. However, it will limit the mapping |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4604 |
object to being able to map a maximum of aMaxReserveSize bytes and may also |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4605 |
waste resources if it is used to map less than aMaxReserveSize bytes. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4606 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4607 |
@return KErrNotSupported on memory models other then flexible. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4608 |
KErrNone, if successful, otherwise one of the other system-wide error codes. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4609 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4610 |
@pre Calling thread must be in a critical section |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4611 |
@pre Interrupts must be enabled. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4612 |
@pre Kernel must be unlocked. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4613 |
@pre No fast mutex can be held. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4614 |
@pre Call in a thread context. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4615 |
@pre Suitable for use in a device driver. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4616 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4617 |
@see Kern::DestroyKernelMapObject() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4618 |
@see Kern::MapAndPinMemory() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4619 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4620 |
@prototype |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4621 |
*/ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4622 |
EXPORT_C TInt Kern::CreateKernelMapObject(TKernelMapObject*& aMapObject, TUint aMaxReserveSize) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4623 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4624 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CreateKernelMapObject"); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4625 |
return M::CreateKernelMapObject(aMapObject, aMaxReserveSize); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4626 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4627 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4628 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4629 |
/** |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4630 |
Maps an area of memory into the kernel address space and physically pins it. Supported by Kernel running |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4631 |
the flexible memory model. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4632 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4633 |
The memory to map and pin is defined by its existing virtual mapping (via the aStart, aSize & aThread parameters). |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4634 |
On return, if aPages is not NULL, aPages will be populated with the list of physical pages mapped. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4635 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4636 |
This operation is provided to enable device drivers to not only operate DMA transfers on memory which was not |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4637 |
originally mapped to the kernel address space (but to user client's, instead) but also read or modify the data |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4638 |
from kernel context, e.g. a DFC. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4639 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4640 |
The act of mapping the memory means that it is guaranteed to be excluded from RAM defragmentation. The new mapping |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4641 |
will also be protected from the effects of demand paging. Once mapped the memory is also guaranteed not to be reused for |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4642 |
some other purpose - even if the process owning the memory decommits it or terminates. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4643 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4644 |
Note that this operation may fail with KErrNoMemory if the kernel mapping object was created with aMaxReserveSize==0 |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4645 |
or the memory to be mapped is demand paged. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4646 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4647 |
@param aMapObject A kernel map object previously created by calling Kern::CreateKernelMapObject(). |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4648 |
@param aThread The thread that owns the memory to map, or NULL to use the current thread. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4649 |
@param aStart Virtual address of memory to map. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4650 |
@param aSize The length (in bytes) of memory to map. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4651 |
@param aMapAttributes A bit mask of TKernelMapAttributes attributes for the mapping. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4652 |
@param aKernelAddr Set to the base linear address of the new kernel mapping. This is the address to use when accessing |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4653 |
the memory from kernel side and to pass to cache maintence operations before and after performing |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4654 |
DMA operations. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4655 |
@param aPages Points to area of TPhysAddr which will on exit hold the addresses of the physical pages contained |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4656 |
in the specified region. The array must be large enough to hold the whole list of pages in the region. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4657 |
Set aPages to NULL if the physical addresses of the pages being mapped are not required. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4658 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4659 |
@return KErrNone, if successful, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4660 |
KErrInUse if aMapObject is already mapping some memory, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4661 |
KErrArgument if aSize is larger than the argument aMaxReserveSize of Kern::CreateKernelMapObject() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4662 |
when creating aMapObject or aMapAttributes has invalid bits set. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4663 |
KErrNotSupported on memory models other then flexible. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4664 |
Otherwise one of the other system-wide error codes. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4665 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4666 |
@pre Interrupts must be enabled. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4667 |
@pre Kernel must be unlocked. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4668 |
@pre No fast mutex can be held. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4669 |
@pre Call in a thread context. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4670 |
@pre Can be used in a device driver. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4671 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4672 |
@see Kern::UnmapAndUnpinMemory() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4673 |
@see Cache::SyncMemoryBeforeDmaWrite() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4674 |
@see Cache::SyncMemoryBeforeDmaRead() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4675 |
@see Cache::SyncMemoryAfterDmaRead() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4676 |
@prototype |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4677 |
*/ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4678 |
EXPORT_C TInt Kern::MapAndPinMemory(TKernelMapObject* aMapObject, DThread* aThread, TLinAddr aStart, TUint aSize, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4679 |
TUint aMapAttributes, TLinAddr& aKernelAddr, TPhysAddr* aPages) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4680 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4681 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::MapAndPinMemory"); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4682 |
if (~EKernelMap_ValidMask & aMapAttributes) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4683 |
{// Invalid mapping attribute flags set. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4684 |
return KErrArgument; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4685 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4686 |
if (aThread == NULL) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4687 |
aThread = TheCurrentThread; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4688 |
if (aSize == 0) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4689 |
return KErrNone; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4690 |
NKern::ThreadEnterCS(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4691 |
TInt r = M::MapAndPinMemory(aMapObject, aThread, aStart, aSize, aMapAttributes, aKernelAddr, aPages); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4692 |
NKern::ThreadLeaveCS(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4693 |
return r; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4694 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4695 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4696 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4697 |
/** |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4698 |
Unmaps and unpins an area of memory previously mapped by calling Kern::MapAndPinMemory(). |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4699 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4700 |
@param aMapObject The kernel mapping object used to map and pin the memory. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4701 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4702 |
@pre Interrupts must be enabled. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4703 |
@pre Kernel must be unlocked. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4704 |
@pre No fast mutex can be held. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4705 |
@pre Call in a thread context. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4706 |
@pre Can be used in a device driver. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4707 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4708 |
@see Kern::MapAndPinMemory() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4709 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4710 |
@prototype |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4711 |
*/ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4712 |
EXPORT_C void Kern::UnmapAndUnpinMemory(TKernelMapObject* aMapObject) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4713 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4714 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::UnmapAndUnpinMemory"); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4715 |
NKern::ThreadEnterCS(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4716 |
M::UnmapAndUnpinMemory(aMapObject); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4717 |
NKern::ThreadLeaveCS(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4718 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4719 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4720 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4721 |
/** |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4722 |
Dispose of a kernel mapping object which is no longer required. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4723 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4724 |
Any memory mapped and pinned by the object is unmapped and unpinned first. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4725 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4726 |
@param aMapObject A reference to a pointer to the mapping object to destroy. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4727 |
This pointer will be set to NULL on return. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4728 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4729 |
@pre Calling thread must be in a critical section |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4730 |
@pre Interrupts must be enabled. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4731 |
@pre Kernel must be unlocked. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4732 |
@pre No fast mutex can be held. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4733 |
@pre Call in a thread context. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4734 |
@pre Suitable for use in a device driver. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4735 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4736 |
@see Kern::CreateKernelMapObject() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4737 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4738 |
@prototype |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4739 |
*/ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4740 |
EXPORT_C void Kern::DestroyKernelMapObject(TKernelMapObject*& aMapObject) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4741 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4742 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::DestroyKernelMapObject"); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4743 |
M::DestroyKernelMapObject(aMapObject); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
4744 |
} |