Adding small hack to getting SetPixel color right when it is more that 3 bytes long.
[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 "ex.h"
21 #include "ps.h"
22 #include "cc.h"
23 #include "io.h"
24 #include "po.h"
25 #include "se.h"
26 #include "ldr.h"
27 #include "kd.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 #include "vdm.h"
39
40 #include <pshpack1.h>
41 /*
42 * Defines a descriptor as it appears in the processor tables
43 */
44 typedef struct __DESCRIPTOR
45 {
46 ULONG a;
47 ULONG b;
48 } IDT_DESCRIPTOR, GDT_DESCRIPTOR;
49
50 #include <poppack.h>
51 //extern GDT_DESCRIPTOR KiGdt[256];
52
53 /*
54 * Initalization functions (called once by main())
55 */
56 VOID MmInitSystem(ULONG Phase, PROS_LOADER_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, PROS_LOADER_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 FORCEINLINE
106 LONG
107 InterlockedOr(IN OUT LONG volatile *Target,
108 IN LONG Set)
109 {
110 LONG i;
111 LONG j;
112
113 j = *Target;
114 do {
115 i = j;
116 j = InterlockedCompareExchange((PLONG)Target,
117 i | Set,
118 i);
119
120 } while (i != j);
121
122 return j;
123 }
124
125 /*
126 * generic information class probing code
127 */
128
129 #define ICIF_QUERY 0x1
130 #define ICIF_SET 0x2
131 #define ICIF_QUERY_SIZE_VARIABLE 0x4
132 #define ICIF_SET_SIZE_VARIABLE 0x8
133 #define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
134
135 typedef struct _INFORMATION_CLASS_INFO
136 {
137 ULONG RequiredSizeQUERY;
138 ULONG RequiredSizeSET;
139 ULONG AlignmentSET;
140 ULONG AlignmentQUERY;
141 ULONG Flags;
142 } INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
143
144 #define ICI_SQ_SAME(Type, Alignment, Flags) \
145 { Type, Type, Alignment, Alignment, Flags }
146
147 #define ICI_SQ(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
148 { TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags }
149
150 //
151 // TEMPORARY
152 //
153 #define IQS_SAME(Type, Alignment, Flags) \
154 { sizeof(Type), sizeof(Type), sizeof(Alignment), sizeof(Alignment), Flags }
155
156 #define IQS(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags) \
157 { sizeof(TypeQuery), sizeof(TypeSet), sizeof(AlignmentQuery), sizeof(AlignmentSet), Flags }
158
159 static __inline NTSTATUS
160 DefaultSetInfoBufferCheck(UINT Class,
161 const INFORMATION_CLASS_INFO *ClassList,
162 UINT ClassListEntries,
163 PVOID Buffer,
164 ULONG BufferLength,
165 KPROCESSOR_MODE PreviousMode)
166 {
167 NTSTATUS Status = STATUS_SUCCESS;
168
169 if (Class >= 0 && Class < ClassListEntries)
170 {
171 if (!(ClassList[Class].Flags & ICIF_SET))
172 {
173 Status = STATUS_INVALID_INFO_CLASS;
174 }
175 else if (ClassList[Class].RequiredSizeSET > 0 &&
176 BufferLength != ClassList[Class].RequiredSizeSET)
177 {
178 if (!(ClassList[Class].Flags & ICIF_SET_SIZE_VARIABLE))
179 {
180 Status = STATUS_INFO_LENGTH_MISMATCH;
181 }
182 }
183
184 if (NT_SUCCESS(Status))
185 {
186 if (PreviousMode != KernelMode)
187 {
188 _SEH_TRY
189 {
190 ProbeForRead(Buffer,
191 BufferLength,
192 ClassList[Class].AlignmentSET);
193 }
194 _SEH_HANDLE
195 {
196 Status = _SEH_GetExceptionCode();
197 }
198 _SEH_END;
199 }
200 }
201 }
202 else
203 Status = STATUS_INVALID_INFO_CLASS;
204
205 return Status;
206 }
207
208 static __inline NTSTATUS
209 DefaultQueryInfoBufferCheck(UINT Class,
210 const INFORMATION_CLASS_INFO *ClassList,
211 UINT ClassListEntries,
212 PVOID Buffer,
213 ULONG BufferLength,
214 PULONG ReturnLength,
215 KPROCESSOR_MODE PreviousMode)
216 {
217 NTSTATUS Status = STATUS_SUCCESS;
218
219 if (Class >= 0 && Class < ClassListEntries)
220 {
221 if (!(ClassList[Class].Flags & ICIF_QUERY))
222 {
223 Status = STATUS_INVALID_INFO_CLASS;
224 }
225 else if (ClassList[Class].RequiredSizeQUERY > 0 &&
226 BufferLength != ClassList[Class].RequiredSizeQUERY)
227 {
228 if (!(ClassList[Class].Flags & ICIF_QUERY_SIZE_VARIABLE))
229 {
230 Status = STATUS_INFO_LENGTH_MISMATCH;
231 }
232 }
233
234 if (NT_SUCCESS(Status))
235 {
236 if (PreviousMode != KernelMode)
237 {
238 _SEH_TRY
239 {
240 if (Buffer != NULL)
241 {
242 ProbeForWrite(Buffer,
243 BufferLength,
244 ClassList[Class].AlignmentQUERY);
245 }
246
247 if (ReturnLength != NULL)
248 {
249 ProbeForWriteUlong(ReturnLength);
250 }
251 }
252 _SEH_HANDLE
253 {
254 Status = _SEH_GetExceptionCode();
255 }
256 _SEH_END;
257 }
258 }
259 }
260 else
261 Status = STATUS_INVALID_INFO_CLASS;
262
263 return Status;
264 }
265
266 /*
267 * Use IsPointerOffset to test whether a pointer should be interpreted as an offset
268 * or as a pointer
269 */
270 #if defined(_X86_) || defined(_M_AMD64)
271
272 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
273 #define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
274
275 #elif defined(_IA64_)
276
277 /* on Itanium if the 24 most significant bits are set, we're not dealing with
278 offsets anymore. */
279 #define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
280
281 #else
282 #error IsPointerOffset() needs to be defined for this architecture
283 #endif
284
285 #endif
286
287 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */