亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? functions.c

?? Introduction to the Transport Device Interface-f
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**********************************************************************
 * 
 *  Toby Opferman
 *
 *  Example Driver
 *
 *  This example is for educational purposes only.  I license this source
 *  out for use in learning how to write a device driver.
 *
 *  Copyright (c) 2005, All Rights Reserved  
 **********************************************************************/


#define _X86_ 

#include <wdm.h>
#include <tdi.h>
#include <tdikrnl.h>
#include <netdrv.h>
#include "kmem.h"
#include "tdiexample.h"
#include "handleirp.h"
#include "tdifuncs.h"


typedef enum
{
    CS_NOT_CONNECTED,
    CS_CONNECTING,
    CS_CONNECTED,    
    CS_DISCONNECTING
                                           
} CONNECTION_STATUS;

typedef struct _TDI_EXAMPLE_CONTEXT
{
    TDI_HANDLE TdiHandle;
    CONNECTION_STATUS csConnectionState;
    PIRPLISTHEAD pReadIrpListHead;
    PIRPLISTHEAD pWriteIrpListHead;
    KMUTEX kConnectionLock;
    KEVENT kWriteIrpReady;
    KEVENT kWakeWriteIrpThread;
    KEVENT kInitEvent;
    NTSTATUS NtThreadStatus;
    BOOLEAN bWriteThreadAlive;       
    PFILE_OBJECT pWriteThread;

} TDI_EXAMPLE_CONTEXT, *PTDI_EXAMPLE_CONTEXT;



/**********************************************************************
 * Internal Functions
 **********************************************************************/
 
 VOID TdiExample_CancelRoutine(PDEVICE_OBJECT DeviceObject, PIRP pIrp); 
 VOID TdiExample_IrpCleanUp(PIRP pIrp, PVOID pContext);
 NTSTATUS TdiExample_Connect(PTDI_EXAMPLE_CONTEXT pTdiExampleContext, PVOID pAddressContext, UINT uiLength);
 NTSTATUS TdiExample_Disconnect(PTDI_EXAMPLE_CONTEXT pTdiExampleContext);
 VOID TdiExample_WorkItem(PDEVICE_OBJECT  DeviceObject, PVOID  Context);
 VOID TdiExample_NetworkWriteThread(PVOID StartContext);
 NTSTATUS TdiExample_ClientEventReceive(PVOID TdiEventContext, CONNECTION_CONTEXT ConnectionContext, ULONG ReceiveFlags, ULONG  BytesIndicated, ULONG  BytesAvailable, ULONG  *BytesTaken, PVOID  Tsdu, PIRP  *IoRequestPacket);

#pragma alloc_text(PAGE, TdiExample_NetworkWriteThread)
#pragma alloc_text(PAGE, TdiExample_WorkItem)
#pragma alloc_text(PAGE, TdiExample_Disconnect)
#pragma alloc_text(PAGE, TdiExample_IrpCleanUp)
/* #pragma alloc_text(PAGE, TdiExample_CancelRoutine) */
#pragma alloc_text(PAGE, TdiExample_IoControlInternal)
#pragma alloc_text(PAGE, TdiExample_Create) 
#pragma alloc_text(PAGE, TdiExample_Close) 
#pragma alloc_text(PAGE, TdiExample_IoControl) 
#pragma alloc_text(PAGE, TdiExample_Read)
#pragma alloc_text(PAGE, TdiExample_Write)
#pragma alloc_text(PAGE, TdiExample_UnSupportedFunction)
#pragma alloc_text(PAGE, TdiExample_Connect)
/* #pragma alloc_text(PAGE, TdiExample_ClientEventReceive) */
                                
#define STATUS_CONTINUE_COMPLETION  STATUS_SUCCESS
#define TDIEXAMPLE_POOL_TAG         ((ULONG)'EidT')
#define READ_IRPLIST_POOL_TAG       ((ULONG)'RprI')
#define WRITE_IRPLIST_POOL_TAG      ((ULONG)'WprI')


/**********************************************************************
 * 
 *  TdiExample_Create
 *
 *    This is called when an instance of this driver is created (CreateFile)
 *
 **********************************************************************/
NTSTATUS TdiExample_Create(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
    NTSTATUS NtStatus = STATUS_INSUFFICIENT_RESOURCES;
    PIO_STACK_LOCATION pIoStackIrp = NULL;
    PTDI_EXAMPLE_CONTEXT pTdiExampleContext = NULL;

    DbgPrint("TdiExample_Create Called \r\n");


    pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);

    /* 
     * We need to allocate our instance context for this handle.  This
     * data structure will be associated with this user mode handle.
     *
     * We are allocating it in Non-Paged Pool so we can use it while holding
     * Spin Locks in our IRP Queue.
     *
     */

    pTdiExampleContext = (PTDI_EXAMPLE_CONTEXT)KMem_AllocateNonPagedMemory(sizeof(TDI_EXAMPLE_CONTEXT), TDIEXAMPLE_POOL_TAG);

    if(pTdiExampleContext)
    {
         DbgPrint("TdiExample_Create Allocate = 0x%0x \r\n", pTdiExampleContext);
        /*
         * We have created a library called "HandleIrp" which helps to queue our Pending IRP's.
         * The first thing we do is create the context for this list.
         */
        pTdiExampleContext->pReadIrpListHead = HandleIrp_CreateIrpList(READ_IRPLIST_POOL_TAG);
        pTdiExampleContext->pWriteIrpListHead = HandleIrp_CreateIrpList(WRITE_IRPLIST_POOL_TAG);

        if(pTdiExampleContext->pWriteIrpListHead && pTdiExampleContext->pReadIrpListHead)
        {
            /*
             * We need to maintain a state for this handle which will help us to know
             * if a Read or Write request should be ignored or performed for example.
             *
             * We obviously start with not connected.
             */
            pTdiExampleContext->csConnectionState = CS_NOT_CONNECTED;
    
            /*
             * We have our own TDI Client Driver library which allows us to simply
             * call functions to initate connections, etc.  The first thing we need to do
             * is create a TdiHandle context which can then be used in other TDI Library Calls.
             */
            NtStatus = TdiFuncs_InitializeTransportHandles(&pTdiExampleContext->TdiHandle);
    
            if(NT_SUCCESS(NtStatus))
            {
                NtStatus = TdiFuncs_SetEventHandler(pTdiExampleContext->TdiHandle.pfoTransport, TDI_EVENT_RECEIVE, TdiExample_ClientEventReceive, (PVOID)pTdiExampleContext);
            }

            if(NT_SUCCESS(NtStatus))
            {
                PIO_WORKITEM pIoWorkItem;

                /*
                 * We need to initialize our locks and events for this handle.  
                 *
                 * The Connection Lock is used to Synchronize access to connecting and disconnecting
                 *
                 * The Write IRP Ready event is used to signal the Writer thread
                 * that an IRP has been queued and it's waiting to be sent.
                 *
                 * The Wake Up Write Irp Thread is used to signal the thread to wake up.  It is generally
                 * used to signal the thread to exit.
                 *
                 * kInitEvent is used to synchronize initialization and notify when the work item has
                 * signaled that the thread has been created.
                 *
                 * The bWriteThreadAlive variable is used to tell the thread it should exit. 
                 */
                KeInitializeMutex(&pTdiExampleContext->kConnectionLock, 0);
                
                KeInitializeEvent(&pTdiExampleContext->kWriteIrpReady, SynchronizationEvent, FALSE);
                KeInitializeEvent(&pTdiExampleContext->kWakeWriteIrpThread, SynchronizationEvent, FALSE); 
                KeInitializeEvent(&pTdiExampleContext->kInitEvent, NotificationEvent, FALSE); 
                    
                pTdiExampleContext->bWriteThreadAlive = TRUE;   
                
                /* 
                 * We want to create a SYSTEM thread so we can handle our Writes Asynchronously.
                 * The problem is that we can't call PsCreateSystemThread() outside of the SYSTEM
                 * process on Windows 2000.  On Windows XP/2003 we can by using the object attributes,
                 * however we want this driver to run on Windows 2000 as well.  So we need to create
                 * a work item which will process some work on our behalf in the system context.
                 *
                 * We can use this to be in the context of SYSTEM to create our thread.
                 *
                 * IO_WORKITEM is an opaque data structure used by the system.
                 *
                 */

                pIoWorkItem = IoAllocateWorkItem(DeviceObject);

                if(pIoWorkItem)
                {

                    IoQueueWorkItem(pIoWorkItem, TdiExample_WorkItem, DelayedWorkQueue, (PVOID)pTdiExampleContext);
                    
                    /* 
                     * Wait for the work item to complete creating the thread.
                     */
                    KeWaitForSingleObject(&pTdiExampleContext->kInitEvent, Executive, KernelMode, FALSE, NULL);
                    
                    NtStatus = pTdiExampleContext->NtThreadStatus;

                    /*
                     * It is safe to free the work item when the Work Item function is called.  The work
                     * item is dequeued before the function is called.  It is not safe to free a work item
                     * that is currently queued.
                     */
                    IoFreeWorkItem(pIoWorkItem);

                    if(NT_SUCCESS(NtStatus))
                    {
                        /*
                         * Set the context of our FILE_OBJECT
                         */
                        pIoStackIrp->FileObject->FsContext = (PVOID)pTdiExampleContext;
                    }
                    else
                    {
                        HandleIrp_FreeIrpList(pTdiExampleContext->pReadIrpListHead);
                        HandleIrp_FreeIrpList(pTdiExampleContext->pWriteIrpListHead);
                        DbgPrint("TdiExample_Create Free = 0x%0x \r\n", pTdiExampleContext);

                        KMem_FreeNonPagedMemory(pTdiExampleContext);
                    }
                }
                else
                {
                    HandleIrp_FreeIrpList(pTdiExampleContext->pReadIrpListHead);
                    HandleIrp_FreeIrpList(pTdiExampleContext->pWriteIrpListHead);
                    DbgPrint("TdiExample_Create Free = 0x%0x \r\n", pTdiExampleContext);

                    KMem_FreeNonPagedMemory(pTdiExampleContext);
                }

            }
            else
            {
                HandleIrp_FreeIrpList(pTdiExampleContext->pReadIrpListHead);
                HandleIrp_FreeIrpList(pTdiExampleContext->pWriteIrpListHead);
                DbgPrint("TdiExample_Create Free = 0x%0x \r\n", pTdiExampleContext);

                KMem_FreeNonPagedMemory(pTdiExampleContext);
            }
        }
        else
        {
            if(pTdiExampleContext->pWriteIrpListHead)
            {
                HandleIrp_FreeIrpList(pTdiExampleContext->pWriteIrpListHead);
            }

            if(pTdiExampleContext->pReadIrpListHead)
            {
                HandleIrp_FreeIrpList(pTdiExampleContext->pReadIrpListHead);
            }
            DbgPrint("TdiExample_Create Free = 0x%0x \r\n", pTdiExampleContext);

            KMem_FreeNonPagedMemory(pTdiExampleContext);

        }
    }

    Irp->IoStatus.Status      = NtStatus;
    Irp->IoStatus.Information = 0;

    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    DbgPrint("TdiExample_Create Exit 0x%0x \r\n", NtStatus);

    return NtStatus;
}

/**********************************************************************
 * 
 *  TdiExample_WorkItem
 *
 *    This is executed in the context of the SYSTEM process.
 *
 **********************************************************************/
VOID TdiExample_WorkItem(PDEVICE_OBJECT  DeviceObject, PVOID  Context)
{
   PTDI_EXAMPLE_CONTEXT pTdiExampleContext = (PVOID)Context;
   HANDLE WriteThreadHandle;

   DbgPrint("TdiExample_WorkItem Enter \r\n");
    /*
     * We want to allow asynchronous Reads and Writes.  To handle our Writes we will have our
     * own thread in the SYSTEM process space.  This thread will simply be woken up when we have
     * Write's on the Queue and perform the write.
     *
     * If a write is issued Asynchronous the I/O Manager will return to user mode and allow this
     * thread to continue.  If it is not, even though we return from our write and post to this
     * thread the I/O Manager will wait for it to finish, just as we are doing when we issue TDI
     * IRPs.
     */
    pTdiExampleContext->NtThreadStatus = PsCreateSystemThread(&WriteThreadHandle, 0, NULL, NULL, NULL, TdiExample_NetworkWriteThread, (PVOID)pTdiExampleContext);
    
    if(NT_SUCCESS(pTdiExampleContext->NtThreadStatus))
    {
        /*
         * We would rather use the PFILE_OBJECT since it is a pointer to the object rather than a handle.  Handles
         * are only good from within the context of a particular process.
         */
        ObReferenceObjectByHandle(WriteThreadHandle, GENERIC_READ | GENERIC_WRITE, NULL, KernelMode, (PVOID *)&pTdiExampleContext->pWriteThread, NULL);
        ZwClose(WriteThreadHandle);
    }

    KeSetEvent(&pTdiExampleContext->kInitEvent, IO_NO_INCREMENT, FALSE);
}


/**********************************************************************
 * 
 *  TdiExample_NetworkWriteThread
 *
 *    This is executed in the context of the SYSTEM process.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线高清视频| 国产网红主播福利一区二区| 精品久久久久久久久久久久包黑料 | 日韩二区在线观看| 国v精品久久久网| 911精品国产一区二区在线| 国产精品毛片无遮挡高清| 奇米四色…亚洲| 91久久久免费一区二区| 国产欧美精品区一区二区三区| 天天色综合天天| 色呦呦一区二区三区| 日本一区二区高清| 麻豆精品一区二区| 欧美日韩高清一区二区三区| 亚洲欧洲日产国码二区| 国内精品视频666| 91精品国产综合久久福利软件 | 91免费看视频| 国产女主播一区| 国产精品888| 26uuu亚洲综合色欧美| 免费在线观看视频一区| 91精品视频网| 日本美女一区二区三区| 91麻豆精品国产91久久久久久久久 | 国产亚洲一区二区三区| 久久激情综合网| 欧美成人精精品一区二区频| 日产欧产美韩系列久久99| 欧美精三区欧美精三区| 午夜a成v人精品| 欧美日韩色综合| 日韩精品成人一区二区在线| 欧美精品自拍偷拍| 久久综合综合久久综合| 337p粉嫩大胆噜噜噜噜噜91av | 久久综合狠狠综合久久激情| 麻豆国产精品视频| 日韩欧美高清一区| 国产麻豆午夜三级精品| 国产日韩欧美a| 波多野结衣一区二区三区| 中文字幕综合网| 在线免费观看日韩欧美| 日韩高清不卡一区二区| 欧美成人激情免费网| 国产91综合网| 亚洲欧美国产高清| 欧美日韩午夜影院| 狠狠色丁香婷婷综合| 国产亲近乱来精品视频| 色婷婷久久99综合精品jk白丝| 亚洲自拍偷拍欧美| 日韩一二在线观看| 国产成人精品亚洲午夜麻豆| 亚洲欧美日韩成人高清在线一区| 欧美日韩在线一区二区| 美国毛片一区二区| 国产精品电影一区二区| 欧美在线一二三四区| 久久97超碰色| 亚洲欧洲另类国产综合| 91麻豆精品国产91久久久使用方法 | 国产女同互慰高潮91漫画| eeuss鲁一区二区三区| 午夜精品免费在线| 日日夜夜免费精品视频| 久久一留热品黄| 91国偷自产一区二区三区观看| 日本欧美一区二区三区| 中文字幕日韩一区二区| 91精品国产aⅴ一区二区| 成人激情综合网站| 日韩不卡免费视频| 亚洲欧洲制服丝袜| 欧美videos中文字幕| 色乱码一区二区三区88| 国产一区二区三区久久久| 亚洲国产精品精华液网站| 国产欧美日韩激情| 欧美一级二级三级蜜桃| 色天使久久综合网天天| 国产成人精品一区二区三区四区| 日韩中文字幕区一区有砖一区| 国产精品久久久久久一区二区三区| 555www色欧美视频| 在线亚洲欧美专区二区| 成人自拍视频在线观看| 美女视频免费一区| 亚洲国产成人av好男人在线观看| 国产日产精品1区| 精品久久人人做人人爽| 制服丝袜在线91| 欧美性大战久久| 99综合影院在线| 大白屁股一区二区视频| 激情综合亚洲精品| 免费在线观看精品| 日韩激情一区二区| 五月婷婷激情综合网| 亚洲精品乱码久久久久久| 欧美国产成人在线| 国产亚洲精品中文字幕| 精品久久久久久久久久久久包黑料 | 国产欧美1区2区3区| 精品国产乱码久久久久久影片| 欧美另类一区二区三区| 欧美日产国产精品| 欧洲av一区二区嗯嗯嗯啊| 色拍拍在线精品视频8848| www.欧美.com| 91丨porny丨在线| 91麻豆国产在线观看| 91色在线porny| 色综合久久精品| 在线视频欧美精品| 欧美日韩一级二级| 欧美高清一级片在线| 欧美一区二区三区视频免费| 日韩视频国产视频| 26uuu亚洲综合色欧美| 国产日韩在线不卡| 中文字幕中文字幕一区| 亚洲免费观看高清完整版在线| 亚洲激情男女视频| 日韩精彩视频在线观看| 久久99久久久久久久久久久| 国模一区二区三区白浆| 成人丝袜视频网| 色综合久久久久久久久久久| 91电影在线观看| 91精品国产入口在线| 久久亚洲精品国产精品紫薇| 亚洲国产精品国自产拍av| 亚洲视频在线观看一区| 亚洲成av人片在线| 精品无人码麻豆乱码1区2区| 波多野洁衣一区| 欧美日韩免费高清一区色橹橹| 欧美一卡在线观看| 日本一区二区三区国色天香| 亚洲精品日产精品乱码不卡| 日韩影院免费视频| 国产成人亚洲综合a∨婷婷| 91在线云播放| 91精品国产综合久久精品| 中文字幕欧美三区| 亚洲午夜一区二区| 国产一区二区三区四区五区美女| k8久久久一区二区三区| 欧美精品1区2区| 中文字幕av一区 二区| 亚洲一区二区欧美| 国产成a人亚洲精| 欧美人狂配大交3d怪物一区| 国产亚洲成av人在线观看导航| 亚洲图片另类小说| 捆绑变态av一区二区三区| 色婷婷综合久久久中文一区二区| 日韩欧美精品在线视频| 亚洲免费观看高清| 韩国av一区二区三区四区| 在线亚洲免费视频| 国产视频一区不卡| 偷偷要91色婷婷| 91丨porny丨户外露出| 久久只精品国产| 97国产一区二区| 精品国产露脸精彩对白| 亚洲资源中文字幕| 粉嫩在线一区二区三区视频| 日韩一区二区三免费高清| 亚洲欧美偷拍三级| 国产99久久久国产精品| 欧美mv日韩mv| 日韩vs国产vs欧美| 欧美性videosxxxxx| ...中文天堂在线一区| 国产一区二区视频在线| 欧美一级高清大全免费观看| 亚洲福利视频一区| 日本黄色一区二区| 国产精品久久二区二区| 国产成人精品影院| 久久欧美一区二区| 黄页网站大全一区二区| 日韩一区二区三区视频在线观看| 亚洲国产裸拍裸体视频在线观看乱了 | 亚洲色图欧洲色图婷婷| 国产成人av电影| 欧美经典一区二区| 国产精品一区二区视频| 欧美tickle裸体挠脚心vk| 免费观看91视频大全| 欧美日韩国产小视频| 午夜免费久久看| 欧美一区二区三级| 日本午夜一本久久久综合| 91精品国产黑色紧身裤美女|