⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devctrl.c

📁 操作系统引导的一些介绍,对学习引导的有很大的帮助与提高
💻 C
字号:
//
// (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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -