[BASESRV]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 16 Feb 2014 00:09:27 +0000 (00:09 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 16 Feb 2014 00:09:27 +0000 (00:09 +0000)
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
dll/win32/kernel32/k32.h
include/reactos/subsys/win/vdm.h [new file with mode: 0644]
subsystems/win/basesrv/vdm.c
subsystems/win/basesrv/vdm.h

index 646298c..5917a22 100644 (file)
@@ -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
index e544b0c..7228f83 100644 (file)
@@ -46,6 +46,7 @@
 #include <win/basemsg.h>
 #include <win/console.h>
 #include <win/conmsg.h>
+#include <win/vdm.h>
 
 /* DDK Driver Headers */
 #include <mountmgr.h>
diff --git a/include/reactos/subsys/win/vdm.h b/include/reactos/subsys/win/vdm.h
new file mode 100644 (file)
index 0000000..7df83a0
--- /dev/null
@@ -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 <theflash AT sdf DOT lonestar DOT org>
+ *                  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 */
index dcfeb6d..82e2d24 100644 (file)
@@ -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)
index 1b844b6..3ade17f 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef __VDM_H__
 #define __VDM_H__
 
+#include <win/vdm.h>
+
 /* 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;