_Assert_Range

#include vmm.h 

_Assert_Range(DWORD pStruc, DWORD ulSize, DWORD sSignature, 
              DWORD lSignatureOffset, DWORD ulFlags);
 

Verifies that a pointer to any structure is valid. Uses the C calling convention.

pStruc
Structure pointer to validate.
ulSize
Size of the structure in bytes.
sSignature
A DWORD value to validate.
lSignatureOffset
Offset in bytes to sSignature.
ulFlags
Validation flags. May be one or more of these values:
ASSERT_RANGE_NULL_BAD Return failure for NULL pointers. May not be combined with ASSERT_RANGE_NULL_OK.
ASSERT_RANGE_NULL_OK Return success for NULL pointers. May not be combined with ASSERT_RANGE_NULL_BAD.
ASSERT_RANGE_NO_DEBUG Do not output a debugging message on failure when debugger is present. This flag is ignored if no debugger is installed.

The following validation steps are taken.

  1. If pStruc is a null pointer, its validity is determined by which of the ASSERT_RANGE_NULL_BAD or ASSERT_RANGE_NULL_OK flags is passed.
  2. Otherwise, pStruc must be a pointer to valid data of length ulSize bytes.
  3. Furthermore, if sSignature is nonzero, then the DWORD at pStruc + lSignatureOffset must be equal to sSignature.

For example, suppose you have a structure defined as follows:

struct ABC {
    DWORD member1;
    BYTE  member2[20];
    DWORD dwSignature;
};

// Every valid ABC has ABCSIGNATURE stored in the dwSignature field.

#define ABCSIGNATURE 0x31415926
 

If you want to check whether some pointer variable p is a valid pointer to a ABC, except that null pointers are okay, then you would write

if (!_Assert_Range(p, sizeof(SAMPLE), ABCSIGNATURE, 
    offsetof( SAMPLE, dwSignature), ASSERT_RANGE_NULL_OK)) {
       return ERROR_INVALID_PARAMETER;
    }
 

This service can be called only at a time when page faults can safely be handled. It cannot be called at hardware interrupt time, nor at any other time when paging is not allowed. Since this service touches the memory at pStruc as part of the validation (even if sSignature is zero), if pStruc points to a phys/linear region owned by memory-mapped hardware, there may be unusual side-effects.