Table of Contents
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
| Type | Description |
|---|---|
| Level‑Sensitive | Triggered while the interrupt line is active. |
| Edge‑Triggered | Triggered 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
IoConnectInterruptExwith theCM_RESOURCE_TYPE_INTERRUPTdescriptor. - Synchronize access to shared data within the ISR using spin locks.