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 */
#endif
LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL;
- LoadedServerDll->DisconnectCallback = NULL;
+ LoadedServerDll->DisconnectCallback = BaseSrvDisconnect;
LoadedServerDll->ShutdownProcessCallback = NULL;
BaseSrvDllInstance = LoadedServerDll->ServerHandle;
/* INCLUDES *******************************************************************/
#include "basesrv.h"
+#include "vdm.h"
#define NDEBUG
#include <debug.h>
/* 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;
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);
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;
}
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;
HANDLE ProcessHandle;
HANDLE ServerEvent;
HANDLE ClientEvent;
+ ULONG ProcessId;
ULONG ReenterCount;
PCHAR CurrentDirs;
ULONG CurDirsLength;
/* 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__