Author: hbelusca
Date: Sun Dec 30 21:02:12 2012
New Revision: 58063
URL:
http://svn.reactos.org/svn/reactos?rev=58063&view=rev
Log:
[KERNEL32/CONSRV]
- Code reorganization.
- In particular, move IsConsoleHandle macro to a place which it can be used by both
kernel32 and consrv.
Modified:
branches/ros-csrss/dll/win32/kernel32/include/kernel32.h
branches/ros-csrss/dll/win32/kernel32/k32.h
branches/ros-csrss/include/reactos/subsys/win/console.h
branches/ros-csrss/win32ss/user/consrv/conio.h
branches/ros-csrss/win32ss/user/consrv/consrv.h
branches/ros-csrss/win32ss/user/consrv/handle.c
Modified: branches/ros-csrss/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/in…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ branches/ros-csrss/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Sun Dec 30
21:02:12 2012
@@ -61,9 +61,6 @@
#define FIELD_OFFSET(type,fld) ((LONG)&(((type *)0)->fld))
#endif
-#define IsConsoleHandle(h) \
- (((((ULONG_PTR)h) & 0x10000003) == 0x3) ? TRUE : FALSE)
-
#define HANDLE_DETACHED_PROCESS (HANDLE)-2
#define HANDLE_CREATE_NEW_CONSOLE (HANDLE)-3
#define HANDLE_CREATE_NO_WINDOW (HANDLE)-4
@@ -194,12 +191,12 @@
BOOL WINAPI CloseConsoleHandle(HANDLE Handle);
HANDLE WINAPI
-GetConsoleInputWaitHandle (VOID);
-
-HANDLE WINAPI OpenConsoleW (LPCWSTR wsName,
- DWORD dwDesiredAccess,
- BOOL bInheritHandle,
- DWORD dwShareMode);
+GetConsoleInputWaitHandle(VOID);
+
+HANDLE WINAPI OpenConsoleW(LPCWSTR wsName,
+ DWORD dwDesiredAccess,
+ BOOL bInheritHandle,
+ DWORD dwShareMode);
BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR lpInputExeName);
Modified: branches/ros-csrss/dll/win32/kernel32/k32.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/k3…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/k32.h [iso-8859-1] (original)
+++ branches/ros-csrss/dll/win32/kernel32/k32.h [iso-8859-1] Sun Dec 30 21:02:12 2012
@@ -39,6 +39,7 @@
#include <csr/csr.h>
#include <win/base.h>
#include <win/basemsg.h>
+#include <win/console.h>
#include <win/conmsg.h>
#include <win/winmsg.h>
Modified: branches/ros-csrss/include/reactos/subsys/win/console.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/console.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/console.h [iso-8859-1] Sun Dec 30
21:02:12 2012
@@ -11,23 +11,8 @@
#pragma once
-#define ConsoleGetPerProcessData(pcsrprocess) \
- ((PCONSOLE_PROCESS_DATA)((pcsrprocess)->ServerData[CONSRV_SERVERDLL_INDEX]))
-
-
-typedef struct _CONSOLE_PROCESS_DATA
-{
- LIST_ENTRY ConsoleLink;
- PCSR_PROCESS Process; // Parent process.
- HANDLE ConsoleEvent;
- /* PCSRSS_CONSOLE */ struct tagCSRSS_CONSOLE* Console;
- /* PCSRSS_CONSOLE */ struct tagCSRSS_CONSOLE* ParentConsole;
- BOOL bInheritHandles;
- RTL_CRITICAL_SECTION HandleTableLock;
- ULONG HandleTableSize;
- /* PCSRSS_HANDLE */ struct _CSRSS_HANDLE* HandleTable; // Is it a length-varying
table or length-fixed ??
- LPTHREAD_START_ROUTINE CtrlDispatcher;
-} CONSOLE_PROCESS_DATA, *PCONSOLE_PROCESS_DATA;
+#define IsConsoleHandle(h) \
+ (((ULONG_PTR)(h) & 0x3) == 0x3)
#endif // _CONSOLE_H
Modified: branches/ros-csrss/win32ss/user/consrv/conio.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conio.h [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conio.h [iso-8859-1] Sun Dec 30 21:02:12 2012
@@ -51,12 +51,16 @@
Object_t Header; /* Object header */
LONG ReferenceCount;
CRITICAL_SECTION Lock;
+
struct tagCSRSS_CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
+ struct tagCSRSS_CONSOLE_VTBL *Vtbl; /* Using CUI or GUI consoles */
+ LIST_ENTRY ProcessList;
+
+ LIST_ENTRY InputEvents; /* List head for input event queue */
HANDLE ActiveEvent; /* Event set when an input event is added in
its queue */
LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks
*/
- LIST_ENTRY InputEvents; /* List head for input event queue */
PWCHAR LineBuffer; /* current line being input, in line buffered
mode */
WORD LineMaxSize; /* maximum size of line in characters
(including CR+LF) */
WORD LineSize; /* current size of line */
@@ -65,28 +69,30 @@
BOOLEAN LineUpPressed;
BOOLEAN LineInsertToggle; /* replace character over cursor instead of
inserting */
ULONG LineWakeupMask; /* bitmap of which control characters will end
line input */
+
+ struct tagALIAS_HEADER *Aliases;
LIST_ENTRY HistoryBuffers;
UINT HistoryBufferSize; /* size for newly created history buffers */
UINT NumberOfHistoryBuffers; /* maximum number of history buffers allowed
*/
BOOLEAN HistoryNoDup; /* remove old duplicate history entries */
+
LIST_ENTRY BufferList; /* List of all screen buffers for this console
*/
PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer
*/
+ BYTE PauseFlags;
+ HANDLE UnpauseEvent;
+ LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks
*/
+
WORD Mode; /* Console mode flags */
UNICODE_STRING Title; /* Title of console */
DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
HWND hWindow;
COORD Size;
PVOID PrivateData;
+
UINT CodePage;
UINT OutputCodePage;
- struct tagCSRSS_CONSOLE_VTBL *Vtbl;
- LIST_ENTRY ProcessList;
- struct tagALIAS_HEADER *Aliases;
+
CONSOLE_SELECTION_INFO Selection;
-
- BYTE PauseFlags;
- HANDLE UnpauseEvent;
- LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks
*/
} CSRSS_CONSOLE, *PCSRSS_CONSOLE;
typedef struct tagCSRSS_CONSOLE_VTBL
Modified: branches/ros-csrss/win32ss/user/consrv/consrv.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/consrv.h [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/consrv.h [iso-8859-1] Sun Dec 30 21:02:12 2012
@@ -36,7 +36,7 @@
// extern PBASE_STATIC_SERVER_DATA BaseStaticServerData;
-
+/* Common things to input/output/console objects */
typedef struct Object_tt
{
LONG Type;
@@ -49,12 +49,29 @@
typedef struct _CSRSS_HANDLE
{
- Object_t *Object;
+ Object_t *Object; /* The object on which the handle points to */
DWORD Access;
BOOL Inheritable;
DWORD ShareMode;
} CSRSS_HANDLE, *PCSRSS_HANDLE;
+
+#define ConsoleGetPerProcessData(pcsrprocess) \
+ ((PCONSOLE_PROCESS_DATA)((pcsrprocess)->ServerData[CONSRV_SERVERDLL_INDEX]))
+
+typedef struct _CONSOLE_PROCESS_DATA
+{
+ LIST_ENTRY ConsoleLink;
+ PCSR_PROCESS Process; // Parent process.
+ HANDLE ConsoleEvent;
+ /* PCSRSS_CONSOLE */ struct tagCSRSS_CONSOLE* Console;
+ /* PCSRSS_CONSOLE */ struct tagCSRSS_CONSOLE* ParentConsole;
+ BOOL bInheritHandles;
+ RTL_CRITICAL_SECTION HandleTableLock;
+ ULONG HandleTableSize;
+ /* PCSRSS_HANDLE */ struct _CSRSS_HANDLE* HandleTable; // Is it a length-varying
table or length-fixed ??
+ LPTHREAD_START_ROUTINE CtrlDispatcher;
+} CONSOLE_PROCESS_DATA, *PCONSOLE_PROCESS_DATA;
/* alias.c */
Modified: branches/ros-csrss/win32ss/user/consrv/handle.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/h…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/handle.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/handle.c [iso-8859-1] Sun Dec 30 21:02:12 2012
@@ -2,7 +2,7 @@
* LICENSE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/handle.c
- * PURPOSE: Handle functions
+ * PURPOSE: Console IO Handle functions
* PROGRAMMERS:
*/
@@ -15,14 +15,7 @@
#include <debug.h>
-/* FUNCTIONS *****************************************************************/
-
-static
-BOOL
-CsrIsConsoleHandle(HANDLE Handle)
-{
- return ((ULONG_PTR)Handle & 0x10000003) == 0x3;
-}
+/* PRIVATE FUNCTIONS *********************************************************/
static INT
AdjustHandleCounts(PCSRSS_HANDLE Entry, INT Change)
@@ -69,6 +62,57 @@
}
}
+
+/* FUNCTIONS *****************************************************************/
+
+NTSTATUS
+FASTCALL
+Win32CsrInsertObject(PCONSOLE_PROCESS_DATA ProcessData,
+ PHANDLE Handle,
+ Object_t *Object,
+ DWORD Access,
+ BOOL Inheritable,
+ DWORD ShareMode)
+{
+ ULONG i;
+ PCSRSS_HANDLE Block;
+
+ RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
+ for (i = 0; i < ProcessData->HandleTableSize; i++)
+ {
+ if (ProcessData->HandleTable[i].Object == NULL)
+ {
+ break;
+ }
+ }
+ if (i >= ProcessData->HandleTableSize)
+ {
+ Block = RtlAllocateHeap(ConSrvHeap,
+ HEAP_ZERO_MEMORY,
+ (ProcessData->HandleTableSize + 64) *
sizeof(CSRSS_HANDLE));
+ if (Block == NULL)
+ {
+ RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+ return(STATUS_UNSUCCESSFUL);
+ }
+ RtlCopyMemory(Block,
+ ProcessData->HandleTable,
+ ProcessData->HandleTableSize * sizeof(CSRSS_HANDLE));
+ RtlFreeHeap(ConSrvHeap, 0, ProcessData->HandleTable);
+ ProcessData->HandleTable = Block;
+ ProcessData->HandleTableSize += 64;
+ }
+ ProcessData->HandleTable[i].Object = Object;
+ ProcessData->HandleTable[i].Access = Access;
+ ProcessData->HandleTable[i].Inheritable = Inheritable;
+ ProcessData->HandleTable[i].ShareMode = ShareMode;
+ Win32CsrCreateHandleEntry(&ProcessData->HandleTable[i]);
+ *Handle = UlongToHandle((i << 2) | 0x3);
+ RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+ return STATUS_SUCCESS;
+}
+
NTSTATUS
FASTCALL
Win32CsrReleaseObject(PCONSOLE_PROCESS_DATA ProcessData,
@@ -78,14 +122,17 @@
Object_t *Object;
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if (h >= ProcessData->HandleTableSize
- || (Object = ProcessData->HandleTable[h].Object) == NULL)
+
+ if (h >= ProcessData->HandleTableSize ||
+ (Object = ProcessData->HandleTable[h].Object) == NULL)
{
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
Win32CsrCloseHandleEntry(&ProcessData->HandleTable[h]);
- RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+
+ RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+
return STATUS_SUCCESS;
}
@@ -103,15 +150,18 @@
Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0);
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if (!CsrIsConsoleHandle(Handle) || h >= ProcessData->HandleTableSize
- || (*Object = ProcessData->HandleTable[h].Object) == NULL
- || ~ProcessData->HandleTable[h].Access & Access
- || (Type != 0 && (*Object)->Type != Type))
+
+ if ( !IsConsoleHandle(Handle) ||
+ h >= ProcessData->HandleTableSize ||
+ (*Object = ProcessData->HandleTable[h].Object) == NULL ||
+ ~ProcessData->HandleTable[h].Access & Access ||
+ (Type != 0 && (*Object)->Type != Type) )
{
DPRINT1("CsrGetObject returning invalid handle (%x)\n", Handle);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
+
_InterlockedIncrement(&(*Object)->Console->ReferenceCount);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
@@ -129,6 +179,8 @@
if (_InterlockedDecrement(&Console->ReferenceCount) == 0)
ConioDeleteConsole(&Console->Header);
}
+
+
NTSTATUS
NTAPI
@@ -238,54 +290,6 @@
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
}
-NTSTATUS
-FASTCALL
-Win32CsrInsertObject(PCONSOLE_PROCESS_DATA ProcessData,
- PHANDLE Handle,
- Object_t *Object,
- DWORD Access,
- BOOL Inheritable,
- DWORD ShareMode)
-{
- ULONG i;
- PCSRSS_HANDLE Block;
-
- RtlEnterCriticalSection(&ProcessData->HandleTableLock);
-
- for (i = 0; i < ProcessData->HandleTableSize; i++)
- {
- if (ProcessData->HandleTable[i].Object == NULL)
- {
- break;
- }
- }
- if (i >= ProcessData->HandleTableSize)
- {
- Block = RtlAllocateHeap(ConSrvHeap,
- HEAP_ZERO_MEMORY,
- (ProcessData->HandleTableSize + 64) *
sizeof(CSRSS_HANDLE));
- if (Block == NULL)
- {
- RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
- return(STATUS_UNSUCCESSFUL);
- }
- RtlCopyMemory(Block,
- ProcessData->HandleTable,
- ProcessData->HandleTableSize * sizeof(CSRSS_HANDLE));
- RtlFreeHeap(ConSrvHeap, 0, ProcessData->HandleTable);
- ProcessData->HandleTable = Block;
- ProcessData->HandleTableSize += 64;
- }
- ProcessData->HandleTable[i].Object = Object;
- ProcessData->HandleTable[i].Access = Access;
- ProcessData->HandleTable[i].Inheritable = Inheritable;
- ProcessData->HandleTable[i].ShareMode = ShareMode;
- Win32CsrCreateHandleEntry(&ProcessData->HandleTable[i]);
- *Handle = UlongToHandle((i << 2) | 0x3);
- RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
- return STATUS_SUCCESS;
-}
-
CSR_API(SrvCloseHandle)
{
PCSRSS_CLOSE_HANDLE CloseHandleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CloseHandleRequest;
@@ -299,16 +303,19 @@
NTSTATUS Status = STATUS_SUCCESS;
PCSRSS_VERIFY_HANDLE VerifyHandleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.VerifyHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
- ULONG_PTR Index;
-
- Index = (ULONG_PTR)VerifyHandleRequest->Handle >> 2;
- RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if (Index >= ProcessData->HandleTableSize ||
+ HANDLE Handle = VerifyHandleRequest->Handle;
+ ULONG_PTR Index = (ULONG_PTR)Handle >> 2;
+
+ RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
+ if (!IsConsoleHandle(Handle) ||
+ Index >= ProcessData->HandleTableSize ||
ProcessData->HandleTable[Index].Object == NULL)
{
DPRINT("CsrVerifyObject failed\n");
Status = STATUS_INVALID_HANDLE;
}
+
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
@@ -316,18 +323,20 @@
CSR_API(SrvDuplicateHandle)
{
- ULONG_PTR Index;
PCSRSS_HANDLE Entry;
DWORD DesiredAccess;
PCSRSS_DUPLICATE_HANDLE DuplicateHandleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.DuplicateHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
-
- Index = (ULONG_PTR)DuplicateHandleRequest->Handle >> 2;
- RtlEnterCriticalSection(&ProcessData->HandleTableLock);
- if (Index >= ProcessData->HandleTableSize
- || (Entry = &ProcessData->HandleTable[Index])->Object == NULL)
- {
- DPRINT1("Couldn't dup invalid handle %p\n",
DuplicateHandleRequest->Handle);
+ HANDLE Handle = DuplicateHandleRequest->Handle;
+ ULONG_PTR Index = (ULONG_PTR)Handle >> 2;
+
+ RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
+ if ( /** !IsConsoleHandle(Handle) || **/
+ Index >= ProcessData->HandleTableSize ||
+ (Entry = &ProcessData->HandleTable[Index])->Object == NULL)
+ {
+ DPRINT1("Couldn't duplicate invalid handle %p\n", Handle);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
@@ -343,20 +352,20 @@
if (~Entry->Access & DesiredAccess)
{
DPRINT1("Handle %p only has access %X; requested %X\n",
- DuplicateHandleRequest->Handle, Entry->Access, DesiredAccess);
+ Handle, Entry->Access, DesiredAccess);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_PARAMETER;
}
}
ApiMessage->Status = Win32CsrInsertObject(ProcessData,
- &DuplicateHandleRequest->Handle,
+ &DuplicateHandleRequest->Handle, //
Use the new handle value!
Entry->Object,
DesiredAccess,
DuplicateHandleRequest->Inheritable,
Entry->ShareMode);
- if (NT_SUCCESS(ApiMessage->Status)
- && DuplicateHandleRequest->Options & DUPLICATE_CLOSE_SOURCE)
+ if (NT_SUCCESS(ApiMessage->Status) &&
+ DuplicateHandleRequest->Options & DUPLICATE_CLOSE_SOURCE)
{
Win32CsrCloseHandleEntry(Entry);
}