ReactOS  r75907
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 CLOCK_LEVEL 13
11 #define IPI_LEVEL 14
12 #define DRS_LEVEL 14
13 #define POWER_LEVEL 14
14 #define PROFILE_LEVEL 15
15 #define HIGH_LEVEL 15
16 
17 #define KI_USER_SHARED_DATA 0xFFFFF78000000000ULL
18 #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
19 #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
20 #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
21 #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
22 
23 #define PAGE_SIZE 0x1000
24 #define PAGE_SHIFT 12L
25 
26 #define EFLAG_SIGN 0x8000
27 #define EFLAG_ZERO 0x4000
28 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
29 
30 typedef struct _KFLOATING_SAVE
31 {
32  ULONG Dummy;
34 
36 
37 #define KeQueryInterruptTime() \
38  (*(volatile ULONG64*)SharedInterruptTime)
39 
40 #define KeQuerySystemTime(CurrentCount) \
41  *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedSystemTime
42 
43 #define KeQueryTickCount(CurrentCount) \
44  *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedTickCount
45 
46 #define KeGetDcacheFillSize() 1L
47 
48 #define YieldProcessor _mm_pause
49 #define MemoryBarrier __faststorefence
50 #define FastFence __faststorefence
51 #define LoadFence _mm_lfence
52 #define MemoryFence _mm_mfence
53 #define StoreFence _mm_sfence
54 #define LFENCE_ACQUIRE() LoadFence()
55 
57 VOID
59  VOID)
60 {
61  // FIXME: Do we really need lfence after the __faststorefence ?
62  FastFence();
64 }
65 
66 #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
67 
71 KIRQL
73 {
74  return (KIRQL)__readcr8();
75 }
76 
79 VOID
82 {
83  //ASSERT((KIRQL)__readcr8() >= NewIrql);
84  __writecr8(NewIrql);
85 }
86 
91 KIRQL
94 {
95  KIRQL OldIrql;
96 
97  OldIrql = (KIRQL)__readcr8();
98  //ASSERT(OldIrql <= NewIrql);
99  __writecr8(NewIrql);
100  return OldIrql;
101 }
102 #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
103 
108 KIRQL
110  VOID)
111 {
112  return KfRaiseIrql(DISPATCH_LEVEL);
113 }
114 
116 KIRQL
118 {
119  return KfRaiseIrql(12); // SYNCH_LEVEL = IPI_LEVEL - 2
120 }
121 
123 PKTHREAD
125 {
126  return (struct _KTHREAD *)__readgsqword(0x188);
127 }
128 
129 _Always_(_Post_satisfies_(return<=0))
135 NTSTATUS
137  _Out_ PKFLOATING_SAVE FloatSave)
138 {
139  UNREFERENCED_PARAMETER(FloatSave);
140  return STATUS_SUCCESS;
141 }
142 
143 _Success_(1)
147 NTSTATUS
149  _In_ PKFLOATING_SAVE FloatSave)
150 {
151  UNREFERENCED_PARAMETER(FloatSave);
152  return STATUS_SUCCESS;
153 }
154 
155 /* VOID
156  * KeFlushIoBuffers(
157  * IN PMDL Mdl,
158  * IN BOOLEAN ReadOperation,
159  * IN BOOLEAN DmaOperation)
160  */
161 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
162 
163 /* x86 and x64 performs a 0x2C interrupt */
164 #define DbgRaiseAssertionFailure __int2c
165 
166 $endif /* _WDMDDK_ */
168 
169 #define PAUSE_PROCESSOR YieldProcessor();
170 
171 #define KERNEL_STACK_SIZE 0x6000
172 #define KERNEL_LARGE_STACK_SIZE 0x12000
173 #define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
174 
175 #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
176 
177 #define EXCEPTION_READ_FAULT 0
178 #define EXCEPTION_WRITE_FAULT 1
179 #define EXCEPTION_EXECUTE_FAULT 8
180 
181 #if !defined(RC_INVOKED)
182 
183 #define CONTEXT_AMD64 0x100000
184 
185 #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
186 #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
187 #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
188 #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
189 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
190 
191 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
192 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
193 
194 #define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
195 
196 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
197 #define CONTEXT_SERVICE_ACTIVE 0x10000000
198 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
199 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
200 
201 #endif /* !defined(RC_INVOKED) */
202 
203 #define INITIAL_MXCSR 0x1f80
204 #define INITIAL_FPCSR 0x027f
205 
206 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
207  ULONG64 P1Home;
208  ULONG64 P2Home;
209  ULONG64 P3Home;
210  ULONG64 P4Home;
211  ULONG64 P5Home;
212  ULONG64 P6Home;
213  ULONG ContextFlags;
214  ULONG MxCsr;
215  USHORT SegCs;
216  USHORT SegDs;
217  USHORT SegEs;
218  USHORT SegFs;
219  USHORT SegGs;
220  USHORT SegSs;
221  ULONG EFlags;
222  ULONG64 Dr0;
223  ULONG64 Dr1;
224  ULONG64 Dr2;
225  ULONG64 Dr3;
226  ULONG64 Dr6;
227  ULONG64 Dr7;
228  ULONG64 Rax;
229  ULONG64 Rcx;
230  ULONG64 Rdx;
231  ULONG64 Rbx;
232  ULONG64 Rsp;
233  ULONG64 Rbp;
234  ULONG64 Rsi;
235  ULONG64 Rdi;
236  ULONG64 R8;
237  ULONG64 R9;
238  ULONG64 R10;
239  ULONG64 R11;
240  ULONG64 R12;
241  ULONG64 R13;
242  ULONG64 R14;
243  ULONG64 R15;
244  ULONG64 Rip;
245  union {
246  XMM_SAVE_AREA32 FltSave;
247  struct {
248  M128A Header[2];
249  M128A Legacy[8];
250  M128A Xmm0;
251  M128A Xmm1;
252  M128A Xmm2;
253  M128A Xmm3;
254  M128A Xmm4;
255  M128A Xmm5;
256  M128A Xmm6;
257  M128A Xmm7;
258  M128A Xmm8;
259  M128A Xmm9;
260  M128A Xmm10;
261  M128A Xmm11;
262  M128A Xmm12;
263  M128A Xmm13;
264  M128A Xmm14;
265  M128A Xmm15;
266  } DUMMYSTRUCTNAME;
267  } DUMMYUNIONNAME;
268  M128A VectorRegister[26];
269  ULONG64 VectorControl;
270  ULONG64 DebugControl;
271  ULONG64 LastBranchToRip;
272  ULONG64 LastBranchFromRip;
273  ULONG64 LastExceptionToRip;
274  ULONG64 LastExceptionFromRip;
276 
277 #define PCR_MINOR_VERSION 1
278 #define PCR_MAJOR_VERSION 1
279 
280 typedef struct _KPCR
281 {
282  _ANONYMOUS_UNION union
283  {
285  _ANONYMOUS_STRUCT struct
286  {
288  struct _KTSS64 *TssBase;
290  struct _KPCR *Self;
294  };
295  };
314 } KPCR, *PKPCR;
315 
317 PKPCR
319 {
320  return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
321 }
322 
324 ULONG
326 {
327  return (ULONG)__readgsword(0x184);
328 }
329 
330 $endif /* _NTDDK_ */
DWORD *typedef PVOID
Definition: winlogon.h:52
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
PKSPIN_LOCK_QUEUE LockArray
Definition: ke.h:292
struct _KPCR * Self
Definition: ke.h:290
KIRQL Irql
Definition: ke.h:298
struct _KFLOATING_SAVE KFLOATING_SAVE
#define _Must_inspect_result_
Definition: no_sal2.h:314
ULONG StallScaleFactor
Definition: ke.h:305
__INTRIN_INLINE unsigned long __readcr8(void)
Definition: intrin_x86.h:1615
#define DISPATCH_LEVEL
#define _Kernel_releases_resource_(kind)
Definition: no_sal2.h:663
PVOID Unused3
Definition: ke.h:312
UCHAR Fill0
Definition: ke.h:301
ULONG64 UserRsp
Definition: ke.h:289
struct _KFLOATING_SAVE * PKFLOATING_SAVE
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:315
M128A
Definition: ketypes.h:903
#define _IRQL_saves_
Definition: no_sal2.h:655
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define _ANONYMOUS_UNION
Definition: ntbasedef.h:30
$if(_WDMDDK_) typedef struct _KFLOATING_SAVE
Definition: ke.h:1
FORCEINLINE KIRQL KeRaiseIrqlToSynchLevel(VOID)
Definition: ke.h:117
#define _WDMDDK_
Definition: wdm.template.h:26
Definition: ke.h:280
union _KIDTENTRY64 * IdtBase
Definition: ke.h:296
union _KGDTENTRY64 * GdtBase
Definition: ke.h:287
#define DECLSPEC_ALIGN(x)
Definition: ntbasedef.h:249
#define DUMMYUNIONNAME
Definition: ntbasedef.h:32
__INTRIN_INLINE void __writecr8(unsigned int Data)
Definition: intrin_x86.h:1582
_Kernel_requires_resource_held_(FloatState) _Kernel_releases_resource_(FloatState)) FORCEINLINE NTSTATUS KeRestoreFloatingPointState(_In_ PKFLOATING_SAVE FloatSave)
Definition: ke.h:145
ULONG SecondLevelCacheSize
Definition: ke.h:308
ULONG Dummy
Definition: ke.h:24
USHORT MinorVersion
Definition: ke.h:304
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:325
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define LFENCE_ACQUIRE()
Definition: ke.h:54
Definition: Header.h:8
NTKERNELAPI KIRQL NTAPI KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:284
PVOID Used_Self
Definition: ke.h:293
PVOID KdVersionBlock
Definition: ke.h:311
XSAVE_FORMAT * PXMM_SAVE_AREA32
Definition: ke.h:35
uint64_t ULONG64
Definition: typedefs.h:66
#define FORCEINLINE
Definition: ntbasedef.h:213
#define _Out_
Definition: no_sal2.h:323
#define _At_(target, annos)
Definition: no_sal2.h:11
#define _Kernel_float_restored_
Definition: no_sal2.h:659
$endif(_WDMDDK_) $if(_NTDDK_) typedef struct _NEON128
Definition: ke.h:202
USHORT MajorVersion
Definition: ke.h:303
#define KeRestoreFloatingPointState(x)
Definition: kmixer.h:33
#define _Kernel_acquires_resource_(kind)
Definition: no_sal2.h:666
struct _KPRCB * CurrentPrcb
Definition: ke.h:291
#define HIGH_LEVEL
_Kernel_requires_resource_not_held_(FloatState) _Kernel_acquires_resource_(FloatState)) FORCEINLINE NTSTATUS KeSaveFloatingPointState(_Out_ PKFLOATING_SAVE FloatSave)
Definition: ke.h:133
#define _Notliteral_
Definition: no_sal2.h:315
ULONG HalReserved[16]
Definition: ke.h:309
#define KeLowerIrql(a)
Definition: ke.h:79
_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
#define KeSaveFloatingPointState(x)
Definition: kmixer.h:32
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
PVOID Unused1[3]
Definition: ke.h:306
struct _CONTEXT CONTEXT
NT_TIB NtTib
Definition: ke.h:284
_Success_(1) _Kernel_float_restored_ _At_(*FloatSave
struct _KTSS64 * TssBase
Definition: ke.h:288
UCHAR ObsoleteNumber
Definition: ke.h:300
#define _ANONYMOUS_STRUCT
Definition: ntbasedef.h:56
_IRQL_requires_max_(HIGH_LEVEL) _IRQL_saves_ FORCEINLINE KIRQL KeGetCurrentIrql(VOID)
Definition: ke.h:68
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318
UCHAR SecondLevelCacheAssociativity
Definition: ke.h:299
#define _In_
Definition: no_sal2.h:204
ULONG64 Unused[2]
Definition: ke.h:297
LONG NTSTATUS
Definition: DriverTester.h:11
unsigned short USHORT
Definition: pedump.c:61
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
struct _KPCR KPCR
#define FastFence
Definition: ke.h:50
#define _Post_satisfies_(a)
Definition: btrfs_drv.h:167
XSAVE_FORMAT
Definition: ketypes.h:929
ULONG Unused2
Definition: ke.h:310
ULONG Unused0[3]
Definition: ke.h:302
XSAVE_FORMAT XMM_SAVE_AREA32
Definition: ke.h:35
NTKERNELAPI KIRQL NTAPI KeRaiseIrqlToDpcLevel(VOID)
Definition: pic.c:133
ULONG PcrAlign1[24]
Definition: ke.h:313
unsigned int ULONG
Definition: retypes.h:1
#define _IRQL_raises_(irql)
Definition: no_sal2.h:648
struct _KPCR * PKPCR
ULONG KernelReserved[15]
Definition: ke.h:307
FORCEINLINE VOID KeMemoryBarrier(VOID)
Definition: ke.h:58
#define DUMMYSTRUCTNAME
Definition: ntbasedef.h:58
#define _NTDDK_
#define _IRQL_restores_
Definition: no_sal2.h:653
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114