My driver is giving a bugcheck 0x50, which I’d like to avoid.
I think I know the root cause of the error (it’s misconfigured hardware) and
how to fix it (configure the hardware properly) but that isn’t the purpose
of my question: I’d like to be able to return a sensible error message, put
stuff in the event log etc., rather than blue screen.
The bugcheck occurs the first time I attempt to access the device memory at
the address returned by MmMapIoSpace.
The DDK says at the bottom of the discussion of bugcheck 0x50
“This cannot be protected by a try-except handler - it can only be protected
by a probe.”
I’ve looked at the 50 or so topics in the DDK brought up by a search for
“probe” but they either refer to the probing of user space memory, or use
the word in a context that obviously doesn’t apply.
So, temporarily disregarding the DDK (not usually a good idea), I wrote
BOOLEAN probe(PVOID addr, ULONG length)
{
PMDL probeMdl = IoAllocateMdl(addr, length, FALSE, FALSE, NULL);
if (probeMdl == NULL) return FALSE;
__try
{
__try
{
MmBuildMdlForNonPagedPool(probeMdl);
MmProbeAndLockPages(probeMdl, KernelMode, IoModifyAccess);
MmUnlockPages(probeMdl);
return TRUE;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
}
}
__finally
{
IoFreeMdl(probeMdl);
}
}
When I feed the routine with the (non NULL) address returned by
MmMapIoSpace, which in turn was supplied with the translated memory address
from the resource list in startdevice, I get two problems:
a) An assert fails in MmBuildMdlForNonPagedPool
*** Assertion failed: (MemoryDescriptorList->MdlFlags & ( MDL_PAGES_LOCKED |
MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL | MDL_PARTIAL |
MDL_IO_SPACE)) == 0
*** Source File: d:\srv03rtm\base\ntos\mm\iosup.c, line 347
The flags field is 0x804, which I read as (MDL_SOURCE_IS_NONPAGED_POOL |
MDL_IO_SPACE)
b) It bugchecks 0x50 inside MmProbeAndLockPages
Which brings me to my question: How do I perform the probe mentioned at the
bottom of the discussion of bugcheck 0x50?
Any help gratefully accepted.
I should perhaps add that I’m running the checked build of Server2003 and
would like my driver to run on Win2K and later. Thankfully, I can live
without 98, ME etc.
Don Ward