[FORMATTING] Standardize win32csr to 4-space indents. Based on a patch by Adam Kachwalla [Bug 5380]. No code changes.

svn path=/trunk/; revision=47457
This commit is contained in:
Jeffrey Morlan 2010-05-30 20:00:17 +00:00
parent dfc4dcb9b5
commit d27f068a19
10 changed files with 3838 additions and 3837 deletions

View file

@ -5,7 +5,7 @@
* PURPOSE: CSRSS alias support functions * PURPOSE: CSRSS alias support functions
* COPYRIGHT: Christoph Wittich * COPYRIGHT: Christoph Wittich
* Johannes Anderwald * Johannes Anderwald
* *
*/ */
@ -17,10 +17,10 @@
typedef struct tagALIAS_ENTRY typedef struct tagALIAS_ENTRY
{ {
LPCWSTR lpSource; LPCWSTR lpSource;
LPCWSTR lpTarget; LPCWSTR lpTarget;
struct tagALIAS_ENTRY * Next; struct tagALIAS_ENTRY * Next;
}ALIAS_ENTRY, *PALIAS_ENTRY; } ALIAS_ENTRY, *PALIAS_ENTRY;
typedef struct tagALIAS_HEADER typedef struct tagALIAS_HEADER
@ -29,7 +29,7 @@ typedef struct tagALIAS_HEADER
PALIAS_ENTRY Data; PALIAS_ENTRY Data;
struct tagALIAS_HEADER * Next; struct tagALIAS_HEADER * Next;
}ALIAS_HEADER, *PALIAS_HEADER; } ALIAS_HEADER, *PALIAS_HEADER;
/* Ensure that a buffer is contained within the process's shared memory section. */ /* Ensure that a buffer is contained within the process's shared memory section. */
static BOOL static BOOL
@ -37,10 +37,10 @@ ValidateBuffer(PCSRSS_PROCESS_DATA ProcessData, PVOID Buffer, ULONG Size)
{ {
ULONG Offset = (BYTE *)Buffer - (BYTE *)ProcessData->CsrSectionViewBase; ULONG Offset = (BYTE *)Buffer - (BYTE *)ProcessData->CsrSectionViewBase;
if (Offset >= ProcessData->CsrSectionViewSize if (Offset >= ProcessData->CsrSectionViewSize
|| Size > (ProcessData->CsrSectionViewSize - Offset)) || Size > (ProcessData->CsrSectionViewSize - Offset))
{ {
DPRINT1("Invalid buffer %p %d; not within %p %d\n", DPRINT1("Invalid buffer %p %d; not within %p %d\n",
Buffer, Size, ProcessData->CsrSectionViewBase, ProcessData->CsrSectionViewSize); Buffer, Size, ProcessData->CsrSectionViewBase, ProcessData->CsrSectionViewSize);
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -67,38 +67,38 @@ IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName)
PALIAS_HEADER PALIAS_HEADER
IntCreateAliasHeader(LPCWSTR lpExeName) IntCreateAliasHeader(LPCWSTR lpExeName)
{ {
PALIAS_HEADER Entry; PALIAS_HEADER Entry;
UINT dwLength = wcslen(lpExeName) + 1; UINT dwLength = wcslen(lpExeName) + 1;
Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength); Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength);
if (!Entry) if (!Entry)
return Entry; return Entry;
Entry->lpExeName = (LPCWSTR)(Entry + 1); Entry->lpExeName = (LPCWSTR)(Entry + 1);
wcscpy((WCHAR*)Entry->lpExeName, lpExeName); wcscpy((WCHAR*)Entry->lpExeName, lpExeName);
Entry->Data = NULL; Entry->Data = NULL;
Entry->Next = NULL; Entry->Next = NULL;
return Entry; return Entry;
} }
VOID VOID
IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader) IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader)
{ {
PALIAS_HEADER CurrentHeader; PALIAS_HEADER CurrentHeader;
PALIAS_HEADER *LastLink = RootHeader; PALIAS_HEADER *LastLink = RootHeader;
while ((CurrentHeader = *LastLink) != NULL) while ((CurrentHeader = *LastLink) != NULL)
{ {
INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName); INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName);
if (Diff < 0) if (Diff < 0)
{ {
break; break;
} }
LastLink = &CurrentHeader->Next; LastLink = &CurrentHeader->Next;
} }
*LastLink = NewHeader; *LastLink = NewHeader;
NewHeader->Next = CurrentHeader; NewHeader->Next = CurrentHeader;
} }
PALIAS_ENTRY PALIAS_ENTRY
@ -130,60 +130,60 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
VOID VOID
IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry) IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
{ {
PALIAS_ENTRY CurrentEntry; PALIAS_ENTRY CurrentEntry;
PALIAS_ENTRY *LastLink = &Header->Data; PALIAS_ENTRY *LastLink = &Header->Data;
while ((CurrentEntry = *LastLink) != NULL) while ((CurrentEntry = *LastLink) != NULL)
{
INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource);
if (Diff < 0)
{ {
break; INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource);
if (Diff < 0)
{
break;
}
LastLink = &CurrentEntry->Next;
} }
LastLink = &CurrentEntry->Next;
}
*LastLink = NewEntry; *LastLink = NewEntry;
NewEntry->Next = CurrentEntry; NewEntry->Next = CurrentEntry;
} }
PALIAS_ENTRY PALIAS_ENTRY
IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget) IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget)
{ {
UINT dwSource; UINT dwSource;
UINT dwTarget; UINT dwTarget;
PALIAS_ENTRY Entry; PALIAS_ENTRY Entry;
dwSource = wcslen(lpSource) + 1; dwSource = wcslen(lpSource) + 1;
dwTarget = wcslen(lpTarget) + 1; dwTarget = wcslen(lpTarget) + 1;
Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget)); Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget));
if (!Entry) if (!Entry)
return Entry; return Entry;
Entry->lpSource = (LPCWSTR)(Entry + 1); Entry->lpSource = (LPCWSTR)(Entry + 1);
wcscpy((LPWSTR)Entry->lpSource, lpSource); wcscpy((LPWSTR)Entry->lpSource, lpSource);
Entry->lpTarget = Entry->lpSource + dwSource; Entry->lpTarget = Entry->lpSource + dwSource;
wcscpy((LPWSTR)Entry->lpTarget, lpTarget); wcscpy((LPWSTR)Entry->lpTarget, lpTarget);
Entry->Next = NULL; Entry->Next = NULL;
return Entry; return Entry;
} }
UINT UINT
IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader) IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader)
{ {
UINT length = 0; UINT length = 0;
while(RootHeader) while(RootHeader)
{ {
length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR); length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR);
RootHeader = RootHeader->Next; RootHeader = RootHeader->Next;
} }
if (length) if (length)
length += sizeof(WCHAR); // last entry entry is terminated with 2 zero bytes length += sizeof(WCHAR); // last entry entry is terminated with 2 zero bytes
return length; return length;
} }
UINT UINT
@ -215,22 +215,22 @@ IntGetConsoleAliasesExes(PALIAS_HEADER RootHeader, LPWSTR TargetBuffer, UINT Tar
UINT UINT
IntGetAllConsoleAliasesLength(PALIAS_HEADER Header) IntGetAllConsoleAliasesLength(PALIAS_HEADER Header)
{ {
UINT Length = 0; UINT Length = 0;
PALIAS_ENTRY CurEntry = Header->Data; PALIAS_ENTRY CurEntry = Header->Data;
while(CurEntry) while(CurEntry)
{ {
Length += wcslen(CurEntry->lpSource); Length += wcslen(CurEntry->lpSource);
Length += wcslen(CurEntry->lpTarget); Length += wcslen(CurEntry->lpTarget);
Length += 2; // zero byte and '=' Length += 2; // zero byte and '='
CurEntry = CurEntry->Next; CurEntry = CurEntry->Next;
} }
if (Length) if (Length)
{ {
return (Length+1) * sizeof(WCHAR); return (Length+1) * sizeof(WCHAR);
} }
return 0; return 0;
} }
UINT UINT
IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBufferLength) IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBufferLength)
@ -316,7 +316,7 @@ CSR_API(CsrAddConsoleAlias)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
Request->Status = ConioConsoleFromProcessData(ProcessData, &Console); Request->Status = ConioConsoleFromProcessData(ProcessData, &Console);
if (!NT_SUCCESS(Request->Status)) if (!NT_SUCCESS(Request->Status))
{ {
@ -379,11 +379,11 @@ CSR_API(CsrGetConsoleAlias)
lpTarget = Request->Data.GetConsoleAlias.TargetBuffer; lpTarget = Request->Data.GetConsoleAlias.TargetBuffer;
DPRINT("CsrGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p TargetBufferLength %u\n", DPRINT("CsrGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p TargetBufferLength %u\n",
lpExeName, lpSource, lpTarget, Request->Data.GetConsoleAlias.TargetBufferLength); lpExeName, lpSource, lpTarget, Request->Data.GetConsoleAlias.TargetBufferLength);
if (Request->Data.GetConsoleAlias.ExeLength == 0 || lpTarget == NULL || if (Request->Data.GetConsoleAlias.ExeLength == 0 || lpTarget == NULL ||
Request->Data.GetConsoleAlias.TargetBufferLength == 0 || Request->Data.GetConsoleAlias.SourceLength == 0) Request->Data.GetConsoleAlias.TargetBufferLength == 0 || Request->Data.GetConsoleAlias.SourceLength == 0)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
@ -465,7 +465,7 @@ CSR_API(CsrGetAllConsoleAliases)
return STATUS_ACCESS_VIOLATION; return STATUS_ACCESS_VIOLATION;
} }
BytesWritten = IntGetAllConsoleAliases(Header, BytesWritten = IntGetAllConsoleAliases(Header,
Request->Data.GetAllConsoleAlias.AliasBuffer, Request->Data.GetAllConsoleAlias.AliasBuffer,
Request->Data.GetAllConsoleAlias.AliasBufferLength); Request->Data.GetAllConsoleAlias.AliasBufferLength);
@ -509,7 +509,7 @@ CSR_API(CsrGetConsoleAliasesExes)
PCSRSS_CONSOLE Console; PCSRSS_CONSOLE Console;
UINT BytesWritten; UINT BytesWritten;
UINT ExesLength; UINT ExesLength;
DPRINT("CsrGetConsoleAliasesExes entered\n"); DPRINT("CsrGetConsoleAliasesExes entered\n");
Request->Status = ConioConsoleFromProcessData(ProcessData, &Console); Request->Status = ConioConsoleFromProcessData(ProcessData, &Console);
@ -519,7 +519,7 @@ CSR_API(CsrGetConsoleAliasesExes)
} }
ExesLength = IntGetConsoleAliasesExesLength(Console->Aliases); ExesLength = IntGetConsoleAliasesExesLength(Console->Aliases);
if (ExesLength > Request->Data.GetConsoleAliasesExes.Length) if (ExesLength > Request->Data.GetConsoleAliasesExes.Length)
{ {
ConioUnlockConsole(Console); ConioUnlockConsole(Console);
@ -531,7 +531,7 @@ CSR_API(CsrGetConsoleAliasesExes)
ConioUnlockConsole(Console); ConioUnlockConsole(Console);
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
if (!ValidateBuffer(ProcessData, if (!ValidateBuffer(ProcessData,
Request->Data.GetConsoleAliasesExes.ExeNames, Request->Data.GetConsoleAliasesExes.ExeNames,
Request->Data.GetConsoleAliasesExes.Length)) Request->Data.GetConsoleAliasesExes.Length))
@ -540,7 +540,7 @@ CSR_API(CsrGetConsoleAliasesExes)
return STATUS_ACCESS_VIOLATION; return STATUS_ACCESS_VIOLATION;
} }
BytesWritten = IntGetConsoleAliasesExes(Console->Aliases, BytesWritten = IntGetConsoleAliasesExes(Console->Aliases,
Request->Data.GetConsoleAliasesExes.ExeNames, Request->Data.GetConsoleAliasesExes.ExeNames,
Request->Data.GetConsoleAliasesExes.Length); Request->Data.GetConsoleAliasesExes.Length);

View file

@ -19,7 +19,7 @@ typedef struct APPSWITCH_ITEM
BOOL bFocus; BOOL bFocus;
struct APPSWITCH_ITEM * Next; struct APPSWITCH_ITEM * Next;
WCHAR szText[1]; WCHAR szText[1];
}APPSWITCH_ITEM, *PAPPSWITCH_ITEM; } APPSWITCH_ITEM, *PAPPSWITCH_ITEM;
static PAPPSWITCH_ITEM pRoot = NULL; static PAPPSWITCH_ITEM pRoot = NULL;
static DWORD NumOfWindows = 0; static DWORD NumOfWindows = 0;
@ -30,7 +30,7 @@ UINT WINAPI PrivateExtractIconExW(LPCWSTR,int,HICON*,HICON*,UINT);
BOOL BOOL
CALLBACK CALLBACK
EnumWindowEnumProc( EnumWindowEnumProc(
HWND hwnd, HWND hwnd,
LPARAM lParam LPARAM lParam
@ -51,21 +51,21 @@ EnumWindowEnumProc(
hIcon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_BIG, 0); hIcon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_BIG, 0);
if (!hIcon) if (!hIcon)
{ {
GetWindowThreadProcessId(hwnd, &dwPid); GetWindowThreadProcessId(hwnd, &dwPid);
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwPid); hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwPid);
if (hProcess) if (hProcess)
{ {
if (GetModuleFileNameExW(hProcess, NULL, szFileName, MAX_PATH)) if (GetModuleFileNameExW(hProcess, NULL, szFileName, MAX_PATH))
{ {
szFileName[MAX_PATH-1] = L'\0'; szFileName[MAX_PATH-1] = L'\0';
PrivateExtractIconExW(szFileName, 0, &hIcon, NULL, 1); PrivateExtractIconExW(szFileName, 0, &hIcon, NULL, 1);
} }
} }
} }
else else
{ {
/* icons from WM_GETICON need to be copied */ /* icons from WM_GETICON need to be copied */
hIcon = CopyIcon(hIcon); hIcon = CopyIcon(hIcon);
} }
/* get the text length */ /* get the text length */
Length = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); Length = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
@ -88,9 +88,9 @@ EnumWindowEnumProc(
if (!pRoot) if (!pRoot)
{ {
/* first item */ /* first item */
pRoot = pItem; pRoot = pItem;
return TRUE; return TRUE;
} }
/* enumerate the last item */ /* enumerate the last item */
@ -107,16 +107,16 @@ EnumWindowEnumProc(
VOID VOID
EnumerateAppWindows(HDESK hDesk, HWND hwndDlg) EnumerateAppWindows(HDESK hDesk, HWND hwndDlg)
{ {
/* initialize defaults */ /* initialize defaults */
pRoot = NULL; pRoot = NULL;
NumOfWindows = 0; NumOfWindows = 0;
hAppWindowDlg = hwndDlg; hAppWindowDlg = hwndDlg;
/* enumerate all windows */ /* enumerate all windows */
EnumDesktopWindows(hDesk, EnumWindowEnumProc, (LPARAM)NULL); EnumDesktopWindows(hDesk, EnumWindowEnumProc, (LPARAM)NULL);
if (NumOfWindows > 7) if (NumOfWindows > 7)
{ {
/* FIXME resize window */ /* FIXME resize window */
} }
} }
VOID VOID
@ -126,7 +126,7 @@ MarkNextEntryAsActive()
pItem = pRoot; pItem = pRoot;
if (!pRoot) if (!pRoot)
return; return;
while(pItem) while(pItem)
{ {
@ -153,82 +153,82 @@ KeyboardHookProc(
LPARAM lParam LPARAM lParam
) )
{ {
PKBDLLHOOKSTRUCT hk = (PKBDLLHOOKSTRUCT) lParam; PKBDLLHOOKSTRUCT hk = (PKBDLLHOOKSTRUCT) lParam;
if (wParam == WM_SYSKEYUP) if (wParam == WM_SYSKEYUP)
{ {
/* is tab key pressed */ /* is tab key pressed */
if (hk->vkCode == VK_TAB) if (hk->vkCode == VK_TAB)
{ {
if (hAppWindowDlg == NULL) if (hAppWindowDlg == NULL)
{ {
/* FIXME /* FIXME
* launch window * launch window
*/ */
DPRINT1("launch alt-tab window\n"); DPRINT1("launch alt-tab window\n");
} }
else else
{ {
MarkNextEntryAsActive(); MarkNextEntryAsActive();
} }
} }
} }
return CallNextHookEx(hhk, nCode, wParam, lParam); return CallNextHookEx(hhk, nCode, wParam, lParam);
} }
VOID VOID
PaintAppWindows(HWND hwndDlg, HDC hDc) PaintAppWindows(HWND hwndDlg, HDC hDc)
{ {
DWORD dwIndex, X, Y; DWORD dwIndex, X, Y;
PAPPSWITCH_ITEM pCurItem; PAPPSWITCH_ITEM pCurItem;
RECT Rect; RECT Rect;
DWORD XSize, YSize, XMax; DWORD XSize, YSize, XMax;
HBRUSH hBrush; HBRUSH hBrush;
X = 10; X = 10;
Y = 10; Y = 10;
XSize = GetSystemMetrics(SM_CXICON); XSize = GetSystemMetrics(SM_CXICON);
YSize = GetSystemMetrics(SM_CYICON); YSize = GetSystemMetrics(SM_CYICON);
XMax = (XSize+(XSize/2)) * 7 + X; XMax = (XSize+(XSize/2)) * 7 + X;
pCurItem = pRoot; pCurItem = pRoot;
for (dwIndex = 0; dwIndex < NumOfWindows; dwIndex++) for (dwIndex = 0; dwIndex < NumOfWindows; dwIndex++)
{ {
if (X >= XMax) if (X >= XMax)
{ {
X = 10; X = 10;
Y += YSize + (YSize/2); Y += YSize + (YSize/2);
} }
if (pCurItem->bFocus) if (pCurItem->bFocus)
{ {
hBrush = CreateSolidBrush(RGB(30, 30, 255)); hBrush = CreateSolidBrush(RGB(30, 30, 255));
SetRect(&Rect, X-5, Y-5, X + XSize + 5, Y + YSize + 5); SetRect(&Rect, X-5, Y-5, X + XSize + 5, Y + YSize + 5);
FillRect(hDc, &Rect, hBrush); FillRect(hDc, &Rect, hBrush);
DeleteObject((HGDIOBJ)hBrush); DeleteObject((HGDIOBJ)hBrush);
SendDlgItemMessageW(hwndDlg, IDC_STATIC_CUR_APP, WM_SETTEXT, 0, (LPARAM)pCurItem->szText); SendDlgItemMessageW(hwndDlg, IDC_STATIC_CUR_APP, WM_SETTEXT, 0, (LPARAM)pCurItem->szText);
} }
DrawIcon(hDc, X, Y, pCurItem->hIcon); DrawIcon(hDc, X, Y, pCurItem->hIcon);
pCurItem = pCurItem->Next; pCurItem = pCurItem->Next;
X += XSize +(XSize/2); X += XSize +(XSize/2);
} }
} }
VOID VOID
DestroyAppWindows() DestroyAppWindows()
{ {
PAPPSWITCH_ITEM pCurItem, pNextItem; PAPPSWITCH_ITEM pCurItem, pNextItem;
pCurItem = pRoot; pCurItem = pRoot;
while(pCurItem) while(pCurItem)
{ {
pNextItem = pCurItem->Next; pNextItem = pCurItem->Next;
DestroyIcon(pCurItem->hIcon); DestroyIcon(pCurItem->hIcon);
HeapFree(Win32CsrApiHeap, 0, pCurItem); HeapFree(Win32CsrApiHeap, 0, pCurItem);
pCurItem = pNextItem; pCurItem = pNextItem;
} }
pRoot = NULL; pRoot = NULL;
hAppWindowDlg = NULL; hAppWindowDlg = NULL;
NumOfWindows = 0; NumOfWindows = 0;
} }
INT_PTR INT_PTR

File diff suppressed because it is too large Load diff

View file

@ -49,71 +49,71 @@ DtbgWindowProc(HWND Wnd,
switch (Msg) switch (Msg)
{ {
case WM_ERASEBKGND: case WM_ERASEBKGND:
PaintDesktop((HDC)wParam); PaintDesktop((HDC)wParam);
return 1; return 1;
case WM_PAINT: case WM_PAINT:
if (BeginPaint(Wnd, &PS)) if (BeginPaint(Wnd, &PS))
EndPaint(Wnd, &PS); EndPaint(Wnd, &PS);
return 0; return 0;
case WM_SETCURSOR: case WM_SETCURSOR:
return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW)); return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
case WM_NCCREATE: case WM_NCCREATE:
return (LRESULT)TRUE; return (LRESULT)TRUE;
case WM_CREATE: case WM_CREATE:
case WM_CLOSE: case WM_CLOSE:
return 0; return 0;
case WM_NOTIFY: case WM_NOTIFY:
{
PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam;
/* Use WM_NOTIFY for private messages since
* it can't be sent between processes!
*/
switch (nmh->hdr.code)
{ {
PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam; case PM_SHOW_DESKTOP:
{
LRESULT Result;
/* Use WM_NOTIFY for private messages since Result = !SetWindowPos(Wnd, NULL, 0, 0,
* it can't be sent between processes! nmh->ShowDesktop.Width,
*/ nmh->ShowDesktop.Height,
switch (nmh->hdr.code) SWP_NOACTIVATE | SWP_NOZORDER |
{ SWP_SHOWWINDOW);
case PM_SHOW_DESKTOP:
{
LRESULT Result;
Result = !SetWindowPos(Wnd, NULL, 0, 0, UpdateWindow(Wnd);
nmh->ShowDesktop.Width, VisibleDesktopWindow = Wnd;
nmh->ShowDesktop.Height, return Result;
SWP_NOACTIVATE | SWP_NOZORDER | }
SWP_SHOWWINDOW);
UpdateWindow(Wnd); case PM_HIDE_DESKTOP:
VisibleDesktopWindow = Wnd; {
return Result; LRESULT Result;
}
case PM_HIDE_DESKTOP: Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0,
{ SWP_NOACTIVATE | SWP_NOZORDER |
LRESULT Result; SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0, UpdateWindow(Wnd);
SWP_NOACTIVATE | SWP_NOZORDER | VisibleDesktopWindow = NULL;
SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); return Result;
UpdateWindow(Wnd);
VisibleDesktopWindow = NULL;
return Result;
}
default:
DPRINT("Unknown notification code 0x%x sent to the desktop window!\n",
nmh->hdr.code);
return 0;
}
} }
default: default:
return DefWindowProcW(Wnd, Msg, wParam, lParam); DPRINT("Unknown notification code 0x%x sent to the desktop window!\n",
nmh->hdr.code);
return 0;
}
}
default:
return DefWindowProcW(Wnd, Msg, wParam, lParam);
} }
return 0; return 0;
@ -309,7 +309,7 @@ FASTCALL
DtbgIsDesktopVisible(VOID) DtbgIsDesktopVisible(VOID)
{ {
if (VisibleDesktopWindow != NULL && if (VisibleDesktopWindow != NULL &&
!IsWindowVisible(VisibleDesktopWindow)) !IsWindowVisible(VisibleDesktopWindow))
{ {
VisibleDesktopWindow = NULL; VisibleDesktopWindow = NULL;
} }

View file

@ -23,7 +23,7 @@ HINSTANCE Win32CsrDllHandle = NULL;
static CSRSS_EXPORTED_FUNCS CsrExports; static CSRSS_EXPORTED_FUNCS CsrExports;
static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
{ {
CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetHandle), CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetHandle),
CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetHandle), CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetHandle),
CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle), CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle),
@ -83,37 +83,37 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
CSRSS_DEFINE_API(SET_SCREEN_BUFFER_SIZE, CsrSetScreenBufferSize), CSRSS_DEFINE_API(SET_SCREEN_BUFFER_SIZE, CsrSetScreenBufferSize),
CSRSS_DEFINE_API(GET_CONSOLE_SELECTION_INFO, CsrGetConsoleSelectionInfo), CSRSS_DEFINE_API(GET_CONSOLE_SELECTION_INFO, CsrGetConsoleSelectionInfo),
{ 0, 0, NULL } { 0, 0, NULL }
}; };
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
BOOL WINAPI BOOL WINAPI
DllMain(HANDLE hDll, DllMain(HANDLE hDll,
DWORD dwReason, DWORD dwReason,
LPVOID lpReserved) LPVOID lpReserved)
{ {
if (DLL_PROCESS_ATTACH == dwReason) if (DLL_PROCESS_ATTACH == dwReason)
{ {
Win32CsrDllHandle = hDll; Win32CsrDllHandle = hDll;
InitializeAppSwitchHook(); InitializeAppSwitchHook();
} }
return TRUE; return TRUE;
} }
NTSTATUS FASTCALL NTSTATUS FASTCALL
Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc, Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
PVOID Context) PVOID Context)
{ {
return (CsrExports.CsrEnumProcessesProc)(EnumProc, Context); return (CsrExports.CsrEnumProcessesProc)(EnumProc, Context);
} }
static BOOL WINAPI static BOOL WINAPI
Win32CsrInitComplete(void) Win32CsrInitComplete(void)
{ {
PrivateCsrssInitialized(); PrivateCsrssInitialized();
return TRUE; return TRUE;
} }
BOOL WINAPI BOOL WINAPI
@ -122,22 +122,22 @@ Win32CsrInitialization(PCSRSS_API_DEFINITION *ApiDefinitions,
PCSRSS_EXPORTED_FUNCS Exports, PCSRSS_EXPORTED_FUNCS Exports,
HANDLE CsrssApiHeap) HANDLE CsrssApiHeap)
{ {
NTSTATUS Status; NTSTATUS Status;
CsrExports = *Exports; CsrExports = *Exports;
Win32CsrApiHeap = CsrssApiHeap; Win32CsrApiHeap = CsrssApiHeap;
Status = NtUserInitialize(0 ,NULL, NULL); Status = NtUserInitialize(0, NULL, NULL);
PrivateCsrssManualGuiCheck(0); PrivateCsrssManualGuiCheck(0);
CsrInitConsoleSupport(); CsrInitConsoleSupport();
*ApiDefinitions = Win32CsrApiDefinitions; *ApiDefinitions = Win32CsrApiDefinitions;
ServerProcs->InitCompleteProc = Win32CsrInitComplete; ServerProcs->InitCompleteProc = Win32CsrInitComplete;
ServerProcs->HardErrorProc = Win32CsrHardError; ServerProcs->HardErrorProc = Win32CsrHardError;
ServerProcs->ProcessInheritProc = Win32CsrDuplicateHandleTable; ServerProcs->ProcessInheritProc = Win32CsrDuplicateHandleTable;
ServerProcs->ProcessDeletedProc = Win32CsrReleaseConsole; ServerProcs->ProcessDeletedProc = Win32CsrReleaseConsole;
return TRUE; return TRUE;
} }
/* EOF */ /* EOF */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -101,7 +101,7 @@ Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData,
{ {
ULONG_PTR h = (ULONG_PTR)Handle >> 2; ULONG_PTR h = (ULONG_PTR)Handle >> 2;
DPRINT("CsrGetObject, Object: %x, %x, %x\n", DPRINT("CsrGetObject, Object: %x, %x, %x\n",
Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0); Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0);
RtlEnterCriticalSection(&ProcessData->HandleTableLock); RtlEnterCriticalSection(&ProcessData->HandleTableLock);
@ -271,7 +271,7 @@ CSR_API(CsrGetHandle)
PCSRSS_CONSOLE Console = ProcessData->Console; PCSRSS_CONSOLE Console = ProcessData->Console;
Object_t *Object; Object_t *Object;
EnterCriticalSection(&Console->Lock); EnterCriticalSection(&Console->Lock);
if (Request->Type == GET_OUTPUT_HANDLE) if (Request->Type == GET_OUTPUT_HANDLE)
Object = &Console->ActiveBuffer->Header; Object = &Console->ActiveBuffer->Header;
@ -366,7 +366,7 @@ CSR_API(CsrDuplicateHandle)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
} }
Request->Status = Win32CsrInsertObject(ProcessData, Request->Status = Win32CsrInsertObject(ProcessData,
&Request->Data.DuplicateHandleRequest.Handle, &Request->Data.DuplicateHandleRequest.Handle,
Entry->Object, Entry->Object,

View file

@ -84,8 +84,8 @@ CsrpGetClientFileName(
ClientFileNameU->MaximumLength = ModuleData.BaseDllName.MaximumLength; ClientFileNameU->MaximumLength = ModuleData.BaseDllName.MaximumLength;
ClientFileNameU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), ClientFileNameU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
ClientFileNameU->MaximumLength); ClientFileNameU->MaximumLength);
Status = NtReadVirtualMemory(hProcess, Status = NtReadVirtualMemory(hProcess,
ModuleData.BaseDllName.Buffer, ModuleData.BaseDllName.Buffer,
@ -123,9 +123,9 @@ CsrpCaptureStringParameters(
UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
/* Read all strings from client space */ /* Read all strings from client space */
for (nParam = 0; for (nParam = 0;
nParam < HardErrorMessage->NumberOfParameters; nParam < HardErrorMessage->NumberOfParameters;
nParam++, UnicodeStringParameterMask >>= 1) nParam++, UnicodeStringParameterMask >>= 1)
{ {
Parameters[nParam] = 0; Parameters[nParam] = 0;
@ -194,9 +194,9 @@ CsrpFreeStringParameters(
UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
/* Loop all parameters */ /* Loop all parameters */
for (nParam = 0; for (nParam = 0;
nParam < HardErrorMessage->NumberOfParameters; nParam < HardErrorMessage->NumberOfParameters;
nParam++, UnicodeStringParameterMask >>= 1) nParam++, UnicodeStringParameterMask >>= 1)
{ {
/* Check if the current parameter is a string */ /* Check if the current parameter is a string */
if (UnicodeStringParameterMask & 0x01) if (UnicodeStringParameterMask & 0x01)
@ -292,8 +292,8 @@ CsrpFormatMessages(
/* Allocate a buffer for the caption */ /* Allocate a buffer for the caption */
CaptionStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), CaptionStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
CaptionStringU->MaximumLength); CaptionStringU->MaximumLength);
/* Append the file name, seperator and the caption text */ /* Append the file name, seperator and the caption text */
CaptionStringU->Length = 0; CaptionStringU->Length = 0;
@ -383,13 +383,13 @@ CsrpFormatMessages(
{ {
/* Print the string into the buffer */ /* Print the string into the buffer */
StringCbPrintfW(TextStringU->Buffer, StringCbPrintfW(TextStringU->Buffer,
TextStringU->MaximumLength, TextStringU->MaximumLength,
FormatString, FormatString,
Parameters[0], Parameters[0],
Parameters[1], Parameters[1],
Parameters[2], Parameters[2],
Parameters[3], Parameters[3],
Parameters[4]); Parameters[4]);
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
@ -424,30 +424,30 @@ CsrpMessageBox(
/* Set the message box type */ /* Set the message box type */
switch (ValidResponseOptions) switch (ValidResponseOptions)
{ {
case OptionAbortRetryIgnore: case OptionAbortRetryIgnore:
Type = MB_ABORTRETRYIGNORE; Type = MB_ABORTRETRYIGNORE;
break; break;
case OptionOk: case OptionOk:
Type = MB_OK; Type = MB_OK;
break; break;
case OptionOkCancel: case OptionOkCancel:
Type = MB_OKCANCEL; Type = MB_OKCANCEL;
break; break;
case OptionRetryCancel: case OptionRetryCancel:
Type = MB_RETRYCANCEL; Type = MB_RETRYCANCEL;
break; break;
case OptionYesNo: case OptionYesNo:
Type = MB_YESNO; Type = MB_YESNO;
break; break;
case OptionYesNoCancel: case OptionYesNoCancel:
Type = MB_YESNOCANCEL; Type = MB_YESNOCANCEL;
break; break;
case OptionShutdownSystem: case OptionShutdownSystem:
Type = MB_RETRYCANCEL; // FIXME??? Type = MB_RETRYCANCEL; // FIXME???
break; break;
/* Anything else is invalid */ /* Anything else is invalid */
default: default:
return ResponseNotHandled; return ResponseNotHandled;
} }
/* Set severity */ /* Set severity */
@ -457,7 +457,7 @@ CsrpMessageBox(
Type |= MB_SYSTEMMODAL | MB_SETFOREGROUND; Type |= MB_SYSTEMMODAL | MB_SETFOREGROUND;
DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n", DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n",
Text, Caption, Severity, Type); Text, Caption, Severity, Type);
/* Display a message box */ /* Display a message box */
@ -466,15 +466,15 @@ CsrpMessageBox(
/* Return response value */ /* Return response value */
switch (MessageBoxResponse) switch (MessageBoxResponse)
{ {
case IDOK: return ResponseOk; case IDOK: return ResponseOk;
case IDCANCEL: return ResponseCancel; case IDCANCEL: return ResponseCancel;
case IDYES: return ResponseYes; case IDYES: return ResponseYes;
case IDNO: return ResponseNo; case IDNO: return ResponseNo;
case IDABORT: return ResponseAbort; case IDABORT: return ResponseAbort;
case IDIGNORE: return ResponseIgnore; case IDIGNORE: return ResponseIgnore;
case IDRETRY: return ResponseRetry; case IDRETRY: return ResponseRetry;
case IDTRYAGAIN: return ResponseTryAgain; case IDTRYAGAIN: return ResponseTryAgain;
case IDCONTINUE: return ResponseContinue; case IDCONTINUE: return ResponseContinue;
} }
return ResponseNotHandled; return ResponseNotHandled;
@ -537,7 +537,7 @@ Win32CsrHardError(
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return FALSE; return FALSE;
} }
/* Display the message box */ /* Display the message box */

View file

@ -20,15 +20,15 @@ static BOOL ConsInitialized = FALSE;
static LRESULT CALLBACK static LRESULT CALLBACK
TuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) TuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if (msg == WM_ACTIVATE) if (msg == WM_ACTIVATE)
{ {
if (LOWORD(wParam) != WA_INACTIVE) if (LOWORD(wParam) != WA_INACTIVE)
{ {
SetFocus(hWnd); SetFocus(hWnd);
ConioDrawConsole(ActiveConsole); ConioDrawConsole(ActiveConsole);
} }
} }
return DefWindowProcW(hWnd, msg, wParam, lParam); return DefWindowProcW(hWnd, msg, wParam, lParam);
} }
static BOOL FASTCALL static BOOL FASTCALL
@ -63,19 +63,19 @@ cleanup:
static BOOL FASTCALL static BOOL FASTCALL
TuiInit(DWORD OemCP) TuiInit(DWORD OemCP)
{ {
CONSOLE_SCREEN_BUFFER_INFO ScrInfo; CONSOLE_SCREEN_BUFFER_INFO ScrInfo;
DWORD BytesReturned; DWORD BytesReturned;
WNDCLASSEXW wc; WNDCLASSEXW wc;
USHORT TextAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; USHORT TextAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
TuiStartService(L"Blue"); TuiStartService(L"Blue");
ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0, NULL, ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0, NULL,
OPEN_EXISTING, 0, NULL); OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == ConsoleDeviceHandle) if (INVALID_HANDLE_VALUE == ConsoleDeviceHandle)
{ {
DPRINT1("Failed to open BlueScreen.\n"); DPRINT1("Failed to open BlueScreen.\n");
return FALSE; return FALSE;
} }
if (!DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_LOADFONT, if (!DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_LOADFONT,
@ -93,163 +93,163 @@ TuiInit(DWORD OemCP)
DPRINT1("Failed to set text attribute\n"); DPRINT1("Failed to set text attribute\n");
} }
ActiveConsole = NULL; ActiveConsole = NULL;
InitializeCriticalSection(&ActiveConsoleLock); InitializeCriticalSection(&ActiveConsoleLock);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO, if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO,
NULL, 0, &ScrInfo, sizeof(ScrInfo), &BytesReturned, NULL)) NULL, 0, &ScrInfo, sizeof(ScrInfo), &BytesReturned, NULL))
{ {
DPRINT1("Failed to get console info\n"); DPRINT1("Failed to get console info\n");
return FALSE; return FALSE;
} }
PhysicalConsoleSize = ScrInfo.dwSize; PhysicalConsoleSize = ScrInfo.dwSize;
RtlZeroMemory(&wc, sizeof(WNDCLASSEXW)); RtlZeroMemory(&wc, sizeof(WNDCLASSEXW));
wc.cbSize = sizeof(WNDCLASSEXW); wc.cbSize = sizeof(WNDCLASSEXW);
wc.lpszClassName = L"TuiConsoleWindowClass"; wc.lpszClassName = L"TuiConsoleWindowClass";
wc.lpfnWndProc = TuiConsoleWndProc; wc.lpfnWndProc = TuiConsoleWndProc;
wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL);
if (RegisterClassExW(&wc) == 0) if (RegisterClassExW(&wc) == 0)
{ {
DPRINT1("Failed to register console wndproc\n"); DPRINT1("Failed to register console wndproc\n");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static VOID WINAPI static VOID WINAPI
TuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer) TuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer)
{ {
Buffer->DefaultAttrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; Buffer->DefaultAttrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
} }
static void FASTCALL static void FASTCALL
TuiCopyRect(char *Dest, PCSRSS_SCREEN_BUFFER Buff, SMALL_RECT *Region) TuiCopyRect(char *Dest, PCSRSS_SCREEN_BUFFER Buff, SMALL_RECT *Region)
{ {
UINT SrcDelta, DestDelta; UINT SrcDelta, DestDelta;
LONG i; LONG i;
PBYTE Src, SrcEnd; PBYTE Src, SrcEnd;
Src = ConioCoordToPointer(Buff, Region->Left, Region->Top); Src = ConioCoordToPointer(Buff, Region->Left, Region->Top);
SrcDelta = Buff->MaxX * 2; SrcDelta = Buff->MaxX * 2;
SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2; SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2;
DestDelta = ConioRectWidth(Region) * 2; DestDelta = ConioRectWidth(Region) * 2;
for (i = Region->Top; i <= Region->Bottom; i++) for (i = Region->Top; i <= Region->Bottom; i++)
{ {
memcpy(Dest, Src, DestDelta); memcpy(Dest, Src, DestDelta);
Src += SrcDelta; Src += SrcDelta;
if (SrcEnd <= Src) if (SrcEnd <= Src)
{ {
Src -= Buff->MaxY * Buff->MaxX * 2; Src -= Buff->MaxY * Buff->MaxX * 2;
} }
Dest += DestDelta; Dest += DestDelta;
} }
} }
static VOID WINAPI static VOID WINAPI
TuiDrawRegion(PCSRSS_CONSOLE Console, SMALL_RECT *Region) TuiDrawRegion(PCSRSS_CONSOLE Console, SMALL_RECT *Region)
{ {
DWORD BytesReturned; DWORD BytesReturned;
PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer;
PCONSOLE_DRAW ConsoleDraw; PCONSOLE_DRAW ConsoleDraw;
UINT ConsoleDrawSize; UINT ConsoleDrawSize;
if (ActiveConsole != Console) if (ActiveConsole != Console)
{ {
return; return;
} }
ConsoleDrawSize = sizeof(CONSOLE_DRAW) + ConsoleDrawSize = sizeof(CONSOLE_DRAW) +
(ConioRectWidth(Region) * ConioRectHeight(Region)) * 2; (ConioRectWidth(Region) * ConioRectHeight(Region)) * 2;
ConsoleDraw = HeapAlloc(Win32CsrApiHeap, 0, ConsoleDrawSize); ConsoleDraw = HeapAlloc(Win32CsrApiHeap, 0, ConsoleDrawSize);
if (NULL == ConsoleDraw) if (NULL == ConsoleDraw)
{ {
DPRINT1("HeapAlloc failed\n"); DPRINT1("HeapAlloc failed\n");
return; return;
} }
ConsoleDraw->X = Region->Left; ConsoleDraw->X = Region->Left;
ConsoleDraw->Y = Region->Top; ConsoleDraw->Y = Region->Top;
ConsoleDraw->SizeX = ConioRectWidth(Region); ConsoleDraw->SizeX = ConioRectWidth(Region);
ConsoleDraw->SizeY = ConioRectHeight(Region); ConsoleDraw->SizeY = ConioRectHeight(Region);
ConsoleDraw->CursorX = Buff->CurrentX; ConsoleDraw->CursorX = Buff->CurrentX;
ConsoleDraw->CursorY = Buff->CurrentY; ConsoleDraw->CursorY = Buff->CurrentY;
TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region); TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_DRAW, if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_DRAW,
NULL, 0, ConsoleDraw, ConsoleDrawSize, &BytesReturned, NULL)) NULL, 0, ConsoleDraw, ConsoleDrawSize, &BytesReturned, NULL))
{ {
DPRINT1("Failed to draw console\n"); DPRINT1("Failed to draw console\n");
HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); HeapFree(Win32CsrApiHeap, 0, ConsoleDraw);
return; return;
} }
HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); HeapFree(Win32CsrApiHeap, 0, ConsoleDraw);
} }
static VOID WINAPI static VOID WINAPI
TuiWriteStream(PCSRSS_CONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG CursorStartY, TuiWriteStream(PCSRSS_CONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length) UINT ScrolledLines, CHAR *Buffer, UINT Length)
{ {
DWORD BytesWritten; DWORD BytesWritten;
PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer;
if (ActiveConsole->ActiveBuffer != Buff) if (ActiveConsole->ActiveBuffer != Buff)
{ {
return; return;
} }
if (! WriteFile(ConsoleDeviceHandle, Buffer, Length, &BytesWritten, NULL)) if (! WriteFile(ConsoleDeviceHandle, Buffer, Length, &BytesWritten, NULL))
{ {
DPRINT1("Error writing to BlueScreen\n"); DPRINT1("Error writing to BlueScreen\n");
} }
} }
static BOOL WINAPI static BOOL WINAPI
TuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff) TuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff)
{ {
DWORD BytesReturned; DWORD BytesReturned;
if (ActiveConsole->ActiveBuffer != Buff) if (ActiveConsole->ActiveBuffer != Buff)
{ {
return TRUE; return TRUE;
} }
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_CURSOR_INFO, if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_CURSOR_INFO,
&Buff->CursorInfo, sizeof(Buff->CursorInfo), NULL, 0, &Buff->CursorInfo, sizeof(Buff->CursorInfo), NULL, 0,
&BytesReturned, NULL)) &BytesReturned, NULL))
{ {
DPRINT1( "Failed to set cursor info\n" ); DPRINT1( "Failed to set cursor info\n" );
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static BOOL WINAPI static BOOL WINAPI
TuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY) TuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY)
{ {
CONSOLE_SCREEN_BUFFER_INFO Info; CONSOLE_SCREEN_BUFFER_INFO Info;
DWORD BytesReturned; DWORD BytesReturned;
if (ActiveConsole->ActiveBuffer != Buff) if (ActiveConsole->ActiveBuffer != Buff)
{ {
return TRUE; return TRUE;
} }
Info.dwCursorPosition.X = Buff->CurrentX; Info.dwCursorPosition.X = Buff->CurrentX;
Info.dwCursorPosition.Y = Buff->CurrentY; Info.dwCursorPosition.Y = Buff->CurrentY;
Info.wAttributes = Buff->DefaultAttrib; Info.wAttributes = Buff->DefaultAttrib;
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO, if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO,
&Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0, &Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0,
&BytesReturned, NULL)) &BytesReturned, NULL))
{ {
DPRINT1( "Failed to set cursor position\n" ); DPRINT1( "Failed to set cursor position\n" );
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static BOOL WINAPI static BOOL WINAPI
@ -261,32 +261,32 @@ TuiUpdateScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff)
static BOOL WINAPI static BOOL WINAPI
TuiChangeTitle(PCSRSS_CONSOLE Console) TuiChangeTitle(PCSRSS_CONSOLE Console)
{ {
return TRUE; return TRUE;
} }
static VOID WINAPI static VOID WINAPI
TuiCleanupConsole(PCSRSS_CONSOLE Console) TuiCleanupConsole(PCSRSS_CONSOLE Console)
{ {
DestroyWindow(Console->hWindow); DestroyWindow(Console->hWindow);
EnterCriticalSection(&ActiveConsoleLock); EnterCriticalSection(&ActiveConsoleLock);
/* Switch to next console */ /* Switch to next console */
if (ActiveConsole == Console) if (ActiveConsole == Console)
{ {
ActiveConsole = Console->Next != Console ? Console->Next : NULL; ActiveConsole = Console->Next != Console ? Console->Next : NULL;
} }
if (Console->Next != Console) if (Console->Next != Console)
{ {
Console->Prev->Next = Console->Next; Console->Prev->Next = Console->Next;
Console->Next->Prev = Console->Prev; Console->Next->Prev = Console->Prev;
} }
LeaveCriticalSection(&ActiveConsoleLock); LeaveCriticalSection(&ActiveConsoleLock);
if (NULL != ActiveConsole) if (NULL != ActiveConsole)
{ {
ConioDrawConsole(ActiveConsole); ConioDrawConsole(ActiveConsole);
} }
} }
@ -306,179 +306,179 @@ TuiResizeBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD
DWORD WINAPI DWORD WINAPI
TuiConsoleThread (PVOID Data) TuiConsoleThread (PVOID Data)
{ {
PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Data; PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Data;
HWND NewWindow; HWND NewWindow;
MSG msg; MSG msg;
NewWindow = CreateWindowW(L"TuiConsoleWindowClass", NewWindow = CreateWindowW(L"TuiConsoleWindowClass",
Console->Title.Buffer, Console->Title.Buffer,
0, 0,
-32000, -32000, 0, 0, -32000, -32000, 0, 0,
NULL, NULL, NULL, NULL,
(HINSTANCE) GetModuleHandleW(NULL), (HINSTANCE) GetModuleHandleW(NULL),
(PVOID) Console); (PVOID) Console);
Console->hWindow = NewWindow; Console->hWindow = NewWindow;
if (NULL == NewWindow) if (NULL == NewWindow)
{ {
DPRINT1("CSR: Unable to create console window\n"); DPRINT1("CSR: Unable to create console window\n");
return 1; return 1;
} }
SetForegroundWindow(Console->hWindow); SetForegroundWindow(Console->hWindow);
while (TRUE) while (TRUE)
{ {
GetMessageW(&msg, 0, 0, 0); GetMessageW(&msg, 0, 0, 0);
DispatchMessage(&msg); DispatchMessage(&msg);
TranslateMessage(&msg); TranslateMessage(&msg);
if (msg.message == WM_CHAR || msg.message == WM_SYSCHAR || if (msg.message == WM_CHAR || msg.message == WM_SYSCHAR ||
msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || msg.message == WM_KEYDOWN || msg.message == WM_KEYUP ||
msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP)
{ {
ConioProcessKey(&msg, Console, TRUE); ConioProcessKey(&msg, Console, TRUE);
} }
} }
return 0; return 0;
} }
static CSRSS_CONSOLE_VTBL TuiVtbl = static CSRSS_CONSOLE_VTBL TuiVtbl =
{ {
TuiInitScreenBuffer, TuiInitScreenBuffer,
TuiWriteStream, TuiWriteStream,
TuiDrawRegion, TuiDrawRegion,
TuiSetCursorInfo, TuiSetCursorInfo,
TuiSetScreenInfo, TuiSetScreenInfo,
TuiUpdateScreenInfo, TuiUpdateScreenInfo,
TuiChangeTitle, TuiChangeTitle,
TuiCleanupConsole, TuiCleanupConsole,
TuiChangeIcon, TuiChangeIcon,
TuiResizeBuffer, TuiResizeBuffer,
}; };
NTSTATUS FASTCALL NTSTATUS FASTCALL
TuiInitConsole(PCSRSS_CONSOLE Console) TuiInitConsole(PCSRSS_CONSOLE Console)
{ {
HANDLE ThreadHandle; HANDLE ThreadHandle;
if (! ConsInitialized) if (! ConsInitialized)
{ {
ConsInitialized = TRUE; ConsInitialized = TRUE;
if (! TuiInit(Console->CodePage)) if (! TuiInit(Console->CodePage))
{ {
ConsInitialized = FALSE; ConsInitialized = FALSE;
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
} }
Console->Vtbl = &TuiVtbl; Console->Vtbl = &TuiVtbl;
Console->hWindow = NULL; Console->hWindow = NULL;
Console->Size = PhysicalConsoleSize; Console->Size = PhysicalConsoleSize;
Console->ActiveBuffer->MaxX = PhysicalConsoleSize.X; Console->ActiveBuffer->MaxX = PhysicalConsoleSize.X;
Console->ActiveBuffer->MaxY = PhysicalConsoleSize.Y; Console->ActiveBuffer->MaxY = PhysicalConsoleSize.Y;
ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TuiConsoleThread, ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TuiConsoleThread,
Console, 0, NULL); Console, 0, NULL);
if (NULL == ThreadHandle) if (NULL == ThreadHandle)
{ {
DPRINT1("CSR: Unable to create console thread\n"); DPRINT1("CSR: Unable to create console thread\n");
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
CloseHandle(ThreadHandle); CloseHandle(ThreadHandle);
EnterCriticalSection(&ActiveConsoleLock); EnterCriticalSection(&ActiveConsoleLock);
if (NULL != ActiveConsole) if (NULL != ActiveConsole)
{ {
Console->Prev = ActiveConsole; Console->Prev = ActiveConsole;
Console->Next = ActiveConsole->Next; Console->Next = ActiveConsole->Next;
ActiveConsole->Next->Prev = Console; ActiveConsole->Next->Prev = Console;
ActiveConsole->Next = Console; ActiveConsole->Next = Console;
} }
else else
{ {
Console->Prev = Console; Console->Prev = Console;
Console->Next = Console; Console->Next = Console;
} }
ActiveConsole = Console; ActiveConsole = Console;
LeaveCriticalSection(&ActiveConsoleLock); LeaveCriticalSection(&ActiveConsoleLock);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
PCSRSS_CONSOLE FASTCALL PCSRSS_CONSOLE FASTCALL
TuiGetFocusConsole(VOID) TuiGetFocusConsole(VOID)
{ {
return ActiveConsole; return ActiveConsole;
} }
BOOL FASTCALL BOOL FASTCALL
TuiSwapConsole(int Next) TuiSwapConsole(int Next)
{ {
static PCSRSS_CONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */ static PCSRSS_CONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */
DWORD BytesReturned; DWORD BytesReturned;
ANSI_STRING Title; ANSI_STRING Title;
void * Buffer; void * Buffer;
COORD *pos; COORD *pos;
if (0 != Next) if (0 != Next)
{ {
/* alt-tab, swap consoles */ /* alt-tab, swap consoles */
/* move SwapConsole to next console, and print its title */ /* move SwapConsole to next console, and print its title */
EnterCriticalSection(&ActiveConsoleLock); EnterCriticalSection(&ActiveConsoleLock);
if (! SwapConsole) if (! SwapConsole)
{ {
SwapConsole = ActiveConsole; SwapConsole = ActiveConsole;
} }
SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev); SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev);
Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title); Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title);
Title.Length = 0; Title.Length = 0;
Buffer = HeapAlloc(Win32CsrApiHeap, Buffer = HeapAlloc(Win32CsrApiHeap,
0, 0,
sizeof(COORD) + Title.MaximumLength); sizeof(COORD) + Title.MaximumLength);
pos = (COORD *)Buffer; pos = (COORD *)Buffer;
Title.Buffer = (PVOID)((ULONG_PTR)Buffer + sizeof( COORD )); Title.Buffer = (PVOID)((ULONG_PTR)Buffer + sizeof( COORD ));
RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE); RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE);
pos->Y = PhysicalConsoleSize.Y / 2; pos->Y = PhysicalConsoleSize.Y / 2;
pos->X = (PhysicalConsoleSize.X - Title.Length) / 2; pos->X = (PhysicalConsoleSize.X - Title.Length) / 2;
/* redraw the console to clear off old title */ /* redraw the console to clear off old title */
ConioDrawConsole(ActiveConsole); ConioDrawConsole(ActiveConsole);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER, if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER,
NULL, 0, Buffer, sizeof(COORD) + Title.Length, NULL, 0, Buffer, sizeof(COORD) + Title.Length,
&BytesReturned, NULL)) &BytesReturned, NULL))
{ {
DPRINT1( "Error writing to console\n" ); DPRINT1( "Error writing to console\n" );
} }
HeapFree(Win32CsrApiHeap, 0, Buffer); HeapFree(Win32CsrApiHeap, 0, Buffer);
LeaveCriticalSection(&ActiveConsoleLock); LeaveCriticalSection(&ActiveConsoleLock);
return TRUE; return TRUE;
} }
else if (NULL != SwapConsole) else if (NULL != SwapConsole)
{ {
EnterCriticalSection(&ActiveConsoleLock); EnterCriticalSection(&ActiveConsoleLock);
if (SwapConsole != ActiveConsole) if (SwapConsole != ActiveConsole)
{ {
/* first remove swapconsole from the list */ /* first remove swapconsole from the list */
SwapConsole->Prev->Next = SwapConsole->Next; SwapConsole->Prev->Next = SwapConsole->Next;
SwapConsole->Next->Prev = SwapConsole->Prev; SwapConsole->Next->Prev = SwapConsole->Prev;
/* now insert before activeconsole */ /* now insert before activeconsole */
SwapConsole->Next = ActiveConsole; SwapConsole->Next = ActiveConsole;
SwapConsole->Prev = ActiveConsole->Prev; SwapConsole->Prev = ActiveConsole->Prev;
ActiveConsole->Prev->Next = SwapConsole; ActiveConsole->Prev->Next = SwapConsole;
ActiveConsole->Prev = SwapConsole; ActiveConsole->Prev = SwapConsole;
} }
ActiveConsole = SwapConsole; ActiveConsole = SwapConsole;
SwapConsole = NULL; SwapConsole = NULL;
ConioDrawConsole(ActiveConsole); ConioDrawConsole(ActiveConsole);
LeaveCriticalSection(&ActiveConsoleLock); LeaveCriticalSection(&ActiveConsoleLock);
return TRUE; return TRUE;
} }
else else
{ {
return FALSE; return FALSE;
} }
} }