2005-01-06 13:34:15 +00:00
|
|
|
/* $Id$
|
2000-02-27 02:12:07 +00:00
|
|
|
*
|
1998-12-04 18:28:13 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/kernel32/misc/dllmain.c
|
2005-05-09 01:46:57 +00:00
|
|
|
* PURPOSE: Initialization
|
1998-12-04 18:28:13 +00:00
|
|
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 01/11/98
|
|
|
|
*/
|
|
|
|
|
2001-04-04 22:21:32 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
1999-04-10 12:08:24 +00:00
|
|
|
|
1999-04-14 00:52:19 +00:00
|
|
|
#define NDEBUG
|
2004-01-23 21:16:04 +00:00
|
|
|
#include "../include/debug.h"
|
1998-12-04 18:28:13 +00:00
|
|
|
|
2001-04-04 22:21:32 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2000-08-15 12:44:47 +00:00
|
|
|
|
|
|
|
extern UNICODE_STRING SystemDirectory;
|
|
|
|
extern UNICODE_STRING WindowsDirectory;
|
|
|
|
|
2001-01-20 12:20:43 +00:00
|
|
|
HANDLE hProcessHeap = NULL;
|
2004-06-26 20:07:40 +00:00
|
|
|
HMODULE hCurrentModule = NULL;
|
2001-01-20 18:37:58 +00:00
|
|
|
HANDLE hBaseDir = NULL;
|
2001-01-20 12:20:43 +00:00
|
|
|
|
2004-01-23 17:18:16 +00:00
|
|
|
static BOOL DllInitialized = FALSE;
|
2000-08-15 12:44:47 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
DllMain(HANDLE hInst,
|
|
|
|
DWORD dwReason,
|
|
|
|
LPVOID lpReserved);
|
1998-12-04 18:28:13 +00:00
|
|
|
|
2001-04-04 22:21:32 +00:00
|
|
|
/* Critical section for various kernel32 data structures */
|
2005-01-03 23:02:15 +00:00
|
|
|
RTL_CRITICAL_SECTION DllLock;
|
|
|
|
RTL_CRITICAL_SECTION ConsoleLock;
|
2001-04-04 22:21:32 +00:00
|
|
|
|
2003-08-18 10:47:04 +00:00
|
|
|
extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event);
|
|
|
|
|
2004-08-24 17:21:12 +00:00
|
|
|
extern BOOL FASTCALL NlsInit();
|
|
|
|
extern VOID FASTCALL NlsUninit();
|
|
|
|
|
2001-04-04 22:21:32 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
1998-12-04 18:28:13 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
static NTSTATUS
|
2001-04-04 22:21:32 +00:00
|
|
|
OpenBaseDirectory(PHANDLE DirHandle)
|
2001-01-20 18:37:58 +00:00
|
|
|
{
|
2003-03-05 22:51:48 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2005-06-20 04:18:03 +00:00
|
|
|
UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\BaseNamedObjects");
|
2003-03-05 22:51:48 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Name,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenDirectoryObject(DirHandle,
|
|
|
|
DIRECTORY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = NtCreateDirectoryObject(DirHandle,
|
|
|
|
DIRECTORY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DbgPrint("NtCreateDirectoryObject() failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
2001-01-20 18:37:58 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2001-01-20 18:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
DllMain(HANDLE hDll,
|
|
|
|
DWORD dwReason,
|
2001-04-04 22:21:32 +00:00
|
|
|
LPVOID lpReserved)
|
1998-12-04 18:28:13 +00:00
|
|
|
{
|
2003-03-05 22:51:48 +00:00
|
|
|
NTSTATUS Status;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
(void)lpReserved;
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
|
2004-02-22 17:30:33 +00:00
|
|
|
hDll, dwReason);
|
2003-03-05 22:51:48 +00:00
|
|
|
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
1999-04-10 12:08:24 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-03-05 22:51:48 +00:00
|
|
|
DPRINT("DLL_PROCESS_ATTACH\n");
|
|
|
|
|
|
|
|
LdrDisableThreadCalloutsForDll ((PVOID)hDll);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Connect to the csrss server
|
|
|
|
*/
|
Large change to modify NTDLL'S CSR Functions to be compatible with NT. They are external and we should at least try to match the number of arguments (one vs eight? come on!). Because this is also the direction that Emanuele wants to be taking, the whole external calling interface was modified to be more compatible with NT (although internally it still isn't, and does not have a reason to be). API Names are now generated by a macro from the Server ID, like Emanuele and I noticed from traces, and I've entirely removed the concept of a reply structure. CSRSS uses full-duplex one-way structures, not dual-strutures (this would've been incompatible with the external interface anyways). I don't seem to have introduced any new bugs (console-ROS works great for me, as does the GUI), but there is still a chance some obscure bug might happen, so please bear with me, I had to hand-edit over 250 calls. Also, this now allows full removal of ntdll headers and the next commits will clean this up
svn path=/trunk/; revision=16213
2005-06-22 04:02:32 +00:00
|
|
|
Status = CsrClientConnectToServer(NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
2003-03-05 22:51:48 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2000-02-27 02:12:07 +00:00
|
|
|
{
|
2003-03-05 22:51:48 +00:00
|
|
|
DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
|
|
|
|
Status);
|
|
|
|
ZwTerminateProcess(NtCurrentProcess(), Status);
|
|
|
|
return FALSE;
|
1999-04-10 12:08:24 +00:00
|
|
|
}
|
2003-03-05 22:51:48 +00:00
|
|
|
|
|
|
|
hProcessHeap = RtlGetProcessHeap();
|
2004-06-26 20:07:40 +00:00
|
|
|
hCurrentModule = hDll;
|
2003-03-05 22:51:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize WindowsDirectory and SystemDirectory
|
|
|
|
*/
|
|
|
|
DPRINT("NtSystemRoot: %S\n",
|
|
|
|
SharedUserData->NtSystemRoot);
|
|
|
|
RtlCreateUnicodeString (&WindowsDirectory,
|
|
|
|
SharedUserData->NtSystemRoot);
|
|
|
|
SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
|
|
|
|
SystemDirectory.Length = WindowsDirectory.Length + 18;
|
|
|
|
SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
|
|
|
|
0,
|
|
|
|
SystemDirectory.MaximumLength);
|
|
|
|
wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
|
|
|
|
wcscat (SystemDirectory.Buffer, L"\\System32");
|
|
|
|
|
|
|
|
/* Open object base directory */
|
|
|
|
Status = OpenBaseDirectory(&hBaseDir);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DbgPrint("Failed to open object base directory (Status %lx)\n",
|
|
|
|
Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the DLL critical section */
|
|
|
|
RtlInitializeCriticalSection(&DllLock);
|
2003-08-18 10:47:04 +00:00
|
|
|
|
2004-08-24 17:21:12 +00:00
|
|
|
/* Initialize the National Language Support routines */
|
|
|
|
if (! NlsInit())
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-08-18 10:47:04 +00:00
|
|
|
/* Initialize console ctrl handler */
|
2003-08-16 06:19:15 +00:00
|
|
|
RtlInitializeCriticalSection(&ConsoleLock);
|
2003-08-18 10:47:04 +00:00
|
|
|
SetConsoleCtrlHandler(DefaultConsoleCtrlHandler, TRUE);
|
2003-03-05 22:51:48 +00:00
|
|
|
|
|
|
|
|
2005-03-15 19:40:22 +00:00
|
|
|
/* Insert more dll attach stuff here! */
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
DllInitialized = TRUE;
|
|
|
|
break;
|
|
|
|
|
1999-04-10 12:08:24 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
2003-03-05 22:51:48 +00:00
|
|
|
DPRINT("DLL_PROCESS_DETACH\n");
|
|
|
|
if (DllInitialized == TRUE)
|
1999-04-10 12:08:24 +00:00
|
|
|
{
|
2003-03-05 22:51:48 +00:00
|
|
|
/* Insert more dll detach stuff here! */
|
|
|
|
|
2004-08-24 17:21:12 +00:00
|
|
|
NlsUninit();
|
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
/* Delete DLL critical section */
|
2003-08-16 06:19:15 +00:00
|
|
|
RtlDeleteCriticalSection (&ConsoleLock);
|
2003-03-05 22:51:48 +00:00
|
|
|
RtlDeleteCriticalSection (&DllLock);
|
|
|
|
|
|
|
|
/* Close object base directory */
|
|
|
|
NtClose(hBaseDir);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString (&SystemDirectory);
|
|
|
|
RtlFreeUnicodeString (&WindowsDirectory);
|
1999-04-10 12:08:24 +00:00
|
|
|
}
|
2003-03-05 22:51:48 +00:00
|
|
|
break;
|
|
|
|
|
1999-04-10 12:08:24 +00:00
|
|
|
default:
|
1998-12-04 18:28:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-03-05 22:51:48 +00:00
|
|
|
|
2000-02-27 02:12:07 +00:00
|
|
|
return TRUE;
|
1998-12-04 18:28:13 +00:00
|
|
|
}
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2000-03-22 18:36:00 +00:00
|
|
|
/* EOF */
|