1 #ifndef __INCLUDE_INTERNAL_NTOSKRNL_H
2 #define __INCLUDE_INTERNAL_NTOSKRNL_H
5 * Use these to place a function in a specific section of the executable
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")
33 #include "../kdbg/kdb.h"
42 * Defines a descriptor as it appears in the processor tables
44 typedef struct __DESCRIPTOR
48 } IDT_DESCRIPTOR
, GDT_DESCRIPTOR
;
52 extern IDT_DESCRIPTOR KiIdt
[256];
53 //extern GDT_DESCRIPTOR KiGdt[256];
56 * Initalization functions (called once by main())
58 VOID
MmInitSystem(ULONG Phase
, PLOADER_PARAMETER_BLOCK LoaderBlock
, ULONG LastKernelAddress
);
60 VOID
IoInit2(BOOLEAN BootLog
);
61 VOID STDCALL
IoInit3(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
);
72 /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
74 RtlpCreateUnicodeString(
75 IN OUT PUNICODE_STRING UniDest
,
77 IN POOL_TYPE PoolType
);
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
89 RtlReleaseCapturedUnicodeString(
90 IN PUNICODE_STRING CapturedString
,
91 IN KPROCESSOR_MODE CurrentMode
,
92 IN BOOLEAN CaptureIfKernel
96 * Inlined Probing Macros
98 * NOTE: Alignment of the pointers is not verified!
100 #define ProbeForWriteGenericType(Ptr, Type) \
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); \
106 *(volatile Type *)(Ptr) = *(volatile Type *)(Ptr); \
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)
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 : \
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))
151 * Use IsPointerOffset to test whether a pointer should be interpreted as an offset
154 #if defined(_X86_) || defined(_M_AMD64)
156 /* for x86 and x86-64 the MSB is 1 so we can simply test on that */
157 #define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
159 #elif defined(_IA64_)
161 /* on Itanium if the 24 most significant bits are set, we're not dealing with
163 #define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
166 #error IsPointerOffset() needs to be defined for this architecture
173 #define MM_STACK_SIZE (3*4096)
175 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */