Author: hbelusca
Date: Sun Jan 13 19:50:52 2013
New Revision: 58169
URL:
http://svn.reactos.org/svn/reactos?rev=58169&view=rev
Log:
[CONSRV]
- Finish to do the replacements HeapAlloc --> RtlAllocateHeap and Co.
- Finish to UNICODify consrv (it happens that it has been almost done already).
- Modify the way we start BlueScreen driver (in TUI mode): instead of using the SCM which,
at that moment, is starting (and is not ready to answer to start/stop services requests),
use the NT apis to start the driver (in the same way the SCM performs driver starting).
- Add a note on HAVE_WMEMSET.
Modified:
branches/ros-csrss/win32ss/user/consrv/CMakeLists.txt
branches/ros-csrss/win32ss/user/consrv/alias.c
branches/ros-csrss/win32ss/user/consrv/conio.h
branches/ros-csrss/win32ss/user/consrv/conoutput.c
branches/ros-csrss/win32ss/user/consrv/guiconsole.c
branches/ros-csrss/win32ss/user/consrv/tuiconsole.c
branches/ros-csrss/win32ss/user/consrv/tuiconsole.h
Modified: branches/ros-csrss/win32ss/user/consrv/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/C…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/CMakeLists.txt [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/CMakeLists.txt [iso-8859-1] Sun Jan 13 19:50:52
2013
@@ -23,7 +23,7 @@
target_link_libraries(consrv win32ksys ${PSEH_LIB}) # win32ksys because of NtUser...()
-set_module_type(consrv win32dll)
+set_module_type(consrv win32dll UNICODE)
add_importlibs(consrv psapi msvcrt kernel32 ntdll csrsrv)
add_delay_importlibs(consrv user32 gdi32 advapi32)
Modified: branches/ros-csrss/win32ss/user/consrv/alias.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/a…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/alias.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/alias.c [iso-8859-1] Sun Jan 13 19:50:52 2013
@@ -64,7 +64,7 @@
return Entry;
Entry->lpExeName = (LPCWSTR)(Entry + 1);
- wcscpy((WCHAR*)Entry->lpExeName, lpExeName);
+ wcscpy((PWCHAR)Entry->lpExeName, lpExeName);
Entry->Data = NULL;
Entry->Next = NULL;
return Entry;
Modified: branches/ros-csrss/win32ss/user/consrv/conio.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conio.h [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conio.h [iso-8859-1] Sun Jan 13 19:50:52 2013
@@ -107,9 +107,9 @@
typedef struct _CONSOLE_VTBL
{
VOID (WINAPI *InitScreenBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER
ScreenBuffer);
- VOID (WINAPI *WriteStream)(PCONSOLE Console, SMALL_RECT *Block, LONG CursorStartX,
LONG CursorStartY,
+ VOID (WINAPI *WriteStream)(PCONSOLE Console, SMALL_RECT* Block, LONG CursorStartX,
LONG CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length);
- VOID (WINAPI *DrawRegion)(PCONSOLE Console, SMALL_RECT *Region);
+ VOID (WINAPI *DrawRegion)(PCONSOLE Console, SMALL_RECT* Region);
BOOL (WINAPI *SetCursorInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
BOOL (WINAPI *SetScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer,
UINT OldCursorX, UINT OldCursorY);
Modified: branches/ros-csrss/win32ss/user/consrv/conoutput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] Sun Jan 13 19:50:52
2013
@@ -89,7 +89,7 @@
}
static VOID FASTCALL
-ConioNextLine(PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT *UpdateRect, UINT *ScrolledLines)
+ConioNextLine(PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT* UpdateRect, UINT *ScrolledLines)
{
/* If we hit bottom, slide the viewable screen */
if (++Buff->CurrentY == Buff->MaxY)
@@ -240,9 +240,9 @@
}
__inline BOOLEAN ConioGetIntersection(
- SMALL_RECT *Intersection,
- SMALL_RECT *Rect1,
- SMALL_RECT *Rect2)
+ SMALL_RECT* Intersection,
+ SMALL_RECT* Rect1,
+ SMALL_RECT* Rect2)
{
if (ConioIsRectEmpty(Rect1) ||
(ConioIsRectEmpty(Rect2)) ||
@@ -266,9 +266,9 @@
}
__inline BOOLEAN ConioGetUnion(
- SMALL_RECT *Union,
- SMALL_RECT *Rect1,
- SMALL_RECT *Rect2)
+ SMALL_RECT* Union,
+ SMALL_RECT* Rect1,
+ SMALL_RECT* Rect2)
{
if (ConioIsRectEmpty(Rect1))
{
@@ -304,9 +304,9 @@
*/
static VOID FASTCALL
ConioMoveRegion(PCONSOLE_SCREEN_BUFFER ScreenBuffer,
- SMALL_RECT *SrcRegion,
- SMALL_RECT *DstRegion,
- SMALL_RECT *ClipRegion,
+ SMALL_RECT* SrcRegion,
+ SMALL_RECT* DstRegion,
+ SMALL_RECT* ClipRegion,
WORD Fill)
{
int Width = ConioRectWidth(SrcRegion);
@@ -394,7 +394,7 @@
}
static VOID FASTCALL
-ConioComputeUpdateRect(PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT *UpdateRect, COORD *Start,
UINT Length)
+ConioComputeUpdateRect(PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT* UpdateRect, PCOORD Start,
UINT Length)
{
if (Buff->MaxX <= Start->X + Length)
{
Modified: branches/ros-csrss/win32ss/user/consrv/guiconsole.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/g…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/guiconsole.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/guiconsole.c [iso-8859-1] Sun Jan 13 19:50:52
2013
@@ -15,6 +15,11 @@
#define NDEBUG
#include <debug.h>
+/*
+// Define wmemset(...)
+#include <wchar.h>
+#define HAVE_WMEMSET
+*/
/* GUI Console Window Class name */
#define GUI_CONSOLE_WINDOW_CLASS L"ConsoleWindowClass"
@@ -1074,7 +1079,7 @@
}
static VOID WINAPI
-GuiDrawRegion(PCONSOLE Console, SMALL_RECT *Region)
+GuiDrawRegion(PCONSOLE Console, SMALL_RECT* Region)
{
RECT RegionRect;
SmallRectToRect(Console, &RegionRect, Region);
@@ -1089,7 +1094,7 @@
}
static VOID WINAPI
-GuiWriteStream(PCONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG
CursorStartY,
+GuiWriteStream(PCONSOLE Console, SMALL_RECT* Region, LONG CursorStartX, LONG
CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length)
{
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData;
@@ -1519,7 +1524,7 @@
{
PCONSOLE Console;
APPLET_PROC CPLFunc;
- TCHAR szBuffer[MAX_PATH];
+ WCHAR szBuffer[MAX_PATH];
ConsoleInfo SharedInfo;
DPRINT("GuiConsoleShowConsoleProperties entered\n");
@@ -1534,9 +1539,9 @@
if (GuiData->ConsoleLibrary == NULL)
{
- GetWindowsDirectory(szBuffer,MAX_PATH);
- _tcscat(szBuffer, _T("\\system32\\console.dll"));
- GuiData->ConsoleLibrary = LoadLibrary(szBuffer);
+ GetWindowsDirectoryW(szBuffer, MAX_PATH);
+ wcscat(szBuffer, L"\\system32\\console.dll");
+ GuiData->ConsoleLibrary = LoadLibraryW(szBuffer);
if (GuiData->ConsoleLibrary == NULL)
{
@@ -1545,7 +1550,7 @@
}
}
- CPLFunc = (APPLET_PROC) GetProcAddress(GuiData->ConsoleLibrary,
_T("CPlApplet"));
+ CPLFunc = (APPLET_PROC)GetProcAddress(GuiData->ConsoleLibrary,
"CPlApplet");
if (!CPLFunc)
{
DPRINT("Error: Console.dll misses CPlApplet export\n");
@@ -1755,11 +1760,12 @@
BYTE * OldPtr;
USHORT CurrentY;
BYTE * OldBuffer;
-#if HAVE_WMEMSET
+#ifdef HAVE_WMEMSET
USHORT value = MAKEWORD(' ', ScreenBuffer->DefaultAttrib);
+#else
+ DWORD i;
#endif
DWORD diff;
- DWORD i;
/* Buffer size is not allowed to be smaller than window size */
if (Size.X < Console->Size.X || Size.Y < Console->Size.Y)
@@ -1792,8 +1798,8 @@
diff = Size.X - ScreenBuffer->MaxX;
/* zero new part of it */
-#if HAVE_WMEMSET
- wmemset((WCHAR*)&Buffer[Offset], value, diff);
+#ifdef HAVE_WMEMSET
+ wmemset((PWCHAR)&Buffer[Offset], value, diff);
#else
for (i = 0; i < diff; i++)
{
@@ -1807,8 +1813,8 @@
if (Size.Y > ScreenBuffer->MaxY)
{
diff = Size.X * (Size.Y - ScreenBuffer->MaxY);
-#if HAVE_WMEMSET
- wmemset((WCHAR*)&Buffer[Offset], value, diff);
+#ifdef HAVE_WMEMSET
+ wmemset((PWCHAR)&Buffer[Offset], value, diff);
#else
for (i = 0; i < diff; i++)
{
Modified: branches/ros-csrss/win32ss/user/consrv/tuiconsole.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/t…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/tuiconsole.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/tuiconsole.c [iso-8859-1] Sun Jan 13 19:50:52
2013
@@ -25,6 +25,157 @@
static BOOL ConsInitialized = FALSE;
+/******************************************************************************\
+|** BlueScreen Driver management **|
+\**/
+/* Code taken and adapted from base/system/services/driver.c */
+static DWORD EnablePrivilege(LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
+{
+ DWORD dwRet = ERROR_SUCCESS;
+ HANDLE hToken = NULL;
+
+ if (OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES,
+ &hToken))
+ {
+ TOKEN_PRIVILEGES tp;
+
+ tp.PrivilegeCount = 1;
+ tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0);
+
+ if (LookupPrivilegeValueW(NULL,
+ lpszPrivilegeName,
+ &tp.Privileges[0].Luid))
+ {
+ if (AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL))
+ {
+ if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
+ dwRet = ERROR_NOT_ALL_ASSIGNED;
+ }
+ else
+ {
+ dwRet = GetLastError();
+ }
+ }
+ else
+ {
+ dwRet = GetLastError();
+ }
+
+ CloseHandle(hToken);
+ }
+ else
+ {
+ dwRet = GetLastError();
+ }
+
+ return dwRet;
+}
+
+static DWORD
+ScmLoadDriver(LPCWSTR lpServiceName)
+{
+ PWSTR pszDriverPath;
+ UNICODE_STRING DriverPath;
+ NTSTATUS Status;
+ DWORD dwError = ERROR_SUCCESS;
+
+ /* Build the driver path */
+ /* 52 =
wcslen(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\") */
+ pszDriverPath = RtlAllocateHeap(ConSrvHeap,
+ HEAP_ZERO_MEMORY,
+ (52 + wcslen(lpServiceName) + 1) * sizeof(WCHAR));
+ if (pszDriverPath == NULL)
+ return ERROR_NOT_ENOUGH_MEMORY;
+
+ wcscpy(pszDriverPath,
+ L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
+ wcscat(pszDriverPath,
+ lpServiceName);
+
+ RtlInitUnicodeString(&DriverPath,
+ pszDriverPath);
+
+ DPRINT(" Path: %wZ\n", &DriverPath);
+
+ /* Acquire driver-loading privilege */
+ dwError = EnablePrivilege(SE_LOAD_DRIVER_NAME, TRUE);
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* We encountered a failure, exit properly */
+ DPRINT1("CONSRV: Cannot acquire driver-loading privilege, error =
%lu\n", dwError);
+ goto done;
+ }
+
+ Status = NtLoadDriver(&DriverPath);
+
+ /* Release driver-loading privilege */
+ EnablePrivilege(SE_LOAD_DRIVER_NAME, FALSE);
+
+ if (!NT_SUCCESS(Status))
+ {
+ dwError = RtlNtStatusToDosError(Status);
+ }
+
+done:
+ RtlFreeHeap(ConSrvHeap, 0, pszDriverPath);
+
+ return dwError;
+}
+
+#ifdef BLUESCREEN_DRIVER_UNLOADING
+static DWORD
+ScmUnloadDriver(LPCWSTR lpServiceName)
+{
+ PWSTR pszDriverPath;
+ UNICODE_STRING DriverPath;
+ NTSTATUS Status;
+ DWORD dwError = ERROR_SUCCESS;
+
+ /* Build the driver path */
+ /* 52 =
wcslen(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\") */
+ pszDriverPath = RtlAllocateHeap(ConSrvHeap,
+ HEAP_ZERO_MEMORY,
+ (52 + wcslen(lpServiceName) + 1) * sizeof(WCHAR));
+ if (pszDriverPath == NULL)
+ return ERROR_NOT_ENOUGH_MEMORY;
+
+ wcscpy(pszDriverPath,
+ L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
+ wcscat(pszDriverPath,
+ lpServiceName);
+
+ RtlInitUnicodeString(&DriverPath,
+ pszDriverPath);
+
+ /* Acquire driver-unloading privilege */
+ dwError = EnablePrivilege(SE_LOAD_DRIVER_NAME, TRUE);
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* We encountered a failure, exit properly */
+ DPRINT1("CONSRV: Cannot acquire driver-unloading privilege, error =
%lu\n", dwError);
+ goto done;
+ }
+
+ Status = NtUnloadDriver(&DriverPath);
+
+ /* Release driver-unloading privilege */
+ EnablePrivilege(SE_LOAD_DRIVER_NAME, FALSE);
+
+ if (!NT_SUCCESS(Status))
+ {
+ dwError = RtlNtStatusToDosError(Status);
+ }
+
+done:
+ RtlFreeHeap(ConSrvHeap, 0, pszDriverPath);
+
+ return dwError;
+}
+#endif
+/**\
+\******************************************************************************/
+
static LRESULT CALLBACK
TuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -37,35 +188,6 @@
}
}
return DefWindowProcW(hWnd, msg, wParam, lParam);
-}
-
-static BOOL FASTCALL
-TuiStartService(LPCWSTR lpServiceName)
-{
- SC_HANDLE hSCManager = NULL;
- SC_HANDLE hService = NULL;
- BOOL ret = FALSE;
-
- hSCManager = OpenSCManagerW(NULL, NULL, 0);
- if (hSCManager == NULL)
- goto cleanup;
-
- hService = OpenServiceW(hSCManager, lpServiceName, SERVICE_START);
- if (hService == NULL)
- goto cleanup;
-
- ret = StartServiceW(hService, 0, NULL);
- if (!ret)
- goto cleanup;
-
- ret = TRUE;
-
-cleanup:
- if (hSCManager != NULL)
- CloseServiceHandle(hSCManager);
- if (hService != NULL)
- CloseServiceHandle(hService);
- return ret;
}
static BOOL FASTCALL
@@ -77,7 +199,7 @@
ATOM ConsoleClassAtom;
USHORT TextAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
- TuiStartService(L"Blue");
+ ScmLoadDriver(L"Blue");
ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0,
NULL,
OPEN_EXISTING, 0, NULL);
@@ -140,7 +262,7 @@
}
static void FASTCALL
-TuiCopyRect(char *Dest, PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT *Region)
+TuiCopyRect(char *Dest, PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT* Region)
{
UINT SrcDelta, DestDelta;
LONG i;
@@ -163,7 +285,7 @@
}
static VOID WINAPI
-TuiDrawRegion(PCONSOLE Console, SMALL_RECT *Region)
+TuiDrawRegion(PCONSOLE Console, SMALL_RECT* Region)
{
DWORD BytesReturned;
PCONSOLE_SCREEN_BUFFER Buff = Console->ActiveBuffer;
@@ -177,10 +299,10 @@
ConsoleDrawSize = sizeof(CONSOLE_DRAW) +
(ConioRectWidth(Region) * ConioRectHeight(Region)) * 2;
- ConsoleDraw = HeapAlloc(ConSrvHeap, 0, ConsoleDrawSize);
+ ConsoleDraw = RtlAllocateHeap(ConSrvHeap, 0, ConsoleDrawSize);
if (NULL == ConsoleDraw)
{
- DPRINT1("HeapAlloc failed\n");
+ DPRINT1("RtlAllocateHeap failed\n");
return;
}
ConsoleDraw->X = Region->Left;
@@ -196,15 +318,15 @@
NULL, 0, ConsoleDraw, ConsoleDrawSize, &BytesReturned,
NULL))
{
DPRINT1("Failed to draw console\n");
- HeapFree(ConSrvHeap, 0, ConsoleDraw);
+ RtlFreeHeap(ConSrvHeap, 0, ConsoleDraw);
return;
}
- HeapFree(ConSrvHeap, 0, ConsoleDraw);
+ RtlFreeHeap(ConSrvHeap, 0, ConsoleDraw);
}
static VOID WINAPI
-TuiWriteStream(PCONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG
CursorStartY,
+TuiWriteStream(PCONSOLE Console, SMALL_RECT* Region, LONG CursorStartX, LONG
CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length)
{
DWORD BytesWritten;
@@ -437,13 +559,13 @@
}
BOOL FASTCALL
-TuiSwapConsole(int Next)
+TuiSwapConsole(INT Next)
{
static PCONSOLE SwapConsole = NULL; /* console we are thinking about swapping with
*/
DWORD BytesReturned;
ANSI_STRING Title;
- void * Buffer;
- COORD *pos;
+ PVOID Buffer;
+ PCOORD pos;
if (0 != Next)
{
@@ -458,10 +580,10 @@
SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev);
Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title);
Title.Length = 0;
- Buffer = HeapAlloc(ConSrvHeap,
+ Buffer = RtlAllocateHeap(ConSrvHeap,
0,
sizeof(COORD) + Title.MaximumLength);
- pos = (COORD *)Buffer;
+ pos = (PCOORD )Buffer;
Title.Buffer = (PVOID)((ULONG_PTR)Buffer + sizeof( COORD ));
RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE);
@@ -475,7 +597,7 @@
{
DPRINT1( "Error writing to console\n" );
}
- HeapFree(ConSrvHeap, 0, Buffer);
+ RtlFreeHeap(ConSrvHeap, 0, Buffer);
LeaveCriticalSection(&ActiveConsoleLock);
return TRUE;
Modified: branches/ros-csrss/win32ss/user/consrv/tuiconsole.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/t…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/tuiconsole.h [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/tuiconsole.h [iso-8859-1] Sun Jan 13 19:50:52
2013
@@ -10,6 +10,6 @@
extern NTSTATUS FASTCALL TuiInitConsole(PCONSOLE Console);
extern PCONSOLE FASTCALL TuiGetFocusConsole(VOID);
-extern BOOL FASTCALL TuiSwapConsole(int Next);
+extern BOOL FASTCALL TuiSwapConsole(INT Next);
/* EOF */