日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 嵌入式 > 嵌入式軟件
[導(dǎo)讀]giveio驅(qū)動(dòng)程序源代碼

/*********************************************************************



Author:     Dale Roberts

Date:       8/30/95

Program:    GIVEIO.SYS

Compile:    Use DDK BUILD facility



Purpose:    Give direct port I/O access to a user mode process.



*********************************************************************/

#include 



/*

 *  The name of our device driver.

 */

#define DEVICE_NAME_STRING    L"giveio"



/*

 *  This is the "structure" of the IOPM.  It is just a simple

 * character array of length 0x2000.

 *

 *  This holds 8K * 8 bits -> 64K bits of the IOPM, which maps the

 * entire 64K I/O space of the x86 processor.  Any 0 bits will give

 * access to the corresponding port for user mode processes.  Any 1

 * bits will disallow I/O access to the corresponding port.

 */

#define    IOPM_SIZE    0x2000

typedef UCHAR IOPM[IOPM_SIZE];



/*

 *  This will hold simply an array of 0's which will be copied

 * into our actual IOPM in the TSS by Ke386SetIoAccessMap().

 * The memory is allocated at driver load time.

 */

IOPM *IOPM_local = 0;



/*

 *  These are the two undocumented calls that we will use to give

 * the calling process I/O access.

 *

 *  Ke386IoSetAccessMap() copies the passed map to the TSS.

 *

 *  Ke386IoSetAccessProcess() adjusts the IOPM offset pointer so that

 * the newly copied map is actually used.  Otherwise, the IOPM offset

 * points beyond the end of the TSS segment limit, causing any I/O

 * access by the user mode process to generate an exception.

 */

void Ke386SetIoAccessMap(int, IOPM *);

void Ke386QueryIoAccessMap(int, IOPM *);

void Ke386IoSetAccessProcess(PEPROCESS, int);



/*********************************************************************

  Release any allocated objects.

*********************************************************************/

VOID GiveioUnload(IN PDRIVER_OBJECT DriverObject)

{

    WCHAR DOSNameBuffer[] = L"DosDevices" DEVICE_NAME_STRING;

    UNICODE_STRING uniDOSString;



    if(IOPM_local)

        MmFreeNonCachedMemory(IOPM_local, sizeof(IOPM));



    RtlInitUnicodeString(&uniDOSString, DOSNameBuffer);

    IoDeleteSymbolicLink (&uniDOSString);

    IoDeleteDevice(DriverObject->DeviceObject);

}



/*********************************************************************

  Set the IOPM (I/O permission map) of the calling process so that it

is given full I/O access.  Our IOPM_local[] array is all zeros, so

the IOPM will be all zeros.  If OnFlag is 1, the process is given I/O

access.  If it is 0, access is removed.

*********************************************************************/

VOID SetIOPermissionMap(int OnFlag)

{

    Ke386IoSetAccessProcess(PsGetCurrentProcess(), OnFlag);

    Ke386SetIoAccessMap(1, IOPM_local);

}



void GiveIO(void)

{

    SetIOPermissionMap(1);

}



/*********************************************************************

  Service handler for a CreateFile() user mode call.



  This routine is entered in the driver object function call table by

the DriverEntry() routine.  When the user mode application calls

CreateFile(), this routine gets called while still in the context of

the user mode application, but with the CPL (the processor's Current

Privelege Level) set to 0.  This allows us to do kernel mode

operations.  GiveIO() is called to give the calling process I/O

access.  All the user mode application needs do to obtain I/O access

is open this device with CreateFile().  No other operations are

required.

*********************************************************************/

NTSTATUS GiveioCreateDispatch(

    IN  PDEVICE_OBJECT  DeviceObject,

    IN  PIRP            Irp

    )

{

    GiveIO();            // give the calling process I/O access



    Irp->IoStatus.Information = 0;

    Irp->IoStatus.Status = STATUS_SUCCESS;

    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    return STATUS_SUCCESS;

}



/*********************************************************************

  Driver Entry routine.



  This routine is called only once after the driver is initially

loaded into memory.  It allocates everything necessary for the

driver's operation.  In our case, it allocates memory for our IOPM

array, and creates a device which user mode applications can open.

It also creates a symbolic link to the device driver.  This allows

a user mode application to access our driver using the .giveio

notation.

*********************************************************************/

NTSTATUS DriverEntry(

    IN PDRIVER_OBJECT DriverObject,

    IN PUNICODE_STRING RegistryPath

    )

{

    PDEVICE_OBJECT deviceObject;

    NTSTATUS status;

    WCHAR NameBuffer[] = L"Device" DEVICE_NAME_STRING;

    WCHAR DOSNameBuffer[] = L"DosDevices" DEVICE_NAME_STRING;

    UNICODE_STRING uniNameString, uniDOSString;



    //

    //  Allocate a buffer for the local IOPM and zero it.

    //

    IOPM_local = MmAllocateNonCachedMemory(sizeof(IOPM));

    if(IOPM_local == 0)

        return STATUS_INSUFFICIENT_RESOURCES;

    RtlZeroMemory(IOPM_local, sizeof(IOPM));



    //

    //  Set up device driver name and device object.

    //

    RtlInitUnicodeString(&uniNameString, NameBuffer);

    RtlInitUnicodeString(&uniDOSString, DOSNameBuffer);



    status = IoCreateDevice(DriverObject, 0,

                    &uniNameString,

                    FILE_DEVICE_UNKNOWN,

                    0, FALSE, &deviceObject);



    if(!NT_SUCCESS(status))

        return status;



    status = IoCreateSymbolicLink (&uniDOSString, &uniNameString);



    if (!NT_SUCCESS(status))

        return status;



    //

    //  Initialize the Driver Object with driver's entry points.

    // All we require are the Create and Unload operations.

    //

    DriverObject->MajorFunction[IRP_MJ_CREATE] = GiveioCreateDispatch;

    DriverObject->DriverUnload = GiveioUnload;

    return STATUS_SUCCESS;

}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉