Author: hbelusca
Date: Sun May 4 00:01:48 2014
New Revision: 63141
URL:
http://svn.reactos.org/svn/reactos?rev=63141&view=rev
Log:
[CONSRV]
- Move aliases & history management structures & initialization into the console
server part.
- Maintain two different console lists, the first one for all the consoles (that are
managed by the console driver) and the other for the consoles that are also owned by the
console server.
- Simplify few function prototypes.
Modified:
branches/condrv_restructure/win32ss/user/winsrv/consrv/condrv/console.c
branches/condrv_restructure/win32ss/user/winsrv/consrv/console.c
branches/condrv_restructure/win32ss/user/winsrv/consrv/console.h
branches/condrv_restructure/win32ss/user/winsrv/consrv/consrv.h
branches/condrv_restructure/win32ss/user/winsrv/consrv/handle.c
branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio.h
branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio_winsrv.h
branches/condrv_restructure/win32ss/user/winsrv/consrv/include/console.h
branches/condrv_restructure/win32ss/user/winsrv/consrv/init.c
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/condrv/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/condrv/console.c [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/condrv/console.c [iso-8859-1]
Sun May 4 00:01:48 2014
@@ -12,7 +12,6 @@
#include <consrv.h>
-#include <alias.h>
#include <coninput.h>
#define NDEBUG
@@ -21,8 +20,10 @@
/* GLOBALS ********************************************************************/
-static ULONG ConsoleListSize;
-static PCONSOLE* ConsoleList; /* The list of all the allocated consoles */
+static ULONG CurrentConsoleID = 0;
+
+/* Linked list of consoles */
+static LIST_ENTRY ConsoleList;
static RTL_RESOURCE ListLock;
#define ConDrvLockConsoleListExclusive() \
@@ -33,6 +34,47 @@
#define ConDrvUnlockConsoleList() \
RtlReleaseResource(&ListLock)
+
+
+static NTSTATUS
+InsertConsole(IN PCONSOLE Console)
+{
+ ASSERT(Console);
+
+ /* All went right, so add the console to the list */
+ ConDrvLockConsoleListExclusive();
+
+ DPRINT1("Insert in the list\n");
+ InsertTailList(&ConsoleList, &Console->ListEntry);
+
+ // FIXME: Move this code to the caller function!!
+ /* Get a new console ID */
+ _InterlockedExchange((PLONG)&Console->ConsoleID, CurrentConsoleID);
+ _InterlockedIncrement((PLONG)&CurrentConsoleID);
+
+ /* Unlock the console list and return success */
+ ConDrvUnlockConsoleList();
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS
+RemoveConsole(IN PCONSOLE Console)
+{
+ // ASSERT(Console);
+ if (!Console) return STATUS_INVALID_PARAMETER;
+
+ /* Remove the console from the list */
+ ConDrvLockConsoleListExclusive();
+
+ RemoveEntryList(&Console->ListEntry);
+
+ /* Unlock the console list and return success */
+ ConDrvUnlockConsoleList();
+ return STATUS_SUCCESS;
+}
+
+
+/* PRIVATE FUNCTIONS **********************************************************/
// Adapted from reactos/lib/rtl/unicode.c, RtlCreateUnicodeString line 2180
static BOOLEAN
@@ -63,135 +105,6 @@
}
}
-
-static NTSTATUS
-InsertConsole(OUT PHANDLE Handle,
- IN PCONSOLE Console)
-{
-#define CONSOLE_HANDLES_INCREMENT 2 * 3
-
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG i = 0;
- PCONSOLE* Block;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* All went right, so add the console to the list */
- ConDrvLockConsoleListExclusive();
- DPRINT1("Insert in the list\n");
-
- if (ConsoleList)
- {
- for (i = 0; i < ConsoleListSize; i++)
- {
- if (ConsoleList[i] == NULL) break;
- }
- }
-
- if (i >= ConsoleListSize)
- {
- DPRINT1("Creation of a new handles table\n");
- /* Allocate a new handles table */
- Block = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
- (ConsoleListSize +
- CONSOLE_HANDLES_INCREMENT) * sizeof(PCONSOLE));
- if (Block == NULL)
- {
- Status = STATUS_UNSUCCESSFUL;
- goto Quit;
- }
-
- /* If we previously had a handles table, free it and use the new one */
- if (ConsoleList)
- {
- /* Copy the handles from the old table to the new one */
- RtlCopyMemory(Block,
- ConsoleList,
- ConsoleListSize * sizeof(PCONSOLE));
- ConsoleFreeHeap(ConsoleList);
- }
- ConsoleList = Block;
- ConsoleListSize += CONSOLE_HANDLES_INCREMENT;
- }
-
- ConsoleList[i] = Console;
- *Handle = ULongToHandle((i << 2) | 0x3);
-
-Quit:
- /* Unlock the console list and return status */
- ConDrvUnlockConsoleList();
- return Status;
-}
-
-/* Unused */
-#if 0
-static NTSTATUS
-RemoveConsoleByHandle(IN HANDLE Handle)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PCONSOLE Console;
-
- BOOLEAN ValidHandle = ((HandleToULong(Handle) & 0x3) == 0x3);
- ULONG Index = HandleToULong(Handle) >> 2;
-
- if (!ValidHandle) return STATUS_INVALID_HANDLE;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* Remove the console from the list */
- ConDrvLockConsoleListExclusive();
-
- if (Index >= ConsoleListSize ||
- (Console = ConsoleList[Index]) == NULL)
- {
- Status = STATUS_INVALID_HANDLE;
- goto Quit;
- }
-
- ConsoleList[Index] = NULL;
-
-Quit:
- /* Unlock the console list and return status */
- ConDrvUnlockConsoleList();
- return Status;
-}
-#endif
-
-static NTSTATUS
-RemoveConsoleByPointer(IN PCONSOLE Console)
-{
- ULONG i = 0;
-
- if (!Console) return STATUS_INVALID_PARAMETER;
-
- ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
- (ConsoleList != NULL && ConsoleListSize != 0) );
-
- /* Remove the console from the list */
- ConDrvLockConsoleListExclusive();
-
- if (ConsoleList)
- {
- for (i = 0; i < ConsoleListSize; i++)
- {
- if (ConsoleList[i] == Console) ConsoleList[i] = NULL;
- }
- }
-
- /* Unlock the console list */
- ConDrvUnlockConsoleList();
-
- return STATUS_SUCCESS;
-}
-
-
-/* PRIVATE FUNCTIONS **********************************************************/
-
-/* For resetting the terminal - defined in dummyterm.c */
-VOID ResetTerminal(IN PCONSOLE Console);
-
VOID NTAPI
ConDrvPause(PCONSOLE Console)
{
@@ -254,103 +167,6 @@
return TRUE;
}
-BOOLEAN NTAPI
-ConDrvValidateConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN CONSOLE_STATE ExpectedState,
- IN BOOLEAN LockConsole)
-{
- BOOLEAN RetVal = FALSE;
- PCONSOLE ValidatedConsole;
-
- BOOLEAN ValidHandle = ((HandleToULong(ConsoleHandle) & 0x3) == 0x3);
- ULONG Index = HandleToULong(ConsoleHandle) >> 2;
-
- if (!ValidHandle) return FALSE;
-
- if (!Console) return FALSE;
- *Console = NULL;
-
- /*
- * Forbid creation or deletion of consoles when
- * checking for the existence of a console.
- */
- ConDrvLockConsoleListShared();
-
- if (Index >= ConsoleListSize ||
- (ValidatedConsole = ConsoleList[Index]) == NULL)
- {
- /* Unlock the console list */
- ConDrvUnlockConsoleList();
-
- return FALSE;
- }
-
- ValidatedConsole = ConsoleList[Index];
-
- /* Unlock the console list and return */
- ConDrvUnlockConsoleList();
-
- RetVal = ConDrvValidateConsoleUnsafe(ValidatedConsole,
- ExpectedState,
- LockConsole);
- if (RetVal) *Console = ValidatedConsole;
-
- return RetVal;
-}
-
-NTSTATUS NTAPI
-ConDrvGetConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN BOOLEAN LockConsole)
-{
- NTSTATUS Status = STATUS_INVALID_HANDLE;
- PCONSOLE GrabConsole;
-
- if (Console == NULL) return STATUS_INVALID_PARAMETER;
- *Console = NULL;
-
- if (ConDrvValidateConsole(&GrabConsole,
- ConsoleHandle,
- CONSOLE_RUNNING,
- LockConsole))
- {
- InterlockedIncrement(&GrabConsole->ReferenceCount);
- *Console = GrabConsole;
- Status = STATUS_SUCCESS;
- }
-
- return Status;
-}
-
-VOID NTAPI
-ConDrvReleaseConsole(IN PCONSOLE Console,
- IN BOOLEAN WasConsoleLocked)
-{
- LONG RefCount = 0;
-
- if (!Console) return;
- // if (Console->ReferenceCount == 0) return; // This shouldn't happen
- ASSERT(Console->ReferenceCount > 0);
-
- /* The console must be locked */
- // ASSERT(Console_locked);
-
- /*
- * Decrement the reference count. Save the new value too,
- * because Console->ReferenceCount might be modified after
- * the console gets unlocked but before we check whether we
- * can destroy it.
- */
- RefCount = _InterlockedDecrement(&Console->ReferenceCount);
-
- /* Unlock the console if needed */
- if (WasConsoleLocked) LeaveCriticalSection(&Console->Lock);
-
- /* Delete the console if needed */
- if (RefCount <= 0) ConDrvDeleteConsole(Console);
-}
-
/* CONSOLE INITIALIZATION FUNCTIONS *******************************************/
@@ -360,38 +176,36 @@
DPRINT("CONSRV: ConDrvInitConsoleSupport()\n");
/* Initialize the console list and its lock */
- ConsoleListSize = 0;
- ConsoleList = NULL;
+ InitializeListHead(&ConsoleList);
RtlInitializeResource(&ListLock);
/* Should call LoadKeyboardLayout */
}
-NTSTATUS NTAPI
-ConDrvInitConsole(OUT PHANDLE NewConsoleHandle,
- OUT PCONSOLE* NewConsole,
- IN PCONSOLE_INFO ConsoleInfo,
- IN ULONG ConsoleLeaderProcessId)
+/* For resetting the terminal - defined in dummyterm.c */
+VOID ResetTerminal(IN PCONSOLE Console);
+
+NTSTATUS NTAPI
+ConDrvInitConsole(OUT PCONSOLE* NewConsole,
+ IN PCONSOLE_INFO ConsoleInfo)
{
NTSTATUS Status;
SECURITY_ATTRIBUTES SecurityAttributes;
// CONSOLE_INFO CapturedConsoleInfo;
TEXTMODE_BUFFER_INFO ScreenBufferInfo;
- HANDLE ConsoleHandle;
PCONSOLE Console;
PCONSOLE_SCREEN_BUFFER NewBuffer;
#if 0
WCHAR DefaultTitle[128];
#endif
- if (NewConsoleHandle == NULL || NewConsole == NULL || ConsoleInfo == NULL)
+ if (NewConsole == NULL || ConsoleInfo == NULL)
return STATUS_INVALID_PARAMETER;
- *NewConsoleHandle = NULL;
*NewConsole = NULL;
/*
- * Allocate a console structure
+ * Allocate a new console
*/
Console = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*Console));
if (NULL == Console)
@@ -478,15 +292,6 @@
Console->ActiveBuffer = NewBuffer;
Console->UnpauseEvent = NULL;
- /*
- * Initialize the alias and history buffers
- */
- Console->Aliases = NULL;
- InitializeListHead(&Console->HistoryBuffers);
- Console->HistoryBufferSize = ConsoleInfo->HistoryBufferSize;
- Console->NumberOfHistoryBuffers = ConsoleInfo->NumberOfHistoryBuffers;
- Console->HistoryNoDup = ConsoleInfo->HistoryNoDup;
-
/* Initialize the console title */
ConsoleCreateUnicodeString(&Console->OriginalTitle,
ConsoleInfo->ConsoleTitle);
#if 0
@@ -509,13 +314,10 @@
}
#endif
- /* Lock the console until its initialization is finished */
- // EnterCriticalSection(&Console->Lock);
-
DPRINT("Console initialized\n");
/* All went right, so add the console to the list */
- Status = InsertConsole(&ConsoleHandle, Console);
+ Status = InsertConsole(Console);
if (!NT_SUCCESS(Status))
{
/* Fail */
@@ -527,12 +329,8 @@
DPRINT("Change state\n");
Console->State = CONSOLE_RUNNING;
- /* Unlock the console */
- // LeaveCriticalSection(&Console->Lock);
-
/* Return the newly created console to the caller and a success code too */
- *NewConsoleHandle = ConsoleHandle;
- *NewConsole = Console;
+ *NewConsole = Console;
return STATUS_SUCCESS;
}
@@ -630,7 +428,7 @@
/*
* Allow other threads to finish their job: basically, unlock
* all other calls to EnterCriticalSection(&Console->Lock); by
- * ConDrvValidateConsole(Unsafe) functions so that they just see
+ * ConDrvValidateConsoleUnsafe functions so that they just see
* that we are not in CONSOLE_RUNNING state anymore, or unlock
* other concurrent calls to ConDrvDeleteConsole so that they
* can see that we are in fact already deleting the console.
@@ -666,16 +464,13 @@
Console->ReferenceCount = 0;
/* Remove the console from the list */
- RemoveConsoleByPointer(Console);
+ RemoveConsole(Console);
/* Discard all entries in the input event queue */
PurgeInputBuffer(Console);
-
if (Console->LineBuffer) ConsoleFreeHeap(Console->LineBuffer);
- IntDeleteAllAliases(Console);
- HistoryDeleteBuffers(Console);
-
+ /* Delete the last screen buffer */
ConioDeleteScreenBuffer(Console->ActiveBuffer);
Console->ActiveBuffer = NULL;
if (!IsListEmpty(&Console->BufferList))
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/console.c [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/console.c [iso-8859-1] Sun May
4 00:01:48 2014
@@ -13,6 +13,8 @@
#include "consrv.h"
#include <ndk/psfuncs.h>
+
+#include <alias.h>
#include "procinit.h"
#define NDEBUG
@@ -22,6 +24,188 @@
NTSTATUS NTAPI RtlGetLastNtStatus(VOID);
/* GLOBALS ********************************************************************/
+
+static ULONG ConsoleListSize;
+static PCONSOLE* ConsoleList; /* The list of the ConSrv consoles */
+static RTL_RESOURCE ListLock;
+
+#define ConSrvLockConsoleListExclusive() \
+ RtlAcquireResourceExclusive(&ListLock, TRUE)
+
+#define ConSrvLockConsoleListShared() \
+ RtlAcquireResourceShared(&ListLock, TRUE)
+
+#define ConSrvUnlockConsoleList() \
+ RtlReleaseResource(&ListLock)
+
+
+static NTSTATUS
+InsertConsole(OUT PHANDLE Handle,
+ IN PCONSOLE Console)
+{
+#define CONSOLE_HANDLES_INCREMENT 2 * 3
+
+ NTSTATUS Status = STATUS_SUCCESS;
+ ULONG i = 0;
+ PCONSOLE* Block;
+
+ ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
+ (ConsoleList != NULL && ConsoleListSize != 0) );
+
+ /* All went right, so add the console to the list */
+ ConSrvLockConsoleListExclusive();
+ DPRINT1("Insert in the list\n");
+
+ if (ConsoleList)
+ {
+ for (i = 0; i < ConsoleListSize; i++)
+ {
+ if (ConsoleList[i] == NULL) break;
+ }
+ }
+
+ if (i >= ConsoleListSize)
+ {
+ DPRINT1("Creation of a new handles table\n");
+ /* Allocate a new handles table */
+ Block = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
+ (ConsoleListSize +
+ CONSOLE_HANDLES_INCREMENT) * sizeof(PCONSOLE));
+ if (Block == NULL)
+ {
+ Status = STATUS_UNSUCCESSFUL;
+ goto Quit;
+ }
+
+ /* If we previously had a handles table, free it and use the new one */
+ if (ConsoleList)
+ {
+ /* Copy the handles from the old table to the new one */
+ RtlCopyMemory(Block,
+ ConsoleList,
+ ConsoleListSize * sizeof(PCONSOLE));
+ ConsoleFreeHeap(ConsoleList);
+ }
+ ConsoleList = Block;
+ ConsoleListSize += CONSOLE_HANDLES_INCREMENT;
+ }
+
+ ConsoleList[i] = Console;
+ *Handle = ULongToHandle((i << 2) | 0x3);
+
+Quit:
+ /* Unlock the console list and return status */
+ ConSrvUnlockConsoleList();
+ return Status;
+}
+
+/* Unused */
+#if 0
+static NTSTATUS
+RemoveConsoleByHandle(IN HANDLE Handle)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+ PCONSOLE Console;
+
+ BOOLEAN ValidHandle = ((HandleToULong(Handle) & 0x3) == 0x3);
+ ULONG Index = HandleToULong(Handle) >> 2;
+
+ if (!ValidHandle) return STATUS_INVALID_HANDLE;
+
+ ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
+ (ConsoleList != NULL && ConsoleListSize != 0) );
+
+ /* Remove the console from the list */
+ ConSrvLockConsoleListExclusive();
+
+ if (Index >= ConsoleListSize ||
+ (Console = ConsoleList[Index]) == NULL)
+ {
+ Status = STATUS_INVALID_HANDLE;
+ goto Quit;
+ }
+
+ ConsoleList[Index] = NULL;
+
+Quit:
+ /* Unlock the console list and return status */
+ ConSrvUnlockConsoleList();
+ return Status;
+}
+#endif
+
+static NTSTATUS
+RemoveConsoleByPointer(IN PCONSOLE Console)
+{
+ ULONG i = 0;
+
+ if (!Console) return STATUS_INVALID_PARAMETER;
+
+ ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
+ (ConsoleList != NULL && ConsoleListSize != 0) );
+
+ /* Remove the console from the list */
+ ConSrvLockConsoleListExclusive();
+
+ if (ConsoleList)
+ {
+ for (i = 0; i < ConsoleListSize; i++)
+ {
+ if (ConsoleList[i] == Console) ConsoleList[i] = NULL;
+ }
+ }
+
+ /* Unlock the console list */
+ ConSrvUnlockConsoleList();
+
+ return STATUS_SUCCESS;
+}
+
+BOOLEAN NTAPI
+ConSrvValidateConsole(OUT PCONSOLE* Console,
+ IN HANDLE ConsoleHandle,
+ IN CONSOLE_STATE ExpectedState,
+ IN BOOLEAN LockConsole)
+{
+ BOOLEAN RetVal = FALSE;
+ PCONSOLE ValidatedConsole;
+
+ BOOLEAN ValidHandle = ((HandleToULong(ConsoleHandle) & 0x3) == 0x3);
+ ULONG Index = HandleToULong(ConsoleHandle) >> 2;
+
+ if (!ValidHandle) return FALSE;
+
+ if (!Console) return FALSE;
+ *Console = NULL;
+
+ /*
+ * Forbid creation or deletion of consoles when
+ * checking for the existence of a console.
+ */
+ ConSrvLockConsoleListShared();
+
+ if (Index >= ConsoleListSize ||
+ (ValidatedConsole = ConsoleList[Index]) == NULL)
+ {
+ /* Unlock the console list */
+ ConSrvUnlockConsoleList();
+
+ return FALSE;
+ }
+
+ ValidatedConsole = ConsoleList[Index];
+
+ /* Unlock the console list and return */
+ ConSrvUnlockConsoleList();
+
+ RetVal = ConDrvValidateConsoleUnsafe(ValidatedConsole,
+ ExpectedState,
+ LockConsole);
+ if (RetVal) *Console = ValidatedConsole;
+
+ return RetVal;
+}
+
/* PRIVATE FUNCTIONS **********************************************************/
@@ -54,33 +238,76 @@
}
NTSTATUS
-ConSrvGetConsole(PCONSOLE_PROCESS_DATA ProcessData,
- PCONSOLE* Console,
- BOOL LockConsole)
-{
- NTSTATUS Status = STATUS_SUCCESS;
- PCONSOLE ProcessConsole;
-
+ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData,
+ OUT PCONSOLE* Console,
+ IN BOOLEAN LockConsole)
+{
+ NTSTATUS Status = STATUS_INVALID_HANDLE;
+ PCONSOLE GrabConsole;
+
+ // if (Console == NULL) return STATUS_INVALID_PARAMETER;
ASSERT(Console);
*Console = NULL;
// RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- Status = ConDrvGetConsole(&ProcessConsole, ProcessData->ConsoleHandle,
LockConsole);
- if (NT_SUCCESS(Status)) *Console = ProcessConsole;
+ if (ConSrvValidateConsole(&GrabConsole,
+ ProcessData->ConsoleHandle,
+ CONSOLE_RUNNING,
+ LockConsole))
+ {
+ InterlockedIncrement(&GrabConsole->ReferenceCount);
+ *Console = GrabConsole;
+ Status = STATUS_SUCCESS;
+ }
// RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
}
VOID
-ConSrvReleaseConsole(PCONSOLE Console,
- BOOL WasConsoleLocked)
-{
- /* Just call the driver */
- ConDrvReleaseConsole(Console, WasConsoleLocked);
-}
-
+ConSrvReleaseConsole(IN PCONSOLE Console,
+ IN BOOLEAN WasConsoleLocked)
+{
+ LONG RefCount = 0;
+
+ if (!Console) return;
+ // if (Console->ReferenceCount == 0) return; // This shouldn't happen
+ ASSERT(Console->ReferenceCount > 0);
+
+ /* The console must be locked */
+ // ASSERT(Console_locked);
+
+ /*
+ * Decrement the reference count. Save the new value too,
+ * because Console->ReferenceCount might be modified after
+ * the console gets unlocked but before we check whether we
+ * can destroy it.
+ */
+ RefCount = _InterlockedDecrement(&Console->ReferenceCount);
+
+ /* Unlock the console if needed */
+ if (WasConsoleLocked) LeaveCriticalSection(&Console->Lock);
+
+ /* Delete the console if needed */
+ if (RefCount <= 0) ConSrvDeleteConsole(Console);
+}
+
+
+/* CONSOLE INITIALIZATION FUNCTIONS *******************************************/
+
+VOID NTAPI
+ConSrvInitConsoleSupport(VOID)
+{
+ DPRINT("CONSRV: ConSrvInitConsoleSupport()\n");
+
+ /* Initialize the console list and its lock */
+ ConsoleListSize = 0;
+ ConsoleList = NULL;
+ RtlInitializeResource(&ListLock);
+
+ /* Should call LoadKeyboardLayout */
+}
NTSTATUS NTAPI
ConSrvInitTerminal(IN OUT PTERMINAL Terminal,
@@ -170,10 +397,7 @@
ConsoleInfo.CodePage = GetOEMCP();
/* Initialize a new console via the driver */
- Status = ConDrvInitConsole(&ConsoleHandle,
- &Console,
- &ConsoleInfo,
- ConsoleLeaderProcessId);
+ Status = ConDrvInitConsole(&Console, &ConsoleInfo);
if (!NT_SUCCESS(Status))
{
DPRINT1("Creating a new console failed, Status = 0x%08lx\n", Status);
@@ -196,6 +420,13 @@
InitializeListHead(&Console->ReadWaitQueue);
InitializeListHead(&Console->WriteWaitQueue);
+ /* Initialize the alias and history buffers */
+ Console->Aliases = NULL;
+ InitializeListHead(&Console->HistoryBuffers);
+ Console->HistoryBufferSize = ConsoleInfo.HistoryBufferSize;
+ Console->NumberOfHistoryBuffers = ConsoleInfo.NumberOfHistoryBuffers;
+ Console->HistoryNoDup = ConsoleInfo.HistoryNoDup;
+
Console->QuickEdit = ConsoleInfo.QuickEdit;
/* Attach the ConSrv terminal to the console */
@@ -209,6 +440,9 @@
}
DPRINT("Terminal registered\n");
+ /* All went right, so add the console to the list */
+ Status = InsertConsole(&ConsoleHandle, Console);
+
/* Return the newly created console to the caller and a success code too */
*NewConsoleHandle = ConsoleHandle;
*NewConsole = Console;
@@ -220,7 +454,16 @@
{
DPRINT("ConSrvDeleteConsole\n");
- /* Just call the driver. ConDrvDeregisterTerminal is called on-demand. */
+ // FIXME: Send a terminate message to all the processes owning this console
+
+ /* Remove the console from the list */
+ RemoveConsoleByPointer(Console);
+
+ /* Clean aliases and history */
+ IntDeleteAllAliases(Console);
+ HistoryDeleteBuffers(Console);
+
+ /* Now, call the driver. ConDrvDeregisterTerminal is called on-demand. */
ConDrvDeleteConsole(Console);
}
@@ -402,7 +645,7 @@
/* Return the console handle and the input wait handle to the caller */
AllocConsoleRequest->ConsoleHandle = ProcessData->ConsoleHandle;
- AllocConsoleRequest->InputWaitHandle = ProcessData->ConsoleEvent;
+ AllocConsoleRequest->InputWaitHandle = ProcessData->InputWaitHandle;
/* Set the Property-Dialog and Control-Dispatcher handlers */
ProcessData->PropDispatcher = AllocConsoleRequest->PropDispatcher;
@@ -479,7 +722,7 @@
/* Return the console handle and the input wait handle to the caller */
AttachConsoleRequest->ConsoleHandle = TargetProcessData->ConsoleHandle;
- AttachConsoleRequest->InputWaitHandle = TargetProcessData->ConsoleEvent;
+ AttachConsoleRequest->InputWaitHandle = TargetProcessData->InputWaitHandle;
/* Set the Property-Dialog and Control-Dispatcher handlers */
TargetProcessData->PropDispatcher = AttachConsoleRequest->PropDispatcher;
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/console.h
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/console.h [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/console.h [iso-8859-1] Sun May
4 00:01:48 2014
@@ -8,6 +8,9 @@
#pragma once
+VOID NTAPI
+ConSrvInitConsoleSupport(VOID);
+
NTSTATUS NTAPI
ConSrvInitConsole(OUT PHANDLE NewConsoleHandle,
OUT struct _CONSOLE** /* PCONSOLE* */ NewConsole,
@@ -15,8 +18,17 @@
IN ULONG ConsoleLeaderProcessId);
VOID NTAPI ConSrvDeleteConsole(struct _CONSOLE* /* PCONSOLE */ Console);
-NTSTATUS ConSrvGetConsole(PCONSOLE_PROCESS_DATA ProcessData,
- struct _CONSOLE** /* PCONSOLE* */ Console,
- BOOL LockConsole);
-VOID ConSrvReleaseConsole(struct _CONSOLE* /* PCONSOLE */ Console,
- BOOL WasConsoleLocked);
+NTSTATUS
+ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData,
+ OUT struct _CONSOLE** /* PCONSOLE* */ Console,
+ IN BOOLEAN LockConsole);
+VOID
+ConSrvReleaseConsole(IN struct _CONSOLE* /* PCONSOLE */ Console,
+ IN BOOLEAN WasConsoleLocked);
+
+
+BOOLEAN NTAPI
+ConSrvValidateConsole(OUT struct _CONSOLE** /* PCONSOLE* */ Console,
+ IN HANDLE ConsoleHandle,
+ IN CONSOLE_STATE ExpectedState,
+ IN BOOLEAN LockConsole);
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/consrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1] Sun May
4 00:01:48 2014
@@ -51,7 +51,7 @@
{
LIST_ENTRY ConsoleLink;
PCSR_PROCESS Process; // Process owning this structure.
- HANDLE ConsoleEvent;
+ HANDLE InputWaitHandle;
HANDLE ConsoleHandle;
HANDLE ParentConsoleHandle;
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/handle.c
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/handle.c [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/handle.c [iso-8859-1] Sun May
4 00:01:48 2014
@@ -440,7 +440,7 @@
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
- // Status = ConDrvGetConsole(&ObjectConsole, ProcessData->ConsoleHandle,
LockConsole);
+ // Status = ConSrvGetConsole(ProcessData, &ObjectConsole, LockConsole);
// if (NT_SUCCESS(Status))
if (ConDrvValidateConsoleUnsafe(ObjectEntry->Console, CONSOLE_RUNNING,
LockConsole))
{
@@ -522,7 +522,7 @@
Status = NtDuplicateObject(NtCurrentProcess(),
Console->InputBuffer.ActiveEvent,
ProcessData->Process->ProcessHandle,
- &ProcessData->ConsoleEvent,
+ &ProcessData->InputWaitHandle,
EVENT_ALL_ACCESS, 0, 0);
if (!NT_SUCCESS(Status))
{
@@ -557,7 +557,7 @@
PCONSOLE Console;
/* Validate and lock the console */
- if (!ConDrvValidateConsole(&Console,
+ if (!ConSrvValidateConsole(&Console,
ConsoleHandle,
CONSOLE_RUNNING, TRUE))
{
@@ -600,7 +600,7 @@
Status = NtDuplicateObject(NtCurrentProcess(),
Console->InputBuffer.ActiveEvent,
ProcessData->Process->ProcessHandle,
- &ProcessData->ConsoleEvent,
+ &ProcessData->InputWaitHandle,
EVENT_ALL_ACCESS, 0, 0);
if (!NT_SUCCESS(Status))
{
@@ -637,7 +637,7 @@
// RtlEnterCriticalSection(&ProcessData->HandleTableLock);
/* Validate and lock the console */
- if (ConDrvValidateConsole(&Console,
+ if (ConSrvValidateConsole(&Console,
ProcessData->ConsoleHandle,
CONSOLE_RUNNING, TRUE))
{
@@ -689,9 +689,9 @@
/* Release the console */
DPRINT("ConSrvRemoveConsole - Decrement Console->ReferenceCount =
%lu\n", Console->ReferenceCount);
- ConDrvReleaseConsole(Console, TRUE);
- //CloseHandle(ProcessData->ConsoleEvent);
- //ProcessData->ConsoleEvent = NULL;
+ ConSrvReleaseConsole(Console, TRUE);
+ //CloseHandle(ProcessData->InputWaitHandle);
+ //ProcessData->InputWaitHandle = NULL;
}
// RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio.h
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio.h [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio.h [iso-8859-1]
Sun May 4 00:01:48 2014
@@ -274,6 +274,7 @@
TERMINAL TermIFace; /* Frontend-specific interface */
ULONG ConsoleID; /* The ID of the console */
+ LIST_ENTRY ListEntry; /* Entry in the list of consoles */
/**************************** Input buffer and data ***************************/
CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
@@ -296,13 +297,6 @@
LIST_ENTRY BufferList; /* List of all screen buffers for this
console */
PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer
*/
UINT OutputCodePage;
-
-/**************************** Aliases and Histories ***************************/
- struct _ALIAS_HEADER *Aliases;
- LIST_ENTRY HistoryBuffers;
- ULONG HistoryBufferSize; /* Size for newly created history buffers */
- ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed
*/
- BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
/****************************** Other properties ******************************/
UNICODE_STRING OriginalTitle; /* Original title of console, the one defined
when the console leader is launched; it never changes. Always NULL-terminated */
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio_winsrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
---
branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio_winsrv.h [iso-8859-1]
(original)
+++
branches/condrv_restructure/win32ss/user/winsrv/consrv/include/conio_winsrv.h [iso-8859-1]
Sun May 4 00:01:48 2014
@@ -109,15 +109,24 @@
FRONTEND FrontEndIFace; /* Frontend-specific interface */
+/******************************* Process support ******************************/
LIST_ENTRY ProcessList; /* List of processes owning the console. The first
one is the so-called "Console Leader Process" */
PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess; /* Pointer to the unique process that
needs to be notified when the console leader process is killed */
BOOLEAN NotifyLastClose; /* TRUE if the console should send a control event
when the console leader process is killed */
BOOLEAN QuickEdit;
+/******************************* Pausing support ******************************/
BYTE PauseFlags;
LIST_ENTRY ReadWaitQueue; /* List head for the queue of unique input buffer
read wait blocks */
LIST_ENTRY WriteWaitQueue; /* List head for the queue of current screen-buffer
write wait blocks */
+
+/**************************** Aliases and Histories ***************************/
+ struct _ALIAS_HEADER *Aliases;
+ LIST_ENTRY HistoryBuffers;
+ ULONG HistoryBufferSize; /* Size for newly created history buffers */
+ ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed
*/
+ BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
} WINSRV_CONSOLE, *PWINSRV_CONSOLE;
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/include/console.h
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/include/console.h [iso-8859-1]
(original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/include/console.h [iso-8859-1]
Sun May 4 00:01:48 2014
@@ -12,10 +12,8 @@
ConDrvInitConsoleSupport(VOID);
NTSTATUS NTAPI
-ConDrvInitConsole(OUT PHANDLE NewConsoleHandle,
- OUT PCONSOLE* NewConsole,
- IN PCONSOLE_INFO ConsoleInfo,
- IN ULONG ConsoleLeaderProcessId);
+ConDrvInitConsole(OUT PCONSOLE* NewConsole,
+ IN PCONSOLE_INFO ConsoleInfo);
NTSTATUS NTAPI
ConDrvRegisterTerminal(IN PCONSOLE Console,
IN PTERMINAL Terminal);
@@ -35,20 +33,4 @@
IN CONSOLE_STATE ExpectedState,
IN BOOLEAN LockConsole);
-BOOLEAN NTAPI
-ConDrvValidateConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN CONSOLE_STATE ExpectedState,
- IN BOOLEAN LockConsole);
-
-
-
-NTSTATUS NTAPI
-ConDrvGetConsole(OUT PCONSOLE* Console,
- IN HANDLE ConsoleHandle,
- IN BOOLEAN LockConsole);
-VOID NTAPI
-ConDrvReleaseConsole(IN PCONSOLE Console,
- IN BOOLEAN WasConsoleLocked);
-
/* EOF */
Modified: branches/condrv_restructure/win32ss/user/winsrv/consrv/init.c
URL:
http://svn.reactos.org/svn/reactos/branches/condrv_restructure/win32ss/user…
==============================================================================
--- branches/condrv_restructure/win32ss/user/winsrv/consrv/init.c [iso-8859-1] (original)
+++ branches/condrv_restructure/win32ss/user/winsrv/consrv/init.c [iso-8859-1] Sun May 4
00:01:48 2014
@@ -353,7 +353,7 @@
/* Initialize the new (target) process */
RtlZeroMemory(TargetProcessData, sizeof(*TargetProcessData));
TargetProcessData->Process = TargetProcess;
- TargetProcessData->ConsoleEvent = NULL;
+ TargetProcessData->InputWaitHandle = NULL;
TargetProcessData->ConsoleHandle = TargetProcessData->ParentConsoleHandle =
NULL;
TargetProcessData->ConsoleApp = ((TargetProcess->Flags &
CsrProcessIsConsoleApp) ? TRUE : FALSE);
@@ -383,7 +383,7 @@
PCONSOLE SourceConsole;
/* Validate and lock the parent's console */
- if (ConDrvValidateConsole(&SourceConsole,
+ if (ConSrvValidateConsole(&SourceConsole,
SourceProcessData->ConsoleHandle,
CONSOLE_RUNNING, TRUE))
{
@@ -484,7 +484,7 @@
/* Return the console handle and the input wait handle to the caller */
ConnectInfo->ConsoleHandle = ProcessData->ConsoleHandle;
- ConnectInfo->InputWaitHandle = ProcessData->ConsoleEvent;
+ ConnectInfo->InputWaitHandle = ProcessData->InputWaitHandle;
/* Set the Property-Dialog and Control-Dispatcher handlers */
ProcessData->PropDispatcher = ConnectInfo->ConsoleStartInfo.PropDispatcher;
@@ -529,6 +529,7 @@
*/
ConDrvInitConsoleSupport();
+ ConSrvInitConsoleSupport();
/* Setup the DLL Object */
LoadedServerDll->ApiBase = CONSRV_FIRST_API_NUMBER;