Geoff Chappell, Software Analyst
This function copies data to an IRP as its generic IRP extension.
NTSTATUS IoSetGenericIrpExtension ( IRP *Irp, UCHAR *GenericExtensionData, USHORT GenericExtensionDataSize, BOOLEAN OverwriteIfPresent);
The Irp argument is the address of an IRP that is to get a generic extension.
The GenericExtensionData and GenericExtensionDataSize arguments are respectively the address and size, in bytes, of a buffer from which the function is to copy the generic extension.
If the OverwriteIfPresent argument is FALSE, the function can succeed only if the IRP does not already have a generic IRP extension.
The function returns STATUS_SUCCESS if successful, else a negative error code which can presently be ony STATUS_INVALID_PARAMETER or STATUS_ALREADY_COMMITTED.
The IoSetGenericIrpExtension function is exported by name from the kernel in version 6.3 and higher.
The IoSetGenericIrpExtension function is not documented. It is, however, declared in the NTOSIFS.H and NTOSP.H files in the Windows Driver Kit (WDK) for Windows 10.
A generic IRP extension can hold 4 bytes. If asked to set more, the function fails, returning STATUS_INVALID_PARAMETER.
If the OverwriteIfPresent argument is FALSE and the IRP already has a generic extension, whether overlaying the IrpExtension or in an IOP_IRP_EXTENSION that is pointed to by the IrpExtension, then the function fails, returning STATUS_ALREADY_COMMITTED.
From here, the generic IRP extension will be set. First, the function must choose where. If IrpExtension in the IRP already points to an IOP_IRP_EXTENSION and the AllocationFlags in the IRP have a clear IRP_EXTENSION_GENERIC_ONLY bit (0x80), then the generic IRP extension goes in the IOP_IRP_EXTENSION as the four bytes of the GenericExtension member. The function sets the 0x0004 bit in that structure’s TypesAllocated to mark that the structure contains data for a generic IRP extension. Otherwise, the generic IRP extension goes in the IRP itself, overlaying IrpExtension: if the IRP_EXTENSION_GENERIC_ONLY bit is not already set, the function sets it now to mark the IRP as having only a generic IRP extension.
Having chosen where the generic IRP extension goes, the function copies the given data there and is done.