ReactOS  0.4.15-dev-425-gc40b086
ke.h
Go to the documentation of this file.
4 /* Interrupt request levels */
5 #define PASSIVE_LEVEL 0
6 #define LOW_LEVEL 0
7 #define APC_LEVEL 1
8 #define DISPATCH_LEVEL 2
9 #define CMCI_LEVEL 5
10 #define PROFILE_LEVEL 27
11 #define CLOCK1_LEVEL 28
12 #define CLOCK2_LEVEL 28
13 #define IPI_LEVEL 29
14 #define POWER_LEVEL 30
15 #define HIGH_LEVEL 31
16 #define CLOCK_LEVEL CLOCK2_LEVEL
17 
18 #define KIP0PCRADDRESS 0xffdff000
19 #define KI_USER_SHARED_DATA 0xffdf0000
20 #define SharedUserData ((KUSER_SHARED_DATA * CONST)KI_USER_SHARED_DATA)
21 
22 #define PAGE_SIZE 0x1000
23 #define PAGE_SHIFT 12L
24 #define KeGetDcacheFillSize() 1L
25 
26 #define EFLAG_SIGN 0x8000
27 #define EFLAG_ZERO 0x4000
28 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
29 
30 #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
31 #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
32 #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
33 
34 
35 typedef struct _KFLOATING_SAVE {
36  ULONG ControlWord;
37  ULONG StatusWord;
38  ULONG ErrorOffset;
39  ULONG ErrorSelector;
40  ULONG DataOffset;
41  ULONG DataSelector;
42  ULONG Cr0NpxState;
43  ULONG Spare1;
45 
46 extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount;
47 
48 #define YieldProcessor _mm_pause
49 
51 VOID
53 {
54  LONG Barrier, *Dummy = &Barrier;
56 
57 #if defined(__GNUC__)
58  __asm__ __volatile__ ("xchg %%eax, %0" : : "m" (Barrier) : "%eax");
59 #elif defined(_MSC_VER)
60  __asm xchg [Barrier], eax
61 #endif
62 }
63 
64 #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
65 
69 KIRQL
70 NTAPI
72 
75 VOID
79 #define KeLowerIrql(a) KfLowerIrql(a)
80 
85 KIRQL
89 #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
90 
95 KIRQL
96 NTAPI
98 
100 KIRQL
101 NTAPI
103 
109 NTHALAPI
110 KIRQL
111 FASTCALL
114 #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
115 
119 NTHALAPI
120 VOID
121 FASTCALL
125 #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
126 
131 VOID
132 FASTCALL
135 #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
136 
141 VOID
142 FASTCALL
145 #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
146 
147 NTSYSAPI
148 PKTHREAD
149 NTAPI
151 
152 _Always_(_Post_satisfies_(return<=0))
156 _At_(*FloatSave, _Kernel_requires_resource_not_held_(FloatState) _Kernel_acquires_resource_(FloatState))
158 NTSTATUS
159 NTAPI
161  _Out_ PKFLOATING_SAVE FloatSave);
162 
163 _Success_(1)
165 _At_(*FloatSave, _Kernel_requires_resource_held_(FloatState) _Kernel_releases_resource_(FloatState))
167 NTSTATUS
168 NTAPI
170  _In_ PKFLOATING_SAVE FloatSave);
171 
172 #if (NTDDI_VERSION >= NTDDI_WIN7)
174 ULONG
175 NTAPI
177 {
178  return __readfsbyte(0x51);
179 }
180 #endif
181 
182 /* VOID
183  * KeFlushIoBuffers(
184  * IN PMDL Mdl,
185  * IN BOOLEAN ReadOperation,
186  * IN BOOLEAN DmaOperation)
187  */
188 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
189 
190 /* x86 and x64 performs a 0x2C interrupt */
191 #define DbgRaiseAssertionFailure __int2c
192 
194 VOID
196  OUT PLARGE_INTEGER CurrentCount)
197 {
198  for (;;) {
199 #ifdef NONAMELESSUNION
200  CurrentCount->s.HighPart = KeTickCount.High1Time;
201  CurrentCount->s.LowPart = KeTickCount.LowPart;
202  if (CurrentCount->s.HighPart == KeTickCount.High2Time) break;
203 #else
204  CurrentCount->HighPart = KeTickCount.High1Time;
205  CurrentCount->LowPart = KeTickCount.LowPart;
206  if (CurrentCount->HighPart == KeTickCount.High2Time) break;
207 #endif
208  YieldProcessor();
209  }
210 }
211 #define KeQueryTickCount(CurrentCount) _KeQueryTickCount(CurrentCount)
212 
214 $if (_NTDDK_)
215 
216 #define PAUSE_PROCESSOR YieldProcessor();
217 
218 #define KERNEL_STACK_SIZE 12288
219 #define KERNEL_LARGE_STACK_SIZE 61440
220 #define KERNEL_LARGE_STACK_COMMIT 12288
221 
222 #define SIZE_OF_80387_REGISTERS 80
223 
224 #if !defined(RC_INVOKED)
225 
226 #define CONTEXT_i386 0x10000
227 #define CONTEXT_i486 0x10000
228 #define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L)
229 #define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L)
230 #define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L)
231 #define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L)
232 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L)
233 #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
234 
235 #define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
236 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
237  CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \
238  CONTEXT_EXTENDED_REGISTERS)
239 
240 #define CONTEXT_XSTATE (CONTEXT_i386 | 0x00000040L)
241 
242 #endif /* !defined(RC_INVOKED) */
243 
244 typedef struct _FLOATING_SAVE_AREA {
247  ULONG TagWord;
255 
256 #include "pshpack4.h"
257 typedef struct _CONTEXT {
259  ULONG Dr0;
260  ULONG Dr1;
261  ULONG Dr2;
262  ULONG Dr3;
263  ULONG Dr6;
264  ULONG Dr7;
266  ULONG SegGs;
267  ULONG SegFs;
268  ULONG SegEs;
269  ULONG SegDs;
270  ULONG Edi;
271  ULONG Esi;
272  ULONG Ebx;
273  ULONG Edx;
274  ULONG Ecx;
275  ULONG Eax;
276  ULONG Ebp;
277  ULONG Eip;
278  ULONG SegCs;
279  ULONG EFlags;
280  ULONG Esp;
281  ULONG SegSs;
283 } CONTEXT;
284 #include "poppack.h"
285 
286 #define KeGetPcr() PCR
287 
288 #define PCR_MINOR_VERSION 1
289 #define PCR_MAJOR_VERSION 1
290 
291 typedef struct _KPCR {
292  union {
293  NT_TIB NtTib;
294  struct {
302  };
303  };
304  struct _KPCR *SelfPcr;
305  struct _KPRCB *Prcb;
306  KIRQL Irql;
307  ULONG IRR;
309  ULONG IDR;
311  struct _KIDTENTRY *IDT;
312  struct _KGDTENTRY *GDT;
313  struct _KTSS *TSS;
319  UCHAR Number;
323  ULONG KernelReserved[14];
325  ULONG HalReserved[16];
326 } KPCR, *PKPCR;
327 
328 #if (NTDDI_VERSION >= NTDDI_WIN7)
329 _CRT_DEPRECATE_TEXT("KeGetCurrentProcessorNumber is deprecated. Use KeGetCurrentProcessorNumberEx or KeGetCurrentProcessorIndex instead.")
330 #endif
332 ULONG
334 {
336 }
337 
338 $endif (_NTDDK_)
339 
340 
341 
342 
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
struct _EXCEPTION_REGISTRATION_RECORD * Used_ExceptionList
Definition: ke.h:295
PVOID Spare2
Definition: ke.h:297
ULONG LowPart
Definition: ketypes.h:910
#define YieldProcessor
Definition: ke.h:48
KIRQL Irql
Definition: ke.h:307
PVOID Used_StackBase
Definition: ke.h:296
struct _KFLOATING_SAVE KFLOATING_SAVE
#define _Must_inspect_result_
Definition: no_sal2.h:314
ULONG StallScaleFactor
Definition: ke.h:314
ULONG Esp
Definition: nt_native.h:1479
#define _Kernel_releases_resource_(kind)
Definition: no_sal2.h:663
ULONG Eip
Definition: nt_native.h:1476
#define NTHALAPI
Definition: ntoskrnl.h:40
FLOATING_SAVE_AREA FloatSave
Definition: nt_native.h:1446
struct _KFLOATING_SAVE * PKFLOATING_SAVE
#define _IRQL_saves_
Definition: no_sal2.h:655
$if(_WDMDDK_) typedef struct _KFLOATING_SAVE
Definition: ke.h:1
ULONG Ecx
Definition: nt_native.h:1467
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE KIRQL KeRaiseIrqlToSynchLevel(VOID)
Definition: ke.h:117
ULONG IDR
Definition: ke.h:22
#define DISPATCH_LEVEL
_Requires_lock_not_held_ SpinLock _Acquires_lock_ SpinLock _IRQL_requires_min_(DISPATCH_LEVEL) NTKERNELAPI VOID FASTCALL KefAcquireSpinLockAtDpcLevel(_Inout_ PKSPIN_LOCK SpinLock)
#define _WDMDDK_
Definition: wdm.template.h:26
_Requires_lock_not_held_(Vcb->fcb_lock) _Acquires_shared_lock_(Vcb -> fcb_lock) static __inline void acquire_fcb_lock_shared(device_extension *Vcb)
Definition: btrfs_drv.h:967
ULONG SegGs
Definition: nt_native.h:1453
Definition: ke.h:289
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
ULONG SegFs
Definition: nt_native.h:1454
ULONG SegDs
Definition: nt_native.h:1456
#define FASTCALL
Definition: nt_native.h:50
#define NTSYSAPI
Definition: ntoskrnl.h:14
_Kernel_requires_resource_held_(FloatState) _Kernel_releases_resource_(FloatState)) FORCEINLINE NTSTATUS KeRestoreFloatingPointState(_In_ PKFLOATING_SAVE FloatSave)
Definition: ke.h:145
ULONG Dr7
Definition: nt_native.h:1439
ULONG Dr3
Definition: nt_native.h:1437
ULONG SecondLevelCacheSize
Definition: ke.h:317
USHORT MinorVersion
Definition: ke.h:313
#define UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:324
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:337
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define _CRT_DEPRECATE_TEXT(_Text)
Definition: crtdefs.h:181
#define _Acquires_lock_(lock)
Definition: no_sal2.h:677
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
long LONG
Definition: pedump.c:60
NTKERNELAPI KIRQL NTAPI KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:284
PVOID Used_Self
Definition: ke.h:302
PVOID KdVersionBlock
Definition: ke.h:320
#define _Releases_lock_(a)
Definition: btrfs_drv.h:208
ULONG SegEs
Definition: nt_native.h:1455
ULONG Esi
Definition: nt_native.h:1464
FORCEINLINE ULONG KeGetCurrentProcessorIndex(VOID)
Definition: ke.h:158
ULONG Dr1
Definition: nt_native.h:1435
ULONG SegCs
Definition: nt_native.h:1477
ULONG Edx
Definition: nt_native.h:1466
#define FORCEINLINE
Definition: ntbasedef.h:221
#define _Out_
Definition: no_sal2.h:323
Definition: ketypes.h:789
#define _At_(target, annos)
Definition: no_sal2.h:11
#define NTKERNELAPI
#define _Kernel_float_restored_
Definition: no_sal2.h:659
ULONG IrrActive
Definition: ke.h:49
$endif(_WDMDDK_) $if(_NTDDK_) typedef struct _NEON128
Definition: ke.h:202
ULONG EFlags
Definition: nt_native.h:1478
ULONG Dr2
Definition: nt_native.h:1436
ULONG Ebx
Definition: nt_native.h:1465
ULONG VdmAlert
Definition: ke.h:322
USHORT MajorVersion
Definition: ke.h:312
ULONG ContextFlags
Definition: nt_native.h:1426
#define KeRestoreFloatingPointState(x)
Definition: kmixer.h:33
struct _KGDTENTRY * GDT
Definition: ke.h:312
#define _Kernel_acquires_resource_(kind)
Definition: no_sal2.h:666
UCHAR RegisterArea[SIZE_OF_80387_REGISTERS]
Definition: nt_native.h:1390
_Kernel_requires_resource_not_held_(FloatState) _Kernel_acquires_resource_(FloatState)) FORCEINLINE NTSTATUS KeSaveFloatingPointState(_Out_ PKFLOATING_SAVE FloatSave)
Definition: ke.h:133
KAFFINITY SetMember
Definition: ke.h:57
LONG High1Time
Definition: ketypes.h:911
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
#define _Post_satisfies_(cond)
Definition: no_sal2.h:465
struct _KIDTENTRY * IDT
Definition: ke.h:311
#define _Notliteral_
Definition: no_sal2.h:315
ULONG HalReserved[16]
Definition: ke.h:318
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _IRQL_requires_(DISPATCH_LEVEL) NTHALAPI VOID FASTCALL KfReleaseSpinLock(_Inout_ PKSPIN_LOCK SpinLock
Definition: expool.c:1448
PPC_QUAL unsigned char __readfsbyte(const unsigned long Offset)
Definition: intrin_ppc.h:360
ULONG ContextSwitches
Definition: ke.h:299
#define _Inout_
Definition: no_sal2.h:244
* PFLOATING_SAVE_AREA
Definition: ke.h:254
_Always_(_Post_satisfies_(return<=0)) _Must_inspect_result_ _IRQL_requires_max_(DISPATCH_LEVEL) _Kernel_float_saved_ _At_(*FloatSave
unsigned char UCHAR
Definition: xmlstorage.h:181
#define _Kernel_float_saved_
Definition: no_sal2.h:660
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
#define KeSaveFloatingPointState(x)
Definition: kmixer.h:32
struct _CONTEXT CONTEXT
struct _KPCR * SelfPcr
Definition: ke.h:304
NT_TIB NtTib
Definition: ke.h:293
_Success_(1) _Kernel_float_restored_ _At_(*FloatSave
ULONG Eax
Definition: nt_native.h:1468
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
_IRQL_requires_max_(HIGH_LEVEL) _IRQL_saves_ FORCEINLINE KIRQL KeGetCurrentIrql(VOID)
Definition: ke.h:68
UCHAR SecondLevelCacheAssociativity
Definition: ke.h:308
#define _In_
Definition: no_sal2.h:204
LONG High2Time
Definition: ketypes.h:912
struct _KTSS * TSS
Definition: ke.h:54
#define HIGH_LEVEL
ULONG SegSs
Definition: nt_native.h:1480
unsigned short USHORT
Definition: pedump.c:61
UCHAR Spare0
Definition: ke.h:320
ULONG_PTR KAFFINITY
Definition: compat.h:75
UCHAR SpareUnused
Definition: ke.h:59
#define MAXIMUM_SUPPORTED_EXTENSION
Definition: x86context.h:35
NTKERNELAPI VOID NTAPI KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
UCHAR Number
Definition: ke.h:60
ULONG Dr6
Definition: nt_native.h:1438
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
struct _KPCR KPCR
PVOID TssCopy
Definition: ke.h:298
ULONG Dr0
Definition: nt_native.h:1434
VOID FASTCALL KefReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:259
NTKERNELAPI KIRQL NTAPI KeRaiseIrqlToDpcLevel(VOID)
Definition: pic.c:133
#define OUT
Definition: typedefs.h:40
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
unsigned int ULONG
Definition: retypes.h:1
VOID FASTCALL KefAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:237
#define _IRQL_raises_(irql)
Definition: no_sal2.h:648
struct _KPCR * PKPCR
ULONG KernelReserved[15]
Definition: ke.h:316
FORCEINLINE VOID KeMemoryBarrier(VOID)
Definition: ke.h:58
UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]
Definition: ke.h:282
FLOATING_SAVE_AREA
Definition: ke.h:254
#define SIZE_OF_80387_REGISTERS
ULONG IRR
Definition: ke.h:21
KAFFINITY SetMemberCopy
Definition: ke.h:300
#define _NTDDK_
ULONG Ebp
Definition: nt_native.h:1475
#define _Requires_lock_held_(a)
Definition: btrfs_drv.h:206
ULONG Edi
Definition: nt_native.h:1463
#define _IRQL_restores_
Definition: no_sal2.h:653
struct _KPRCB * Prcb
Definition: ke.h:19
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
FORCEINLINE VOID _KeQueryTickCount(OUT PLARGE_INTEGER CurrentCount)
Definition: ke.h:178