ReactOS 0.4.15-dev-7958-gcd0bb1a
dllmain.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for dllmain.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define WIN_OBJ_DIR   L"\\Windows"
 
#define SESSION_DIR   L"\\Sessions"
 

Functions

BOOL FASTCALL NlsInit (VOID)
 
VOID FASTCALL NlsUninit (VOID)
 
NTSTATUS NTAPI BaseCreateThreadPoolThread (IN PTHREAD_START_ROUTINE Function, IN PVOID Parameter, OUT PHANDLE ThreadHandle)
 
NTSTATUS NTAPI BaseExitThreadPoolThread (IN NTSTATUS ExitStatus)
 
BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
 

Variables

PBASE_STATIC_SERVER_DATA BaseStaticServerData
 
BOOLEAN BaseRunningInServerProcess = FALSE
 
WCHAR BaseDefaultPathBuffer [6140]
 
HANDLE BaseNamedObjectDirectory
 
HMODULE hCurrentModule = NULL
 
HMODULE kernel32_handle = NULL
 
PPEB Peb
 
ULONG SessionId
 
static BOOL DllInitialized = FALSE
 
RTL_CRITICAL_SECTION BaseDllDirectoryLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file dllmain.c.

◆ SESSION_DIR

#define SESSION_DIR   L"\\Sessions"

Definition at line 38 of file dllmain.c.

◆ WIN_OBJ_DIR

#define WIN_OBJ_DIR   L"\\Windows"

Definition at line 37 of file dllmain.c.

Function Documentation

◆ BaseCreateThreadPoolThread()

NTSTATUS NTAPI BaseCreateThreadPoolThread ( IN PTHREAD_START_ROUTINE  Function,
IN PVOID  Parameter,
OUT PHANDLE  ThreadHandle 
)

Definition at line 44 of file dllmain.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
Status
Definition: gdiplustypes.h:25
#define NtCurrentTeb
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CREATE_SUSPENDED
Definition: winbase.h:178
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323

Referenced by DllMain().

◆ BaseExitThreadPoolThread()

NTSTATUS NTAPI BaseExitThreadPoolThread ( IN NTSTATUS  ExitStatus)

Definition at line 76 of file dllmain.c.

77{
78 /* Exit the thread */
80 return STATUS_SUCCESS;
81}
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:867

Referenced by DllMain().

◆ DllMain()

BOOL WINAPI DllMain ( HANDLE  hDll,
DWORD  dwReason,
LPVOID  lpReserved 
)

Definition at line 85 of file dllmain.c.

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}
#define NtCurrentPeb()
Definition: FLS.c:22
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:154
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#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
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
PRTL_CONVERT_STRING Basep8BitStringToUnicodeString
Definition: utils.c:26
#define swprintf
Definition: precomp.h:40
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI BaseDllInitializeMemoryManager(VOID)
Definition: heapmem.c:26
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI PVOID WINAPI RtlEncodePointer(PVOID)
VOID NTAPI LdrSetDllManifestProber(_In_ PLDR_MANIFEST_PROBER_ROUTINE Routine)
Definition: ldrapi.c:73
NTSTATUS NTAPI LdrDisableThreadCalloutsForDll(_In_ PVOID BaseAddress)
Definition: ldrapi.c:1194
#define ASSERT(a)
Definition: mode.c:44
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)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
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 DPRINT
Definition: sndvol32.h:71
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ NlsInit()

BOOL FASTCALL NlsInit ( VOID  )

Definition at line 151 of file nls.c.

152{
159
162
163 /*
164 * FIXME: Eventually this should be done only for the NLS Server
165 * process, but since we don't have anything like that (yet?) we
166 * always try to create the "\NLS" directory here.
167 */
169
170 /* Create a security descriptor for the NLS directory */
172 sizeof(SecurityDescriptor));
173 if (!NT_SUCCESS(Status))
174 {
175 DPRINT1("Failed to create NLS directory security (Status 0x%08x)\n", Status);
176 return FALSE;
177 }
178
180 &DirName,
182 NULL,
184
188 if (NT_SUCCESS(Status))
189 {
191 }
192
193 /* Setup ANSI code page. */
195 AnsiCodePage.SectionMapping = NtCurrentTeb()->ProcessEnvironmentBlock->AnsiCodePageData;
196
200
202
203 /* Setup OEM code page. */
205 OemCodePage.SectionMapping = NtCurrentTeb()->ProcessEnvironmentBlock->OemCodePageData;
206
211
212 return TRUE;
213}
#define NLS_SIZEOF_ACE_AND_SIDS(n)
Definition: base.h:26
#define NLS_SECTION_SECURITY_DESCRIPTOR_SIZE
Definition: base.h:31
_In_ PFCB _In_ PCD_NAME DirName
Definition: cdprocs.h:737
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
static CODEPAGE_ENTRY AnsiCodePage
Definition: nls.c:46
static RTL_CRITICAL_SECTION CodePageListLock
Definition: nls.c:48
static NTSTATUS CreateNlsDirectorySecurity(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ SIZE_T DescriptorSize)
Creates a security descriptor for the NLS object directory.
Definition: nls.c:81
static CODEPAGE_ENTRY OemCodePage
Definition: nls.c:47
static LIST_ENTRY CodePageListHead
Definition: nls.c:45
#define InsertTailList(ListHead, Entry)
ULONG Handle
Definition: gdb_input.c:15
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:765
VOID NTAPI RtlInitCodePageTable(IN PUSHORT TableBase, OUT PCPTABLEINFO CodePageTable)
Definition: nls.c:155
UINT CodePage
Definition: kernel32.h:65
LIST_ENTRY Entry
Definition: kernel32.h:64
HANDLE SectionHandle
Definition: kernel32.h:66
CPTABLEINFO CodePageTable
Definition: kernel32.h:68
PBYTE SectionMapping
Definition: kernel32.h:67
USHORT CodePage
Definition: precomp.h:32
uint16_t * PUSHORT
Definition: typedefs.h:56
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DllMain().

◆ NlsUninit()

VOID FASTCALL NlsUninit ( VOID  )

Definition at line 223 of file nls.c.

224{
225 PCODEPAGE_ENTRY Current;
226
227 /* Delete the code page list. */
229 {
231 if (Current->SectionHandle != NULL)
232 {
234 NtClose(Current->SectionHandle);
235 }
237 }
239}
#define UnmapViewOfFile
Definition: compat.h:746
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
base of all file and directory entries
Definition: entries.h:83
Definition: kernel32.h:63
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by DllMain().

Variable Documentation

◆ BaseDefaultPathBuffer

WCHAR BaseDefaultPathBuffer[6140]

Definition at line 22 of file dllmain.c.

Referenced by DllMain().

◆ BaseDllDirectoryLock

◆ BaseNamedObjectDirectory

HANDLE BaseNamedObjectDirectory

Definition at line 24 of file dllmain.c.

Referenced by BaseGetNamedObjectDirectory().

◆ BaseRunningInServerProcess

BOOLEAN BaseRunningInServerProcess = FALSE

◆ BaseStaticServerData

◆ DllInitialized

BOOL DllInitialized = FALSE
static

Definition at line 29 of file dllmain.c.

Referenced by DllMain().

◆ hCurrentModule

HMODULE hCurrentModule = NULL

Definition at line 25 of file dllmain.c.

Referenced by DllMain(), and GetLocalisedText().

◆ kernel32_handle

◆ Peb

◆ SessionId