ReactOS  r75636
ntoskrnl.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4  * Use these to place a function in a specific section of the executable
5  */
6 #ifdef __GNUC__
7 #define INIT_SECTION __attribute__((section ("INIT")))
8 #define INIT_FUNCTION INIT_SECTION
9 #else
10 #define INIT_SECTION /* Done via alloc_text for MSC */
11 #define INIT_FUNCTION INIT_SECTION
12 #endif
13 
14 
15 
16 #ifdef _NTOSKRNL_
17 
18 #ifndef _ARM_
19 #define KeGetCurrentThread _KeGetCurrentThread
20 #define KeGetPreviousMode _KeGetPreviousMode
21 #endif
22 #undef PsGetCurrentProcess
23 #define PsGetCurrentProcess _PsGetCurrentProcess
24 
25 #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
26 
27 //
28 // We are very lazy on ARM -- we just import intrinsics
29 // Question: Why wasn't this done for x86 too? (see fastintrlck.asm)
30 //
31 #define InterlockedDecrement _InterlockedDecrement
32 #define InterlockedDecrement16 _InterlockedDecrement16
33 #define InterlockedIncrement _InterlockedIncrement
34 #define InterlockedIncrement16 _InterlockedIncrement16
35 #define InterlockedCompareExchange _InterlockedCompareExchange
36 #define InterlockedCompareExchange16 _InterlockedCompareExchange16
37 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
38 #define InterlockedExchange _InterlockedExchange
39 #define InterlockedExchangeAdd _InterlockedExchangeAdd
40 #define InterlockedOr _InterlockedOr
41 #define InterlockedAnd _InterlockedAnd
42 
43 //
44 // Use inlined versions of fast/guarded mutex routines
45 //
46 #define ExEnterCriticalRegionAndAcquireFastMutexUnsafe _ExEnterCriticalRegionAndAcquireFastMutexUnsafe
47 #define ExReleaseFastMutexUnsafeAndLeaveCriticalRegion _ExReleaseFastMutexUnsafeAndLeaveCriticalRegion
48 #define ExAcquireFastMutex _ExAcquireFastMutex
49 #define ExReleaseFastMutex _ExReleaseFastMutex
50 #define ExAcquireFastMutexUnsafe _ExAcquireFastMutexUnsafe
51 #define ExReleaseFastMutexUnsafe _ExReleaseFastMutexUnsafe
52 #define ExTryToAcquireFastMutex _ExTryToAcquireFastMutex
53 
54 #define KeInitializeGuardedMutex _KeInitializeGuardedMutex
55 #define KeAcquireGuardedMutex _KeAcquireGuardedMutex
56 #define KeReleaseGuardedMutex _KeReleaseGuardedMutex
57 #define KeAcquireGuardedMutexUnsafe _KeAcquireGuardedMutexUnsafe
58 #define KeReleaseGuardedMutexUnsafe _KeReleaseGuardedMutexUnsafe
59 #define KeTryToAcquireGuardedMutex _KeTryToAcquireGuardedMutex
60 
61 #include "tag.h"
62 #include "ke.h"
63 #include "ob.h"
64 #include "mm.h"
65 #include "ex.h"
66 #include "cm.h"
67 #include "ps.h"
68 #include "cc.h"
69 #include "io.h"
70 #include "po.h"
71 #include "se.h"
72 #include "ldr.h"
73 #ifndef _WINKD_
74 #include "kd.h"
75 #else
76 #include "kd64.h"
77 #endif
78 #include "fsrtl.h"
79 #include "lpc.h"
80 #include "rtl.h"
81 #ifdef KDBG
82 #include <kdbg/kdb.h>
83 #endif
84 #include "dbgk.h"
85 #include "spinlock.h"
86 #include "test.h"
87 #include "inbv.h"
88 #include "vdm.h"
89 #include "hal.h"
90 #include "hdl.h"
91 #include "arch/intrin_i.h"
92 
93 /*
94  * generic information class probing code
95  */
96 
97 #define ICIF_QUERY 0x1
98 #define ICIF_SET 0x2
99 #define ICIF_QUERY_SIZE_VARIABLE 0x4
100 #define ICIF_SET_SIZE_VARIABLE 0x8
101 #define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
102 
103 typedef struct _INFORMATION_CLASS_INFO
104 {
105  ULONG RequiredSizeQUERY;
106  ULONG RequiredSizeSET;
107  ULONG AlignmentSET;
108  ULONG AlignmentQUERY;
109  ULONG Flags;
110 } INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
111 
112 #define ICI_SQ_SAME(Type, Alignment, Flags) \
113  { Type, Type, Alignment, Alignment, Flags }
114 
115 #define ICI_SQ(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
116  { TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags }
117 
118 //
119 // TEMPORARY
120 //
121 #define IQS_SAME(Type, Alignment, Flags) \
122  { sizeof(Type), sizeof(Type), sizeof(Alignment), sizeof(Alignment), Flags }
123 
124 #define IQS(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
125  { sizeof(TypeQuery), sizeof(TypeSet), sizeof(AlignmentQuery), sizeof(AlignmentSet), Flags }
126 
127 /*
128  * Use IsPointerOffset to test whether a pointer should be interpreted as an offset
129  * or as a pointer
130  */
131 #if defined(_X86_) || defined(_M_AMD64) || defined(_MIPS_) || defined(_PPC_) || defined(_ARM_)
132 
133 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
134 #define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
135 
136 #elif defined(_IA64_)
137 
138 /* on Itanium if the 24 most significant bits are set, we're not dealing with
139  offsets anymore. */
140 #define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
141 
142 #else
143 #error IsPointerOffset() needs to be defined for this architecture
144 #endif
145 
146 #endif
147 
148 #ifdef _M_IX86
149 C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
150 
153 C_ASSERT(FIELD_OFFSET(KTHREAD, SystemAffinityActive) == FIELD_OFFSET(KTHREAD, WaitBlock) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
155 C_ASSERT(FIELD_OFFSET(KTHREAD, ApcQueueable) == FIELD_OFFSET(KTHREAD, ApcState.UserApcPending) + 1);
156 C_ASSERT(FIELD_OFFSET(KTHREAD, ApcQueueable) == 0x3F);
157 C_ASSERT(FIELD_OFFSET(KTHREAD, NextProcessor) == 0x40);
158 C_ASSERT(FIELD_OFFSET(KTHREAD, DeferredProcessor) == 0x41);
159 C_ASSERT(FIELD_OFFSET(KTHREAD, AdjustReason) == 0x42);
162 C_ASSERT(FIELD_OFFSET(KTHREAD, SwapBusy) == 0x05D);
164 C_ASSERT(FIELD_OFFSET(KTHREAD, Timer) == 0x078);
165 C_ASSERT(FIELD_OFFSET(KTHREAD, ThreadFlags) == 0x0A0);
166 C_ASSERT(FIELD_OFFSET(KTHREAD, WaitBlock) == 0x0A8);
167 C_ASSERT(FIELD_OFFSET(KTHREAD, WaitBlockFill0) == 0x0A8);
168 C_ASSERT(FIELD_OFFSET(KTHREAD, QueueListEntry) == 0x108);
171 C_ASSERT(FIELD_OFFSET(KTHREAD, ResourceIndex) == FIELD_OFFSET(KTHREAD, WaitBlock) + 2*sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
172 C_ASSERT(FIELD_OFFSET(KTHREAD, LargeStack) == FIELD_OFFSET(KTHREAD, WaitBlock) + 3*sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
176 C_ASSERT(FIELD_OFFSET(KTHREAD, FreezeCount) == FIELD_OFFSET(KTHREAD, SavedApcState.UserApcPending) + 1);
177 C_ASSERT(FIELD_OFFSET(KTHREAD, Quantum) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareByte0));
178 C_ASSERT(FIELD_OFFSET(KTHREAD, QuantumReset) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareByte1));
179 C_ASSERT(FIELD_OFFSET(KTHREAD, KernelTime) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareLong0));
180 C_ASSERT(FIELD_OFFSET(KTHREAD, TlsArray) == FIELD_OFFSET(KTHREAD, SuspendApc.SystemArgument1));
181 C_ASSERT(FIELD_OFFSET(KTHREAD, LegoData) == FIELD_OFFSET(KTHREAD, SuspendApc.SystemArgument2));
182 C_ASSERT(FIELD_OFFSET(KTHREAD, PowerState) == FIELD_OFFSET(KTHREAD, SuspendApc.Inserted) + 1);
183 C_ASSERT(sizeof(KTHREAD) == 0x1B8);
184 
186 
187 C_ASSERT(FIELD_OFFSET(KPCR, NtTib.ExceptionList) == KPCR_EXCEPTION_LIST);
188 C_ASSERT(FIELD_OFFSET(KPCR, SelfPcr) == KPCR_SELF);
214 
215 /* Platform specific checks */
219 C_ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
220 #endif
#define KTHREAD_CALLBACK_STACK
Definition: asm.h:109
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:452
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
#define KPCR_CURRENT_THREAD
Definition: asm.h:175
#define KPCR_IRR
Definition: asm.h:163
KPRCB PrcbData[MAXIMUM_PROCESSORS]
Definition: kiinit.c:27
#define KPCR_PRCB_DPC_STACK
Definition: asm.h:196
#define KPCR_NPX_THREAD
Definition: asm.h:182
#define SIZEOF_FX_SAVE_AREA
Definition: asm.h:29
#define KTHREAD_TRAP_FRAME
Definition: asm.h:108
#define KTHREAD_INITIAL_STACK
Definition: asm.h:50
Definition: ke.h:280
#define KTSS_IOMAPBASE
Definition: asm.h:80
#define KPCR_PRCB_DEFERRED_READY_LIST_HEAD
Definition: asm.h:205
_Out_ PKIRQL Irql
Definition: csq.h:179
#define KPCR_PRCB_PRCB_LOCK
Definition: asm.h:181
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define KPCR_PRCB_DPC_INTERRUPT_REQUESTED
Definition: asm.h:199
#define KPCR_IDR
Definition: asm.h:165
#define KPCR_SELF
Definition: asm.h:64
#define KTHREAD_APCSTATE_PROCESS
Definition: asm.h:92
#define KTHREAD_KERNEL_STACK
Definition: asm.h:90
#define KPCR_SYSTEM_CALLS
Definition: asm.h:193
Definition: ketypes.h:787
#define KPCR_EXCEPTION_LIST
Definition: asm.h:153
#define KPCR_PRCB_DPC_COUNT
Definition: asm.h:195
#define KPROCESS_IOPM_OFFSET
Definition: asm.h:124
#define KPCR_PRCB_TIMER_REQUEST
Definition: asm.h:202
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define KPCR_PRCB_DATA
Definition: asm.h:174
SERVICE_TABLE_ENTRYW ServiceTable[]
Definition: service_main.c:23
#define KPCR_PRCB_DPC_REQUEST_RATE
Definition: asm.h:198
#define KTHREAD_SERVICE_TABLE
Definition: asm.h:103
#define KTHREAD_TEB
Definition: asm.h:89
#define KPCR_PRCB_QUANTUM_END
Definition: asm.h:203
#define KPCR_PRCB_POWER_STATE_IDLE_FUNCTION
Definition: asm.h:206
#define KPCR_PRCB_IDLE_SCHEDULE
Definition: asm.h:204
#define KPCR_PRCB_MAXIMUM_DPC_QUEUE_DEPTH
Definition: asm.h:197
#define KTHREAD_NPX_STATE
Definition: asm.h:97
#define KPCR_PRCB_DPC_LAST_COUNT
Definition: asm.h:201
#define KTSS_ESP0
Definition: asm.h:61
#define KPROCESS_DIRECTORY_TABLE_BASE
Definition: asm.h:119
#define KPCR_IRQL
Definition: asm.h:162
#define C_ASSERT(e)
Definition: ntstrsafe.h:22
#define KPROCESS_LDT_DESCRIPTOR0
Definition: asm.h:120
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1411
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define KPCR_PRCB_DPC_ROUTINE_ACTIVE
Definition: asm.h:200
#define KTHREAD_PREVIOUS_MODE
Definition: asm.h:104
unsigned int ULONG
Definition: retypes.h:1
#define KPCR_PRCB_DPC_QUEUE_DEPTH
Definition: asm.h:194
#define KPCR_PRCB_NEXT_THREAD
Definition: asm.h:176