From 9b188f4ebc1ee510d2e0f92728aca2c511428b2d Mon Sep 17 00:00:00 2001 From: Jeffrey Morlan Date: Sat, 2 Aug 2008 17:01:22 +0000 Subject: [PATCH] - Implement GenerateConsoleCtrlEvent. - Remove IgnoreCtrlEvents variable (which ConsoleControlDispatcher did not actually use); set ProcessParameters->ConsoleFlags instead. Despite the name "ConsoleFlags", SetConsoleCtrlHandler treats it like a boolean. - Preserve all 16 bits of the attribute set by SetConsoleTextAttribute. Even though the upper byte does not affect text colors, it should be retrievable with GetConsoleScreenBufferInfo. - Update OpenConsoleW prototype in kernel32.h to match the change made in r34694. svn path=/trunk/; revision=35041 --- reactos/dll/win32/kernel32/include/kernel32.h | 2 +- reactos/dll/win32/kernel32/misc/console.c | 37 ++++++++++++++----- reactos/include/reactos/subsys/csrss/csrss.h | 10 ++++- reactos/subsystems/win32/csrss/api/process.c | 9 +++++ reactos/subsystems/win32/csrss/include/api.h | 1 + .../subsystems/win32/csrss/include/conio.h | 3 +- .../subsystems/win32/csrss/win32csr/conio.c | 36 ++++++++++++++++++ .../subsystems/win32/csrss/win32csr/dllmain.c | 1 + 8 files changed, 87 insertions(+), 12 deletions(-) diff --git a/reactos/dll/win32/kernel32/include/kernel32.h b/reactos/dll/win32/kernel32/include/kernel32.h index b2abfa8e828..5ba86675750 100755 --- a/reactos/dll/win32/kernel32/include/kernel32.h +++ b/reactos/dll/win32/kernel32/include/kernel32.h @@ -69,7 +69,7 @@ GetConsoleInputWaitHandle (VOID); HANDLE STDCALL OpenConsoleW (LPCWSTR wsName, DWORD dwDesiredAccess, BOOL bInheritHandle, - DWORD dwCreationDistribution); + DWORD dwShareMode); PTEB GetTeb(VOID); diff --git a/reactos/dll/win32/kernel32/misc/console.c b/reactos/dll/win32/kernel32/misc/console.c index 10de6a44800..b638e4ef137 100644 --- a/reactos/dll/win32/kernel32/misc/console.c +++ b/reactos/dll/win32/kernel32/misc/console.c @@ -27,8 +27,6 @@ extern BOOL WINAPI IsDebuggerPresent(VOID); /* GLOBALS *******************************************************************/ -static BOOL IgnoreCtrlEvents = FALSE; - static PHANDLER_ROUTINE* CtrlHandlers = NULL; static ULONG NrCtrlHandlers = 0; static WCHAR InputExeName[MAX_PATH + 1] = L""; @@ -3141,7 +3139,7 @@ SetConsoleTextAttribute( CsrRequest = MAKE_CSR_API(SET_ATTRIB, CSR_CONSOLE); Request.Data.SetAttribRequest.ConsoleHandle = hConsoleOutput; - Request.Data.SetAttribRequest.Attrib = (CHAR)wAttributes; + Request.Data.SetAttribRequest.Attrib = wAttributes; Status = CsrClientCallServer( &Request, NULL, CsrRequest, sizeof( CSR_API_MESSAGE ) ); if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Request.Status ) ) { @@ -3157,7 +3155,7 @@ AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine) { if (HandlerRoutine == NULL) { - IgnoreCtrlEvents = TRUE; + NtCurrentPeb()->ProcessParameters->ConsoleFlags = TRUE; return(TRUE); } else @@ -3193,7 +3191,7 @@ RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine) if (HandlerRoutine == NULL) { - IgnoreCtrlEvents = FALSE; + NtCurrentPeb()->ProcessParameters->ConsoleFlags = FALSE; return(TRUE); } else @@ -3245,7 +3243,7 @@ SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, /*-------------------------------------------------------------- * GenerateConsoleCtrlEvent * - * @unimplemented + * @implemented */ BOOL WINAPI GenerateConsoleCtrlEvent( @@ -3253,9 +3251,30 @@ GenerateConsoleCtrlEvent( DWORD dwProcessGroupId ) { - DPRINT1("GenerateConsoleCtrlEvent(0x%x, 0x%x) UNIMPLEMENTED!\n", dwCtrlEvent, dwProcessGroupId); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + CSR_API_MESSAGE Request; + ULONG CsrRequest; + NTSTATUS Status; + + if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + CsrRequest = MAKE_CSR_API(GENERATE_CTRL_EVENT, CSR_CONSOLE); + Request.Data.GenerateCtrlEvent.Event = dwCtrlEvent; + Request.Data.GenerateCtrlEvent.ProcessGroup = dwProcessGroupId; + Status = CsrClientCallServer(&Request, + NULL, + CsrRequest, + sizeof(CSR_API_MESSAGE)); + if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Request.Status))) + { + SetLastErrorByStatus(Status); + return FALSE; + } + + return TRUE; } diff --git a/reactos/include/reactos/subsys/csrss/csrss.h b/reactos/include/reactos/subsys/csrss/csrss.h index 6aa80f3596b..b23bf0c29e2 100644 --- a/reactos/include/reactos/subsys/csrss/csrss.h +++ b/reactos/include/reactos/subsys/csrss/csrss.h @@ -163,7 +163,7 @@ typedef struct typedef struct { HANDLE ConsoleHandle; - CHAR Attrib; + WORD Attrib; } CSRSS_SET_ATTRIB, *PCSRSS_SET_ATTRIB; typedef struct @@ -460,6 +460,12 @@ typedef struct DWORD Length; } CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH, *PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH; +typedef struct +{ + DWORD Event; + DWORD ProcessGroup; +} CSRSS_GENERATE_CTRL_EVENT, *PCSRSS_GENERATE_CTRL_EVENT; + #define CSR_API_MESSAGE_HEADER_SIZE(Type) (FIELD_OFFSET(CSR_API_MESSAGE, Data) + sizeof(Type)) @@ -537,6 +543,7 @@ typedef struct #define GET_ALL_CONSOLE_ALIASES_LENGTH (0x3B) #define GET_CONSOLE_ALIASES_EXES (0x3C) #define GET_CONSOLE_ALIASES_EXES_LENGTH (0x3D) +#define GENERATE_CTRL_EVENT (0x3E) /* Keep in sync with definition below. */ #define CSRSS_HEADER_SIZE (sizeof(PORT_MESSAGE) + sizeof(ULONG) + sizeof(NTSTATUS)) @@ -608,6 +615,7 @@ typedef struct _CSR_API_MESSAGE CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength; CSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes; CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength; + CSRSS_GENERATE_CTRL_EVENT GenerateCtrlEvent; } Data; } CSR_API_MESSAGE, *PCSR_API_MESSAGE; diff --git a/reactos/subsystems/win32/csrss/api/process.c b/reactos/subsystems/win32/csrss/api/process.c index d96651ff980..1c439fc8ab3 100644 --- a/reactos/subsystems/win32/csrss/api/process.c +++ b/reactos/subsystems/win32/csrss/api/process.c @@ -242,6 +242,15 @@ CSR_API(CsrCreateProcess) } } + if (Request->Data.CreateProcessRequest.Flags & CREATE_NEW_PROCESS_GROUP) + { + NewProcessData->ProcessGroup = (DWORD)NewProcessData->ProcessId; + } + else + { + NewProcessData->ProcessGroup = ProcessData->ProcessGroup; + } + /* Set default shutdown parameters */ NewProcessData->ShutdownLevel = 0x280; NewProcessData->ShutdownFlags = 0; diff --git a/reactos/subsystems/win32/csrss/include/api.h b/reactos/subsystems/win32/csrss/include/api.h index 7ec1d22d176..651da359656 100644 --- a/reactos/subsystems/win32/csrss/include/api.h +++ b/reactos/subsystems/win32/csrss/include/api.h @@ -48,6 +48,7 @@ typedef struct _CSRSS_PROCESS_DATA ULONG HandleTableSize; PCSRSS_HANDLE HandleTable; HANDLE ProcessId; + DWORD ProcessGroup; HANDLE Process; ULONG ShutdownLevel; ULONG ShutdownFlags; diff --git a/reactos/subsystems/win32/csrss/include/conio.h b/reactos/subsystems/win32/csrss/include/conio.h index 38c18b201cf..07dff611589 100644 --- a/reactos/subsystems/win32/csrss/include/conio.h +++ b/reactos/subsystems/win32/csrss/include/conio.h @@ -41,7 +41,7 @@ typedef struct tagCSRSS_SCREEN_BUFFER USHORT ShowX, ShowY; /* beginning offset for the actual display area */ ULONG CurrentX; /* Current X cursor position */ ULONG CurrentY; /* Current Y cursor position */ - BYTE DefaultAttrib; /* default char attribute */ + WORD DefaultAttrib; /* default char attribute */ USHORT VirtualY; /* top row of buffer being displayed, reported to callers */ CONSOLE_CURSOR_INFO CursorInfo; USHORT Mode; @@ -135,6 +135,7 @@ CSR_API(CsrSetConsoleCodePage); CSR_API(CsrGetConsoleOutputCodePage); CSR_API(CsrSetConsoleOutputCodePage); CSR_API(CsrGetProcessList); +CSR_API(CsrGenerateCtrlEvent); #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff)) #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region)) diff --git a/reactos/subsystems/win32/csrss/win32csr/conio.c b/reactos/subsystems/win32/csrss/win32csr/conio.c index ff65c58e37a..d1a7d222ac4 100644 --- a/reactos/subsystems/win32/csrss/win32csr/conio.c +++ b/reactos/subsystems/win32/csrss/win32csr/conio.c @@ -3129,4 +3129,40 @@ CSR_API(CsrGetProcessList) return Request->Status = STATUS_SUCCESS; } +CSR_API(CsrGenerateCtrlEvent) +{ + PCSRSS_CONSOLE Console; + PCSRSS_PROCESS_DATA current; + PLIST_ENTRY current_entry; + DWORD Group; + NTSTATUS Status; + + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) + { + return Request->Status = Status; + } + + Group = Request->Data.GenerateCtrlEvent.ProcessGroup; + Status = STATUS_INVALID_PARAMETER; + for (current_entry = Console->ProcessList.Flink; + current_entry != &Console->ProcessList; + current_entry = current_entry->Flink) + { + current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); + if (Group == 0 || current->ProcessGroup == Group) + { + ConioConsoleCtrlEvent(Request->Data.GenerateCtrlEvent.Event, current); + Status = STATUS_SUCCESS; + } + } + + ConioUnlockConsole(Console); + + return Request->Status = Status; +} + /* EOF */ diff --git a/reactos/subsystems/win32/csrss/win32csr/dllmain.c b/reactos/subsystems/win32/csrss/win32csr/dllmain.c index 0b73d2df16c..34c72eefc81 100644 --- a/reactos/subsystems/win32/csrss/win32csr/dllmain.c +++ b/reactos/subsystems/win32/csrss/win32csr/dllmain.c @@ -74,6 +74,7 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = CSRSS_DEFINE_API(GET_ALL_CONSOLE_ALIASES_LENGTH, CsrGetAllConsoleAliasesLength), CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES, CsrGetConsoleAliasesExes), CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES_LENGTH, CsrGetConsoleAliasesExesLength), + CSRSS_DEFINE_API(GENERATE_CTRL_EVENT, CsrGenerateCtrlEvent), { 0, 0, NULL } };