2013-12-17 02:19:52 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Virtual DOS Machine
|
2015-09-18 17:01:49 +00:00
|
|
|
* FILE: subsystems/mvdm/ntvdm/vddsup.c
|
2013-12-17 23:13:11 +00:00
|
|
|
* PURPOSE: Virtual Device Drivers (VDD) Support
|
2013-12-17 02:19:52 +00:00
|
|
|
* PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
|
|
|
*/
|
|
|
|
|
2015-10-04 11:49:28 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
2015-10-03 19:17:55 +00:00
|
|
|
#include "ntvdm.h"
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
#define NDEBUG
|
2015-10-03 19:17:55 +00:00
|
|
|
#include <debug.h>
|
2013-12-17 02:19:52 +00:00
|
|
|
|
2015-10-04 11:49:28 +00:00
|
|
|
#include "emulator.h"
|
|
|
|
#include "vddsup.h"
|
|
|
|
|
|
|
|
#include "cpu/bop.h"
|
|
|
|
#include <isvbop.h>
|
|
|
|
|
2013-12-17 22:10:58 +00:00
|
|
|
typedef VOID (WINAPI *VDD_PROC)(VOID);
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
typedef struct _VDD_MODULE
|
|
|
|
{
|
2013-12-17 22:10:58 +00:00
|
|
|
HMODULE hDll;
|
|
|
|
VDD_PROC DispatchRoutine;
|
2013-12-17 02:19:52 +00:00
|
|
|
} VDD_MODULE, *PVDD_MODULE;
|
|
|
|
|
2015-05-11 23:04:24 +00:00
|
|
|
// WARNING: A structure with the same name exists in nt_vdd.h,
|
|
|
|
// however it is not declared because its inclusion was prevented
|
|
|
|
// with #define NO_NTVDD_COMPAT, see ntvdm.h
|
|
|
|
typedef struct _VDD_USER_HANDLERS
|
|
|
|
{
|
|
|
|
LIST_ENTRY Entry;
|
|
|
|
|
|
|
|
HANDLE hVdd;
|
|
|
|
PFNVDD_UCREATE Ucr_Handler;
|
|
|
|
PFNVDD_UTERMINATE Uterm_Handler;
|
|
|
|
PFNVDD_UBLOCK Ublock_Handler;
|
|
|
|
PFNVDD_URESUME Uresume_Handler;
|
|
|
|
} VDD_USER_HANDLERS, *PVDD_USER_HANDLERS;
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
/* PRIVATE VARIABLES **********************************************************/
|
|
|
|
|
2013-12-17 22:34:08 +00:00
|
|
|
// TODO: Maybe use a linked list.
|
2013-12-24 13:33:51 +00:00
|
|
|
// But the number of elements must be <= MAXUSHORT (MAXWORD)
|
2013-12-17 22:10:58 +00:00
|
|
|
#define MAX_VDD_MODULES 0xFF + 1
|
2014-11-21 00:11:11 +00:00
|
|
|
static VDD_MODULE VDDList[MAX_VDD_MODULES] = {{NULL}};
|
2013-12-17 22:34:08 +00:00
|
|
|
|
|
|
|
// Valid handles of VDD DLLs start at 1 and finish at MAX_VDD_MODULES
|
|
|
|
#define ENTRY_TO_HANDLE(Entry) ((Entry) + 1)
|
|
|
|
#define HANDLE_TO_ENTRY(Handle) ((Handle) - 1)
|
|
|
|
#define IS_VALID_HANDLE(Handle) ((Handle) > 0 && (Handle) <= MAX_VDD_MODULES)
|
2013-12-17 02:19:52 +00:00
|
|
|
|
2015-05-11 23:04:24 +00:00
|
|
|
static LIST_ENTRY VddUserHooksList = {&VddUserHooksList, &VddUserHooksList};
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
2014-11-21 00:11:11 +00:00
|
|
|
static USHORT GetNextFreeVDDEntry(VOID)
|
2013-12-17 02:19:52 +00:00
|
|
|
{
|
2020-05-25 21:49:47 +00:00
|
|
|
USHORT Entry;
|
2015-04-19 00:01:03 +00:00
|
|
|
for (Entry = 0; Entry < ARRAYSIZE(VDDList); ++Entry)
|
2013-12-17 02:19:52 +00:00
|
|
|
{
|
|
|
|
if (VDDList[Entry].hDll == NULL) break;
|
|
|
|
}
|
|
|
|
return Entry;
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:11:11 +00:00
|
|
|
static VOID WINAPI ThirdPartyVDDBop(LPWORD Stack)
|
2013-12-17 02:19:52 +00:00
|
|
|
{
|
|
|
|
/* Get the Function Number and skip it */
|
|
|
|
BYTE FuncNum = *(PBYTE)SEG_OFF_TO_PTR(getCS(), getIP());
|
|
|
|
setIP(getIP() + 1);
|
|
|
|
|
|
|
|
switch (FuncNum)
|
|
|
|
{
|
|
|
|
/* RegisterModule */
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL Success = TRUE;
|
2013-12-17 22:10:58 +00:00
|
|
|
WORD RetVal = 0;
|
|
|
|
WORD Entry = 0;
|
2013-12-17 02:19:52 +00:00
|
|
|
LPCSTR DllName = NULL,
|
2013-12-17 22:10:58 +00:00
|
|
|
InitRoutineName = NULL,
|
2013-12-17 02:19:52 +00:00
|
|
|
DispatchRoutineName = NULL;
|
|
|
|
HMODULE hDll = NULL;
|
2013-12-17 22:10:58 +00:00
|
|
|
VDD_PROC InitRoutine = NULL,
|
|
|
|
DispatchRoutine = NULL;
|
2013-12-17 02:19:52 +00:00
|
|
|
|
2013-12-27 19:51:43 +00:00
|
|
|
DPRINT("RegisterModule() called\n");
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Clear the Carry Flag (no error happened so far) */
|
|
|
|
setCF(0);
|
|
|
|
|
2013-12-24 13:33:51 +00:00
|
|
|
/* Retrieve the next free entry in the table (used later on) */
|
|
|
|
Entry = GetNextFreeVDDEntry();
|
|
|
|
if (Entry >= MAX_VDD_MODULES)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create a new VDD module entry\n");
|
|
|
|
Success = FALSE;
|
|
|
|
RetVal = 4;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
/* Retrieve the VDD name in DS:SI */
|
2013-12-17 22:34:08 +00:00
|
|
|
DllName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getSI());
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Retrieve the initialization routine API name in ES:DI (optional --> ES=DI=0) */
|
2013-12-24 13:33:51 +00:00
|
|
|
if (TO_LINEAR(getES(), getDI()) != 0)
|
2013-12-17 22:34:08 +00:00
|
|
|
InitRoutineName = (LPCSTR)SEG_OFF_TO_PTR(getES(), getDI());
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Retrieve the dispatch routine API name in DS:BX */
|
2013-12-17 22:34:08 +00:00
|
|
|
DispatchRoutineName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getBX());
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
DPRINT1("DllName = '%s' - InitRoutineName = '%s' - DispatchRoutineName = '%s'\n",
|
|
|
|
(DllName ? DllName : "n/a"),
|
|
|
|
(InitRoutineName ? InitRoutineName : "n/a"),
|
|
|
|
(DispatchRoutineName ? DispatchRoutineName : "n/a"));
|
|
|
|
|
|
|
|
/* Load the VDD DLL */
|
|
|
|
hDll = LoadLibraryA(DllName);
|
|
|
|
if (hDll == NULL)
|
|
|
|
{
|
|
|
|
DWORD LastError = GetLastError();
|
|
|
|
Success = FALSE;
|
|
|
|
|
|
|
|
if (LastError == ERROR_NOT_ENOUGH_MEMORY)
|
|
|
|
{
|
|
|
|
DPRINT1("Not enough memory to load DLL '%s'\n", DllName);
|
|
|
|
RetVal = 4;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to load DLL '%s'; last error = %d\n", DllName, LastError);
|
|
|
|
RetVal = 1;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the initialization routine if needed */
|
|
|
|
if (InitRoutineName)
|
|
|
|
{
|
2013-12-17 22:10:58 +00:00
|
|
|
InitRoutine = (VDD_PROC)GetProcAddress(hDll, InitRoutineName);
|
2013-12-17 02:19:52 +00:00
|
|
|
if (InitRoutine == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to load the initialization routine '%s'\n", InitRoutineName);
|
|
|
|
Success = FALSE;
|
|
|
|
RetVal = 3;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the dispatch routine */
|
2013-12-17 22:10:58 +00:00
|
|
|
DispatchRoutine = (VDD_PROC)GetProcAddress(hDll, DispatchRoutineName);
|
2013-12-17 02:19:52 +00:00
|
|
|
if (DispatchRoutine == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to load the dispatch routine '%s'\n", DispatchRoutineName);
|
|
|
|
Success = FALSE;
|
|
|
|
RetVal = 2;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
2015-05-11 23:04:24 +00:00
|
|
|
/* If we reached this point, that means everything is OK */
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Register the VDD DLL */
|
|
|
|
VDDList[Entry].hDll = hDll;
|
|
|
|
VDDList[Entry].DispatchRoutine = DispatchRoutine;
|
|
|
|
|
|
|
|
/* Call the initialization routine if needed */
|
|
|
|
if (InitRoutine) InitRoutine();
|
|
|
|
|
2013-12-17 22:34:08 +00:00
|
|
|
/* We succeeded. RetVal will contain a valid VDD DLL handle */
|
2013-12-17 02:19:52 +00:00
|
|
|
Success = TRUE;
|
2013-12-17 22:34:08 +00:00
|
|
|
RetVal = ENTRY_TO_HANDLE(Entry); // Convert the entry to a valid handle
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
Quit:
|
|
|
|
if (!Success)
|
|
|
|
{
|
|
|
|
/* Unload the VDD DLL */
|
|
|
|
if (hDll) FreeLibrary(hDll);
|
|
|
|
|
|
|
|
/* Set the Carry Flag to indicate that an error happened */
|
|
|
|
setCF(1);
|
|
|
|
}
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// /* Clear the Carry Flag (success) */
|
|
|
|
// setCF(0);
|
|
|
|
// }
|
|
|
|
setAX(RetVal);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UnRegisterModule */
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-17 22:34:08 +00:00
|
|
|
WORD Handle = getAX();
|
|
|
|
WORD Entry = HANDLE_TO_ENTRY(Handle); // Convert the handle to a valid entry
|
2013-12-17 02:19:52 +00:00
|
|
|
|
2013-12-27 19:51:43 +00:00
|
|
|
DPRINT("UnRegisterModule() called\n");
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2013-12-17 22:34:08 +00:00
|
|
|
if (!IS_VALID_HANDLE(Handle) || VDDList[Entry].hDll == NULL)
|
2013-12-17 02:19:52 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Invalid VDD DLL Handle: %d\n", Entry);
|
|
|
|
/* Stop the VDM */
|
2014-03-02 14:37:51 +00:00
|
|
|
EmulatorTerminate();
|
2013-12-17 02:19:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unregister the VDD DLL */
|
|
|
|
FreeLibrary(VDDList[Entry].hDll);
|
|
|
|
VDDList[Entry].hDll = NULL;
|
|
|
|
VDDList[Entry].DispatchRoutine = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DispatchCall */
|
|
|
|
case 2:
|
|
|
|
{
|
2013-12-17 22:34:08 +00:00
|
|
|
WORD Handle = getAX();
|
|
|
|
WORD Entry = HANDLE_TO_ENTRY(Handle); // Convert the handle to a valid entry
|
2013-12-17 02:19:52 +00:00
|
|
|
|
2013-12-27 19:51:43 +00:00
|
|
|
DPRINT("DispatchCall() called\n");
|
2013-12-17 02:19:52 +00:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2013-12-17 22:34:08 +00:00
|
|
|
if (!IS_VALID_HANDLE(Handle) ||
|
2013-12-17 02:19:52 +00:00
|
|
|
VDDList[Entry].hDll == NULL ||
|
|
|
|
VDDList[Entry].DispatchRoutine == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid VDD DLL Handle: %d\n", Entry);
|
|
|
|
/* Stop the VDM */
|
2014-03-02 14:37:51 +00:00
|
|
|
EmulatorTerminate();
|
2013-12-17 02:19:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the dispatch routine */
|
|
|
|
VDDList[Entry].DispatchRoutine();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("Unknown 3rd-party VDD BOP Function: 0x%02X\n", FuncNum);
|
|
|
|
setCF(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:11:11 +00:00
|
|
|
static BOOL LoadInstallableVDD(VOID)
|
2013-12-24 13:33:51 +00:00
|
|
|
{
|
2015-05-07 01:23:33 +00:00
|
|
|
// FIXME: These strings should be localized.
|
2013-12-24 13:33:51 +00:00
|
|
|
#define ERROR_MEMORYVDD L"Insufficient memory to load installable Virtual Device Drivers."
|
|
|
|
#define ERROR_REGVDD L"Virtual Device Driver format in the registry is invalid."
|
|
|
|
#define ERROR_LOADVDD L"An installable Virtual Device Driver failed Dll initialization."
|
|
|
|
|
|
|
|
BOOL Success = TRUE;
|
|
|
|
LONG Error = 0;
|
|
|
|
DWORD Type = 0;
|
|
|
|
DWORD BufSize = 0;
|
|
|
|
|
|
|
|
HKEY hVDDKey;
|
|
|
|
LPCWSTR VDDKeyName = L"SYSTEM\\CurrentControlSet\\Control\\VirtualDeviceDrivers";
|
|
|
|
LPWSTR VDDValueName = L"VDD";
|
|
|
|
LPWSTR VDDList = NULL;
|
|
|
|
|
|
|
|
HANDLE hVDD;
|
|
|
|
|
2013-12-28 22:22:12 +00:00
|
|
|
/* Try to open the VDD registry key */
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
VDDKeyName,
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hVDDKey);
|
|
|
|
if (Error == ERROR_FILE_NOT_FOUND)
|
2013-12-24 13:33:51 +00:00
|
|
|
{
|
2013-12-28 22:22:12 +00:00
|
|
|
/* If the key just doesn't exist, don't do anything else */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (Error != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* The key exists but there was an access error: display an error and quit */
|
2013-12-24 13:33:51 +00:00
|
|
|
DisplayMessage(ERROR_REGVDD);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve the size of the VDD registry value
|
|
|
|
* and check that it's of REG_MULTI_SZ type.
|
|
|
|
*/
|
|
|
|
Error = RegQueryValueExW(hVDDKey,
|
|
|
|
VDDValueName,
|
|
|
|
NULL,
|
|
|
|
&Type,
|
|
|
|
NULL,
|
|
|
|
&BufSize);
|
2013-12-28 22:22:12 +00:00
|
|
|
if (Error == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
/* If the value just doesn't exist, don't do anything else */
|
|
|
|
Success = TRUE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
else if (Error != ERROR_SUCCESS || Type != REG_MULTI_SZ)
|
2013-12-24 13:33:51 +00:00
|
|
|
{
|
2013-12-28 22:22:12 +00:00
|
|
|
/*
|
|
|
|
* The value exists but there was an access error or
|
|
|
|
* is of the wrong type: display an error and quit.
|
|
|
|
*/
|
2013-12-24 13:33:51 +00:00
|
|
|
DisplayMessage(ERROR_REGVDD);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the buffer */
|
|
|
|
BufSize = (BufSize < 2*sizeof(WCHAR) ? 2*sizeof(WCHAR) : BufSize);
|
2015-04-19 00:01:03 +00:00
|
|
|
VDDList = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, BufSize);
|
2013-12-24 13:33:51 +00:00
|
|
|
if (VDDList == NULL)
|
|
|
|
{
|
|
|
|
DisplayMessage(ERROR_MEMORYVDD);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the list of VDDs to load */
|
|
|
|
if (RegQueryValueExW(hVDDKey,
|
|
|
|
VDDValueName,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)VDDList,
|
|
|
|
&BufSize) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DisplayMessage(ERROR_REGVDD);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the VDDs */
|
|
|
|
VDDValueName = VDDList;
|
|
|
|
while (*VDDList)
|
|
|
|
{
|
2023-12-16 22:57:35 +00:00
|
|
|
DPRINT1("Loading VDD '%S'... ", VDDList);
|
2013-12-24 13:33:51 +00:00
|
|
|
hVDD = LoadLibraryW(VDDList);
|
|
|
|
if (hVDD == NULL)
|
|
|
|
{
|
|
|
|
DbgPrint("Failed\n");
|
|
|
|
DisplayMessage(ERROR_LOADVDD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DbgPrint("Succeeded\n");
|
|
|
|
}
|
|
|
|
/* Go to next string */
|
|
|
|
VDDList += wcslen(VDDList) + 1;
|
|
|
|
}
|
|
|
|
VDDList = VDDValueName;
|
|
|
|
|
|
|
|
Quit:
|
2015-04-19 00:01:03 +00:00
|
|
|
if (VDDList) RtlFreeHeap(RtlGetProcessHeap(), 0, VDDList);
|
2013-12-24 13:33:51 +00:00
|
|
|
RegCloseKey(hVDDKey);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
2015-05-11 23:04:24 +00:00
|
|
|
/*
|
|
|
|
* NOTE: This function can be called multiple times by the same VDD, if
|
|
|
|
* it wants to install different hooks for a same action. The most recent
|
|
|
|
* registered hooks are called first.
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
VDDInstallUserHook(IN HANDLE hVdd,
|
|
|
|
IN PFNVDD_UCREATE Ucr_Handler,
|
|
|
|
IN PFNVDD_UTERMINATE Uterm_Handler,
|
|
|
|
IN PFNVDD_UBLOCK Ublock_Handler,
|
|
|
|
IN PFNVDD_URESUME Uresume_Handler)
|
|
|
|
{
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Check validity of the VDD handle */
|
|
|
|
if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: If we want that a VDD can install hooks only once, it's here
|
|
|
|
// that we need to check whether a hook entry is already registered.
|
|
|
|
|
|
|
|
/* Create and initialize a new hook entry... */
|
|
|
|
UserHook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*UserHook));
|
|
|
|
if (UserHook == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserHook->hVdd = hVdd;
|
|
|
|
UserHook->Ucr_Handler = Ucr_Handler;
|
|
|
|
UserHook->Uterm_Handler = Uterm_Handler;
|
|
|
|
UserHook->Ublock_Handler = Ublock_Handler;
|
|
|
|
UserHook->Uresume_Handler = Uresume_Handler;
|
|
|
|
|
|
|
|
/* ... and add it at the top of the list of hooks */
|
|
|
|
InsertHeadList(&VddUserHooksList, &UserHook->Entry);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: This function uninstalls the latest installed hooks for a given VDD.
|
|
|
|
* It can be called multiple times by the same VDD to uninstall many hooks
|
|
|
|
* installed by multiple invocations of VDDInstallUserHook.
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
VDDDeInstallUserHook(IN HANDLE hVdd)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Pointer;
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Check validity of the VDD handle */
|
|
|
|
if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uninstall the latest installed hooks */
|
|
|
|
for (Pointer = VddUserHooksList.Flink; Pointer != &VddUserHooksList; Pointer = Pointer->Flink)
|
|
|
|
{
|
|
|
|
UserHook = CONTAINING_RECORD(Pointer, VDD_USER_HANDLERS, Entry);
|
|
|
|
if (UserHook->hVdd == hVdd)
|
|
|
|
{
|
|
|
|
RemoveEntryList(&UserHook->Entry);
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, UserHook);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal functions for calling the VDD user hooks.
|
|
|
|
* Their names come directly from the Windows 2kX DDK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VOID VDDCreateUserHook(USHORT DosPDB)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Pointer;
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Call the hooks starting from the most recent ones */
|
|
|
|
for (Pointer = VddUserHooksList.Flink; Pointer != &VddUserHooksList; Pointer = Pointer->Flink)
|
|
|
|
{
|
|
|
|
UserHook = CONTAINING_RECORD(Pointer, VDD_USER_HANDLERS, Entry);
|
|
|
|
if (UserHook->Ucr_Handler) UserHook->Ucr_Handler(DosPDB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID VDDTerminateUserHook(USHORT DosPDB)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Pointer;
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Call the hooks starting from the most recent ones */
|
|
|
|
for (Pointer = VddUserHooksList.Flink; Pointer != &VddUserHooksList; Pointer = Pointer->Flink)
|
|
|
|
{
|
|
|
|
UserHook = CONTAINING_RECORD(Pointer, VDD_USER_HANDLERS, Entry);
|
|
|
|
if (UserHook->Uterm_Handler) UserHook->Uterm_Handler(DosPDB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID VDDBlockUserHook(VOID)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Pointer;
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Call the hooks starting from the most recent ones */
|
|
|
|
for (Pointer = VddUserHooksList.Flink; Pointer != &VddUserHooksList; Pointer = Pointer->Flink)
|
|
|
|
{
|
|
|
|
UserHook = CONTAINING_RECORD(Pointer, VDD_USER_HANDLERS, Entry);
|
|
|
|
if (UserHook->Ublock_Handler) UserHook->Ublock_Handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID VDDResumeUserHook(VOID)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY Pointer;
|
|
|
|
PVDD_USER_HANDLERS UserHook;
|
|
|
|
|
|
|
|
/* Call the hooks starting from the most recent ones */
|
|
|
|
for (Pointer = VddUserHooksList.Flink; Pointer != &VddUserHooksList; Pointer = Pointer->Flink)
|
|
|
|
{
|
|
|
|
UserHook = CONTAINING_RECORD(Pointer, VDD_USER_HANDLERS, Entry);
|
|
|
|
if (UserHook->Uresume_Handler) UserHook->Uresume_Handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 02:19:52 +00:00
|
|
|
VOID VDDSupInitialize(VOID)
|
|
|
|
{
|
|
|
|
/* Register the 3rd-party VDD BOP Handler */
|
|
|
|
RegisterBop(BOP_3RDPARTY, ThirdPartyVDDBop);
|
2013-12-24 13:33:51 +00:00
|
|
|
|
|
|
|
/* Load the installable VDDs from the registry */
|
|
|
|
LoadInstallableVDD();
|
2013-12-17 02:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|