Search code examples
windowsdevice-driverkernelbsod

Kernel driver check if memory is mapped (BugCheck 0xC2)


This seems like such a simple issue but I cannot find an elegant solution. I've traced my driver down to a call to MmUnmapIoSpace, which produces a BugCheck 0xC2 {7,,,} message.

Is there a way to test if a particular area is mapped within a windows driver before calling MmUnmapIoSpace? I've checked if the pointer is NULL but it doesn't seem to be working.

I don't seem to see any documented/undocumented functions to test whether or not a call to MmUnmapIoSpace will produce a 0xC2 bugcheck.

Any fool-proof way to test this without holding a bunch of booleans or the like?


Solution

  • No, there is no function to check. Instead, I just wrapped the pointer in a struct which held a boolean that indicated if it had already been mapped.