| 1229 | } |
| 1230 | |
| 1231 | void InterceptPage( |
| 1232 | unsigned long long Pa, |
| 1233 | unsigned long long ReadPa, |
| 1234 | unsigned long long WritePa, |
| 1235 | unsigned long long ExecutePa, |
| 1236 | unsigned long long ExecuteReadPa, |
| 1237 | unsigned long long ExecuteWritePa |
| 1238 | ) { |
| 1239 | unsigned long long Pa4Kb = ALIGN_DOWN_BY(Pa, PageSize); |
| 1240 | auto HandlerEntry = m_Handlers.find(Pa4Kb); |
| 1241 | if (HandlerEntry != m_Handlers.end()) |
| 1242 | { |
| 1243 | PAGE_HANDLER Handler = {}; |
| 1244 | BuildPageHandler(static_cast<MTRR_MEMORY_TYPE>(HandlerEntry->second.Handlers.OnRead.Page4Kb.Type), ReadPa, WritePa, ExecutePa, ExecuteReadPa, ExecuteWritePa, OUT Handler); |
| 1245 | HandlerEntry->second.Handlers = Handler; |
| 1246 | *HandlerEntry->second.Pte = Handler.OnRead; |
| 1247 | invept(); |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | unsigned long long Pa2Mb = ALIGN_DOWN_BY(Pa, LargePageSize); |
| 1252 | auto DescriptorEntry = m_PageDescriptors.find(Pa2Mb); |
| 1253 | if (DescriptorEntry == m_PageDescriptors.end()) |
| 1254 | { |
| 1255 | EPT_ENTRIES EptEntries; |
| 1256 | GetEptEntries(Pa2Mb, *m_Ept, OUT EptEntries); |
| 1257 | |
| 1258 | LARGE_PAGE_DESCRIPTOR Desc = { |
| 1259 | .Pde = EptEntries.Pde, |
| 1260 | .OriginalPde = *EptEntries.Pde, |
| 1261 | .Layout = reinterpret_cast<LARGE_PAGE_LAYOUT*>(Supplementation::AllocPhys(sizeof(LARGE_PAGE_LAYOUT))) |
| 1262 | }; |
| 1263 | |
| 1264 | BuildPtesForPde(Desc.OriginalPde, OUT *Desc.Layout); |
| 1265 | |
| 1266 | DescriptorEntry = m_PageDescriptors.emplace(Pa2Mb, Desc).first; |
| 1267 | } |
| 1268 | |
| 1269 | auto& Descriptor = DescriptorEntry->second; |
| 1270 | auto* Pde = &Descriptor.Pde->Page4Kb; |
| 1271 | Pde->LargePage = FALSE; |
| 1272 | Pde->Reserved0 = 0; |
| 1273 | Pde->EptPtePhysicalPfn = PAGE_TO_PFN(reinterpret_cast<uint64_t>(PhysicalMemory::GetPhysicalAddress(Descriptor.Layout))); |
| 1274 | |
| 1275 | unsigned long long PteIndex = (Pa - Pa2Mb) / PageSize; |
| 1276 | auto* Pte = &Descriptor.Layout->Pte[PteIndex]; |
| 1277 | |
| 1278 | EPT_PTE_HANDLER Handler = {}; |
| 1279 | BuildPageHandler(static_cast<MTRR_MEMORY_TYPE>(DescriptorEntry->second.OriginalPde.Page2Mb.Type), ReadPa, WritePa, ExecutePa, ExecuteReadPa, ExecuteWritePa, OUT Handler.Handlers); |
| 1280 | Handler.Pte = Pte; |
| 1281 | m_Handlers.emplace(Pa4Kb, Handler); |
| 1282 | |
| 1283 | *Pte = Handler.Handlers.OnRead; |
| 1284 | invept(); |
| 1285 | } |
| 1286 | |
| 1287 | void DeinterceptPage(unsigned long long Pa) |
| 1288 | { |
no test coverage detected