ReactOS  0.4.14-dev-55-g2da92ac
load_notifications.c
Go to the documentation of this file.
1 #define WIN32_NO_STATUS
2 #define _INC_WINDOWS
3 #define COM_NO_WINDOWS_H
4 
5 #include <windows.h>
6 
7 
8 #if defined(_MSC_VER)
9 #define _CRTALLOC(x) __declspec(allocate(x))
10 #elif defined(__GNUC__)
11 #define _CRTALLOC(x) __attribute__ ((section (x) ))
12 #else
13 #error Your compiler is not supported.
14 #endif
15 
16 
17 static VOID (WINAPI* pTlsCallback)(IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved);
18 
20 TlsCallback(IN HANDLE hDllHandle,
23 {
24  if (!pTlsCallback)
25  pTlsCallback = (VOID*)GetProcAddress(NULL, "notify_TlsCallback");
26  if (pTlsCallback)
27  {
28  pTlsCallback(hDllHandle, dwReason, lpvReserved);
29  return;
30  }
31  OutputDebugStringA("WARNING: load_notifications.dll loaded from a process without notify_TlsCallback\n");
32 }
33 
34 /* Tls magic stolen from sdk/lib/crt/startup/tlssup.c */
35 
36 #if defined(_MSC_VER)
37 #pragma section(".rdata$T",long,read)
38 #pragma section(".tls",long,read,write)
39 #pragma section(".tls$ZZZ",long,read,write)
40 #endif
41 
42 _CRTALLOC(".tls") char _tls_start = 0;
43 _CRTALLOC(".tls$ZZZ") char _tls_end = 0;
44 
45 PIMAGE_TLS_CALLBACK __xl_a[2] = { &TlsCallback, NULL };
46 
48 
49 _CRTALLOC(".rdata$T") const IMAGE_TLS_DIRECTORY _tls_used = {
50  (ULONG_PTR) &_tls_start+1, (ULONG_PTR) &_tls_end,
51  (ULONG_PTR) &_tls_index, (ULONG_PTR) (__xl_a),
52  (ULONG) 0, (ULONG) 0
53 };
54 
55 
56 static BOOL (WINAPI* pDllMain)(IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved);
57 
58 
60 DllMain(IN HINSTANCE hDllHandle,
63 {
64  if (!pDllMain)
65  pDllMain = (VOID*)GetProcAddress(NULL, "notify_DllMain");
66  if (pDllMain)
67  {
68  return pDllMain(hDllHandle, dwReason, lpvReserved);
69  }
70  OutputDebugStringA("WARNING: load_notifications.dll loaded from a process without notify_DllMain\n");
71  return TRUE;
72 }
static BOOL(WINAPI *pDllMain)(IN HINSTANCE hDllHandle
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
static IN DWORD IN LPVOID lpvReserved
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID(NTAPI * PIMAGE_TLS_CALLBACK)(PVOID DllHandle, ULONG Reason, PVOID Reserved)
Definition: ntimage.h:531
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
VOID WINAPI TlsCallback(IN HANDLE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
unsigned char
Definition: typeof.h:29
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static IN DWORD dwReason
BOOL WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD dwReason, IN LPVOID lpvReserved)
ULONG _tls_index
static VOID(WINAPI *pTlsCallback)(IN HINSTANCE hDllHandle
_CRTALLOC(".tls")
unsigned int ULONG
Definition: retypes.h:1
#define const
Definition: zconf.h:230
#define ULONG_PTR
Definition: config.h:101
#define GetProcAddress(x, y)
Definition: compat.h:410
static DWORD tls
Definition: sock.c:230
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18