?? handle.c
字號:
// HANDLE.CPP -- Implementation of handle object
// Copyright (C) 1999 by Walter Oney
// All rights reserved
#include "precomp.h"
#include "stddcls.h"
#include "driver.h"
#include "cons_def.h"
/*
extern PFILE_OBJECT g_alarmfop;
extern PDEVICE_EXTENSION g_alarmpdx;
extern PFILE_OBJECT g_logfop;
extern PDEVICE_EXTENSION g_logpdx;
*/
///////////////////////////////////////////////////////////////////////////////
/*
VOID CloseHandle(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop)
{ // CloseHandle
PHANDLE_OBJECT hop = FindHandle(pdx, fop);
KIRQL oldirql;
if (!hop)
return;
KeAcquireSpinLock(&pdx->lockHandles, &oldirql);
RemoveEntryList(&hop->link);
KeReleaseSpinLock(&pdx->lockHandles, oldirql);
ReleaseHandle(hop);
g_alarmfop=NULL;
g_alarmpdx=NULL;
g_logfop=NULL;
g_logpdx=NULL;
//ReleaseHandle(hop);
} // CloseHandle
///////////////////////////////////////////////////////////////////////////////
VOID DeregisterEvent(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop)
{ // DeregisterEvent
PHANDLE_OBJECT hop = FindHandle(pdx, fop);
if (!hop)
return;
if (hop->pevent)
{ // dereference event
ObDereferenceObject(hop->pevent);
hop->pevent = NULL;
} // dereference vent
ReleaseHandle(hop);
} // DeregisterEvent
///////////////////////////////////////////////////////////////////////////////
PHANDLE_OBJECT FindHandle(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop)
{ // FindHandle
// The FsContext and FsContext2 fields of the file object are for use by
// whoever actually implements the IRP_MJ_CREATE (us, this case). We
// save our handle object pointer there in OpenHandle
PHANDLE_OBJECT hop = (PHANDLE_OBJECT) fop->FsContext;
if (hop)
++hop->refcnt;
return hop;
} // FindHandle
///////////////////////////////////////////////////////////////////////////////
PHANDLE_OBJECT OpenHandle(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop)
{ // OpenHandle
PHANDLE_OBJECT hop = (PHANDLE_OBJECT) ExAllocatePool(NonPagedPool, sizeof(HANDLE_OBJECT));
if (!hop)
return NULL;
hop->refcnt = 1;
hop->pevent = NULL;
hop->FileObject = fop;
fop->FsContext = (PVOID) hop;
ExInterlockedInsertTailList(&pdx->hlist, &hop->link, &pdx->lockHandles);
return hop;
} // OpenHandle
///////////////////////////////////////////////////////////////////////////////
BOOLEAN RegisterEvent(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop, HANDLE hEvent, KPROCESSOR_MODE AccessMode, char eType)
{ // RegisterEvent
NTSTATUS status;
PHANDLE_OBJECT hop = FindHandle(pdx, fop);
switch (eType)
{
case E_ALARM:
g_alarmpdx=pdx;
g_alarmfop=fop;
break;
case E_LOG:
g_logpdx=pdx;
g_logfop=fop;
break;
default:
break;
}
if (!hop)
return FALSE; // no handle for this file object??
if (hop->pevent)
{ // event already registered
ObDereferenceObject(hop->pevent);
hop->pevent = NULL;
} // event already registered
status = ObReferenceObjectByHandle(hEvent, EVENT_MODIFY_STATE, *ExEventObjectType,
AccessMode, (PVOID*) &hop->pevent, NULL);
ReleaseHandle(hop);
if (!NT_SUCCESS(status))
{
return FALSE;
}
return TRUE;
} // RegisterEvent
///////////////////////////////////////////////////////////////////////////////
VOID ReleaseHandle(PHANDLE_OBJECT hop)
{ // ReleaseHandle
if (InterlockedDecrement(&hop->refcnt) > 0)
return;
if (hop->pevent)
ObDereferenceObject(hop->pevent);
ExFreePool(hop);
} // ReleaseHandle
///////////////////////////////////////////////////////////////////////////////
VOID SignalEvent(PDEVICE_EXTENSION pdx, PFILE_OBJECT fop)
{ // SignalEvent
PHANDLE_OBJECT hop = FindHandle(pdx, fop);
if (hop && hop->pevent)
KeSetEvent(hop->pevent, 0, FALSE);
if (hop)
ReleaseHandle(hop);
} // SignalEvent
///////////////////////////////////////////////////////////////////////////////
*/
NTSTATUS CompleteRequest(IN PIRP Irp, IN NTSTATUS status, IN ULONG_PTR info)
{ // CompleteRequest
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = info;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
} // CompleteRequest
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -