- 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
This commit is contained in:
Jeffrey Morlan 2008-08-02 17:01:22 +00:00
parent 61c0684353
commit 9b188f4ebc
8 changed files with 87 additions and 12 deletions

View file

@ -69,7 +69,7 @@ GetConsoleInputWaitHandle (VOID);
HANDLE STDCALL OpenConsoleW (LPCWSTR wsName,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwCreationDistribution);
DWORD dwShareMode);
PTEB GetTeb(VOID);

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -48,6 +48,7 @@ typedef struct _CSRSS_PROCESS_DATA
ULONG HandleTableSize;
PCSRSS_HANDLE HandleTable;
HANDLE ProcessId;
DWORD ProcessGroup;
HANDLE Process;
ULONG ShutdownLevel;
ULONG ShutdownFlags;

View file

@ -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))

View file

@ -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 */

View file

@ -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 }
};