ReactOS 0.4.15-dev-7906-g1b85a5f
drvmgmt.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/drvmgmt.c
5 * PURPOSE: ARM Memory Manager Driver Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <ntoskrnl.h>
12#define NDEBUG
13#include <debug.h>
14
15#define MODULE_INVOLVED_IN_ARM3
16#include <mm/ARM3/miarm.h>
17
18/* GLOBALS *******************************************************************/
19
29
30/* PUBLIC FUNCTIONS ***********************************************************/
31
32/*
33 * @unimplemented
34 */
35VOID
38{
39 static ULONG Warn; if (!Warn++) UNIMPLEMENTED;
40}
41
42/*
43 * @unimplemented
44 */
45VOID
48{
50}
51
52/*
53 * @unimplemented
54 */
57MmLockPageableDataSection(IN PVOID AddressWithinSection)
58{
59 //
60 // We should just find the section and call MmLockPageableSectionByHandle
61 //
62 static ULONG Warn; if (!Warn++) UNIMPLEMENTED;
63 return AddressWithinSection;
64}
65
66/*
67 * @unimplemented
68 */
72{
74 return 0;
75}
76
77/*
78 * @implemented
79 */
84{
86 ULONG ThunkCount;
88 PLDR_DATA_TABLE_ENTRY LdrEntry;
89 PVOID ModuleBase, ModuleEnd;
90 ULONG i;
92 PAGED_CODE();
93
94 //
95 // Make sure the driver verifier is initialized
96 //
98
99 //
100 // Get the thunk pairs and count them
101 //
102 ThunkCount = ThunkBufferSize / sizeof(DRIVER_VERIFIER_THUNK_PAIRS);
103 if (!ThunkCount) return STATUS_INVALID_PARAMETER_1;
104
105 //
106 // Now allocate our own thunk table
107 //
108 DriverThunks = ExAllocatePoolWithTag(PagedPool,
109 sizeof(*DriverThunks) +
110 ThunkCount *
112 'tVmM');
113 if (!DriverThunks) return STATUS_INSUFFICIENT_RESOURCES;
114
115 //
116 // Now copy the driver-fed part
117 //
118 ThunkTable = (PDRIVER_VERIFIER_THUNK_PAIRS)(DriverThunks + 1);
119 RtlCopyMemory(ThunkTable,
120 ThunkBuffer,
121 ThunkCount * sizeof(DRIVER_VERIFIER_THUNK_PAIRS));
122
123 //
124 // Acquire the system load lock
125 //
130 FALSE,
131 NULL);
132
133 //
134 // Get the loader entry
135 //
136 LdrEntry = MiLookupDataTableEntry(ThunkTable->PristineRoutine);
137 if (!LdrEntry)
138 {
139 //
140 // Fail
141 //
143 goto Cleanup;
144 }
145
146 //
147 // Get driver base and end
148 //
149 ModuleBase = LdrEntry->DllBase;
150 ModuleEnd = (PVOID)((ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage);
151
152 //
153 // Don't allow hooking the kernel or HAL
154 //
155 if (ModuleBase < (PVOID)(KSEG0_BASE + MmBootImageSize))
156 {
157 //
158 // Fail
159 //
161 goto Cleanup;
162 }
163
164 //
165 // Loop all the thunks
166 //
167 for (i = 0; i < ThunkCount; i++)
168 {
169 //
170 // Make sure it's in the driver
171 //
172 if (((ULONG_PTR)ThunkTable->PristineRoutine < (ULONG_PTR)ModuleBase) ||
173 ((ULONG_PTR)ThunkTable->PristineRoutine >= (ULONG_PTR)ModuleEnd))
174 {
175 //
176 // Nope, fail
177 //
179 goto Cleanup;
180 }
181 }
182
183 //
184 // Otherwise, add this entry
185 //
186 DriverThunks->DataTableEntry = LdrEntry;
187 DriverThunks->NumberOfThunks = ThunkCount;
190 &DriverThunks->ListEntry);
191 DriverThunks = NULL;
192
193Cleanup:
194 //
195 // Release the lock
196 //
199
200 //
201 // Free the table if we failed and return status
202 //
203 if (DriverThunks) ExFreePoolWithTag(DriverThunks, 'tVmM');
204 return Status;
205}
206
207/*
208 * @implemented
209 */
210LOGICAL
211NTAPI
213{
214 PLDR_DATA_TABLE_ENTRY LdrEntry;
215
216 //
217 // Get the loader entry
218 //
219 LdrEntry = (PLDR_DATA_TABLE_ENTRY)DriverObject->DriverSection;
220 if (!LdrEntry) return FALSE;
221
222 //
223 // Check if we're verifying or not
224 //
225 return (LdrEntry->Flags & LDRP_IMAGE_VERIFYING) ? TRUE: FALSE;
226}
227
228/*
229 * @implemented
230 */
232NTAPI
234{
235 //
236 // Check if we've actually added anything to the list
237 //
239 {
240 //
241 // We have, read the verifier level
242 //
243 *VerifierFlags = MmVerifierData.Level;
244 return STATUS_SUCCESS;
245 }
246
247 //
248 // Otherwise, we're disabled
249 //
250 *VerifierFlags = 0;
252}
253
254/* EOF */
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:115
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
#define ULONG_PTR
Definition: config.h:101
ULONG MiActiveVerifierThunks
Definition: drvmgmt.c:22
VOID NTAPI MmLockPageableSectionByHandle(IN PVOID ImageSectionHandle)
Definition: drvmgmt.c:47
PVOID MmTriageActionTaken
Definition: drvmgmt.c:27
ULONG MmVerifyDriverBufferType
Definition: drvmgmt.c:25
VOID NTAPI MmUnlockPageableImageSection(IN PVOID ImageSectionHandle)
Definition: drvmgmt.c:37
NTSTATUS NTAPI MmAddVerifierThunks(IN PVOID ThunkBuffer, IN ULONG ThunkBufferSize)
Definition: drvmgmt.c:82
ULONG MmVerifyDriverLevel
Definition: drvmgmt.c:26
ULONG MmVerifyDriverBufferLength
Definition: drvmgmt.c:24
WCHAR MmVerifyDriverBuffer[512]
Definition: drvmgmt.c:23
MM_DRIVER_VERIFIER_DATA MmVerifierData
Definition: drvmgmt.c:20
ULONG NTAPI MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList)
Definition: drvmgmt.c:71
PVOID KernelVerifier
Definition: drvmgmt.c:28
PVOID NTAPI MmLockPageableDataSection(IN PVOID AddressWithinSection)
Definition: drvmgmt.c:57
NTSTATUS NTAPI MmIsVerifierEnabled(OUT PULONG VerifierFlags)
Definition: drvmgmt.c:233
LIST_ENTRY MiVerifierDriverAddedThunkListHead
Definition: drvmgmt.c:21
LOGICAL NTAPI MmIsDriverVerifying(IN PDRIVER_OBJECT DriverObject)
Definition: drvmgmt.c:212
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define LDRP_IMAGE_VERIFYING
Definition: ldrtypes.h:55
if(dx< 0)
Definition: linetemp.h:194
PLDR_DATA_TABLE_ENTRY NTAPI MiLookupDataTableEntry(IN PVOID Address)
Definition: sysldr.c:3517
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:34
#define KSEG0_BASE
Definition: ketypes.h:339
#define MUTANT_INCREMENT
Definition: extypes.h:84
#define REG_NONE
Definition: nt_native.h:1492
struct _DRIVER_VERIFIER_THUNK_PAIRS DRIVER_VERIFIER_THUNK_PAIRS
struct _DRIVER_VERIFIER_THUNK_PAIRS * PDRIVER_VERIFIER_THUNK_PAIRS
KMUTANT MmSystemLoadLock
Definition: sysldr.c:26
LONG NTAPI KeReleaseMutant(IN PKMUTANT Mutant, IN KPRIORITY Increment, IN BOOLEAN Abandon, IN BOOLEAN Wait)
Definition: mutex.c:98
ULONG MmBootImageSize
Definition: init.c:49
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
@ Warn
Definition: video.h:589
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _LDR_DATA_TABLE_ENTRY * DataTableEntry
Definition: mmtypes.h:1021
PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine
Definition: btrfs_drv.h:1876
ULONG SizeOfImage
Definition: ldrtypes.h:143
PVOID DllBase
Definition: btrfs_drv.h:1880
ULONG Flags
Definition: ntddk_ex.h:207
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
@ WrVirtualMemory
Definition: ketypes.h:433
_In_ ULONG ThunkBufferSize
Definition: mmfuncs.h:699
__wchar_t WCHAR
Definition: xmlstorage.h:180