Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendrvmgmt.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: BSD - See COPYING.ARM in the top level directory 00004 * FILE: ntoskrnl/mm/ARM3/drvmgmt.c 00005 * PURPOSE: ARM Memory Manager Driver Management 00006 * PROGRAMMERS: ReactOS Portable Systems Group 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <ntoskrnl.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 #define MODULE_INVOLVED_IN_ARM3 00016 #include "../ARM3/miarm.h" 00017 00018 /* GLOBALS *******************************************************************/ 00019 00020 MM_DRIVER_VERIFIER_DATA MmVerifierData; 00021 LIST_ENTRY MiVerifierDriverAddedThunkListHead; 00022 ULONG MiActiveVerifierThunks; 00023 WCHAR MmVerifyDriverBuffer[512] = {0}; 00024 ULONG MmVerifyDriverBufferLength = sizeof(MmVerifyDriverBuffer); 00025 ULONG MmVerifyDriverBufferType = REG_NONE; 00026 ULONG MmVerifyDriverLevel = -1; 00027 PVOID MmTriageActionTaken; 00028 PVOID KernelVerifier; 00029 00030 /* PUBLIC FUNCTIONS ***********************************************************/ 00031 00032 /* 00033 * @unimplemented 00034 */ 00035 VOID 00036 NTAPI 00037 MmUnlockPageableImageSection(IN PVOID ImageSectionHandle) 00038 { 00039 UNIMPLEMENTED; 00040 } 00041 00042 /* 00043 * @unimplemented 00044 */ 00045 VOID 00046 NTAPI 00047 MmLockPageableSectionByHandle(IN PVOID ImageSectionHandle) 00048 { 00049 UNIMPLEMENTED; 00050 } 00051 00052 /* 00053 * @unimplemented 00054 */ 00055 PVOID 00056 NTAPI 00057 MmLockPageableDataSection(IN PVOID AddressWithinSection) 00058 { 00059 // 00060 // We should just find the section and call MmLockPageableSectionByHandle 00061 // 00062 static BOOLEAN Warn; if (!Warn++) UNIMPLEMENTED; 00063 return AddressWithinSection; 00064 } 00065 00066 /* 00067 * @unimplemented 00068 */ 00069 ULONG 00070 NTAPI 00071 MmTrimAllSystemPageableMemory(IN ULONG PurgeTransitionList) 00072 { 00073 UNIMPLEMENTED; 00074 return 0; 00075 } 00076 00077 /* 00078 * @implemented 00079 */ 00080 NTSTATUS 00081 NTAPI 00082 MmAddVerifierThunks(IN PVOID ThunkBuffer, 00083 IN ULONG ThunkBufferSize) 00084 { 00085 PDRIVER_VERIFIER_THUNK_PAIRS ThunkTable; 00086 ULONG ThunkCount; 00087 PDRIVER_SPECIFIED_VERIFIER_THUNKS DriverThunks; 00088 PLDR_DATA_TABLE_ENTRY LdrEntry; 00089 PVOID ModuleBase, ModuleEnd; 00090 ULONG i; 00091 NTSTATUS Status = STATUS_SUCCESS; 00092 PAGED_CODE(); 00093 00094 // 00095 // Make sure the driver verifier is initialized 00096 // 00097 if (!MiVerifierDriverAddedThunkListHead.Flink) return STATUS_NOT_SUPPORTED; 00098 00099 // 00100 // Get the thunk pairs and count them 00101 // 00102 ThunkCount = ThunkBufferSize / sizeof(DRIVER_VERIFIER_THUNK_PAIRS); 00103 if (!ThunkCount) return STATUS_INVALID_PARAMETER_1; 00104 00105 // 00106 // Now allocate our own thunk table 00107 // 00108 DriverThunks = ExAllocatePoolWithTag(PagedPool, 00109 sizeof(*DriverThunks) + 00110 ThunkCount * 00111 sizeof(DRIVER_VERIFIER_THUNK_PAIRS), 00112 'tVmM'); 00113 if (!DriverThunks) return STATUS_INSUFFICIENT_RESOURCES; 00114 00115 // 00116 // Now copy the driver-fed part 00117 // 00118 ThunkTable = (PDRIVER_VERIFIER_THUNK_PAIRS)(DriverThunks + 1); 00119 RtlCopyMemory(ThunkTable, 00120 ThunkBuffer, 00121 ThunkCount * sizeof(DRIVER_VERIFIER_THUNK_PAIRS)); 00122 00123 // 00124 // Acquire the system load lock 00125 // 00126 KeEnterCriticalRegion(); 00127 KeWaitForSingleObject(&MmSystemLoadLock, 00128 WrVirtualMemory, 00129 KernelMode, 00130 FALSE, 00131 NULL); 00132 00133 // 00134 // Get the loader entry 00135 // 00136 LdrEntry = MiLookupDataTableEntry(ThunkTable->PristineRoutine); 00137 if (!LdrEntry) 00138 { 00139 // 00140 // Fail 00141 // 00142 Status = STATUS_INVALID_PARAMETER_2; 00143 goto Cleanup; 00144 } 00145 00146 // 00147 // Get driver base and end 00148 // 00149 ModuleBase = LdrEntry->DllBase; 00150 ModuleEnd = (PVOID)((ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage); 00151 00152 // 00153 // Don't allow hooking the kernel or HAL 00154 // 00155 if (ModuleBase < (PVOID)(KSEG0_BASE + MmBootImageSize)) 00156 { 00157 // 00158 // Fail 00159 // 00160 Status = STATUS_INVALID_PARAMETER_2; 00161 goto Cleanup; 00162 } 00163 00164 // 00165 // Loop all the thunks 00166 // 00167 for (i = 0; i < ThunkCount; i++) 00168 { 00169 // 00170 // Make sure it's in the driver 00171 // 00172 if (((ULONG_PTR)ThunkTable->PristineRoutine < (ULONG_PTR)ModuleBase) || 00173 ((ULONG_PTR)ThunkTable->PristineRoutine >= (ULONG_PTR)ModuleEnd)) 00174 { 00175 // 00176 // Nope, fail 00177 // 00178 Status = STATUS_INVALID_PARAMETER_2; 00179 goto Cleanup; 00180 } 00181 } 00182 00183 // 00184 // Otherwise, add this entry 00185 // 00186 DriverThunks->DataTableEntry = LdrEntry; 00187 DriverThunks->NumberOfThunks = ThunkCount; 00188 MiActiveVerifierThunks++; 00189 InsertTailList(&MiVerifierDriverAddedThunkListHead, 00190 &DriverThunks->ListEntry); 00191 DriverThunks = NULL; 00192 00193 Cleanup: 00194 // 00195 // Release the lock 00196 // 00197 KeReleaseMutant(&MmSystemLoadLock, 1, FALSE, FALSE); 00198 KeLeaveCriticalRegion(); 00199 00200 // 00201 // Free the table if we failed and return status 00202 // 00203 if (DriverThunks) ExFreePool(DriverThunks); 00204 return Status; 00205 } 00206 00207 /* 00208 * @implemented 00209 */ 00210 LOGICAL 00211 NTAPI 00212 MmIsDriverVerifying(IN PDRIVER_OBJECT DriverObject) 00213 { 00214 PLDR_DATA_TABLE_ENTRY LdrEntry; 00215 00216 // 00217 // Get the loader entry 00218 // 00219 LdrEntry = (PLDR_DATA_TABLE_ENTRY)DriverObject->DriverSection; 00220 if (!LdrEntry) return FALSE; 00221 00222 // 00223 // Check if we're verifying or not 00224 // 00225 return (LdrEntry->Flags & LDRP_IMAGE_VERIFYING) ? TRUE: FALSE; 00226 } 00227 00228 /* 00229 * @implemented 00230 */ 00231 NTSTATUS 00232 NTAPI 00233 MmIsVerifierEnabled(OUT PULONG VerifierFlags) 00234 { 00235 // 00236 // Check if we've actually added anything to the list 00237 // 00238 if (MiVerifierDriverAddedThunkListHead.Flink) 00239 { 00240 // 00241 // We have, read the verifier level 00242 // 00243 *VerifierFlags = MmVerifierData.Level; 00244 return STATUS_SUCCESS; 00245 } 00246 00247 // 00248 // Otherwise, we're disabled 00249 // 00250 *VerifierFlags = 0; 00251 return STATUS_NOT_SUPPORTED; 00252 } 00253 00254 /* EOF */ Generated on Sat May 26 2012 04:36:21 for ReactOS by
1.7.6.1
|