mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 05:45:50 +00:00
[CONSRV]
Be sure to use our local heap instead of the current application heap, to store the console title. To simplify the code, I introduced helper functions based on well-known Rtl functions. svn path=/trunk/; revision=58925
This commit is contained in:
parent
3b0611bcc9
commit
9c6d52c545
1 changed files with 39 additions and 10 deletions
|
@ -51,6 +51,35 @@ static RTL_RESOURCE ListLock;
|
||||||
#define ConSrvUnlockConsoleList() \
|
#define ConSrvUnlockConsoleList() \
|
||||||
RtlReleaseResource(&ListLock)
|
RtlReleaseResource(&ListLock)
|
||||||
|
|
||||||
|
// Adapted from reactos/lib/rtl/unicode.c, RtlCreateUnicodeString line 2180
|
||||||
|
BOOLEAN
|
||||||
|
ConsoleCreateUnicodeString(IN OUT PUNICODE_STRING UniDest,
|
||||||
|
IN PCWSTR Source)
|
||||||
|
{
|
||||||
|
SIZE_T Size = (wcslen(Source) + 1) * sizeof(WCHAR);
|
||||||
|
if (Size > MAXUSHORT) return FALSE;
|
||||||
|
|
||||||
|
UniDest->Buffer = RtlAllocateHeap(ConSrvHeap, HEAP_ZERO_MEMORY, Size);
|
||||||
|
if (UniDest->Buffer == NULL) return FALSE;
|
||||||
|
|
||||||
|
RtlCopyMemory(UniDest->Buffer, Source, Size);
|
||||||
|
UniDest->MaximumLength = (USHORT)Size;
|
||||||
|
UniDest->Length = (USHORT)Size - sizeof(WCHAR);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adapted from reactos/lib/rtl/unicode.c, RtlFreeUnicodeString line 431
|
||||||
|
VOID
|
||||||
|
ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
|
||||||
|
{
|
||||||
|
if (UnicodeString->Buffer)
|
||||||
|
{
|
||||||
|
RtlFreeHeap(ConSrvHeap, 0, UnicodeString->Buffer);
|
||||||
|
RtlZeroMemory(UnicodeString, sizeof(UNICODE_STRING));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* PRIVATE FUNCTIONS **********************************************************/
|
/* PRIVATE FUNCTIONS **********************************************************/
|
||||||
|
|
||||||
|
@ -612,21 +641,21 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
|
||||||
Console->HistoryNoDup = ConsoleInfo.HistoryNoDup;
|
Console->HistoryNoDup = ConsoleInfo.HistoryNoDup;
|
||||||
|
|
||||||
/* Initialize the console title */
|
/* Initialize the console title */
|
||||||
RtlCreateUnicodeString(&Console->OriginalTitle, ConsoleInfo.ConsoleTitle);
|
ConsoleCreateUnicodeString(&Console->OriginalTitle, ConsoleInfo.ConsoleTitle);
|
||||||
if (ConsoleInfo.ConsoleTitle[0] == L'\0')
|
if (ConsoleInfo.ConsoleTitle[0] == L'\0')
|
||||||
{
|
{
|
||||||
if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, Title, sizeof(Title) / sizeof(Title[0])))
|
if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, Title, sizeof(Title) / sizeof(Title[0])))
|
||||||
{
|
{
|
||||||
RtlCreateUnicodeString(&Console->Title, Title);
|
ConsoleCreateUnicodeString(&Console->Title, Title);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RtlCreateUnicodeString(&Console->Title, L"ReactOS Console");
|
ConsoleCreateUnicodeString(&Console->Title, L"ReactOS Console");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RtlCreateUnicodeString(&Console->Title, ConsoleInfo.ConsoleTitle);
|
ConsoleCreateUnicodeString(&Console->Title, ConsoleInfo.ConsoleTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lock the console until its initialization is finished */
|
/* Lock the console until its initialization is finished */
|
||||||
|
@ -674,8 +703,8 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("GuiInitConsole: failed, Status = 0x%08lx\n", Status);
|
DPRINT1("GuiInitConsole: failed, Status = 0x%08lx\n", Status);
|
||||||
RtlFreeUnicodeString(&Console->Title);
|
ConsoleFreeUnicodeString(&Console->OriginalTitle);
|
||||||
RtlFreeUnicodeString(&Console->OriginalTitle);
|
ConsoleFreeUnicodeString(&Console->Title);
|
||||||
ConioDeleteScreenBuffer(NewBuffer);
|
ConioDeleteScreenBuffer(NewBuffer);
|
||||||
CloseHandle(Console->InputBuffer.ActiveEvent);
|
CloseHandle(Console->InputBuffer.ActiveEvent);
|
||||||
// LeaveCriticalSection(&Console->Lock);
|
// LeaveCriticalSection(&Console->Lock);
|
||||||
|
@ -812,8 +841,8 @@ ConSrvDeleteConsole(PCONSOLE Console)
|
||||||
// CloseHandle(Console->InputBuffer.ActiveEvent);
|
// CloseHandle(Console->InputBuffer.ActiveEvent);
|
||||||
if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
|
if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&Console->OriginalTitle);
|
ConsoleFreeUnicodeString(&Console->OriginalTitle);
|
||||||
RtlFreeUnicodeString(&Console->Title);
|
ConsoleFreeUnicodeString(&Console->Title);
|
||||||
|
|
||||||
DPRINT("ConSrvDeleteConsole - Unlocking\n");
|
DPRINT("ConSrvDeleteConsole - Unlocking\n");
|
||||||
LeaveCriticalSection(&Console->Lock);
|
LeaveCriticalSection(&Console->Lock);
|
||||||
|
@ -1183,11 +1212,11 @@ CSR_API(SrvSetConsoleTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a new buffer to hold the new title (NULL-terminated) */
|
/* Allocate a new buffer to hold the new title (NULL-terminated) */
|
||||||
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, TitleRequest->Length + sizeof(WCHAR));
|
Buffer = RtlAllocateHeap(ConSrvHeap, 0, TitleRequest->Length + sizeof(WCHAR));
|
||||||
if (Buffer)
|
if (Buffer)
|
||||||
{
|
{
|
||||||
/* Free the old title */
|
/* Free the old title */
|
||||||
RtlFreeUnicodeString(&Console->Title);
|
ConsoleFreeUnicodeString(&Console->Title);
|
||||||
|
|
||||||
/* Copy title to console */
|
/* Copy title to console */
|
||||||
Console->Title.Buffer = Buffer;
|
Console->Title.Buffer = Buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue