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
19 VOID WINAPI
TlsCallback(IN HANDLE hDllHandle,IN DWORD dwReason,IN LPVOID lpvReserved)20 TlsCallback(IN HANDLE hDllHandle,
21 IN DWORD dwReason,
22 IN LPVOID lpvReserved)
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
47 ULONG _tls_index = 0;
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
59 BOOL WINAPI
DllMain(IN HINSTANCE hDllHandle,IN DWORD dwReason,IN LPVOID lpvReserved)60 DllMain(IN HINSTANCE hDllHandle,
61 IN DWORD dwReason,
62 IN LPVOID lpvReserved)
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 }
73