Author: aandrejevic
Date: Tue Apr 29 00:41:48 2014
New Revision: 63042
URL:
http://svn.reactos.org/svn/reactos?rev=63042&view=rev
Log:
[BASESRV]
Implement BaseSrvDisconnect and BaseSrvCleanupVdmRecords, which will remove VDM console
and DOS records
which have been left behind by a terminated ntvdm process.
Implement the "VDM voodoo" in BaseSrvCreateProcess. It's supposed to store
the process ID of the VDM
in the VDM console record.
Fix minor bugs.
Add function declarations to the header file.
Modified:
branches/ntvdm/subsystems/win/basesrv/init.c
branches/ntvdm/subsystems/win/basesrv/proc.c
branches/ntvdm/subsystems/win/basesrv/vdm.c
branches/ntvdm/subsystems/win/basesrv/vdm.h
Modified: branches/ntvdm/subsystems/win/basesrv/init.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/win/basesrv/in…
==============================================================================
--- branches/ntvdm/subsystems/win/basesrv/init.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/win/basesrv/init.c [iso-8859-1] Tue Apr 29 00:41:48 2014
@@ -570,6 +570,14 @@
LoadedServerDll->SharedSection = BaseStaticServerData;
}
+VOID
+NTAPI
+BaseSrvDisconnect(PCSR_PROCESS Process)
+{
+ /* Cleanup the VDM console records */
+ BaseSrvCleanupVdmRecords(HandleToUlong(Process->ClientId.UniqueProcess));
+}
+
CSR_SERVER_DLL_INIT(ServerDllInitialization)
{
/* Setup the DLL Object */
@@ -582,7 +590,7 @@
#endif
LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL;
- LoadedServerDll->DisconnectCallback = NULL;
+ LoadedServerDll->DisconnectCallback = BaseSrvDisconnect;
LoadedServerDll->ShutdownProcessCallback = NULL;
BaseSrvDllInstance = LoadedServerDll->ServerHandle;
Modified: branches/ntvdm/subsystems/win/basesrv/proc.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/win/basesrv/pr…
==============================================================================
--- branches/ntvdm/subsystems/win/basesrv/proc.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/win/basesrv/proc.c [iso-8859-1] Tue Apr 29 00:41:48 2014
@@ -9,6 +9,7 @@
/* INCLUDES *******************************************************************/
#include "basesrv.h"
+#include "vdm.h"
#define NDEBUG
#include <debug.h>
@@ -167,7 +168,30 @@
/* FIXME: Should notify user32 */
- /* FIXME: VDM vodoo */
+ /* Check if this is a VDM process */
+ if (CreateProcessRequest->VdmBinaryType)
+ {
+ PVDM_CONSOLE_RECORD ConsoleRecord;
+
+ if (CreateProcessRequest->VdmTask != 0)
+ {
+ /* Get the console record using the task ID */
+ Status = GetConsoleRecordBySessionId(CreateProcessRequest->VdmTask,
+ &ConsoleRecord);
+ }
+ else
+ {
+ /* Get the console record using the console handle */
+ Status = BaseSrvGetConsoleRecord(CreateProcessRequest->hVDM,
+ &ConsoleRecord);
+ }
+
+ /* Check if it failed */
+ if (!NT_SUCCESS(Status)) return Status;
+
+ /* Store the process ID of the VDM in the console record */
+ ConsoleRecord->ProcessId =
HandleToUlong(CreateProcessRequest->ClientId.UniqueProcess);
+ }
/* Return the result of this operation */
return Status;
Modified: branches/ntvdm/subsystems/win/basesrv/vdm.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/win/basesrv/vd…
==============================================================================
--- branches/ntvdm/subsystems/win/basesrv/vdm.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/win/basesrv/vdm.c [iso-8859-1] Tue Apr 29 00:41:48 2014
@@ -203,7 +203,7 @@
return Status;
}
-VOID BaseSrvFreeVDMInfo(PVDM_COMMAND_INFO CommandInfo)
+VOID NTAPI BaseSrvFreeVDMInfo(PVDM_COMMAND_INFO CommandInfo)
{
/* Free the allocated structure members */
if (CommandInfo->CmdLine != NULL) RtlFreeHeap(BaseSrvHeap, 0,
CommandInfo->CmdLine);
@@ -219,6 +219,61 @@
RtlFreeHeap(BaseSrvHeap, 0, CommandInfo);
}
+VOID NTAPI BaseSrvCleanupVdmRecords(ULONG ProcessId)
+{
+ PLIST_ENTRY i;
+ PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
+ PVDM_DOS_RECORD DosRecord;
+
+ /* Enter the critical section */
+ RtlEnterCriticalSection(&DosCriticalSection);
+
+ /* Search for a record that has the same process handle */
+ for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
+ {
+ ConsoleRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);
+
+ if (ConsoleRecord->ProcessId == ProcessId)
+ {
+ /* Cleanup the DOS records */
+ while (ConsoleRecord->DosListHead.Flink !=
&ConsoleRecord->DosListHead)
+ {
+ DosRecord = CONTAINING_RECORD(ConsoleRecord->DosListHead.Flink,
+ VDM_DOS_RECORD,
+ Entry);
+
+ /* Set the event and close it */
+ NtSetEvent(DosRecord->ServerEvent, NULL);
+ NtClose(DosRecord->ServerEvent);
+
+ /* Remove the DOS entry */
+ if (DosRecord->CommandInfo)
BaseSrvFreeVDMInfo(DosRecord->CommandInfo);
+ RemoveEntryList(&DosRecord->Entry);
+ RtlFreeHeap(BaseSrvHeap, 0, DosRecord);
+ }
+
+ if (ConsoleRecord->CurrentDirs != NULL)
+ {
+ /* Free the current directories */
+ RtlFreeHeap(BaseSrvHeap, 0, ConsoleRecord->CurrentDirs);
+ ConsoleRecord->CurrentDirs = NULL;
+ ConsoleRecord->CurDirsLength = 0;
+ }
+
+ /* Close the event handle */
+ if (ConsoleRecord->ServerEvent) NtClose(ConsoleRecord->ServerEvent);
+
+ /* Remove the console record */
+ i = i->Blink;
+ RemoveEntryList(&ConsoleRecord->Entry);
+ RtlFreeHeap(BaseSrvHeap, 0, ConsoleRecord);
+ }
+ }
+
+ /* Leave the critical section */
+ RtlLeaveCriticalSection(&DosCriticalSection);
+}
+
BOOLEAN NTAPI BaseSrvCopyCommand(PBASE_CHECK_VDM CheckVdmRequest, PVDM_DOS_RECORD
DosRecord)
{
BOOLEAN Success = FALSE;
@@ -367,7 +422,7 @@
}
NTSTATUS NTAPI BaseSrvFillCommandInfo(PVDM_COMMAND_INFO CommandInfo,
- PBASE_GET_NEXT_VDM_COMMAND Message)
+ PBASE_GET_NEXT_VDM_COMMAND Message)
{
/* Copy the data */
Message->iTask = CommandInfo->TaskId;
Modified: branches/ntvdm/subsystems/win/basesrv/vdm.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/win/basesrv/vd…
==============================================================================
--- branches/ntvdm/subsystems/win/basesrv/vdm.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/win/basesrv/vdm.h [iso-8859-1] Tue Apr 29 00:41:48 2014
@@ -23,6 +23,7 @@
HANDLE ProcessHandle;
HANDLE ServerEvent;
HANDLE ClientEvent;
+ ULONG ProcessId;
ULONG ReenterCount;
PCHAR CurrentDirs;
ULONG CurDirsLength;
@@ -43,6 +44,17 @@
/* FUNCTIONS ******************************************************************/
NTSTATUS NTAPI BaseSrvGetConsoleRecord(HANDLE ConsoleHandle, PVDM_CONSOLE_RECORD
*Record);
+NTSTATUS NTAPI GetConsoleRecordBySessionId(ULONG TaskId, PVDM_CONSOLE_RECORD *Record);
+ULONG NTAPI GetNextDosSesId(VOID);
+BOOLEAN NTAPI BaseSrvIsVdmAllowed(VOID);
+NTSTATUS NTAPI BaseSrvCreatePairWaitHandles(PHANDLE ServerEvent, PHANDLE ClientEvent);
+VOID NTAPI BaseSrvFreeVDMInfo(PVDM_COMMAND_INFO CommandInfo);
+VOID NTAPI BaseSrvCleanupVdmRecords(ULONG ProcessId);
+BOOLEAN NTAPI BaseSrvCopyCommand(PBASE_CHECK_VDM CheckVdmRequest, PVDM_DOS_RECORD
DosRecord);
+NTSTATUS NTAPI BaseSrvFillCommandInfo(
+ PVDM_COMMAND_INFO CommandInfo,
+ PBASE_GET_NEXT_VDM_COMMAND Message
+);
VOID NTAPI BaseInitializeVDM(VOID);
#endif // __VDM_H__