|
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\include\kernel\kernel.h |
|
15 // Public header for device drivers |
|
16 // |
|
17 // WARNING: This file contains some APIs which are internal and are subject |
|
18 // to change without notice. Such APIs should therefore not be used |
|
19 // outside the Kernel and Hardware Services package. |
|
20 // |
|
21 |
|
22 |
|
23 #ifndef __K32STD_H__ |
|
24 #define __K32STD_H__ |
|
25 |
|
26 #include <kernel/klib.h> |
|
27 #include <e32kpan.h> |
|
28 #include <u32std.h> |
|
29 #include <e32ldr.h> |
|
30 #include <e32event.h> |
|
31 #include <e32event_private.h> |
|
32 #include <d32locd.h> |
|
33 #include <kernel/localise.h> |
|
34 #include <nkern.h> |
|
35 #include <kernel/sproperty.h> |
|
36 |
|
37 class DObject; |
|
38 class DObjectCon; |
|
39 class DThread; |
|
40 class DCodeSeg; |
|
41 class DProcess; |
|
42 class DLibrary; |
|
43 class DMutex; |
|
44 class DSemaphore; |
|
45 class DChunk; |
|
46 class DShPool; |
|
47 class DShBuf; |
|
48 |
|
49 |
|
50 /** Data type for physical addresses |
|
51 @publishedPartner |
|
52 @released |
|
53 */ |
|
54 typedef TUint32 TPhysAddr; |
|
55 |
|
56 |
|
57 /** |
|
58 A constant representing an invalid physical address. |
|
59 @publishedPartner |
|
60 @released |
|
61 */ |
|
62 const TPhysAddr KPhysAddrInvalid=0xFFFFFFFFu; |
|
63 |
|
64 |
|
65 /** @internalComponent */ |
|
66 _LIT(KLitKernExec, "KERN-EXEC"); |
|
67 |
|
68 /******************************************** |
|
69 * HAL entry array |
|
70 ********************************************/ |
|
71 |
|
72 /** @internalTechnology */ |
|
73 const TInt KMaxHalGroups=32; |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 /** |
|
79 @publishedPartner |
|
80 @released |
|
81 |
|
82 Defines the signature for a HAL handler function. |
|
83 */ |
|
84 typedef TInt (*THalFunc)(TAny*,TInt,TAny*,TAny*); |
|
85 |
|
86 /** @internalTechnology */ |
|
87 const TInt KMaxHalEntries=8; |
|
88 |
|
89 /** @internalTechnology */ |
|
90 struct SHalEntry |
|
91 { |
|
92 THalFunc iFunction; |
|
93 TAny* iPtr; |
|
94 }; |
|
95 |
|
96 /** @internalTechnology */ |
|
97 struct SHalEntry2 : public SHalEntry |
|
98 { |
|
99 SHalEntry* iExtendedEntries; |
|
100 }; |
|
101 |
|
102 /******************************************** |
|
103 * Exports from layer 1 of the kernel |
|
104 ********************************************/ |
|
105 class TThreadMessage; |
|
106 class DObjectCon; |
|
107 class DPowerModel; |
|
108 class TSuperPage; |
|
109 class TMachineConfig; |
|
110 |
|
111 /******************************************** |
|
112 * Thread creation info block |
|
113 ********************************************/ |
|
114 |
|
115 /** |
|
116 @publishedPartner |
|
117 @released |
|
118 |
|
119 Defines a set of thread types. |
|
120 */ |
|
121 enum TThreadType |
|
122 { |
|
123 /** The thread is the initial thread |
|
124 @internalComponent |
|
125 */ |
|
126 EThreadInitial, |
|
127 |
|
128 /** The thread runs in supervisor mode */ |
|
129 EThreadSupervisor, |
|
130 |
|
131 /** The thread runs in supervisor mode and has no handles array */ |
|
132 EThreadMinimalSupervisor, |
|
133 |
|
134 /** The thread runs in user mode */ |
|
135 EThreadUser, |
|
136 |
|
137 /** The thread is the initial thread on a non-boot processor (SMP only) |
|
138 @internalComponent |
|
139 */ |
|
140 EThreadAPInitial, |
|
141 }; |
|
142 |
|
143 /******************************************** |
|
144 * Kernel Mutex Ordering |
|
145 ********************************************/ |
|
146 const TUint8 KMutexOrdNone = 0xff; /**< @internalComponent */ |
|
147 const TUint8 KMutexOrdUser = 0xfe; /**< @internalComponent */ |
|
148 |
|
149 /** |
|
150 Mutex order value for general purpose use. This value is higher than any used internally |
|
151 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
152 functions may be called whilst a mutex of this order is held. |
|
153 @see Kern::MutexCreate() |
|
154 @publishedPartner |
|
155 @released |
|
156 */ |
|
157 const TUint8 KMutexOrdGeneral7 = 0xf7; |
|
158 |
|
159 /** |
|
160 Mutex order value for general purpose use. This value is higher than any used internally |
|
161 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
162 functions may be called whilst a mutex of this order is held. |
|
163 @see Kern::MutexCreate() |
|
164 @publishedPartner |
|
165 @released |
|
166 */ |
|
167 const TUint8 KMutexOrdGeneral6 = 0xf6; |
|
168 |
|
169 /** |
|
170 Mutex order value for general purpose use. This value is higher than any used internally |
|
171 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
172 functions may be called whilst a mutex of this order is held. |
|
173 @see Kern::MutexCreate() |
|
174 @publishedPartner |
|
175 @released |
|
176 */ |
|
177 const TUint8 KMutexOrdGeneral5 = 0xf5; |
|
178 |
|
179 /** |
|
180 Mutex order value for general purpose use. This value is higher than any used internally |
|
181 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
182 functions may be called whilst a mutex of this order is held. |
|
183 @see Kern::MutexCreate() |
|
184 @publishedPartner |
|
185 @released |
|
186 */ |
|
187 const TUint8 KMutexOrdGeneral4 = 0xf4; |
|
188 |
|
189 /** |
|
190 Mutex order value for general purpose use. This value is higher than any used internally |
|
191 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
192 functions may be called whilst a mutex of this order is held. |
|
193 @see Kern::MutexCreate() |
|
194 @publishedPartner |
|
195 @released |
|
196 */ |
|
197 const TUint8 KMutexOrdGeneral3 = 0xf3; |
|
198 |
|
199 /** |
|
200 Mutex order value for general purpose use. This value is higher than any used internally |
|
201 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
202 functions may be called whilst a mutex of this order is held. |
|
203 @see Kern::MutexCreate() |
|
204 @publishedPartner |
|
205 @released |
|
206 */ |
|
207 const TUint8 KMutexOrdGeneral2 = 0xf2; |
|
208 |
|
209 /** |
|
210 Mutex order value for general purpose use. This value is higher than any used internally |
|
211 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
212 functions may be called whilst a mutex of this order is held. |
|
213 @see Kern::MutexCreate() |
|
214 @publishedPartner |
|
215 @released |
|
216 */ |
|
217 const TUint8 KMutexOrdGeneral1 = 0xf1; |
|
218 |
|
219 /** |
|
220 Mutex order value for general purpose use. This value is higher than any used internally |
|
221 by the kernel, therefore there are no mutex ordering restrictions that limit which kernel |
|
222 functions may be called whilst a mutex of this order is held. |
|
223 @see Kern::MutexCreate() |
|
224 @publishedPartner |
|
225 @released |
|
226 */ |
|
227 const TUint8 KMutexOrdGeneral0 = 0xf0; |
|
228 |
|
229 |
|
230 const TUint8 KMutexOrdRamDrive = KMutexOrdGeneral7; /**< @internalComponent */ |
|
231 const TUint8 KMutexOrdShPool = 0x68; /**< @internalComponent */ |
|
232 const TUint8 KMutexOrdCodeSegLock = 0x60; /**< @internalComponent */ |
|
233 const TUint8 KMutexOrdPubSub2 = 0x5e; /**< @internalComponent */ |
|
234 |
|
235 /** |
|
236 @internalComponent |
|
237 @prototype |
|
238 */ |
|
239 const TUint8 KMutexOrdPageIn = 0x5c; |
|
240 |
|
241 const TUint8 KMutexOrdRamDefrag = 0x59; /**< @internalComponent */ |
|
242 const TUint8 KMutexOrdPowerMgr = 0x58; /**< @internalComponent */ |
|
243 const TUint8 KMutexOrdPubSub = 0x50; /**< @internalComponent */ |
|
244 const TUint8 KMutexOrdProcessLock = 0x48; /**< @internalComponent */ |
|
245 const TUint8 KMutexOrdDebug = 0x47; /**< @internalComponent */ |
|
246 const TUint8 KMutexOrdTimer = 0x40; /**< @internalComponent */ |
|
247 const TUint8 KMutexOrdObjectCon2 = 0x38; /**< @internalComponent */ // servers |
|
248 const TUint8 KMutexOrdHandle = 0x30; /**< @internalComponent */ |
|
249 const TUint8 KMutexOrdObjectCon = 0x28; /**< @internalComponent */ |
|
250 const TUint8 KMutexOrdMachineConfig = 0x20; /**< @internalComponent */ |
|
251 const TUint8 KMutexOrdHwChunk = 0x10; /**< @internalComponent */ |
|
252 const TUint8 KMutexOrdKernelHeap = 0x08; /**< @internalComponent */ |
|
253 const TUint8 KMutexOrdRamAlloc = 0x04; /**< @internalComponent */ |
|
254 #if defined(__MEMMODEL_FLEXIBLE__) |
|
255 const TUint8 KMutexOrdSyncPhysMem = 0x03; /**< @internalComponent */ |
|
256 #endif |
|
257 const TUint8 KMutexOrdPageOut = 0x02; /**< @internalComponent */ |
|
258 const TUint8 KMutexOrdResourceManager = 0x01; /**< @internalComponent */ |
|
259 |
|
260 |
|
261 /******************************************** |
|
262 * Kernel Extension Priority Ordering |
|
263 ********************************************/ |
|
264 |
|
265 /** |
|
266 @internalComponent |
|
267 @prototype 9.5 |
|
268 */ |
|
269 const TUint8 KExtensionMaximumPriority = 0xff; |
|
270 |
|
271 /** |
|
272 @internalComponent |
|
273 @prototype 9.5 |
|
274 */ |
|
275 const TUint8 KExtensionStandardPriority = 0; |
|
276 |
|
277 |
|
278 /** |
|
279 Defines a function type that implements a polling operation. |
|
280 |
|
281 A function of this type takes a single TAny* type argument, and returns |
|
282 a TBool type, and is passed as an argument to Kern::PollingWait(). |
|
283 |
|
284 @see Kern::PollingWait() |
|
285 |
|
286 @publishedPartner |
|
287 @released |
|
288 */ |
|
289 typedef TBool (*TPollFunction)(TAny*); |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 /** |
|
295 Structure used to specify parameters to Kern::ChunkCreate() |
|
296 @see Kern::ChunkCreate() |
|
297 @publishedPartner |
|
298 @released |
|
299 */ |
|
300 class TChunkCreateInfo |
|
301 { |
|
302 public: |
|
303 /** |
|
304 Enumeration representing the type of chunk to be created. |
|
305 */ |
|
306 enum TType |
|
307 { |
|
308 /** |
|
309 A chunk which may only be opened by one user side process at a time. |
|
310 Chunks of this type are slightly more efficient than the |
|
311 ESharedKernelMultiple type when used on the Moving Memory Model. |
|
312 */ |
|
313 ESharedKernelSingle = 9, |
|
314 |
|
315 /** |
|
316 A chunk which may be opened by any number of user side processes. |
|
317 */ |
|
318 ESharedKernelMultiple = 10, |
|
319 }; |
|
320 |
|
321 /** |
|
322 The chunk type to be created. |
|
323 @see TChunkCreateInfo::TType |
|
324 */ |
|
325 TType iType; |
|
326 |
|
327 /** |
|
328 The size of linear address space to reserve for this chunk. |
|
329 */ |
|
330 TInt iMaxSize; |
|
331 |
|
332 /** |
|
333 Caching attributes for the chunks memory. |
|
334 |
|
335 This is a value constructed from the TMappingAttributes values. |
|
336 E.g. EMapAttrFullyBlocking (no caching) or EMapAttrCachedMax (full caching). |
|
337 |
|
338 Note that if the MMU doesn't support the requested attributes then a lesser |
|
339 cached attribute will be used. The actual value used is returned in aMapAttr of |
|
340 Kern::ChunkCreate() |
|
341 |
|
342 @see TMappingAttributes |
|
343 */ |
|
344 TUint32 iMapAttr; |
|
345 |
|
346 /** |
|
347 Set to true if the chunk is to own its committed memory. In which case all |
|
348 memory committed to the chunk will come from the system's free pool and will be |
|
349 returned there when the chunk is destroyed. |
|
350 */ |
|
351 TUint8 iOwnsMemory; |
|
352 |
|
353 /** |
|
354 @internalComponent |
|
355 Reserved for future expansion. |
|
356 */ |
|
357 TInt8 iSpare8[3]; |
|
358 |
|
359 /** |
|
360 Pointer to a DFC which will be queued on destruction of chunk. |
|
361 */ |
|
362 TDfc* iDestroyedDfc; |
|
363 |
|
364 /** |
|
365 @internalComponent |
|
366 Reserved for future expansion. |
|
367 */ |
|
368 TInt32 iSpare32[2]; |
|
369 public: |
|
370 /** |
|
371 Constructor which zeros all member data. |
|
372 */ |
|
373 inline TChunkCreateInfo() |
|
374 { memset(this,0,sizeof(*this)); } |
|
375 }; |
|
376 |
|
377 |
|
378 |
|
379 /** |
|
380 Generic kernel hook function. |
|
381 @internalComponent |
|
382 */ |
|
383 typedef TInt (*TKernelHookFn)(); |
|
384 |
|
385 /** |
|
386 Available kernel hooks. |
|
387 @internalComponent |
|
388 */ |
|
389 enum TKernelHookType |
|
390 { |
|
391 EHookTrace, |
|
392 EHookNanoWait, |
|
393 EHookInitialTime, |
|
394 |
|
395 ENumKernelHooks |
|
396 }; |
|
397 |
|
398 |
|
399 /* |
|
400 Specifies the origin of the log when calling trace handler hook. |
|
401 @publishedPartner |
|
402 @released |
|
403 */ |
|
404 enum TTraceSource |
|
405 { |
|
406 /** |
|
407 User side tracing |
|
408 @see User::DebugPrint |
|
409 */ |
|
410 EUserTrace, |
|
411 /** |
|
412 Kernel tracing |
|
413 @see Kern::Print |
|
414 */ |
|
415 EKernelTrace, |
|
416 /** |
|
417 Platform security tracing |
|
418 */ |
|
419 EPlatSecTrace, |
|
420 }; |
|
421 |
|
422 /* |
|
423 Trace handler hook |
|
424 @param aText Debug log. The content of the descriptor resides in kernel memory. |
|
425 @param aTraceType Identifies the origin of the debug log. |
|
426 @see TTraceHandlerType |
|
427 @return Specifies whether the log is processed or not. |
|
428 If ETrue, the log is processed. Kernel will drop the log (it won't be passed to trace port - UART) |
|
429 If EFalse, the log is not processed. Kernel will pass the log to the trace port, as well. |
|
430 @publishedPartner |
|
431 @released |
|
432 */ |
|
433 typedef TBool (*TTraceHandler)(const TDesC8& /*aText*/, TTraceSource /*aTraceSource*/); |
|
434 |
|
435 |
|
436 /** |
|
437 Defines the prototype of the kernel hook for the Kern::NanoWait implementation. |
|
438 @see Kern::NanoWait |
|
439 @see Kern::SetNanoWaitHandler |
|
440 @publishedPartner |
|
441 @released |
|
442 */ |
|
443 typedef void (*TNanoWaitHandler)(TUint32 aInterval); |
|
444 |
|
445 |
|
446 /** |
|
447 Defines the prototype of the kernel hook to get the initial system time. |
|
448 |
|
449 The hook is called during boot to get the inital system time. It should attempt |
|
450 to read the time from the hardware RTC. If the contents of the RTC are invalid |
|
451 it should return KErrCorrupt. |
|
452 |
|
453 @return The time in seconds from 00:00:00 01-01-2000, or one of the |
|
454 system-wide error codes. |
|
455 |
|
456 @see Kern::SetInitialTimeHandler |
|
457 @see P::InitSystemTime |
|
458 @publishedPartner |
|
459 @released |
|
460 */ |
|
461 typedef TInt (*TInitialTimeHandler)(); |
|
462 |
|
463 |
|
464 /** |
|
465 A thread's realtime state. |
|
466 |
|
467 Some non-realtime behaviour can be detected by the kernel. When it does so, action is taken |
|
468 depending on the thread state: |
|
469 |
|
470 - ERealtimeStateOff - no action. |
|
471 - ERealtimeStateOn - the the thread will be panicked with KERN-EXEC 61 (EIllegalFunctionForRealtimeThread). |
|
472 - ERealtimeStateWarn - no action. However, if the kernel trace flag KREALTIME is enabled |
|
473 then tracing will be emitted as if the thread state was ERealtimeStateOn. |
|
474 |
|
475 @publishedPartner |
|
476 @released |
|
477 */ |
|
478 enum TThreadRealtimeState |
|
479 { |
|
480 ERealtimeStateOff, /**< Thread is not realtime */ |
|
481 ERealtimeStateOn, /**< Thread is realtime */ |
|
482 ERealtimeStateWarn /**< Thread is realtime but doesn't want this enforced */ |
|
483 }; |
|
484 |
|
485 |
|
486 /** |
|
487 A DFC queue intended to be created and destroyed as needed. |
|
488 |
|
489 This class extends the TDfcQue class with a destroy method. |
|
490 |
|
491 @publishedPartner |
|
492 @released |
|
493 */ |
|
494 class TDynamicDfcQue : public TDfcQue |
|
495 { |
|
496 public: |
|
497 TDynamicDfcQue(); |
|
498 IMPORT_C void Destroy(); |
|
499 IMPORT_C void SetRealtimeState(TThreadRealtimeState aNewState); |
|
500 private: |
|
501 TDfc iKillDfc; |
|
502 }; |
|
503 |
|
504 |
|
505 /** |
|
506 An object representing an asynchronous request from a user thread, containing a TRequestStatus |
|
507 pointer. |
|
508 |
|
509 It can be queued for completion when the thread next returns to user-mode, to move the impact of any |
|
510 page faults from the thread posting the completion to the thread that made the request. |
|
511 |
|
512 @publishedPartner |
|
513 @released |
|
514 */ |
|
515 class TClientRequest : public TUserModeCallback |
|
516 { |
|
517 public: |
|
518 IMPORT_C TInt SetStatus(TRequestStatus*); |
|
519 IMPORT_C void Reset(); |
|
520 IMPORT_C TRequestStatus* StatusPtr(); |
|
521 IMPORT_C TBool IsReady(); |
|
522 public: |
|
523 void Close(); |
|
524 protected: |
|
525 enum TState |
|
526 { |
|
527 EFree, |
|
528 EReady, |
|
529 EInUse, |
|
530 EClosing, |
|
531 EBad |
|
532 }; |
|
533 TClientRequest(TUserModeCallbackFunc aCallback = CallbackFunc); |
|
534 ~TClientRequest(); |
|
535 TState State(); |
|
536 static TState GetState(T_UintPtr aStatus); |
|
537 TBool StartComplete(DThread* aThread, TInt aReason); |
|
538 void EndComplete(DThread* aThread); |
|
539 static void CallbackFunc(TAny* aData, TUserModeCallbackReason aReason); |
|
540 private: |
|
541 static TDfc DeadClientCleanupDfc; |
|
542 static void DoDeadClientCleanup(TAny*); |
|
543 private: |
|
544 T_UintPtr MakeFree(); |
|
545 public: |
|
546 volatile T_UintPtr iStatus; // holds TRequestStatus pointer and state flag bits |
|
547 TInt iResult; |
|
548 friend class Kern; |
|
549 friend class K; |
|
550 }; |
|
551 |
|
552 |
|
553 /** |
|
554 Base classs for TClientDataRequest. |
|
555 |
|
556 @internalTechnology |
|
557 */ |
|
558 class TClientDataRequestBase : public TClientRequest |
|
559 { |
|
560 public: |
|
561 /** |
|
562 Set the destination in the client's address space where the data will be copied to when the |
|
563 request is completed. |
|
564 @publishedPartner |
|
565 @released |
|
566 */ |
|
567 inline void SetDestPtr(TAny* aPtr) { iDestPtr = aPtr; } /**< */ |
|
568 /** |
|
569 Get the destination address in the client's address space. |
|
570 @publishedPartner |
|
571 @released |
|
572 */ |
|
573 inline TAny* DestPtr() { return iDestPtr; } |
|
574 /** |
|
575 Get the local address of the buffer where the structure data will be held until it is copied to |
|
576 the client. |
|
577 @publishedPartner |
|
578 @released |
|
579 */ |
|
580 inline TUint8* Buffer() { return (TUint8*)this + _ALIGN_UP(sizeof(*this), 8); } |
|
581 protected: |
|
582 TClientDataRequestBase(TInt aBufferSize); |
|
583 ~TClientDataRequestBase() { } // call Close(), don't delete |
|
584 static void CallbackFunc(TAny* aData, TUserModeCallbackReason aReason); |
|
585 public: |
|
586 TInt iSize; |
|
587 TAny* iDestPtr; |
|
588 friend class Kern; |
|
589 }; |
|
590 |
|
591 /** |
|
592 An object representing an asynchronous request from a user thread that involves copying a small |
|
593 fixed-size structure to the client. It contains a TRequestStatus pointer and a buffer to hold the |
|
594 structure. |
|
595 |
|
596 It can be queued for completion when the thread next returns to user-mode, to move the impact of any |
|
597 page faults from the thread posting the completion to the thread that made the request. |
|
598 |
|
599 @publishedPartner |
|
600 @released |
|
601 */ |
|
602 template <class T> |
|
603 class TClientDataRequest : public TClientDataRequestBase |
|
604 { |
|
605 public: |
|
606 T& Data() { return *(T*)Buffer(); } |
|
607 private: |
|
608 TClientDataRequest(); |
|
609 ~TClientDataRequest(); // call Close(), don't delete |
|
610 }; |
|
611 |
|
612 /** |
|
613 Base classs for TClientDataRequest2. |
|
614 |
|
615 @prototype |
|
616 @internalTechnology |
|
617 */ |
|
618 class TClientDataRequestBase2 : public TClientRequest |
|
619 { |
|
620 public: |
|
621 inline void SetDestPtr1(TAny* aPtr) { iDestPtr1 = aPtr; } |
|
622 inline TAny* DestPtr1() { return iDestPtr1; } |
|
623 inline TUint8* Buffer1() { return (TUint8*)this + _ALIGN_UP(sizeof(*this), 8); } |
|
624 inline void SetDestPtr2(TAny* aPtr) { iDestPtr2 = aPtr; } |
|
625 inline TAny* DestPtr2() { return iDestPtr2; } |
|
626 inline TUint8* Buffer2() { return Buffer1() + _ALIGN_UP(iSize1, 8); } |
|
627 protected: |
|
628 TClientDataRequestBase2(TInt aBufferSize1, TInt aBufferSize2); |
|
629 ~TClientDataRequestBase2() { } // call Close(), don't delete |
|
630 static void CallbackFunc(TAny* aData, TUserModeCallbackReason aReason); |
|
631 public: |
|
632 TInt iSize1; |
|
633 TAny* iDestPtr1; |
|
634 TInt iSize2; |
|
635 TAny* iDestPtr2; |
|
636 friend class Kern; |
|
637 }; |
|
638 |
|
639 /** |
|
640 An object representing an asynchronous request from a user thread that involves copying two small |
|
641 fixed-size structures to the client. It contains a TRequestStatus pointer and two buffer to hold |
|
642 the structures. |
|
643 |
|
644 It can be queued for completion when the thread next returns to user-mode, to move the impact of any |
|
645 page faults from the thread posting the completion to the thread that made the request. |
|
646 |
|
647 @prototype |
|
648 @internalTechnology |
|
649 */ |
|
650 template <class T1, class T2> |
|
651 class TClientDataRequest2 : public TClientDataRequestBase2 |
|
652 { |
|
653 public: |
|
654 T1& Data1() { return *(T1*)Buffer1(); } |
|
655 T2& Data2() { return *(T2*)Buffer2(); } |
|
656 private: |
|
657 TClientDataRequest2(); |
|
658 ~TClientDataRequest2(); // call Close(), don't delete |
|
659 }; |
|
660 |
|
661 /** |
|
662 A parsed descriptor header. |
|
663 |
|
664 This has the same internal structure as TRawDesHeader but the header data is stored in a parsed |
|
665 representation. |
|
666 |
|
667 @see TRawDesHeader. |
|
668 |
|
669 @prototype |
|
670 @internalTechnology |
|
671 */ |
|
672 class TDesHeader |
|
673 { |
|
674 public: |
|
675 enum { KConstMaxLength = (TUint)KErrBadDescriptor }; |
|
676 inline TDesHeader(); |
|
677 /// Set the contents of this object |
|
678 inline void Set(TUint32 aTypeAndLength, TLinAddr aDataPtr, TUint aMaxLength = KConstMaxLength); |
|
679 /// Reset the object to its initial un-set state |
|
680 inline void Unset(); |
|
681 /// Determine whether this object has been set to a valid descriptor header |
|
682 inline TBool IsSet() const; |
|
683 /// Set both type and length fields in one operation |
|
684 inline void SetTypeAndLength(TUint32 aTypeAndLength); |
|
685 // Accessors |
|
686 inline const TUint32& TypeAndLength() const; |
|
687 inline TDesType Type() const; |
|
688 inline TInt Length() const; |
|
689 inline TBool IsWriteable() const; |
|
690 inline TInt MaxLength() const; |
|
691 inline TLinAddr DataPtr() const; |
|
692 private: |
|
693 enum { KUnsetFlag = 0xffffffff }; |
|
694 TUint32 iData[3]; |
|
695 }; |
|
696 |
|
697 inline TDesHeader::TDesHeader() |
|
698 { |
|
699 iData[0] = (TUint32)KUnsetFlag; |
|
700 } |
|
701 |
|
702 inline void TDesHeader::Set(TUint32 aTypeAndLength, TLinAddr aDataPtr, TUint aMaxLength) |
|
703 { |
|
704 iData[0] = aTypeAndLength; |
|
705 iData[1] = aMaxLength; |
|
706 iData[2] = aDataPtr; |
|
707 } |
|
708 |
|
709 inline void TDesHeader::Unset() |
|
710 { |
|
711 iData[0] = (TUint32)KUnsetFlag; |
|
712 } |
|
713 |
|
714 inline TBool TDesHeader::IsSet() const |
|
715 { |
|
716 return iData[0] != KUnsetFlag; |
|
717 } |
|
718 |
|
719 inline void TDesHeader::SetTypeAndLength(TUint32 aTypeAndLength) |
|
720 { |
|
721 iData[0] = aTypeAndLength; |
|
722 } |
|
723 |
|
724 inline const TUint32& TDesHeader::TypeAndLength() const |
|
725 { |
|
726 return iData[0]; |
|
727 } |
|
728 |
|
729 inline TDesType TDesHeader::Type() const |
|
730 { |
|
731 return (TDesType)(iData[0] >> KShiftDesType); |
|
732 } |
|
733 |
|
734 inline TInt TDesHeader::Length() const |
|
735 { |
|
736 return (TInt)(iData[0] & KMaskDesLength); |
|
737 } |
|
738 |
|
739 inline TBool TDesHeader::IsWriteable() const |
|
740 { |
|
741 return iData[1] != KConstMaxLength; |
|
742 } |
|
743 |
|
744 inline TInt TDesHeader::MaxLength() const |
|
745 { |
|
746 return (TInt)iData[1]; |
|
747 } |
|
748 |
|
749 inline TLinAddr TDesHeader::DataPtr() const |
|
750 { |
|
751 return (TLinAddr)iData[2]; |
|
752 } |
|
753 |
|
754 /** |
|
755 An object representing a client buffer that resides in user-side memory. |
|
756 |
|
757 TClientBuffer objects can be used to specify memory to pin using Kern::PinVirtualMemory |
|
758 @see, and can be read and written using Kern::ThreadBufRead and Kern::ThreadBufWrite. |
|
759 |
|
760 @see TClientBufferRequest |
|
761 @see Kern::PinVirtualMemory |
|
762 @see Kern::UnpinVirtualMemory |
|
763 @see Kern::ThreadBufRead |
|
764 @see Kern::ThreadBufWrite |
|
765 |
|
766 @publishedPartner |
|
767 @released |
|
768 */ |
|
769 class TClientBuffer |
|
770 { |
|
771 public: |
|
772 IMPORT_C TClientBuffer(); |
|
773 IMPORT_C TInt SetFromDescriptor(TAny* aDesPtr, DThread* aClientThread = NULL); |
|
774 IMPORT_C void SetFromBuffer(TLinAddr aStartAddr, TInt aLength, TBool aWriteable); |
|
775 IMPORT_C TBool IsSet() const; |
|
776 IMPORT_C void Reset(); |
|
777 IMPORT_C TBool IsWriteable() const; |
|
778 IMPORT_C TInt Length() const; |
|
779 IMPORT_C TInt MaxLength() const; |
|
780 IMPORT_C TInt UpdateDescriptorLength(DThread* aClientThread = NULL); |
|
781 public: |
|
782 TAny* DesPtr() const; |
|
783 TAny* DataPtr() const; |
|
784 private: |
|
785 enum TFlags |
|
786 { |
|
787 EIsBuffer = 1 |
|
788 }; |
|
789 private: |
|
790 TUint32 iPtr; |
|
791 TDesHeader iHeader; |
|
792 friend class Kern; |
|
793 }; |
|
794 |
|
795 class TVirtualPinObject; |
|
796 class TPhysicalPinObject; |
|
797 class TShPool; |
|
798 class TShBuf; |
|
799 |
|
800 /** |
|
801 An object representing a device driver request that involves writing data to one or more user-side |
|
802 buffers. |
|
803 |
|
804 It handles pinning of the buffers when the request is set up, so that the memory can be accessed in |
|
805 kernel thread context. |
|
806 |
|
807 It can be queued for completion when the thread next returns to user-mode. Any writeable |
|
808 descriptors have their lengths written back to the client at the same time as the completion value. |
|
809 |
|
810 The following operations can only be called from client thread context: |
|
811 |
|
812 StartSetup |
|
813 AddBuffer |
|
814 EndSetup |
|
815 |
|
816 These operations can be called from any thread context: |
|
817 |
|
818 Kern::QueueRequestComplete |
|
819 |
|
820 @publishedPartner |
|
821 @released |
|
822 */ |
|
823 class TClientBufferRequest : private TClientRequest |
|
824 { |
|
825 public: |
|
826 enum TFlags |
|
827 { |
|
828 /** A flag indicating that buffers should have their virtual memory pinned. */ |
|
829 EPinVirtual = 1 |
|
830 }; |
|
831 IMPORT_C TInt StartSetup(TRequestStatus* aStatus); |
|
832 IMPORT_C TInt AddBuffer(TClientBuffer*& aBufOut, TAny* aDesPtr); |
|
833 IMPORT_C TInt AddBuffer(TClientBuffer*& aBufOut, TLinAddr aStartAddr, TInt aLength, TBool aWriteable = EFalse); |
|
834 IMPORT_C void EndSetup(); |
|
835 IMPORT_C void Reset(); |
|
836 inline TInt Setup(TClientBuffer*& aBufOut, TRequestStatus* aStatus, TAny* aDesPtr); |
|
837 inline TInt Setup(TClientBuffer*& aBufOut, TRequestStatus* aStatus, TLinAddr aStartAddr, TInt aLength, TBool aWriteable = EFalse); |
|
838 inline TBool IsReady(); |
|
839 private: |
|
840 struct SBufferData : public SDblQueLink |
|
841 { |
|
842 TClientBuffer iBuffer; |
|
843 TVirtualPinObject* iPinObject; |
|
844 }; |
|
845 TClientBufferRequest(TUint aFlags); |
|
846 ~TClientBufferRequest(); // call Close(), don't delete |
|
847 TInt Construct(TInt aMaxBuffers); |
|
848 void Close(); |
|
849 TInt AllocateBufferData(); |
|
850 SBufferData* StartAddBuffer(); |
|
851 TInt EndAddBuffer(TClientBuffer*& aBufOut, SBufferData* aBuf); |
|
852 void QueueComplete(DThread* aThread, TInt aReason); |
|
853 static void CallbackFunc(TAny* aData, TUserModeCallbackReason aReason); |
|
854 private: |
|
855 TUint iFlags; |
|
856 DThread* iSetupThread; |
|
857 SDblQue iBufferList; |
|
858 static NFastMutex Lock; |
|
859 friend class Kern; |
|
860 }; |
|
861 |
|
862 inline TInt TClientBufferRequest::Setup(TClientBuffer*& aBufOut, TRequestStatus* aStatus, TAny* aDesPtr) |
|
863 { |
|
864 TInt r = StartSetup(aStatus); |
|
865 if (r == KErrNone) |
|
866 r = AddBuffer(aBufOut, aDesPtr); |
|
867 if (r == KErrNone) |
|
868 EndSetup(); |
|
869 return r; |
|
870 } |
|
871 |
|
872 inline TInt TClientBufferRequest::Setup(TClientBuffer*& aBufOut, TRequestStatus* aStatus, TLinAddr aStartAddr, TInt aLength, TBool aWriteable) |
|
873 { |
|
874 TInt r = StartSetup(aStatus); |
|
875 if (r == KErrNone) |
|
876 r = AddBuffer(aBufOut, aStartAddr, aLength, aWriteable); |
|
877 if (r == KErrNone) |
|
878 EndSetup(); |
|
879 return r; |
|
880 } |
|
881 |
|
882 inline TBool TClientBufferRequest::IsReady() |
|
883 { |
|
884 return TClientRequest::IsReady(); |
|
885 } |
|
886 |
|
887 class DPagingDevice; |
|
888 class DLogicalDevice; |
|
889 class DPhysicalDevice; |
|
890 class TShPoolCreateInfo; |
|
891 |
|
892 class Kern |
|
893 /** |
|
894 Kernel utility functions |
|
895 |
|
896 @publishedPartner |
|
897 @released |
|
898 */ |
|
899 { |
|
900 public: |
|
901 /** |
|
902 Bit values to be used with the aMode parameter of Kern::SetSytemTime() to |
|
903 specify the mode of operation of Kern::SetSytemTime(). |
|
904 */ |
|
905 enum TTimeSetMode |
|
906 { |
|
907 ETimeSet_SetHwRtc = 1, /**< Set HW as well as SW RTC */ |
|
908 ETimeSet_LocalTime = 2, /**< The Kern::SetSytemTime() parameter aTime is specified in local time rather than UTC */ |
|
909 ETimeSet_SyncNotify = 4, /**< Synchronously trigger change notifiers*/ |
|
910 ETimeSet_AsyncNotify = 8, /**< Asynchronously trigger change notifiers*/ |
|
911 ETimeSet_Secure = 16 /**< Set the secure clock (implies ETimeSet_SetHwRtc)*/ |
|
912 }; |
|
913 public: |
|
914 IMPORT_C static void Printf(const char* aFmt, ...); |
|
915 IMPORT_C static TInt AddHalEntry(TInt aId, THalFunc aFunc, TAny* aPtr); |
|
916 IMPORT_C static TInt AddHalEntry(TInt aId, THalFunc aFunc, TAny* aPtr, TInt aDeviceNumber); |
|
917 IMPORT_C static TInt RemoveHalEntry(TInt aId); |
|
918 IMPORT_C static TInt RemoveHalEntry(TInt aId, TInt aDeviceNumber); |
|
919 IMPORT_C static SHalEntry* FindHalEntry(TInt aId); |
|
920 IMPORT_C static SHalEntry* FindHalEntry(TInt aId, TInt aDeviceNumber); |
|
921 IMPORT_C static void SafeClose(DObject*& aObj, TAny* aPtr); |
|
922 IMPORT_C static TInt ValidateName(const TDesC& aName); |
|
923 IMPORT_C static TInt ValidateFullName(const TDesC& aName); |
|
924 IMPORT_C static TBool PowerGood(); |
|
925 IMPORT_C static void NotifyChanges(TUint aChangesMask); |
|
926 IMPORT_C static void NotifyThreadDeath(DThread* aDeadThread); /**< @internalComponent */ |
|
927 IMPORT_C static void AsyncNotifyChanges(TUint aChangesMask); |
|
928 IMPORT_C static void InfoCopy(TDes8& aDest, const TDesC8& aSrc); |
|
929 IMPORT_C static void InfoCopy(TDes8& aDest, const TUint8* aPtr, TInt aLength); |
|
930 IMPORT_C static void RequestComplete(DThread* aThread, TRequestStatus*& aStatus, TInt aReason); |
|
931 IMPORT_C static void RequestComplete(TRequestStatus*& aStatus, TInt aReason); |
|
932 IMPORT_C static void QueueRequestComplete(DThread* aThread, TClientRequest* aRequest, TInt aReason); |
|
933 IMPORT_C static TInt CreateClientRequest(TClientRequest*& aRequestPtr); |
|
934 |
|
935 template <class T> inline static TInt CreateClientDataRequest(TClientDataRequest<T>*& aRequestPtr) |
|
936 { |
|
937 TInt r = Kern::CreateClientDataRequestBase((TClientDataRequestBase*&)aRequestPtr, sizeof(T)); |
|
938 if (r == KErrNone) |
|
939 new (aRequestPtr->Buffer()) T; |
|
940 return r; |
|
941 } |
|
942 |
|
943 template <class T1, class T2> inline static TInt CreateClientDataRequest2(TClientDataRequest2<T1,T2>*& aRequestPtr) |
|
944 { |
|
945 TInt r = Kern::CreateClientDataRequestBase2((TClientDataRequestBase2*&)aRequestPtr, sizeof(T1), sizeof(T2)); |
|
946 if (r == KErrNone) |
|
947 { |
|
948 new (aRequestPtr->Buffer1()) T1; |
|
949 new (aRequestPtr->Buffer2()) T2; |
|
950 } |
|
951 return r; |
|
952 } |
|
953 |
|
954 IMPORT_C static void DestroyClientRequest(TClientRequest*& aRequestPtr); |
|
955 template <class T> inline static void DestroyClientRequest(TClientDataRequest<T>*& aRequestPtr) |
|
956 { DestroyClientRequest((TClientRequest*&)aRequestPtr); } /**< @prototype */ |
|
957 template <class T, class T2> inline static void DestroyClientRequest(TClientDataRequest2<T,T2>*& aRequestPtr) |
|
958 { DestroyClientRequest((TClientRequest*&)aRequestPtr); } /**< @prototype */ |
|
959 IMPORT_C static TInt CreateClientBufferRequest(TClientBufferRequest*& aRequestPtr, TUint aInitialBuffers, TUint aFlags); |
|
960 IMPORT_C static void DestroyClientBufferRequest(TClientBufferRequest*& aRequestPtr); |
|
961 IMPORT_C static void QueueBufferRequestComplete(DThread* aThread, TClientBufferRequest* aRequest, TInt aReason); |
|
962 IMPORT_C static TDfcQue* DfcQue0(); |
|
963 IMPORT_C static TDfcQue* DfcQue1(); |
|
964 IMPORT_C static TDfcQue* TimerDfcQ(); |
|
965 IMPORT_C static TDfcQue* SvMsgQue(); |
|
966 IMPORT_C static DObjectCon* const *Containers(); /**< @internalComponent */ |
|
967 IMPORT_C static SDblQue* CodeSegList(); |
|
968 IMPORT_C static DMutex* CodeSegLock(); |
|
969 IMPORT_C static DPowerModel* PowerModel(); |
|
970 IMPORT_C static TInt SetThreadPriority(TInt aPriority, DThread* aThread=NULL); |
|
971 IMPORT_C static void SetRealtimeState(TThreadRealtimeState aNewState); |
|
972 IMPORT_C static DObject* ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType); |
|
973 IMPORT_C static DObject* ObjectFromHandle(DThread* aThread, TInt aHandle, TInt aType, TUint& aAttr); |
|
974 IMPORT_C static DThread* ThreadFromId(TUint aId); |
|
975 IMPORT_C static DProcess* ProcessFromId(TUint aId); |
|
976 IMPORT_C static void ThreadSuspend(DThread& aThread, TInt aCount); |
|
977 IMPORT_C static void ThreadResume(DThread& aThread); |
|
978 IMPORT_C static TInt MutexWait(DMutex& aMutex); |
|
979 IMPORT_C static void MutexSignal(DMutex& aMutex); |
|
980 IMPORT_C static TInt MutexCreate(DMutex*& aMutex, const TDesC& aName, TUint aOrder); |
|
981 IMPORT_C static TInt SemaphoreWait(DSemaphore& aSem, TInt aNTicks=0); |
|
982 IMPORT_C static void SemaphoreSignal(DSemaphore& aSem); |
|
983 IMPORT_C static TInt SemaphoreCreate(DSemaphore*& aSem, const TDesC& aName, TInt aInitialCount); |
|
984 IMPORT_C static TInt ThreadCreate(SThreadCreateInfo& aInfo); |
|
985 IMPORT_C static TInt DfcQInit(TDfcQue* aDfcQ, TInt aPriority, const TDesC* aName=NULL); |
|
986 IMPORT_C static TInt DfcQCreate(TDfcQue*& aDfcQ, TInt aPriority, const TDesC* aName=NULL); |
|
987 IMPORT_C static TInt DynamicDfcQCreate(TDynamicDfcQue*& aDfcQ, TInt aPriority, const TDesC& aBaseName); |
|
988 IMPORT_C static TInt ProcessCreate(DProcess*& aProcess, TProcessCreateInfo& aInfo, HBuf*& aCommand, TInt* aHandle); /**< @internalComponent */ |
|
989 IMPORT_C static TSupplyStatus MachinePowerStatus(); |
|
990 IMPORT_C static void AppendFormat(TDes8& aDes, const char* aFmt, VA_LIST aList); |
|
991 IMPORT_C static TSuperPage& SuperPage(); |
|
992 IMPORT_C static TMachineConfig& MachineConfig(); |
|
993 IMPORT_C static TUint32 Random(); |
|
994 IMPORT_C static void RandomSalt(TUint32 aBit); |
|
995 IMPORT_C static void WaitForRequest(TRequestStatus& aStatus); /**< @internalTechnology */ |
|
996 IMPORT_C static TAny* Alloc(TInt aSize); |
|
997 IMPORT_C static TAny* AllocZ(TInt aSize); |
|
998 IMPORT_C static void Free(TAny* aPtr); |
|
999 IMPORT_C static void AsyncFree(TAny* aPtr); |
|
1000 IMPORT_C static TAny* ReAlloc(TAny* aPtr, TInt aSize, TInt aMode=0); |
|
1001 IMPORT_C static TInt SafeReAlloc(TAny*& aPtr, TInt aOldSize, TInt aNewSize); |
|
1002 IMPORT_C static void ValidateHeap(); |
|
1003 IMPORT_C static void PanicCurrentThread(const TDesC& aCategory, TInt aReason); |
|
1004 IMPORT_C static TBool QueryVersionSupported(const TVersion& aCurrent,const TVersion& aRequested); |
|
1005 IMPORT_C static TTimeK SystemTimeSecure(); |
|
1006 IMPORT_C static TTimeK SystemTime(); |
|
1007 IMPORT_C static TInt SetSystemTime(const TTimeK& aTime, TUint aMode); |
|
1008 IMPORT_C static TInt HalFunction(TInt aGroup, TInt aFunction, TAny* a1, TAny* a2); |
|
1009 IMPORT_C static TInt HalFunction(TInt aGroup, TInt aFunction, TAny* a1, TAny* a2, TInt aDeviceNumber); |
|
1010 IMPORT_C static TInt AddEvent(const TRawEvent& aEvent); |
|
1011 IMPORT_C static TInt AddEvent(const TRawEvent& aEvent, TBool aResetUserActivity); |
|
1012 IMPORT_C static void Exit(TInt aReason); |
|
1013 IMPORT_C static TInt TickPeriod(); |
|
1014 IMPORT_C static void KUDesGet(TDes8& aDest, const TDesC8& aSrc); |
|
1015 IMPORT_C static void KUDesPut(TDes8& aDest, const TDesC8& aSrc); |
|
1016 IMPORT_C static const TUint8* KUDesInfo(const TDesC8& aSrc, TInt& aLength, TInt& aMaxLength); |
|
1017 IMPORT_C static void KUDesSetLength(TDes8& aDes, TInt aLength); |
|
1018 IMPORT_C static TInt ThreadDesRead(DThread* aThread, const TAny* aSrc, TDes8& aDest, TInt aOffset, TInt aMode); |
|
1019 IMPORT_C static TInt ThreadRawRead(DThread* aThread, const TAny* aSrc, TAny* aDest, TInt aSize); |
|
1020 IMPORT_C static TInt ThreadDesWrite(DThread* aThread, TAny* aDest, const TDesC8& aSrc, TInt aOffset, TInt aMode, DThread* aOrigThread); |
|
1021 IMPORT_C static TInt ThreadRawWrite(DThread* aThread, TAny* aDest, const TAny* aSrc, TInt aSize, DThread* aOrigThread=NULL); |
|
1022 inline static TInt ThreadDesRead(DThread* aThread, const TAny* aSrc, TDes8& aDest, TInt aOffset); |
|
1023 inline static TInt ThreadDesWrite(DThread* aThread, TAny* aDest, const TDesC8& aSrc, TInt aOffset, DThread* aOrigThread=NULL); |
|
1024 IMPORT_C static TInt ThreadBufRead(DThread* aThread, const TClientBuffer* aSrc, TDes8& aDest, TInt aOffset, TInt aMode); |
|
1025 IMPORT_C static TInt ThreadBufWrite(DThread* aThread, TClientBuffer* aDest, const TDesC8& aSrc, TInt aOffset, TInt aMode, DThread* aOrigThread); |
|
1026 IMPORT_C static TInt ThreadGetDesLength(DThread* aThread, const TAny* aDes); |
|
1027 IMPORT_C static TInt ThreadGetDesMaxLength(DThread* aThread, const TAny* aDes); |
|
1028 IMPORT_C static TInt ThreadGetDesInfo(DThread* aThread, const TAny* aDes, TInt& aLength, TInt& aMaxLength, TUint8*& aPtr, TBool aWriteable); |
|
1029 IMPORT_C static void ThreadKill(DThread* aThread, TExitType aType, TInt aReason, const TDesC& aCategory); |
|
1030 IMPORT_C static TAny* KUSafeRead(const TAny* aSrc, TAny* aDest, TInt aSize); /**< @internalTechnology */ |
|
1031 IMPORT_C static TAny* SafeRead(const TAny* aSrc, TAny* aDest, TInt aSize); /**< @internalTechnology */ |
|
1032 IMPORT_C static TAny* KUSafeWrite(TAny* aDest, const TAny* aSrc, TInt aSize); /**< @internalTechnology */ |
|
1033 IMPORT_C static TAny* SafeWrite(TAny* aDest, const TAny* aSrc, TInt aSize); /**< @internalTechnology */ |
|
1034 IMPORT_C static TInt KUSafeInc(TInt& aValue); /**< @internalTechnology */ |
|
1035 IMPORT_C static TInt KUSafeDec(TInt& aValue); /**< @internalTechnology */ |
|
1036 IMPORT_C static DThread& CurrentThread(); |
|
1037 IMPORT_C static DProcess& CurrentProcess(); |
|
1038 IMPORT_C static TThreadMessage& Message(); |
|
1039 IMPORT_C static TInt FreeRamInBytes(); |
|
1040 IMPORT_C static void Fault(const char* aCat, TInt aFault); |
|
1041 IMPORT_C static TBool ColdStart(); |
|
1042 IMPORT_C static void NanoWait(TUint32 aInterval); |
|
1043 IMPORT_C static TUint32 TickCount(); |
|
1044 IMPORT_C static TInt PollingWait(TPollFunction aFunction, TAny* aPtr, TInt aPollPeriodMs, TInt aMaxPoll); |
|
1045 IMPORT_C static TUint32 RoundToPageSize(TUint32 aSize); |
|
1046 IMPORT_C static TUint32 RoundToChunkSize(TUint32 aSize); |
|
1047 IMPORT_C static void Restart(TInt aMode); /**< @internalTechnology */ |
|
1048 IMPORT_C static void AccessCode(); |
|
1049 IMPORT_C static void EndAccessCode(); |
|
1050 IMPORT_C static DThread* NThreadToDThread(NThread* aNThread); |
|
1051 IMPORT_C static TInt PrepareMemoryForDMA(DThread* aThread, TAny* aAddress, TInt aSize, TPhysAddr* aPageList); /**< @internalComponent */ |
|
1052 IMPORT_C static TInt ReleaseMemoryFromDMA(DThread* aThread, TAny* aAddress, TInt aSize, TPhysAddr* aPageList);/**< @internalComponent */ |
|
1053 |
|
1054 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
1055 /** |
|
1056 Checks whether the process that owns the current thread has the specified capability. |
|
1057 |
|
1058 When a check fails the action taken is determined by the system wide Platform Security |
|
1059 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted. |
|
1060 If PlatSecEnforcement is OFF, then this function will return True even though the |
|
1061 check failed. |
|
1062 |
|
1063 @param aCapability The capability to be tested. |
|
1064 @param aDiagnosticText A string that will be emitted along with any diagnostic message |
|
1065 that may be issued if the test finds the capability is not present. |
|
1066 This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro |
|
1067 which enables it to be easily removed from the system. |
|
1068 |
|
1069 @return True if the current thread's process has the capability, False otherwise. |
|
1070 */ |
|
1071 inline static TBool CurrentThreadHasCapability(TCapability aCapability, const char* aDiagnosticText=0) |
|
1072 { return DoCurrentThreadHasCapability(aCapability, aDiagnosticText); } |
|
1073 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
1074 // Only available to NULL arguments |
|
1075 /** |
|
1076 Checks whether the process that owns the current thread has the specified capability. |
|
1077 |
|
1078 When a check fails the action taken is determined by the system wide Platform Security |
|
1079 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted. |
|
1080 If PlatSecEnforcement is OFF, then this function will return True even though the |
|
1081 check failed. |
|
1082 |
|
1083 @param aCapability The capability to be tested. |
|
1084 |
|
1085 @return True if the current thread's process has the capability, False otherwise. |
|
1086 */ |
|
1087 inline static TBool CurrentThreadHasCapability(TCapability aCapability, OnlyCreateWithNull /*aDiagnosticText*/=NULL) |
|
1088 { return DoCurrentThreadHasCapability(aCapability); } |
|
1089 #endif // !__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
1090 |
|
1091 IMPORT_C static TVendorId ThreadVendorId(DThread* aThread); |
|
1092 IMPORT_C static TVendorId ProcessVendorId(DProcess* aProcess); |
|
1093 IMPORT_C static TSecureId ThreadSecureId(DThread* aThread); |
|
1094 IMPORT_C static TSecureId ProcessSecureId(DProcess* aProcess); |
|
1095 |
|
1096 IMPORT_C static DCodeSeg* CodeSegFromAddress(TLinAddr aAddr, DProcess* aProcess); |
|
1097 IMPORT_C static void CodeSegGetMemoryInfo(DCodeSeg& aCodeSeg, TModuleMemoryInfo& aInfo, DProcess* aProcess); |
|
1098 IMPORT_C static TInt MakeHandleAndOpen(DThread* aThread, DObject* aObject); |
|
1099 IMPORT_C static TInt CloseHandle(DThread* aThread, TInt aHandle); |
|
1100 IMPORT_C static TInt ChunkCreate(const TChunkCreateInfo& aInfo, DChunk*& aChunk, TLinAddr& aKernAddr, TUint32& iMapAttr); |
|
1101 IMPORT_C static TInt ChunkCommit(DChunk* aChunk, TInt aOffset, TInt aSize); |
|
1102 IMPORT_C static TInt ChunkCommitContiguous(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32& aPhysicalAddress); |
|
1103 IMPORT_C static TInt ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32 aPhysicalAddress); |
|
1104 IMPORT_C static TInt ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, const TUint32* aPhysicalAddressList); |
|
1105 IMPORT_C static TInt ChunkClose(DChunk* aChunk); |
|
1106 IMPORT_C static DChunk* OpenSharedChunk(DThread* aThread, const TAny* aAddress, TBool aWrite, TInt& aOffset); |
|
1107 IMPORT_C static DChunk* OpenSharedChunk(DThread* aThread, TInt aChunkHandle, TBool aWrite); |
|
1108 IMPORT_C static TInt ChunkAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress); |
|
1109 IMPORT_C static TInt ChunkPhysicalAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aMapAttr, TUint32& aPhysicalAddress, TUint32* aPhysicalPageList=NULL); |
|
1110 IMPORT_C static TUint8* ChunkUserBase(DChunk* aChunk, DThread* aThread); |
|
1111 |
|
1112 /** |
|
1113 Enumeration indicating the behaviour of text trace messages. |
|
1114 @publishedPartner |
|
1115 @released |
|
1116 */ |
|
1117 enum TTextTraceMode |
|
1118 { |
|
1119 /** Traces are sent to the serial port if not already handled by other means. */ |
|
1120 ESerialOutDefault = 0, |
|
1121 /** Traces are never sent to the serial port. */ |
|
1122 ESerialOutNever = 1, |
|
1123 /** Traces are always sent to the serial port. */ |
|
1124 ESerialOutAlways = 2, |
|
1125 /** Mask for serial port mode values. */ |
|
1126 ESerialOutMask = 3 |
|
1127 }; |
|
1128 IMPORT_C static TUint SetTextTraceMode(TUint aMode, TUint aMask); |
|
1129 IMPORT_C static TTraceHandler SetTraceHandler(TTraceHandler aHandler); |
|
1130 inline static TNanoWaitHandler SetNanoWaitHandler(TNanoWaitHandler aHandler); |
|
1131 inline static TInitialTimeHandler SetInitialTimeHandler(TInitialTimeHandler aHandler); |
|
1132 |
|
1133 /** |
|
1134 Install the specified paging device. |
|
1135 @param aDevice The device. |
|
1136 @return KErrNone or standard error code. |
|
1137 @post The devices DPagingDevice::iDeviceId has been set. |
|
1138 @internalTechnology |
|
1139 */ |
|
1140 IMPORT_C static TInt InstallPagingDevice(DPagingDevice* aDevice); |
|
1141 IMPORT_C static TInt InstallLogicalDevice(DLogicalDevice* aDevice); /**< @internalTechnology */ |
|
1142 IMPORT_C static TInt InstallPhysicalDevice(DPhysicalDevice* aDevice); /**< @internalTechnology */ |
|
1143 |
|
1144 IMPORT_C static TInt CreateVirtualPinObject(TVirtualPinObject*& aPinObject); // prototype |
|
1145 IMPORT_C static TInt PinVirtualMemory(TVirtualPinObject* aPinObject, TLinAddr aStart, TUint aSize, DThread* aThread=NULL); // prototype |
|
1146 IMPORT_C static TInt PinVirtualMemory(TVirtualPinObject* aPinObject, const TClientBuffer& aDes, DThread* aThread=NULL); // prototype |
|
1147 IMPORT_C static TInt CreateAndPinVirtualMemory(TVirtualPinObject*& aPinObject, TLinAddr aStart, TUint aSize); //prototype |
|
1148 IMPORT_C static void UnpinVirtualMemory(TVirtualPinObject* aPinObject); // prototype |
|
1149 IMPORT_C static void DestroyVirtualPinObject(TVirtualPinObject*& aPinObject); // prototype |
|
1150 |
|
1151 IMPORT_C static TInt CreatePhysicalPinObject(TPhysicalPinObject*& aPinObject); // prototype |
|
1152 IMPORT_C static TInt PinPhysicalMemory(TPhysicalPinObject* aPinObject, TLinAddr aStart, TUint aSize, TBool aReadOnly, TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour, DThread* aThread=NULL); |
|
1153 IMPORT_C static TInt UnpinPhysicalMemory(TPhysicalPinObject* aPinObject); // prototype |
|
1154 IMPORT_C static TInt DestroyPhysicalPinObject(TPhysicalPinObject*& aPinObject); // prototype |
|
1155 |
|
1156 |
|
1157 IMPORT_C static TInt ShPoolCreate(TShPool*& aPool, TShPoolCreateInfo& aInfo, TBool aMap, TUint aFlags); |
|
1158 IMPORT_C static TInt ShPoolOpen(TShPool*& aPool, DThread* aThread, TInt aHandle, TBool aMap, TUint aFlags); |
|
1159 IMPORT_C static TInt ShPoolClose(TShPool* aPool); |
|
1160 IMPORT_C static TInt ShPoolMakeHandleAndOpen(TShPool* aPool, DThread* aThread, TUint aAttr); |
|
1161 IMPORT_C static TInt ShPoolSetBufferWindow(TShPool* aPool, TInt aWindowSize); |
|
1162 IMPORT_C static TInt ShPoolAlloc(TShPool* aPool, TShBuf*& aBuf, TUint aFlags); |
|
1163 IMPORT_C static void ShPoolGetInfo(TShPool* aPool, TShPoolInfo& aInfo); |
|
1164 IMPORT_C static TUint ShPoolBufSize(TShPool* aPool); |
|
1165 IMPORT_C static TUint ShPoolFreeCount(TShPool* aPool); |
|
1166 IMPORT_C static TInt ShBufOpen(TShBuf*& aBuf, DThread* aThread, TInt aHandle); |
|
1167 IMPORT_C static TInt ShBufClose(TShBuf* aBuf); |
|
1168 IMPORT_C static TInt ShBufMakeHandleAndOpen(TShBuf* aBuf, DThread* aThread); |
|
1169 IMPORT_C static void ShBufCopyFrom(TShBuf* aBuf, const TDesC8& aSrc, TUint aOffset); |
|
1170 IMPORT_C static TUint8* ShBufPtr(TShBuf* aBuf); |
|
1171 IMPORT_C static TUint ShBufSize(TShBuf* aBuf); |
|
1172 IMPORT_C static TInt ShBufPin(TShBuf* aBuf, TPhysicalPinObject* aPinObject, TBool aReadOnly, TPhysAddr& Address, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour); |
|
1173 |
|
1174 |
|
1175 private: |
|
1176 IMPORT_C static TBool DoCurrentThreadHasCapability(TCapability aCapability, const char* aDiagnosticText); |
|
1177 IMPORT_C static TBool DoCurrentThreadHasCapability(TCapability aCapability); |
|
1178 IMPORT_C static TKernelHookFn SetHook(TKernelHookType aType, TKernelHookFn aFunction, TBool aAllowOveride=EFalse); |
|
1179 IMPORT_C static TInt CreateClientDataRequestBase(TClientDataRequestBase*& aRequestPtr, TInt aSize); /**< @internalTechnology */ |
|
1180 IMPORT_C static TInt CreateClientDataRequestBase2(TClientDataRequestBase2*& aRequestPtr, TInt aSize1, TInt aSize2); /**< @internalTechnology */ |
|
1181 friend class DThread; |
|
1182 }; |
|
1183 |
|
1184 |
|
1185 |
|
1186 /** |
|
1187 Reads an 8-bit descriptor from the specified thread's address space, enforcing |
|
1188 checks on validity of source and destination if necessary. |
|
1189 |
|
1190 It is used especially by device drivers to transfer data from a user thread. |
|
1191 aDes might be accessed with user permission validation. |
|
1192 |
|
1193 @param aThread The thread from whose address space data is to be read. |
|
1194 @param aSrc Pointer to a source descriptor in the specified thread's address |
|
1195 space. This must not be NULL. |
|
1196 @param aDest Target descriptor |
|
1197 @param aOffset Offset in aSrc from where to start reading data. |
|
1198 |
|
1199 @return KErrNone, if sucessful; KErrBadDescriptor, if aPtr or aDes is an |
|
1200 invalid decriptor; KErrArgument if anOffset is negative; KErrDied if aThread |
|
1201 is dead. |
|
1202 */ |
|
1203 inline TInt Kern::ThreadDesRead(DThread* aThread, const TAny* aSrc, TDes8& aDest, TInt aOffset) |
|
1204 { return ThreadDesRead(aThread,aSrc,aDest,aOffset,KChunkShiftBy0); } |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 /** |
|
1210 Writes an 8-bit descriptor to the specified thread's address space, enforcing |
|
1211 checks on validity of source and destination if necessary. |
|
1212 |
|
1213 It is used especially by device drivers to transfer data to a user thread. |
|
1214 aDes might be accessed with user permission validation. |
|
1215 |
|
1216 @param aThread The thread into whose address space data is to be written. |
|
1217 @param aDest Pointer to a target descriptor in the specified thread's address |
|
1218 space. It must not be NULL |
|
1219 @param aSrc Source descriptor |
|
1220 @param aOffset Offset in aDest to start writing data to. |
|
1221 @param aOrigThread The thread on behalf of which this operation is performed (eg client of device driver). |
|
1222 |
|
1223 @return KErrNone, if sucessful; KErrBadDescriptor, if aPtr or aDes is an |
|
1224 invalid decriptor; KErrArgument if anOffset is negative; KErrDied if aThread |
|
1225 is dead. |
|
1226 */ |
|
1227 inline TInt Kern::ThreadDesWrite(DThread* aThread, TAny* aDest, const TDesC8& aSrc, TInt aOffset, DThread* aOrigThread) |
|
1228 { return ThreadDesWrite(aThread,aDest,aSrc,aOffset,KChunkShiftBy0,aOrigThread); } |
|
1229 |
|
1230 |
|
1231 /** |
|
1232 Register the function used to implement Kern::NanoWait. |
|
1233 |
|
1234 This should be called from the variant to supply an accurate implementation for Kern::NanoWait. |
|
1235 |
|
1236 @return The previous implemention. |
|
1237 |
|
1238 @see Kern::NanoWait |
|
1239 |
|
1240 @publishedPartner |
|
1241 @released |
|
1242 */ |
|
1243 inline TNanoWaitHandler Kern::SetNanoWaitHandler(TNanoWaitHandler aHandler) |
|
1244 { |
|
1245 return (TNanoWaitHandler) SetHook(EHookNanoWait, (TKernelHookFn)aHandler, ETrue); |
|
1246 } |
|
1247 |
|
1248 |
|
1249 |
|
1250 /** |
|
1251 Register the function used to read the initial system time. |
|
1252 |
|
1253 This may be called from the variant to override the default behaviour. If so it |
|
1254 should be called in phase 1 of initialisation. |
|
1255 |
|
1256 @return The previous implemention. |
|
1257 |
|
1258 @publishedPartner |
|
1259 @released |
|
1260 */ |
|
1261 inline TInitialTimeHandler Kern::SetInitialTimeHandler(TInitialTimeHandler aHandler) |
|
1262 { |
|
1263 return (TInitialTimeHandler) SetHook(EHookInitialTime, (TKernelHookFn)aHandler, ETrue); |
|
1264 } |
|
1265 |
|
1266 |
|
1267 |
|
1268 struct SMiscNotifierQ; |
|
1269 class TMiscNotifierMgr; |
|
1270 class DObject : public DBase |
|
1271 /** |
|
1272 Base class for reference-counted kernel side objects. |
|
1273 |
|
1274 @publishedPartner |
|
1275 @released |
|
1276 */ |
|
1277 // NOTE: Any changes to the structure of this class should be duplicated in class DMonObject |
|
1278 { |
|
1279 public: |
|
1280 |
|
1281 /** |
|
1282 Defines a set of bit values that are returned from calls |
|
1283 to DObject::Close(), or by an overriding implementation of Close() provided |
|
1284 by a derived class. |
|
1285 |
|
1286 The values describe the state of the object on return from Close(). |
|
1287 */ |
|
1288 enum TCloseReturn |
|
1289 { |
|
1290 |
|
1291 /** |
|
1292 If set, indicates that the object has been deleted. |
|
1293 */ |
|
1294 EObjectDeleted=1, |
|
1295 |
|
1296 /** |
|
1297 If set, indicates that the last reference |
|
1298 from a user process has been removed. |
|
1299 |
|
1300 Note that this only applies to DLibrary objects. |
|
1301 */ |
|
1302 EObjectUnmapped=2, |
|
1303 }; |
|
1304 |
|
1305 /** @internalComponent */ |
|
1306 enum TObjectProtection |
|
1307 { |
|
1308 ELocal=0, // Private |
|
1309 EProtected, |
|
1310 EGlobal, // Public |
|
1311 }; |
|
1312 |
|
1313 /** @internalComponent */ |
|
1314 enum TObjectFlags |
|
1315 { |
|
1316 EObjectExtraReference = (1<<0), |
|
1317 EObjectDeferKernelCodesegCleanup = (1<<1) |
|
1318 }; |
|
1319 |
|
1320 public: |
|
1321 /** @internalComponent */ |
|
1322 inline TInt Inc() { return __e32_atomic_tas_ord32(&iAccessCount, 1, 1, 0); } |
|
1323 |
|
1324 /** @internalComponent */ |
|
1325 inline TInt Dec() { return __e32_atomic_tas_ord32(&iAccessCount, 1, -1, 0); } |
|
1326 |
|
1327 IMPORT_C DObject(); |
|
1328 IMPORT_C ~DObject(); |
|
1329 |
|
1330 /** |
|
1331 Opens this kernel side reference-counted object. |
|
1332 |
|
1333 Opening a reference-counted object increments its reference count |
|
1334 by one. The increment operation is done atomically. |
|
1335 |
|
1336 @return KErrNone, if the increment operation succeeds; |
|
1337 KErrGeneral, if the reference count value is either zero |
|
1338 or negative before performing the increment operation; |
|
1339 the reference count is initialised to 1 on construction |
|
1340 of the object, and can never be less than 1. |
|
1341 */ |
|
1342 inline TInt Open() { return(Inc()?KErrNone:KErrGeneral); } |
|
1343 IMPORT_C void CheckedOpen(); |
|
1344 IMPORT_C virtual TInt Close(TAny* aPtr); |
|
1345 IMPORT_C virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); |
|
1346 IMPORT_C virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType, TUint aAttr); |
|
1347 IMPORT_C virtual TInt AddToProcess(DProcess* aProcess); |
|
1348 IMPORT_C virtual TInt AddToProcess(DProcess* aProcess, TUint aAttr); |
|
1349 IMPORT_C TInt AsyncClose(); |
|
1350 IMPORT_C virtual void DoAppendName(TDes& aName); |
|
1351 IMPORT_C void DoAppendFullName(TDes& aFullName); |
|
1352 IMPORT_C void Name(TDes& aName); |
|
1353 IMPORT_C void AppendName(TDes& aName); |
|
1354 IMPORT_C void FullName(TDes& aFullName); |
|
1355 IMPORT_C void AppendFullName(TDes& aFullName); |
|
1356 IMPORT_C TInt SetName(const TDesC* aName); |
|
1357 IMPORT_C TInt SetOwner(DObject* aOwner); |
|
1358 IMPORT_C void TraceAppendName(TDes8& aName, TBool aLock); |
|
1359 IMPORT_C void TraceAppendFullName(TDes8& aFullName, TBool aLock); |
|
1360 inline DObject* Owner(); |
|
1361 inline TInt AccessCount(); |
|
1362 inline TInt UniqueID(); |
|
1363 inline HBuf* NameBuf(); |
|
1364 inline void SetProtection(TObjectProtection aProtection); |
|
1365 inline TUint Protection(); |
|
1366 void BaseName(TDes& aName); |
|
1367 inline TUint64 ObjectId() const; /**< @internalComponent */ |
|
1368 public: |
|
1369 /** @internalComponent */ |
|
1370 TInt iAccessCount; // must be first |
|
1371 |
|
1372 /** @internalComponent */ |
|
1373 DObject* iOwner; |
|
1374 |
|
1375 /** A TObjectType value with one added |
|
1376 @internalComponent */ |
|
1377 TUint8 iContainerID; |
|
1378 |
|
1379 /** A TObjectProtection value |
|
1380 @internalComponent */ |
|
1381 TUint8 iProtection; |
|
1382 |
|
1383 /** Bit field made of values from TObjectFlags |
|
1384 @internalComponent */ |
|
1385 TUint8 iObjectFlags; |
|
1386 |
|
1387 /** @internalComponent */ |
|
1388 TUint8 iNotQLow; |
|
1389 |
|
1390 /** @internalComponent */ |
|
1391 HBuf* iName; |
|
1392 |
|
1393 /** A unique ID. |
|
1394 @internalComponent */ |
|
1395 TUint64 iObjectId; |
|
1396 |
|
1397 /** @internalComponent */ |
|
1398 // SMiscNotifierQ* iNotifierQ; |
|
1399 |
|
1400 public: |
|
1401 static NFastMutex Lock; |
|
1402 private: |
|
1403 inline SMiscNotifierQ* NotifierQ() const; /**< @internalComponent */ |
|
1404 inline void SetNotifierQ(SMiscNotifierQ*); /**< @internalComponent */ |
|
1405 inline TBool HasNotifierQ() const; /**< @internalComponent */ |
|
1406 private: |
|
1407 static TUint64 NextObjectId; |
|
1408 |
|
1409 friend class DObjectCon; |
|
1410 friend class RObjectIx; |
|
1411 friend class Monitor; |
|
1412 friend class Debugger; |
|
1413 friend void Kern::AppendFormat(TDes8&, const char*, VA_LIST); |
|
1414 friend class K; |
|
1415 friend struct SMiscNotifierQ; |
|
1416 friend class TMiscNotifierMgr; |
|
1417 }; |
|
1418 |
|
1419 /** |
|
1420 Gets the number of open references to |
|
1421 this reference-counted kernel side object. |
|
1422 |
|
1423 @return The number of open references. |
|
1424 */ |
|
1425 inline TInt DObject::AccessCount() |
|
1426 { return iAccessCount; } |
|
1427 |
|
1428 /** |
|
1429 Gets a pointer to the kernel-side reference counted object |
|
1430 that owns this kernel side reference-counted object. |
|
1431 |
|
1432 @return A pointer to the owning reference-counted object. |
|
1433 This is NULL, if there is no owner. |
|
1434 */ |
|
1435 inline DObject* DObject::Owner() |
|
1436 { return iOwner; } |
|
1437 |
|
1438 /** @internalComponent */ |
|
1439 inline HBuf* DObject::NameBuf() |
|
1440 { return iName; } |
|
1441 |
|
1442 /** @internalComponent */ |
|
1443 inline TInt DObject::UniqueID() |
|
1444 {return(iContainerID);} |
|
1445 |
|
1446 /** @internalComponent */ |
|
1447 inline TUint DObject::Protection() |
|
1448 {return (TUint8)iProtection;} |
|
1449 |
|
1450 /** @internalComponent */ |
|
1451 inline void DObject::SetProtection(TObjectProtection aProtection) |
|
1452 {iProtection=(TUint8)aProtection;} |
|
1453 |
|
1454 /******************************************** |
|
1455 * Device driver base classes |
|
1456 ********************************************/ |
|
1457 |
|
1458 /** |
|
1459 @publishedPartner |
|
1460 @released |
|
1461 |
|
1462 If set, it indicates that the use of units is valid. |
|
1463 |
|
1464 @see DLogicalDevice::iParsemask |
|
1465 */ |
|
1466 const TUint KDeviceAllowUnit=0x01; |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 /** |
|
1472 @publishedPartner |
|
1473 @released |
|
1474 |
|
1475 If set, then an LDD requires a PDD. |
|
1476 |
|
1477 @see DLogicalDevice::iParsemask |
|
1478 */ |
|
1479 const TUint KDeviceAllowPhysicalDevice=0x02; |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 /** |
|
1485 @publishedPartner |
|
1486 @released |
|
1487 |
|
1488 If set, it indicates that the use of additional information is allowed. |
|
1489 |
|
1490 @see DLogicalDevice::iParsemask |
|
1491 */ |
|
1492 const TUint KDeviceAllowInfo=0x04; |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 /** |
|
1498 @publishedPartner |
|
1499 @released |
|
1500 |
|
1501 Combines all of: KDeviceAllowUnit, KDeviceAllowPhysicalDevice and KDeviceAllowInfo. |
|
1502 |
|
1503 @see DLogicalDevice::iParsemask |
|
1504 */ |
|
1505 const TUint KDeviceAllowAll=(KDeviceAllowUnit|KDeviceAllowPhysicalDevice|KDeviceAllowInfo); |
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 /** |
|
1511 @publishedPartner |
|
1512 @released |
|
1513 |
|
1514 A flag bit that can set in the aMode parameter passed to the |
|
1515 Kern::ThreadDesWrite(DThread* ,TAny*, const TDesC8&, TInt, TInt aMode, DThread*); |
|
1516 variant. |
|
1517 |
|
1518 It ensures that the length of data copied to the target descriptor is |
|
1519 truncated, if necesary, to prevent the maximum length of that target descriptor |
|
1520 from being exceeded. |
|
1521 |
|
1522 @see Kern::ThreadDesWrite() |
|
1523 */ |
|
1524 const TInt KTruncateToMaxLength=(TInt)0x40000000; |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 /** |
|
1530 @publishedPartner |
|
1531 @released |
|
1532 |
|
1533 Used internally by Symbian OS. |
|
1534 */ |
|
1535 const TInt KCheckLocalAddress=(TInt)0x20000000; |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 /** |
|
1541 @internalTechnology |
|
1542 @prototype |
|
1543 |
|
1544 A flag bit that can set in the aMode parameter passed to the |
|
1545 Kern::ThreadDesWrite(DThread* ,TAny*, const TDesC8&, TInt, TInt aMode, DThread*); |
|
1546 variant. |
|
1547 |
|
1548 It indicates that the descriptor header should not be updated to reflect the new length. |
|
1549 |
|
1550 @see Kern::ThreadDesWrite() |
|
1551 */ |
|
1552 const TInt KDoNotUpdateDesLength=(TInt)0x10000000; |
|
1553 |
|
1554 class DLogicalDevice; |
|
1555 class DPhysicalDevice; |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 /** |
|
1561 @publishedPartner |
|
1562 @released |
|
1563 |
|
1564 The abstract base class for a logical channel. |
|
1565 */ |
|
1566 class DLogicalChannelBase : public DObject |
|
1567 { |
|
1568 public: |
|
1569 IMPORT_C virtual ~DLogicalChannelBase(); |
|
1570 public: |
|
1571 /** |
|
1572 Handles a client request in the client context. |
|
1573 |
|
1574 The function is called from within the kernel, but the implementation |
|
1575 must be provided by external code. |
|
1576 */ |
|
1577 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2)=0; |
|
1578 IMPORT_C virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer); |
|
1579 public: |
|
1580 DLogicalDevice* iDevice; |
|
1581 DPhysicalDevice* iPhysicalDevice; |
|
1582 DBase* iPdd; |
|
1583 }; |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 /** |
|
1589 @publishedPartner |
|
1590 @released |
|
1591 |
|
1592 The abstract base class for an LDD factory object. |
|
1593 */ |
|
1594 class DLogicalDevice : public DObject |
|
1595 { |
|
1596 public: |
|
1597 IMPORT_C virtual ~DLogicalDevice(); |
|
1598 IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVer) const; |
|
1599 IMPORT_C virtual TBool IsAvailable(TInt aUnit, const TDesC* aDriver, const TDesC8* aInfo) const; |
|
1600 TInt ChannelCreate(DLogicalChannelBase*& pC, TChannelCreateInfo& aInfo); |
|
1601 TInt FindPhysicalDevice(DLogicalChannelBase* aChannel, TChannelCreateInfo& aInfo); |
|
1602 |
|
1603 |
|
1604 /** |
|
1605 Second stage constructor for derived objects. |
|
1606 This must at least set a name for the driver object. |
|
1607 |
|
1608 @return KErrNone or standard error code. |
|
1609 */ |
|
1610 virtual TInt Install()=0; |
|
1611 |
|
1612 |
|
1613 /** |
|
1614 Gets the driver's capabilities. |
|
1615 |
|
1616 This is called in the response to an RDevice::GetCaps() request. |
|
1617 |
|
1618 @param aDes A user-side descriptor into which capabilities information is to be wriiten. |
|
1619 */ |
|
1620 virtual void GetCaps(TDes8& aDes) const =0; |
|
1621 |
|
1622 |
|
1623 /** |
|
1624 Called by the kernel's device driver framework to create a Logical Channel. |
|
1625 This is called in the context of the user thread (client) which requested the creation of a Logical Channel |
|
1626 (e.g. through a call to RBusLogicalChannel::DoCreate). |
|
1627 The thread is in a critical section. |
|
1628 |
|
1629 @param aChannel Set to point to the created Logical Channel |
|
1630 |
|
1631 @return KErrNone or standard error code. |
|
1632 */ |
|
1633 virtual TInt Create(DLogicalChannelBase*& aChannel)=0; |
|
1634 |
|
1635 |
|
1636 public: |
|
1637 /** |
|
1638 The version of this factory object. |
|
1639 |
|
1640 This is used to check that an LDD and PDD are compatible. |
|
1641 Typically, this is set by the constructor of a derived class. |
|
1642 */ |
|
1643 TVersion iVersion; |
|
1644 |
|
1645 |
|
1646 /** |
|
1647 A bitmask that indicates device properties. |
|
1648 |
|
1649 This can take the following values: |
|
1650 KDeviceAllowUnit |
|
1651 KDeviceAllowPhysicalDevice |
|
1652 KDeviceAllowInfo |
|
1653 KDeviceAllowAll |
|
1654 |
|
1655 Typically, this is set by the constructor of a derived class. |
|
1656 |
|
1657 @see RBusLogicalChannel::DoCreate() |
|
1658 @see KDeviceAllowUnit |
|
1659 @see KDeviceAllowPhysicalDevice |
|
1660 @see KDeviceAllowInfo |
|
1661 @see KDeviceAllowAll |
|
1662 */ |
|
1663 TUint iParseMask; |
|
1664 |
|
1665 |
|
1666 /** |
|
1667 Indicates which units are valid. |
|
1668 |
|
1669 If units are allowed, i.e. the KDeviceAllowUnit bit is set in iParseMask, |
|
1670 then this mask indicates which of the units (from 0 to 31) are valid. |
|
1671 |
|
1672 The DPhysicalDevice object associated with the PDD has a similar mask, |
|
1673 and both masks are used to indicate which units the LDD-PDD pair |
|
1674 can handle. |
|
1675 |
|
1676 Typically, this is set by the constructor of a derived class. |
|
1677 |
|
1678 @see KDeviceAllowUnit |
|
1679 */ |
|
1680 TUint iUnitsMask; |
|
1681 |
|
1682 |
|
1683 /** |
|
1684 Pointer to the DCodeSeg object which contains the executable code |
|
1685 for this LDD. |
|
1686 */ |
|
1687 DCodeSeg* iCodeSeg; |
|
1688 |
|
1689 |
|
1690 /** |
|
1691 Number of DLogicalChannelBase objects currently in existence which |
|
1692 have been created from this LDD. |
|
1693 */ |
|
1694 TInt iOpenChannels; |
|
1695 }; |
|
1696 |
|
1697 /** @internalComponent */ |
|
1698 typedef DLogicalDevice* (*TLogicalDeviceNew)(); |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 /** |
|
1704 @publishedPartner |
|
1705 @released |
|
1706 |
|
1707 The abstract base class for a PDD factory object. |
|
1708 */ |
|
1709 class DPhysicalDevice : public DObject |
|
1710 { |
|
1711 public: |
|
1712 enum TInfoFunction |
|
1713 { |
|
1714 EPriority=0, |
|
1715 |
|
1716 /** if implemented (i.e. Info(EMediaDriverPersistent) returns KErrNone) implies the media driver |
|
1717 created by this DPhysicalDevice will not be unloaded when the peripheral bus is powered down */ |
|
1718 EMediaDriverPersistent=1, |
|
1719 }; |
|
1720 public: |
|
1721 IMPORT_C virtual ~DPhysicalDevice(); |
|
1722 IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVer) const; |
|
1723 IMPORT_C virtual TBool IsAvailable(TInt aUnit, const TDesC8* aInfo) const; |
|
1724 |
|
1725 /** |
|
1726 Second stage constructor for derived objects. |
|
1727 This must at least set a name for the driver object. |
|
1728 |
|
1729 @return KErrNone or standard error code. |
|
1730 */ |
|
1731 virtual TInt Install() =0; |
|
1732 |
|
1733 /** |
|
1734 Returns the drivers capabilities. This is not used by the Symbian OS device driver framework |
|
1735 but may be useful for the LDD to use. |
|
1736 |
|
1737 @param aDes Descriptor to write capabilities information into |
|
1738 */ |
|
1739 virtual void GetCaps(TDes8& aDes) const =0; |
|
1740 |
|
1741 /** |
|
1742 Called by the kernel's device driver framework to create a Physical Channel. |
|
1743 This is called in the context of the user thread (client) which requested the creation of a Logical Channel |
|
1744 (E.g. through a call to RBusLogicalChannel::DoCreate) |
|
1745 The thread is in a critical section. |
|
1746 |
|
1747 @param aChannel Set to point to the created Physical Channel |
|
1748 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate |
|
1749 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate |
|
1750 @param aVer The version number of the Logical Channel which will use this Physical Channel |
|
1751 |
|
1752 @return KErrNone or standard error code. |
|
1753 */ |
|
1754 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer) =0; |
|
1755 |
|
1756 /** |
|
1757 Called by the kernel's device driver framework to check if this PDD is suitable for use with a Logical Channel. |
|
1758 This is called in the context of the user thread (client) which requested the creation of a Logical Channel |
|
1759 (E.g. through a call to RBusLogicalChannel::DoCreate) |
|
1760 The thread is in a critical section. |
|
1761 |
|
1762 @param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate |
|
1763 @param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate |
|
1764 @param aVer The version number of the Logical Channel which will use this Physical Channel |
|
1765 |
|
1766 @return KErrNone or standard error code. |
|
1767 */ |
|
1768 virtual TInt Validate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer) =0; |
|
1769 IMPORT_C virtual TInt Info(TInt aFunction, TAny* a1); |
|
1770 public: |
|
1771 TVersion iVersion; |
|
1772 TUint iUnitsMask; |
|
1773 DCodeSeg* iCodeSeg; |
|
1774 }; |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 /** @internalComponent */ |
|
1780 typedef DPhysicalDevice* (*TPhysicalDeviceNew)(); |
|
1781 |
|
1782 // Utility stuff for PDD finding |
|
1783 |
|
1784 /** @internalTechnology */ |
|
1785 struct SPhysicalDeviceEntry |
|
1786 { |
|
1787 TInt iPriority; |
|
1788 DPhysicalDevice* iPhysicalDevice; |
|
1789 }; |
|
1790 |
|
1791 /** @internalTechnology */ |
|
1792 class RPhysicalDeviceArray : public RArray<SPhysicalDeviceEntry> |
|
1793 { |
|
1794 public: |
|
1795 IMPORT_C RPhysicalDeviceArray(); |
|
1796 IMPORT_C void Close(); |
|
1797 IMPORT_C TInt GetDriverList(const TDesC& aMatch, TInt aUnit, const TDesC8* aInfo, const TVersion& aVersion); |
|
1798 }; |
|
1799 |
|
1800 /******************************************** |
|
1801 * Kernel-side messages and message queues. |
|
1802 ********************************************/ |
|
1803 class TMessageQue; |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 /** |
|
1809 @publishedPartner |
|
1810 @released |
|
1811 |
|
1812 The base class for a kernel side message. |
|
1813 |
|
1814 This is a means of communication between Symbian OS threads |
|
1815 executing kernel-side code. |
|
1816 */ |
|
1817 class TMessageBase : public SDblQueLink |
|
1818 { |
|
1819 public: |
|
1820 /** @internalComponent */ |
|
1821 enum TState {EFree,EDelivered,EAccepted}; |
|
1822 public: |
|
1823 TMessageBase() : iState(EFree), iQueue(NULL) {} |
|
1824 IMPORT_C void Send(TMessageQue* aQ); |
|
1825 IMPORT_C TInt SendReceive(TMessageQue* aQ); |
|
1826 IMPORT_C void Forward(TMessageQue* aQ, TBool aReceiveNext); |
|
1827 IMPORT_C void Complete(TInt aResult, TBool aReceiveNext); |
|
1828 IMPORT_C void Cancel(); /**< @internalComponent */ |
|
1829 IMPORT_C void PanicClient(const TDesC& aCategory, TInt aReason); |
|
1830 public: |
|
1831 IMPORT_C DThread* Client(); |
|
1832 public: |
|
1833 TUint8 iState; /**< @internalComponent */ |
|
1834 TMessageQue* iQueue; /**< @internalComponent */ |
|
1835 NFastSemaphore iSem; /**< @internalComponent */ |
|
1836 TInt iValue; /**< @internalComponent */ // msg id/return code |
|
1837 }; |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 /** |
|
1843 @publishedPartner |
|
1844 @released |
|
1845 |
|
1846 A queue for kernel-side messages. |
|
1847 |
|
1848 Objects of this type consist of a DFC plus a doubly-linked list |
|
1849 of received messages. |
|
1850 */ |
|
1851 class TMessageQue : private TDfc |
|
1852 { |
|
1853 public: |
|
1854 IMPORT_C TMessageQue(TDfcFn aFunction, TAny* aPtr, TDfcQue* aDfcQ, TInt aPriority); |
|
1855 IMPORT_C void Receive(); |
|
1856 IMPORT_C TMessageBase* Poll(); |
|
1857 IMPORT_C TMessageBase* Last(); |
|
1858 IMPORT_C void CompleteAll(TInt aResult); |
|
1859 using TDfc::SetDfcQ; |
|
1860 public: |
|
1861 inline static void Lock() {NKern::FMWait(&MsgLock);} /**< @internalComponent */ |
|
1862 inline static void Unlock() {NKern::FMSignal(&MsgLock);} /**< @internalComponent */ |
|
1863 inline void UnlockAndKick() {Enque(&MsgLock);} /**< @internalComponent */ |
|
1864 public: |
|
1865 SDblQue iQ; /**< @internalComponent */ |
|
1866 TBool iReady; /**< @internalComponent */ |
|
1867 TMessageBase* iMessage; /**< @internalComponent */ |
|
1868 static NFastMutex MsgLock; /**< @internalComponent */ |
|
1869 friend class TMessageBase; |
|
1870 }; |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 /** |
|
1876 @publishedPartner |
|
1877 @released |
|
1878 |
|
1879 Synchronous kernel-side messages. |
|
1880 |
|
1881 There is one per thread, and the thread always blocks while the message is outstanding. |
|
1882 The iPtr field of a DFC points to the message. |
|
1883 */ |
|
1884 class TThreadMessage : public TMessageBase |
|
1885 { |
|
1886 public: |
|
1887 /** |
|
1888 Returns argument 0 as an integer. |
|
1889 */ |
|
1890 inline TInt Int0() const {return (TInt)iArg[0];} |
|
1891 |
|
1892 /** |
|
1893 Returns argument 1 as an integer. |
|
1894 */ |
|
1895 inline TInt Int1() const {return (TInt)iArg[1];} |
|
1896 |
|
1897 /** |
|
1898 Returns argument 2 as an integer. |
|
1899 */ |
|
1900 inline TInt Int2() const {return (TInt)iArg[2];} |
|
1901 |
|
1902 /** |
|
1903 Returns argument 3 as an integer. |
|
1904 */ |
|
1905 inline TInt Int3() const {return (TInt)iArg[3];} |
|
1906 |
|
1907 /** |
|
1908 Returns argument 0 as a pointer type. |
|
1909 */ |
|
1910 inline TAny* Ptr0() const {return iArg[0];} |
|
1911 |
|
1912 /** |
|
1913 Returns argument 1 as a pointer type. |
|
1914 */ |
|
1915 inline TAny* Ptr1() const {return iArg[1];} |
|
1916 |
|
1917 /** |
|
1918 Returns argument 2 as a pointer type. |
|
1919 */ |
|
1920 inline TAny* Ptr2() const {return iArg[2];} |
|
1921 |
|
1922 /** |
|
1923 Returns argument 3 as a pointer type. |
|
1924 */ |
|
1925 inline TAny* Ptr3() const {return iArg[3];} |
|
1926 public: |
|
1927 /** |
|
1928 Message arguments. |
|
1929 */ |
|
1930 TAny* iArg[10]; // message arguments |
|
1931 }; |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 /** |
|
1937 @publishedPartner |
|
1938 @released |
|
1939 |
|
1940 An abstract class for a logical channel that provides a framework in which |
|
1941 user-side client requests are executed in the context of |
|
1942 a single kernel-side thread. |
|
1943 */ |
|
1944 class DLogicalChannel : public DLogicalChannelBase |
|
1945 { |
|
1946 public: |
|
1947 enum { |
|
1948 /** |
|
1949 Defines the smallest request number that Request() accepts. |
|
1950 Smaller request numbers will raise a panic. |
|
1951 */ |
|
1952 EMinRequestId=(TInt)0xc0000000, |
|
1953 |
|
1954 /** |
|
1955 The value of the close message sent to the device driver thread |
|
1956 by Close(). |
|
1957 */ |
|
1958 ECloseMsg=(TInt)0x80000000}; |
|
1959 public: |
|
1960 IMPORT_C DLogicalChannel(); |
|
1961 IMPORT_C virtual ~DLogicalChannel(); |
|
1962 IMPORT_C virtual TInt Close(TAny*); |
|
1963 IMPORT_C virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
1964 IMPORT_C virtual TInt SendMsg(TMessageBase* aMsg); |
|
1965 |
|
1966 /** |
|
1967 Processes a message for this logical channel. |
|
1968 This function is called in the context of a DFC thread. |
|
1969 |
|
1970 @param aMsg The message to process. |
|
1971 The iValue member of this distinguishes the message type: |
|
1972 iValue==ECloseMsg, channel close message |
|
1973 iValue==KMaxTInt, a 'DoCancel' message |
|
1974 iValue>=0, a 'DoControl' message with function number equal to iValue |
|
1975 iValue<0, a 'DoRequest' message with function number equal to ~iValue |
|
1976 */ |
|
1977 IMPORT_C virtual void HandleMsg(TMessageBase* aMsg)=0; |
|
1978 IMPORT_C void SetDfcQ(TDfcQue* aDfcQ); |
|
1979 public: |
|
1980 static void MsgQFunc(TAny* aPtr); |
|
1981 public: |
|
1982 TDfcQue* iDfcQ; |
|
1983 TMessageQue iMsgQ; |
|
1984 }; |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 /******************************************** |
|
1990 * Timers based on the system tick |
|
1991 ********************************************/ |
|
1992 |
|
1993 /** |
|
1994 @publishedPartner |
|
1995 @released |
|
1996 |
|
1997 Defines the signature for a tick timer callback function. |
|
1998 */ |
|
1999 typedef void (*TTickCallBack)(TAny* aPtr); |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 /** |
|
2005 @publishedPartner |
|
2006 @released |
|
2007 |
|
2008 Relative timer with the resolution of one Symbian OS tick (generally 1/64 second). |
|
2009 |
|
2010 Tick timers are general purpose interval timers which are used where there |
|
2011 is no need for high resolution or great accuracy. They correspond to the |
|
2012 timing functions available to user side code on EKA1 (User::After, |
|
2013 RTimer::After, RTimer::Lock). |
|
2014 |
|
2015 @see User::After() |
|
2016 @see RTimer::After() |
|
2017 @see RTimer::Lock() |
|
2018 */ |
|
2019 class TTickLink : public SDeltaQueLink |
|
2020 { |
|
2021 public: |
|
2022 IMPORT_C TTickLink(); |
|
2023 IMPORT_C void Periodic(TInt aPeriod, TTickCallBack aCallBack, TAny* aPtr); |
|
2024 IMPORT_C void OneShot(TInt aTime, TTickCallBack aCallBack, TAny* aPtr); |
|
2025 IMPORT_C void Lock(TInt aTicks, TTickCallBack aCallBack, TAny* aPtr); |
|
2026 IMPORT_C void Cancel(); |
|
2027 void DoCancel(); |
|
2028 TInt GetNextLock(TTimerLockSpec aMark, TInt &aTickCount) const; |
|
2029 public: |
|
2030 TInt iPeriod; /**< @internalComponent */ |
|
2031 TAny *iPtr; /**< @internalComponent */ |
|
2032 TTickCallBack iCallBack; /**< @internalComponent */ |
|
2033 Int64 iLastLock; /**< @internalComponent */ |
|
2034 }; |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 /** |
|
2040 @publishedPartner |
|
2041 @released |
|
2042 |
|
2043 Defines the signature for a second timer callback function. |
|
2044 |
|
2045 @see TSecondLink |
|
2046 */ |
|
2047 typedef void (*TSecondCallBack)(TAny* aPtr); |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 /** |
|
2053 @publishedPartner |
|
2054 @released |
|
2055 |
|
2056 Absolute timer with a resolution of 1 second. |
|
2057 |
|
2058 Second timers are used when an event needs to occur at a specific date and |
|
2059 time of day, rather than after a specified interval. They have a resolution of |
|
2060 1 second. |
|
2061 |
|
2062 They are typically used for user alarms, and, if necessary, will power up |
|
2063 the system at the expiry time. |
|
2064 */ |
|
2065 class TSecondLink : public SDblQueLink |
|
2066 { |
|
2067 public: |
|
2068 IMPORT_C TSecondLink(); |
|
2069 IMPORT_C TInt At(const TTimeK& aUTCTime, TSecondCallBack aCallBack, TAny* aPtr); |
|
2070 IMPORT_C void Cancel(); |
|
2071 public: |
|
2072 Int64 iTime; /**< @internalComponent */ |
|
2073 TAny* iPtr; /**< @internalComponent */ |
|
2074 TSecondCallBack iCallBack; /**< @internalComponent */ |
|
2075 }; |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 /** |
|
2081 @publishedPartner |
|
2082 @released |
|
2083 |
|
2084 Defines the signature for an inactivity timer callback function. |
|
2085 |
|
2086 @see TInactivityLink |
|
2087 */ |
|
2088 typedef void (*TInactivityCallBack)(TAny*); |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 /** |
|
2094 @publishedPartner |
|
2095 @released |
|
2096 |
|
2097 Inactivity timer. |
|
2098 |
|
2099 Inactivity timers are used to detect a specified period of user inactivity, |
|
2100 for example to enable device auto power down or screen saver functionality. |
|
2101 */ |
|
2102 class TInactivityLink : public SDblQueLink |
|
2103 { |
|
2104 public: |
|
2105 IMPORT_C TInactivityLink(); |
|
2106 IMPORT_C TInt Start(TInt aSeconds, TInactivityCallBack aCallBack, TAny* aPtr); |
|
2107 IMPORT_C void Cancel(); |
|
2108 public: |
|
2109 TUint32 iTime; /**< @internalComponent */ // expiry time in ticks |
|
2110 TAny* iPtr; /**< @internalComponent */ |
|
2111 TInactivityCallBack iCallBack; /**< @internalComponent */ |
|
2112 }; |
|
2113 |
|
2114 /******************************************** |
|
2115 * Internal RAM drive |
|
2116 ********************************************/ |
|
2117 |
|
2118 /** |
|
2119 @internalTechnology |
|
2120 */ |
|
2121 class TInternalRamDrive |
|
2122 { |
|
2123 public: |
|
2124 static TInt Create(); |
|
2125 IMPORT_C static TLinAddr Base(); |
|
2126 IMPORT_C static TInt Size(); |
|
2127 IMPORT_C static TInt MaxSize(); |
|
2128 IMPORT_C static TInt Adjust(TInt aNewSize); |
|
2129 IMPORT_C static void Lock(); |
|
2130 IMPORT_C static void Unlock(); |
|
2131 IMPORT_C static void Wait(); |
|
2132 IMPORT_C static void Signal(); |
|
2133 public: |
|
2134 static DMutex* Mutex; |
|
2135 friend class Monitor; |
|
2136 }; |
|
2137 |
|
2138 /********************************************/ |
|
2139 |
|
2140 /** List of all supported events. |
|
2141 |
|
2142 By default, all events, except the explicitly mentioned ones, are sent only |
|
2143 if the kernel is built with __DEBUGGER_SUPPORT__ defined. |
|
2144 |
|
2145 This event set may be extended in the future, so clients should handle |
|
2146 unknown events gracefully. |
|
2147 |
|
2148 @see DKernelEventHandler |
|
2149 @publishedPartner |
|
2150 @released |
|
2151 */ |
|
2152 enum TKernelEvent |
|
2153 { |
|
2154 /** |
|
2155 Event delivered when a user-side software exception occurs. |
|
2156 This event is always sent. |
|
2157 The following conditions are true: |
|
2158 - a1 contains a TExcType instance. |
|
2159 - The current thread is the thread taking the exception. |
|
2160 */ |
|
2161 EEventSwExc, |
|
2162 |
|
2163 /** |
|
2164 Event delivered when a hardware exception occurs. |
|
2165 This event is always sent. |
|
2166 The following conditions are true: |
|
2167 - a1 points to the CPU-specific structure stored on the |
|
2168 stack where the processor state has been saved. For ARM, |
|
2169 the structure is TArmExcInfo. |
|
2170 - The current thread is the thread taking the exception. |
|
2171 On exit, use DKernelEventHandler::EExcHandled to indicate event |
|
2172 handled. |
|
2173 */ |
|
2174 EEventHwExc, |
|
2175 |
|
2176 /** |
|
2177 Event delivered when a process is created (i.e. during a call to |
|
2178 RProcess::Create or Kern::ProcessCreate()). |
|
2179 The following conditions are true: |
|
2180 - a1 points to the process being created. |
|
2181 - a2 points to the creator thread (which may not be the current thread). |
|
2182 In some case the creator thread can not be reliably determined and a2 |
|
2183 will be set to NULL. |
|
2184 - The process being created is partly constructed (no threads and no chunks yet). |
|
2185 */ |
|
2186 EEventAddProcess, |
|
2187 |
|
2188 /** |
|
2189 Event delivered after a process attribute change. Currently this applies |
|
2190 only to process renaming and address space change (chunk addition/removal) |
|
2191 but may be extended in the future. |
|
2192 The following conditions are true: |
|
2193 - a1 points to the process being modified. |
|
2194 - The process lock may be held |
|
2195 */ |
|
2196 EEventUpdateProcess, |
|
2197 |
|
2198 /** |
|
2199 Event delivered when a process terminates. |
|
2200 The following conditions are true: |
|
2201 - a1 points to the process being terminated. |
|
2202 - The current thread is the kernel server thread. |
|
2203 - The process is partly destructed so its resources should be accessed |
|
2204 only after checking they still exist. |
|
2205 */ |
|
2206 EEventRemoveProcess, |
|
2207 |
|
2208 /** |
|
2209 Event delivered when a user or kernel thread is created (i.e. during a call |
|
2210 to RProcess::Create(), RThread::Create() or Kern::ThreadCreate()). |
|
2211 The following conditions are true: |
|
2212 - a1 points to the thread being created. |
|
2213 - a2 points to the creator thread (which may not be the current thread). |
|
2214 - The thread being created is fully constructed but has not executed any code yet. |
|
2215 */ |
|
2216 EEventAddThread, |
|
2217 |
|
2218 /** |
|
2219 Event delivered when a user or kernel thread is scheduled for the first time. |
|
2220 The following conditions are true: |
|
2221 - a1 points to the thread being scheduled. |
|
2222 - The current thread is the thread being scheduled. |
|
2223 - The thread has not executed any code yet. |
|
2224 */ |
|
2225 EEventStartThread, |
|
2226 |
|
2227 /** |
|
2228 Event delivered after a thread attribute change. Currently this applies |
|
2229 only to thread renaming but may be extended in the future. |
|
2230 a1 points to the thread being modified. |
|
2231 */ |
|
2232 EEventUpdateThread, |
|
2233 |
|
2234 /** |
|
2235 Event delivered when a user or kernel thread terminates. |
|
2236 This event is always sent. |
|
2237 The following conditions are true: |
|
2238 - a1 points to the thread being terminated. |
|
2239 - The current thread is the thread being terminated. |
|
2240 - The current thread is in the ECSExitInProgress state, |
|
2241 and so can not be suspended. |
|
2242 - The thread's address space can be inspected. |
|
2243 */ |
|
2244 EEventKillThread, |
|
2245 |
|
2246 /** |
|
2247 Event delivered when a user or kernel thread is about to be closed. |
|
2248 The following conditions are true: |
|
2249 - a1 points to the thread being terminated. |
|
2250 - The current thread is the supervisor thread. |
|
2251 - The thread is partly destructed so its resources should be accessed |
|
2252 only after checking if they still exist. |
|
2253 */ |
|
2254 EEventRemoveThread, |
|
2255 |
|
2256 /** |
|
2257 Event delivered when a chunk is created. |
|
2258 The following conditions are true: |
|
2259 - a1 points to the chunk being created. |
|
2260 */ |
|
2261 EEventNewChunk, |
|
2262 |
|
2263 /** |
|
2264 Event delivered when physical memory is committed to/decommitted from a |
|
2265 chunk. |
|
2266 The following conditions are true: |
|
2267 - a1 points to the chunk being modified. |
|
2268 */ |
|
2269 EEventUpdateChunk, |
|
2270 |
|
2271 /** |
|
2272 Event delivered when a chunk is deleted. |
|
2273 The following conditions are true: |
|
2274 - a1 points to the chunk being deleted. |
|
2275 */ |
|
2276 EEventDeleteChunk, |
|
2277 |
|
2278 /** |
|
2279 Event delivered when a user-side DLL is explicitly loaded. |
|
2280 The following conditions are true: |
|
2281 - a1 points to the DLibrary instance being loaded. |
|
2282 - a2 points to the creator thread. |
|
2283 - DLibrary::iMapCount is equals to 1 if the DLL is loaded for the first |
|
2284 time into the creator thread's address space. |
|
2285 - If the DLL is loaded for the first time, its global c'tors (if any) |
|
2286 haven't been called yet. |
|
2287 - The DLL and all its dependencies have been mapped. |
|
2288 - The system-wide mutex DCodeSeg::CodeSegLock is held. |
|
2289 */ |
|
2290 EEventAddLibrary, |
|
2291 |
|
2292 /** |
|
2293 Event delivered when a previously explicitly loaded user-side DLL is |
|
2294 closed or unloaded (i.e. call to RLibrary::Close()). |
|
2295 The following conditions are true: |
|
2296 - a1 points to the DLibrary instance being unloaded. |
|
2297 - DLibrary::iMapCount is equals to 0 if the DLL is about to be unloaded. |
|
2298 - If the DLL is about to be unloaded, its global d'tors have been called |
|
2299 but it is still mapped (and so are its dependencies). |
|
2300 - The current thread may be the kernel server. |
|
2301 - The system-wide mutex DCodeSeg::CodeSegLock is held. |
|
2302 */ |
|
2303 EEventRemoveLibrary, |
|
2304 |
|
2305 /** |
|
2306 Event delivered when a LDD is loaded. |
|
2307 The following conditions are true: |
|
2308 - a1 points to the LDD's code segment (DCodeSeg instance). |
|
2309 - The current thread is the loader thread. |
|
2310 - The LDD factory function has not been called yet. |
|
2311 */ |
|
2312 EEventLoadLdd, |
|
2313 |
|
2314 /** |
|
2315 Event delivered when a LDD is unloaded. |
|
2316 The following conditions are true: |
|
2317 - a1 points to the LDD's code segment (DCodeSeg instance). |
|
2318 - The current thread is the loader thread. |
|
2319 */ |
|
2320 EEventUnloadLdd, |
|
2321 |
|
2322 /** |
|
2323 Event delivered when a PDD is loaded. |
|
2324 The following conditions are true: |
|
2325 - a1 points to the PDD's code segment (DCodeSeg instance). |
|
2326 - The current thread is the loader thread. |
|
2327 - The PDD factory function has not been called yet. |
|
2328 */ |
|
2329 EEventLoadPdd, |
|
2330 |
|
2331 /** |
|
2332 Event delivered when a PDD is unloaded. |
|
2333 The following conditions are true: |
|
2334 - a1 points to the PDD's code segment (DCodeSeg instance). |
|
2335 - The current thread is the loader thread. |
|
2336 */ |
|
2337 EEventUnloadPdd, |
|
2338 |
|
2339 /** |
|
2340 Event delivered when RDebug::Print is called in user-side code. |
|
2341 The following conditions are true: |
|
2342 - a1 points to the user-side buffer containing the unicode string |
|
2343 for printing. The characters can not be accessed directly. The |
|
2344 string must copied instead using kumemget() and, as the event |
|
2345 is delivered in thread critical section, the call to kumemget() |
|
2346 must be protected with XTRAP. |
|
2347 - a2 is a TInt which holds the length in characters of the string |
|
2348 for printing. As this is a unicode string, the size of the |
|
2349 user-side buffer is twice the length. |
|
2350 - The current thread is the user-side client. |
|
2351 On exit use DKernelEventHandler::ETraceHandled to indicate event handled. |
|
2352 */ |
|
2353 EEventUserTrace, |
|
2354 |
|
2355 /** |
|
2356 Event delivered when a code segment is mapped into a process. |
|
2357 The following conditions are true: |
|
2358 - a1 points to the code segment. |
|
2359 - a2 points to the process. |
|
2360 - The system-wide mutex DCodeSeg::CodeSegLock is held. |
|
2361 */ |
|
2362 EEventAddCodeSeg, |
|
2363 |
|
2364 /** |
|
2365 Event delivered when a code segment is unmapped from a process. |
|
2366 The following conditions are true: |
|
2367 - a1 points to the code segment. |
|
2368 - a2 points to the process. |
|
2369 - The system-wide mutex DCodeSeg::CodeSegLock is held. |
|
2370 */ |
|
2371 EEventRemoveCodeSeg, |
|
2372 |
|
2373 /** |
|
2374 Event delivered when a process is created (i.e. during a call to |
|
2375 RProcess::Create or Kern::ProcessCreate()). |
|
2376 The following conditions are true: |
|
2377 - a1 points to the process. |
|
2378 - The process being created is fully constructed. |
|
2379 */ |
|
2380 EEventLoadedProcess, |
|
2381 |
|
2382 /** |
|
2383 Event delivered when a process is being released, before its code segment, |
|
2384 stack chunk, etc. are unmapped. |
|
2385 The following conditions are true: |
|
2386 - a1 points to the process. |
|
2387 - The process being released is fully constructed. |
|
2388 */ |
|
2389 EEventUnloadingProcess, |
|
2390 |
|
2391 /** |
|
2392 Must be last |
|
2393 */ |
|
2394 EEventLimit |
|
2395 }; |
|
2396 |
|
2397 /** Access-counted event handler callback. |
|
2398 |
|
2399 The kernel maintains a queue of event handlers which are called in turn |
|
2400 when various events (thread creation, hardware exception, ...) occur. |
|
2401 |
|
2402 Typical clients would be drivers or kernel extensions implementing kernel |
|
2403 debug agents or profilers. This class could also be used to extend the |
|
2404 instruction set (by trapping undefined instructions). |
|
2405 |
|
2406 An access count needs to be maintained because handlers can not be dequeued |
|
2407 and destructed while one or more threads are executing some code inside the |
|
2408 callback. The access count, initially set to 1, is incremented every time |
|
2409 a thread enters the callback and decremented every time a thread exits the |
|
2410 callback. |
|
2411 |
|
2412 Consequently: |
|
2413 |
|
2414 - Client code should use Close() instead the operator delete to destroy the |
|
2415 event handler. |
|
2416 |
|
2417 - If the client is a LDD, the lifetime of the event handler may exceed that |
|
2418 of the logical channel and its user-side client thread. Therefore, the |
|
2419 callback should not refer to data stored in the channel and any |
|
2420 asynchronous request to be completed in the callback should be cancelled by |
|
2421 the channel destructor. |
|
2422 |
|
2423 If the client is a RAM-loaded LDD (or PDD), it is possible for the DLL to |
|
2424 be unloaded while the handler is still in use. This would result in an |
|
2425 exception. To avoid this, the handler must open a reference to the |
|
2426 DLogicalDevice (or DPhysicalDevice) and close it in its d'tor. |
|
2427 |
|
2428 @publishedPartner |
|
2429 @released |
|
2430 */ |
|
2431 class DKernelEventHandler : public DBase |
|
2432 { |
|
2433 public: |
|
2434 /** Values used to select where to insert the handler in the queue */ |
|
2435 enum TAddPolicy |
|
2436 { |
|
2437 EAppend, /**< Append at end of queue */ |
|
2438 }; |
|
2439 |
|
2440 /** Bitmask returned by callback function */ |
|
2441 enum TReturnCode |
|
2442 { |
|
2443 /** Run next handler if set, ignore remaining handlers if cleared */ |
|
2444 ERunNext = 1, |
|
2445 /** Available for EEventUserTrace only. Ignore trace statement if set. */ |
|
2446 ETraceHandled = 0x40000000, |
|
2447 /** Available for hardware exceptions only. Do not panic thread if set. */ |
|
2448 EExcHandled = (TInt)0x80000000, |
|
2449 }; |
|
2450 |
|
2451 /** Pointer to C callback function called when an event occurs. |
|
2452 aEvent designates what event is dispatched. a1 and a2 are event-specific. |
|
2453 aPrivateData is specified when the handler is created, typically a pointer |
|
2454 to the event handler. |
|
2455 The function is always called in thread critical section. |
|
2456 @see TReturnCode |
|
2457 */ |
|
2458 typedef TUint (*TCallback)(TKernelEvent aEvent, TAny* a1, TAny* a2, TAny* aPrivateData); |
|
2459 public: |
|
2460 // external interface |
|
2461 IMPORT_C static TBool DebugSupportEnabled(); |
|
2462 IMPORT_C DKernelEventHandler(TCallback aCb, TAny* aPrivateData); |
|
2463 IMPORT_C TInt Add(TAddPolicy aPolicy = EAppend); |
|
2464 IMPORT_C TInt Close(); |
|
2465 inline TBool IsQueued() const; |
|
2466 public: |
|
2467 // kernel internal interface |
|
2468 static TUint Dispatch(TKernelEvent aEvent, TAny* a1, TAny* a2); |
|
2469 private: |
|
2470 static SDblQue HandlersQ; |
|
2471 private: |
|
2472 TInt iAccessCount; |
|
2473 SDblQueLink iLink; |
|
2474 TCallback iCb; |
|
2475 TAny* iPrivateData; |
|
2476 }; |
|
2477 |
|
2478 /** Returns whether or not the handler has been queued. */ |
|
2479 inline TBool DKernelEventHandler::IsQueued() const |
|
2480 { |
|
2481 return iLink.iNext != NULL; |
|
2482 } |
|
2483 |
|
2484 |
|
2485 /******************************************** |
|
2486 * Persistent Machine Configuration |
|
2487 ********************************************/ |
|
2488 |
|
2489 /** |
|
2490 @internalTechnology |
|
2491 */ |
|
2492 class TMachineConfig |
|
2493 { |
|
2494 public: |
|
2495 TInt iLogSize; |
|
2496 TInt iLogMaxSize; |
|
2497 SLocaleData iLocale; |
|
2498 TInt iXtalError; |
|
2499 |
|
2500 /** The last time set by the user */ |
|
2501 TTimeK LastSetTime; |
|
2502 |
|
2503 /** The accumulated RTC correction due to crystal errors */ |
|
2504 TInt TheRTCCorrection; |
|
2505 }; |
|
2506 |
|
2507 /****************************************************************************** |
|
2508 * Macros for typical extensions/device drivers/ASSPs |
|
2509 ******************************************************************************/ |
|
2510 #ifndef __WINS__ |
|
2511 /** |
|
2512 @internalComponent |
|
2513 @prototype 9.5 |
|
2514 |
|
2515 Defines the entry point for an extension that specifies a priority |
|
2516 Priorities are used to sequence calls to the entry point (KModuleEntryReasonExtensionInit1) |
|
2517 and may be used to ensure that extensions with higher priority are started before |
|
2518 ones with lower priority. When the priority of 2 extensions is the same, the order |
|
2519 they are started is the order they appear in the ROM header extension list. |
|
2520 The maximum priority is 255. Priority 0 is the lowest priority (standard extension). |
|
2521 @note This feature is not available for the emulator. |
|
2522 */ |
|
2523 #define DECLARE_EXTENSION_WITH_PRIORITY(priority) \ |
|
2524 GLREF_C TInt InitExtension(); \ |
|
2525 TInt KernelModuleEntry(TInt aReason) \ |
|
2526 { \ |
|
2527 if (aReason==KModuleEntryReasonExtensionInit0) \ |
|
2528 return priority; \ |
|
2529 if (aReason!=KModuleEntryReasonExtensionInit1) \ |
|
2530 return KErrArgument; \ |
|
2531 return InitExtension(); \ |
|
2532 } \ |
|
2533 GLDEF_C TInt InitExtension() |
|
2534 |
|
2535 |
|
2536 /** |
|
2537 @publishedPartner |
|
2538 @released |
|
2539 |
|
2540 Defines the entry point for a standard extension |
|
2541 */ |
|
2542 #define DECLARE_STANDARD_EXTENSION() DECLARE_EXTENSION_WITH_PRIORITY(KExtensionStandardPriority) |
|
2543 |
|
2544 #else |
|
2545 /** |
|
2546 @publishedPartner |
|
2547 @released |
|
2548 |
|
2549 Defines the entry point for a standard extension |
|
2550 */ |
|
2551 #define DECLARE_STANDARD_EXTENSION() \ |
|
2552 GLREF_C TInt InitExtension(); \ |
|
2553 TInt KernelModuleEntry(TInt aReason) \ |
|
2554 { \ |
|
2555 if (aReason==KModuleEntryReasonExtensionInit0) \ |
|
2556 return KErrNone; \ |
|
2557 if (aReason!=KModuleEntryReasonExtensionInit1) \ |
|
2558 return KErrArgument; \ |
|
2559 return InitExtension(); \ |
|
2560 } \ |
|
2561 GLDEF_C TInt InitExtension() |
|
2562 |
|
2563 #endif |
|
2564 |
|
2565 /** |
|
2566 @publishedPartner |
|
2567 @released |
|
2568 |
|
2569 Defines the entry point for a standard logical device driver (LDD), |
|
2570 and declares the ordinal 1 export function for creating the LDD factory object |
|
2571 */ |
|
2572 #define DECLARE_STANDARD_LDD() \ |
|
2573 TInt KernelModuleEntry(TInt) \ |
|
2574 { return KErrNone; } \ |
|
2575 EXPORT_C DLogicalDevice* CreateLogicalDevice() |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 /** |
|
2581 @publishedPartner |
|
2582 @released |
|
2583 |
|
2584 Defines the entry point for a standard physical device driver (PDD), |
|
2585 and declares the ordinal 1 export function for creating the PDD factory object. |
|
2586 */ |
|
2587 #define DECLARE_STANDARD_PDD() \ |
|
2588 TInt KernelModuleEntry(TInt) \ |
|
2589 { return KErrNone; } \ |
|
2590 EXPORT_C DPhysicalDevice* CreatePhysicalDevice() |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 /** |
|
2596 @publishedPartner |
|
2597 @released |
|
2598 |
|
2599 Defines the entry point for a standard logical device driver (LDD) |
|
2600 that is also an extension, and declares the ordinal 1 export function |
|
2601 for creating the LDD factory object |
|
2602 */ |
|
2603 #define DECLARE_EXTENSION_LDD() \ |
|
2604 EXPORT_C DLogicalDevice* CreateLogicalDevice() |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 /** |
|
2610 @publishedPartner |
|
2611 @released |
|
2612 |
|
2613 Defines the entry point for a standard physical device driver (PDD) |
|
2614 that is also an extension, and declares the ordinal 1 export function |
|
2615 for creating the PDD factory object |
|
2616 */ |
|
2617 #define DECLARE_EXTENSION_PDD() \ |
|
2618 EXPORT_C DPhysicalDevice* CreatePhysicalDevice() |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 /** |
|
2624 @publishedPartner |
|
2625 @released |
|
2626 |
|
2627 Generates a stub entry point function and the AsicInitialise() function that |
|
2628 causes static constructors to be called. |
|
2629 |
|
2630 ASSP DLLs require static constructors to be called at the same time as |
|
2631 the variant is initialised. |
|
2632 */ |
|
2633 #define DECLARE_STANDARD_ASSP() \ |
|
2634 extern "C" { GLREF_C TInt _E32Dll(TInt); } \ |
|
2635 GLDEF_C TInt KernelModuleEntry(TInt aReason) \ |
|
2636 { return (aReason==KModuleEntryReasonExtensionInit1) \ |
|
2637 ?KErrNone:KErrGeneral; } \ |
|
2638 EXPORT_C void AsicInitialise() \ |
|
2639 { _E32Dll(KModuleEntryReasonExtensionInit1); } |
|
2640 |
|
2641 |
|
2642 /** |
|
2643 @internalComponent |
|
2644 */ |
|
2645 #define __VARIANT_SUPPORTS_ADDITIONAL_INTERFACE_BLOCK__(x) \ |
|
2646 __Variant_Flags__ |= (x) |
|
2647 |
|
2648 /** |
|
2649 @internalTechnology |
|
2650 @prototype |
|
2651 Used to indicate that a variant supports the nanokernel interface block |
|
2652 */ |
|
2653 #define __VARIANT_SUPPORTS_NANOKERNEL_INTERFACE_BLOCK__() \ |
|
2654 __VARIANT_SUPPORTS_ADDITIONAL_INTERFACE_BLOCK__(1) |
|
2655 |
|
2656 |
|
2657 class DemandPaging; |
|
2658 |
|
2659 /** |
|
2660 Memory locking on demand paging systems. |
|
2661 |
|
2662 This class is not thread safe. I.e. Only one method should be executed at any time |
|
2663 for a given instance of an object. |
|
2664 |
|
2665 @internalTechnology |
|
2666 @prototype |
|
2667 */ |
|
2668 class DDemandPagingLock : public DBase |
|
2669 { |
|
2670 public: |
|
2671 IMPORT_C DDemandPagingLock(); |
|
2672 |
|
2673 /** |
|
2674 Unlock and Free the memory associated with this object |
|
2675 */ |
|
2676 inline ~DDemandPagingLock() { Free(); } |
|
2677 |
|
2678 /** |
|
2679 Reserve memory so that this object can be used for locking up to |
|
2680 the specified number of bytes. |
|
2681 |
|
2682 @param aSize Maximum number of bytes to be locked. |
|
2683 |
|
2684 @return KErrNone or standard error code. |
|
2685 */ |
|
2686 IMPORT_C TInt Alloc(TInt aSize); |
|
2687 |
|
2688 /** |
|
2689 Unlock any memory locked by this object, then free the memory reserved with |
|
2690 Alloc(). This returns the object to the same state it was at immediately after |
|
2691 construction. |
|
2692 */ |
|
2693 IMPORT_C void Free(); |
|
2694 |
|
2695 /** |
|
2696 Ensure all pages in the given region are present and lock them so that they will |
|
2697 not be paged out. If the region contained no demand paged memory, then no action |
|
2698 is performed. |
|
2699 |
|
2700 This function may not be called again until the previous memory has been |
|
2701 unlocked. |
|
2702 |
|
2703 @param aThread The thread in whoes process the memory lies. |
|
2704 @param aStart The address of the first byte of memory to be locked. |
|
2705 @param aSize The number of bytes to lock. |
|
2706 |
|
2707 @return 1 (one) if any memory was locked. 0 (KErrNone) if memory |
|
2708 did not need locking because it is not demand paged. Otherwise |
|
2709 KErrBadDescriptor to indicate that the memory region was not |
|
2710 valid. |
|
2711 |
|
2712 @pre Alloc must have been used to reserve sufficient RAM. |
|
2713 */ |
|
2714 IMPORT_C TInt Lock(DThread* aThread, TLinAddr aStart, TInt aSize); |
|
2715 |
|
2716 /** |
|
2717 Unlock the memory region which was previousely locked with Lock. |
|
2718 This may be called even if memory wasn't previousely locked. |
|
2719 */ |
|
2720 inline void Unlock() { if(iLockedPageCount) DoUnlock(); } |
|
2721 |
|
2722 private: |
|
2723 IMPORT_C void DoUnlock(); |
|
2724 private: |
|
2725 DemandPaging* iThePager; |
|
2726 TInt iReservedPageCount; |
|
2727 TInt iLockedPageCount; |
|
2728 TLinAddr iLockedStart; |
|
2729 DProcess* iProcess; |
|
2730 TPhysAddr* iPages; |
|
2731 TAny* iPinMapping; |
|
2732 TInt iMaxPageCount; |
|
2733 |
|
2734 friend class DemandPaging; |
|
2735 }; |
|
2736 |
|
2737 |
|
2738 |
|
2739 class DPagingRequestPool; |
|
2740 |
|
2741 /** |
|
2742 Base class for Paging Devices. |
|
2743 A Paging Device provides the paging system with access to storage media which holds |
|
2744 data being demand paged. |
|
2745 @internalTechnology |
|
2746 @prototype |
|
2747 */ |
|
2748 class DPagingDevice : public DBase |
|
2749 { |
|
2750 public: |
|
2751 /** The type of device this represents. */ |
|
2752 enum TType |
|
2753 { |
|
2754 ERom = 1<<0, /**< Paged ROM device type. */ |
|
2755 ECode = 1<<1, /**< Code paging device type. */ |
|
2756 EData = 1<<2 /**< Data paging device type. */ |
|
2757 }; |
|
2758 |
|
2759 enum TSpecialDrives |
|
2760 { |
|
2761 EDriveRomPaging = -1, /**< Special drive number to indicate rom paging. */ |
|
2762 EDriveDataPaging = -2, /**< Special drive number to indicate data paging. */ |
|
2763 }; |
|
2764 |
|
2765 /** |
|
2766 Called by the paging system to read data from the media represented by this |
|
2767 device. |
|
2768 |
|
2769 @param aBuffer The location where the read data should be stored. |
|
2770 @param aOffset The offset from the media start, in read units, from where |
|
2771 data should be read. |
|
2772 @param aSize The number of read units to be read. |
|
2773 |
|
2774 @param aDrvNumber The drive number for code paging or a member of TSpecialDrives for rom or data |
|
2775 paging. |
|
2776 |
|
2777 @return KErrNone or standard error code. |
|
2778 */ |
|
2779 virtual TInt Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize, TInt aDrvNumber) = 0; |
|
2780 |
|
2781 /** |
|
2782 Called by the paging system to write data to the media represented by this device. |
|
2783 |
|
2784 This is only used in the implementation of data paging to write to the swap partition. |
|
2785 |
|
2786 @param aBuffer The location of the data to write. |
|
2787 @param aOffset The offset from the media start, in read units, to where data should be written. |
|
2788 @param aSize The number of read units to write. |
|
2789 @param aBackground If set, this indicates that the request should not count as making the device busy. |
|
2790 |
|
2791 @return KErrNone or standard error code. |
|
2792 */ |
|
2793 inline virtual TInt Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground); |
|
2794 |
|
2795 /** |
|
2796 Called by the paging system to notify the media driver that data that was previously written is |
|
2797 now no longer needed. |
|
2798 |
|
2799 This is only used in the implementation of data paging when data in the swap partition is no |
|
2800 longer needed. |
|
2801 |
|
2802 @param aOffset The offset from the media start, in read units, to where data was written. |
|
2803 @param aSize The size in read units. |
|
2804 |
|
2805 @return KErrNone or standard error code. |
|
2806 */ |
|
2807 inline virtual TInt DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize); |
|
2808 |
|
2809 /** |
|
2810 Called by the paging device to notify the kernel that the device has just become idle and is not |
|
2811 currently processing any requests. |
|
2812 |
|
2813 This is used by the kernel to work out when to clean pages in the background. |
|
2814 |
|
2815 Note that write requests made by calling the DPagingDevice::Write() with the aBackground flag |
|
2816 set do not count towards the device being busy. |
|
2817 */ |
|
2818 IMPORT_C void NotifyIdle(); |
|
2819 |
|
2820 /** |
|
2821 Called by the paging device to notify the kernel that the device has just become busy and is |
|
2822 currently processing requests. |
|
2823 |
|
2824 This is used by the kernel to work out when to clean pages in the background. |
|
2825 |
|
2826 Note that write requests made by calling the DPagingDevice::Write() with the aBackground flag |
|
2827 set do not count towards the device being busy. |
|
2828 */ |
|
2829 IMPORT_C void NotifyBusy(); |
|
2830 |
|
2831 public: |
|
2832 /** The type of device this represents. */ |
|
2833 TUint32 iType; |
|
2834 |
|
2835 /** The local drives supported for code paging. |
|
2836 This is a bitmask containing one bit set for each local drive supported, where the bit set |
|
2837 is 1 << the local drive number. If this device does not support code paging, this should be |
|
2838 zero. */ |
|
2839 TUint32 iDrivesSupported; |
|
2840 |
|
2841 /** Zero terminated string representing the name of the device. |
|
2842 (Only used for debug tracing purposes.) */ |
|
2843 const char* iName; |
|
2844 |
|
2845 /** Log2 of the read unit size. A read unit is the number of bytes which |
|
2846 the device can optimally read from the underlying media. |
|
2847 E.g. for small block NAND, a read unit would be equal to the page size, |
|
2848 512 bytes, therefore iReadUnitShift would be set to 9. */ |
|
2849 TInt iReadUnitShift; |
|
2850 |
|
2851 /** The value the device should use to identify itself. |
|
2852 This value is set by Kern::InstallPagingDevice(). |
|
2853 The purpose of this Id is to distinguish multiple Code Paging devices. */ |
|
2854 TInt iDeviceId; |
|
2855 |
|
2856 /** For data paging only, the size of the swap partition supported by this device, in read units. |
|
2857 |
|
2858 If data paging is not supported, or has been disabled by the media driver, this should be |
|
2859 zero. |
|
2860 */ |
|
2861 TInt iSwapSize; |
|
2862 |
|
2863 /** The pool of DPagingRequest objects used to issue requests for this device. |
|
2864 This is setup and used internally by the kernel. |
|
2865 */ |
|
2866 DPagingRequestPool* iRequestPool; |
|
2867 |
|
2868 /** Reserved for future use. |
|
2869 */ |
|
2870 TInt iSpare[4]; |
|
2871 }; |
|
2872 |
|
2873 inline TInt DPagingDevice::Write(TThreadMessage*,TLinAddr,TUint,TUint,TBool) |
|
2874 { |
|
2875 // Default implementation, may be overriden by dervied classes |
|
2876 return KErrNotSupported; |
|
2877 } |
|
2878 |
|
2879 inline TInt DPagingDevice::DeleteNotify(TThreadMessage*,TUint,TUint) |
|
2880 { |
|
2881 // Default implementation, may be overriden by dervied classes |
|
2882 return KErrNotSupported; |
|
2883 } |
|
2884 |
|
2885 extern "C" { extern TInt __Variant_Flags__; } |
|
2886 |
|
2887 /******************************************** |
|
2888 * Shareable Data Buffers |
|
2889 ********************************************/ |
|
2890 /** |
|
2891 Pool create info |
|
2892 |
|
2893 @publishedPartner |
|
2894 @prototype |
|
2895 */ |
|
2896 class TMappingAttributes2; |
|
2897 |
|
2898 #include <e32shbufcmn.h> |
|
2899 |
|
2900 class TShPoolCreateInfo |
|
2901 { |
|
2902 public: |
|
2903 /** |
|
2904 Enumeration type to say that the shared pool is to be backed with memory supplied by the kernel. |
|
2905 */ |
|
2906 enum TShPoolPageAlignedBuffers |
|
2907 { |
|
2908 EPageAlignedBuffer = EShPoolPageAlignedBuffer, |
|
2909 }; |
|
2910 |
|
2911 /** |
|
2912 Enumeration type to say that the shared pool is to be backed with memory supplied by the kernel. |
|
2913 */ |
|
2914 enum TShPoolNonPageAlignedBuffers |
|
2915 { |
|
2916 ENonPageAlignedBuffer = EShPoolNonPageAlignedBuffer, |
|
2917 }; |
|
2918 |
|
2919 /** |
|
2920 Enumeration type to say that the shared pool is to be mapped onto device memory. |
|
2921 */ |
|
2922 enum TShPoolMemoryDevice |
|
2923 { |
|
2924 EDevice = EShPoolPhysicalMemoryPool, |
|
2925 }; |
|
2926 |
|
2927 IMPORT_C TShPoolCreateInfo(TShPoolPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs); |
|
2928 IMPORT_C TShPoolCreateInfo(TShPoolNonPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment); |
|
2929 |
|
2930 IMPORT_C TShPoolCreateInfo(TShPoolMemoryDevice aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment, TUint aPages, TPhysAddr* aPhysicalAddressList); |
|
2931 |
|
2932 IMPORT_C TShPoolCreateInfo(TShPoolMemoryDevice aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment, TUint aPages, TPhysAddr aPhysicalAddress); |
|
2933 |
|
2934 IMPORT_C TInt SetSizingAttributes(TUint aMaxBufs, TUint aMinFreeBufs, TUint aGrowByBufs, TUint aShrinkByBufs); |
|
2935 IMPORT_C TInt SetExclusive(); |
|
2936 IMPORT_C TInt SetContiguous(); |
|
2937 IMPORT_C TInt SetGuardPages(); |
|
2938 |
|
2939 private: |
|
2940 friend class ExecHandler; |
|
2941 friend class DShPool; |
|
2942 friend class DMemModelShPool; |
|
2943 friend class DMemModelAlignedShPool; |
|
2944 friend class DMemModelNonAlignedShPool; |
|
2945 friend class DMemModelProcess; |
|
2946 friend class DWin32ShPool; |
|
2947 friend class DWin32AlignedShPool; |
|
2948 friend class DWin32NonAlignedShPool; |
|
2949 friend class DWin32Process; |
|
2950 friend class DShBufTestDrvChannel; |
|
2951 |
|
2952 inline TShPoolCreateInfo() ///< default constructor |
|
2953 { |
|
2954 memclr(this, sizeof(TShPoolCreateInfo)); |
|
2955 }; |
|
2956 |
|
2957 TShPoolInfo iInfo; |
|
2958 |
|
2959 union PhysAddr |
|
2960 { |
|
2961 TPhysAddr* iPhysAddrList; ///< physical addresses for hardware |
|
2962 TPhysAddr iPhysAddr; ///< physical address for hardware |
|
2963 } iPhysAddr; |
|
2964 |
|
2965 TUint iPages; ///< number of pages to commit |
|
2966 }; |
|
2967 |
|
2968 #endif //__K32STD_H__ |