QuasiCodo
2010-09-14 10:46:29 UTC
I'm trying to manage my own virtual address space from my driver, but I
am having trouble when try to allocate, map and lock a subset of the VA
space. Here is what I am doing:
// Allocate our virtual address space
// Start at 1 TB and work our way down
va_space_size = MAX_VA_SPACE_SIZE;
do
{
va_space = MmAllocateMappingAddress (
pgallctr.va_space_size,
PGALLCTR_TAG);
if ( !va_space )
{
// Negoiate to smaller size
va_space_size >>= 1;
if ( va_space_size < MIN_VA_SPACE_SIZE )
{
error ("Cannot allocate VA space!\n");
goto Exit;
}
}
} while (!va_space);
alloc_size = 128 * 1024 * 1024;
//mdl = IoAllocateMdl (ptr, alloc_size, FALSE, FALSE, NULL);
//if ( !mdl )
//{
// error ("IoAllcateMdl failed\n");
// goto Exit;
//}
low.QuadPart = 0;
high.QuadPart = 0xFFFFFFFFFFFFFFFF;
skip.QuadPart = PAGE_SIZE;
mdl = MmAllocatePagesForMdlEx (low, high, skip, alloc_size,
MmNonCached, 0);
if ( !mdl )
{
error ("MmAllocatePagesForMdlEx failed\n");
goto Exit;
}
{
// Probe and lock pages
MmProbeAndLockPages (mdl, KernelMode, IoWriteAccess);
locked = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
error ("MmProbeAndLockPages failed, status = 0x%x\n",
GetExceptionCode());
goto Exit;
}
I would appreciate any help or reference.
thx,
((&->
am having trouble when try to allocate, map and lock a subset of the VA
space. Here is what I am doing:
// Allocate our virtual address space
// Start at 1 TB and work our way down
va_space_size = MAX_VA_SPACE_SIZE;
do
{
va_space = MmAllocateMappingAddress (
pgallctr.va_space_size,
PGALLCTR_TAG);
if ( !va_space )
{
// Negoiate to smaller size
va_space_size >>= 1;
if ( va_space_size < MIN_VA_SPACE_SIZE )
{
error ("Cannot allocate VA space!\n");
goto Exit;
}
}
} while (!va_space);
I actually get 64 GB of VA space allocated -- which is plenty for my
purposes
I tried two different ways to allocate an MLD
// Allocate an MDL for the slot addresspurposes
I tried two different ways to allocate an MLD
alloc_size = 128 * 1024 * 1024;
//mdl = IoAllocateMdl (ptr, alloc_size, FALSE, FALSE, NULL);
//if ( !mdl )
//{
// error ("IoAllcateMdl failed\n");
// goto Exit;
//}
low.QuadPart = 0;
high.QuadPart = 0xFFFFFFFFFFFFFFFF;
skip.QuadPart = PAGE_SIZE;
mdl = MmAllocatePagesForMdlEx (low, high, skip, alloc_size,
MmNonCached, 0);
if ( !mdl )
{
error ("MmAllocatePagesForMdlEx failed\n");
goto Exit;
}
I don't know if I need this following line
MmBuildMdlForNonPagedPool (mdl);When I try to probe and lock, MmProbeAndLockPages() throws an
EXCEPTION_EXECUTION_HANDLER exception with status 0xC0000005,
which is an access violation.
__tryEXCEPTION_EXECUTION_HANDLER exception with status 0xC0000005,
which is an access violation.
{
// Probe and lock pages
MmProbeAndLockPages (mdl, KernelMode, IoWriteAccess);
locked = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
error ("MmProbeAndLockPages failed, status = 0x%x\n",
GetExceptionCode());
goto Exit;
}
I would appreciate any help or reference.
thx,
((&->