From c64a03a80f07b6b6a98e07abac8b3aa151797305 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Sun, 16 Feb 2014 00:09:27 +0000 Subject: [PATCH] [BASESRV] Move the VDM states and binary types to a public header file. Implement GetNextDosSesId. Continue implementing BaseSrvCheckVDM. svn path=/branches/ntvdm/; revision=62200 --- dll/win32/kernel32/include/vdm.h | 18 ------- dll/win32/kernel32/k32.h | 1 + include/reactos/subsys/win/vdm.h | 35 +++++++++++++ subsystems/win/basesrv/vdm.c | 89 +++++++++++++++++++++++++++++++- subsystems/win/basesrv/vdm.h | 3 ++ 5 files changed, 126 insertions(+), 20 deletions(-) create mode 100644 include/reactos/subsys/win/vdm.h diff --git a/dll/win32/kernel32/include/vdm.h b/dll/win32/kernel32/include/vdm.h index 646298c0d0c..5917a22f3b3 100644 --- a/dll/win32/kernel32/include/vdm.h +++ b/dll/win32/kernel32/include/vdm.h @@ -25,24 +25,6 @@ typedef enum _VDM_ENTRY_CODE #define VDM_UNDO_REUSE 0x04 #define VDM_UNDO_COMPLETED 0x08 -// -// Binary Types to share with VDM -// -#define BINARY_TYPE_EXE 0x01 -#define BINARY_TYPE_COM 0x02 -#define BINARY_TYPE_PIF 0x03 -#define BINARY_TYPE_DOS 0x10 -#define BINARY_TYPE_SEPARATE_WOW 0x20 -#define BINARY_TYPE_WOW 0x40 -#define BINARY_TYPE_WOW_EX 0x80 - -// -// VDM States -// -#define VDM_NOT_LOADED 0x01 -#define VDM_NOT_READY 0x02 -#define VDM_READY 0x04 - /* STRUCTURES *****************************************************************/ typedef struct _GET_NEXT_VDM_COMMAND_DATA diff --git a/dll/win32/kernel32/k32.h b/dll/win32/kernel32/k32.h index e544b0c7eef..7228f83ed80 100644 --- a/dll/win32/kernel32/k32.h +++ b/dll/win32/kernel32/k32.h @@ -46,6 +46,7 @@ #include #include #include +#include /* DDK Driver Headers */ #include diff --git a/include/reactos/subsys/win/vdm.h b/include/reactos/subsys/win/vdm.h new file mode 100644 index 00000000000..7df83a003f7 --- /dev/null +++ b/include/reactos/subsys/win/vdm.h @@ -0,0 +1,35 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS Base API Server DLL + * FILE: include/reactos/subsys/win/vdm.h + * PURPOSE: Public definitions for the Virtual Dos Machine + * PROGRAMMERS: Aleksandar Andrejevic + * Alex Ionescu (alex.ionescu@reactos.org) + */ + +#ifndef _VDM_H +#define _VDM_H + +#pragma once + +// +// Binary Types to share with VDM +// +#define BINARY_TYPE_EXE 0x01 +#define BINARY_TYPE_COM 0x02 +#define BINARY_TYPE_PIF 0x03 +#define BINARY_TYPE_DOS 0x10 +#define BINARY_TYPE_SEPARATE_WOW 0x20 +#define BINARY_TYPE_WOW 0x40 +#define BINARY_TYPE_WOW_EX 0x80 + +// +// VDM States +// +#define VDM_NOT_LOADED 0x01 +#define VDM_NOT_READY 0x02 +#define VDM_READY 0x04 + +#endif // _VDM_H + +/* EOF */ diff --git a/subsystems/win/basesrv/vdm.c b/subsystems/win/basesrv/vdm.c index dcfeb6d5730..82e2d248084 100644 --- a/subsystems/win/basesrv/vdm.c +++ b/subsystems/win/basesrv/vdm.c @@ -20,6 +20,7 @@ BOOLEAN FirstVDM = TRUE; LIST_ENTRY VDMConsoleListHead; RTL_CRITICAL_SECTION DosCriticalSection; +RTL_CRITICAL_SECTION WowCriticalSection; /* FUNCTIONS ******************************************************************/ @@ -39,6 +40,35 @@ NTSTATUS NTAPI BaseSrvGetConsoleRecord(HANDLE ConsoleHandle, PVDM_CONSOLE_RECORD return CurrentRecord ? STATUS_SUCCESS : STATUS_NOT_FOUND; } +ULONG NTAPI GetNextDosSesId(VOID) +{ + ULONG SessionId; + PLIST_ENTRY i; + PVDM_CONSOLE_RECORD CurrentRecord = NULL; + BOOLEAN Found; + + /* Search for an available session ID */ + for (SessionId = 1; SessionId != 0; SessionId++) + { + Found = FALSE; + + /* Check if the ID is already in use */ + for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink) + { + CurrentRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry); + if (CurrentRecord->SessionId == SessionId) Found = TRUE; + } + + /* If not, we found one */ + if (!Found) break; + } + + ASSERT(SessionId != 0); + + /* Return the session ID */ + return SessionId; +} + VOID NTAPI BaseInitializeVDM(VOID) { /* Initialize the list head */ @@ -46,13 +76,17 @@ VOID NTAPI BaseInitializeVDM(VOID) /* Initialize the critical section */ RtlInitializeCriticalSection(&DosCriticalSection); + RtlInitializeCriticalSection(&WowCriticalSection); } /* PUBLIC SERVER APIS *********************************************************/ CSR_API(BaseSrvCheckVDM) { + NTSTATUS Status; PBASE_CHECK_VDM CheckVdmRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CheckVDMRequest; + PRTL_CRITICAL_SECTION CriticalSection = NULL; + PVDM_CONSOLE_RECORD ConsoleRecord = NULL; /* Validate the message buffers */ if (!CsrValidateMessageBuffer(ApiMessage, @@ -87,8 +121,59 @@ CSR_API(BaseSrvCheckVDM) return STATUS_INVALID_PARAMETER; } - // TODO: NOT IMPLEMENTED - return STATUS_NOT_IMPLEMENTED; + CriticalSection = (CheckVdmRequest->BinaryType != BINARY_TYPE_SEPARATE_WOW) + ? &DosCriticalSection + : &WowCriticalSection; + + /* Enter the critical section */ + RtlEnterCriticalSection(CriticalSection); + + /* Check if this is a DOS or WOW VDM */ + if (CheckVdmRequest->BinaryType != BINARY_TYPE_SEPARATE_WOW) + { + /* Get the console record */ + Status = BaseSrvGetConsoleRecord(CheckVdmRequest->ConsoleHandle, + &ConsoleRecord); + + if (!NT_SUCCESS(Status)) + { + /* Allocate a new console record */ + ConsoleRecord = (PVDM_CONSOLE_RECORD)RtlAllocateHeap(BaseSrvHeap, + HEAP_ZERO_MEMORY, + sizeof(VDM_CONSOLE_RECORD)); + if (ConsoleRecord == NULL) + { + Status = STATUS_NO_MEMORY; + goto Cleanup; + } + + /* Initialize the console record */ + ConsoleRecord->ConsoleHandle = CheckVdmRequest->ConsoleHandle; + ConsoleRecord->CurrentDirs = NULL; + ConsoleRecord->CurDirsLength = 0; + ConsoleRecord->SessionId = GetNextDosSesId(); + InitializeListHead(&ConsoleRecord->DosListHead); + + /* Add the console record */ + InsertTailList(&VDMConsoleListHead, &ConsoleRecord->Entry); + } + + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + return STATUS_NOT_IMPLEMENTED; + } + else + { + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + return STATUS_NOT_IMPLEMENTED; + } + +Cleanup: + /* Leave the critical section */ + RtlLeaveCriticalSection(CriticalSection); + + return Status; } CSR_API(BaseSrvUpdateVDMEntry) diff --git a/subsystems/win/basesrv/vdm.h b/subsystems/win/basesrv/vdm.h index 1b844b6aca8..3ade17fb0ce 100644 --- a/subsystems/win/basesrv/vdm.h +++ b/subsystems/win/basesrv/vdm.h @@ -9,6 +9,8 @@ #ifndef __VDM_H__ #define __VDM_H__ +#include + /* DEFINITIONS ****************************************************************/ typedef struct _VDM_CONSOLE_RECORD @@ -17,6 +19,7 @@ typedef struct _VDM_CONSOLE_RECORD HANDLE ConsoleHandle; PCHAR CurrentDirs; ULONG CurDirsLength; + ULONG SessionId; LIST_ENTRY DosListHead; // TODO: Structure incomplete!!! } VDM_CONSOLE_RECORD, *PVDM_CONSOLE_RECORD;