mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
[KERNEL32]
Code reorganization only : move the console-related initialization functions into a dedicated file, and create a specific header to hold console function definitions. svn path=/branches/ros-csrss/; revision=58306
This commit is contained in:
parent
f4d53fbd91
commit
4738893a1d
7 changed files with 428 additions and 352 deletions
|
@ -37,6 +37,7 @@ list(APPEND SOURCE
|
|||
client/console/alias.c
|
||||
client/console/console.c
|
||||
client/console/history.c
|
||||
client/console/init.c
|
||||
client/console/readwrite.c
|
||||
client/console/vista.c
|
||||
client/file/backup.c
|
||||
|
|
|
@ -14,12 +14,13 @@
|
|||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* GLOBALS ********************************************************************/
|
||||
|
||||
extern RTL_CRITICAL_SECTION ConsoleLock;
|
||||
extern BOOL ConsoleInitialized;
|
||||
extern BOOL WINAPI IsDebuggerPresent(VOID);
|
||||
|
||||
/* GLOBALS ********************************************************************/
|
||||
|
||||
/* Console reserved "file" names */
|
||||
static LPCWSTR BaseConFileName = CONSOLE_FILE_NAME;
|
||||
static LPCWSTR BaseConInputFileName = CONSOLE_INPUT_FILE_NAME;
|
||||
|
@ -35,6 +36,7 @@ HANDLE InputWaitHandle = INVALID_HANDLE_VALUE;
|
|||
#define INPUTEXENAME_BUFLEN 256
|
||||
static WCHAR InputExeName[INPUTEXENAME_BUFLEN];
|
||||
|
||||
|
||||
/* Default Console Control Handler ********************************************/
|
||||
|
||||
BOOL
|
||||
|
@ -190,49 +192,6 @@ InitConsoleCtrlHandling(VOID)
|
|||
|
||||
/* FUNCTIONS ******************************************************************/
|
||||
|
||||
VOID
|
||||
InitConsoleProps(IN OUT PCONSOLE_PROPS ConsoleProps)
|
||||
{
|
||||
STARTUPINFOW si;
|
||||
|
||||
GetStartupInfoW(&si);
|
||||
|
||||
ConsoleProps->dwStartupFlags = si.dwFlags;
|
||||
if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
|
||||
{
|
||||
ConsoleProps->FillAttribute = si.dwFillAttribute;
|
||||
}
|
||||
if (si.dwFlags & STARTF_USECOUNTCHARS)
|
||||
{
|
||||
ConsoleProps->ScreenBufferSize.X = (SHORT)(si.dwXCountChars);
|
||||
ConsoleProps->ScreenBufferSize.Y = (SHORT)(si.dwYCountChars);
|
||||
}
|
||||
if (si.dwFlags & STARTF_USESHOWWINDOW)
|
||||
{
|
||||
ConsoleProps->ShowWindow = si.wShowWindow;
|
||||
}
|
||||
if (si.dwFlags & STARTF_USEPOSITION)
|
||||
{
|
||||
ConsoleProps->ConsoleWindowOrigin.x = (LONG)(si.dwX);
|
||||
ConsoleProps->ConsoleWindowOrigin.y = (LONG)(si.dwY);
|
||||
}
|
||||
if (si.dwFlags & STARTF_USESIZE)
|
||||
{
|
||||
ConsoleProps->ConsoleWindowSize.cx = (LONG)(si.dwXSize);
|
||||
ConsoleProps->ConsoleWindowSize.cy = (LONG)(si.dwYSize);
|
||||
}
|
||||
|
||||
if (si.lpTitle)
|
||||
{
|
||||
wcsncpy(ConsoleProps->ConsoleTitle, si.lpTitle, MAX_PATH + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleProps->ConsoleTitle[0] = L'\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LPCWSTR
|
||||
IntCheckForConsoleFileName(IN LPCWSTR pszName,
|
||||
IN DWORD dwDesiredAccess)
|
||||
|
|
241
dll/win32/kernel32/client/console/init.c
Normal file
241
dll/win32/kernel32/client/console/init.c
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: dll/win32/kernel32/client/console/init.c
|
||||
* PURPOSE: Console API Client Initialization
|
||||
* PROGRAMMERS: Hermes Belusca - Maito
|
||||
*/
|
||||
|
||||
/* INCLUDES *******************************************************************/
|
||||
|
||||
#include <k32.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* GLOBALS ********************************************************************/
|
||||
|
||||
RTL_CRITICAL_SECTION ConsoleLock;
|
||||
BOOL ConsoleInitialized = FALSE;
|
||||
|
||||
extern DWORD WINAPI ConsoleControlDispatcher(IN LPVOID lpThreadParameter);
|
||||
extern HANDLE InputWaitHandle;
|
||||
|
||||
#define WIN_OBJ_DIR L"\\Windows"
|
||||
#define SESSION_DIR L"\\Sessions"
|
||||
|
||||
|
||||
/* FUNCTIONS ******************************************************************/
|
||||
|
||||
VOID
|
||||
InitConsoleProps(IN OUT PCONSOLE_PROPS ConsoleProps)
|
||||
{
|
||||
STARTUPINFOW si;
|
||||
|
||||
GetStartupInfoW(&si);
|
||||
|
||||
ConsoleProps->dwStartupFlags = si.dwFlags;
|
||||
if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
|
||||
{
|
||||
ConsoleProps->FillAttribute = si.dwFillAttribute;
|
||||
}
|
||||
if (si.dwFlags & STARTF_USECOUNTCHARS)
|
||||
{
|
||||
ConsoleProps->ScreenBufferSize.X = (SHORT)(si.dwXCountChars);
|
||||
ConsoleProps->ScreenBufferSize.Y = (SHORT)(si.dwYCountChars);
|
||||
}
|
||||
if (si.dwFlags & STARTF_USESHOWWINDOW)
|
||||
{
|
||||
ConsoleProps->ShowWindow = si.wShowWindow;
|
||||
}
|
||||
if (si.dwFlags & STARTF_USEPOSITION)
|
||||
{
|
||||
ConsoleProps->ConsoleWindowOrigin.x = (LONG)(si.dwX);
|
||||
ConsoleProps->ConsoleWindowOrigin.y = (LONG)(si.dwY);
|
||||
}
|
||||
if (si.dwFlags & STARTF_USESIZE)
|
||||
{
|
||||
ConsoleProps->ConsoleWindowSize.cx = (LONG)(si.dwXSize);
|
||||
ConsoleProps->ConsoleWindowSize.cy = (LONG)(si.dwYSize);
|
||||
}
|
||||
|
||||
if (si.lpTitle)
|
||||
{
|
||||
wcsncpy(ConsoleProps->ConsoleTitle, si.lpTitle, MAX_PATH + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleProps->ConsoleTitle[0] = L'\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOL
|
||||
WINAPI
|
||||
BasepInitConsole(VOID)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
|
||||
WCHAR SessionDir[256];
|
||||
ULONG SessionId = NtCurrentPeb()->SessionId;
|
||||
BOOLEAN InServer;
|
||||
|
||||
CONSOLE_CONNECTION_INFO ConnectInfo;
|
||||
ULONG ConnectInfoSize = sizeof(ConnectInfo);
|
||||
|
||||
DPRINT("BasepInitConsole for : %wZ\n", &Parameters->ImagePathName);
|
||||
DPRINT("Our current console handles are: %lx, %lx, %lx %lx\n",
|
||||
Parameters->ConsoleHandle, Parameters->StandardInput,
|
||||
Parameters->StandardOutput, Parameters->StandardError);
|
||||
|
||||
/* Initialize our global console DLL lock */
|
||||
Status = RtlInitializeCriticalSection(&ConsoleLock);
|
||||
if (!NT_SUCCESS(Status)) return FALSE;
|
||||
ConsoleInitialized = TRUE;
|
||||
|
||||
/* Do nothing if this isn't a console app... */
|
||||
if (RtlImageNtHeader(GetModuleHandle(NULL))->OptionalHeader.Subsystem !=
|
||||
IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
||||
{
|
||||
DPRINT("Image is not a console application\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleNeeded = FALSE; // ConsoleNeeded is used for knowing whether or not this is a CUI app.
|
||||
|
||||
ConnectInfo.ConsoleProps.ConsoleTitle[0] = L'\0';
|
||||
ConnectInfo.AppPath[0] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
SIZE_T Length = 0;
|
||||
LPCWSTR ExeName;
|
||||
|
||||
InitConsoleProps(&ConnectInfo.ConsoleProps);
|
||||
|
||||
Length = min(sizeof(ConnectInfo.AppPath) / sizeof(ConnectInfo.AppPath[0]),
|
||||
Parameters->ImagePathName.Length / sizeof(WCHAR));
|
||||
wcsncpy(ConnectInfo.AppPath, Parameters->ImagePathName.Buffer, Length);
|
||||
ConnectInfo.AppPath[Length] = L'\0';
|
||||
|
||||
/* Initialize Input EXE name */
|
||||
ExeName = wcsrchr(Parameters->ImagePathName.Buffer, L'\\');
|
||||
if (ExeName) SetConsoleInputExeNameW(ExeName + 1);
|
||||
|
||||
/* Assume one is needed */
|
||||
ConnectInfo.ConsoleNeeded = TRUE;
|
||||
|
||||
/* Handle the special flags given to us by BasePushProcessParameters */
|
||||
if (Parameters->ConsoleHandle == HANDLE_DETACHED_PROCESS)
|
||||
{
|
||||
/* No console to create */
|
||||
DPRINT("No console to create\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleNeeded = FALSE;
|
||||
}
|
||||
else if (Parameters->ConsoleHandle == HANDLE_CREATE_NEW_CONSOLE)
|
||||
{
|
||||
/* We'll get the real one soon */
|
||||
DPRINT("Creating new console\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
}
|
||||
else if (Parameters->ConsoleHandle == HANDLE_CREATE_NO_WINDOW)
|
||||
{
|
||||
/* We'll get the real one soon */
|
||||
DPRINT("Creating new invisible console\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleProps.ShowWindow = SW_HIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Parameters->ConsoleHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
}
|
||||
DPRINT("Using existing console: %x\n", Parameters->ConsoleHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now use the proper console handle */
|
||||
ConnectInfo.Console = Parameters->ConsoleHandle;
|
||||
|
||||
/* Initialize Console Ctrl Handler */
|
||||
InitConsoleCtrlHandling();
|
||||
ConnectInfo.CtrlDispatcher = ConsoleControlDispatcher;
|
||||
|
||||
/* Setup the right Object Directory path */
|
||||
if (!SessionId)
|
||||
{
|
||||
/* Use the raw path */
|
||||
wcscpy(SessionDir, WIN_OBJ_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use the session path */
|
||||
swprintf(SessionDir,
|
||||
L"%ws\\%ld%ws",
|
||||
SESSION_DIR,
|
||||
SessionId,
|
||||
WIN_OBJ_DIR);
|
||||
}
|
||||
|
||||
/* Connect to the Console Server */
|
||||
DPRINT("Connecting to the Console Server in BasepInitConsole...\n");
|
||||
Status = CsrClientConnectToServer(SessionDir,
|
||||
CONSRV_SERVERDLL_INDEX,
|
||||
&ConnectInfo,
|
||||
&ConnectInfoSize,
|
||||
&InServer);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to connect to the Console Server (Status %lx)\n", Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Nothing to do for server-to-server */
|
||||
if (InServer) return TRUE;
|
||||
|
||||
/* Nothing to do if not a console app */
|
||||
if (!ConnectInfo.ConsoleNeeded) return TRUE;
|
||||
|
||||
/* We got the handles, let's set them */
|
||||
if ((Parameters->ConsoleHandle = ConnectInfo.Console))
|
||||
{
|
||||
/* If we already had some, don't use the new ones */
|
||||
if (!Parameters->StandardInput)
|
||||
{
|
||||
Parameters->StandardInput = ConnectInfo.InputHandle;
|
||||
}
|
||||
if (!Parameters->StandardOutput)
|
||||
{
|
||||
Parameters->StandardOutput = ConnectInfo.OutputHandle;
|
||||
}
|
||||
if (!Parameters->StandardError)
|
||||
{
|
||||
Parameters->StandardError = ConnectInfo.ErrorHandle;
|
||||
}
|
||||
}
|
||||
|
||||
InputWaitHandle = ConnectInfo.InputWaitHandle;
|
||||
|
||||
DPRINT("Console setup: %lx, %lx, %lx, %lx\n",
|
||||
Parameters->ConsoleHandle,
|
||||
Parameters->StandardInput,
|
||||
Parameters->StandardOutput,
|
||||
Parameters->StandardError);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
WINAPI
|
||||
BasepUninitConsole(VOID)
|
||||
{
|
||||
/* Delete our critical section if we were initialized */
|
||||
if (ConsoleInitialized == TRUE)
|
||||
{
|
||||
ConsoleInitialized = FALSE;
|
||||
RtlDeleteCriticalSection(&ConsoleLock);
|
||||
}
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -27,15 +27,10 @@ HMODULE hCurrentModule = NULL;
|
|||
HMODULE kernel32_handle = NULL;
|
||||
PPEB Peb;
|
||||
ULONG SessionId;
|
||||
BOOL ConsoleInitialized = FALSE;
|
||||
static BOOL DllInitialized = FALSE;
|
||||
|
||||
/* Critical section for various kernel32 data structures */
|
||||
RTL_CRITICAL_SECTION BaseDllDirectoryLock;
|
||||
RTL_CRITICAL_SECTION ConsoleLock;
|
||||
|
||||
extern DWORD WINAPI ConsoleControlDispatcher(IN LPVOID lpThreadParameter);
|
||||
extern HANDLE InputWaitHandle;
|
||||
|
||||
extern BOOL FASTCALL NlsInit(VOID);
|
||||
extern VOID FASTCALL NlsUninit(VOID);
|
||||
|
@ -45,160 +40,6 @@ extern VOID FASTCALL NlsUninit(VOID);
|
|||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
BOOL
|
||||
WINAPI
|
||||
BasepInitConsole(VOID)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
|
||||
WCHAR SessionDir[256];
|
||||
ULONG SessionId = NtCurrentPeb()->SessionId;
|
||||
BOOLEAN InServer;
|
||||
|
||||
CONSOLE_CONNECTION_INFO ConnectInfo;
|
||||
ULONG ConnectInfoSize = sizeof(ConnectInfo);
|
||||
|
||||
DPRINT("BasepInitConsole for : %wZ\n", &Parameters->ImagePathName);
|
||||
DPRINT("Our current console handles are: %lx, %lx, %lx %lx\n",
|
||||
Parameters->ConsoleHandle, Parameters->StandardInput,
|
||||
Parameters->StandardOutput, Parameters->StandardError);
|
||||
|
||||
/* Initialize our global console DLL lock */
|
||||
Status = RtlInitializeCriticalSection(&ConsoleLock);
|
||||
if (!NT_SUCCESS(Status)) return FALSE;
|
||||
ConsoleInitialized = TRUE;
|
||||
|
||||
/* Do nothing if this isn't a console app... */
|
||||
if (RtlImageNtHeader(GetModuleHandle(NULL))->OptionalHeader.Subsystem !=
|
||||
IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
||||
{
|
||||
DPRINT("Image is not a console application\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleNeeded = FALSE; // ConsoleNeeded is used for knowing whether or not this is a CUI app.
|
||||
|
||||
ConnectInfo.ConsoleProps.ConsoleTitle[0] = L'\0';
|
||||
ConnectInfo.AppPath[0] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
SIZE_T Length = 0;
|
||||
LPCWSTR ExeName;
|
||||
|
||||
InitConsoleProps(&ConnectInfo.ConsoleProps);
|
||||
|
||||
Length = min(sizeof(ConnectInfo.AppPath) / sizeof(ConnectInfo.AppPath[0]),
|
||||
Parameters->ImagePathName.Length / sizeof(WCHAR));
|
||||
wcsncpy(ConnectInfo.AppPath, Parameters->ImagePathName.Buffer, Length);
|
||||
ConnectInfo.AppPath[Length] = L'\0';
|
||||
|
||||
/* Initialize Input EXE name */
|
||||
ExeName = wcsrchr(Parameters->ImagePathName.Buffer, L'\\');
|
||||
if (ExeName) SetConsoleInputExeNameW(ExeName + 1);
|
||||
|
||||
/* Assume one is needed */
|
||||
ConnectInfo.ConsoleNeeded = TRUE;
|
||||
|
||||
/* Handle the special flags given to us by BasePushProcessParameters */
|
||||
if (Parameters->ConsoleHandle == HANDLE_DETACHED_PROCESS)
|
||||
{
|
||||
/* No console to create */
|
||||
DPRINT("No console to create\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleNeeded = FALSE;
|
||||
}
|
||||
else if (Parameters->ConsoleHandle == HANDLE_CREATE_NEW_CONSOLE)
|
||||
{
|
||||
/* We'll get the real one soon */
|
||||
DPRINT("Creating new console\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
}
|
||||
else if (Parameters->ConsoleHandle == HANDLE_CREATE_NO_WINDOW)
|
||||
{
|
||||
/* We'll get the real one soon */
|
||||
DPRINT("Creating new invisible console\n");
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
ConnectInfo.ConsoleProps.ShowWindow = SW_HIDE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Parameters->ConsoleHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Parameters->ConsoleHandle = NULL;
|
||||
}
|
||||
DPRINT("Using existing console: %x\n", Parameters->ConsoleHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now use the proper console handle */
|
||||
ConnectInfo.Console = Parameters->ConsoleHandle;
|
||||
|
||||
/* Initialize Console Ctrl Handler */
|
||||
InitConsoleCtrlHandling();
|
||||
ConnectInfo.CtrlDispatcher = ConsoleControlDispatcher;
|
||||
|
||||
/* Setup the right Object Directory path */
|
||||
if (!SessionId)
|
||||
{
|
||||
/* Use the raw path */
|
||||
wcscpy(SessionDir, WIN_OBJ_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use the session path */
|
||||
swprintf(SessionDir,
|
||||
L"%ws\\%ld%ws",
|
||||
SESSION_DIR,
|
||||
SessionId,
|
||||
WIN_OBJ_DIR);
|
||||
}
|
||||
|
||||
/* Connect to the Console Server */
|
||||
DPRINT("Connecting to the Console Server in BasepInitConsole...\n");
|
||||
Status = CsrClientConnectToServer(SessionDir,
|
||||
CONSRV_SERVERDLL_INDEX,
|
||||
&ConnectInfo,
|
||||
&ConnectInfoSize,
|
||||
&InServer);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to connect to the Console Server (Status %lx)\n", Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Nothing to do for server-to-server */
|
||||
if (InServer) return TRUE;
|
||||
|
||||
/* Nothing to do if not a console app */
|
||||
if (!ConnectInfo.ConsoleNeeded) return TRUE;
|
||||
|
||||
/* We got the handles, let's set them */
|
||||
if ((Parameters->ConsoleHandle = ConnectInfo.Console))
|
||||
{
|
||||
/* If we already had some, don't use the new ones */
|
||||
if (!Parameters->StandardInput)
|
||||
{
|
||||
Parameters->StandardInput = ConnectInfo.InputHandle;
|
||||
}
|
||||
if (!Parameters->StandardOutput)
|
||||
{
|
||||
Parameters->StandardOutput = ConnectInfo.OutputHandle;
|
||||
}
|
||||
if (!Parameters->StandardError)
|
||||
{
|
||||
Parameters->StandardError = ConnectInfo.ErrorHandle;
|
||||
}
|
||||
}
|
||||
|
||||
InputWaitHandle = ConnectInfo.InputWaitHandle;
|
||||
|
||||
DPRINT("Console setup: %lx, %lx, %lx, %lx\n",
|
||||
Parameters->ConsoleHandle,
|
||||
Parameters->StandardInput,
|
||||
Parameters->StandardOutput,
|
||||
Parameters->StandardError);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
BaseCreateThreadPoolThread(IN PTHREAD_START_ROUTINE Function,
|
||||
|
@ -262,132 +103,136 @@ DllMain(HANDLE hDll,
|
|||
switch (dwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
|
||||
/* Set no filter intially */
|
||||
GlobalTopLevelExceptionFilter = RtlEncodePointer(NULL);
|
||||
|
||||
/* Enable the Rtl thread pool and timer queue to use proper Win32 thread */
|
||||
RtlSetThreadPoolStartFunc(BaseCreateThreadPoolThread, BaseExitThreadPoolThread);
|
||||
|
||||
/* Don't bother us for each thread */
|
||||
LdrDisableThreadCalloutsForDll((PVOID)hDll);
|
||||
|
||||
/* Initialize default path to NULL */
|
||||
RtlInitUnicodeString(&BaseDefaultPath, NULL);
|
||||
|
||||
/* Setup the right Object Directory path */
|
||||
if (!SessionId)
|
||||
{
|
||||
/* Use the raw path */
|
||||
wcscpy(SessionDir, WIN_OBJ_DIR);
|
||||
/* Set no filter intially */
|
||||
GlobalTopLevelExceptionFilter = RtlEncodePointer(NULL);
|
||||
|
||||
/* Enable the Rtl thread pool and timer queue to use proper Win32 thread */
|
||||
RtlSetThreadPoolStartFunc(BaseCreateThreadPoolThread, BaseExitThreadPoolThread);
|
||||
|
||||
/* Don't bother us for each thread */
|
||||
LdrDisableThreadCalloutsForDll((PVOID)hDll);
|
||||
|
||||
/* Initialize default path to NULL */
|
||||
RtlInitUnicodeString(&BaseDefaultPath, NULL);
|
||||
|
||||
/* Setup the right Object Directory path */
|
||||
if (!SessionId)
|
||||
{
|
||||
/* Use the raw path */
|
||||
wcscpy(SessionDir, WIN_OBJ_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use the session path */
|
||||
swprintf(SessionDir,
|
||||
L"%ws\\%ld%ws",
|
||||
SESSION_DIR,
|
||||
SessionId,
|
||||
WIN_OBJ_DIR);
|
||||
}
|
||||
|
||||
/* Connect to the base server */
|
||||
DPRINT("Connecting to CSR in DllMain...\n");
|
||||
Status = CsrClientConnectToServer(SessionDir,
|
||||
BASESRV_SERVERDLL_INDEX,
|
||||
&Dummy,
|
||||
&DummySize,
|
||||
&BaseRunningInServerProcess);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to connect to CSR (Status %lx)\n", Status);
|
||||
NtTerminateProcess(NtCurrentProcess(), Status);
|
||||
return FALSE;
|
||||
}
|
||||
DPRINT("kernel32 DllMain - OK, connection succeeded\n");
|
||||
|
||||
/* Get the server data */
|
||||
ASSERT(Peb->ReadOnlyStaticServerData);
|
||||
BaseStaticServerData = Peb->ReadOnlyStaticServerData[BASESRV_SERVERDLL_INDEX];
|
||||
ASSERT(BaseStaticServerData);
|
||||
|
||||
/* Check if we are running a CSR Server */
|
||||
if (!BaseRunningInServerProcess)
|
||||
{
|
||||
/* Set the termination port for the thread */
|
||||
DPRINT("Creating new thread for CSR\n");
|
||||
CsrNewThread();
|
||||
}
|
||||
|
||||
/* Initialize heap handle table */
|
||||
BaseDllInitializeMemoryManager();
|
||||
|
||||
/* Set HMODULE for our DLL */
|
||||
kernel32_handle = hCurrentModule = hDll;
|
||||
|
||||
/* Set the directories */
|
||||
BaseWindowsDirectory = BaseStaticServerData->WindowsDirectory;
|
||||
BaseWindowsSystemDirectory = BaseStaticServerData->WindowsSystemDirectory;
|
||||
|
||||
/* Construct the default path (using the static buffer) */
|
||||
_snwprintf(BaseDefaultPathBuffer,
|
||||
sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR),
|
||||
L".;%wZ;%wZ\\system;%wZ;",
|
||||
&BaseWindowsSystemDirectory,
|
||||
&BaseWindowsDirectory,
|
||||
&BaseWindowsDirectory);
|
||||
|
||||
BaseDefaultPath.Buffer = BaseDefaultPathBuffer;
|
||||
BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
|
||||
BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer);
|
||||
|
||||
/* Use remaining part of the default path buffer for the append path */
|
||||
BaseDefaultPathAppend.Buffer = (PWSTR)((ULONG_PTR)BaseDefaultPathBuffer + BaseDefaultPath.Length);
|
||||
BaseDefaultPathAppend.Length = 0;
|
||||
BaseDefaultPathAppend.MaximumLength = BaseDefaultPath.MaximumLength - BaseDefaultPath.Length;
|
||||
|
||||
/* Initialize command line */
|
||||
InitCommandLines();
|
||||
|
||||
/* Initialize the DLL critical section */
|
||||
RtlInitializeCriticalSection(&BaseDllDirectoryLock);
|
||||
|
||||
/* Initialize the National Language Support routines */
|
||||
if (!NlsInit())
|
||||
{
|
||||
DPRINT1("NLS Init failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Initialize Console Support */
|
||||
if (!BasepInitConsole())
|
||||
{
|
||||
DPRINT1("Failed to set up console\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Initialize application certification globals */
|
||||
InitializeListHead(&BasepAppCertDllsList);
|
||||
RtlInitializeCriticalSection(&gcsAppCert);
|
||||
|
||||
/* Insert more dll attach stuff here! */
|
||||
DllInitialized = TRUE;
|
||||
DPRINT("Initialization complete\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use the session path */
|
||||
swprintf(SessionDir,
|
||||
L"%ws\\%ld%ws",
|
||||
SESSION_DIR,
|
||||
SessionId,
|
||||
WIN_OBJ_DIR);
|
||||
}
|
||||
|
||||
/* Connect to the base server */
|
||||
DPRINT("Connecting to CSR in DllMain...\n");
|
||||
Status = CsrClientConnectToServer(SessionDir,
|
||||
BASESRV_SERVERDLL_INDEX,
|
||||
&Dummy,
|
||||
&DummySize,
|
||||
&BaseRunningInServerProcess);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to connect to CSR (Status %lx)\n", Status);
|
||||
NtTerminateProcess(NtCurrentProcess(), Status);
|
||||
return FALSE;
|
||||
}
|
||||
DPRINT("kernel32 DllMain - OK, connection succeeded\n");
|
||||
|
||||
/* Get the server data */
|
||||
ASSERT(Peb->ReadOnlyStaticServerData);
|
||||
BaseStaticServerData = Peb->ReadOnlyStaticServerData[BASESRV_SERVERDLL_INDEX];
|
||||
ASSERT(BaseStaticServerData);
|
||||
|
||||
/* Check if we are running a CSR Server */
|
||||
if (!BaseRunningInServerProcess)
|
||||
{
|
||||
/* Set the termination port for the thread */
|
||||
DPRINT("Creating new thread for CSR\n");
|
||||
CsrNewThread();
|
||||
}
|
||||
|
||||
/* Initialize heap handle table */
|
||||
BaseDllInitializeMemoryManager();
|
||||
|
||||
/* Set HMODULE for our DLL */
|
||||
kernel32_handle = hCurrentModule = hDll;
|
||||
|
||||
/* Set the directories */
|
||||
BaseWindowsDirectory = BaseStaticServerData->WindowsDirectory;
|
||||
BaseWindowsSystemDirectory = BaseStaticServerData->WindowsSystemDirectory;
|
||||
|
||||
/* Construct the default path (using the static buffer) */
|
||||
_snwprintf(BaseDefaultPathBuffer, sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR),
|
||||
L".;%wZ;%wZ\\system;%wZ;", &BaseWindowsSystemDirectory, &BaseWindowsDirectory, &BaseWindowsDirectory);
|
||||
|
||||
BaseDefaultPath.Buffer = BaseDefaultPathBuffer;
|
||||
BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
|
||||
BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer);
|
||||
|
||||
/* Use remaining part of the default path buffer for the append path */
|
||||
BaseDefaultPathAppend.Buffer = (PWSTR)((ULONG_PTR)BaseDefaultPathBuffer + BaseDefaultPath.Length);
|
||||
BaseDefaultPathAppend.Length = 0;
|
||||
BaseDefaultPathAppend.MaximumLength = BaseDefaultPath.MaximumLength - BaseDefaultPath.Length;
|
||||
|
||||
/* Initialize command line */
|
||||
InitCommandLines();
|
||||
|
||||
/* Initialize the DLL critical section */
|
||||
RtlInitializeCriticalSection(&BaseDllDirectoryLock);
|
||||
|
||||
/* Initialize the National Language Support routines */
|
||||
if (!NlsInit())
|
||||
{
|
||||
DPRINT1("NLS Init failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Initialize Console Support */
|
||||
if (!BasepInitConsole())
|
||||
{
|
||||
DPRINT1("Failed to set up console\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Initialize application certification globals */
|
||||
InitializeListHead(&BasepAppCertDllsList);
|
||||
RtlInitializeCriticalSection(&gcsAppCert);
|
||||
|
||||
/* Insert more dll attach stuff here! */
|
||||
DllInitialized = TRUE;
|
||||
DPRINT("Initialization complete\n");
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
||||
{
|
||||
DPRINT("DLL_PROCESS_DETACH\n");
|
||||
if (DllInitialized == TRUE)
|
||||
{
|
||||
/* Insert more dll detach stuff here! */
|
||||
NlsUninit();
|
||||
|
||||
/* Uninitialize console support */
|
||||
BasepUninitConsole();
|
||||
|
||||
/* Delete DLL critical section */
|
||||
if (ConsoleInitialized == TRUE)
|
||||
{
|
||||
ConsoleInitialized = FALSE;
|
||||
RtlDeleteCriticalSection(&ConsoleLock);
|
||||
}
|
||||
RtlDeleteCriticalSection(&BaseDllDirectoryLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
63
dll/win32/kernel32/include/console.h
Normal file
63
dll/win32/kernel32/include/console.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS System Libraries
|
||||
* FILE: dll/win32/kernel32/include/console.h
|
||||
* PURPOSE: Console API Client Definitions
|
||||
* PROGRAMMER: Hermes Belusca - Maito
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* CONSTANTS ******************************************************************/
|
||||
|
||||
#define HANDLE_DETACHED_PROCESS (HANDLE)-2
|
||||
#define HANDLE_CREATE_NEW_CONSOLE (HANDLE)-3
|
||||
#define HANDLE_CREATE_NO_WINDOW (HANDLE)-4
|
||||
|
||||
|
||||
/* FUNCTION PROTOTYPES ********************************************************/
|
||||
|
||||
BOOL WINAPI
|
||||
BasepInitConsole(VOID);
|
||||
|
||||
VOID WINAPI
|
||||
BasepUninitConsole(VOID);
|
||||
|
||||
VOID WINAPI
|
||||
InitConsoleCtrlHandling(VOID);
|
||||
|
||||
HANDLE WINAPI
|
||||
DuplicateConsoleHandle(HANDLE hConsole,
|
||||
DWORD dwDesiredAccess,
|
||||
BOOL bInheritHandle,
|
||||
DWORD dwOptions);
|
||||
|
||||
BOOL WINAPI
|
||||
VerifyConsoleIoHandle(HANDLE Handle);
|
||||
|
||||
BOOL WINAPI
|
||||
CloseConsoleHandle(HANDLE Handle);
|
||||
|
||||
HANDLE WINAPI
|
||||
GetConsoleInputWaitHandle(VOID);
|
||||
|
||||
HANDLE FASTCALL
|
||||
TranslateStdHandle(HANDLE hHandle);
|
||||
|
||||
VOID
|
||||
InitConsoleProps(IN OUT PCONSOLE_PROPS ConsoleProps);
|
||||
|
||||
LPCWSTR
|
||||
IntCheckForConsoleFileName(IN LPCWSTR pszName,
|
||||
IN DWORD dwDesiredAccess);
|
||||
|
||||
HANDLE WINAPI
|
||||
OpenConsoleW(LPCWSTR wsName,
|
||||
DWORD dwDesiredAccess,
|
||||
BOOL bInheritHandle,
|
||||
DWORD dwShareMode);
|
||||
|
||||
BOOL WINAPI
|
||||
SetConsoleInputExeNameW(LPCWSTR lpInputExeName);
|
||||
|
||||
/* EOF */
|
|
@ -61,10 +61,6 @@
|
|||
#define FIELD_OFFSET(type,fld) ((LONG)&(((type *)0)->fld))
|
||||
#endif
|
||||
|
||||
#define HANDLE_DETACHED_PROCESS (HANDLE)-2
|
||||
#define HANDLE_CREATE_NEW_CONSOLE (HANDLE)-3
|
||||
#define HANDLE_CREATE_NO_WINDOW (HANDLE)-4
|
||||
|
||||
//
|
||||
// This stuff maybe should go in a vdm.h?
|
||||
//
|
||||
|
@ -187,33 +183,8 @@ VOID
|
|||
NTAPI
|
||||
BaseDllInitializeMemoryManager(VOID);
|
||||
|
||||
VOID WINAPI InitConsoleCtrlHandling(VOID);
|
||||
|
||||
BOOL WINAPI VerifyConsoleIoHandle(HANDLE Handle);
|
||||
|
||||
BOOL WINAPI CloseConsoleHandle(HANDLE Handle);
|
||||
|
||||
HANDLE WINAPI
|
||||
GetConsoleInputWaitHandle(VOID);
|
||||
|
||||
VOID
|
||||
InitConsoleProps(IN OUT PCONSOLE_PROPS ConsoleProps);
|
||||
|
||||
LPCWSTR
|
||||
IntCheckForConsoleFileName(IN LPCWSTR pszName,
|
||||
IN DWORD dwDesiredAccess);
|
||||
|
||||
HANDLE WINAPI OpenConsoleW(LPCWSTR wsName,
|
||||
DWORD dwDesiredAccess,
|
||||
BOOL bInheritHandle,
|
||||
DWORD dwShareMode);
|
||||
|
||||
BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR lpInputExeName);
|
||||
|
||||
PTEB GetTeb(VOID);
|
||||
|
||||
HANDLE FASTCALL TranslateStdHandle(HANDLE hHandle);
|
||||
|
||||
PWCHAR FilenameA2W(LPCSTR NameA, BOOL alloc);
|
||||
DWORD FilenameW2A_N(LPSTR dest, INT destlen, LPCWSTR src, INT srclen);
|
||||
|
||||
|
@ -431,13 +402,6 @@ BaseSetLastNTError(IN NTSTATUS Status);
|
|||
/* FIXME */
|
||||
WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *);
|
||||
|
||||
HANDLE
|
||||
WINAPI
|
||||
DuplicateConsoleHandle(HANDLE hConsole,
|
||||
DWORD dwDesiredAccess,
|
||||
BOOL bInheritHandle,
|
||||
DWORD dwOptions);
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
BasepLocateExeLdrEntry(IN PLDR_DATA_TABLE_ENTRY Entry,
|
||||
|
|
|
@ -70,4 +70,7 @@
|
|||
/* Base Macros */
|
||||
#include "include/base_x.h"
|
||||
|
||||
/* Console API Client Definitions */
|
||||
#include "include/console.h"
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue