Update contrib.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\nkern\win32\nk_plat.h
16 // WARNING: This file contains some APIs which are internal and are subject
17 // to change without notice. Such APIs should therefore not be used
18 // outside the Kernel and Hardware Services package.
26 #ifndef __NK_WIN32_H__
27 #define __NK_WIN32_H__
34 #define _CRTIMP // we want to use the win32 static runtime library
36 #define WIN32_LEAN_AND_MEAN
43 #define _WIN32_WINNT 0x0400
46 typedef void (*TExcHandler)(TAny*,TAny*);
50 enum {EExcInKernel = 0x1};
55 // ExcType, iExcId, iFaultAddress, iEax, iEcx, iEdx, iEbx, iEsp, iEbp, iEsi, iEdi,
56 // iSs, iDs, iEs, iFs, iGs, iEflags, iEip, iCs
57 TUint32 iExcType; // filled in by EPOC
59 TUint32 iExcDataAddress;
80 EThreadEvent, // an 'interrupt' thread, interacts with Win32 events
81 EThreadNKern // a nKern thread, identified by a NThread control block
84 class NThread : public NThreadBase
87 typedef void (*TDivert)();
88 enum TWakeup {ERelease,EResume,EResumeLocked,EIdle,EEscaped,EResumeDiverted};
89 enum TSelectCpu {ECpuAll=-1,ECpuSingle=-2};
91 TInt Create(SNThreadCreateInfo& aInfo, TBool aInitial);
95 IMPORT_C static void Idle();
96 IMPORT_C static void SetProperties(TBool aTrace, TInt aCpu);
98 TBool IsSafeToPreempt();
99 void Divert(TDivert aDivert);
100 void ApplyDiversion();
103 static DWORD WINAPI StartThread(LPVOID aParam);
105 static void ExitSync();
106 static void ExitAsync();
108 static void Exception();
109 static LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS* aExc);
112 static void Diverted();
113 // Has to be accessible to code user-side via emulator.lib
114 static DWORD ExceptionHandler(EXCEPTION_RECORD* aException, CONTEXT* aContext);
119 HANDLE iScheduleLock; // event used for scheduling interlock
120 TBool iDiverted; // flag to indicate that the thread is being diverted
121 TDivert iDivert; // function to invoke after reschedule, may be null
122 TAny* iDivertReturn; // return address from diversion
123 TInt iInKernel; // flag to indicate if the thread is running 'in' the kernel
124 TWakeup iWakeup; // indicates how to wake up the thread
125 TLinAddr iUserStackBase;
128 IMPORT_C HANDLE CreateWin32Thread(TEmulThreadType aType, LPTHREAD_START_ROUTINE aThreadFunc, LPVOID aPtr, TBool aRun);
129 IMPORT_C void StartOfInterrupt();
130 IMPORT_C void EndOfInterrupt();
132 void SchedulerInit(NThread& aInit);
133 void SchedulerRegister(NThread& aSelf);
134 NThread* SchedulerThread();
135 NThread& CheckedCurrentThread();
136 void SchedulerLock();
137 void SchedulerUnlock();
138 void SchedulerEscape();
139 void SchedulerReenter();
140 void Win32FindNonPreemptibleFunctions();
142 inline void EnterKernel(TBool aCheck=TRUE)
144 if (++CheckedCurrentThread().iInKernel==1 && aCheck)
146 NThread& t = CheckedCurrentThread();
147 __NK_ASSERT_ALWAYS(t.iCsCount==0);
148 __NK_ASSERT_ALWAYS(t.iHeldFastMutex==0);
149 __NK_ASSERT_ALWAYS(TheScheduler.iKernCSLocked==0);
155 IMPORT_C TInt __fastcall Dispatch(TInt aFunction, TInt* aArgs);
157 typedef TInt (__cdecl *TExecHandler)(TInt,TInt,TInt,TInt);
158 typedef void (__cdecl *TPreprocessHandler)(TInt*,TUint32);
160 // Emulator nKern scheduling data
166 void Restore(TInt aLevel);
169 inline TBool InInterrupt() const
170 {return iInterrupted!=0;}
171 void ForceReschedule();
172 inline TBool InterruptsStatus(TBool aRequest) const
173 {return aRequest?(iLevel==0):(iLevel!=0);}
175 static void Reschedule(TAny*);
181 TBool iRescheduleOnExit;
182 NThread* iInterrupted;
186 extern TBool Win32AtomicSOAW; // flag to indicate availability of SignalObjectAndWait() API
187 extern TBool Win32TraceThreadId;
188 extern TInt Win32SingleCpu;
189 extern Win32Interrupt Interrupt;
191 // Emulator nKern exception data
192 extern TAny* Win32ExcAddress;
193 extern TAny* Win32ExcDataAddress;
194 extern TUint Win32ExcCode;
196 void FastCounterInit();