VBoxUsbHook.cpp revision 67bfa93839cac50828c90f19a00256bf44cc0f33
/* $Id$ */
/** @file
* Driver Dispatch Table Hooking API
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "VBoxUsbMon.h"
#define VBOXUSBHOOK_MEMTAG 'HUBV'
{
if (pHook->fIsInstalled)
{
WARN(("hook is marked installed, returning failure"));
return STATUS_UNSUCCESSFUL;
}
pHook->pfnOldHandler = (PDRIVER_DISPATCH)InterlockedExchangePointer((PVOID*)&pHook->pDrvObj->MajorFunction[pHook->iMjFunction], pHook->pfnHook);
return STATUS_SUCCESS;
}
{
if (!pHook->fIsInstalled)
{
return STATUS_SUCCESS;
}
PDRIVER_DISPATCH pfnOldVal = (PDRIVER_DISPATCH)InterlockedCompareExchangePointer((PVOID*)&pHook->pDrvObj->MajorFunction[pHook->iMjFunction], pHook->pfnOldHandler, pHook->pfnHook);
{
AssertMsgFailed(("unhook failed!!!\n"));
/* this is bad! this could happen if someone else has chained another hook,
* or (which is even worse) restored the "initial" entry value it saved when doing a hooking before us
* return the failure and don't do anything else
* the best thing to do if this happens is to leave everything as is
* and to prevent the driver from being unloaded to ensure no one references our unloaded hook routine */
return STATUS_UNSUCCESSFUL;
}
/* wait for the current handlers to exit */
return STATUS_SUCCESS;
}
{
return fIsInstalled;
}
VOID VBoxUsbHookInit(PVBOXUSBHOOK_ENTRY pHook, PDRIVER_OBJECT pDrvObj, UCHAR iMjFunction, PDRIVER_DISPATCH pfnHook)
{
}
static void vboxUsbHookRequestRegisterCompletion(PVBOXUSBHOOK_ENTRY pHook, PDEVICE_OBJECT pDevObj, PIRP pIrp, PIO_COMPLETION_ROUTINE pfnCompletion, PVBOXUSBHOOK_REQUEST pRequest)
{
}
NTSTATUS VBoxUsbHookRequestPassDownHookCompletion(PVBOXUSBHOOK_ENTRY pHook, PDEVICE_OBJECT pDevObj, PIRP pIrp, PIO_COMPLETION_ROUTINE pfnCompletion, PVBOXUSBHOOK_REQUEST pRequest)
{
}
NTSTATUS VBoxUsbHookRequestPassDownHookSkip(PVBOXUSBHOOK_ENTRY pHook, PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
}
NTSTATUS VBoxUsbHookRequestMoreProcessingRequired(PVBOXUSBHOOK_ENTRY pHook, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVBOXUSBHOOK_REQUEST pRequest)
{
return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS VBoxUsbHookRequestComplete(PVBOXUSBHOOK_ENTRY pHook, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVBOXUSBHOOK_REQUEST pRequest)
{
{
}
{
if (pRequest->bCompletionStopped)
{
}
}
/*
* else - in case driver returned STATUS_MORE_PROCESSING_REQUIRED,
* it will call IoCompleteRequest itself
*/
return Status;
}
#define PVBOXUSBHOOK_REQUEST_FROM_LE(_pLe) ( (PVBOXUSBHOOK_REQUEST)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBHOOK_REQUEST, ListEntry) ) )
VOID VBoxUsbHookVerifyCompletion(PVBOXUSBHOOK_ENTRY pHook, PVBOXUSBHOOK_REQUEST pRequest, PIRP pIrp)
{
{
continue;
continue;
AssertFailed();
}
}