kernel/eka/include/kernel/kernel.h
changeset 9 96e5fb8b040d
child 10 36bfc973b146
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     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 MakeHandleAndOpen(DThread* aThread, DObject* aObject, TOwnerType aType);
       
  1100 	IMPORT_C static TInt CloseHandle(DThread* aThread, TInt aHandle);
       
  1101 	IMPORT_C static TInt ChunkCreate(const TChunkCreateInfo& aInfo, DChunk*& aChunk, TLinAddr& aKernAddr, TUint32& iMapAttr);
       
  1102 	IMPORT_C static TInt ChunkCommit(DChunk* aChunk, TInt aOffset, TInt aSize);
       
  1103 	IMPORT_C static TInt ChunkCommitContiguous(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32& aPhysicalAddress);
       
  1104 	IMPORT_C static TInt ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32 aPhysicalAddress);
       
  1105 	IMPORT_C static TInt ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, const TUint32* aPhysicalAddressList);
       
  1106 	IMPORT_C static TInt ChunkClose(DChunk* aChunk);
       
  1107 	IMPORT_C static DChunk* OpenSharedChunk(DThread* aThread, const TAny* aAddress, TBool aWrite, TInt& aOffset);
       
  1108 	IMPORT_C static DChunk* OpenSharedChunk(DThread* aThread, TInt aChunkHandle, TBool aWrite);
       
  1109 	IMPORT_C static TInt ChunkAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress);
       
  1110 	IMPORT_C static TInt ChunkPhysicalAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aMapAttr, TUint32& aPhysicalAddress, TUint32* aPhysicalPageList=NULL);
       
  1111 	IMPORT_C static TUint8* ChunkUserBase(DChunk* aChunk, DThread* aThread);
       
  1112 
       
  1113 	/**
       
  1114 	Enumeration indicating the behaviour of text trace messages.
       
  1115 	@publishedPartner
       
  1116 	@released
       
  1117 	*/
       
  1118 	enum TTextTraceMode
       
  1119 		{
       
  1120 		/** Traces are sent to the serial port if not already handled by other means. */
       
  1121 		ESerialOutDefault = 0, 
       
  1122 		/** Traces are never sent to the serial port. */
       
  1123 		ESerialOutNever = 1,
       
  1124 		/** Traces are always sent to the serial port. */
       
  1125 		ESerialOutAlways = 2,
       
  1126 		/** Mask for serial port mode values. */
       
  1127 		ESerialOutMask = 3
       
  1128 		};
       
  1129 	IMPORT_C static TUint SetTextTraceMode(TUint aMode, TUint aMask);
       
  1130 	IMPORT_C static TTraceHandler SetTraceHandler(TTraceHandler aHandler);
       
  1131 	inline static TNanoWaitHandler SetNanoWaitHandler(TNanoWaitHandler aHandler);
       
  1132 	inline static TInitialTimeHandler SetInitialTimeHandler(TInitialTimeHandler aHandler);
       
  1133 	
       
  1134 	/**
       
  1135 	Install the specified paging device.
       
  1136 	@param aDevice The device.
       
  1137 	@return KErrNone or standard error code.
       
  1138 	@post The devices DPagingDevice::iDeviceId has been set.
       
  1139 	@internalTechnology
       
  1140 	*/
       
  1141 	IMPORT_C static TInt InstallPagingDevice(DPagingDevice* aDevice);
       
  1142 	IMPORT_C static TInt InstallLogicalDevice(DLogicalDevice* aDevice);		/**< @internalTechnology */
       
  1143 	IMPORT_C static TInt InstallPhysicalDevice(DPhysicalDevice* aDevice);		/**< @internalTechnology */
       
  1144 
       
  1145 	IMPORT_C static TInt CreateVirtualPinObject(TVirtualPinObject*& aPinObject); // prototype
       
  1146 	IMPORT_C static TInt PinVirtualMemory(TVirtualPinObject* aPinObject, TLinAddr aStart, TUint aSize, DThread* aThread=NULL); // prototype
       
  1147 	IMPORT_C static TInt PinVirtualMemory(TVirtualPinObject* aPinObject, const TClientBuffer& aDes, DThread* aThread=NULL); // prototype
       
  1148 	IMPORT_C static TInt CreateAndPinVirtualMemory(TVirtualPinObject*& aPinObject, TLinAddr aStart, TUint aSize); //prototype
       
  1149 	IMPORT_C static void UnpinVirtualMemory(TVirtualPinObject* aPinObject); // prototype
       
  1150 	IMPORT_C static void DestroyVirtualPinObject(TVirtualPinObject*& aPinObject); // prototype
       
  1151 
       
  1152 	IMPORT_C static TInt CreatePhysicalPinObject(TPhysicalPinObject*& aPinObject); // prototype
       
  1153 	IMPORT_C static TInt PinPhysicalMemory(TPhysicalPinObject* aPinObject, TLinAddr aStart, TUint aSize, TBool aReadOnly, TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour, DThread* aThread=NULL);
       
  1154 	IMPORT_C static TInt UnpinPhysicalMemory(TPhysicalPinObject* aPinObject); // prototype
       
  1155 	IMPORT_C static TInt DestroyPhysicalPinObject(TPhysicalPinObject*& aPinObject); // prototype
       
  1156 	
       
  1157 
       
  1158 	IMPORT_C static TInt ShPoolCreate(TShPool*& aPool, TShPoolCreateInfo& aInfo, TBool aMap, TUint aFlags);
       
  1159 	IMPORT_C static TInt ShPoolOpen(TShPool*& aPool, DThread* aThread, TInt aHandle, TBool aMap, TUint aFlags);
       
  1160 	IMPORT_C static TInt ShPoolClose(TShPool* aPool);
       
  1161 	IMPORT_C static TInt ShPoolMakeHandleAndOpen(TShPool* aPool, DThread* aThread, TUint aAttr);
       
  1162 	IMPORT_C static TInt ShPoolSetBufferWindow(TShPool* aPool, TInt aWindowSize);
       
  1163 	IMPORT_C static TInt ShPoolAlloc(TShPool* aPool, TShBuf*& aBuf, TUint aFlags);
       
  1164 	IMPORT_C static void ShPoolGetInfo(TShPool* aPool, TShPoolInfo& aInfo);
       
  1165 	IMPORT_C static TUint ShPoolBufSize(TShPool* aPool);
       
  1166 	IMPORT_C static TUint ShPoolFreeCount(TShPool* aPool);
       
  1167 	IMPORT_C static TInt ShBufOpen(TShBuf*& aBuf, DThread* aThread, TInt aHandle);
       
  1168 	IMPORT_C static TInt ShBufClose(TShBuf* aBuf);
       
  1169 	IMPORT_C static TInt ShBufMakeHandleAndOpen(TShBuf* aBuf, DThread* aThread);
       
  1170 	IMPORT_C static void ShBufCopyFrom(TShBuf* aBuf, const TDesC8& aSrc, TUint aOffset);
       
  1171 	IMPORT_C static TUint8* ShBufPtr(TShBuf* aBuf);
       
  1172 	IMPORT_C static TUint ShBufSize(TShBuf* aBuf);
       
  1173 	IMPORT_C static TInt ShBufPin(TShBuf* aBuf, TPhysicalPinObject* aPinObject, TBool aReadOnly, TPhysAddr& Address, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour);
       
  1174 
       
  1175 
       
  1176 private:
       
  1177 	IMPORT_C static TBool DoCurrentThreadHasCapability(TCapability aCapability, const char* aDiagnosticText);
       
  1178 	IMPORT_C static TBool DoCurrentThreadHasCapability(TCapability aCapability);
       
  1179 	IMPORT_C static TKernelHookFn SetHook(TKernelHookType aType, TKernelHookFn aFunction, TBool aAllowOveride=EFalse);
       
  1180 	IMPORT_C static TInt CreateClientDataRequestBase(TClientDataRequestBase*& aRequestPtr, TInt aSize);					/**< @internalTechnology */
       
  1181 	IMPORT_C static TInt CreateClientDataRequestBase2(TClientDataRequestBase2*& aRequestPtr, TInt aSize1, TInt aSize2);	/**< @internalTechnology */
       
  1182 	friend class DThread;
       
  1183 	};
       
  1184 
       
  1185 
       
  1186 
       
  1187 /**
       
  1188 Reads an 8-bit descriptor from the specified thread's address space, enforcing
       
  1189 checks on validity of source and destination if necessary.
       
  1190 	
       
  1191 It is used especially by device drivers to transfer data from a user thread.
       
  1192 aDes might be accessed with user permission validation.
       
  1193 
       
  1194 @param aThread The thread from whose address space data is to be read.
       
  1195 @param aSrc Pointer to a source descriptor in the specified thread's address
       
  1196             space. This must not be NULL.
       
  1197 @param aDest Target descriptor
       
  1198 @param aOffset Offset in aSrc from where to start reading data.
       
  1199 
       
  1200 @return KErrNone, if sucessful; KErrBadDescriptor, if aPtr or aDes is an
       
  1201         invalid decriptor; KErrArgument if anOffset is negative; KErrDied if aThread
       
  1202         is dead.
       
  1203 */
       
  1204 inline TInt Kern::ThreadDesRead(DThread* aThread, const TAny* aSrc, TDes8& aDest, TInt aOffset)
       
  1205 	{ return ThreadDesRead(aThread,aSrc,aDest,aOffset,KChunkShiftBy0); }
       
  1206 
       
  1207 
       
  1208 
       
  1209 
       
  1210 /**
       
  1211 Writes an 8-bit descriptor to the specified thread's address space, enforcing
       
  1212 checks on validity of source and destination if necessary.
       
  1213 	
       
  1214 It is used especially by device drivers to transfer data to a user thread.
       
  1215 aDes might be accessed with user permission validation.
       
  1216 	  
       
  1217 @param aThread The thread into whose address space data is to be written.
       
  1218 @param aDest Pointer to a target descriptor in the specified thread's address
       
  1219             space. It must not be NULL
       
  1220 @param aSrc Source descriptor
       
  1221 @param aOffset Offset in aDest to start writing data to.
       
  1222 @param aOrigThread The thread on behalf of which this operation is performed (eg client of device driver).
       
  1223 
       
  1224 @return KErrNone, if sucessful; KErrBadDescriptor, if aPtr or aDes is an
       
  1225         invalid decriptor; KErrArgument if anOffset is negative; KErrDied if aThread
       
  1226         is dead.
       
  1227 */
       
  1228 inline TInt Kern::ThreadDesWrite(DThread* aThread, TAny* aDest, const TDesC8& aSrc, TInt aOffset, DThread* aOrigThread)
       
  1229 	{ return ThreadDesWrite(aThread,aDest,aSrc,aOffset,KChunkShiftBy0,aOrigThread); }
       
  1230 
       
  1231 
       
  1232 /**
       
  1233 Register the function used to implement Kern::NanoWait.
       
  1234 
       
  1235 This should be called from the variant to supply an accurate implementation for Kern::NanoWait.
       
  1236 
       
  1237 @return The previous implemention.
       
  1238 
       
  1239 @see Kern::NanoWait
       
  1240 
       
  1241 @publishedPartner
       
  1242 @released
       
  1243 */
       
  1244 inline TNanoWaitHandler Kern::SetNanoWaitHandler(TNanoWaitHandler aHandler)
       
  1245 	{
       
  1246 	return (TNanoWaitHandler) SetHook(EHookNanoWait, (TKernelHookFn)aHandler, ETrue);
       
  1247 	}
       
  1248 
       
  1249 
       
  1250 
       
  1251 /**
       
  1252 Register the function used to read the initial system time.
       
  1253 
       
  1254 This may be called from the variant to override the default behaviour.  If so it
       
  1255 should be called in phase 1 of initialisation.
       
  1256 
       
  1257 @return The previous implemention.
       
  1258 
       
  1259 @publishedPartner
       
  1260 @released
       
  1261 */
       
  1262 inline TInitialTimeHandler Kern::SetInitialTimeHandler(TInitialTimeHandler aHandler)
       
  1263 	{
       
  1264 	return (TInitialTimeHandler) SetHook(EHookInitialTime, (TKernelHookFn)aHandler, ETrue);
       
  1265 	}
       
  1266 
       
  1267 
       
  1268 
       
  1269 struct SMiscNotifierQ;
       
  1270 class TMiscNotifierMgr;
       
  1271 class DObject : public DBase
       
  1272 /**
       
  1273 Base class for reference-counted kernel side objects.
       
  1274 
       
  1275 @publishedPartner
       
  1276 @released
       
  1277 */
       
  1278 // NOTE: Any changes to the structure of this class should be duplicated in class DMonObject
       
  1279 	{
       
  1280 public:
       
  1281 
       
  1282     /**
       
  1283     Defines a set of bit values that are returned from calls
       
  1284     to DObject::Close(), or by an overriding implementation of Close() provided
       
  1285     by a derived class.
       
  1286     
       
  1287     The values describe the state of the object on return from Close().
       
  1288     */
       
  1289 	enum TCloseReturn
       
  1290 		{
       
  1291 		
       
  1292 		/**
       
  1293 		If set, indicates that the object has been deleted.  
       
  1294 		*/
       
  1295 		EObjectDeleted=1,
       
  1296 		
       
  1297 		/**
       
  1298 		If set, indicates that the last reference
       
  1299 		from a user process has been removed.
       
  1300 		
       
  1301 		Note that this only applies to DLibrary objects.
       
  1302 		*/
       
  1303 		EObjectUnmapped=2,
       
  1304 		};
       
  1305 		
       
  1306 	/**	@internalComponent */
       
  1307 	enum TObjectProtection
       
  1308 		{
       
  1309 		ELocal=0,		// Private
       
  1310 		EProtected,
       
  1311 		EGlobal,		// Public
       
  1312 		};
       
  1313 		
       
  1314 	/**	@internalComponent */
       
  1315 	enum TObjectFlags
       
  1316 		{
       
  1317 		EObjectExtraReference = (1<<0),
       
  1318 		EObjectDeferKernelCodesegCleanup = (1<<1)
       
  1319 		};
       
  1320 		
       
  1321 public:
       
  1322 	/**	@internalComponent */
       
  1323 	inline TInt Inc() { return __e32_atomic_tas_ord32(&iAccessCount, 1, 1, 0); }
       
  1324 
       
  1325 	/**	@internalComponent */
       
  1326 	inline TInt Dec() { return __e32_atomic_tas_ord32(&iAccessCount, 1, -1, 0); }
       
  1327 
       
  1328 	IMPORT_C DObject();
       
  1329 	IMPORT_C ~DObject();
       
  1330 	
       
  1331 	/**
       
  1332 	Opens this kernel side reference-counted object.
       
  1333 	
       
  1334 	Opening a reference-counted object increments its reference count
       
  1335 	by one. The increment operation is done atomically.
       
  1336 	
       
  1337 	@return KErrNone, if the increment operation succeeds;
       
  1338 	        KErrGeneral, if the reference count value is either zero
       
  1339 	        or negative before performing the increment operation;
       
  1340 	        the reference count is initialised to 1 on construction
       
  1341 	        of the object, and can never be less than 1.
       
  1342 	*/
       
  1343 	inline TInt Open() { return(Inc()?KErrNone:KErrGeneral); }
       
  1344 	IMPORT_C void CheckedOpen();
       
  1345 	IMPORT_C virtual TInt Close(TAny* aPtr);
       
  1346 	IMPORT_C virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
       
  1347 	IMPORT_C virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType, TUint aAttr);
       
  1348 	IMPORT_C virtual TInt AddToProcess(DProcess* aProcess);
       
  1349 	IMPORT_C virtual TInt AddToProcess(DProcess* aProcess, TUint aAttr);
       
  1350 	IMPORT_C TInt AsyncClose();
       
  1351 	IMPORT_C virtual void DoAppendName(TDes& aName);
       
  1352 	IMPORT_C void DoAppendFullName(TDes& aFullName);
       
  1353 	IMPORT_C void Name(TDes& aName);
       
  1354 	IMPORT_C void AppendName(TDes& aName);
       
  1355 	IMPORT_C void FullName(TDes& aFullName);
       
  1356 	IMPORT_C void AppendFullName(TDes& aFullName);
       
  1357 	IMPORT_C TInt SetName(const TDesC* aName);
       
  1358 	IMPORT_C TInt SetOwner(DObject* aOwner);
       
  1359 	IMPORT_C void TraceAppendName(TDes8& aName, TBool aLock);
       
  1360 	IMPORT_C void TraceAppendFullName(TDes8& aFullName, TBool aLock);
       
  1361 	inline DObject* Owner();
       
  1362 	inline TInt AccessCount();
       
  1363 	inline TInt UniqueID();
       
  1364 	inline HBuf* NameBuf();
       
  1365 	inline void SetProtection(TObjectProtection aProtection);
       
  1366 	inline TUint Protection();
       
  1367 	void BaseName(TDes& aName);
       
  1368 	inline TUint64 ObjectId() const;		/**< @internalComponent */
       
  1369 public:
       
  1370 	/**	@internalComponent */
       
  1371 	TInt iAccessCount;			// must be first
       
  1372 
       
  1373 	/**	@internalComponent */
       
  1374 	DObject* iOwner;
       
  1375 
       
  1376 	/** A TObjectType value with one added
       
  1377 		@internalComponent */
       
  1378 	TUint8 iContainerID;
       
  1379 
       
  1380 	/** A TObjectProtection value
       
  1381 		@internalComponent */
       
  1382 	TUint8 iProtection;
       
  1383 
       
  1384 	/**	Bit field made of values from TObjectFlags
       
  1385 		@internalComponent */
       
  1386 	TUint8 iObjectFlags;
       
  1387 
       
  1388 	/**	@internalComponent */
       
  1389 	TUint8 iNotQLow;
       
  1390 
       
  1391 	/**	@internalComponent */
       
  1392 	HBuf* iName;
       
  1393 
       
  1394 	/** A unique ID.
       
  1395 	    @internalComponent */
       
  1396 	TUint64 iObjectId;
       
  1397 
       
  1398 	/**	@internalComponent */
       
  1399 //	SMiscNotifierQ* iNotifierQ;
       
  1400 
       
  1401 public:
       
  1402 	static NFastMutex Lock;
       
  1403 private:
       
  1404 	inline SMiscNotifierQ* NotifierQ() const;	/**< @internalComponent */
       
  1405 	inline void SetNotifierQ(SMiscNotifierQ*);	/**< @internalComponent */
       
  1406 	inline TBool HasNotifierQ() const;			/**< @internalComponent */
       
  1407 private:
       
  1408 	static TUint64 NextObjectId;
       
  1409 
       
  1410 	friend class DObjectCon;
       
  1411 	friend class RObjectIx;
       
  1412 	friend class Monitor;
       
  1413 	friend class Debugger;
       
  1414 	friend void Kern::AppendFormat(TDes8&, const char*, VA_LIST);
       
  1415 	friend class K;
       
  1416 	friend struct SMiscNotifierQ;
       
  1417 	friend class TMiscNotifierMgr;
       
  1418 	};
       
  1419 
       
  1420 /**
       
  1421 Gets the number of open references to
       
  1422 this reference-counted kernel side object.
       
  1423 
       
  1424 @return The number of open references.
       
  1425 */
       
  1426 inline TInt DObject::AccessCount()
       
  1427 	{ return iAccessCount; }
       
  1428 	
       
  1429 /**
       
  1430 Gets a pointer to the kernel-side reference counted object
       
  1431 that owns this kernel side reference-counted object.
       
  1432 
       
  1433 @return A pointer to the owning reference-counted object.
       
  1434         This is NULL, if there is no owner.
       
  1435 */	
       
  1436 inline DObject* DObject::Owner()
       
  1437 	{ return iOwner; }
       
  1438 
       
  1439 /** @internalComponent */
       
  1440 inline HBuf* DObject::NameBuf()
       
  1441 	{ return iName; }
       
  1442 
       
  1443 /** @internalComponent */
       
  1444 inline TInt DObject::UniqueID()
       
  1445 	{return(iContainerID);}
       
  1446 
       
  1447 /** @internalComponent */
       
  1448 inline TUint DObject::Protection()
       
  1449 	{return (TUint8)iProtection;}
       
  1450 
       
  1451 /** @internalComponent */
       
  1452 inline void DObject::SetProtection(TObjectProtection aProtection)
       
  1453 	{iProtection=(TUint8)aProtection;}
       
  1454 
       
  1455 /********************************************
       
  1456  * Device driver base classes
       
  1457  ********************************************/
       
  1458 
       
  1459 /**
       
  1460 @publishedPartner
       
  1461 @released
       
  1462 
       
  1463 If set, it indicates that the use of units is valid.
       
  1464 
       
  1465 @see DLogicalDevice::iParsemask
       
  1466 */
       
  1467 const TUint KDeviceAllowUnit=0x01;
       
  1468 
       
  1469 
       
  1470 
       
  1471 
       
  1472 /**
       
  1473 @publishedPartner
       
  1474 @released
       
  1475 
       
  1476 If set, then an LDD requires a PDD.
       
  1477 
       
  1478 @see DLogicalDevice::iParsemask
       
  1479 */
       
  1480 const TUint KDeviceAllowPhysicalDevice=0x02;
       
  1481 
       
  1482 
       
  1483 
       
  1484 
       
  1485 /**
       
  1486 @publishedPartner
       
  1487 @released
       
  1488 
       
  1489 If set, it indicates that the use of additional information is allowed.
       
  1490 
       
  1491 @see DLogicalDevice::iParsemask
       
  1492 */
       
  1493 const TUint KDeviceAllowInfo=0x04;
       
  1494 
       
  1495 
       
  1496 
       
  1497 
       
  1498 /**
       
  1499 @publishedPartner
       
  1500 @released
       
  1501 
       
  1502 Combines all of: KDeviceAllowUnit, KDeviceAllowPhysicalDevice and KDeviceAllowInfo.
       
  1503 
       
  1504 @see DLogicalDevice::iParsemask
       
  1505 */
       
  1506 const TUint KDeviceAllowAll=(KDeviceAllowUnit|KDeviceAllowPhysicalDevice|KDeviceAllowInfo);
       
  1507 
       
  1508 
       
  1509 
       
  1510 
       
  1511 /**
       
  1512 @publishedPartner
       
  1513 @released
       
  1514 
       
  1515 A flag bit that can set in the aMode parameter passed to the
       
  1516 Kern::ThreadDesWrite(DThread* ,TAny*, const TDesC8&, TInt, TInt aMode, DThread*);
       
  1517 variant.
       
  1518 
       
  1519 It ensures that the length of data copied to the target descriptor is
       
  1520 truncated, if necesary, to prevent the maximum length of that target descriptor
       
  1521 from being exceeded.
       
  1522 
       
  1523 @see Kern::ThreadDesWrite()
       
  1524 */
       
  1525 const TInt KTruncateToMaxLength=(TInt)0x40000000;
       
  1526 
       
  1527 
       
  1528 
       
  1529 
       
  1530 /**
       
  1531 @publishedPartner
       
  1532 @released
       
  1533 
       
  1534 Used internally by Symbian OS.
       
  1535 */
       
  1536 const TInt KCheckLocalAddress=(TInt)0x20000000;
       
  1537 
       
  1538 
       
  1539 
       
  1540 
       
  1541 /**
       
  1542 @internalTechnology
       
  1543 @prototype
       
  1544 
       
  1545 A flag bit that can set in the aMode parameter passed to the
       
  1546 Kern::ThreadDesWrite(DThread* ,TAny*, const TDesC8&, TInt, TInt aMode, DThread*);
       
  1547 variant.
       
  1548 
       
  1549 It indicates that the descriptor header should not be updated to reflect the new length.
       
  1550 
       
  1551 @see Kern::ThreadDesWrite()
       
  1552 */
       
  1553 const TInt KDoNotUpdateDesLength=(TInt)0x10000000;
       
  1554 
       
  1555 class DLogicalDevice;
       
  1556 class DPhysicalDevice;
       
  1557 
       
  1558 
       
  1559 
       
  1560 
       
  1561 /**
       
  1562 @publishedPartner
       
  1563 @released
       
  1564 
       
  1565 The abstract base class for a logical channel.
       
  1566 */
       
  1567 class DLogicalChannelBase : public DObject
       
  1568 	{
       
  1569 public:
       
  1570 	IMPORT_C virtual ~DLogicalChannelBase();
       
  1571 public:
       
  1572     /**
       
  1573     Handles a client request in the client context.
       
  1574     
       
  1575     The function is called from within the kernel, but the implementation
       
  1576     must be provided by external code.
       
  1577     */
       
  1578 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2)=0;
       
  1579 	IMPORT_C virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
       
  1580 public:
       
  1581 	DLogicalDevice* iDevice;
       
  1582 	DPhysicalDevice* iPhysicalDevice;
       
  1583 	DBase* iPdd;
       
  1584 	};
       
  1585 
       
  1586 
       
  1587 
       
  1588 
       
  1589 /**
       
  1590 @publishedPartner
       
  1591 @released
       
  1592 
       
  1593 The abstract base class for an LDD factory object.
       
  1594 */
       
  1595 class DLogicalDevice : public DObject
       
  1596 	{
       
  1597 public:
       
  1598 	IMPORT_C virtual ~DLogicalDevice();
       
  1599 	IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVer) const;
       
  1600 	IMPORT_C virtual TBool IsAvailable(TInt aUnit, const TDesC* aDriver, const TDesC8* aInfo) const;
       
  1601 	TInt ChannelCreate(DLogicalChannelBase*& pC, TChannelCreateInfo& aInfo);
       
  1602 	TInt FindPhysicalDevice(DLogicalChannelBase* aChannel, TChannelCreateInfo& aInfo);
       
  1603 
       
  1604 
       
  1605 	/**
       
  1606 	Second stage constructor for derived objects.
       
  1607 	This must at least set a name for the driver object.
       
  1608 
       
  1609 	@return KErrNone or standard error code.
       
  1610 	*/
       
  1611 	virtual TInt Install()=0;
       
  1612 
       
  1613 
       
  1614 	/**
       
  1615 	Gets the driver's capabilities.
       
  1616 	
       
  1617 	This is called in the response to an RDevice::GetCaps() request.
       
  1618 
       
  1619 	@param aDes A user-side descriptor into which capabilities information is to be wriiten.
       
  1620 	*/
       
  1621 	virtual void GetCaps(TDes8& aDes) const =0;
       
  1622 
       
  1623 
       
  1624 	/**
       
  1625 	Called by the kernel's device driver framework to create a Logical Channel.
       
  1626 	This is called in the context of the user thread (client) which requested the creation of a Logical Channel
       
  1627 	(e.g. through a call to RBusLogicalChannel::DoCreate).
       
  1628 	The thread is in a critical section.
       
  1629 
       
  1630 	@param aChannel Set to point to the created Logical Channel
       
  1631 
       
  1632 	@return KErrNone or standard error code.
       
  1633 	*/
       
  1634 	virtual TInt Create(DLogicalChannelBase*& aChannel)=0;
       
  1635 
       
  1636 
       
  1637 public:
       
  1638     /**
       
  1639     The version of this factory object.
       
  1640 
       
  1641     This is used to check that an LDD and PDD are compatible.
       
  1642     Typically, this is set by the constructor of a derived class.
       
  1643     */
       
  1644 	TVersion iVersion;
       
  1645 	
       
  1646 	
       
  1647 	/**
       
  1648 	A bitmask that indicates device properties.
       
  1649 
       
  1650     This can take the following values:
       
  1651     KDeviceAllowUnit
       
  1652     KDeviceAllowPhysicalDevice
       
  1653     KDeviceAllowInfo
       
  1654     KDeviceAllowAll
       
  1655     
       
  1656     Typically, this is set by the constructor of a derived class.
       
  1657 
       
  1658     @see RBusLogicalChannel::DoCreate()
       
  1659     @see KDeviceAllowUnit
       
  1660     @see KDeviceAllowPhysicalDevice
       
  1661     @see KDeviceAllowInfo
       
  1662     @see KDeviceAllowAll
       
  1663 	*/
       
  1664 	TUint iParseMask;
       
  1665 	
       
  1666 	
       
  1667 	/**
       
  1668 	Indicates which units are valid.
       
  1669 
       
  1670     If units are allowed, i.e. the KDeviceAllowUnit bit is set in iParseMask,
       
  1671     then this mask indicates which of the units (from 0 to 31) are valid.
       
  1672 
       
  1673     The DPhysicalDevice object associated with the PDD has a similar mask,
       
  1674     and both masks are used to indicate which units the LDD-PDD pair
       
  1675     can handle.
       
  1676 
       
  1677     Typically, this is set by the constructor of a derived class.
       
  1678     
       
  1679     @see KDeviceAllowUnit
       
  1680 	*/
       
  1681 	TUint iUnitsMask;
       
  1682 	
       
  1683 	
       
  1684 	/**
       
  1685 	Pointer to the DCodeSeg object which contains the executable code
       
  1686 	for this LDD.
       
  1687 	*/
       
  1688 	DCodeSeg* iCodeSeg;
       
  1689 	
       
  1690 	
       
  1691 	/**
       
  1692 	Number of DLogicalChannelBase objects currently in existence which
       
  1693 	have been created from this LDD.
       
  1694 	*/
       
  1695 	TInt iOpenChannels;
       
  1696 	};
       
  1697 
       
  1698 /** @internalComponent */
       
  1699 typedef DLogicalDevice* (*TLogicalDeviceNew)();
       
  1700 
       
  1701 
       
  1702 
       
  1703 
       
  1704 /**
       
  1705 @publishedPartner
       
  1706 @released
       
  1707 
       
  1708 The abstract base class for a PDD factory object.
       
  1709 */
       
  1710 class DPhysicalDevice : public DObject
       
  1711 	{
       
  1712 public:
       
  1713 	enum TInfoFunction
       
  1714 		{
       
  1715 		EPriority=0,
       
  1716 		
       
  1717 		/** if implemented (i.e. Info(EMediaDriverPersistent) returns KErrNone) implies the media driver 
       
  1718 		created by this DPhysicalDevice will not be unloaded when the peripheral bus is powered down */
       
  1719 		EMediaDriverPersistent=1,
       
  1720 		};
       
  1721 public:
       
  1722 	IMPORT_C virtual ~DPhysicalDevice();
       
  1723 	IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVer) const;
       
  1724 	IMPORT_C virtual TBool IsAvailable(TInt aUnit, const TDesC8* aInfo) const;
       
  1725 
       
  1726 	/**
       
  1727 	Second stage constructor for derived objects.
       
  1728 	This must at least set a name for the driver object.
       
  1729 
       
  1730 	@return KErrNone or standard error code.
       
  1731 	*/
       
  1732 	virtual TInt Install() =0;
       
  1733 
       
  1734 	/**
       
  1735 	Returns the drivers capabilities. This is not used by the Symbian OS device driver framework
       
  1736 	but may be useful for the LDD to use.
       
  1737 
       
  1738 	@param aDes Descriptor to write capabilities information into
       
  1739 	*/
       
  1740 	virtual void GetCaps(TDes8& aDes) const =0;
       
  1741 
       
  1742 	/**
       
  1743 	Called by the kernel's device driver framework to create a Physical Channel.
       
  1744 	This is called in the context of the user thread (client) which requested the creation of a Logical Channel
       
  1745 	(E.g. through a call to RBusLogicalChannel::DoCreate)
       
  1746 	The thread is in a critical section.
       
  1747 
       
  1748 	@param aChannel Set to point to the created Physical Channel
       
  1749 	@param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate
       
  1750 	@param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate
       
  1751 	@param aVer The version number of the Logical Channel which will use this Physical Channel 
       
  1752 
       
  1753 	@return KErrNone or standard error code.
       
  1754 	*/
       
  1755 	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer) =0;
       
  1756 
       
  1757 	/**
       
  1758 	Called by the kernel's device driver framework to check if this PDD is suitable for use with a Logical Channel.
       
  1759 	This is called in the context of the user thread (client) which requested the creation of a Logical Channel
       
  1760 	(E.g. through a call to RBusLogicalChannel::DoCreate)
       
  1761 	The thread is in a critical section.
       
  1762 
       
  1763 	@param aUnit The unit argument supplied by the client to RBusLogicalChannel::DoCreate
       
  1764 	@param aInfo The info argument supplied by the client to RBusLogicalChannel::DoCreate
       
  1765 	@param aVer The version number of the Logical Channel which will use this Physical Channel 
       
  1766 
       
  1767 	@return KErrNone or standard error code.
       
  1768 	*/
       
  1769 	virtual TInt Validate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer) =0;
       
  1770 	IMPORT_C virtual TInt Info(TInt aFunction, TAny* a1);
       
  1771 public:
       
  1772 	TVersion iVersion;
       
  1773 	TUint iUnitsMask;
       
  1774 	DCodeSeg* iCodeSeg;
       
  1775 	};
       
  1776 
       
  1777 
       
  1778 
       
  1779 
       
  1780 /** @internalComponent */
       
  1781 typedef DPhysicalDevice* (*TPhysicalDeviceNew)();
       
  1782 
       
  1783 // Utility stuff for PDD finding
       
  1784 
       
  1785 /** @internalTechnology */
       
  1786 struct SPhysicalDeviceEntry
       
  1787 	{
       
  1788 	TInt iPriority;
       
  1789 	DPhysicalDevice* iPhysicalDevice;
       
  1790 	};
       
  1791 
       
  1792 /** @internalTechnology */
       
  1793 class RPhysicalDeviceArray : public RArray<SPhysicalDeviceEntry>
       
  1794 	{
       
  1795 public:
       
  1796 	IMPORT_C RPhysicalDeviceArray();
       
  1797 	IMPORT_C void Close();
       
  1798 	IMPORT_C TInt GetDriverList(const TDesC& aMatch, TInt aUnit, const TDesC8* aInfo, const TVersion& aVersion);
       
  1799 	};
       
  1800 
       
  1801 /********************************************
       
  1802  * Kernel-side messages and message queues.
       
  1803  ********************************************/
       
  1804 class TMessageQue;
       
  1805 
       
  1806 
       
  1807 
       
  1808 
       
  1809 /**
       
  1810 @publishedPartner
       
  1811 @released
       
  1812 
       
  1813 The base class for a kernel side message.
       
  1814 
       
  1815 This is a means of communication between Symbian OS threads
       
  1816 executing kernel-side code.
       
  1817 */
       
  1818 class TMessageBase : public SDblQueLink
       
  1819 	{
       
  1820 public:
       
  1821 	/** @internalComponent */
       
  1822 	enum TState {EFree,EDelivered,EAccepted};
       
  1823 public:
       
  1824 	TMessageBase() : iState(EFree), iQueue(NULL) {}
       
  1825 	IMPORT_C void Send(TMessageQue* aQ);
       
  1826 	IMPORT_C TInt SendReceive(TMessageQue* aQ);
       
  1827 	IMPORT_C void Forward(TMessageQue* aQ, TBool aReceiveNext);
       
  1828 	IMPORT_C void Complete(TInt aResult, TBool aReceiveNext);
       
  1829 	IMPORT_C void Cancel();			/**< @internalComponent */
       
  1830 	IMPORT_C void PanicClient(const TDesC& aCategory, TInt aReason);
       
  1831 public:
       
  1832 	IMPORT_C DThread* Client();
       
  1833 public:
       
  1834 	TUint8 iState;					/**< @internalComponent */
       
  1835 	TMessageQue* iQueue;			/**< @internalComponent */
       
  1836 	NFastSemaphore iSem;			/**< @internalComponent */
       
  1837 	TInt iValue;					/**< @internalComponent */ // msg id/return code
       
  1838 	};
       
  1839 
       
  1840 
       
  1841 
       
  1842 
       
  1843 /**
       
  1844 @publishedPartner
       
  1845 @released
       
  1846 
       
  1847 A queue for kernel-side messages.
       
  1848 
       
  1849 Objects of this type consist of a DFC plus a doubly-linked list
       
  1850 of received messages.
       
  1851 */
       
  1852 class TMessageQue : private TDfc
       
  1853 	{
       
  1854 public:
       
  1855 	IMPORT_C TMessageQue(TDfcFn aFunction, TAny* aPtr, TDfcQue* aDfcQ, TInt aPriority);
       
  1856 	IMPORT_C void Receive();
       
  1857 	IMPORT_C TMessageBase* Poll();
       
  1858 	IMPORT_C TMessageBase* Last();
       
  1859 	IMPORT_C void CompleteAll(TInt aResult);
       
  1860 	using TDfc::SetDfcQ;
       
  1861 public:
       
  1862 	inline static void Lock() {NKern::FMWait(&MsgLock);}			/**< @internalComponent */
       
  1863 	inline static void Unlock() {NKern::FMSignal(&MsgLock);}		/**< @internalComponent */
       
  1864 	inline void UnlockAndKick() {Enque(&MsgLock);}					/**< @internalComponent */
       
  1865 public:
       
  1866 	SDblQue iQ;						/**< @internalComponent */
       
  1867 	TBool iReady;					/**< @internalComponent */
       
  1868 	TMessageBase* iMessage;			/**< @internalComponent */
       
  1869 	static NFastMutex MsgLock;		/**< @internalComponent */
       
  1870 	friend class TMessageBase;
       
  1871 	};
       
  1872 
       
  1873 
       
  1874 
       
  1875 
       
  1876 /**
       
  1877 @publishedPartner
       
  1878 @released
       
  1879 	
       
  1880 Synchronous kernel-side messages.
       
  1881 	
       
  1882 There is one per thread, and the thread always blocks while the message is outstanding.
       
  1883 The iPtr field of a DFC points to the message.
       
  1884 */
       
  1885 class TThreadMessage : public TMessageBase
       
  1886 	{
       
  1887 public:
       
  1888     /**
       
  1889     Returns argument 0 as an integer.
       
  1890     */
       
  1891 	inline TInt Int0() const {return (TInt)iArg[0];}
       
  1892 	
       
  1893     /**
       
  1894     Returns argument 1 as an integer.
       
  1895     */
       
  1896 	inline TInt Int1() const {return (TInt)iArg[1];}
       
  1897 	
       
  1898     /**
       
  1899     Returns argument 2 as an integer.
       
  1900     */
       
  1901 	inline TInt Int2() const {return (TInt)iArg[2];}
       
  1902 	
       
  1903     /**
       
  1904     Returns argument 3 as an integer.
       
  1905     */
       
  1906 	inline TInt Int3() const {return (TInt)iArg[3];}
       
  1907 	
       
  1908     /**
       
  1909     Returns argument 0 as a pointer type.
       
  1910     */
       
  1911 	inline TAny* Ptr0() const {return iArg[0];}
       
  1912 	
       
  1913     /**
       
  1914     Returns argument 1 as a pointer type.
       
  1915     */
       
  1916 	inline TAny* Ptr1() const {return iArg[1];}
       
  1917 	
       
  1918     /**
       
  1919     Returns argument 2 as a pointer type.
       
  1920     */
       
  1921 	inline TAny* Ptr2() const {return iArg[2];}
       
  1922 	
       
  1923     /**
       
  1924     Returns argument 3 as a pointer type.
       
  1925     */
       
  1926 	inline TAny* Ptr3() const {return iArg[3];}
       
  1927 public:
       
  1928     /**
       
  1929     Message arguments.
       
  1930     */
       
  1931 	TAny* iArg[10];				// message arguments
       
  1932 	};
       
  1933 
       
  1934 
       
  1935 
       
  1936 
       
  1937 /**
       
  1938 @publishedPartner
       
  1939 @released
       
  1940 	
       
  1941 An abstract class for a logical channel that provides a framework in which
       
  1942 user-side client requests are executed in the context of
       
  1943 a single kernel-side thread.
       
  1944 */
       
  1945 class DLogicalChannel : public DLogicalChannelBase
       
  1946 	{
       
  1947 public:
       
  1948 	enum {
       
  1949 	      /**
       
  1950 	      Defines the smallest request number that Request() accepts.
       
  1951 	      Smaller request numbers will raise a panic.
       
  1952 	      */
       
  1953 	      EMinRequestId=(TInt)0xc0000000,
       
  1954 	      
       
  1955 	      /**
       
  1956 	      The value of the close message sent to the device driver thread
       
  1957 	      by Close().
       
  1958 	      */
       
  1959 	      ECloseMsg=(TInt)0x80000000};
       
  1960 public:
       
  1961 	IMPORT_C DLogicalChannel();
       
  1962 	IMPORT_C virtual ~DLogicalChannel();
       
  1963 	IMPORT_C virtual TInt Close(TAny*);
       
  1964 	IMPORT_C virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
       
  1965  	IMPORT_C virtual TInt SendMsg(TMessageBase* aMsg);
       
  1966 
       
  1967 	/**
       
  1968 	Processes a message for this logical channel.
       
  1969 	This function is called in the context of a DFC thread.
       
  1970 
       
  1971 	@param aMsg     The message to process.
       
  1972 	                The iValue member of this distinguishes the message type:
       
  1973 	                iValue==ECloseMsg, channel close message
       
  1974 	                iValue==KMaxTInt, a 'DoCancel' message
       
  1975 	                iValue>=0, a 'DoControl' message with function number equal to iValue
       
  1976 	                iValue<0, a 'DoRequest' message with function number equal to ~iValue
       
  1977 	*/
       
  1978 	IMPORT_C virtual void HandleMsg(TMessageBase* aMsg)=0;
       
  1979 	IMPORT_C void SetDfcQ(TDfcQue* aDfcQ);
       
  1980 public:
       
  1981 	static void MsgQFunc(TAny* aPtr);
       
  1982 public:
       
  1983 	TDfcQue* iDfcQ;
       
  1984 	TMessageQue iMsgQ;
       
  1985 	};
       
  1986 
       
  1987 
       
  1988 
       
  1989 
       
  1990 /********************************************
       
  1991  * Timers based on the system tick
       
  1992  ********************************************/
       
  1993 
       
  1994 /**
       
  1995 @publishedPartner
       
  1996 @released
       
  1997 
       
  1998 Defines the signature for a tick timer callback function.
       
  1999 */
       
  2000 typedef void (*TTickCallBack)(TAny* aPtr);
       
  2001 
       
  2002 
       
  2003 
       
  2004 
       
  2005 /**
       
  2006 @publishedPartner
       
  2007 @released
       
  2008 
       
  2009 Relative timer with the resolution of one Symbian OS tick (generally 1/64 second).
       
  2010 
       
  2011 Tick timers are general purpose interval timers which are used where there
       
  2012 is no need for high resolution or great accuracy. They correspond to the
       
  2013 timing functions available to user side code on EKA1 (User::After,
       
  2014 RTimer::After, RTimer::Lock).
       
  2015 
       
  2016 @see User::After()
       
  2017 @see RTimer::After()
       
  2018 @see RTimer::Lock()
       
  2019 */
       
  2020 class TTickLink : public SDeltaQueLink
       
  2021 	{
       
  2022 public:
       
  2023 	IMPORT_C TTickLink();
       
  2024 	IMPORT_C void Periodic(TInt aPeriod, TTickCallBack aCallBack, TAny* aPtr);
       
  2025 	IMPORT_C void OneShot(TInt aTime, TTickCallBack aCallBack, TAny* aPtr);
       
  2026 	IMPORT_C void Lock(TInt aTicks, TTickCallBack aCallBack, TAny* aPtr);
       
  2027 	IMPORT_C void Cancel();
       
  2028 	void DoCancel();
       
  2029 	TInt GetNextLock(TTimerLockSpec aMark, TInt &aTickCount) const;
       
  2030 public:
       
  2031 	TInt iPeriod;				/**< @internalComponent */
       
  2032 	TAny *iPtr;					/**< @internalComponent */
       
  2033 	TTickCallBack iCallBack;	/**< @internalComponent */
       
  2034 	Int64 iLastLock;			/**< @internalComponent */
       
  2035 	};
       
  2036 
       
  2037 
       
  2038 
       
  2039 
       
  2040 /**
       
  2041 @publishedPartner
       
  2042 @released
       
  2043 	
       
  2044 Defines the signature for a second timer callback function.
       
  2045 
       
  2046 @see TSecondLink
       
  2047 */
       
  2048 typedef void (*TSecondCallBack)(TAny* aPtr);
       
  2049 
       
  2050 
       
  2051 
       
  2052 
       
  2053 /**
       
  2054 @publishedPartner
       
  2055 @released
       
  2056 
       
  2057 Absolute timer with a resolution of 1 second.
       
  2058 
       
  2059 Second timers are used when an event needs to occur at a specific date and
       
  2060 time of day, rather than after a specified interval. They have a resolution of
       
  2061 1 second.
       
  2062 
       
  2063 They are typically used for user alarms, and, if necessary, will power up
       
  2064 the system at the expiry time.
       
  2065 */
       
  2066 class TSecondLink : public SDblQueLink
       
  2067 	{
       
  2068 public:
       
  2069 	IMPORT_C TSecondLink();
       
  2070 	IMPORT_C TInt At(const TTimeK& aUTCTime, TSecondCallBack aCallBack, TAny* aPtr);
       
  2071 	IMPORT_C void Cancel();
       
  2072 public:
       
  2073 	Int64 iTime;				/**< @internalComponent */
       
  2074 	TAny* iPtr;					/**< @internalComponent */
       
  2075 	TSecondCallBack iCallBack;	/**< @internalComponent */
       
  2076 	};
       
  2077 
       
  2078 
       
  2079 
       
  2080 
       
  2081 /**
       
  2082 @publishedPartner
       
  2083 @released
       
  2084 
       
  2085 Defines the signature for an inactivity timer callback function.
       
  2086 
       
  2087 @see TInactivityLink
       
  2088 */
       
  2089 typedef void (*TInactivityCallBack)(TAny*);
       
  2090 
       
  2091 
       
  2092 
       
  2093 
       
  2094 /**
       
  2095 @publishedPartner
       
  2096 @released
       
  2097 
       
  2098 Inactivity timer.
       
  2099 
       
  2100 Inactivity timers are used to detect a specified period of user inactivity,
       
  2101 for example to enable device auto power down or screen saver functionality.
       
  2102 */
       
  2103 class TInactivityLink : public SDblQueLink
       
  2104 	{
       
  2105 public:
       
  2106 	IMPORT_C TInactivityLink();
       
  2107 	IMPORT_C TInt Start(TInt aSeconds, TInactivityCallBack aCallBack, TAny* aPtr);
       
  2108 	IMPORT_C void Cancel();
       
  2109 public:
       
  2110 	TUint32 iTime;					/**< @internalComponent */ // expiry time in ticks
       
  2111 	TAny* iPtr;						/**< @internalComponent */
       
  2112 	TInactivityCallBack iCallBack;	/**< @internalComponent */
       
  2113 	};
       
  2114 
       
  2115 /********************************************
       
  2116  * Internal RAM drive
       
  2117  ********************************************/
       
  2118 
       
  2119 /**
       
  2120 	@internalTechnology
       
  2121 */
       
  2122 class TInternalRamDrive
       
  2123 	{
       
  2124 public:
       
  2125 	static TInt Create();
       
  2126 	IMPORT_C static TLinAddr Base();
       
  2127 	IMPORT_C static TInt Size();
       
  2128 	IMPORT_C static TInt MaxSize();
       
  2129 	IMPORT_C static TInt Adjust(TInt aNewSize);
       
  2130 	IMPORT_C static void Lock();
       
  2131 	IMPORT_C static void Unlock();
       
  2132 	IMPORT_C static void Wait();
       
  2133 	IMPORT_C static void Signal();
       
  2134 public:
       
  2135 	static DMutex* Mutex;
       
  2136 	friend class Monitor;
       
  2137 	};
       
  2138 
       
  2139 /********************************************/
       
  2140 
       
  2141 /** List of all supported events.
       
  2142 
       
  2143 	By default, all events, except the explicitly mentioned ones, are sent only
       
  2144 	if the kernel is built with __DEBUGGER_SUPPORT__ defined.
       
  2145 
       
  2146 	This event set may be extended in the future, so clients should handle
       
  2147 	unknown events gracefully.
       
  2148 
       
  2149 	@see DKernelEventHandler
       
  2150 	@publishedPartner
       
  2151 	@released
       
  2152 */
       
  2153 enum TKernelEvent
       
  2154 	{
       
  2155 	/**
       
  2156 	Event delivered when a user-side software exception occurs.
       
  2157 	This event is always sent.
       
  2158 	The following conditions are true:
       
  2159 		- a1 contains a TExcType instance.
       
  2160 		- The current thread is the thread taking the exception.
       
  2161 	*/
       
  2162 	EEventSwExc,
       
  2163 
       
  2164 	/**
       
  2165 	Event delivered when a hardware exception occurs.
       
  2166 	This event is always sent.
       
  2167 	The following conditions are true:
       
  2168 		- a1 points to the CPU-specific structure stored on the 
       
  2169 		  stack where the processor state has been saved.  For ARM, 
       
  2170 		  the structure is TArmExcInfo.
       
  2171 		- The current thread is the thread taking the exception.
       
  2172 	On exit, use DKernelEventHandler::EExcHandled to indicate event
       
  2173 	handled.
       
  2174 	*/
       
  2175 	EEventHwExc,
       
  2176 
       
  2177 	/**
       
  2178 	Event delivered when a process is created (i.e. during a call to 
       
  2179 	RProcess::Create or Kern::ProcessCreate()).
       
  2180 	The following conditions are true:
       
  2181 		- a1 points to the process being created.
       
  2182 		- a2 points to the creator thread (which may not be the current thread).
       
  2183 		  In some case the creator thread can not be reliably determined and a2
       
  2184 		  will be set to NULL.
       
  2185 		- The process being created is partly constructed (no threads and no chunks yet).
       
  2186 	*/
       
  2187 	EEventAddProcess,
       
  2188 
       
  2189 	/**
       
  2190 	Event delivered after a process attribute change.  Currently this applies
       
  2191 	only to process renaming and address space change (chunk addition/removal)
       
  2192 	but may be extended in the future.
       
  2193 	The following conditions are true:
       
  2194 		- a1 points to the process being modified.
       
  2195 		- The process lock may be held
       
  2196 	*/
       
  2197 	EEventUpdateProcess,
       
  2198 
       
  2199 	/**
       
  2200 	Event delivered when a process terminates.
       
  2201 	The following conditions are true:
       
  2202 		- a1 points to the process being terminated.
       
  2203 		- The current thread is the kernel server thread.
       
  2204 		- The process is partly destructed so its resources should be accessed
       
  2205 		  only after checking they still exist.
       
  2206 	*/
       
  2207 	EEventRemoveProcess,
       
  2208 
       
  2209 	/**
       
  2210 	Event delivered when a user or kernel thread is created (i.e. during a call
       
  2211 	to RProcess::Create(), RThread::Create() or Kern::ThreadCreate()).  
       
  2212 	The following conditions are true:
       
  2213 		- a1 points to the thread being created.
       
  2214 		- a2 points to the creator thread (which may not be the current thread).
       
  2215 		- The thread being created is fully constructed but has not executed any code yet.
       
  2216 	*/
       
  2217 	EEventAddThread,
       
  2218 
       
  2219 	/**
       
  2220 	Event delivered when a user or kernel thread is scheduled for the first time.
       
  2221 	The following conditions are true:
       
  2222 		- a1 points to the thread being scheduled.
       
  2223 		- The current thread is the thread being scheduled.
       
  2224 		- The thread has not executed any code yet.
       
  2225 	*/
       
  2226 	EEventStartThread,
       
  2227 
       
  2228 	/**
       
  2229 	Event delivered after a thread attribute change.  Currently this applies
       
  2230 	only to thread renaming but may be extended in the future.
       
  2231 	a1 points to the thread being modified.
       
  2232 	*/
       
  2233 	EEventUpdateThread,
       
  2234 
       
  2235 	/**
       
  2236 	Event delivered when a user or kernel thread terminates.
       
  2237 	This event is always sent.
       
  2238 	The following conditions are true:
       
  2239 		- a1 points to the thread being terminated.
       
  2240 		- The current thread is the thread being terminated.
       
  2241 		- The current thread is in the ECSExitInProgress state, 
       
  2242 		  and so can not be suspended.
       
  2243 		- The thread's address space can be inspected.
       
  2244 	*/
       
  2245 	EEventKillThread,
       
  2246 
       
  2247 	/**
       
  2248 	Event delivered when a user or kernel thread is about to be closed.
       
  2249 	The following conditions are true:
       
  2250 		- a1 points to the thread being terminated.
       
  2251 		- The current thread is the supervisor thread.
       
  2252 		- The thread is partly destructed so its resources should be accessed
       
  2253 		  only after checking if they still exist.
       
  2254 	 */
       
  2255 	EEventRemoveThread,
       
  2256 
       
  2257 	/**
       
  2258 	Event delivered when a chunk is created.
       
  2259 	The following conditions are true:
       
  2260 		- a1 points to the chunk being created.
       
  2261 	*/
       
  2262 	EEventNewChunk,
       
  2263 
       
  2264 	/**
       
  2265 	Event delivered when physical memory is committed to/decommitted from a
       
  2266 	chunk.
       
  2267 	The following conditions are true:
       
  2268 		- a1 points to the chunk being modified.
       
  2269 	*/
       
  2270 	EEventUpdateChunk,
       
  2271 
       
  2272 	/**
       
  2273 	Event delivered when a chunk is deleted.
       
  2274 	The following conditions are true:
       
  2275 		- a1 points to the chunk being deleted.
       
  2276 	*/
       
  2277 	EEventDeleteChunk,
       
  2278 
       
  2279 	/**
       
  2280 	Event delivered when a user-side DLL is explicitly loaded.
       
  2281 	The following conditions are true:
       
  2282 		- a1 points to the DLibrary instance being loaded.
       
  2283 		- a2 points to the creator thread.
       
  2284 		- DLibrary::iMapCount is equals to 1 if the DLL is loaded for the first 
       
  2285 		  time into the creator thread's address space.
       
  2286 		- If the DLL is loaded for the first time, its global c'tors (if any) 
       
  2287 		  haven't been called yet.
       
  2288 		- The DLL and all its dependencies have been mapped.
       
  2289 		- The system-wide mutex DCodeSeg::CodeSegLock is held.
       
  2290 	*/
       
  2291 	EEventAddLibrary,
       
  2292 
       
  2293 	/**
       
  2294 	Event delivered when a previously explicitly loaded user-side DLL is 
       
  2295 	closed or unloaded (i.e. call to RLibrary::Close()).
       
  2296 	The following conditions are true:
       
  2297 		- a1 points to the DLibrary instance being unloaded.
       
  2298 		- DLibrary::iMapCount is equals to 0 if the DLL is about to be unloaded.
       
  2299 		- If the DLL is about to be unloaded, its global d'tors have been called
       
  2300 		  but it is still mapped (and so are its dependencies).
       
  2301 		- The current thread may be the kernel server.
       
  2302 		- The system-wide mutex DCodeSeg::CodeSegLock is held.
       
  2303 	*/
       
  2304 	EEventRemoveLibrary,
       
  2305 
       
  2306 	/**
       
  2307 	Event delivered when a LDD is loaded.  
       
  2308 	The following conditions are true:
       
  2309 		- a1 points to the LDD's code segment (DCodeSeg instance).
       
  2310 		- The current thread is the loader thread.
       
  2311 		- The LDD factory function has not been called yet.
       
  2312 	*/
       
  2313 	EEventLoadLdd,
       
  2314 
       
  2315 	/** 
       
  2316 	Event delivered when a LDD is unloaded.
       
  2317 	The following conditions are true:
       
  2318 		- a1 points to the LDD's code segment (DCodeSeg instance).
       
  2319 		- The current thread is the loader thread.
       
  2320 	*/
       
  2321 	EEventUnloadLdd,
       
  2322 
       
  2323 	/**
       
  2324 	Event delivered when a PDD is loaded.
       
  2325 	The following conditions are true:
       
  2326 		- a1 points to the PDD's code segment (DCodeSeg instance).
       
  2327 		- The current thread is the loader thread.
       
  2328 		- The PDD factory function has not been called yet.
       
  2329 	*/
       
  2330 	EEventLoadPdd,
       
  2331 
       
  2332 	/** 
       
  2333 	Event delivered when a PDD is unloaded.
       
  2334 	The following conditions are true:
       
  2335 		- a1 points to the PDD's code segment (DCodeSeg instance).
       
  2336 		- The current thread is the loader thread.
       
  2337 	*/
       
  2338 	EEventUnloadPdd,
       
  2339 
       
  2340 	/** 
       
  2341 	Event delivered when RDebug::Print is called in user-side code.
       
  2342 	The following conditions are true:
       
  2343 		- a1 points to the user-side buffer containing the unicode string 
       
  2344 		  for printing.  The characters can not be accessed directly. The
       
  2345 		  string must copied instead using kumemget() and, as the event
       
  2346 		  is delivered in thread critical section, the call to kumemget()
       
  2347 		  must be protected with XTRAP.
       
  2348 		- a2 is a TInt which holds the length in characters of the string 
       
  2349 		  for printing.  As this is a unicode string, the size of the 
       
  2350 		  user-side buffer is twice the length.
       
  2351 		- The current thread is the user-side client.
       
  2352 	On exit use DKernelEventHandler::ETraceHandled to indicate event handled.
       
  2353 	*/
       
  2354 	EEventUserTrace,
       
  2355 	
       
  2356 	/**
       
  2357 	Event delivered when a code segment is mapped into a process.
       
  2358 	The following conditions are true:
       
  2359 		- a1 points to the code segment.
       
  2360 		- a2 points to the process.
       
  2361 		- The system-wide mutex DCodeSeg::CodeSegLock is held.
       
  2362 	*/
       
  2363 	EEventAddCodeSeg,
       
  2364 
       
  2365 	/**
       
  2366 	Event delivered when a code segment is unmapped from a process.
       
  2367 	The following conditions are true:
       
  2368 		- a1 points to the code segment.
       
  2369 		- a2 points to the process.
       
  2370 		- The system-wide mutex DCodeSeg::CodeSegLock is held.
       
  2371 	*/
       
  2372 	EEventRemoveCodeSeg,
       
  2373 	
       
  2374 	/**
       
  2375 	Event delivered when a process is created (i.e. during a call to 
       
  2376 	RProcess::Create or Kern::ProcessCreate()).
       
  2377 	The following conditions are true:
       
  2378 		- a1 points to the process.
       
  2379 		- The process being created is fully constructed.
       
  2380 	*/
       
  2381 	EEventLoadedProcess,
       
  2382 
       
  2383 	/**
       
  2384 	Event delivered when a process is being released, before its code segment,
       
  2385 	stack chunk, etc. are unmapped.
       
  2386 	The following conditions are true:
       
  2387 		- a1 points to the process.
       
  2388 		- The process being released is fully constructed.
       
  2389 	*/
       
  2390 	EEventUnloadingProcess,
       
  2391 
       
  2392 	/**
       
  2393 	Must be last
       
  2394 	*/
       
  2395 	EEventLimit
       
  2396 	};
       
  2397 
       
  2398 /** Access-counted event handler callback.
       
  2399 
       
  2400 	The kernel maintains a queue of event handlers which are called in turn 
       
  2401 	when various events (thread creation, hardware exception, ...) occur.
       
  2402 
       
  2403 	Typical clients would be drivers or kernel extensions implementing kernel
       
  2404 	debug agents or profilers.  This class could also be used to extend the
       
  2405 	instruction set (by trapping undefined instructions).
       
  2406 
       
  2407 	An access count needs to be maintained because handlers can not be dequeued
       
  2408 	and destructed while one or more threads are executing some code inside the
       
  2409 	callback.  The access count, initially set to 1, is incremented every time
       
  2410 	a thread enters the callback and decremented every time a thread exits the
       
  2411 	callback.  
       
  2412 	
       
  2413 	Consequently: 
       
  2414 
       
  2415 	- Client code should use Close() instead the operator delete to destroy the
       
  2416 	  event handler.  
       
  2417 
       
  2418 	- If the client is a LDD, the lifetime of the event handler may exceed that
       
  2419 	of the logical channel and its user-side client thread.  Therefore, the
       
  2420 	callback should not refer to data stored in the channel and any
       
  2421 	asynchronous request to be completed in the callback should be cancelled by
       
  2422 	the channel destructor.
       
  2423 
       
  2424 	If the client is a RAM-loaded LDD (or PDD), it is possible for the DLL to
       
  2425 	be unloaded while the handler is still in use.  This would result in an
       
  2426 	exception.  To avoid this, the handler must open a reference to the
       
  2427 	DLogicalDevice (or DPhysicalDevice) and close it in its d'tor.
       
  2428 
       
  2429 	@publishedPartner
       
  2430 	@released
       
  2431 */
       
  2432 class DKernelEventHandler : public DBase
       
  2433 	{
       
  2434 public:
       
  2435 	/** Values used to select where to insert the handler in the queue */
       
  2436 	enum TAddPolicy
       
  2437 		{
       
  2438 		EAppend, /**< Append at end of queue */
       
  2439 		};
       
  2440 
       
  2441 	/** Bitmask returned by callback function */
       
  2442 	enum TReturnCode
       
  2443 		{
       
  2444 		/** Run next handler if set, ignore remaining handlers if cleared */
       
  2445 		ERunNext = 1,
       
  2446 		/** Available for EEventUserTrace only.  Ignore trace statement if set. */
       
  2447 		ETraceHandled = 0x40000000,
       
  2448 		/** Available for hardware exceptions only.  Do not panic thread if set. */
       
  2449 		EExcHandled = (TInt)0x80000000,
       
  2450 		};
       
  2451 
       
  2452 	/** Pointer to C callback function called when an event occurs.
       
  2453 		aEvent designates what event is dispatched.  a1 and a2 are event-specific.  
       
  2454 		aPrivateData is specified when the handler is created, typically a pointer
       
  2455 		to the event handler.  
       
  2456 		The function is always called in thread critical section. 
       
  2457 		@see TReturnCode
       
  2458 	 */
       
  2459 	typedef TUint (*TCallback)(TKernelEvent aEvent, TAny* a1, TAny* a2, TAny* aPrivateData);
       
  2460 public:
       
  2461 	// external interface
       
  2462 	IMPORT_C static TBool DebugSupportEnabled();
       
  2463 	IMPORT_C DKernelEventHandler(TCallback aCb, TAny* aPrivateData);
       
  2464 	IMPORT_C TInt Add(TAddPolicy aPolicy = EAppend);
       
  2465 	IMPORT_C TInt Close();
       
  2466 	inline TBool IsQueued() const;
       
  2467 public:
       
  2468 	// kernel internal interface
       
  2469 	static TUint Dispatch(TKernelEvent aEvent, TAny* a1, TAny* a2);
       
  2470 private:
       
  2471 	static SDblQue HandlersQ;
       
  2472 private:
       
  2473 	TInt iAccessCount;
       
  2474 	SDblQueLink iLink;
       
  2475 	TCallback iCb;
       
  2476 	TAny* iPrivateData;
       
  2477 	};
       
  2478 
       
  2479 /** Returns whether or not the handler has been queued. */
       
  2480 inline TBool DKernelEventHandler::IsQueued() const
       
  2481 	{
       
  2482 	return iLink.iNext != NULL;
       
  2483 	}
       
  2484 
       
  2485 
       
  2486 /********************************************
       
  2487  * Persistent Machine Configuration
       
  2488  ********************************************/
       
  2489 
       
  2490 /**
       
  2491 	@internalTechnology
       
  2492 */
       
  2493 class TMachineConfig
       
  2494 	{
       
  2495 public:
       
  2496 	TInt iLogSize;
       
  2497 	TInt iLogMaxSize;
       
  2498 	SLocaleData iLocale;
       
  2499 	TInt iXtalError;
       
  2500 
       
  2501 	/** The last time set by the user */
       
  2502 	TTimeK LastSetTime;
       
  2503 
       
  2504 	/** The accumulated RTC correction due to crystal errors */
       
  2505 	TInt TheRTCCorrection;
       
  2506 	};
       
  2507 
       
  2508 /******************************************************************************
       
  2509  * Macros for typical extensions/device drivers/ASSPs
       
  2510  ******************************************************************************/
       
  2511 #ifndef __WINS__
       
  2512 /**
       
  2513 @internalComponent
       
  2514 @prototype 9.5
       
  2515 	
       
  2516 Defines the entry point for an extension that specifies a priority
       
  2517 Priorities are used to sequence calls to the entry point (KModuleEntryReasonExtensionInit1)
       
  2518 and may be used to ensure that extensions with higher priority are started before
       
  2519 ones with lower priority. When the priority of 2 extensions is the same, the order
       
  2520 they are started is the order they appear in the ROM header extension list.
       
  2521 The maximum priority is 255. Priority 0 is the lowest priority (standard extension).
       
  2522 @note This feature is not available for the emulator.
       
  2523 */
       
  2524 #define	DECLARE_EXTENSION_WITH_PRIORITY(priority)							\
       
  2525 	GLREF_C TInt InitExtension();											\
       
  2526 	TInt KernelModuleEntry(TInt aReason)									\
       
  2527 		{																	\
       
  2528 		if (aReason==KModuleEntryReasonExtensionInit0)						\
       
  2529 			return priority;												\
       
  2530 		if (aReason!=KModuleEntryReasonExtensionInit1)						\
       
  2531 			return KErrArgument;											\
       
  2532 		return InitExtension();												\
       
  2533 		}																	\
       
  2534 	GLDEF_C TInt InitExtension()
       
  2535 
       
  2536 
       
  2537 /**
       
  2538 @publishedPartner
       
  2539 @released
       
  2540 	
       
  2541 Defines the entry point for a standard extension	
       
  2542 */
       
  2543 #define	DECLARE_STANDARD_EXTENSION() DECLARE_EXTENSION_WITH_PRIORITY(KExtensionStandardPriority)
       
  2544 
       
  2545 #else 
       
  2546 /**
       
  2547 @publishedPartner
       
  2548 @released
       
  2549 	
       
  2550 Defines the entry point for a standard extension	
       
  2551 */
       
  2552 #define	DECLARE_STANDARD_EXTENSION()										\
       
  2553 	GLREF_C TInt InitExtension();											\
       
  2554 	TInt KernelModuleEntry(TInt aReason)									\
       
  2555 		{																	\
       
  2556 		if (aReason==KModuleEntryReasonExtensionInit0)						\
       
  2557 			return KErrNone;												\
       
  2558 		if (aReason!=KModuleEntryReasonExtensionInit1)						\
       
  2559 			return KErrArgument;											\
       
  2560 		return InitExtension();												\
       
  2561 		}																	\
       
  2562 	GLDEF_C TInt InitExtension()
       
  2563 
       
  2564 #endif
       
  2565 
       
  2566 /**
       
  2567 @publishedPartner
       
  2568 @released
       
  2569 
       
  2570 Defines the entry point for a standard logical device driver (LDD),
       
  2571 and declares the ordinal 1 export function for creating the LDD factory object	
       
  2572 */
       
  2573 #define	DECLARE_STANDARD_LDD()												\
       
  2574 	TInt KernelModuleEntry(TInt)											\
       
  2575 		{ return KErrNone; }												\
       
  2576 	EXPORT_C DLogicalDevice* CreateLogicalDevice()
       
  2577 
       
  2578 
       
  2579 
       
  2580 
       
  2581 /**
       
  2582 @publishedPartner
       
  2583 @released
       
  2584 
       
  2585 Defines the entry point for a standard physical device driver (PDD),
       
  2586 and declares the ordinal 1 export function for creating the PDD factory object.
       
  2587 */
       
  2588 #define	DECLARE_STANDARD_PDD()												\
       
  2589 	TInt KernelModuleEntry(TInt)											\
       
  2590 		{ return KErrNone; }												\
       
  2591 	EXPORT_C DPhysicalDevice* CreatePhysicalDevice()
       
  2592 
       
  2593 
       
  2594 
       
  2595 
       
  2596 /**
       
  2597 @publishedPartner
       
  2598 @released
       
  2599 
       
  2600 Defines the entry point for a standard logical device driver (LDD)
       
  2601 that is also an extension, and declares the ordinal 1 export function
       
  2602 for creating the LDD factory object	
       
  2603 */
       
  2604 #define	DECLARE_EXTENSION_LDD()												\
       
  2605 	EXPORT_C DLogicalDevice* CreateLogicalDevice()
       
  2606 
       
  2607 
       
  2608 
       
  2609 
       
  2610 /**
       
  2611 @publishedPartner
       
  2612 @released
       
  2613 	
       
  2614 Defines the entry point for a standard physical device driver (PDD)
       
  2615 that is also an extension, and declares the ordinal 1 export function
       
  2616 for creating the PDD factory object	
       
  2617 */
       
  2618 #define	DECLARE_EXTENSION_PDD()												\
       
  2619 	EXPORT_C DPhysicalDevice* CreatePhysicalDevice()
       
  2620 
       
  2621 
       
  2622 
       
  2623 
       
  2624 /**
       
  2625 @publishedPartner
       
  2626 @released
       
  2627 
       
  2628 Generates a stub entry point function and the AsicInitialise() function that 
       
  2629 causes static constructors to be called.
       
  2630 
       
  2631 ASSP DLLs require static constructors to be called at the same time as
       
  2632 the variant is initialised.
       
  2633 */
       
  2634 #define	DECLARE_STANDARD_ASSP()												\
       
  2635 	extern "C" { GLREF_C TInt _E32Dll(TInt); }								\
       
  2636 	GLDEF_C TInt KernelModuleEntry(TInt aReason)							\
       
  2637 		{ return (aReason==KModuleEntryReasonExtensionInit1)				\
       
  2638 						?KErrNone:KErrGeneral; }							\
       
  2639 	EXPORT_C void AsicInitialise()											\
       
  2640 		{ _E32Dll(KModuleEntryReasonExtensionInit1); }
       
  2641 
       
  2642 
       
  2643 /**
       
  2644 @internalComponent
       
  2645 */
       
  2646 #define	__VARIANT_SUPPORTS_ADDITIONAL_INTERFACE_BLOCK__(x)					\
       
  2647 	__Variant_Flags__ |= (x)
       
  2648 
       
  2649 /**
       
  2650 @internalTechnology
       
  2651 @prototype
       
  2652 Used to indicate that a variant supports the nanokernel interface block
       
  2653 */
       
  2654 #define	__VARIANT_SUPPORTS_NANOKERNEL_INTERFACE_BLOCK__()					\
       
  2655 			__VARIANT_SUPPORTS_ADDITIONAL_INTERFACE_BLOCK__(1)
       
  2656 
       
  2657 
       
  2658 class DemandPaging;
       
  2659 
       
  2660 /**
       
  2661 Memory locking on demand paging systems.
       
  2662 
       
  2663 This class is not thread safe. I.e. Only one method should be executed at any time
       
  2664 for a given instance of an object.
       
  2665 
       
  2666 @internalTechnology
       
  2667 @prototype
       
  2668 */
       
  2669 class DDemandPagingLock : public DBase
       
  2670 	{
       
  2671 public:
       
  2672 	IMPORT_C DDemandPagingLock();
       
  2673 
       
  2674 	/**
       
  2675 	Unlock and Free the memory associated with this object
       
  2676 	*/
       
  2677 	inline ~DDemandPagingLock() { Free(); }
       
  2678 
       
  2679 	/**
       
  2680 	Reserve memory so that this object can be used for locking up to
       
  2681 	the specified number of bytes.
       
  2682 
       
  2683 	@param aSize Maximum number of bytes to be locked.
       
  2684 
       
  2685 	@return KErrNone or standard error code.
       
  2686 	*/
       
  2687 	IMPORT_C TInt Alloc(TInt aSize);
       
  2688 
       
  2689 	/**
       
  2690 	Unlock any memory locked by this object, then free the memory reserved with 
       
  2691 	Alloc(). This returns the object to the same state it was at immediately after 
       
  2692 	construction.
       
  2693 	*/
       
  2694 	IMPORT_C void Free();
       
  2695 
       
  2696 	/**
       
  2697 	Ensure all pages in the given region are present and lock them so that they will 
       
  2698 	not be paged out. If the region contained no demand paged memory, then no action 
       
  2699 	is performed.
       
  2700 
       
  2701 	This function may not be called again until the previous memory has been 
       
  2702 	unlocked.
       
  2703 
       
  2704 	@param aThread The thread in whoes process the memory lies.
       
  2705 	@param aStart The address of the first byte of memory to be locked.
       
  2706 	@param aSize The number of bytes to lock.
       
  2707 
       
  2708 	@return 1 (one) if any memory was locked. 0 (KErrNone) if memory
       
  2709 			did not need locking because it is not demand paged. Otherwise
       
  2710 			KErrBadDescriptor to indicate that the memory region was not
       
  2711 			valid.
       
  2712 
       
  2713 	@pre Alloc must have been used to reserve sufficient RAM.
       
  2714 	*/
       
  2715 	IMPORT_C TInt Lock(DThread* aThread, TLinAddr aStart, TInt aSize);
       
  2716 
       
  2717 	/**
       
  2718 	Unlock the memory region which was previousely locked with Lock.
       
  2719 	This may be called even if memory wasn't previousely locked.
       
  2720 	*/
       
  2721 	inline void Unlock() { if(iLockedPageCount) DoUnlock(); }
       
  2722 
       
  2723 private:
       
  2724 	IMPORT_C void DoUnlock();
       
  2725 private:
       
  2726 	DemandPaging* iThePager;
       
  2727 	TInt iReservedPageCount;
       
  2728 	TInt iLockedPageCount;
       
  2729 	TLinAddr iLockedStart;
       
  2730 	DProcess* iProcess;
       
  2731 	TPhysAddr* iPages;
       
  2732 	TAny* iPinMapping;
       
  2733 	TInt iMaxPageCount;
       
  2734 
       
  2735 	friend class DemandPaging;
       
  2736 	};
       
  2737 
       
  2738 
       
  2739 
       
  2740 class DPagingRequestPool;
       
  2741 
       
  2742 /**
       
  2743 Base class for Paging Devices.
       
  2744 A Paging Device provides the paging system with access to storage media which holds
       
  2745 data being demand paged.
       
  2746 @internalTechnology
       
  2747 @prototype
       
  2748 */
       
  2749 class DPagingDevice : public DBase
       
  2750 	{
       
  2751 public:
       
  2752 	/** The type of device this represents. */
       
  2753 	enum TType
       
  2754 		{
       
  2755 		ERom  = 1<<0,	/**< Paged ROM device type. */
       
  2756 		ECode = 1<<1,	/**< Code paging device type. */
       
  2757 		EData = 1<<2	/**< Data paging device type. */
       
  2758 		};
       
  2759 
       
  2760 	enum TSpecialDrives
       
  2761 		{
       
  2762 		EDriveRomPaging = -1,	/**< Special drive number to indicate rom paging. */
       
  2763 		EDriveDataPaging = -2,	/**< Special drive number to indicate data paging. */
       
  2764 		};
       
  2765 
       
  2766 	/**
       
  2767 	Called by the paging system to read data from the media represented by this
       
  2768 	device.
       
  2769 
       
  2770 	@param aBuffer The location where the read data should be stored.
       
  2771 	@param aOffset The offset from the media start, in read units, from where
       
  2772 				   data should be read.
       
  2773 	@param aSize   The number of read units to be read.
       
  2774 	
       
  2775 	@param aDrvNumber The drive number for code paging or a member of TSpecialDrives for rom or data
       
  2776 	paging.
       
  2777 
       
  2778 	@return KErrNone or standard error code.
       
  2779 	*/
       
  2780 	virtual TInt Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize, TInt aDrvNumber) = 0;
       
  2781 
       
  2782 	/**
       
  2783 	Called by the paging system to write data to the media represented by this device.
       
  2784 
       
  2785 	This is only used in the implementation of data paging to write to the swap partition.
       
  2786 
       
  2787 	@param aBuffer The location of the data to write.
       
  2788 	@param aOffset The offset from the media start, in read units, to where data should be written.
       
  2789 	@param aSize   The number of read units to write.
       
  2790 	@param aBackground  If set, this indicates that the request should not count as making the device busy.
       
  2791 
       
  2792 	@return KErrNone or standard error code.
       
  2793 	*/
       
  2794 	inline virtual TInt Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground);
       
  2795 
       
  2796 	/**
       
  2797 	Called by the paging system to notify the media driver that data that was previously written is
       
  2798 	now no longer needed.
       
  2799 
       
  2800 	This is only used in the implementation of data paging when data in the swap partition is no
       
  2801 	longer needed.
       
  2802 
       
  2803 	@param aOffset The offset from the media start, in read units, to where data was written.
       
  2804 	@param aSize   The size in read units.
       
  2805 
       
  2806 	@return KErrNone or standard error code.
       
  2807 	*/
       
  2808 	inline virtual TInt DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize);
       
  2809 
       
  2810 	/**
       
  2811 	Called by the paging device to notify the kernel that the device has just become idle and is not
       
  2812 	currently processing any requests.
       
  2813 
       
  2814 	This is used by the kernel to work out when to clean pages in the background.
       
  2815 
       
  2816 	Note that write requests made by calling the DPagingDevice::Write() with the aBackground flag
       
  2817 	set do not count towards the device being busy.
       
  2818 	*/
       
  2819 	IMPORT_C void NotifyIdle();
       
  2820 
       
  2821 	/**
       
  2822 	Called by the paging device to notify the kernel that the device has just become busy and is
       
  2823 	currently processing requests.
       
  2824 
       
  2825 	This is used by the kernel to work out when to clean pages in the background.
       
  2826 
       
  2827 	Note that write requests made by calling the DPagingDevice::Write() with the aBackground flag
       
  2828 	set do not count towards the device being busy.
       
  2829 	*/
       
  2830 	IMPORT_C void NotifyBusy();
       
  2831 	
       
  2832 public:
       
  2833 	/** The type of device this represents. */
       
  2834 	TUint32 iType;
       
  2835 
       
  2836 	/** The local drives supported for code paging.
       
  2837 	    This is a bitmask containing one bit set for each local drive supported, where the bit set
       
  2838 	    is 1 << the local drive number.  If this device does not support code paging, this should be
       
  2839 	    zero. */
       
  2840 	TUint32 iDrivesSupported;
       
  2841 
       
  2842 	/** Zero terminated string representing the name of the device.
       
  2843 		(Only used for debug tracing purposes.) */
       
  2844 	const char* iName;
       
  2845 
       
  2846 	/** Log2 of the read unit size. A read unit is the number of bytes which
       
  2847 		the device can optimally read from the underlying media.
       
  2848 		E.g. for small block NAND, a read unit would be equal to the page size,
       
  2849 		512 bytes, therefore iReadUnitShift would be set to 9. */
       
  2850 	TInt iReadUnitShift;
       
  2851 
       
  2852 	/** The value the device should use to identify itself.
       
  2853 		This value is set by Kern::InstallPagingDevice().
       
  2854 		The purpose of this Id is to distinguish multiple Code Paging devices. */
       
  2855 	TInt iDeviceId;
       
  2856 
       
  2857 	/** For data paging only, the size of the swap partition supported by this device, in read units.
       
  2858 		
       
  2859 		If data paging is not supported, or has been disabled by the media driver, this should be
       
  2860 		zero.
       
  2861 	*/
       
  2862 	TInt iSwapSize;
       
  2863 
       
  2864 	/** The pool of DPagingRequest objects used to issue requests for this device.
       
  2865 		This is setup and used internally by the kernel.
       
  2866 	*/
       
  2867 	DPagingRequestPool* iRequestPool;
       
  2868 
       
  2869 	/** Reserved for future use.
       
  2870 	*/
       
  2871 	TInt iSpare[4];
       
  2872 	};
       
  2873 
       
  2874 inline TInt DPagingDevice::Write(TThreadMessage*,TLinAddr,TUint,TUint,TBool)
       
  2875 	{
       
  2876 	// Default implementation, may be overriden by dervied classes
       
  2877 	return KErrNotSupported;
       
  2878 	}
       
  2879 
       
  2880 inline TInt DPagingDevice::DeleteNotify(TThreadMessage*,TUint,TUint)
       
  2881 	{
       
  2882 	// Default implementation, may be overriden by dervied classes
       
  2883 	return KErrNotSupported;
       
  2884 	}
       
  2885 
       
  2886 extern "C" { extern TInt __Variant_Flags__; }
       
  2887 
       
  2888 /********************************************
       
  2889  * Shareable Data Buffers
       
  2890  ********************************************/
       
  2891 /**
       
  2892    Pool create info
       
  2893 
       
  2894    @publishedPartner
       
  2895    @prototype
       
  2896 */
       
  2897 class TMappingAttributes2;
       
  2898 
       
  2899 #include <e32shbufcmn.h>
       
  2900 
       
  2901 class TShPoolCreateInfo
       
  2902 	{
       
  2903 public:
       
  2904 	/**
       
  2905 	Enumeration type to say that the shared pool is to be backed with memory supplied by the kernel.
       
  2906 	*/
       
  2907 	enum TShPoolPageAlignedBuffers
       
  2908 		{
       
  2909 		EPageAlignedBuffer = EShPoolPageAlignedBuffer,
       
  2910 		};
       
  2911 
       
  2912 	/**
       
  2913 	Enumeration type to say that the shared pool is to be backed with memory supplied by the kernel.
       
  2914 	*/
       
  2915 	enum TShPoolNonPageAlignedBuffers
       
  2916 		{
       
  2917 		ENonPageAlignedBuffer = EShPoolNonPageAlignedBuffer,
       
  2918 		};
       
  2919 
       
  2920 	/**
       
  2921 	Enumeration type to say that the shared pool is to be mapped onto device memory.
       
  2922 	*/
       
  2923 	enum TShPoolMemoryDevice
       
  2924 		{
       
  2925 		EDevice = EShPoolPhysicalMemoryPool,
       
  2926 		};
       
  2927 
       
  2928 	IMPORT_C TShPoolCreateInfo(TShPoolPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs);
       
  2929 	IMPORT_C TShPoolCreateInfo(TShPoolNonPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment);
       
  2930 
       
  2931 	IMPORT_C TShPoolCreateInfo(TShPoolMemoryDevice aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment, TUint aPages, TPhysAddr* aPhysicalAddressList);
       
  2932 
       
  2933 	IMPORT_C TShPoolCreateInfo(TShPoolMemoryDevice aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment, TUint aPages, TPhysAddr aPhysicalAddress);
       
  2934 
       
  2935 	IMPORT_C TInt SetSizingAttributes(TUint aMaxBufs, TUint aMinFreeBufs, TUint aGrowByBufs, TUint aShrinkByBufs);
       
  2936 	IMPORT_C TInt SetExclusive();
       
  2937 	IMPORT_C TInt SetContiguous();
       
  2938 	IMPORT_C TInt SetGuardPages();
       
  2939 
       
  2940 private:
       
  2941 	friend class ExecHandler;
       
  2942 	friend class DShPool;
       
  2943 	friend class DMemModelShPool;
       
  2944 	friend class DMemModelAlignedShPool;
       
  2945 	friend class DMemModelNonAlignedShPool;
       
  2946 	friend class DMemModelProcess;
       
  2947 	friend class DWin32ShPool;
       
  2948 	friend class DWin32AlignedShPool;
       
  2949 	friend class DWin32NonAlignedShPool;
       
  2950 	friend class DWin32Process;
       
  2951 	friend class DShBufTestDrvChannel;
       
  2952 
       
  2953 	inline TShPoolCreateInfo()	///< default constructor
       
  2954 		{
       
  2955 		memclr(this, sizeof(TShPoolCreateInfo));
       
  2956 		};
       
  2957 
       
  2958 	TShPoolInfo iInfo;
       
  2959 
       
  2960 	union PhysAddr
       
  2961 		{
       
  2962 		TPhysAddr* iPhysAddrList;	///< physical addresses for hardware
       
  2963 		TPhysAddr  iPhysAddr;		///< physical address for hardware
       
  2964 		} iPhysAddr;
       
  2965 
       
  2966 	TUint iPages;				///< number of pages to commit
       
  2967 };
       
  2968 
       
  2969 #endif //__K32STD_H__