| 292 | |
| 293 | _IRQL_requires_max_(APC_LEVEL) |
| 294 | BOOLEAN IsMemoryRangePresent(OPTIONAL PEPROCESS Process, PVOID Address, SIZE_T Size) |
| 295 | { |
| 296 | if (!Size) return FALSE; |
| 297 | |
| 298 | BOOLEAN NeedToAttach = Process && Process != PsGetCurrentProcess(); |
| 299 | KAPC_STATE ApcState; |
| 300 | if (NeedToAttach) |
| 301 | KeStackAttachProcess(Process, &ApcState); |
| 302 | |
| 303 | BOOLEAN IsPresent = TRUE; |
| 304 | |
| 305 | PVOID Page = Address; |
| 306 | do { |
| 307 | ULONG PageSize = 0; |
| 308 | IsPresent = IsPagePresent(Address, &PageSize) && PageSize; |
| 309 | if (!IsPresent) break; |
| 310 | Page = reinterpret_cast<PVOID>(reinterpret_cast<SIZE_T>(ALIGN_DOWN_POINTER_BY(Page, PageSize)) + PageSize); |
| 311 | } while (Page < reinterpret_cast<PVOID>(reinterpret_cast<SIZE_T>(Address) + Size)); |
| 312 | |
| 313 | if (NeedToAttach) |
| 314 | KeUnstackDetachProcess(&ApcState); |
| 315 | |
| 316 | return IsPresent; |
| 317 | } |
| 318 | } |
no test coverage detected