Author: hbelusca Date: Tue Dec 17 22:34:08 2013 New Revision: 61287
URL: http://svn.reactos.org/svn/reactos?rev=61287&view=rev Log: [NTVDM] Studying the "vddtest" example mentioned in revision 61283 allowed me to see that valid VDD DLL "handles" start at 1 and cannot be equal to zero. Add helper macros to convert from indices to handles. Fixes "vddtest" example.
Have fun at running it :)
Modified: branches/ntvdm/subsystems/ntvdm/vddsup.c
Modified: branches/ntvdm/subsystems/ntvdm/vddsup.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/vddsup.c?... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/vddsup.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/vddsup.c [iso-8859-1] Tue Dec 17 22:34:08 2013 @@ -29,9 +29,15 @@
/* PRIVATE VARIABLES **********************************************************/
+// TODO: Maybe use a linked list. +// But the number of elements must be <= MAXUSHORT #define MAX_VDD_MODULES 0xFF + 1 -VDD_MODULE VDDList[MAX_VDD_MODULES] = {{NULL}}; // TODO: Maybe use a linked list. - // But the number of elements must be <= MAXUSHORT +VDD_MODULE VDDList[MAX_VDD_MODULES] = {{NULL}}; + +// 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)
/* PRIVATE FUNCTIONS **********************************************************/
@@ -72,14 +78,14 @@ setCF(0);
/* Retrieve the VDD name in DS:SI */ - DllName = SEG_OFF_TO_PTR(getDS(), getSI()); + DllName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getSI());
/* Retrieve the initialization routine API name in ES:DI (optional --> ES=DI=0) */ if (getES() != 0 || getDI() != 0) - InitRoutineName = SEG_OFF_TO_PTR(getES(), getDI()); + InitRoutineName = (LPCSTR)SEG_OFF_TO_PTR(getES(), getDI());
/* Retrieve the dispatch routine API name in DS:BX */ - DispatchRoutineName = SEG_OFF_TO_PTR(getDS(), getBX()); + DispatchRoutineName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getBX());
DPRINT1("DllName = '%s' - InitRoutineName = '%s' - DispatchRoutineName = '%s'\n", (DllName ? DllName : "n/a"), @@ -147,9 +153,9 @@ /* Call the initialization routine if needed */ if (InitRoutine) InitRoutine();
- /* We succeeded */ + /* We succeeded. RetVal will contain a valid VDD DLL handle */ Success = TRUE; - RetVal = Entry; + RetVal = ENTRY_TO_HANDLE(Entry); // Convert the entry to a valid handle
Quit: if (!Success) @@ -172,12 +178,13 @@ /* UnRegisterModule */ case 1: { - WORD Entry = getAX(); + WORD Handle = getAX(); + WORD Entry = HANDLE_TO_ENTRY(Handle); // Convert the handle to a valid entry
DPRINT1("UnRegisterModule() called\n");
/* Sanity checks */ - if (Entry > MAX_VDD_MODULES || VDDList[Entry].hDll == NULL) + if (!IS_VALID_HANDLE(Handle) || VDDList[Entry].hDll == NULL) { DPRINT1("Invalid VDD DLL Handle: %d\n", Entry); /* Stop the VDM */ @@ -195,12 +202,13 @@ /* DispatchCall */ case 2: { - WORD Entry = getAX(); + WORD Handle = getAX(); + WORD Entry = HANDLE_TO_ENTRY(Handle); // Convert the handle to a valid entry
DPRINT1("DispatchCall() called\n");
/* Sanity checks */ - if (Entry > MAX_VDD_MODULES || + if (!IS_VALID_HANDLE(Handle) || VDDList[Entry].hDll == NULL || VDDList[Entry].DispatchRoutine == NULL) {