Author: hbelusca
Date: Sat Nov 17 22:42:04 2012
New Revision: 57723
URL:
http://svn.reactos.org/svn/reactos?rev=57723&view=rev
Log:
[KERNEL32/CONSRV]
- Make OpenConsole call only one server api, namely SrvOpenConsole, which was known before
under the name CsrGetHandle (this latter function was removed in r57689 by error).
- Merge CSRSS_GET_INPUT_HANDLE and CSRSS_GET_OUTPUT_HANDLE structures into
CSRSS_OPEN_CONSOLE (used by the functions named above).
[CONSRV]
- Add SrvOpenConsole (copied from CsrGetHandle), and add DPRINT1s to it.
- Load the localized string "Command Prompt" using the Server DLL's instance
handle instead of calling GetModuleHandleW.
- Make use of CONSOLE_PROCESS_DATA structures.
Modified:
branches/ros-csrss/dll/win32/kernel32/client/console/console.c
branches/ros-csrss/include/reactos/subsys/win/conmsg.h
branches/ros-csrss/win32ss/user/consrv/console.c
Modified: branches/ros-csrss/dll/win32/kernel32/client/console/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1]
(original)
+++ branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1] Sat Nov 17
22:42:04 2012
@@ -389,52 +389,53 @@
BOOL bInheritHandle,
DWORD dwShareMode)
{
- CSR_API_MESSAGE Request;
- ULONG CsrRequest;
NTSTATUS Status = STATUS_SUCCESS;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_OPEN_CONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
+ HANDLE_TYPE HandleType;
if (wsName && 0 == _wcsicmp(wsName, L"CONIN$"))
{
- CsrRequest = CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_INPUT_HANDLE);
+ HandleType = HANDLE_INPUT;
}
else if (wsName && 0 == _wcsicmp(wsName, L"CONOUT$"))
{
- CsrRequest = CSR_CREATE_API_NUMBER(CSR_NATIVE, GET_OUTPUT_HANDLE);
+ HandleType = HANDLE_OUTPUT;
}
else
{
SetLastError(ERROR_INVALID_PARAMETER);
- return(INVALID_HANDLE_VALUE);
- }
-
- if (dwDesiredAccess & ~(GENERIC_READ|GENERIC_WRITE))
+ return INVALID_HANDLE_VALUE;
+ }
+
+ if (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))
{
SetLastError(ERROR_INVALID_PARAMETER);
- return(INVALID_HANDLE_VALUE);
- }
-
- if (dwShareMode & ~(FILE_SHARE_READ|FILE_SHARE_WRITE))
+ return INVALID_HANDLE_VALUE;
+ }
+
+ if (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE))
{
SetLastError(ERROR_INVALID_PARAMETER);
- return(INVALID_HANDLE_VALUE);
- }
-
- /* Structures for GET_INPUT_HANDLE and GET_OUTPUT_HANDLE requests are identical */
- Request.Data.GetInputHandleRequest.Access = dwDesiredAccess;
- Request.Data.GetInputHandleRequest.Inheritable = bInheritHandle;
- Request.Data.GetInputHandleRequest.ShareMode = dwShareMode;
-
- Status = CsrClientCallServer(&Request,
- NULL,
- CsrRequest,
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status))
- {
- BaseSetLastNTError(Status);
return INVALID_HANDLE_VALUE;
}
- return Request.Data.GetInputHandleRequest.Handle;
+ OpenConsoleRequest->HandleType = HandleType;
+ OpenConsoleRequest->Access = dwDesiredAccess;
+ OpenConsoleRequest->Inheritable = bInheritHandle;
+ OpenConsoleRequest->ShareMode = dwShareMode;
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepOpenConsole),
+ sizeof(CSRSS_OPEN_CONSOLE));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ {
+ BaseSetLastNTError(Status);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ return OpenConsoleRequest->Handle;
}
Modified: branches/ros-csrss/include/reactos/subsys/win/conmsg.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] Sat Nov 17
22:42:04 2012
@@ -20,8 +20,8 @@
// Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
typedef enum _CONSRV_API_NUMBER
{
- // ConsolepOpenConsole = CONSRV_FIRST_API_NUMBER,
- ConsolepGetConsoleInput = CONSRV_FIRST_API_NUMBER,
+ ConsolepOpenConsole = CONSRV_FIRST_API_NUMBER,
+ ConsolepGetConsoleInput,
ConsolepWriteConsoleInput,
ConsolepReadConsoleOutput,
ConsolepWriteConsoleOutput,
@@ -392,14 +392,23 @@
DWORD Options;
} CSRSS_DUPLICATE_HANDLE, *PCSRSS_DUPLICATE_HANDLE;
-typedef struct
-{
+/*
+ * Type of handles.
+ */
+typedef enum _HANDLE_TYPE
+{
+ HANDLE_INPUT = 0x01,
+ HANDLE_OUTPUT = 0x02
+} HANDLE_TYPE;
+
+typedef struct
+{
+ HANDLE Handle;
+ HANDLE_TYPE HandleType;
DWORD Access;
BOOL Inheritable;
- HANDLE Handle;
DWORD ShareMode;
-} CSRSS_GET_INPUT_HANDLE, *PCSRSS_GET_INPUT_HANDLE,
- CSRSS_GET_OUTPUT_HANDLE, *PCSRSS_GET_OUTPUT_HANDLE;
+} CSRSS_OPEN_CONSOLE, *PCSRSS_OPEN_CONSOLE;
typedef struct
{
@@ -575,8 +584,7 @@
CSRSS_FREE_CONSOLE FreeConsoleRequest;
/* Handles */
- CSRSS_GET_INPUT_HANDLE GetInputHandleRequest;
- CSRSS_GET_OUTPUT_HANDLE GetOutputHandleRequest;
+ CSRSS_OPEN_CONSOLE OpenConsoleRequest;
CSRSS_CLOSE_HANDLE CloseHandleRequest;
CSRSS_VERIFY_HANDLE VerifyHandleRequest;
CSRSS_DUPLICATE_HANDLE DuplicateHandleRequest;
Modified: branches/ros-csrss/win32ss/user/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/console.c [iso-8859-1] Sat Nov 17 22:42:04
2012
@@ -17,7 +17,6 @@
/* FUNCTIONS *****************************************************************/
-/*** Taken from win32ss/user/win32csr/desktopbg.c ***/
BOOL FASTCALL
DtbgIsDesktopVisible(VOID)
{
@@ -31,10 +30,10 @@
return VisibleDesktopWindow != NULL;
}
-/****************************************************/
NTSTATUS FASTCALL
-ConioConsoleFromProcessData(PCSR_PROCESS ProcessData, PCSRSS_CONSOLE *Console)
+ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData,
+ PCSRSS_CONSOLE *Console)
{
PCSRSS_CONSOLE ProcessConsole;
@@ -57,30 +56,32 @@
}
VOID FASTCALL
-ConioConsoleCtrlEventTimeout(DWORD Event, PCSR_PROCESS ProcessData, DWORD Timeout)
+ConioConsoleCtrlEventTimeout(DWORD Event,
+ PCONSOLE_PROCESS_DATA ProcessData,
+ DWORD Timeout)
{
HANDLE Thread;
- DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n",
ProcessData->ClientId.UniqueProcess);
+ DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n",
ProcessData->Process->ClientId.UniqueProcess);
if (ProcessData->CtrlDispatcher)
{
-
- Thread = CreateRemoteThread(ProcessData->ProcessHandle, NULL, 0,
- (LPTHREAD_START_ROUTINE)
ProcessData->CtrlDispatcher,
+ Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
+ ProcessData->CtrlDispatcher,
UlongToPtr(Event), 0, NULL);
if (NULL == Thread)
{
DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
return;
}
+
WaitForSingleObject(Thread, Timeout);
CloseHandle(Thread);
}
}
VOID FASTCALL
-ConioConsoleCtrlEvent(DWORD Event, PCSR_PROCESS ProcessData)
+ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData)
{
ConioConsoleCtrlEventTimeout(Event, ProcessData, 0);
}
@@ -93,13 +94,11 @@
PCSRSS_SCREEN_BUFFER NewBuffer;
BOOL GuiMode;
WCHAR Title[255];
- HINSTANCE hInst;
Console->Title.MaximumLength = Console->Title.Length = 0;
Console->Title.Buffer = NULL;
- hInst = GetModuleHandleW(L"win32csr");
- if (LoadStringW(hInst,IDS_COMMAND_PROMPT,Title,sizeof(Title)/sizeof(Title[0])))
+ if (LoadStringW(ConSrvDllInstance, IDS_COMMAND_PROMPT, Title, sizeof(Title) /
sizeof(Title[0])))
{
RtlCreateUnicodeString(&Console->Title, Title);
}
@@ -150,10 +149,10 @@
/* make console active, and insert into console list */
Console->ActiveBuffer = (PCSRSS_SCREEN_BUFFER) NewBuffer;
- if (! GuiMode)
+ if (!GuiMode)
{
Status = TuiInitConsole(Console);
- if (! NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to open text-mode console, switching to
gui-mode\n");
GuiMode = TRUE;
@@ -162,7 +161,7 @@
else /* GuiMode */
{
Status = GuiInitConsole(Console, ShowCmd);
- if (! NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status))
{
HeapFree(ConSrvHeap,0, NewBuffer);
RtlFreeUnicodeString(&Console->Title);
@@ -189,6 +188,64 @@
ConioDrawConsole(Console);
return STATUS_SUCCESS;
+}
+
+CSR_API(SrvOpenConsole)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+ PCSRSS_OPEN_CONSOLE OpenConsoleRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.OpenConsoleRequest;
+ PCONSOLE_PROCESS_DATA ProcessData =
ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+
+ DPRINT("SrvOpenConsole\n");
+
+ OpenConsoleRequest->Handle = INVALID_HANDLE_VALUE;
+
+ RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+
+ DPRINT1("SrvOpenConsole - Checkpoint 1\n");
+ DPRINT1("ProcessData = 0x%p ; ProcessData->Console = 0x%p\n",
ProcessData, ProcessData->Console);
+
+ if (ProcessData->Console)
+ {
+ DWORD DesiredAccess = OpenConsoleRequest->Access;
+ DWORD ShareMode = OpenConsoleRequest->ShareMode;
+
+ PCSRSS_CONSOLE Console = ProcessData->Console;
+ Object_t *Object;
+
+ DPRINT1("SrvOpenConsole - Checkpoint 2\n");
+ EnterCriticalSection(&Console->Lock);
+ DPRINT1("SrvOpenConsole - Checkpoint 3\n");
+
+ if (OpenConsoleRequest->HandleType == HANDLE_OUTPUT)
+ Object = &Console->ActiveBuffer->Header;
+ else // HANDLE_INPUT
+ Object = &Console->Header;
+
+ if (((DesiredAccess & GENERIC_READ) && Object->ExclusiveRead !=
0) ||
+ ((DesiredAccess & GENERIC_WRITE) && Object->ExclusiveWrite !=
0) ||
+ (!(ShareMode & FILE_SHARE_READ) && Object->AccessRead !=
0) ||
+ (!(ShareMode & FILE_SHARE_WRITE) && Object->AccessWrite !=
0))
+ {
+ DPRINT1("Sharing violation\n");
+ Status = STATUS_SHARING_VIOLATION;
+ }
+ else
+ {
+ Status = Win32CsrInsertObject(ProcessData,
+ &OpenConsoleRequest->Handle,
+ Object,
+ DesiredAccess,
+ OpenConsoleRequest->Inheritable,
+ ShareMode);
+ }
+
+ LeaveCriticalSection(&Console->Lock);
+ }
+
+ RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+
+ return Status;
}
CSR_API(SrvAllocConsole)