8ce0e52ab403a213ef4b5931e05fbf90c9e6034b
[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 "xhal.h"
28 #include "v86m.h"
29 #include "fs.h"
30 #include "port.h"
31 #include "nls.h"
32 #ifdef KDBG
33 #include "../kdbg/kdb.h"
34 #endif
35 #include "dbgk.h"
36 #include "tag.h"
37 #include "test.h"
38 #include "inbv.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
52 extern IDT_DESCRIPTOR KiIdt[256];
53 //extern GDT_DESCRIPTOR KiGdt[256];
54
55 /*
56 * Initalization functions (called once by main())
57 */
58 VOID MmInitSystem(ULONG Phase, PLOADER_PARAMETER_BLOCK LoaderBlock, ULONG LastKernelAddress);
59 VOID IoInit(VOID);
60 VOID IoInit2(BOOLEAN BootLog);
61 VOID STDCALL IoInit3(VOID);
62 VOID ObInit(VOID);
63 VOID PsInit(VOID);
64 VOID CmInitializeRegistry(VOID);
65 VOID STDCALL CmInitHives(BOOLEAN SetupBoot);
66 VOID CmInit2(PCHAR CommandLine);
67 VOID CmShutdownRegistry(VOID);
68 BOOLEAN CmImportSystemHive(PCHAR ChunkBase, ULONG ChunkSize);
69 BOOLEAN CmImportHardwareHive(PCHAR ChunkBase, ULONG ChunkSize);
70 VOID KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock);
71
72 /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
73 BOOLEAN FASTCALL
74 RtlpCreateUnicodeString(
75 IN OUT PUNICODE_STRING UniDest,
76 IN PCWSTR Source,
77 IN POOL_TYPE PoolType);
78
79 NTSTATUS
80 RtlCaptureUnicodeString(
81 OUT PUNICODE_STRING Dest,
82 IN KPROCESSOR_MODE CurrentMode,
83 IN POOL_TYPE PoolType,
84 IN BOOLEAN CaptureIfKernel,
85 IN PUNICODE_STRING UnsafeSrc
86 );
87
88 VOID
89 RtlReleaseCapturedUnicodeString(
90 IN PUNICODE_STRING CapturedString,
91 IN KPROCESSOR_MODE CurrentMode,
92 IN BOOLEAN CaptureIfKernel
93 );
94
95 /*
96 * Inlined Probing Macros
97 *
98 * NOTE: Alignment of the pointers is not verified!
99 */
100 #define ProbeForWriteGenericType(Ptr, Type) \
101 do { \
102 if ((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
103 (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
104 ExRaiseStatus (STATUS_ACCESS_VIOLATION); \
105 } \
106 *(volatile Type *)(Ptr) = *(volatile Type *)(Ptr); \
107 } while (0)
108
109 #define ProbeForWriteBoolean(Ptr) ProbeForWriteGenericType(Ptr, BOOLEAN)
110 #define ProbeForWriteUchar(Ptr) ProbeForWriteGenericType(Ptr, UCHAR)
111 #define ProbeForWriteChar(Ptr) ProbeForWriteGenericType(Ptr, Char)
112 #define ProbeForWriteUshort(Ptr) ProbeForWriteGenericType(Ptr, USHORT)
113 #define ProbeForWriteShort(Ptr) ProbeForWriteGenericType(Ptr, SHORT)
114 #define ProbeForWriteUlong(Ptr) ProbeForWriteGenericType(Ptr, ULONG)
115 #define ProbeForWriteLong(Ptr) ProbeForWriteGenericType(Ptr, LONG)
116 #define ProbeForWriteUint(Ptr) ProbeForWriteGenericType(Ptr, UINT)
117 #define ProbeForWriteInt(Ptr) ProbeForWriteGenericType(Ptr, INT)
118 #define ProbeForWriteUlonglong(Ptr) ProbeForWriteGenericType(Ptr, ULONGLONG)
119 #define ProbeForWriteLonglong(Ptr) ProbeForWriteGenericType(Ptr, LONGLONG)
120 #define ProbeForWriteLonglong(Ptr) ProbeForWriteGenericType(Ptr, LONGLONG)
121 #define ProbeForWritePointer(Ptr) ProbeForWriteGenericType(Ptr, PVOID)
122 #define ProbeForWriteHandle(Ptr) ProbeForWriteGenericType(Ptr, HANDLE)
123 #define ProbeForWriteLangid(Ptr) ProbeForWriteGenericType(Ptr, LANGID)
124 #define ProbeForWriteLargeInteger(Ptr) ProbeForWriteGenericType(&(Ptr)->QuadPart, LONGLONG)
125 #define ProbeForWriteUlargeInteger(Ptr) ProbeForWriteGenericType(&(Ptr)->QuadPart, ULONGLONG)
126
127 #define ProbeForReadGenericType(Ptr, Type, Default) \
128 (((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
129 (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ? \
130 ExRaiseStatus (STATUS_ACCESS_VIOLATION), Default : \
131 *(Type *)(Ptr))
132
133 #define ProbeForReadBoolean(Ptr) ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)
134 #define ProbeForReadUchar(Ptr) ProbeForReadGenericType(Ptr, UCHAR, 0)
135 #define ProbeForReadChar(Ptr) ProbeForReadGenericType(Ptr, CHAR, 0)
136 #define ProbeForReadUshort(Ptr) ProbeForReadGenericType(Ptr, USHORT, 0)
137 #define ProbeForReadShort(Ptr) ProbeForReadGenericType(Ptr, SHORT, 0)
138 #define ProbeForReadUlong(Ptr) ProbeForReadGenericType(Ptr, ULONG, 0)
139 #define ProbeForReadLong(Ptr) ProbeForReadGenericType(Ptr, LONG, 0)
140 #define ProbeForReadUint(Ptr) ProbeForReadGenericType(Ptr, UINT, 0)
141 #define ProbeForReadInt(Ptr) ProbeForReadGenericType(Ptr, INT, 0)
142 #define ProbeForReadUlonglong(Ptr) ProbeForReadGenericType(Ptr, ULONGLONG, 0)
143 #define ProbeForReadLonglong(Ptr) ProbeForReadGenericType(Ptr, LONGLONG, 0)
144 #define ProbeForReadPointer(Ptr) ProbeForReadGenericType(Ptr, PVOID, NULL)
145 #define ProbeForReadHandle(Ptr) ProbeForReadGenericType(Ptr, HANDLE, NULL)
146 #define ProbeForReadLangid(Ptr) ProbeForReadGenericType(Ptr, LANGID, 0)
147 #define ProbeForReadLargeInteger(Ptr) ((LARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, LONGLONG, 0))
148 #define ProbeForReadUlargeInteger(Ptr) ((ULARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, ULONGLONG, 0))
149
150 /*
151 * Use IsKernelPointer to test whether a pointer points to the kernel address
152 * space
153 */
154 #if defined(_X86_) || defined(_M_AMD64)
155
156 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
157 #define IsKernelPointer(Ptr) ((LONG_PTR)(Ptr) < 0)
158
159 #elif defined(_IA64_)
160
161 /* on Itanium if the 24 most significant bits are set, we're not dealing with
162 user mode pointers. */
163 #define IsKernelPointer(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) != 0)
164
165 #else
166 #error IsKernelPointer() needs to be defined for this architecture
167 #endif
168
169 #endif
170 /*
171 *
172 */
173 #define MM_STACK_SIZE (3*4096)
174
175 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */