[HEADERS]
[reactos.git] / reactos / ntoskrnl / include / internal / ntoskrnl.h
1 #pragma once
2
3 /*
4 * Use these to place a function in a specific section of the executable
5 */
6 #define PLACE_IN_SECTION(s) __attribute__((section (s)))
7 #ifdef __GNUC__
8 #define INIT_FUNCTION PLACE_IN_SECTION("INIT")
9 #define PAGE_LOCKED_FUNCTION PLACE_IN_SECTION("pagelk")
10 #define PAGE_UNLOCKED_FUNCTION PLACE_IN_SECTION("pagepo")
11 #else
12 #define INIT_FUNCTION
13 #define PAGE_LOCKED_FUNCTION
14 #define PAGE_UNLOCKED_FUNCTION
15 #endif
16
17 #ifdef _NTOSKRNL_
18
19 #ifndef _ARM_
20 #define KeGetCurrentThread _KeGetCurrentThread
21 #define KeGetPreviousMode _KeGetPreviousMode
22 #endif
23 #undef PsGetCurrentProcess
24 #define PsGetCurrentProcess _PsGetCurrentProcess
25
26 #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
27
28 //
29 // We are very lazy on ARM -- we just import intrinsics
30 // Question: Why wasn't this done for x86 too? (see fastintrlck.asm)
31 //
32 #define InterlockedDecrement _InterlockedDecrement
33 #define InterlockedDecrement16 _InterlockedDecrement16
34 #define InterlockedIncrement _InterlockedIncrement
35 #define InterlockedIncrement16 _InterlockedIncrement16
36 #define InterlockedCompareExchange _InterlockedCompareExchange
37 #define InterlockedCompareExchange16 _InterlockedCompareExchange16
38 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
39 #define InterlockedExchange _InterlockedExchange
40 #define InterlockedExchangeAdd _InterlockedExchangeAdd
41 #define InterlockedOr _InterlockedOr
42 #define InterlockedAnd _InterlockedAnd
43
44 //
45 // Use inlined versions of fast/guarded mutex routines
46 //
47 #define ExEnterCriticalRegionAndAcquireFastMutexUnsafe _ExEnterCriticalRegionAndAcquireFastMutexUnsafe
48 #define ExReleaseFastMutexUnsafeAndLeaveCriticalRegion _ExReleaseFastMutexUnsafeAndLeaveCriticalRegion
49 #define ExAcquireFastMutex _ExAcquireFastMutex
50 #define ExReleaseFastMutex _ExReleaseFastMutex
51 #define ExAcquireFastMutexUnsafe _ExAcquireFastMutexUnsafe
52 #define ExReleaseFastMutexUnsafe _ExReleaseFastMutexUnsafe
53 #define ExTryToAcquireFastMutex _ExTryToAcquireFastMutex
54
55 #define KeInitializeGuardedMutex _KeInitializeGuardedMutex
56 #define KeAcquireGuardedMutex _KeAcquireGuardedMutex
57 #define KeReleaseGuardedMutex _KeReleaseGuardedMutex
58 #define KeAcquireGuardedMutexUnsafe _KeAcquireGuardedMutexUnsafe
59 #define KeReleaseGuardedMutexUnsafe _KeReleaseGuardedMutexUnsafe
60 #define KeTryToAcquireGuardedMutex _KeTryToAcquireGuardedMutex
61
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 "tag.h"
87 #include "test.h"
88 #include "inbv.h"
89 #include "vdm.h"
90 #include "hal.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 #if defined (_M_IX86) || defined(_M_AMD64)
149 C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
150 C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
151 C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
152 C_ASSERT(FIELD_OFFSET(KTHREAD, KernelStack) == KTHREAD_KERNEL_STACK);
153 C_ASSERT(FIELD_OFFSET(KTHREAD, NpxState) == KTHREAD_NPX_STATE);
154 C_ASSERT(FIELD_OFFSET(KTHREAD, ServiceTable) == KTHREAD_SERVICE_TABLE);
155 C_ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
156 C_ASSERT(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
157 C_ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
158 C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
159 C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
160 #endif
161
162 #ifdef _M_IX86
163 C_ASSERT(FIELD_OFFSET(KPCR, NtTib.ExceptionList) == KPCR_EXCEPTION_LIST);
164 C_ASSERT(FIELD_OFFSET(KPCR, SelfPcr) == KPCR_SELF);
165 C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
166 C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
167 C_ASSERT(FIELD_OFFSET(KPCR, Irql) == KPCR_IRQL);
168 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) == KPCR_CURRENT_THREAD);
169 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NextThread) == KPCR_PRCB_NEXT_THREAD);
170 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) == KPCR_NPX_THREAD);
171 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) == KPCR_PRCB_DATA);
172 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, KeSystemCalls) == KPCR_SYSTEM_CALLS);
173 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + FIELD_OFFSET(KDPC_DATA, DpcQueueDepth) == KPCR_PRCB_DPC_QUEUE_DEPTH);
174 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + 16 == KPCR_PRCB_DPC_COUNT);
175 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
176 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
177 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, MaximumDpcQueueDepth) == KPCR_PRCB_MAXIMUM_DPC_QUEUE_DEPTH);
178 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRequestRate) == KPCR_PRCB_DPC_REQUEST_RATE);
179 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcInterruptRequested) == KPCR_PRCB_DPC_INTERRUPT_REQUESTED);
180 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRoutineActive) == KPCR_PRCB_DPC_ROUTINE_ACTIVE);
181 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcLastCount) == KPCR_PRCB_DPC_LAST_COUNT);
182 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
183 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, QuantumEnd) == KPCR_PRCB_QUANTUM_END);
184 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DeferredReadyListHead) == KPCR_PRCB_DEFERRED_READY_LIST_HEAD);
185 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PowerState) == KPCR_PRCB_POWER_STATE_IDLE_FUNCTION);
186 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PrcbLock) == KPCR_PRCB_PRCB_LOCK);
187 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
188 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, IdleSchedule) == KPCR_PRCB_IDLE_SCHEDULE);
189 C_ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
190
191 /* Platform specific checks */
192 C_ASSERT(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
193 C_ASSERT(FIELD_OFFSET(KPROCESS, LdtDescriptor) == KPROCESS_LDT_DESCRIPTOR0);
194 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, SavedExceptionStack) == TF_SAVED_EXCEPTION_STACK);
195 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, regs) == TF_REGS);
196 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, orig_ebp) == TF_ORIG_EBP);
197 C_ASSERT(FIELD_OFFSET(KTSS, Esp0) == KTSS_ESP0);
198 C_ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
199 #endif