Bewerken

Delen via


MM_BAD_POINTER

Note

This page previously contained a list of kernel macros, not just MM_BAD_POINTER. Those macros have now been broken out into their own individual pages. For links, use the See Also section below, or search the web.

Defined in: Wdm.h

Your driver can use the MM_BAD_POINTER macro as a bad pointer value to assign to a pointer variable that is either uninitialized or no longer valid. An attempt to access the memory location pointed to by this invalid pointer variable will cause a bug check.

On many hardware platforms, address 0 (frequently represented as named constant NULL) is an invalid address, but driver developers should not assume that address 0 is universally invalid across all platforms. Setting uninitialized or invalid pointer variables to address 0 might not always guarantee that inappropriate accesses through these pointers will be detected.

In contrast, the value MM_BAD_POINTER is guaranteed to be an invalid address on every platform on which a driver runs.

On platforms on which address 0 is an invalid address, a driver that accesses address 0 at IRQL < DISPATCH_LEVEL causes an exception (access violation) that can be inadvertently caught by a try/except statement. Thus, the driver's exception handling code might mask the invalid access and prevent it from being detected during debugging. However, an access of the MM_BAD_POINTER address is guaranteed to cause a bug check, which cannot be masked by an exception handler.

The following code example shows how to assign the value MM_BAD_POINTER to a pointer variable named ptr. The Ntdef.h header file defines the PUCHAR type to be a pointer to an unsigned char.

PUCHAR ptr = (PUCHAR)MM_BAD_POINTER; // Now _ptr is guaranteed to fault._

After ptr is set to MM_BAD_POINTER, an attempt to access the memory location pointed to by ptr will cause a bug check.

In fact, MM_BAD_POINTER is the base address of an entire page of invalid addresses. Therefore, any access of an address in the range MM_BAD_POINTER to (MM_BAD_POINTER + PAGE_SIZE - 1) will cause a bug check.

Starting with Windows 8.1, the MM_BAD_POINTER macro is defined in the Wdm.h header file. However, driver code that uses this macro definition can run in previous versions of Windows starting with Windows Vista.

Starting with Windows Vista, the MmBadPointer global variable is available as a pointer to a pointer value that is guaranteed to be an invalid address. However, starting with Windows 8.1, the use of MmBadPointer is deprecated, and you should update your drivers to use the MM_BAD_POINTER macro instead.

Available starting with Windows 8.1. Compatible with previous versions of Windows starting with Windows Vista.

See also