devctrl.c
来自「操作系统引导的一些介绍,对学习引导的有很大的帮助与提高」· C语言 代码 · 共 73 行
C
73 行
//
// (C) Copyright 1997 OSR Open Systems Resources, Inc.
// All Rights Reserved
//
#include <ntddk.h>
//
// This demonstrates how to build a device control and send it
// to a lower level device.
//
MakeDeviceControl(PDEVICE_OBJECT DeviceObject,
ULONG IoctlCode,
PVOID InputBuffer,
ULONG InputBufferSize,
PVOID OutputBuffer,
ULONG OutputBufferSize)
{
PIRP Irp;
NTSTATUS Status;
KEVENT Event;
IO_STATUS_BLOCK Iosb;
//
// First, start by initializing the event
//
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
//
// Build the request, using the I/O Manager routine...
//
Irp = IoBuildDeviceIoControlRequest(IoctlCode,
DeviceObject,
InputBuffer,
InputBufferSize,
OutputBuffer,
OutputBufferSize,
FALSE,
&Event,
&Iosb);
//
// Send the request to the lower layer driver.
//
Status = IoCallDriver(DeviceObject, Irp);
//
// Wait, if necessary
//
if (Status == STATUS_PENDING) {
//
// We must wait here in non-interruptable mode. Why? Because our
// event is on the stack. If we were to return out of here (because
// of an APC, for example) we might return from this function BEFORE
// the event is set. When the event is set later, at a minimum we'll
// trash the stack. Worse yet, the stack might be paged out and the
// system will die.
//
(void) KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
}
return (Status);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?