IO_SESSION_NOTIFICATION_FUNCTION callback function (wdm.h)

The IO_SESSION_NOTIFICATION_FUNCTION function type defines a callback routine through which a driver receives notifications of changes in the state of user sessions that the driver is interested in.

Syntax

IO_SESSION_NOTIFICATION_FUNCTION IoSessionNotificationFunction;

NTSTATUS IoSessionNotificationFunction(
  [in] PVOID SessionObject,
  [in] PVOID IoObject,
  [in] ULONG Event,
  [in] PVOID Context,
  [in] PVOID NotificationPayload,
  [in] ULONG PayloadLength
)
{...}

Parameters

[in] SessionObject

Pointer to an opaque, system object that contains information about the user session. The driver can pass this pointer value to the IoGetContainerInformation routine as the ContainerObject parameter value.

[in] IoObject

Pointer to an I/O object owned by the driver. This parameter is the I/O object pointer that the driver supplied to the IoRegisterContainerNotification routine when the driver previously registered to receive notifications of session events. The IoRegisterContainerNotification routine's NotificationInformation parameter points to an IO_SESSION_STATE_NOTIFICATION structure whose IoObject member points to the I/O object.

[in] Event

An IO_SESSION_EVENT enumeration constant that indicates which session event caused the notification callback.

[in] Context

The context value that the driver previously supplied to the IoRegisterContainerNotification routine when the driver registered to receive notifications of session events. In the IoRegisterContainerNotification call, the driver supplied a pointer to an IO_SESSION_STATE_NOTIFICATION structure whose Context member contains the context value.

[in] NotificationPayload

Pointer to a payload buffer that contains an IO_SESSION_CONNECT_INFO structure.

[in] PayloadLength

The size, in bytes, of the buffer pointed to by NotificationPayload. The buffer size never needs exceeds the constant value IO_SESSION_MAX_PAYLOAD_SIZE, which is defined in the Wdm.h header file.

Return value

If the routine succeeds, it must return STATUS_SUCCESS. Otherwise, it must return one of the error status values defined in the Ntstatus.h header file.

Remarks

A kernel-mode driver implements this routine. The I/O manager calls this routine to notify the driver of session events.

To receive notifications of session events, a driver calls the IoRegisterContainerNotification routine and sets this routine's CallbackFunction parameter to point to the driver's IO_SESSION_NOTIFICATION_FUNCTION routine. The I/O object that the driver passes to IoRegisterContainerNotification determines whether the driver will receive notifications of events in a particular user session or of events in all sessions. For more information, see IO_SESSION_STATE_NOTIFICATION.

Examples

To define an I/O-session notification routine, you must first provide a function declaration that identifies the type of callback routine you're defining. Windows provides a set of callback function types for drivers. Declaring a function using the callback function types helps Code Analysis for Drivers, Static Driver Verifier (SDV), and other verification tools find errors, and it's a requirement for writing drivers for the Windows operating system.

For example, to define an I/O-session notification routine that is named MyIoSessionNotification, use the IO_SESSION_NOTIFICATION_FUNCTION type as shown in this code example:

IO_SESSION_NOTIFICATION_FUNCTION MyIoSessionNotification;

Then, implement your callback routine as follows:

_Use_decl_annotations_
NTSTATUS
  MyIoSessionNotification(
    PVOID  SessionObject,
    PVOID  IoObject,
    ULONG  Event,
    PVOID  Context,
    PVOID  NotificationPayload,
    ULONG  PayloadLength
    )
  {
      // Function body
  }

The IO_SESSION_NOTIFICATION_FUNCTION function type is defined in the Wdm.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the _Use_decl_annotations_ annotation to your function definition. The _Use_decl_annotations_ annotation ensures that the annotations that are applied to the IO_SESSION_NOTIFICATION_FUNCTION function type in the header file are used. For more information about the requirements for function declarations, see Declaring Functions by Using Function Role Types for WDM Drivers. For information about _Use_decl_annotations_, see Annotating Function Behavior.

Requirements

Requirement Value
Minimum supported client Supported in Windows 7 and later versions of the Windows operating system.
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h, Fltkernel.h)
IRQL Called at IRQL <= APC_LEVEL.

See also

IO_SESSION_CONNECT_INFO

IO_SESSION_EVENT

IO_SESSION_STATE_NOTIFICATION

IoGetContainerInformation

IoRegisterContainerNotification