I am in need to allocate a page in system space at a given virtual address. In user-mode you can simply use VirtualAlloc and pass in the preferred virtual base address, if free you get a page exactly at that virtual address. I am trying to achieve the same in system space. I was semi-successful to achieving this. I tried the following:
Code: Select all
I need to allocate a page closely to NTOSKRNL.exe in system space, how can I do this?void* not_working_page_base_address = (void*)0xfffff8006b01a000; // assume this is a free virtual address which isn't used by anything
void* working_page_base_address = (void*)0xfffffb0000001000; // assume this is a free virtual address which isn't used by anything
const auto mdl = IoAllocateMdl(working_page_base_address, 0x1000, false, false, nullptr);
if (mdl) {
MmProbeAndLockPages(mdl, KernelMode, IoModifyAccess);
// right now I can use the allocated memory at `working_page_base_address` nicely. But when I try to use a virtual address which is free/unused within the `0xfffff8` range, it seems to fail on `MmProbeAndLockPages`.
}