ReactOS 0.4.16-dev-303-g11d5cb8
dllmain.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/dllmain.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Ariadne (ariadne@xs4all.nl)
7 * Aleksey Bragin (aleksey@reactos.org)
8 */
9
10/* INCLUDES ******************************************************************/
11
12#include <k32.h>
13
14#define NDEBUG
15#include <debug.h>
16
17/* GLOBALS *******************************************************************/
18
21
23
30
31/* Critical section for various kernel32 data structures */
33
36
37#define WIN_OBJ_DIR L"\\Windows"
38#define SESSION_DIR L"\\Sessions"
39
40/* FUNCTIONS *****************************************************************/
41
46 OUT PHANDLE ThreadHandle)
47{
49
50 /* Create a Win32 thread */
51 *ThreadHandle = CreateRemoteThread(NtCurrentProcess(),
52 NULL,
53 0,
57 NULL);
58 if (!(*ThreadHandle))
59 {
60 /* Get the status value if we couldn't get a handle */
61 Status = NtCurrentTeb()->LastStatusValue;
63 }
64 else
65 {
66 /* Set success code */
68 }
69
70 /* All done */
71 return Status;
72}
73
77{
78 /* Exit the thread */
80 return STATUS_SUCCESS;
81}
82
83BOOL
87 LPVOID lpReserved)
88{
90 BASESRV_API_CONNECTINFO ConnectInfo;
91 ULONG ConnectInfoSize = sizeof(ConnectInfo);
92 WCHAR SessionDir[256];
93
94 DPRINT("DllMain(hInst %p, dwReason %lu)\n",
95 hDll, dwReason);
96
98
99 /* Cache the PEB and Session ID */
100 Peb = NtCurrentPeb();
102
103 switch (dwReason)
104 {
106 {
107 /* Set no filter initially */
109
110 /* Enable the Rtl thread pool and timer queue to use proper Win32 thread */
112
113 /* Register the manifest prober routine */
115
116 /* Don't bother us for each thread */
118
119 /* Initialize default path to NULL */
121
122 /* Setup the Object Directory path */
123 if (!SessionId)
124 {
125 /* Use the raw path */
126 wcscpy(SessionDir, WIN_OBJ_DIR);
127 }
128 else
129 {
130 /* Use the session path */
131 swprintf(SessionDir,
132 L"%ws\\%ld%ws",
134 SessionId,
136 }
137
138 /* Connect to the Base Server */
139 Status = CsrClientConnectToServer(SessionDir,
141 &ConnectInfo,
142 &ConnectInfoSize,
144 if (!NT_SUCCESS(Status))
145 {
146 DPRINT1("Failed to connect to CSR (Status %lx)\n", Status);
148 return FALSE;
149 }
150
151 /* Get the server data */
155
156 /* Check if we are running a CSR Server */
158 {
159 /* Set the termination port for the thread */
160 DPRINT("Creating new thread for CSR\n");
161 CsrNewThread();
162 }
163
164 /* Initialize heap handle table */
166
167 /* Set HMODULE for our DLL */
169
170 /* Set the directories */
173
174 /* Construct the default path (using the static buffer) */
176 sizeof(BaseDefaultPathBuffer),
177 L"%wZ;%wZ\\system;%wZ;",
181 if (!NT_SUCCESS(Status))
182 {
183 DPRINT1("NLS Init failed\n");
184 return FALSE;
185 }
186
190
191 /* Use remaining part of the default path buffer for the append path */
195
196 /* Initialize command line */
198
199 /* Initialize the DLL critical section */
201
202 /* Initialize the National Language Support routines */
203 if (!NlsInit())
204 {
205 DPRINT1("NLS Init failed\n");
206 return FALSE;
207 }
208
209 /* Initialize Console Support */
210 if (!ConDllInitialize(dwReason, SessionDir))
211 {
212 DPRINT1("Failed to set up console\n");
213 return FALSE;
214 }
215
216 /* Initialize application certification globals */
219
220 /* Insert more dll attach stuff here! */
222 break;
223 }
224
226 {
227 if (DllInitialized != FALSE)
228 {
229 /* Uninitialize console support */
231
232 /* Insert more dll detach stuff here! */
233 NlsUninit();
234
235 /* Delete DLL critical section */
237 }
238 break;
239 }
240
242 {
243 /* ConDllInitialize sets the current console locale for the new thread */
245 }
246
247 default:
248 break;
249 }
250
251 return TRUE;
252}
253
254/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:141
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition: dllmain.c:52
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
NTSTATUS NTAPI BasepProbeForDllManifest(IN PVOID DllHandle, IN PCWSTR FullDllName, OUT PVOID *ActCtx)
Definition: actctx.c:136
BOOLEAN WINAPI ConDllInitialize(IN ULONG Reason, IN PWSTR SessionDir)
Definition: init.c:338
WCHAR BaseDefaultPathBuffer[6140]
Definition: dllmain.c:22
VOID FASTCALL NlsUninit(VOID)
Definition: nls.c:223
static BOOL DllInitialized
Definition: dllmain.c:29
ULONG SessionId
Definition: dllmain.c:28
PPEB Peb
Definition: dllmain.c:27
NTSTATUS NTAPI BaseCreateThreadPoolThread(IN PTHREAD_START_ROUTINE Function, IN PVOID Parameter, OUT PHANDLE ThreadHandle)
Definition: dllmain.c:44
#define SESSION_DIR
Definition: dllmain.c:38
BOOL FASTCALL NlsInit(VOID)
Definition: nls.c:151
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
HANDLE BaseNamedObjectDirectory
Definition: dllmain.c:24
RTL_CRITICAL_SECTION BaseDllDirectoryLock
Definition: dllmain.c:32
HMODULE hCurrentModule
Definition: dllmain.c:25
#define WIN_OBJ_DIR
Definition: dllmain.c:37
HMODULE kernel32_handle
Definition: dllmain.c:26
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
NTSTATUS NTAPI BaseExitThreadPoolThread(IN NTSTATUS ExitStatus)
Definition: dllmain.c:76
LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter
Definition: except.c:165
UNICODE_STRING BaseWindowsDirectory
Definition: path.c:20
UNICODE_STRING BaseDefaultPathAppend
Definition: path.c:21
UNICODE_STRING BaseWindowsSystemDirectory
Definition: path.c:20
UNICODE_STRING BaseDefaultPath
Definition: path.c:21
RTL_CRITICAL_SECTION gcsAppCert
Definition: proc.c:29
LIST_ENTRY BasepAppCertDllsList
Definition: proc.c:28
VOID WINAPI InitCommandLines(VOID)
Definition: proc.c:842
HANDLE WINAPI CreateRemoteThread(IN HANDLE hProcess, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:159
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
PRTL_CONVERT_STRING Basep8BitStringToUnicodeString
Definition: utils.c:26
#define swprintf
Definition: precomp.h:40
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
VOID NTAPI BaseDllInitializeMemoryManager(VOID)
Definition: heapmem.c:26
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI PVOID WINAPI RtlEncodePointer(PVOID)
#define NtCurrentTeb
VOID NTAPI LdrSetDllManifestProber(_In_ PLDR_MANIFEST_PROBER_ROUTINE Routine)
Definition: ldrapi.c:73
NTSTATUS NTAPI LdrDisableThreadCalloutsForDll(_In_ PVOID BaseAddress)
Definition: ldrapi.c:1154
#define ASSERT(a)
Definition: mode.c:44
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:867
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS NTAPI RtlSetThreadPoolStartFunc(_In_ PRTL_START_POOL_THREAD StartPoolThread, _In_ PRTL_EXIT_POOL_THREAD ExitPoolThread)
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
ULONG(NTAPI * PTHREAD_START_ROUTINE)(PVOID Parameter)
Definition: rtltypes.h:566
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FASTCALL
Definition: nt_native.h:50
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSTATUS NTAPI CsrNewThread(VOID)
Definition: api.c:26
NTSTATUS NTAPI CsrClientConnectToServer(_In_ PCWSTR ObjectDirectory, _In_ ULONG ServerId, _In_ PVOID ConnectionInfo, _Inout_ PULONG ConnectionInfoSize, _Out_ PBOOLEAN ServerToServerCall)
Definition: connect.c:196
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
UNICODE_STRING WindowsDirectory
Definition: base.h:121
UNICODE_STRING WindowsSystemDirectory
Definition: base.h:122
ULONG SessionId
Definition: btrfs_drv.h:1919
PVOID * ReadOnlyStaticServerData
Definition: ntddk_ex.h:263
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CREATE_SUSPENDED
Definition: winbase.h:181
#define WINAPI
Definition: msvc.h:6
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336
__wchar_t WCHAR
Definition: xmlstorage.h:180