- Timestamp:
- Dec 15, 2017 2:51:54 PM (7 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv/nt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp
r70151 r70152 88 88 * This API was introduced in XP. */ 89 89 decltype(MmProtectMdlSystemAddress) *g_pfnrtMmProtectMdlSystemAddress; 90 /** MmAllocatePagesForMdl - Introduced in Windows 2000. */ 91 decltype(MmAllocatePagesForMdl) *g_pfnrtMmAllocatePagesForMdl; 92 /** MmFreePagesFromMdl - Introduced in Windows 2000. */ 93 decltype(MmFreePagesFromMdl) *g_pfnrtMmFreePagesFromMdl; 94 /** MmMapLockedPagesSpecifyCache - Introduced in Windows NT4 SP4. */ 95 decltype(MmMapLockedPagesSpecifyCache) *g_pfnrtMmMapLockedPagesSpecifyCache; 96 /** MmAllocateContiguousMemorySpecifyCache - Introduced in Windows 2000. */ 97 decltype(MmAllocateContiguousMemorySpecifyCache) *g_pfnrtMmAllocateContiguousMemorySpecifyCache; 90 98 /** RtlGetVersion, introduced in ??. */ 91 99 PFNRTRTLGETVERSION g_pfnrtRtlGetVersion; … … 282 290 GET_SYSTEM_ROUTINE(KeDeregisterProcessorChangeCallback); 283 291 GET_SYSTEM_ROUTINE(MmProtectMdlSystemAddress); 292 GET_SYSTEM_ROUTINE(MmAllocatePagesForMdl); 293 GET_SYSTEM_ROUTINE(MmFreePagesFromMdl); 294 GET_SYSTEM_ROUTINE(MmMapLockedPagesSpecifyCache); 295 GET_SYSTEM_ROUTINE(MmAllocateContiguousMemorySpecifyCache); 284 296 285 297 GET_SYSTEM_ROUTINE_TYPE(RtlGetVersion, PFNRTRTLGETVERSION); -
trunk/src/VBox/Runtime/r0drv/nt/internal-r0drv-nt.h
r70151 r70152 81 81 extern PFNKEDEREGISTERPROCESSORCHANGECALLBACK g_pfnrtKeDeregisterProcessorChangeCallback; 82 82 extern decltype(MmProtectMdlSystemAddress) *g_pfnrtMmProtectMdlSystemAddress; 83 extern decltype(MmAllocatePagesForMdl) *g_pfnrtMmAllocatePagesForMdl; 84 extern decltype(MmFreePagesFromMdl) *g_pfnrtMmFreePagesFromMdl; 85 extern decltype(MmMapLockedPagesSpecifyCache) *g_pfnrtMmMapLockedPagesSpecifyCache; 86 extern decltype(MmAllocateContiguousMemorySpecifyCache) *g_pfnrtMmAllocateContiguousMemorySpecifyCache; 83 87 extern PFNRTRTLGETVERSION g_pfnrtRtlGetVersion; 84 88 #ifndef RT_ARCH_AMD64 -
trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp
r70150 r70152 39 39 #include <iprt/process.h> 40 40 #include "internal/memobj.h" 41 #include "internal-r0drv-nt.h" 41 42 42 43 … … 66 67 /** The core structure. */ 67 68 RTR0MEMOBJINTERNAL Core; 68 #ifndef IPRT_TARGET_NT469 69 /** Used MmAllocatePagesForMdl(). */ 70 70 bool fAllocatedPagesForMdl; 71 #endif72 71 /** Pointer returned by MmSecureVirtualMemory */ 73 72 PVOID pvSecureMem; … … 90 89 { 91 90 case RTR0MEMOBJTYPE_LOW: 92 #ifndef IPRT_TARGET_NT493 91 if (pMemNt->fAllocatedPagesForMdl) 94 92 { … … 102 100 } 103 101 104 MmFreePagesFromMdl(pMemNt->apMdls[0]);102 g_pfnrtMmFreePagesFromMdl(pMemNt->apMdls[0]); 105 103 ExFreePool(pMemNt->apMdls[0]); 106 104 pMemNt->apMdls[0] = NULL; … … 108 106 break; 109 107 } 110 #endif111 108 AssertFailed(); 112 109 break; … … 138 135 if (!pMemNt->Core.u.Phys.fAllocated) 139 136 { 140 #ifndef IPRT_TARGET_NT4141 137 Assert(!pMemNt->fAllocatedPagesForMdl); 142 #endif143 138 /* Nothing to do here. */ 144 139 break; … … 147 142 148 143 case RTR0MEMOBJTYPE_PHYS_NC: 149 #ifndef IPRT_TARGET_NT4150 144 if (pMemNt->fAllocatedPagesForMdl) 151 145 { 152 MmFreePagesFromMdl(pMemNt->apMdls[0]);146 g_pfnrtMmFreePagesFromMdl(pMemNt->apMdls[0]); 153 147 ExFreePool(pMemNt->apMdls[0]); 154 148 pMemNt->apMdls[0] = NULL; … … 156 150 break; 157 151 } 158 #endif159 152 AssertFailed(); 160 153 break; … … 286 279 } 287 280 288 #ifndef IPRT_TARGET_NT4289 281 /* 290 282 * Use MmAllocatePagesForMdl to specify the range of physical addresses we wish to use. 291 283 */ 292 PHYSICAL_ADDRESS Zero;293 Zero.QuadPart = 0;294 PHYSICAL_ADDRESS HighAddr;295 HighAddr.QuadPart = _4G - 1;296 PMDL pMdl = MmAllocatePagesForMdl(Zero, HighAddr, Zero, cb);297 if (pMdl)298 {299 if (MmGetMdlByteCount(pMdl) >= cb)300 {301 __try302 303 void *pv = MmMapLockedPagesSpecifyCache(pMdl, KernelMode, MmCached, NULL /* no base address */,304 FALSE /* no bug check on failure */, NormalPagePriority);305 if (pv)284 if ( g_pfnrtMmAllocatePagesForMdl 285 && g_pfnrtMmFreePagesFromMdl 286 && g_pfnrtMmMapLockedPagesSpecifyCache) 287 { 288 PHYSICAL_ADDRESS Zero; 289 Zero.QuadPart = 0; 290 PHYSICAL_ADDRESS HighAddr; 291 HighAddr.QuadPart = _4G - 1; 292 PMDL pMdl = g_pfnrtMmAllocatePagesForMdl(Zero, HighAddr, Zero, cb); 293 if (pMdl) 294 { 295 if (MmGetMdlByteCount(pMdl) >= cb) 296 { 297 __try 306 298 { 307 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_LOW, pv, cb); 308 if (pMemNt) 299 void *pv = g_pfnrtMmMapLockedPagesSpecifyCache(pMdl, KernelMode, MmCached, NULL /* no base address */, 300 FALSE /* no bug check on failure */, NormalPagePriority); 301 if (pv) 309 302 { 310 pMemNt->fAllocatedPagesForMdl = true; 311 pMemNt->cMdls = 1; 312 pMemNt->apMdls[0] = pMdl; 313 *ppMem = &pMemNt->Core; 314 return VINF_SUCCESS; 303 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_LOW, pv, cb); 304 if (pMemNt) 305 { 306 pMemNt->fAllocatedPagesForMdl = true; 307 pMemNt->cMdls = 1; 308 pMemNt->apMdls[0] = pMdl; 309 *ppMem = &pMemNt->Core; 310 return VINF_SUCCESS; 311 } 312 MmUnmapLockedPages(pv, pMdl); 315 313 } 316 MmUnmapLockedPages(pv, pMdl);317 314 } 318 } 319 __except(EXCEPTION_EXECUTE_HANDLER) 320 { 315 __except(EXCEPTION_EXECUTE_HANDLER) 316 { 321 317 # ifdef LOG_ENABLED 322 NTSTATUS rcNt = GetExceptionCode();323 Log(("rtR0MemObjNativeAllocLow: Exception Code %#x\n", rcNt));318 NTSTATUS rcNt = GetExceptionCode(); 319 Log(("rtR0MemObjNativeAllocLow: Exception Code %#x\n", rcNt)); 324 320 # endif 325 /* nothing */326 }327 }328 MmFreePagesFromMdl(pMdl);329 ExFreePool(pMdl);330 }331 #endif /* !IPRT_TARGET_NT4 */ 321 /* nothing */ 322 } 323 } 324 g_pfnrtMmFreePagesFromMdl(pMdl); 325 ExFreePool(pMdl); 326 } 327 } 332 328 333 329 /* … … 356 352 AssertMsgReturn(cb <= _1G, ("%#x\n", cb), VERR_OUT_OF_RANGE); /* for safe size_t -> ULONG */ 357 353 RT_NOREF1(fExecutable); 358 #ifdef IPRT_TARGET_NT4 359 if (uAlignment != PAGE_SIZE) 354 355 /* 356 * Allocate the memory and create an MDL for it. 357 */ 358 PHYSICAL_ADDRESS PhysAddrHighest; 359 PhysAddrHighest.QuadPart = PhysHighest; 360 void *pv; 361 if (g_pfnrtMmAllocateContiguousMemorySpecifyCache) 362 { 363 PHYSICAL_ADDRESS PhysAddrLowest, PhysAddrBoundary; 364 PhysAddrLowest.QuadPart = 0; 365 PhysAddrBoundary.QuadPart = (uAlignment == PAGE_SIZE) ? 0 : uAlignment; 366 pv = MmAllocateContiguousMemorySpecifyCache(cb, PhysAddrLowest, PhysAddrHighest, PhysAddrBoundary, MmCached); 367 } 368 else if (uAlignment == PAGE_SIZE) 369 pv = MmAllocateContiguousMemory(cb, PhysAddrHighest); 370 else 360 371 return VERR_NOT_SUPPORTED; 361 #endif362 363 /*364 * Allocate the memory and create an MDL for it.365 */366 PHYSICAL_ADDRESS PhysAddrHighest;367 PhysAddrHighest.QuadPart = PhysHighest;368 #ifndef IPRT_TARGET_NT4369 PHYSICAL_ADDRESS PhysAddrLowest, PhysAddrBoundary;370 PhysAddrLowest.QuadPart = 0;371 PhysAddrBoundary.QuadPart = (uAlignment == PAGE_SIZE) ? 0 : uAlignment;372 void *pv = MmAllocateContiguousMemorySpecifyCache(cb, PhysAddrLowest, PhysAddrHighest, PhysAddrBoundary, MmCached);373 #else374 void *pv = MmAllocateContiguousMemory(cb, PhysAddrHighest);375 #endif376 372 if (!pv) 377 373 return VERR_NO_MEMORY; … … 410 406 DECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment) 411 407 { 412 #ifndef IPRT_TARGET_NT4413 408 /* 414 409 * Try and see if we're lucky and get a contiguous chunk from MmAllocatePagesForMdl. … … 424 419 */ 425 420 if ( cb < _128K 426 && uAlignment == PAGE_SIZE) 427 421 && uAlignment == PAGE_SIZE 422 && g_pfnrtMmAllocatePagesForMdl 423 && g_pfnrtMmFreePagesFromMdl) 428 424 { 429 425 PHYSICAL_ADDRESS Zero; … … 431 427 PHYSICAL_ADDRESS HighAddr; 432 428 HighAddr.QuadPart = PhysHighest == NIL_RTHCPHYS ? MAXLONGLONG : PhysHighest; 433 PMDL pMdl = MmAllocatePagesForMdl(Zero, HighAddr, Zero, cb);429 PMDL pMdl = g_pfnrtMmAllocatePagesForMdl(Zero, HighAddr, Zero, cb); 434 430 if (pMdl) 435 431 { … … 458 454 } 459 455 } 460 MmFreePagesFromMdl(pMdl);456 g_pfnrtMmFreePagesFromMdl(pMdl); 461 457 ExFreePool(pMdl); 462 458 } 463 459 } 464 #endif /* !IPRT_TARGET_NT4 */465 460 466 461 return rtR0MemObjNativeAllocContEx(ppMem, cb, false, PhysHighest, uAlignment); … … 470 465 DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest) 471 466 { 472 #ifndef IPRT_TARGET_NT4 473 PHYSICAL_ADDRESS Zero;474 Zero.QuadPart = 0;475 PHYSICAL_ADDRESS HighAddr;476 HighAddr.QuadPart = PhysHighest == NIL_RTHCPHYS ? MAXLONGLONG : PhysHighest;477 PMDL pMdl = MmAllocatePagesForMdl(Zero, HighAddr, Zero, cb);478 if (pMdl)479 {480 if (MmGetMdlByteCount(pMdl) >= cb)481 {482 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS_NC, NULL, cb);483 if (pMemNt)484 {485 pMemNt->fAllocatedPagesForMdl = true;486 pMemNt->cMdls = 1;487 pMemNt->apMdls[0] = pMdl;488 *ppMem = &pMemNt->Core;489 return VINF_SUCCESS;490 }491 }492 MmFreePagesFromMdl(pMdl);493 ExFreePool(pMdl);494 }495 return VERR_NO_MEMORY;496 #else /* IPRT_TARGET_NT4 */ 497 RT_NOREF(ppMem, cb, PhysHighest);467 if (g_pfnrtMmAllocatePagesForMdl && g_pfnrtMmFreePagesFromMdl) 468 { 469 PHYSICAL_ADDRESS Zero; 470 Zero.QuadPart = 0; 471 PHYSICAL_ADDRESS HighAddr; 472 HighAddr.QuadPart = PhysHighest == NIL_RTHCPHYS ? MAXLONGLONG : PhysHighest; 473 PMDL pMdl = g_pfnrtMmAllocatePagesForMdl(Zero, HighAddr, Zero, cb); 474 if (pMdl) 475 { 476 if (MmGetMdlByteCount(pMdl) >= cb) 477 { 478 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS_NC, NULL, cb); 479 if (pMemNt) 480 { 481 pMemNt->fAllocatedPagesForMdl = true; 482 pMemNt->cMdls = 1; 483 pMemNt->apMdls[0] = pMdl; 484 *ppMem = &pMemNt->Core; 485 return VINF_SUCCESS; 486 } 487 } 488 g_pfnrtMmFreePagesFromMdl(pMdl); 489 ExFreePool(pMdl); 490 } 491 return VERR_NO_MEMORY; 492 } 498 493 return VERR_NOT_SUPPORTED; 499 #endif /* IPRT_TARGET_NT4 */500 494 } 501 495 … … 718 712 return VERR_NOT_SUPPORTED; 719 713 720 #ifdef IPRT_TARGET_NT4 721 /* NT SP0 can't map to a specific address. */ 722 if (pvFixed != (void *)-1) 714 /* Need g_pfnrtMmMapLockedPagesSpecifyCache to map to a specific address. */ 715 if (pvFixed != (void *)-1 && g_pfnrtMmMapLockedPagesSpecifyCache == NULL) 723 716 return VERR_NOT_SUPPORTED; 724 #endif725 717 726 718 /* we can't map anything to the first page, sorry. */ … … 737 729 /** @todo uAlignment */ 738 730 /** @todo How to set the protection on the pages? */ 739 #ifdef IPRT_TARGET_NT4 740 void *pv = MmMapLockedPages(pMemNtToMap->apMdls[0],741 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode);742 #else 743 void *pv = MmMapLockedPagesSpecifyCache(pMemNtToMap->apMdls[0],744 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode,745 MmCached,746 pvFixed != (void *)-1 ? pvFixed : NULL,747 FALSE /* no bug check on failure */,748 NormalPagePriority);749 #endif 731 void *pv; 732 if (g_pfnrtMmMapLockedPagesSpecifyCache) 733 pv = g_pfnrtMmMapLockedPagesSpecifyCache(pMemNtToMap->apMdls[0], 734 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode, 735 MmCached, 736 pvFixed != (void *)-1 ? pvFixed : NULL, 737 FALSE /* no bug check on failure */, 738 NormalPagePriority); 739 else 740 pv = MmMapLockedPages(pMemNtToMap->apMdls[0], 741 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode); 750 742 if (pv) 751 743 {
Note:
See TracChangeset
for help on using the changeset viewer.