#include "consrv.h"
#include "conio.h"
-#define NDEBUG
+//#define NDEBUG
#include <debug.h>
/* PRIVATE FUNCTIONS *********************************************************/
static INT
-AdjustHandleCounts(PCSRSS_HANDLE Entry, INT Change)
+AdjustHandleCounts(PCONSOLE_IO_HANDLE Entry, INT Change)
{
Object_t *Object = Entry->Object;
}
static VOID
-Win32CsrCreateHandleEntry(PCSRSS_HANDLE Entry)
+Win32CsrCreateHandleEntry(PCONSOLE_IO_HANDLE Entry)
{
Object_t *Object = Entry->Object;
EnterCriticalSection(&Object->Console->Lock);
}
static VOID
-Win32CsrCloseHandleEntry(PCSRSS_HANDLE Entry)
+Win32CsrCloseHandleEntry(PCONSOLE_IO_HANDLE Entry)
{
Object_t *Object = Entry->Object;
-
if (Object != NULL)
{
- PCSRSS_CONSOLE Console = Object->Console;
+ PCONSOLE Console = Object->Console;
EnterCriticalSection(&Console->Lock);
- if (Object->Type == CONIO_CONSOLE_MAGIC)
- {
- // LIST_ENTRY WaitQueue;
-
- /*
- * Wake-up all of the writing waiters if any, dereference them
- * and purge them all from the list.
- */
- CsrNotifyWait(&Console->ReadWaitQueue,
- WaitAll,
- NULL,
- (PVOID)0xdeaddead);
- // InitializeListHead(&WaitQueue);
-
- // CsrMoveSatisfiedWait(&WaitQueue, &Console->ReadWaitQueue);
- if (!IsListEmpty(&Console->ReadWaitQueue /* &WaitQueue */))
- {
- CsrDereferenceWait(&Console->ReadWaitQueue /* &WaitQueue */);
- }
- }
-
/* If the last handle to a screen buffer is closed, delete it... */
if (AdjustHandleCounts(Entry, -1) == 0)
{
if (Object->Type == CONIO_SCREEN_BUFFER_MAGIC)
{
- PCSRSS_SCREEN_BUFFER Buffer = (PCSRSS_SCREEN_BUFFER)Object;
+ PCONSOLE_SCREEN_BUFFER Buffer = (PCONSOLE_SCREEN_BUFFER)Object;
/* ...unless it's the only buffer left. Windows allows deletion
* even of the last buffer, but having to deal with a lack of
* any active buffer might be error-prone. */
DWORD ShareMode)
{
ULONG i;
- PCSRSS_HANDLE Block;
+ PCONSOLE_IO_HANDLE Block;
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
{
Block = RtlAllocateHeap(ConSrvHeap,
HEAP_ZERO_MEMORY,
- (ProcessData->HandleTableSize + 64) * sizeof(CSRSS_HANDLE));
+ (ProcessData->HandleTableSize + 64) * sizeof(CONSOLE_IO_HANDLE));
if (Block == NULL)
{
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
}
RtlCopyMemory(Block,
ProcessData->HandleTable,
- ProcessData->HandleTableSize * sizeof(CSRSS_HANDLE));
+ ProcessData->HandleTableSize * sizeof(CONSOLE_IO_HANDLE));
RtlFreeHeap(ConSrvHeap, 0, ProcessData->HandleTable);
ProcessData->HandleTable = Block;
ProcessData->HandleTableSize += 64;
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
+
+ DPRINT1("Win32CsrReleaseObject - Process 0x%p, Release 0x%p\n", ProcessData->Process, &ProcessData->HandleTable[h]);
Win32CsrCloseHandleEntry(&ProcessData->HandleTable[h]);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
}
VOID FASTCALL
-Win32CsrUnlockConsole(PCSRSS_CONSOLE Console)
+Win32CsrUnlockConsole(PCONSOLE Console)
{
LeaveCriticalSection(&Console->Lock);
-#if 0
- /* If it was the last held lock for the owning thread... */
- if (&Console->Lock.RecursionCount == 0)
- {
- /* ...dereference waiting threads if any */
- LIST_ENTRY WaitQueue;
- InitializeListHead(&WaitQueue);
-
- CsrMoveSatisfiedWait(&WaitQueue, Console->SatisfiedWaits);
- Console->SatisfiedWaits = NULL;
- if (!IsListEmpty(&WaitQueue))
- {
- CsrDereferenceWait(&WaitQueue);
- }
- }
-#endif
-
/* Decrement reference count */
if (_InterlockedDecrement(&Console->ReferenceCount) == 0)
ConioDeleteConsole(Console);
TargetProcessData->HandleTable = RtlAllocateHeap(ConSrvHeap,
HEAP_ZERO_MEMORY,
SourceProcessData->HandleTableSize
- * sizeof(CSRSS_HANDLE));
+ * sizeof(CONSOLE_IO_HANDLE));
if (TargetProcessData->HandleTable == NULL)
{
RtlLeaveCriticalSection(&SourceProcessData->HandleTableLock);
return STATUS_SUCCESS;
}
-// Temporary ; move it to a header.
-NTSTATUS WINAPI CsrInitConsole(PCSRSS_CONSOLE* NewConsole, int ShowCmd);
-
NTSTATUS
NTAPI
ConsoleConnect(IN PCSR_PROCESS CsrProcess,
PCONSOLE_CONNECTION_INFO ConnectInfo = (PCONSOLE_CONNECTION_INFO)ConnectionInfo;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
BOOLEAN NewConsole = FALSE;
- // PCSRSS_CONSOLE Console = NULL;
+ // PCONSOLE Console = NULL;
DPRINT1("ConsoleConnect\n");
if (!ConnectInfo->Console ||
ConnectInfo->Console != ProcessData->ParentConsole)
{
- // PCSRSS_CONSOLE Console;
-
DPRINT1("ConsoleConnect - Allocate a new console\n");
- /* Initialize a new Console */
+ /* Initialize a new Console owned by the Console Leader Process */
NewConsole = TRUE;
- Status = CsrInitConsole(&ProcessData->Console, ConnectInfo->ShowCmd);
+ Status = CsrInitConsole(&ProcessData->Console, ConnectInfo->ShowCmd, CsrProcess);
if (!NT_SUCCESS(Status))
{
DPRINT1("Console initialization failed\n");
Win32CsrReleaseConsole(PCSR_PROCESS Process)
{
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
- PCSRSS_CONSOLE Console;
+ PCONSOLE Console;
ULONG i;
DPRINT1("Win32CsrReleaseConsole\n");
CSR_API(SrvCloseHandle)
{
- PCSRSS_CLOSE_HANDLE CloseHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CloseHandleRequest;
+ PCONSOLE_CLOSEHANDLE CloseHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CloseHandleRequest;
return Win32CsrReleaseObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
- CloseHandleRequest->Handle);
+ CloseHandleRequest->ConsoleHandle);
}
CSR_API(SrvVerifyConsoleIoHandle)
{
NTSTATUS Status = STATUS_SUCCESS;
- PCSRSS_VERIFY_HANDLE VerifyHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.VerifyHandleRequest;
+ PCONSOLE_VERIFYHANDLE VerifyHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.VerifyHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
- HANDLE Handle = VerifyHandleRequest->Handle;
- ULONG_PTR Index = (ULONG_PTR)Handle >> 2;
+ HANDLE ConsoleHandle = VerifyHandleRequest->ConsoleHandle;
+ ULONG_PTR Index = (ULONG_PTR)ConsoleHandle >> 2;
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if (!IsConsoleHandle(Handle) ||
+ if (!IsConsoleHandle(ConsoleHandle) ||
Index >= ProcessData->HandleTableSize ||
ProcessData->HandleTable[Index].Object == NULL)
{
CSR_API(SrvDuplicateHandle)
{
- PCSRSS_HANDLE Entry;
+ PCONSOLE_IO_HANDLE Entry;
DWORD DesiredAccess;
- PCSRSS_DUPLICATE_HANDLE DuplicateHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.DuplicateHandleRequest;
+ PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.DuplicateHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
- HANDLE Handle = DuplicateHandleRequest->Handle;
- ULONG_PTR Index = (ULONG_PTR)Handle >> 2;
+ HANDLE ConsoleHandle = DuplicateHandleRequest->ConsoleHandle;
+ ULONG_PTR Index = (ULONG_PTR)ConsoleHandle >> 2;
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if ( /** !IsConsoleHandle(Handle) || **/
+ if ( /** !IsConsoleHandle(ConsoleHandle) || **/
Index >= ProcessData->HandleTableSize ||
(Entry = &ProcessData->HandleTable[Index])->Object == NULL)
{
- DPRINT1("Couldn't duplicate invalid handle %p\n", Handle);
+ DPRINT1("Couldn't duplicate invalid handle %p\n", ConsoleHandle);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
if (~Entry->Access & DesiredAccess)
{
DPRINT1("Handle %p only has access %X; requested %X\n",
- Handle, Entry->Access, DesiredAccess);
+ ConsoleHandle, Entry->Access, DesiredAccess);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_PARAMETER;
}
}
ApiMessage->Status = Win32CsrInsertObject(ProcessData,
- &DuplicateHandleRequest->Handle, // Use the new handle value!
+ &DuplicateHandleRequest->ConsoleHandle, // Use the new handle value!
Entry->Object,
DesiredAccess,
DuplicateHandleRequest->Inheritable,