[CONSRV] Introduce a set of macros CON_API / CON_API_NOCONSOLE for wrapping around the repetitive prologue/epilogue of every console CSR API entrypoint.

All the per-API message structure unpacking and console validation done
with ConSrvGetConsole() is now automatically generated using the macros,
so that the actual implementation of each API can be done independently
of how the console object is obtained.

This could also allow reusing these API implementations with a different
mechanism for obtaining the console without changing anything in them.
This commit is contained in:
Hermès Bélusca-Maïto 2020-04-12 12:45:31 +02:00
parent 7173a21f4a
commit 9261110760
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
10 changed files with 504 additions and 729 deletions

View file

@ -446,17 +446,13 @@ IntDeleteAllAliases(PCONSRV_CONSOLE Console)
/* PUBLIC SERVER APIS *********************************************************/
/* API_NUMBER: ConsolepAddAlias */
CSR_API(SrvAddConsoleAlias)
CON_API(SrvAddConsoleAlias,
CONSOLE_ADDGETALIAS, ConsoleAliasRequest)
{
NTSTATUS Status;
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
PCONSRV_CONSOLE Console;
PALIAS_HEADER Header;
PALIAS_ENTRY Entry;
PVOID lpTarget;
DPRINT("SrvAddConsoleAlias entered ApiMessage %p\n", ApiMessage);
if ( !CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&ConsoleAliasRequest->Source,
ConsoleAliasRequest->SourceLength,
@ -475,12 +471,6 @@ CSR_API(SrvAddConsoleAlias)
lpTarget = (ConsoleAliasRequest->TargetLength != 0 ? ConsoleAliasRequest->Target : NULL);
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = STATUS_SUCCESS;
Header = IntFindAliasHeader(Console,
ConsoleAliasRequest->ExeName,
ConsoleAliasRequest->ExeLength,
@ -492,10 +482,7 @@ CSR_API(SrvAddConsoleAlias)
ConsoleAliasRequest->ExeLength,
ConsoleAliasRequest->Unicode2);
if (!Header)
{
Status = STATUS_NO_MEMORY;
goto Quit;
}
return STATUS_NO_MEMORY;
IntInsertAliasHeader(&Console->Aliases, Header);
}
@ -507,10 +494,7 @@ CSR_API(SrvAddConsoleAlias)
ConsoleAliasRequest->SourceLength,
ConsoleAliasRequest->Unicode);
if (!Entry)
{
Status = STATUS_UNSUCCESSFUL;
goto Quit;
}
return STATUS_UNSUCCESSFUL;
IntDeleteAliasEntry(Header, Entry);
}
@ -523,32 +507,23 @@ CSR_API(SrvAddConsoleAlias)
ConsoleAliasRequest->TargetLength,
ConsoleAliasRequest->Unicode);
if (!Entry)
{
Status = STATUS_NO_MEMORY;
goto Quit;
}
return STATUS_NO_MEMORY;
IntInsertAliasEntry(Header, Entry);
}
Quit:
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetAlias */
CSR_API(SrvGetConsoleAlias)
CON_API(SrvGetConsoleAlias,
CONSOLE_ADDGETALIAS, ConsoleAliasRequest)
{
NTSTATUS Status;
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleAliasRequest;
PCONSRV_CONSOLE Console;
PALIAS_HEADER Header;
PALIAS_ENTRY Entry;
UINT Length;
PVOID lpTarget;
DPRINT("SrvGetConsoleAlias entered ApiMessage %p\n", ApiMessage);
if ( !CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&ConsoleAliasRequest->Source,
ConsoleAliasRequest->SourceLength,
@ -573,37 +548,26 @@ CSR_API(SrvGetConsoleAlias)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Header = IntFindAliasHeader(Console,
ConsoleAliasRequest->ExeName,
ConsoleAliasRequest->ExeLength,
ConsoleAliasRequest->Unicode2);
if (!Header)
{
Status = STATUS_UNSUCCESSFUL;
goto Quit;
}
return STATUS_UNSUCCESSFUL;
Entry = IntGetAliasEntry(Console, Header,
ConsoleAliasRequest->Source,
ConsoleAliasRequest->SourceLength,
ConsoleAliasRequest->Unicode);
if (!Entry)
{
Status = STATUS_UNSUCCESSFUL;
goto Quit;
}
return STATUS_UNSUCCESSFUL;
if (ConsoleAliasRequest->Unicode)
{
Length = Entry->Target.Length + sizeof(WCHAR);
if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
{
Status = STATUS_BUFFER_TOO_SMALL;
goto Quit;
return STATUS_BUFFER_TOO_SMALL;
}
RtlCopyMemory(lpTarget, Entry->Target.Buffer, Entry->Target.Length);
@ -614,8 +578,7 @@ CSR_API(SrvGetConsoleAlias)
Length = (Entry->Target.Length + sizeof(WCHAR)) / sizeof(WCHAR);
if (Length > ConsoleAliasRequest->TargetLength) // FIXME: Refine computation.
{
Status = STATUS_BUFFER_TOO_SMALL;
goto Quit;
return STATUS_BUFFER_TOO_SMALL;
}
ConvertInputUnicodeToAnsi(Console,
@ -624,22 +587,17 @@ CSR_API(SrvGetConsoleAlias)
ConsoleAliasRequest->TargetLength = Length;
}
Quit:
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetAliases */
CSR_API(SrvGetConsoleAliases)
CON_API(SrvGetConsoleAliases,
CONSOLE_GETALLALIASES, GetAllAliasesRequest)
{
NTSTATUS Status;
PCONSOLE_GETALLALIASES GetAllAliasesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesRequest;
PCONSRV_CONSOLE Console;
ULONG BytesWritten = 0;
PALIAS_HEADER Header;
DPRINT("SrvGetConsoleAliases entered ApiMessage %p\n", ApiMessage);
if ( !CsrValidateMessageBuffer(ApiMessage,
(PVOID)&GetAllAliasesRequest->ExeName,
GetAllAliasesRequest->ExeLength,
@ -652,15 +610,15 @@ CSR_API(SrvGetConsoleAliases)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Header = IntFindAliasHeader(Console,
GetAllAliasesRequest->ExeName,
GetAllAliasesRequest->ExeLength,
GetAllAliasesRequest->Unicode2);
if (!Header) goto Quit;
if (!Header)
{
Status = STATUS_UNSUCCESSFUL;
goto Quit;
}
if (IntGetAllConsoleAliasesLength(Header, GetAllAliasesRequest->Unicode) > GetAllAliasesRequest->AliasesBufferLength)
{
@ -732,20 +690,16 @@ CSR_API(SrvGetConsoleAliases)
Quit:
GetAllAliasesRequest->AliasesBufferLength = BytesWritten;
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetAliasesLength */
CSR_API(SrvGetConsoleAliasesLength)
CON_API(SrvGetConsoleAliasesLength,
CONSOLE_GETALLALIASESLENGTH, GetAllAliasesLengthRequest)
{
NTSTATUS Status;
PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAllAliasesLengthRequest;
PCONSRV_CONSOLE Console;
PALIAS_HEADER Header;
DPRINT("SrvGetConsoleAliasesLength entered ApiMessage %p\n", ApiMessage);
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID)&GetAllAliasesLengthRequest->ExeName,
GetAllAliasesLengthRequest->ExeLength,
@ -754,10 +708,6 @@ CSR_API(SrvGetConsoleAliasesLength)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Header = IntFindAliasHeader(Console,
GetAllAliasesLengthRequest->ExeName,
GetAllAliasesLengthRequest->ExeLength,
@ -774,20 +724,16 @@ CSR_API(SrvGetConsoleAliasesLength)
GetAllAliasesLengthRequest->Length = 0;
}
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetAliasExes */
CSR_API(SrvGetConsoleAliasExes)
CON_API(SrvGetConsoleAliasExes,
CONSOLE_GETALIASESEXES, GetAliasesExesRequest)
{
NTSTATUS Status;
PCONSOLE_GETALIASESEXES GetAliasesExesRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesRequest;
PCONSRV_CONSOLE Console;
UINT BytesWritten = 0;
DPRINT("SrvGetConsoleAliasExes entered\n");
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&GetAliasesExesRequest->ExeNames,
GetAliasesExesRequest->Length,
@ -796,10 +742,6 @@ CSR_API(SrvGetConsoleAliasExes)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (IntGetConsoleAliasesExesLength(Console->Aliases, GetAliasesExesRequest->Unicode) > GetAliasesExesRequest->Length)
{
Status = STATUS_BUFFER_OVERFLOW;
@ -862,29 +804,18 @@ CSR_API(SrvGetConsoleAliasExes)
Quit:
GetAliasesExesRequest->Length = BytesWritten;
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetAliasExesLength */
CSR_API(SrvGetConsoleAliasExesLength)
CON_API(SrvGetConsoleAliasExesLength,
CONSOLE_GETALIASESEXESLENGTH, GetAliasesExesLengthRequest)
{
NTSTATUS Status;
PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetAliasesExesLengthRequest;
PCONSRV_CONSOLE Console;
DPRINT("SrvGetConsoleAliasExesLength entered ApiMessage %p\n", ApiMessage);
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetAliasesExesLengthRequest->Length =
IntGetConsoleAliasesExesLength(Console->Aliases,
GetAliasesExesLengthRequest->Unicode);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -8,6 +8,84 @@
#pragma once
/*
* Helper macros to define the CSR_API_ROUTINE-s defined in CONSRV,
* factoring out the common prologue and epilogue code, and including
* the necessary local variables.
*/
#define CON_API_NOCONSOLE_IMPL(Name, TYPE, RequestName) \
NTSTATUS \
Name##Impl( \
IN PCONSOLE_PROCESS_DATA ProcessData, \
IN OUT PCSR_API_MESSAGE ApiMessage, \
IN TYPE* RequestName, /* Request */ \
IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
// NTSTATUS NTAPI
// Name(
// IN OUT PCSR_API_MESSAGE ApiMessage,
// IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
#define CON_API_NOCONSOLE_ENTRY(Name, TYPE, RequestName) \
CON_API_NOCONSOLE_IMPL(Name, TYPE, RequestName); \
CSR_API(Name) \
{ \
TYPE* RequestName = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.RequestName; \
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); \
\
return Name##Impl(ProcessData, ApiMessage, RequestName, ReplyCode); \
}
#define CON_API_NOCONSOLE(Name, TYPE, RequestName) \
CON_API_NOCONSOLE_ENTRY(Name, TYPE, RequestName); \
CON_API_NOCONSOLE_IMPL(Name, TYPE, RequestName)
#define CON_API_IMPL(Name, TYPE, RequestName) \
NTSTATUS \
Name##Impl( \
IN PCONSOLE_PROCESS_DATA ProcessData, \
IN PCONSRV_CONSOLE Console, \
IN OUT PCSR_API_MESSAGE ApiMessage, \
IN TYPE* RequestName, /* Request */ \
IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
// NTSTATUS NTAPI
// Name(
// IN OUT PCSR_API_MESSAGE ApiMessage,
// IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
#define CON_API_ENTRY(Name, TYPE, RequestName) \
CON_API_IMPL(Name, TYPE, RequestName); \
CSR_API(Name) \
{ \
NTSTATUS Status; \
TYPE* RequestName = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.RequestName; \
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process); \
PCONSRV_CONSOLE Console; \
\
Status = ConSrvGetConsole(ProcessData, \
/* RequestName->ConsoleHandle, */ \
&Console, TRUE); \
if (!NT_SUCCESS(Status)) \
return Status; \
\
Status = Name##Impl(ProcessData, Console, \
ApiMessage, RequestName, ReplyCode); \
\
ConSrvReleaseConsole(Console, TRUE); \
return Status; \
}
#define CON_API(Name, TYPE, RequestName) \
CON_API_ENTRY(Name, TYPE, RequestName); \
CON_API_IMPL(Name, TYPE, RequestName)
/*
* List of CSR_API_ROUTINE-s defined in this module.
*/
/* alias.c */
CSR_API(SrvAddConsoleAlias);
CSR_API(SrvGetConsoleAlias);
@ -104,7 +182,7 @@ CSR_API(SrvSetHandleInformation);
CSR_API(SrvCloseHandle);
CSR_API(SrvVerifyConsoleIoHandle);
/* lineinput.c */
/* history.c */
CSR_API(SrvGetConsoleCommandHistory);
CSR_API(SrvGetConsoleCommandHistoryLength);
CSR_API(SrvExpungeConsoleCommandHistory);

View file

@ -581,11 +581,10 @@ ReadInputBuffer(IN PGET_INPUT_INFO InputInfo,
/* PUBLIC SERVER APIS *********************************************************/
/* API_NUMBER: ConsolepReadConsole */
CSR_API(SrvReadConsole)
CON_API(SrvReadConsole,
CONSOLE_READCONSOLE, ReadConsoleRequest)
{
NTSTATUS Status;
PCONSOLE_READCONSOLE ReadConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PVOID HandleEntry;
PCONSOLE_INPUT_BUFFER InputBuffer;
GET_INPUT_INFO InputInfo;
@ -622,8 +621,16 @@ CSR_API(SrvReadConsole)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetInputBufferAndHandleEntry(ProcessData, ReadConsoleRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConSrvGetInputBufferAndHandleEntry(ProcessData,
ReadConsoleRequest->InputHandle,
&InputBuffer,
&HandleEntry,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == InputBuffer->Header.Console);
InputInfo.CallingThread = CsrGetClientThread();
InputInfo.HandleEntry = HandleEntry;
@ -639,11 +646,10 @@ CSR_API(SrvReadConsole)
}
/* API_NUMBER: ConsolepGetConsoleInput */
CSR_API(SrvGetConsoleInput)
CON_API(SrvGetConsoleInput,
CONSOLE_GETINPUT, GetInputRequest)
{
NTSTATUS Status;
PCONSOLE_GETINPUT GetInputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PVOID HandleEntry;
PCONSOLE_INPUT_BUFFER InputBuffer;
GET_INPUT_INFO InputInfo;
@ -651,7 +657,9 @@ CSR_API(SrvGetConsoleInput)
DPRINT("SrvGetConsoleInput\n");
if (GetInputRequest->Flags & ~(CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE))
{
return STATUS_INVALID_PARAMETER;
}
/*
* For optimization purposes, Windows (and hence ReactOS, too, for
@ -678,8 +686,16 @@ CSR_API(SrvGetConsoleInput)
}
}
Status = ConSrvGetInputBufferAndHandleEntry(ProcessData, GetInputRequest->InputHandle, &InputBuffer, &HandleEntry, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConSrvGetInputBufferAndHandleEntry(ProcessData,
GetInputRequest->InputHandle,
&InputBuffer,
&HandleEntry,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == InputBuffer->Header.Console);
InputInfo.CallingThread = CsrGetClientThread();
InputInfo.HandleEntry = HandleEntry;
@ -705,17 +721,14 @@ ConDrvWriteConsoleInput(IN PCONSOLE Console,
#endif
/* API_NUMBER: ConsolepWriteConsoleInput */
CSR_API(SrvWriteConsoleInput)
CON_API(SrvWriteConsoleInput,
CONSOLE_WRITEINPUT, WriteInputRequest)
{
NTSTATUS Status;
PCONSOLE_WRITEINPUT WriteInputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteInputRequest;
PCONSOLE_INPUT_BUFFER InputBuffer;
ULONG NumEventsWritten;
PINPUT_RECORD InputRecord;
DPRINT("SrvWriteConsoleInput\n");
/*
* For optimization purposes, Windows (and hence ReactOS, too, for
* compatibility reasons) uses a static buffer if no more than five
@ -744,7 +757,7 @@ CSR_API(SrvWriteConsoleInput)
InputRecord = WriteInputRequest->RecordBufPtr;
}
Status = ConSrvGetInputBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetInputBuffer(ProcessData,
WriteInputRequest->InputHandle,
&InputBuffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status))
@ -753,26 +766,28 @@ CSR_API(SrvWriteConsoleInput)
return Status;
}
ASSERT((PCONSOLE)Console == InputBuffer->Header.Console);
/* First translate everything to UNICODE */
if (!WriteInputRequest->Unicode)
{
ULONG i;
for (i = 0; i < WriteInputRequest->NumRecords; ++i)
{
ConioInputEventToUnicode(InputBuffer->Header.Console, &InputRecord[i]);
ConioInputEventToUnicode((PCONSOLE)Console, &InputRecord[i]);
}
}
/* Now, add the events */
NumEventsWritten = 0;
Status = ConioAddInputEvents((PCONSRV_CONSOLE)InputBuffer->Header.Console,
Status = ConioAddInputEvents(Console,
// InputBuffer,
InputRecord,
WriteInputRequest->NumRecords,
&NumEventsWritten,
WriteInputRequest->AppendToEnd);
// Status = ConDrvWriteConsoleInput(InputBuffer->Header.Console,
// Status = ConDrvWriteConsoleInput((PCONSOLE)Console,
// InputBuffer,
// WriteInputRequest->AppendToEnd,
// InputRecord,
@ -789,21 +804,21 @@ NTSTATUS NTAPI
ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console,
IN PCONSOLE_INPUT_BUFFER InputBuffer);
/* API_NUMBER: ConsolepFlushInputBuffer */
CSR_API(SrvFlushConsoleInputBuffer)
CON_API(SrvFlushConsoleInputBuffer,
CONSOLE_FLUSHINPUTBUFFER, FlushInputBufferRequest)
{
NTSTATUS Status;
PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.FlushInputBufferRequest;
PCONSOLE_INPUT_BUFFER InputBuffer;
DPRINT("SrvFlushConsoleInputBuffer\n");
Status = ConSrvGetInputBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetInputBuffer(ProcessData,
FlushInputBufferRequest->InputHandle,
&InputBuffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvFlushConsoleInputBuffer(InputBuffer->Header.Console,
InputBuffer);
ASSERT((PCONSOLE)Console == InputBuffer->Header.Console);
Status = ConDrvFlushConsoleInputBuffer((PCONSOLE)Console, InputBuffer);
ConSrvReleaseInputBuffer(InputBuffer, TRUE);
return Status;
@ -814,20 +829,21 @@ ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console,
IN PCONSOLE_INPUT_BUFFER InputBuffer,
OUT PULONG NumberOfEvents);
/* API_NUMBER: ConsolepGetNumberOfInputEvents */
CSR_API(SrvGetConsoleNumberOfInputEvents)
CON_API(SrvGetConsoleNumberOfInputEvents,
CONSOLE_GETNUMINPUTEVENTS, GetNumInputEventsRequest)
{
NTSTATUS Status;
PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetNumInputEventsRequest;
PCONSOLE_INPUT_BUFFER InputBuffer;
DPRINT("SrvGetConsoleNumberOfInputEvents\n");
Status = ConSrvGetInputBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetInputBuffer(ProcessData,
GetNumInputEventsRequest->InputHandle,
&InputBuffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvGetConsoleNumberOfInputEvents(InputBuffer->Header.Console,
ASSERT((PCONSOLE)Console == InputBuffer->Header.Console);
Status = ConDrvGetConsoleNumberOfInputEvents((PCONSOLE)Console,
InputBuffer,
&GetNumInputEventsRequest->NumberOfEvents);

View file

@ -31,35 +31,33 @@ ConDrvInvalidateBitMapRect(IN PCONSOLE Console,
IN PCONSOLE_SCREEN_BUFFER Buffer,
IN PSMALL_RECT Region);
/* API_NUMBER: ConsolepInvalidateBitMapRect */
CSR_API(SrvInvalidateBitMapRect)
CON_API(SrvInvalidateBitMapRect,
CONSOLE_INVALIDATEDIBITS, InvalidateDIBitsRequest)
{
NTSTATUS Status;
PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.InvalidateDIBitsRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buffer;
DPRINT("SrvInvalidateBitMapRect\n");
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
InvalidateDIBitsRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buffer->Header.Console;
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
/* In text-mode only, draw the VDM buffer if present */
if (GetType(Buffer) == TEXTMODE_BUFFER && Console->VDMBuffer)
{
PTEXTMODE_SCREEN_BUFFER TextBuffer = (PTEXTMODE_SCREEN_BUFFER)Buffer;
/*Status =*/ ConDrvWriteConsoleOutputVDM(Buffer->Header.Console,
/*Status =*/ ConDrvWriteConsoleOutputVDM((PCONSOLE)Console,
TextBuffer,
Console->VDMBuffer,
Console->VDMBufferSize,
&InvalidateDIBitsRequest->Region);
}
Status = ConDrvInvalidateBitMapRect(Buffer->Header.Console,
Status = ConDrvInvalidateBitMapRect((PCONSOLE)Console,
Buffer,
&InvalidateDIBitsRequest->Region);
@ -74,29 +72,30 @@ ConDrvSetConsolePalette(IN PCONSOLE Console,
IN HPALETTE PaletteHandle,
IN UINT PaletteUsage);
/* API_NUMBER: ConsolepSetPalette */
CSR_API(SrvSetConsolePalette)
CON_API(SrvSetConsolePalette,
CONSOLE_SETPALETTE, SetPaletteRequest)
{
NTSTATUS Status;
PCONSOLE_SETPALETTE SetPaletteRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetPaletteRequest;
// PGRAPHICS_SCREEN_BUFFER Buffer;
PCONSOLE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsolePalette\n");
// NOTE: Tests show that this function is used only for graphics screen buffers
// and otherwise it returns FALSE + sets last error to invalid handle.
// I think it's ridiculous, because if you are in text mode, simulating
// a change of VGA palette via DAC registers (done by a call to SetConsolePalette)
// cannot be done... So I allow it in ReactOS !
/*
Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetGraphicsBuffer(ProcessData,
SetPaletteRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
*/
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
SetPaletteRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
/*
* Make the palette handle public, so that it can be
@ -108,7 +107,7 @@ CSR_API(SrvSetConsolePalette)
&SetPaletteRequest->PaletteHandle,
sizeof(SetPaletteRequest->PaletteHandle));
Status = ConDrvSetConsolePalette(Buffer->Header.Console,
Status = ConDrvSetConsolePalette((PCONSOLE)Console,
Buffer,
SetPaletteRequest->PaletteHandle,
SetPaletteRequest->Usage);
@ -122,20 +121,21 @@ ConDrvGetConsoleCursorInfo(IN PCONSOLE Console,
IN PTEXTMODE_SCREEN_BUFFER Buffer,
OUT PCONSOLE_CURSOR_INFO CursorInfo);
/* API_NUMBER: ConsolepGetCursorInfo */
CSR_API(SrvGetConsoleCursorInfo)
CON_API(SrvGetConsoleCursorInfo,
CONSOLE_GETSETCURSORINFO, CursorInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CursorInfoRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvGetConsoleCursorInfo\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
CursorInfoRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvGetConsoleCursorInfo(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvGetConsoleCursorInfo((PCONSOLE)Console,
Buffer,
&CursorInfoRequest->Info);
@ -148,20 +148,21 @@ ConDrvSetConsoleCursorInfo(IN PCONSOLE Console,
IN PTEXTMODE_SCREEN_BUFFER Buffer,
IN PCONSOLE_CURSOR_INFO CursorInfo);
/* API_NUMBER: ConsolepSetCursorInfo */
CSR_API(SrvSetConsoleCursorInfo)
CON_API(SrvSetConsoleCursorInfo,
CONSOLE_GETSETCURSORINFO, CursorInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CursorInfoRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsoleCursorInfo\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
CursorInfoRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleCursorInfo(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleCursorInfo((PCONSOLE)Console,
Buffer,
&CursorInfoRequest->Info);
@ -174,20 +175,21 @@ ConDrvSetConsoleCursorPosition(IN PCONSOLE Console,
IN PTEXTMODE_SCREEN_BUFFER Buffer,
IN PCOORD Position);
/* API_NUMBER: ConsolepSetCursorPosition */
CSR_API(SrvSetConsoleCursorPosition)
CON_API(SrvSetConsoleCursorPosition,
CONSOLE_SETCURSORPOSITION, SetCursorPositionRequest)
{
NTSTATUS Status;
PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetCursorPositionRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsoleCursorPosition\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
SetCursorPositionRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleCursorPosition(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleCursorPosition((PCONSOLE)Console,
Buffer,
&SetCursorPositionRequest->Position);
@ -196,13 +198,12 @@ CSR_API(SrvSetConsoleCursorPosition)
}
/* API_NUMBER: ConsolepCreateScreenBuffer */
CSR_API(SrvCreateConsoleScreenBuffer)
CON_API(SrvCreateConsoleScreenBuffer,
CONSOLE_CREATESCREENBUFFER, CreateScreenBufferRequest)
{
NTSTATUS Status = STATUS_INVALID_PARAMETER;
PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CreateScreenBufferRequest;
NTSTATUS Status;
PCSR_PROCESS Process = CsrGetClientThread()->Process;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
PCONSRV_CONSOLE Console;
// PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
PCONSOLE_SCREEN_BUFFER Buff;
PVOID ScreenBufferInfo = NULL;
@ -215,11 +216,6 @@ CSR_API(SrvCreateConsoleScreenBuffer)
GRAPHICS_BUFFER_INFO GraphicsInfo;
GraphicsInfo.Info = CreateScreenBufferRequest->GraphicsBufferInfo; // HACK for MSVC
DPRINT("SrvCreateConsoleScreenBuffer\n");
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (CreateScreenBufferRequest->ScreenBufferType == CONSOLE_TEXTMODE_BUFFER)
{
ScreenBufferInfo = &TextModeInfo;
@ -271,8 +267,7 @@ CSR_API(SrvCreateConsoleScreenBuffer)
CreateScreenBufferRequest->GraphicsBufferInfo.dwBitMapInfoLength,
sizeof(BYTE)))
{
Status = STATUS_INVALID_PARAMETER;
goto Quit;
return STATUS_INVALID_PARAMETER;
}
ScreenBufferInfo = &GraphicsInfo;
@ -286,13 +281,19 @@ CSR_API(SrvCreateConsoleScreenBuffer)
/* A graphics screen buffer is never inheritable */
CreateScreenBufferRequest->InheritHandle = FALSE;
}
else
{
DPRINT1("Invalid ScreenBuffer type %lu\n", CreateScreenBufferRequest->ScreenBufferType);
return STATUS_INVALID_PARAMETER;
}
Status = ConDrvCreateScreenBuffer(&Buff,
(PCONSOLE)Console,
Process->ProcessHandle,
CreateScreenBufferRequest->ScreenBufferType,
ScreenBufferInfo);
if (!NT_SUCCESS(Status)) goto Quit;
if (!NT_SUCCESS(Status))
return Status;
/* Insert the new handle inside the process handles table */
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
@ -306,7 +307,11 @@ CSR_API(SrvCreateConsoleScreenBuffer)
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
if (!NT_SUCCESS(Status)) goto Quit;
if (!NT_SUCCESS(Status))
{
ConDrvDeleteScreenBuffer(Buff);
return Status;
}
if (CreateScreenBufferRequest->ScreenBufferType == CONSOLE_GRAPHICS_BUFFER)
{
@ -321,8 +326,6 @@ CSR_API(SrvCreateConsoleScreenBuffer)
CreateScreenBufferRequest->lpBitMap = Buffer->ClientBitMap;
}
Quit:
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
@ -330,21 +333,21 @@ NTSTATUS NTAPI
ConDrvSetConsoleActiveScreenBuffer(IN PCONSOLE Console,
IN PCONSOLE_SCREEN_BUFFER Buffer);
/* API_NUMBER: ConsolepSetActiveScreenBuffer */
CSR_API(SrvSetConsoleActiveScreenBuffer)
CON_API(SrvSetConsoleActiveScreenBuffer,
CONSOLE_SETACTIVESCREENBUFFER, SetScreenBufferRequest)
{
NTSTATUS Status;
PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetScreenBufferRequest;
PCONSOLE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsoleActiveScreenBuffer\n");
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
SetScreenBufferRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleActiveScreenBuffer(Buffer->Header.Console,
Buffer);
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleActiveScreenBuffer((PCONSOLE)Console, Buffer);
ConSrvReleaseScreenBuffer(Buffer, TRUE);
return Status;
@ -493,17 +496,14 @@ ConDrvReadConsoleOutput(IN PCONSOLE Console,
OUT PCHAR_INFO CharInfo/*Buffer*/,
IN OUT PSMALL_RECT ReadRegion);
/* API_NUMBER: ConsolepReadConsoleOutput */
CSR_API(SrvReadConsoleOutput)
CON_API(SrvReadConsoleOutput,
CONSOLE_READOUTPUT, ReadOutputRequest)
{
NTSTATUS Status;
PCONSOLE_READOUTPUT ReadOutputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadOutputRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
ULONG NumCells;
PCHAR_INFO CharInfo;
DPRINT("SrvReadConsoleOutput\n");
NumCells = ConioRectWidth(&ReadOutputRequest->ReadRegion) *
ConioRectHeight(&ReadOutputRequest->ReadRegion);
@ -535,12 +535,15 @@ CSR_API(SrvReadConsoleOutput)
CharInfo = ReadOutputRequest->CharInfo;
}
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
ReadOutputRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvReadConsoleOutput(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvReadConsoleOutput((PCONSOLE)Console,
Buffer,
ReadOutputRequest->Unicode,
CharInfo,
@ -557,25 +560,26 @@ ConDrvWriteConsoleOutput(IN PCONSOLE Console,
IN PCHAR_INFO CharInfo/*Buffer*/,
IN OUT PSMALL_RECT WriteRegion);
/* API_NUMBER: ConsolepWriteConsoleOutput */
CSR_API(SrvWriteConsoleOutput)
CON_API(SrvWriteConsoleOutput,
CONSOLE_WRITEOUTPUT, WriteOutputRequest)
{
NTSTATUS Status;
PCONSOLE_WRITEOUTPUT WriteOutputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteOutputRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
PCSR_PROCESS Process = CsrGetClientThread()->Process;
// PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
PTEXTMODE_SCREEN_BUFFER Buffer;
ULONG NumCells;
PCHAR_INFO CharInfo;
DPRINT("SrvWriteConsoleOutput\n");
NumCells = ConioRectWidth(&WriteOutputRequest->WriteRegion) *
ConioRectHeight(&WriteOutputRequest->WriteRegion);
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
WriteOutputRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
/*
* Validate the message buffer if we do not use a process' heap buffer
@ -640,7 +644,7 @@ CSR_API(SrvWriteConsoleOutput)
}
}
Status = ConDrvWriteConsoleOutput(Buffer->Header.Console,
Status = ConDrvWriteConsoleOutput((PCONSOLE)Console,
Buffer,
WriteOutputRequest->Unicode,
CharInfo,
@ -656,10 +660,10 @@ Quit:
}
/* API_NUMBER: ConsolepWriteConsole */
CSR_API(SrvWriteConsole)
CON_API(SrvWriteConsole,
CONSOLE_WRITECONSOLE, WriteConsoleRequest)
{
NTSTATUS Status;
PCONSOLE_WRITECONSOLE WriteConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleRequest;
DPRINT("SrvWriteConsole\n");
@ -706,17 +710,14 @@ ConDrvReadConsoleOutputString(IN PCONSOLE Console,
// OUT PCOORD EndCoord,
OUT PULONG NumCodesRead OPTIONAL);
/* API_NUMBER: ConsolepReadConsoleOutputString */
CSR_API(SrvReadConsoleOutputString)
CON_API(SrvReadConsoleOutputString,
CONSOLE_READOUTPUTCODE, ReadOutputCodeRequest)
{
NTSTATUS Status;
PCONSOLE_READOUTPUTCODE ReadOutputCodeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadOutputCodeRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
ULONG CodeSize;
PVOID pCode;
DPRINT("SrvReadConsoleOutputString\n");
switch (ReadOutputCodeRequest->CodeType)
{
case CODE_ASCII:
@ -763,7 +764,7 @@ CSR_API(SrvReadConsoleOutputString)
pCode = ReadOutputCodeRequest->pCode;
}
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
ReadOutputCodeRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status))
@ -772,7 +773,9 @@ CSR_API(SrvReadConsoleOutputString)
return Status;
}
Status = ConDrvReadConsoleOutputString(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvReadConsoleOutputString((PCONSOLE)Console,
Buffer,
ReadOutputCodeRequest->CodeType,
pCode,
@ -795,17 +798,14 @@ ConDrvWriteConsoleOutputString(IN PCONSOLE Console,
// OUT PCOORD EndCoord,
OUT PULONG NumCodesWritten OPTIONAL);
/* API_NUMBER: ConsolepWriteConsoleOutputString */
CSR_API(SrvWriteConsoleOutputString)
CON_API(SrvWriteConsoleOutputString,
CONSOLE_WRITEOUTPUTCODE, WriteOutputCodeRequest)
{
NTSTATUS Status;
PCONSOLE_WRITEOUTPUTCODE WriteOutputCodeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteOutputCodeRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
ULONG CodeSize;
PVOID pCode;
DPRINT("SrvWriteConsoleOutputString\n");
switch (WriteOutputCodeRequest->CodeType)
{
case CODE_ASCII:
@ -852,7 +852,7 @@ CSR_API(SrvWriteConsoleOutputString)
pCode = WriteOutputCodeRequest->pCode;
}
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
WriteOutputCodeRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status))
@ -861,7 +861,9 @@ CSR_API(SrvWriteConsoleOutputString)
return Status;
}
Status = ConDrvWriteConsoleOutputString(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvWriteConsoleOutputString((PCONSOLE)Console,
Buffer,
WriteOutputCodeRequest->CodeType,
pCode,
@ -883,15 +885,13 @@ ConDrvFillConsoleOutput(IN PCONSOLE Console,
IN PCOORD WriteCoord,
OUT PULONG NumCodesWritten OPTIONAL);
/* API_NUMBER: ConsolepFillConsoleOutput */
CSR_API(SrvFillConsoleOutput)
CON_API(SrvFillConsoleOutput,
CONSOLE_FILLOUTPUTCODE, FillOutputRequest)
{
NTSTATUS Status;
PCONSOLE_FILLOUTPUTCODE FillOutputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.FillOutputRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
CODE_TYPE CodeType = FillOutputRequest->CodeType;
DPRINT("SrvFillConsoleOutput\n");
if ( (CodeType != CODE_ASCII ) &&
(CodeType != CODE_UNICODE ) &&
(CodeType != CODE_ATTRIBUTE) )
@ -899,7 +899,7 @@ CSR_API(SrvFillConsoleOutput)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
FillOutputRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status))
@ -908,7 +908,9 @@ CSR_API(SrvFillConsoleOutput)
return Status;
}
Status = ConDrvFillConsoleOutput(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvFillConsoleOutput((PCONSOLE)Console,
Buffer,
CodeType,
FillOutputRequest->Code,
@ -930,20 +932,21 @@ ConDrvGetConsoleScreenBufferInfo(IN PCONSOLE Console,
OUT PCOORD MaximumViewSize,
OUT PWORD Attributes);
/* API_NUMBER: ConsolepGetScreenBufferInfo */
CSR_API(SrvGetConsoleScreenBufferInfo)
CON_API(SrvGetConsoleScreenBufferInfo,
CONSOLE_GETSCREENBUFFERINFO, ScreenBufferInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ScreenBufferInfoRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvGetConsoleScreenBufferInfo\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
ScreenBufferInfoRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvGetConsoleScreenBufferInfo(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvGetConsoleScreenBufferInfo((PCONSOLE)Console,
Buffer,
&ScreenBufferInfoRequest->ScreenBufferSize,
&ScreenBufferInfoRequest->CursorPosition,
@ -961,20 +964,21 @@ ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
IN PTEXTMODE_SCREEN_BUFFER Buffer,
IN WORD Attributes);
/* API_NUMBER: ConsolepSetTextAttribute */
CSR_API(SrvSetConsoleTextAttribute)
CON_API(SrvSetConsoleTextAttribute,
CONSOLE_SETTEXTATTRIB, SetTextAttribRequest)
{
NTSTATUS Status;
PCONSOLE_SETTEXTATTRIB SetTextAttribRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetTextAttribRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsoleTextAttribute\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
SetTextAttribRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleTextAttribute(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleTextAttribute((PCONSOLE)Console,
Buffer,
SetTextAttribRequest->Attributes);
@ -987,20 +991,21 @@ ConDrvSetConsoleScreenBufferSize(IN PCONSOLE Console,
IN PTEXTMODE_SCREEN_BUFFER Buffer,
IN PCOORD Size);
/* API_NUMBER: ConsolepSetScreenBufferSize */
CSR_API(SrvSetConsoleScreenBufferSize)
CON_API(SrvSetConsoleScreenBufferSize,
CONSOLE_SETSCREENBUFFERSIZE, SetScreenBufferSizeRequest)
{
NTSTATUS Status;
PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetScreenBufferSizeRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvSetConsoleScreenBufferSize\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
SetScreenBufferSizeRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleScreenBufferSize(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleScreenBufferSize((PCONSOLE)Console,
Buffer,
&SetScreenBufferSizeRequest->Size);
@ -1018,20 +1023,21 @@ ConDrvScrollConsoleScreenBuffer(IN PCONSOLE Console,
IN PCOORD DestinationOrigin,
IN CHAR_INFO FillChar);
/* API_NUMBER: ConsolepScrollScreenBuffer */
CSR_API(SrvScrollConsoleScreenBuffer)
CON_API(SrvScrollConsoleScreenBuffer,
CONSOLE_SCROLLSCREENBUFFER, ScrollScreenBufferRequest)
{
NTSTATUS Status;
PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ScrollScreenBufferRequest;
PTEXTMODE_SCREEN_BUFFER Buffer;
DPRINT("SrvScrollConsoleScreenBuffer\n");
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
ScrollScreenBufferRequest->OutputHandle,
&Buffer, GENERIC_WRITE, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvScrollConsoleScreenBuffer(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvScrollConsoleScreenBuffer((PCONSOLE)Console,
Buffer,
ScrollScreenBufferRequest->Unicode,
&ScrollScreenBufferRequest->ScrollRectangle,
@ -1050,10 +1056,10 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
IN BOOLEAN Absolute,
IN PSMALL_RECT WindowRect);
/* API_NUMBER: ConsolepSetWindowInfo */
CSR_API(SrvSetConsoleWindowInfo)
CON_API(SrvSetConsoleWindowInfo,
CONSOLE_SETWINDOWINFO, SetWindowInfoRequest)
{
NTSTATUS Status;
PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetWindowInfoRequest;
// PCONSOLE_SCREEN_BUFFER Buffer;
PTEXTMODE_SCREEN_BUFFER Buffer;
@ -1065,12 +1071,15 @@ CSR_API(SrvSetConsoleWindowInfo)
SetWindowInfoRequest->WindowRect.Bottom);
// ConSrvGetScreenBuffer
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
SetWindowInfoRequest->OutputHandle,
&Buffer, GENERIC_READ, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Status = ConDrvSetConsoleWindowInfo(Buffer->Header.Console,
ASSERT((PCONSOLE)Console == Buffer->Header.Console);
Status = ConDrvSetConsoleWindowInfo((PCONSOLE)Console,
Buffer,
SetWindowInfoRequest->Absolute,
&SetWindowInfoRequest->WindowRect);

View file

@ -1060,12 +1060,10 @@ ConSrvSetConsoleProcessFocus(IN PCONSRV_CONSOLE Console,
/* PUBLIC SERVER APIS *********************************************************/
/* API_NUMBER: ConsolepAlloc */
CSR_API(SrvAllocConsole)
CON_API_NOCONSOLE(SrvAllocConsole,
CONSOLE_ALLOCCONSOLE, AllocConsoleRequest)
{
NTSTATUS Status = STATUS_SUCCESS;
PCONSOLE_ALLOCCONSOLE AllocConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AllocConsoleRequest;
PCSR_PROCESS CsrProcess = CsrGetClientThread()->Process;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
CONSOLE_INIT_INFO ConsoleInitInfo;
if (ProcessData->ConsoleHandle != NULL)
@ -1130,10 +1128,10 @@ CSR_API(SrvAllocConsole)
}
/* API_NUMBER: ConsolepAttach */
CSR_API(SrvAttachConsole)
CON_API_NOCONSOLE(SrvAttachConsole,
CONSOLE_ATTACHCONSOLE, AttachConsoleRequest)
{
NTSTATUS Status = STATUS_SUCCESS;
PCONSOLE_ATTACHCONSOLE AttachConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AttachConsoleRequest;
PCSR_PROCESS SourceProcess = NULL; // The parent process.
PCSR_PROCESS TargetProcess = CsrGetClientThread()->Process; // Ourselves.
HANDLE ProcessId = ULongToHandle(AttachConsoleRequest->ProcessId);
@ -1218,9 +1216,20 @@ Quit:
}
/* API_NUMBER: ConsolepFree */
CSR_API(SrvFreeConsole)
CON_API_NOCONSOLE(SrvFreeConsole,
CONSOLE_FREECONSOLE, FreeConsoleRequest)
{
return ConSrvRemoveConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process));
/*
* If this process doesn't have a console handle, bail out immediately.
* Also the passed console handle should be the same as the process' one.
*/
if ((FreeConsoleRequest->ConsoleHandle == NULL) ||
(FreeConsoleRequest->ConsoleHandle != ProcessData->ConsoleHandle))
{
return STATUS_INVALID_HANDLE; // STATUS_ACCESS_DENIED;
}
return ConSrvRemoveConsole(ProcessData);
}
NTSTATUS NTAPI
@ -1228,24 +1237,23 @@ ConDrvGetConsoleMode(IN PCONSOLE Console,
IN PCONSOLE_IO_OBJECT Object,
OUT PULONG ConsoleMode);
/* API_NUMBER: ConsolepGetMode */
CSR_API(SrvGetConsoleMode)
CON_API(SrvGetConsoleMode,
CONSOLE_GETSETCONSOLEMODE, ConsoleModeRequest)
{
NTSTATUS Status;
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_IO_OBJECT Object;
PULONG ConsoleMode = &ConsoleModeRequest->Mode;
Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetObject(ProcessData,
ConsoleModeRequest->Handle,
&Object, NULL, GENERIC_READ, TRUE, 0);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Object->Console;
ASSERT((PCONSOLE)Console == Object->Console);
/* Get the standard console modes */
Status = ConDrvGetConsoleMode(Object->Console, Object, ConsoleMode);
Status = ConDrvGetConsoleMode((PCONSOLE)Console, Object, ConsoleMode);
if (NT_SUCCESS(Status))
{
/*
@ -1274,29 +1282,28 @@ ConDrvSetConsoleMode(IN PCONSOLE Console,
IN PCONSOLE_IO_OBJECT Object,
IN ULONG ConsoleMode);
/* API_NUMBER: ConsolepSetMode */
CSR_API(SrvSetConsoleMode)
CON_API(SrvSetConsoleMode,
CONSOLE_GETSETCONSOLEMODE, ConsoleModeRequest)
{
#define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS | \
ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
// NOTE: Vista+ ENABLE_AUTO_POSITION is also a control mode.
NTSTATUS Status;
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_IO_OBJECT Object;
ULONG ConsoleMode = ConsoleModeRequest->Mode;
Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetObject(ProcessData,
ConsoleModeRequest->Handle,
&Object, NULL, GENERIC_WRITE, TRUE, 0);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Object->Console;
ASSERT((PCONSOLE)Console == Object->Console);
/* Set the standard console modes (without the CONSRV-specific input modes) */
ConsoleMode &= ~CONSOLE_VALID_CONTROL_MODES; // Remove CONSRV-specific input modes.
Status = ConDrvSetConsoleMode(Object->Console, Object, ConsoleMode);
Status = ConDrvSetConsoleMode((PCONSOLE)Console, Object, ConsoleMode);
if (NT_SUCCESS(Status))
{
/*
@ -1331,11 +1338,9 @@ CSR_API(SrvSetConsoleMode)
}
/* API_NUMBER: ConsolepGetTitle */
CSR_API(SrvGetConsoleTitle)
CON_API(SrvGetConsoleTitle,
CONSOLE_GETSETCONSOLETITLE, TitleRequest)
{
NTSTATUS Status;
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
PCONSRV_CONSOLE Console;
ULONG Length;
if (!CsrValidateMessageBuffer(ApiMessage,
@ -1346,13 +1351,6 @@ CSR_API(SrvGetConsoleTitle)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
/* Copy title of the console to the user title buffer */
if (TitleRequest->Unicode)
{
@ -1386,17 +1384,13 @@ CSR_API(SrvGetConsoleTitle)
}
}
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetTitle */
CSR_API(SrvSetConsoleTitle)
CON_API(SrvSetConsoleTitle,
CONSOLE_GETSETCONSOLETITLE, TitleRequest)
{
NTSTATUS Status;
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
PCONSRV_CONSOLE Console;
PWCHAR Buffer;
ULONG Length;
@ -1408,13 +1402,6 @@ CSR_API(SrvSetConsoleTitle)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
if (TitleRequest->Unicode)
{
/* Length is in bytes */
@ -1433,10 +1420,7 @@ CSR_API(SrvSetConsoleTitle)
/* Allocate a new buffer to hold the new title (NULL-terminated) */
Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Length + sizeof(WCHAR));
if (!Buffer)
{
Status = STATUS_NO_MEMORY;
goto Quit;
}
return STATUS_NO_MEMORY;
/* Free the old title */
ConsoleFreeUnicodeString(&Console->Title);
@ -1462,11 +1446,8 @@ CSR_API(SrvSetConsoleTitle)
Console->Title.Buffer[Console->Title.Length / sizeof(WCHAR)] = UNICODE_NULL;
TermChangeTitle(Console);
Status = STATUS_SUCCESS;
Quit:
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
NTSTATUS NTAPI
@ -1474,24 +1455,15 @@ ConDrvGetConsoleCP(IN PCONSOLE Console,
OUT PUINT CodePage,
IN BOOLEAN OutputCP);
/* API_NUMBER: ConsolepGetCP */
CSR_API(SrvGetConsoleCP)
CON_API(SrvGetConsoleCP,
CONSOLE_GETINPUTOUTPUTCP, GetConsoleCPRequest)
{
NTSTATUS Status;
PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleCPRequest;
PCONSRV_CONSOLE Console;
DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
GetConsoleCPRequest->OutputCP ? "Output" : "Input");
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConDrvGetConsoleCP((PCONSOLE)Console,
&GetConsoleCPRequest->CodePage,
GetConsoleCPRequest->OutputCP);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return ConDrvGetConsoleCP((PCONSOLE)Console,
&GetConsoleCPRequest->CodePage,
GetConsoleCPRequest->OutputCP);
}
NTSTATUS NTAPI
@ -1499,33 +1471,21 @@ ConDrvSetConsoleCP(IN PCONSOLE Console,
IN UINT CodePage,
IN BOOLEAN OutputCP);
/* API_NUMBER: ConsolepSetCP */
CSR_API(SrvSetConsoleCP)
CON_API(SrvSetConsoleCP,
CONSOLE_SETINPUTOUTPUTCP, SetConsoleCPRequest)
{
NTSTATUS Status = STATUS_INVALID_PARAMETER;
PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetConsoleCPRequest;
PCONSRV_CONSOLE Console;
DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
SetConsoleCPRequest->OutputCP ? "Output" : "Input");
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConDrvSetConsoleCP((PCONSOLE)Console,
SetConsoleCPRequest->CodePage,
SetConsoleCPRequest->OutputCP);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return ConDrvSetConsoleCP((PCONSOLE)Console,
SetConsoleCPRequest->CodePage,
SetConsoleCPRequest->OutputCP);
}
/* API_NUMBER: ConsolepGetProcessList */
CSR_API(SrvGetConsoleProcessList)
CON_API(SrvGetConsoleProcessList,
CONSOLE_GETPROCESSLIST, GetProcessListRequest)
{
NTSTATUS Status;
PCONSOLE_GETPROCESSLIST GetProcessListRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetProcessListRequest;
PCONSRV_CONSOLE Console;
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID)&GetProcessListRequest->ProcessIdsList,
GetProcessListRequest->ProcessCount,
@ -1534,76 +1494,40 @@ CSR_API(SrvGetConsoleProcessList)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConSrvGetConsoleProcessList(Console,
GetProcessListRequest->ProcessIdsList,
GetProcessListRequest->ProcessCount,
&GetProcessListRequest->ProcessCount);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return ConSrvGetConsoleProcessList(Console,
GetProcessListRequest->ProcessIdsList,
GetProcessListRequest->ProcessCount,
&GetProcessListRequest->ProcessCount);
}
/* API_NUMBER: ConsolepGenerateCtrlEvent */
CSR_API(SrvGenerateConsoleCtrlEvent)
CON_API(SrvGenerateConsoleCtrlEvent,
CONSOLE_GENERATECTRLEVENT, GenerateCtrlEventRequest)
{
NTSTATUS Status;
PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GenerateCtrlEventRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = ConSrvConsoleProcessCtrlEvent(Console,
GenerateCtrlEventRequest->ProcessGroupId,
GenerateCtrlEventRequest->CtrlEvent);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return ConSrvConsoleProcessCtrlEvent(Console,
GenerateCtrlEventRequest->ProcessGroupId,
GenerateCtrlEventRequest->CtrlEvent);
}
/* API_NUMBER: ConsolepNotifyLastClose */
CSR_API(SrvConsoleNotifyLastClose)
CON_API(SrvConsoleNotifyLastClose,
CONSOLE_NOTIFYLASTCLOSE, NotifyLastCloseRequest)
{
NTSTATUS Status;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
/* Only one process is allowed to be registered for last close notification */
if (!Console->NotifyLastClose)
{
Console->NotifyLastClose = TRUE;
Console->NotifiedLastCloseProcess = ProcessData;
Status = STATUS_SUCCESS;
}
else
{
Status = STATUS_ACCESS_DENIED;
}
if (Console->NotifyLastClose)
return STATUS_ACCESS_DENIED;
ConSrvReleaseConsole(Console, TRUE);
return Status;
Console->NotifyLastClose = TRUE;
Console->NotifiedLastCloseProcess = ProcessData;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetMouseInfo */
CSR_API(SrvGetConsoleMouseInfo)
CON_API(SrvGetConsoleMouseInfo,
CONSOLE_GETMOUSEINFO, GetMouseInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETMOUSEINFO GetMouseInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetMouseInfoRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
/* Just retrieve the number of buttons of the mouse attached to this console */
GetMouseInfoRequest->NumButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
@ -1615,22 +1539,15 @@ CSR_API(SrvSetConsoleKeyShortcuts)
}
/* API_NUMBER: ConsolepGetKeyboardLayoutName */
CSR_API(SrvGetConsoleKeyboardLayoutName)
CON_API(SrvGetConsoleKeyboardLayoutName,
CONSOLE_GETKBDLAYOUTNAME, GetKbdLayoutNameRequest)
{
NTSTATUS Status;
PCONSOLE_GETKBDLAYOUTNAME GetKbdLayoutNameRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetKbdLayoutNameRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
/* Retrieve the keyboard layout name of the system */
if (GetKbdLayoutNameRequest->Ansi)
GetKeyboardLayoutNameA((PCHAR)GetKbdLayoutNameRequest->LayoutBuffer);
else
GetKeyboardLayoutNameW((PWCHAR)GetKbdLayoutNameRequest->LayoutBuffer);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}

View file

@ -63,6 +63,7 @@ typedef struct ConsoleInput_t
#include "include/conio.h"
#include "include/conio_winsrv.h"
#include "api.h" // For the CON_API_* macros.
#include "include/console.h"
#include "include/settings.h"
#include "include/term.h"

View file

@ -53,30 +53,27 @@ SetConsoleHardwareState(PCONSRV_CONSOLE Console, ULONG ConsoleHwState)
#endif
/* API_NUMBER: ConsolepGetHardwareState */
CSR_API(SrvGetConsoleHardwareState)
CON_API(SrvGetConsoleHardwareState,
CONSOLE_GETSETHWSTATE, HardwareStateRequest)
{
#if 0
NTSTATUS Status;
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
PCONSOLE_SCREEN_BUFFER Buff;
PCONSRV_CONSOLE Console;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvGetConsoleHardwareState\n");
return Status;
}
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
HardwareStateRequest->State = Console->HardwareState;
ConSrvReleaseScreenBuffer(Buff, TRUE);
return Status;
return STATUS_SUCCESS;
#else
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
@ -84,31 +81,28 @@ CSR_API(SrvGetConsoleHardwareState)
}
/* API_NUMBER: ConsolepSetHardwareState */
CSR_API(SrvSetConsoleHardwareState)
CON_API(SrvSetConsoleHardwareState,
CONSOLE_GETSETHWSTATE, HardwareStateRequest)
{
#if 0
NTSTATUS Status;
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
PCONSOLE_SCREEN_BUFFER Buff;
PCONSRV_CONSOLE Console;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvSetConsoleHardwareState\n");
return Status;
}
ASSERT((PCONSOLE)Console == Buff->Header.Console);
DPRINT("Setting console hardware state.\n");
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
Status = SetConsoleHardwareState(Console, HardwareStateRequest->State);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return Status;
return STATUS_SUCCESS;
#else
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
@ -116,38 +110,29 @@ CSR_API(SrvSetConsoleHardwareState)
}
/* API_NUMBER: ConsolepGetDisplayMode */
CSR_API(SrvGetConsoleDisplayMode)
CON_API(SrvGetConsoleDisplayMode,
CONSOLE_GETDISPLAYMODE, GetDisplayModeRequest)
{
NTSTATUS Status;
PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetDisplayModeRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetDisplayModeRequest->DisplayMode = TermGetDisplayMode(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetDisplayMode */
CSR_API(SrvSetConsoleDisplayMode)
CON_API(SrvSetConsoleDisplayMode,
CONSOLE_SETDISPLAYMODE, SetDisplayModeRequest)
{
NTSTATUS Status;
PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetDisplayModeRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
SetDisplayModeRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
if (TermSetDisplayMode(Console, SetDisplayModeRequest->DisplayMode))
{
@ -164,21 +149,21 @@ CSR_API(SrvSetConsoleDisplayMode)
}
/* API_NUMBER: ConsolepGetLargestWindowSize */
CSR_API(SrvGetLargestConsoleWindowSize)
CON_API(SrvGetLargestConsoleWindowSize,
CONSOLE_GETLARGESTWINDOWSIZE, GetLargestWindowSizeRequest)
{
NTSTATUS Status;
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetLargestWindowSizeRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
GetLargestWindowSizeRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
/*
* Retrieve the largest possible console window size, without
@ -192,21 +177,21 @@ CSR_API(SrvGetLargestConsoleWindowSize)
}
/* API_NUMBER: ConsolepShowCursor */
CSR_API(SrvShowConsoleCursor)
CON_API(SrvShowConsoleCursor,
CONSOLE_SHOWCURSOR, ShowCursorRequest)
{
NTSTATUS Status;
PCONSOLE_SHOWCURSOR ShowCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ShowCursorRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
ShowCursorRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
ShowCursorRequest->RefCount = TermShowMouseCursor(Console, ShowCursorRequest->Show);
@ -215,25 +200,25 @@ CSR_API(SrvShowConsoleCursor)
}
/* API_NUMBER: ConsolepSetCursor */
CSR_API(SrvSetConsoleCursor)
CON_API(SrvSetConsoleCursor,
CONSOLE_SETCURSOR, SetCursorRequest)
{
NTSTATUS Status;
BOOL Success;
PCONSOLE_SETCURSOR SetCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetCursorRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
// NOTE: Tests show that this function is used only for graphics screen buffers
// and otherwise it returns FALSE and sets last error to ERROR_INVALID_HANDLE.
// I find that behaviour is ridiculous but ok, let's accept it at the moment...
Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetGraphicsBuffer(ProcessData,
SetCursorRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
Success = TermSetMouseCursor(Console, SetCursorRequest->CursorHandle);
@ -242,21 +227,21 @@ CSR_API(SrvSetConsoleCursor)
}
/* API_NUMBER: ConsolepMenuControl */
CSR_API(SrvConsoleMenuControl)
CON_API(SrvConsoleMenuControl,
CONSOLE_MENUCONTROL, MenuControlRequest)
{
NTSTATUS Status;
PCONSOLE_MENUCONTROL MenuControlRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.MenuControlRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetScreenBuffer(ProcessData,
MenuControlRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
MenuControlRequest->MenuHandle = TermMenuControl(Console,
MenuControlRequest->CmdIdLow,
@ -267,21 +252,11 @@ CSR_API(SrvConsoleMenuControl)
}
/* API_NUMBER: ConsolepSetMenuClose */
CSR_API(SrvSetConsoleMenuClose)
CON_API(SrvSetConsoleMenuClose,
CONSOLE_SETMENUCLOSE, SetMenuCloseRequest)
{
NTSTATUS Status;
BOOL Success;
PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetMenuCloseRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Success = TermSetMenuClose(Console, SetMenuCloseRequest->Enable);
ConSrvReleaseConsole(Console, TRUE);
return (Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
return (TermSetMenuClose(Console, SetMenuCloseRequest->Enable)
? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
/* Used by USERSRV!SrvGetThreadConsoleDesktop() */
@ -321,97 +296,58 @@ GetThreadConsoleDesktop(
}
/* API_NUMBER: ConsolepGetConsoleWindow */
CSR_API(SrvGetConsoleWindow)
CON_API(SrvGetConsoleWindow,
CONSOLE_GETWINDOW, GetWindowRequest)
{
NTSTATUS Status;
PCONSOLE_GETWINDOW GetWindowRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetWindowRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetWindowRequest->WindowHandle = TermGetConsoleWindowHandle(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetIcon */
CSR_API(SrvSetConsoleIcon)
CON_API(SrvSetConsoleIcon,
CONSOLE_SETICON, SetIconRequest)
{
NTSTATUS Status;
PCONSOLE_SETICON SetIconRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetIconRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = (TermChangeIcon(Console, SetIconRequest->IconHandle)
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return (TermChangeIcon(Console, SetIconRequest->IconHandle)
? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
/* API_NUMBER: ConsolepGetSelectionInfo */
CSR_API(SrvGetConsoleSelectionInfo)
CON_API(SrvGetConsoleSelectionInfo,
CONSOLE_GETSELECTIONINFO, GetSelectionInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetSelectionInfoRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = (TermGetSelectionInfo(Console, &GetSelectionInfoRequest->Info)
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return (TermGetSelectionInfo(Console, &GetSelectionInfoRequest->Info)
? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
/* API_NUMBER: ConsolepGetNumberOfFonts */
CSR_API(SrvGetConsoleNumberOfFonts)
CON_API(SrvGetConsoleNumberOfFonts,
CONSOLE_GETNUMFONTS, GetNumFontsRequest)
{
NTSTATUS Status;
PCONSOLE_GETNUMFONTS GetNumFontsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetNumFontsRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// TermGetNumberOfFonts(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetNumFontsRequest->NumFonts = 0;
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetFontInfo */
CSR_API(SrvGetConsoleFontInfo)
CON_API(SrvGetConsoleFontInfo,
CONSOLE_GETFONTINFO, GetFontInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETFONTINFO GetFontInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontInfoRequest;
// PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
GetFontInfoRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
// FIXME!
// Console = (PCONSRV_CONSOLE)Buff->Header.Console;
// TermGetFontInfo(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetFontInfoRequest->NumFonts = 0;
@ -421,22 +357,23 @@ CSR_API(SrvGetConsoleFontInfo)
}
/* API_NUMBER: ConsolepGetFontSize */
CSR_API(SrvGetConsoleFontSize)
CON_API(SrvGetConsoleFontSize,
CONSOLE_GETFONTSIZE, GetFontSizeRequest)
{
NTSTATUS Status;
PCONSOLE_GETFONTSIZE GetFontSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontSizeRequest;
// PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
GetFontSizeRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
// FIXME!
// Console = (PCONSRV_CONSOLE)Buff->Header.Console;
// TermGetFontSize(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
@ -445,22 +382,23 @@ CSR_API(SrvGetConsoleFontSize)
}
/* API_NUMBER: ConsolepGetCurrentFont */
CSR_API(SrvGetConsoleCurrentFont)
CON_API(SrvGetConsoleCurrentFont,
CONSOLE_GETCURRENTFONT, GetCurrentFontRequest)
{
NTSTATUS Status;
PCONSOLE_GETCURRENTFONT GetCurrentFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCurrentFontRequest;
// PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
GetCurrentFontRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
// FIXME!
// Console = (PCONSRV_CONSOLE)Buff->Header.Console;
// TermGetCurrentFont(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetCurrentFontRequest->FontIndex = 0;
@ -470,22 +408,23 @@ CSR_API(SrvGetConsoleCurrentFont)
}
/* API_NUMBER: ConsolepSetFont */
CSR_API(SrvSetConsoleFont)
CON_API(SrvSetConsoleFont,
CONSOLE_SETFONT, SetFontRequest)
{
NTSTATUS Status;
PCONSOLE_SETFONT SetFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetFontRequest;
// PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetTextModeBuffer(ProcessData,
SetFontRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
ASSERT((PCONSOLE)Console == Buff->Header.Console);
// FIXME!
// Console = (PCONSRV_CONSOLE)Buff->Header.Console;
// TermSetFont(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);

View file

@ -810,7 +810,8 @@ ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData)
/* PUBLIC SERVER APIS *********************************************************/
/* API_NUMBER: ConsolepOpenConsole */
CSR_API(SrvOpenConsole)
CON_API(SrvOpenConsole,
CONSOLE_OPENCONSOLE, OpenConsoleRequest)
{
/*
* This API opens a handle to either the input buffer or to
@ -818,23 +819,12 @@ CSR_API(SrvOpenConsole)
*/
NTSTATUS Status;
PCONSOLE_OPENCONSOLE OpenConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.OpenConsoleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
DWORD DesiredAccess = OpenConsoleRequest->DesiredAccess;
DWORD ShareMode = OpenConsoleRequest->ShareMode;
PCONSOLE_IO_OBJECT Object;
OpenConsoleRequest->Handle = INVALID_HANDLE_VALUE;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
/*
@ -869,18 +859,14 @@ CSR_API(SrvOpenConsole)
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepDuplicateHandle */
CSR_API(SrvDuplicateHandle)
CON_API(SrvDuplicateHandle,
CONSOLE_DUPLICATEHANDLE, DuplicateHandleRequest)
{
NTSTATUS Status;
PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.DuplicateHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
HANDLE SourceHandle = DuplicateHandleRequest->SourceHandle;
ULONG Index = HandleToULong(SourceHandle) >> 2;
PCONSOLE_IO_HANDLE Entry;
@ -888,13 +874,6 @@ CSR_API(SrvDuplicateHandle)
DuplicateHandleRequest->TargetHandle = INVALID_HANDLE_VALUE;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
// ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
@ -943,29 +922,18 @@ CSR_API(SrvDuplicateHandle)
Quit:
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetHandleInformation */
CSR_API(SrvGetHandleInformation)
CON_API(SrvGetHandleInformation,
CONSOLE_GETHANDLEINFO, GetHandleInfoRequest)
{
NTSTATUS Status;
PCONSOLE_GETHANDLEINFO GetHandleInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetHandleInfoRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
HANDLE Handle = GetHandleInfoRequest->Handle;
ULONG Index = HandleToULong(Handle) >> 2;
PCONSOLE_IO_HANDLE Entry;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
ASSERT(ProcessData->HandleTable);
@ -992,29 +960,18 @@ CSR_API(SrvGetHandleInformation)
Quit:
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepSetHandleInformation */
CSR_API(SrvSetHandleInformation)
CON_API(SrvSetHandleInformation,
CONSOLE_SETHANDLEINFO, SetHandleInfoRequest)
{
NTSTATUS Status;
PCONSOLE_SETHANDLEINFO SetHandleInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHandleInfoRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
HANDLE Handle = SetHandleInfoRequest->Handle;
ULONG Index = HandleToULong(Handle) >> 2;
PCONSOLE_IO_HANDLE Entry;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
ASSERT(ProcessData->HandleTable);
@ -1043,51 +1000,25 @@ CSR_API(SrvSetHandleInformation)
Quit:
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepCloseHandle */
CSR_API(SrvCloseHandle)
CON_API(SrvCloseHandle,
CONSOLE_CLOSEHANDLE, CloseHandleRequest)
{
NTSTATUS Status;
PCONSOLE_CLOSEHANDLE CloseHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.CloseHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
Status = ConSrvRemoveObject(ProcessData, CloseHandleRequest->Handle);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return ConSrvRemoveObject(ProcessData, CloseHandleRequest->Handle);
}
/* API_NUMBER: ConsolepVerifyIoHandle */
CSR_API(SrvVerifyConsoleIoHandle)
CON_API(SrvVerifyConsoleIoHandle,
CONSOLE_VERIFYHANDLE, VerifyHandleRequest)
{
NTSTATUS Status;
PCONSOLE_VERIFYHANDLE VerifyHandleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.VerifyHandleRequest;
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
PCONSRV_CONSOLE Console;
HANDLE IoHandle = VerifyHandleRequest->Handle;
ULONG Index = HandleToULong(IoHandle) >> 2;
VerifyHandleRequest->IsValid = FALSE;
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
RtlEnterCriticalSection(&ProcessData->HandleTableLock);
// ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
@ -1106,7 +1037,6 @@ CSR_API(SrvVerifyConsoleIoHandle)
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}

View file

@ -423,16 +423,13 @@ HistoryReshapeAllBuffers(
/* PUBLIC SERVER APIS *********************************************************/
/* API_NUMBER: ConsolepGetCommandHistory */
CSR_API(SrvGetConsoleCommandHistory)
CON_API(SrvGetConsoleCommandHistory,
CONSOLE_GETCOMMANDHISTORY, GetCommandHistoryRequest)
{
NTSTATUS Status;
PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryRequest;
PCONSRV_CONSOLE Console;
NTSTATUS Status = STATUS_SUCCESS;
ULONG BytesWritten = 0;
PHISTORY_BUFFER Hist;
DPRINT1("SrvGetConsoleCommandHistory entered\n");
if ( !CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&GetCommandHistoryRequest->History,
GetCommandHistoryRequest->HistoryLength,
@ -445,10 +442,6 @@ CSR_API(SrvGetConsoleCommandHistory)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Hist = HistoryFindBuffer(Console,
GetCommandHistoryRequest->ExeName,
GetCommandHistoryRequest->ExeLength,
@ -508,16 +501,13 @@ CSR_API(SrvGetConsoleCommandHistory)
// GetCommandHistoryRequest->HistoryLength = TargetBuffer - (PBYTE)GetCommandHistoryRequest->History;
GetCommandHistoryRequest->HistoryLength = BytesWritten;
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetCommandHistoryLength */
CSR_API(SrvGetConsoleCommandHistoryLength)
CON_API(SrvGetConsoleCommandHistoryLength,
CONSOLE_GETCOMMANDHISTORYLENGTH, GetCommandHistoryLengthRequest)
{
NTSTATUS Status;
PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLengthRequest;
PCONSRV_CONSOLE Console;
PHISTORY_BUFFER Hist;
ULONG Length = 0;
@ -529,10 +519,6 @@ CSR_API(SrvGetConsoleCommandHistoryLength)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Hist = HistoryFindBuffer(Console,
GetCommandHistoryLengthRequest->ExeName,
GetCommandHistoryLengthRequest->ExeLength,
@ -552,16 +538,13 @@ CSR_API(SrvGetConsoleCommandHistoryLength)
GetCommandHistoryLengthRequest->HistoryLength = Length;
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepExpungeCommandHistory */
CSR_API(SrvExpungeConsoleCommandHistory)
CON_API(SrvExpungeConsoleCommandHistory,
CONSOLE_EXPUNGECOMMANDHISTORY, ExpungeCommandHistoryRequest)
{
NTSTATUS Status;
PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistoryRequest;
PCONSRV_CONSOLE Console;
PHISTORY_BUFFER Hist;
if (!CsrValidateMessageBuffer(ApiMessage,
@ -572,26 +555,20 @@ CSR_API(SrvExpungeConsoleCommandHistory)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Hist = HistoryFindBuffer(Console,
ExpungeCommandHistoryRequest->ExeName,
ExpungeCommandHistoryRequest->ExeLength,
ExpungeCommandHistoryRequest->Unicode2);
HistoryDeleteBuffer(Hist);
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetNumberOfCommands */
CSR_API(SrvSetConsoleNumberOfCommands)
CON_API(SrvSetConsoleNumberOfCommands,
CONSOLE_SETHISTORYNUMBERCOMMANDS, SetHistoryNumberCommandsRequest)
{
NTSTATUS Status;
PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommandsRequest;
PCONSRV_CONSOLE Console;
NTSTATUS Status = STATUS_SUCCESS;
PHISTORY_BUFFER Hist;
if (!CsrValidateMessageBuffer(ApiMessage,
@ -602,10 +579,6 @@ CSR_API(SrvSetConsoleNumberOfCommands)
return STATUS_INVALID_PARAMETER;
}
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Hist = HistoryFindBuffer(Console,
SetHistoryNumberCommandsRequest->ExeName,
SetHistoryNumberCommandsRequest->ExeLength,
@ -615,21 +588,21 @@ CSR_API(SrvSetConsoleNumberOfCommands)
Status = HistoryResizeBuffer(Hist, SetHistoryNumberCommandsRequest->NumCommands);
}
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetHistory */
CSR_API(SrvGetConsoleHistory)
CON_API_NOCONSOLE(SrvGetConsoleHistory,
CONSOLE_GETSETHISTORYINFO, HistoryInfoRequest)
{
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
NTSTATUS Status;
PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetConsole(ProcessData,
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
HistoryInfoRequest->HistoryBufferSize = Console->HistoryBufferSize;
HistoryInfoRequest->NumberOfHistoryBuffers = Console->MaxNumberOfHistoryBuffers;
@ -644,16 +617,17 @@ CSR_API(SrvGetConsoleHistory)
}
/* API_NUMBER: ConsolepSetHistory */
CSR_API(SrvSetConsoleHistory)
CON_API_NOCONSOLE(SrvSetConsoleHistory,
CONSOLE_GETSETHISTORYINFO, HistoryInfoRequest)
{
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
NTSTATUS Status;
PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
Status = ConSrvGetConsole(ProcessData,
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
if (!NT_SUCCESS(Status))
return Status;
HistoryReshapeAllBuffers(Console,
HistoryInfoRequest->HistoryBufferSize,
@ -669,22 +643,13 @@ CSR_API(SrvSetConsoleHistory)
}
/* API_NUMBER: ConsolepSetCommandHistoryMode */
CSR_API(SrvSetConsoleCommandHistoryMode)
CON_API(SrvSetConsoleCommandHistoryMode,
CONSOLE_SETHISTORYMODE, SetHistoryModeRequest)
{
NTSTATUS Status;
PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryModeRequest;
PCONSRV_CONSOLE Console;
DPRINT("SrvSetConsoleCommandHistoryMode(Mode = %d) is not yet implemented\n",
SetHistoryModeRequest->Mode);
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console->InsertMode = !!(SetHistoryModeRequest->Mode & CONSOLE_OVERSTRIKE);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}

View file

@ -20,22 +20,13 @@
*/
/* API_NUMBER: ConsolepRegisterVDM */
CSR_API(SrvRegisterConsoleVDM)
CON_API(SrvRegisterConsoleVDM,
CONSOLE_REGISTERVDM, RegisterVDMRequest)
{
NTSTATUS Status;
PCONSOLE_REGISTERVDM RegisterVDMRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.RegisterVDMRequest;
PCONSRV_CONSOLE Console;
DPRINT1("SrvRegisterConsoleVDM(%d)\n", RegisterVDMRequest->RegisterFlags);
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't get console, status %lx\n", Status);
return Status;
}
if (RegisterVDMRequest->RegisterFlags != 0)
{
LARGE_INTEGER SectionSize;
@ -69,7 +60,7 @@ CSR_API(SrvRegisterConsoleVDM)
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to create a shared section, Status = 0x%08lx\n", Status);
goto Quit;
return Status;
}
/*
@ -91,7 +82,7 @@ CSR_API(SrvRegisterConsoleVDM)
{
DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
NtClose(Console->VDMBufferSection);
goto Quit;
return Status;
}
/*
@ -115,14 +106,14 @@ CSR_API(SrvRegisterConsoleVDM)
DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
NtUnmapViewOfSection(NtCurrentProcess(), Console->VDMBuffer);
NtClose(Console->VDMBufferSection);
goto Quit;
return Status;
}
// TODO: Duplicate the event handles.
RegisterVDMRequest->VDMBuffer = Console->ClientVDMBuffer;
Status = STATUS_SUCCESS;
return STATUS_SUCCESS;
}
else
{
@ -143,11 +134,9 @@ CSR_API(SrvRegisterConsoleVDM)
Console->VDMBuffer = Console->ClientVDMBuffer = NULL;
Console->VDMBufferSize.X = Console->VDMBufferSize.Y = 0;
}
Quit:
ConSrvReleaseConsole(Console, TRUE);
return Status;
return STATUS_SUCCESS;
}
}
/* API_NUMBER: ConsolepVDMOperation */