Merge from amd64-branch:
[reactos.git] / reactos / ntoskrnl / include / internal / ntoskrnl.h
1 #ifndef __INCLUDE_INTERNAL_NTOSKRNL_H
2 #define __INCLUDE_INTERNAL_NTOSKRNL_H
3
4 /*
5 * Use these to place a function in a specific section of the executable
6 */
7 #define PLACE_IN_SECTION(s) __attribute__((section (s)))
8 #ifdef __GNUC__
9 #define INIT_FUNCTION PLACE_IN_SECTION("INIT")
10 #define PAGE_LOCKED_FUNCTION PLACE_IN_SECTION("pagelk")
11 #define PAGE_UNLOCKED_FUNCTION PLACE_IN_SECTION("pagepo")
12 #else
13 #define INIT_FUNCTION
14 #define PAGE_LOCKED_FUNCTION
15 #define PAGE_UNLOCKED_FUNCTION
16 #endif
17
18 #ifdef _NTOSKRNL_
19
20 #ifndef _ARM_
21 #define KeGetCurrentThread _KeGetCurrentThread
22 #define KeGetPreviousMode _KeGetPreviousMode
23 #endif
24 #undef PsGetCurrentProcess
25 #define PsGetCurrentProcess _PsGetCurrentProcess
26
27 #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
28
29 //
30 // We are very lazy on ARM -- we just import intrinsics
31 // Question: Why wasn't this done for x86 too? (see fastintrlck.asm)
32 //
33 #define InterlockedDecrement _InterlockedDecrement
34 #define InterlockedDecrement16 _InterlockedDecrement16
35 #define InterlockedIncrement _InterlockedIncrement
36 #define InterlockedIncrement16 _InterlockedIncrement16
37 #define InterlockedCompareExchange _InterlockedCompareExchange
38 #define InterlockedCompareExchange16 _InterlockedCompareExchange16
39 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
40 #define InterlockedExchange _InterlockedExchange
41 #define InterlockedExchangeAdd _InterlockedExchangeAdd
42 #define InterlockedOr _InterlockedOr
43 #define InterlockedAnd _InterlockedAnd
44
45 //
46 // Use inlined versions of fast/guarded mutex routines
47 //
48 #define ExEnterCriticalRegionAndAcquireFastMutexUnsafe _ExEnterCriticalRegionAndAcquireFastMutexUnsafe
49 #define ExReleaseFastMutexUnsafeAndLeaveCriticalRegion _ExReleaseFastMutexUnsafeAndLeaveCriticalRegion
50 #define ExAcquireFastMutex _ExAcquireFastMutex
51 #define ExReleaseFastMutex _ExReleaseFastMutex
52 #define ExAcquireFastMutexUnsafe _ExAcquireFastMutexUnsafe
53 #define ExReleaseFastMutexUnsafe _ExReleaseFastMutexUnsafe
54 #define ExTryToAcquireFastMutex _ExTryToAcquireFastMutex
55
56 #define KeInitializeGuardedMutex _KeInitializeGuardedMutex
57 #define KeAcquireGuardedMutex _KeAcquireGuardedMutex
58 #define KeReleaseGuardedMutex _KeReleaseGuardedMutex
59 #define KeAcquireGuardedMutexUnsafe _KeAcquireGuardedMutexUnsafe
60 #define KeReleaseGuardedMutexUnsafe _KeReleaseGuardedMutexUnsafe
61 #define KeTryToAcquireGuardedMutex _KeTryToAcquireGuardedMutex
62
63 #include "ke.h"
64 #include "ob.h"
65 #include "mm.h"
66 #include "ex.h"
67 #include "cm.h"
68 #include "ps.h"
69 #include "cc.h"
70 #include "io.h"
71 #include "po.h"
72 #include "se.h"
73 #include "ldr.h"
74 #ifndef _WINKD_
75 #include "kd.h"
76 #else
77 #include "kd64.h"
78 #endif
79 #include "fsrtl.h"
80 #include "lpc.h"
81 #include "rtl.h"
82 #ifdef KDBG
83 #include "../kdbg/kdb.h"
84 #endif
85 #include "dbgk.h"
86 #include "spinlock.h"
87 #include "tag.h"
88 #include "test.h"
89 #include "inbv.h"
90 #include "vdm.h"
91 #include "hal.h"
92 #include "arch/intrin_i.h"
93
94 /*
95 * generic information class probing code
96 */
97
98 #define ICIF_QUERY 0x1
99 #define ICIF_SET 0x2
100 #define ICIF_QUERY_SIZE_VARIABLE 0x4
101 #define ICIF_SET_SIZE_VARIABLE 0x8
102 #define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
103
104 typedef struct _INFORMATION_CLASS_INFO
105 {
106 ULONG RequiredSizeQUERY;
107 ULONG RequiredSizeSET;
108 ULONG AlignmentSET;
109 ULONG AlignmentQUERY;
110 ULONG Flags;
111 } INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
112
113 #define ICI_SQ_SAME(Type, Alignment, Flags) \
114 { Type, Type, Alignment, Alignment, Flags }
115
116 #define ICI_SQ(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
117 { TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags }
118
119 //
120 // TEMPORARY
121 //
122 #define IQS_SAME(Type, Alignment, Flags) \
123 { sizeof(Type), sizeof(Type), sizeof(Alignment), sizeof(Alignment), Flags }
124
125 #define IQS(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
126 { sizeof(TypeQuery), sizeof(TypeSet), sizeof(AlignmentQuery), sizeof(AlignmentSet), Flags }
127
128 /*
129 * Use IsPointerOffset to test whether a pointer should be interpreted as an offset
130 * or as a pointer
131 */
132 #if defined(_X86_) || defined(_M_AMD64) || defined(_MIPS_) || defined(_PPC_) || defined(_ARM_)
133
134 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
135 #define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
136
137 #elif defined(_IA64_)
138
139 /* on Itanium if the 24 most significant bits are set, we're not dealing with
140 offsets anymore. */
141 #define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
142
143 #else
144 #error IsPointerOffset() needs to be defined for this architecture
145 #endif
146
147 #endif
148
149 #if defined (_M_IX86) || defined(_M_AMD64)
150 C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
151 C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
152 C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
153 C_ASSERT(FIELD_OFFSET(KTHREAD, KernelStack) == KTHREAD_KERNEL_STACK);
154 C_ASSERT(FIELD_OFFSET(KTHREAD, NpxState) == KTHREAD_NPX_STATE);
155 C_ASSERT(FIELD_OFFSET(KTHREAD, ServiceTable) == KTHREAD_SERVICE_TABLE);
156 C_ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
157 C_ASSERT(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
158 C_ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
159 C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
160 C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
161 #endif
162
163 #ifdef _M_IX86
164 C_ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
165 C_ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
166 C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
167 C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
168 C_ASSERT(FIELD_OFFSET(KPCR, Irql) == KPCR_IRQL);
169 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) == KPCR_CURRENT_THREAD);
170 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NextThread) == KPCR_PRCB_NEXT_THREAD);
171 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) == KPCR_NPX_THREAD);
172 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) == KPCR_PRCB_DATA);
173 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, KeSystemCalls) == KPCR_SYSTEM_CALLS);
174 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + FIELD_OFFSET(KDPC_DATA, DpcQueueDepth) == KPCR_PRCB_DPC_QUEUE_DEPTH);
175 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + 16 == KPCR_PRCB_DPC_COUNT);
176 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
177 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
178 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, MaximumDpcQueueDepth) == KPCR_PRCB_MAXIMUM_DPC_QUEUE_DEPTH);
179 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRequestRate) == KPCR_PRCB_DPC_REQUEST_RATE);
180 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcInterruptRequested) == KPCR_PRCB_DPC_INTERRUPT_REQUESTED);
181 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRoutineActive) == KPCR_PRCB_DPC_ROUTINE_ACTIVE);
182 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcLastCount) == KPCR_PRCB_DPC_LAST_COUNT);
183 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
184 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, QuantumEnd) == KPCR_PRCB_QUANTUM_END);
185 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DeferredReadyListHead) == KPCR_PRCB_DEFERRED_READY_LIST_HEAD);
186 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PowerState) == KPCR_PRCB_POWER_STATE_IDLE_FUNCTION);
187 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PrcbLock) == KPCR_PRCB_PRCB_LOCK);
188 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
189 C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, IdleSchedule) == KPCR_PRCB_IDLE_SCHEDULE);
190 C_ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
191
192 /* Platform specific checks */
193 C_ASSERT(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
194 C_ASSERT(FIELD_OFFSET(KPROCESS, LdtDescriptor) == KPROCESS_LDT_DESCRIPTOR0);
195 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, SavedExceptionStack) == TF_SAVED_EXCEPTION_STACK);
196 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, regs) == TF_REGS);
197 C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, orig_ebp) == TF_ORIG_EBP);
198 C_ASSERT(FIELD_OFFSET(KTSS, Esp0) == KTSS_ESP0);
199 C_ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
200 #endif
201
202 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */