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 #line 15 "ARMĀ³::DRVMGMT"
16 #define MODULE_INVOLVED_IN_ARM3
17 #include "../ARM3/miarm.h"
19 /* GLOBALS *******************************************************************/
21 MM_DRIVER_VERIFIER_DATA MmVerifierData
;
22 LIST_ENTRY MiVerifierDriverAddedThunkListHead
;
23 ULONG MiActiveVerifierThunks
;
24 WCHAR MmVerifyDriverBuffer
[512] = {0};
25 ULONG MmVerifyDriverBufferLength
= sizeof(MmVerifyDriverBuffer
);
26 ULONG MmVerifyDriverBufferType
= REG_NONE
;
27 ULONG MmVerifyDriverLevel
= -1;
28 PVOID MmTriageActionTaken
;
31 /* PUBLIC FUNCTIONS ***********************************************************/
38 MmUnlockPageableImageSection(IN PVOID ImageSectionHandle
)
48 MmLockPageableSectionByHandle(IN PVOID ImageSectionHandle
)
58 MmLockPageableDataSection(IN PVOID AddressWithinSection
)
61 // We should just find the section and call MmLockPageableSectionByHandle
64 return AddressWithinSection
;
72 MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList
)
83 MmAddVerifierThunks(IN PVOID ThunkBuffer
,
84 IN ULONG ThunkBufferSize
)
86 PDRIVER_VERIFIER_THUNK_PAIRS ThunkTable
;
88 PDRIVER_SPECIFIED_VERIFIER_THUNKS DriverThunks
;
89 PLDR_DATA_TABLE_ENTRY LdrEntry
;
90 PVOID ModuleBase
, ModuleEnd
;
92 NTSTATUS Status
= STATUS_SUCCESS
;
96 // Make sure the driver verifier is initialized
98 if (!MiVerifierDriverAddedThunkListHead
.Flink
) return STATUS_NOT_SUPPORTED
;
101 // Get the thunk pairs and count them
103 ThunkCount
= ThunkBufferSize
/ sizeof(DRIVER_VERIFIER_THUNK_PAIRS
);
104 if (!ThunkCount
) return STATUS_INVALID_PARAMETER_1
;
107 // Now allocate our own thunk table
109 DriverThunks
= ExAllocatePoolWithTag(PagedPool
,
110 sizeof(*DriverThunks
) +
112 sizeof(DRIVER_VERIFIER_THUNK_PAIRS
),
114 if (!DriverThunks
) return STATUS_INSUFFICIENT_RESOURCES
;
117 // Now copy the driver-fed part
119 ThunkTable
= (PDRIVER_VERIFIER_THUNK_PAIRS
)(DriverThunks
+ 1);
120 RtlCopyMemory(ThunkTable
,
122 ThunkCount
* sizeof(DRIVER_VERIFIER_THUNK_PAIRS
));
125 // Acquire the system load lock
127 KeEnterCriticalRegion();
128 KeWaitForSingleObject(&MmSystemLoadLock
,
135 // Get the loader entry
137 LdrEntry
= MiLookupDataTableEntry(ThunkTable
->PristineRoutine
);
143 Status
= STATUS_INVALID_PARAMETER_2
;
148 // Get driver base and end
150 ModuleBase
= LdrEntry
->DllBase
;
151 ModuleEnd
= (PVOID
)((ULONG_PTR
)LdrEntry
->DllBase
+ LdrEntry
->SizeOfImage
);
154 // Don't allow hooking the kernel or HAL
156 if (ModuleBase
< (PVOID
)(KSEG0_BASE
+ MmBootImageSize
))
161 Status
= STATUS_INVALID_PARAMETER_2
;
166 // Loop all the thunks
168 for (i
= 0; i
< ThunkCount
; i
++)
171 // Make sure it's in the driver
173 if (((ULONG_PTR
)ThunkTable
->PristineRoutine
< (ULONG_PTR
)ModuleBase
) ||
174 ((ULONG_PTR
)ThunkTable
->PristineRoutine
>= (ULONG_PTR
)ModuleEnd
))
179 Status
= STATUS_INVALID_PARAMETER_2
;
185 // Otherwise, add this entry
187 DriverThunks
->DataTableEntry
= LdrEntry
;
188 DriverThunks
->NumberOfThunks
= ThunkCount
;
189 MiActiveVerifierThunks
++;
190 InsertTailList(&MiVerifierDriverAddedThunkListHead
,
191 &DriverThunks
->ListEntry
);
198 KeReleaseMutant(&MmSystemLoadLock
, 1, FALSE
, FALSE
);
199 KeLeaveCriticalRegion();
202 // Free the table if we failed and return status
204 if (DriverThunks
) ExFreePool(DriverThunks
);
213 MmIsDriverVerifying(IN PDRIVER_OBJECT DriverObject
)
215 PLDR_DATA_TABLE_ENTRY LdrEntry
;
218 // Get the loader entry
220 LdrEntry
= (PLDR_DATA_TABLE_ENTRY
)DriverObject
->DriverSection
;
221 if (!LdrEntry
) return FALSE
;
224 // Check if we're verifying or not
226 return (LdrEntry
->Flags
& LDRP_IMAGE_VERIFYING
) ? TRUE
: FALSE
;
234 MmIsVerifierEnabled(OUT PULONG VerifierFlags
)
237 // Check if we've actually added anything to the list
239 if (MiVerifierDriverAddedThunkListHead
.Flink
)
242 // We have, read the verifier level
244 *VerifierFlags
= MmVerifierData
.Level
;
245 return STATUS_SUCCESS
;
249 // Otherwise, we're disabled
252 return STATUS_NOT_SUPPORTED
;