MSDN Documentation

Overview

The Windows Interrupt API provides mechanisms for handling hardware and software interrupts within kernel-mode drivers. It enables drivers to register interrupt service routines (ISRs), synchronize with the operating system, and manage interrupt objects.

Interrupt Types

TypeDescription
Level‑SensitiveTriggered while the interrupt line is active.
Edge‑TriggeredTriggered on a transition of the interrupt line.
Message Signaled Interrupts (MSI)Interrupts delivered via PCIe messages.

Key Functions

NTSTATUS IoConnectInterrupt(
    PKINTERRUPT *InterruptObject,
    PKSERVICE_ROUTINE ServiceRoutine,
    PVOID ServiceContext,
    PKSPIN_LOCK SpinLock,
    ULONG Vector,
    KIRQL Irql,
    KIRQL SynchronizeIrql,
    KINTERRUPT_MODE InterruptMode,
    BOOLEAN ShareVector,
    KAFFINITY ProcessorEnableMask,
    BOOLEAN FloatingSave
);
VOID IoDisconnectInterrupt(
    PKINTERRUPT InterruptObject
);

Example Usage

#include <ntddk.h>

VOID MyInterruptServiceRoutine(
    PKINTERRUPT Interrupt,
    PVOID ServiceContext
)
{
    UNREFERENCED_PARAMETER(Interrupt);
    UNREFERENCED_PARAMETER(ServiceContext);
    // Handle the interrupt
}

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    UNREFERENCED_PARAMETER(RegistryPath);
    PKINTERRUPT interruptObject = NULL;
    NTSTATUS status;

    status = IoConnectInterrupt(
        &interruptObject,
        MyInterruptServiceRoutine,
        NULL,
        NULL,
        0x80,               // Vector
        DIRQL,              // Irql
        DIRQL,              // SynchronizeIrql
        LevelSensitive,    // Mode
        FALSE,              // ShareVector
        0xFFFFFFFF,         // ProcessorEnableMask
        FALSE               // FloatingSave
    );

    if (!NT_SUCCESS(status)) {
        KdPrint(("Failed to connect interrupt: 0x%X\n", status));
        return status;
    }

    DriverObject->DriverUnload = DriverUnload;
    return STATUS_SUCCESS;
}

VOID DriverUnload(PDRIVER_OBJECT DriverObject)
{
    UNREFERENCED_PARAMETER(DriverObject);
    IoDisconnectInterrupt(interruptObject);
}

Remarks

  • Always validate parameters before calling IoConnectInterrupt.
  • For MSI, use IoConnectInterruptEx with the CM_RESOURCE_TYPE_INTERRUPT descriptor.
  • Synchronize access to shared data within the ISR using spin locks.

See Also