SendDownStreamIrp 函式
本主題中提供的函式程式碼範例 SendDownStreamIrp
示範如何實作驅動程式提供的函式,以將同步 IOCTL 要求傳送至 ACPI 驅動程式。 函 SendDownStreamIrp
式可用來傳送 IOCTL_ACPI_EVAL_METHOD 要求、 IOCTL_ACPI_EVAL_METHOD_EX 要求或 IOCTL_ACPI_ENUM_CHILDREN 要求。
本節中包含的函式範例程式碼 SendDownStreamIrp
會執行下列作業順序:
建立事件物件。
呼叫 IoBuildDeviceIoControlRequest 以建立 IOCTL 要求。
呼叫 IoCallDriver 以傳送 IOCTL 要求。
等候 ACPI 驅動程式發出事件物件的訊號,這表示要求已完成。
將要求的狀態傳回給呼叫端。
NTSTATUS
SendDownStreamIrp(
IN PDEVICE_OBJECT Pdo,
IN ULONG Ioctl,
IN PVOID InputBuffer,
IN ULONG InputSize,
IN PVOID OutputBuffer,
IN ULONG OutputSize
)
/*
Routine Description:
General-purpose function called to send a request to the PDO.
The IOCTL argument accepts the control method being passed down
by the calling function
This subroutine is only valid for the IOCTLS other than ASYNC EVAL.
Parameters:
Pdo - the request is sent to this device object
Ioctl - the request - specified by the calling function
InputBuffer - incoming request
InputSize - size of the incoming request
OutputBuffer - the answer
OutputSize - size of the answer buffer
Return Value:
NT Status of the operation
*/
{
IO_STATUS_BLOCK ioBlock;
KEVENT myIoctlEvent;
NTSTATUS status;
PIRP irp;
// Initialize an event to wait on
KeInitializeEvent(&myIoctlEvent, SynchronizationEvent, FALSE);
// Build the request
irp = IoBuildDeviceIoControlRequest(
Ioctl,
Pdo,
InputBuffer,
InputSize,
OutputBuffer,
OutputSize,
FALSE,
&myIoctlEvent,
&ioBlock);
if (!irp) {
return STATUS_INSUFFICIENT_RESOURCES;
}
// Pass request to Pdo, always wait for completion routine
status = IoCallDriver(Pdo, irp);
if (status == STATUS_PENDING) {
// Wait for the IRP to be completed, and then return the status code
KeWaitForSingleObject(
&myIoctlEvent,
Executive,
KernelMode,
FALSE,
NULL);
status = ioBlock.Status;
}
return status;
}