Compartilhar via


Pointer Annotations

Certain driver functions take a PVOID as a parameter, so they can accept any one of a number of different types. It is a common error to pass the wrong type by mistake, for example, to pass &pStruct instead of pStruct as intended. For any type but PVOID, the compiler would diagnose this as an error. For the PVOID type, the compiler cannot detect the error because it has no type information to check.

Use the __drv_notPointer and __drv_isObjectPointer annotations to diagnose errors when a parameter must not be a pointer.

  • __drv_notPointer
    The __drv_notPointer annotation indicates that the parameter must be a struct or scalar value. This annotation is typically applied as __drv_deref(__drv_notPointer), which indicates that the parameter should be a pointer to a nonpointer object.

  • __drv_isObjectPointer
    The __drv_isObjectPointer annotation indicates that the parameter must be a pointer to a nonpointer object. This annotation is equivalent to __drv_deref(__drv_notPointer).

Example

The following annotation on the Object parameter of KeWaitForSingleObject causes PFD to issue a warning if the function is called with Object as a pointer to a pointer.

NTSTATUS 
  KeWaitForSingleObject(
    __in __drv_isObjectPointer PVOID Object,
    __in 
       __drv_strictTypeMatch(__drv_typeConst)
    KWAIT_REASON  WaitReason,
    __in 
 __drv_strictType(KPROCESSOR_MODE/enum _MODE,
 __drv_typeCond)
    KPROCESSOR_MODE  WaitMode,
    __in BOOLEAN  Alertable,
    __in_opt PLARGE_INTEGER Timeout
    );

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011