MCPcopy Create free account
hub / github.com/HoShiMin/Kernel-Bridge / DbgPrintMtrrEptCacheLayout

Function DbgPrintMtrrEptCacheLayout

Kernel-Bridge/API/Hypervisor.cpp:2535–2618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2533 }
2534
2535 static void DbgPrintMtrrEptCacheLayout(__in const EPT_TABLES* Ept, __in const MTRR_INFO* MtrrInfo)
2536 {
2537 auto MemTypeToStr = [](MTRR_MEMORY_TYPE MemType) -> const char*
2538 {
2539 switch (MemType)
2540 {
2541 case MTRR_MEMORY_TYPE::Uncacheable: return "Uncacheable (0)";
2542 case MTRR_MEMORY_TYPE::WriteCombining: return "WriteCombining (1)";
2543 case MTRR_MEMORY_TYPE::WriteThrough: return "WriteThrough (4)";
2544 case MTRR_MEMORY_TYPE::WriteProtected: return "WriteProtected (5)";
2545 case MTRR_MEMORY_TYPE::WriteBack: return "WriteBack (6)";
2546 default:
2547 return "Unknown";
2548 }
2549 };
2550
2551 MTRR_MEMORY_TYPE CurrentRangeType = MTRR_MEMORY_TYPE::Uncacheable;
2552 unsigned long long RangeBeginning = 0;
2553 for (unsigned int i = 0; i < _ARRAYSIZE(Ept->Pdpte); ++i)
2554 {
2555 for (unsigned int j = 0; j < _ARRAYSIZE(Ept->Pde[i]); ++j)
2556 {
2557 if (i == 0 && j == 0)
2558 {
2559 for (unsigned int k = 0; k < _ARRAYSIZE(Ept->PteForFirstLargePage); ++k)
2560 {
2561 auto Page = Ept->PteForFirstLargePage[k].Page4Kb;
2562 MTRR_MEMORY_TYPE MemType = static_cast<MTRR_MEMORY_TYPE>(Page.Type);
2563 unsigned long long PagePa = Page.PagePhysicalPfn * PAGE_SIZE;
2564 if (MemType != CurrentRangeType)
2565 {
2566 if ((PagePa - RangeBeginning) > 0)
2567 {
2568 DbgPrint("Physical range [%p..%p]: %s\r\n", reinterpret_cast<void*>(RangeBeginning), reinterpret_cast<void*>(PagePa - 1), MemTypeToStr(CurrentRangeType));
2569 }
2570 CurrentRangeType = MemType;
2571 RangeBeginning = PagePa;
2572 }
2573 }
2574 }
2575 else
2576 {
2577 constexpr unsigned long long PageSize = 2 * 1048576; // 2 Mb
2578
2579 auto Page = Ept->Pde[i][j].Page2Mb;
2580 MTRR_MEMORY_TYPE MemType = static_cast<MTRR_MEMORY_TYPE>(Page.Type);
2581 unsigned long long PagePa = Page.PagePhysicalPfn * PageSize;
2582 if (MemType != CurrentRangeType)
2583 {
2584 if ((PagePa - RangeBeginning) > 0)
2585 {
2586 DbgPrint("Physical range [%p..%p]: %s\r\n", reinterpret_cast<void*>(RangeBeginning), reinterpret_cast<void*>(PagePa - 1), MemTypeToStr(CurrentRangeType));
2587 }
2588 CurrentRangeType = MemType;
2589 RangeBeginning = PagePa;
2590 }
2591 }
2592 }

Callers 1

VirtualizeAllProcessorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected