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
9 /* INCLUDES *******************************************************************/
15 #define MODULE_INVOLVED_IN_ARM3
16 #include <mm/ARM3/miarm.h>
18 /* GLOBALS *******************************************************************/
20 MM_DRIVER_VERIFIER_DATA MmVerifierData
;
21 LIST_ENTRY MiVerifierDriverAddedThunkListHead
;
22 ULONG MiActiveVerifierThunks
;
23 WCHAR MmVerifyDriverBuffer
[512] = {0};
24 ULONG MmVerifyDriverBufferLength
= sizeof(MmVerifyDriverBuffer
);
25 ULONG MmVerifyDriverBufferType
= REG_NONE
;
26 ULONG MmVerifyDriverLevel
= -1;
27 PVOID MmTriageActionTaken
;
30 /* PUBLIC FUNCTIONS ***********************************************************/
37 MmUnlockPageableImageSection(IN PVOID ImageSectionHandle
)
47 MmLockPageableSectionByHandle(IN PVOID ImageSectionHandle
)
57 MmLockPageableDataSection(IN PVOID AddressWithinSection
)
60 // We should just find the section and call MmLockPageableSectionByHandle
62 static BOOLEAN Warn
; if (!Warn
++) UNIMPLEMENTED
;
63 return AddressWithinSection
;
71 MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList
)
82 MmAddVerifierThunks(IN PVOID ThunkBuffer
,
83 IN ULONG ThunkBufferSize
)
85 PDRIVER_VERIFIER_THUNK_PAIRS ThunkTable
;
87 PDRIVER_SPECIFIED_VERIFIER_THUNKS DriverThunks
;
88 PLDR_DATA_TABLE_ENTRY LdrEntry
;
89 PVOID ModuleBase
, ModuleEnd
;
91 NTSTATUS Status
= STATUS_SUCCESS
;
95 // Make sure the driver verifier is initialized
97 if (!MiVerifierDriverAddedThunkListHead
.Flink
) return STATUS_NOT_SUPPORTED
;
100 // Get the thunk pairs and count them
102 ThunkCount
= ThunkBufferSize
/ sizeof(DRIVER_VERIFIER_THUNK_PAIRS
);
103 if (!ThunkCount
) return STATUS_INVALID_PARAMETER_1
;
106 // Now allocate our own thunk table
108 DriverThunks
= ExAllocatePoolWithTag(PagedPool
,
109 sizeof(*DriverThunks
) +
111 sizeof(DRIVER_VERIFIER_THUNK_PAIRS
),
113 if (!DriverThunks
) return STATUS_INSUFFICIENT_RESOURCES
;
116 // Now copy the driver-fed part
118 ThunkTable
= (PDRIVER_VERIFIER_THUNK_PAIRS
)(DriverThunks
+ 1);
119 RtlCopyMemory(ThunkTable
,
121 ThunkCount
* sizeof(DRIVER_VERIFIER_THUNK_PAIRS
));
124 // Acquire the system load lock
126 KeEnterCriticalRegion();
127 KeWaitForSingleObject(&MmSystemLoadLock
,
134 // Get the loader entry
136 LdrEntry
= MiLookupDataTableEntry(ThunkTable
->PristineRoutine
);
142 Status
= STATUS_INVALID_PARAMETER_2
;
147 // Get driver base and end
149 ModuleBase
= LdrEntry
->DllBase
;
150 ModuleEnd
= (PVOID
)((ULONG_PTR
)LdrEntry
->DllBase
+ LdrEntry
->SizeOfImage
);
153 // Don't allow hooking the kernel or HAL
155 if (ModuleBase
< (PVOID
)(KSEG0_BASE
+ MmBootImageSize
))
160 Status
= STATUS_INVALID_PARAMETER_2
;
165 // Loop all the thunks
167 for (i
= 0; i
< ThunkCount
; i
++)
170 // Make sure it's in the driver
172 if (((ULONG_PTR
)ThunkTable
->PristineRoutine
< (ULONG_PTR
)ModuleBase
) ||
173 ((ULONG_PTR
)ThunkTable
->PristineRoutine
>= (ULONG_PTR
)ModuleEnd
))
178 Status
= STATUS_INVALID_PARAMETER_2
;
184 // Otherwise, add this entry
186 DriverThunks
->DataTableEntry
= LdrEntry
;
187 DriverThunks
->NumberOfThunks
= ThunkCount
;
188 MiActiveVerifierThunks
++;
189 InsertTailList(&MiVerifierDriverAddedThunkListHead
,
190 &DriverThunks
->ListEntry
);
197 KeReleaseMutant(&MmSystemLoadLock
, 1, FALSE
, FALSE
);
198 KeLeaveCriticalRegion();
201 // Free the table if we failed and return status
203 if (DriverThunks
) ExFreePoolWithTag(DriverThunks
, 'tVmM');
212 MmIsDriverVerifying(IN PDRIVER_OBJECT DriverObject
)
214 PLDR_DATA_TABLE_ENTRY LdrEntry
;
217 // Get the loader entry
219 LdrEntry
= (PLDR_DATA_TABLE_ENTRY
)DriverObject
->DriverSection
;
220 if (!LdrEntry
) return FALSE
;
223 // Check if we're verifying or not
225 return (LdrEntry
->Flags
& LDRP_IMAGE_VERIFYING
) ? TRUE
: FALSE
;
233 MmIsVerifierEnabled(OUT PULONG VerifierFlags
)
236 // Check if we've actually added anything to the list
238 if (MiVerifierDriverAddedThunkListHead
.Flink
)
241 // We have, read the verifier level
243 *VerifierFlags
= MmVerifierData
.Level
;
244 return STATUS_SUCCESS
;
248 // Otherwise, we're disabled
251 return STATUS_NOT_SUPPORTED
;