ReactOS  0.4.14-dev-552-g2fad488
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 {
39  static ULONG Warn; if (!Warn++) UNIMPLEMENTED;
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 ULONG 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  //
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;
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  //
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  //
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 */
PVOID NTAPI MmLockPageableDataSection(IN PVOID AddressWithinSection)
Definition: drvmgmt.c:57
#define IN
Definition: typedefs.h:38
ULONG NTAPI MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList)
Definition: drvmgmt.c:71
#define TRUE
Definition: types.h:120
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
NTSTATUS NTAPI MmAddVerifierThunks(IN PVOID ThunkBuffer, IN ULONG ThunkBufferSize)
Definition: drvmgmt.c:82
struct _LDR_DATA_TABLE_ENTRY * DataTableEntry
Definition: mmtypes.h:994
VOID NTAPI MmUnlockPageableImageSection(IN PVOID ImageSectionHandle)
Definition: drvmgmt.c:37
LONG NTSTATUS
Definition: precomp.h:26
ULONG MmVerifyDriverBufferType
Definition: drvmgmt.c:25
PLDR_DATA_TABLE_ENTRY NTAPI MiLookupDataTableEntry(IN PVOID Address)
Definition: sysldr.c:3330
ULONG SizeOfImage
Definition: ldrtypes.h:143
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
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID DllBase
Definition: btrfs_drv.h:1857
ULONG MmVerifyDriverBufferLength
Definition: drvmgmt.c:24
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
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
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void * PVOID
Definition: retypes.h:9
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG MmBootImageSize
Definition: init.c:49
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: video.h:581
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
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: btrfs_drv.h:1853
Definition: typedefs.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
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:55
#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:39
ULONG Flags
Definition: ntddk_ex.h:207
#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:1099
#define REG_NONE
Definition: nt_native.h:1492
return STATUS_SUCCESS
Definition: btrfs.c:2938
struct _DRIVER_VERIFIER_THUNK_PAIRS DRIVER_VERIFIER_THUNK_PAIRS
PVOID DriverSection
Definition: iotypes.h:2173