当前位置:首页 > 嵌入式 > 嵌入式软件
[导读]giveio驱动程序源代码

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



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;

}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

上海2024年4月17日 /美通社/ -- 在2024 F1中国站即将拉开帷幕之际,高端全合成润滑油品牌美孚1号今日举办了品牌50周年庆祝活动。三届F1年度车手总冠军马克斯•维斯塔潘也亲临现场,共同庆祝这一里程...

关键字: BSP 汽车制造 行业标准 产品系列

北京2024年4月17日 /美通社/ -- 2024年4月13日,由北京康盟慈善基金会主办的"县域诊疗,规范同行"——肿瘤诊疗学术巡讲项目首站在广州隆重召开。本次会议邀请全国多位肺癌领域专家和县域同道...

关键字: AI技术 医疗服务 BSP 互联网

海口2024年4月16日 /美通社/ -- 4月14日,在中法建交60周年之际,科学护肤先锋品牌Galenic法国科兰黎受邀入驻第四届中国国际消费品博览会(以下简称"消博会")法国馆。Galenic法...

关键字: NI IC BSP ACTIVE

上海2024年4月17日 /美通社/ -- 每年4月17日是世界血友病日。今年,世界血友病日以"认识出血性疾病,积极预防和治疗"为主题,呼吁关注所有出血性疾病,提升科学认知,提高规范化诊疗水平,让每一位出血性疾病患者享有...

关键字: VII 动力学 软件 BSP

伦敦2024年4月16日 /美通社/ -- ATFX宣布任命Siju Daniel为首席商务官。Siju在金融服务行业拥有丰富的经验和专业知识,曾在全球各地的高管职位上工作了19年以上。Siju之前担任FXCM首席商务官...

关键字: NI AN SI BSP

USB摄像头是一种采用USB接口的视频采集设备,其优点在于即插即用、操作简便,无需额外驱动程序,支持笔记本电脑,并且成本较低,可以支持远程网络观看。

关键字: usb摄像头 驱动程序

与两相双极步进电机的驱动电路相比,两相单极步进电机的驱动电路在输入段配置、内部逻辑及控制电路和驱动电路使用双通道方面基本相同,但是输出段的配置不同。

关键字: 四相步进电机 驱动程序 程序电路

本文介绍了如何实现嵌入式MICREL网卡的驱动程序开发和设计。首先,我们介绍了MICREL网卡的概述和工作原理。然后,详细探讨了驱动程序的开发流程,包括硬件和软件的配置以及驱动程序的编写和测试。最后,总结了几点注意事项和...

关键字: 嵌入式 MICREL网卡 驱动程序

常州2023年9月25日 /美通社/ -- 9月23日,由江苏省商务厅指导,世界中餐业联合会、常州市人民政府主办的"第三届中华节气菜大会暨首届江南美食节"在江苏常州开幕。文化和旅游部国际交流与合作局一...

关键字: BSP 可持续发展 大赛 质量控制
关闭
关闭