ReactOS  r74223
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  */
35 VOID
36 NTAPI
38 {
40 }
41 
42 /*
43  * @unimplemented
44  */
45 VOID
46 NTAPI
48 {
50 }
51 
52 /*
53  * @unimplemented
54  */
55 PVOID
56 NTAPI
57 MmLockPageableDataSection(IN PVOID AddressWithinSection)
58 {
59  //
60  // We should just find the section and call MmLockPageableSectionByHandle
61  //
62  static BOOLEAN Warn; if (!Warn++) UNIMPLEMENTED;
63  return AddressWithinSection;
64 }
65 
66 /*
67  * @unimplemented
68  */
69 ULONG
70 NTAPI
72 {
74  return 0;
75 }
76 
77 /*
78  * @implemented
79  */
81 NTAPI
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  //
97  if (!MiVerifierDriverAddedThunkListHead.Flink) return STATUS_NOT_SUPPORTED;
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  //
129  KernelMode,
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;
189  InsertTailList(&MiVerifierDriverAddedThunkListHead,
190  &DriverThunks->ListEntry);
191  DriverThunks = NULL;
192 
193 Cleanup:
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  */
210 LOGICAL
211 NTAPI
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  */
231 NTSTATUS
232 NTAPI
234 {
235  //
236  // Check if we've actually added anything to the list
237  //
238  if (MiVerifierDriverAddedThunkListHead.Flink)
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;
251  return STATUS_NOT_SUPPORTED;
252 }
253 
254 /* EOF */
DWORD *typedef PVOID
Definition: winlogon.h:52
PVOID NTAPI MmLockPageableDataSection(IN PVOID AddressWithinSection)
Definition: drvmgmt.c:57
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
#define IN
Definition: typedefs.h:39
ULONG NTAPI MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList)
Definition: drvmgmt.c:71
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID KernelVerifier
Definition: drvmgmt.c:28
MM_DRIVER_VERIFIER_DATA MmVerifierData
Definition: drvmgmt.c:20
VOID NTAPI MmLockPageableSectionByHandle(IN PVOID ImageSectionHandle)
Definition: drvmgmt.c:47
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSTATUS NTAPI MmAddVerifierThunks(IN PVOID ThunkBuffer, IN ULONG ThunkBufferSize)
Definition: drvmgmt.c:82
struct _LDR_DATA_TABLE_ENTRY * DataTableEntry
Definition: mmtypes.h:995
VOID NTAPI MmUnlockPageableImageSection(IN PVOID ImageSectionHandle)
Definition: drvmgmt.c:37
#define TRUE
Definition: numbers.c:17
ULONG MmVerifyDriverBufferType
Definition: drvmgmt.c:25
PLDR_DATA_TABLE_ENTRY NTAPI MiLookupDataTableEntry(IN PVOID Address)
Definition: sysldr.c:3365
ULONG SizeOfImage
Definition: ldrtypes.h:141
LIST_ENTRY MiVerifierDriverAddedThunkListHead
Definition: drvmgmt.c:21
#define InsertTailList(ListHead, Entry)
PVOID MmTriageActionTaken
Definition: drvmgmt.c:27
KMUTANT MmSystemLoadLock
Definition: sysldr.c:39
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:64
PVOID DllBase
Definition: ldrtypes.h:139
ULONG MmVerifyDriverBufferLength
Definition: drvmgmt.c:24
GLenum GLclampf GLint i
Definition: glfuncs.h:14
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define KSEG0_BASE
Definition: ketypes.h:273
PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine
_In_ ULONG ThunkBufferSize
Definition: mmfuncs.h:700
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
smooth NULL
Definition: ftsmooth.c:464
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
ULONG MmBootImageSize
Definition: init.c:49
if(!(yy_init))
Definition: macro.lex.yy.c:704
Definition: video.h:581
#define PAGED_CODE()
Definition: video.h:57
LONG NTAPI KeReleaseMutant(IN PKMUTANT Mutant, IN KPRIORITY Increment, IN BOOLEAN Abandon, IN BOOLEAN Wait)
Definition: mutex.c:98
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
WCHAR MmVerifyDriverBuffer[512]
Definition: drvmgmt.c:23
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:461
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: ntddk_ex.h:202
Definition: typedefs.h:118
static const WCHAR Cleanup[]
Definition: register.c:65
NTSTATUS NTAPI MmIsVerifierEnabled(OUT PULONG VerifierFlags)
Definition: drvmgmt.c:233
ULONG MiActiveVerifierThunks
Definition: drvmgmt.c:22
Status
Definition: gdiplustypes.h:24
#define LDRP_IMAGE_VERIFYING
Definition: ldrtypes.h:53
LONG NTSTATUS
Definition: DriverTester.h:11
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
ULONG MmVerifyDriverLevel
Definition: drvmgmt.c:26
LOGICAL NTAPI MmIsDriverVerifying(IN PDRIVER_OBJECT DriverObject)
Definition: drvmgmt.c:212
struct _DRIVER_VERIFIER_THUNK_PAIRS * PDRIVER_VERIFIER_THUNK_PAIRS
unsigned int * PULONG
Definition: retypes.h:1
#define OUT
Definition: typedefs.h:40
#define FALSE
Definition: numbers.c:16
ULONG Flags
Definition: ntddk_ex.h:211
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define ULONG_PTR
Definition: config.h:101
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097
#define REG_NONE
Definition: nt_native.h:1492
struct _DRIVER_VERIFIER_THUNK_PAIRS DRIVER_VERIFIER_THUNK_PAIRS