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