- Cleanup the mess in query.c by reformatting the code to remove tab/space confusion...
[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 #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
12 #ifdef _NTOSKRNL_
13
14 #include "ke.h"
15 #include "i386/mm.h"
16 #include "i386/fpu.h"
17 #include "i386/v86m.h"
18 #include "ob.h"
19 #include "mm.h"
20 #include "ps.h"
21 #include "cc.h"
22 #include "io.h"
23 #include "po.h"
24 #include "se.h"
25 #include "ldr.h"
26 #include "kd.h"
27 #include "ex.h"
28 #include "fsrtl.h"
29 #include "lpc.h"
30 #include "rtl.h"
31 #ifdef KDBG
32 #include "../kdbg/kdb.h"
33 #endif
34 #include "dbgk.h"
35 #include "tag.h"
36 #include "test.h"
37 #include "inbv.h"
38
39 #include <pshpack1.h>
40 /*
41 * Defines a descriptor as it appears in the processor tables
42 */
43 typedef struct __DESCRIPTOR
44 {
45 ULONG a;
46 ULONG b;
47 } IDT_DESCRIPTOR, GDT_DESCRIPTOR;
48
49 #include <poppack.h>
50 //extern GDT_DESCRIPTOR KiGdt[256];
51
52 /*
53 * Initalization functions (called once by main())
54 */
55 VOID MmInitSystem(ULONG Phase, PROS_LOADER_PARAMETER_BLOCK LoaderBlock, ULONG LastKernelAddress);
56 VOID IoInit(VOID);
57 VOID IoInit2(BOOLEAN BootLog);
58 VOID STDCALL IoInit3(VOID);
59 VOID ObInit(VOID);
60 VOID PsInit(VOID);
61 VOID CmInitializeRegistry(VOID);
62 VOID STDCALL CmInitHives(BOOLEAN SetupBoot);
63 VOID CmInit2(PCHAR CommandLine);
64 VOID CmShutdownRegistry(VOID);
65 BOOLEAN CmImportSystemHive(PCHAR ChunkBase, ULONG ChunkSize);
66 BOOLEAN CmImportHardwareHive(PCHAR ChunkBase, ULONG ChunkSize);
67 VOID KdInitSystem(ULONG Reserved, PROS_LOADER_PARAMETER_BLOCK LoaderBlock);
68
69 /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
70 BOOLEAN FASTCALL
71 RtlpCreateUnicodeString(
72 IN OUT PUNICODE_STRING UniDest,
73 IN PCWSTR Source,
74 IN POOL_TYPE PoolType);
75
76 VOID
77 NTAPI
78 RtlpLogException(IN PEXCEPTION_RECORD ExceptionRecord,
79 IN PCONTEXT ContextRecord,
80 IN PVOID ContextData,
81 IN ULONG Size);
82
83 /* FIXME: Interlocked functions that need to be made into a public header */
84 FORCEINLINE
85 LONG
86 InterlockedAnd(IN OUT LONG volatile *Target,
87 IN LONG Set)
88 {
89 LONG i;
90 LONG j;
91
92 j = *Target;
93 do {
94 i = j;
95 j = InterlockedCompareExchange((PLONG)Target,
96 i & Set,
97 i);
98
99 } while (i != j);
100
101 return j;
102 }
103
104 FORCEINLINE
105 LONG
106 InterlockedOr(IN OUT LONG volatile *Target,
107 IN LONG Set)
108 {
109 LONG i;
110 LONG j;
111
112 j = *Target;
113 do {
114 i = j;
115 j = InterlockedCompareExchange((PLONG)Target,
116 i | Set,
117 i);
118
119 } while (i != j);
120
121 return j;
122 }
123
124 /*
125 * generic information class probing code
126 */
127
128 #define ICIF_QUERY 0x1
129 #define ICIF_SET 0x2
130 #define ICIF_QUERY_SIZE_VARIABLE 0x4
131 #define ICIF_SET_SIZE_VARIABLE 0x8
132 #define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
133
134 typedef struct _INFORMATION_CLASS_INFO
135 {
136 ULONG RequiredSizeQUERY;
137 ULONG RequiredSizeSET;
138 ULONG AlignmentSET;
139 ULONG AlignmentQUERY;
140 ULONG Flags;
141 } INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
142
143 #define ICI_SQ_SAME(Type, Alignment, Flags) \
144 { Type, Type, Alignment, Alignment, Flags }
145
146 #define ICI_SQ(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
147 { TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags }
148
149 //
150 // TEMPORARY
151 //
152 #define IQS_SAME(Type, Alignment, Flags) \
153 { sizeof(Type), sizeof(Type), sizeof(Alignment), sizeof(Alignment), Flags }
154
155 #define IQS(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
156 { sizeof(TypeQuery), sizeof(TypeSet), sizeof(AlignmentQuery), sizeof(AlignmentSet), Flags }
157
158 static __inline NTSTATUS
159 DefaultSetInfoBufferCheck(UINT Class,
160 const INFORMATION_CLASS_INFO *ClassList,
161 UINT ClassListEntries,
162 PVOID Buffer,
163 ULONG BufferLength,
164 KPROCESSOR_MODE PreviousMode)
165 {
166 NTSTATUS Status = STATUS_SUCCESS;
167
168 if (Class >= 0 && Class < ClassListEntries)
169 {
170 if (!(ClassList[Class].Flags & ICIF_SET))
171 {
172 Status = STATUS_INVALID_INFO_CLASS;
173 }
174 else if (ClassList[Class].RequiredSizeSET > 0 &&
175 BufferLength != ClassList[Class].RequiredSizeSET)
176 {
177 if (!(ClassList[Class].Flags & ICIF_SET_SIZE_VARIABLE))
178 {
179 Status = STATUS_INFO_LENGTH_MISMATCH;
180 }
181 }
182
183 if (NT_SUCCESS(Status))
184 {
185 if (PreviousMode != KernelMode)
186 {
187 _SEH_TRY
188 {
189 ProbeForRead(Buffer,
190 BufferLength,
191 ClassList[Class].AlignmentSET);
192 }
193 _SEH_HANDLE
194 {
195 Status = _SEH_GetExceptionCode();
196 }
197 _SEH_END;
198 }
199 }
200 }
201 else
202 Status = STATUS_INVALID_INFO_CLASS;
203
204 return Status;
205 }
206
207 static __inline NTSTATUS
208 DefaultQueryInfoBufferCheck(UINT Class,
209 const INFORMATION_CLASS_INFO *ClassList,
210 UINT ClassListEntries,
211 PVOID Buffer,
212 ULONG BufferLength,
213 PULONG ReturnLength,
214 KPROCESSOR_MODE PreviousMode)
215 {
216 NTSTATUS Status = STATUS_SUCCESS;
217
218 if (Class >= 0 && Class < ClassListEntries)
219 {
220 if (!(ClassList[Class].Flags & ICIF_QUERY))
221 {
222 Status = STATUS_INVALID_INFO_CLASS;
223 }
224 else if (ClassList[Class].RequiredSizeQUERY > 0 &&
225 BufferLength != ClassList[Class].RequiredSizeQUERY)
226 {
227 if (!(ClassList[Class].Flags & ICIF_QUERY_SIZE_VARIABLE))
228 {
229 Status = STATUS_INFO_LENGTH_MISMATCH;
230 }
231 }
232
233 if (NT_SUCCESS(Status))
234 {
235 if (PreviousMode != KernelMode)
236 {
237 _SEH_TRY
238 {
239 if (Buffer != NULL)
240 {
241 ProbeForWrite(Buffer,
242 BufferLength,
243 ClassList[Class].AlignmentQUERY);
244 }
245
246 if (ReturnLength != NULL)
247 {
248 ProbeForWriteUlong(ReturnLength);
249 }
250 }
251 _SEH_HANDLE
252 {
253 Status = _SEH_GetExceptionCode();
254 }
255 _SEH_END;
256 }
257 }
258 }
259 else
260 Status = STATUS_INVALID_INFO_CLASS;
261
262 return Status;
263 }
264
265 /*
266 * Use IsPointerOffset to test whether a pointer should be interpreted as an offset
267 * or as a pointer
268 */
269 #if defined(_X86_) || defined(_M_AMD64)
270
271 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
272 #define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
273
274 #elif defined(_IA64_)
275
276 /* on Itanium if the 24 most significant bits are set, we're not dealing with
277 offsets anymore. */
278 #define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
279
280 #else
281 #error IsPointerOffset() needs to be defined for this architecture
282 #endif
283
284 #endif
285
286 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */