Fix EBCDIC problem in conf_def.h
[openssl.git] / crypto / dllmain.c
1 #include "internal/cryptlib_int.h"
2
3 #if defined(_WIN32) || defined(__CYGWIN__)
4 # ifdef __CYGWIN__
5 /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */
6 #  include <windows.h>
7 /*
8  * this has side-effect of _WIN32 getting defined, which otherwise is
9  * mutually exclusive with __CYGWIN__...
10  */
11 # endif
12
13 /*
14  * All we really need to do is remove the 'error' state when a thread
15  * detaches
16  */
17
18 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
19 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
20 {
21     switch (fdwReason) {
22     case DLL_PROCESS_ATTACH:
23         OPENSSL_cpuid_setup();
24 # if defined(_WIN32_WINNT)
25         {
26             IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *) hinstDLL;
27             IMAGE_NT_HEADERS *nt_headers;
28
29             if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
30                 nt_headers = (IMAGE_NT_HEADERS *) ((char *)dos_header
31                                                    + dos_header->e_lfanew);
32                 if (nt_headers->Signature == IMAGE_NT_SIGNATURE &&
33                     hinstDLL !=
34                     (HINSTANCE) (nt_headers->OptionalHeader.ImageBase))
35                     OPENSSL_NONPIC_relocated = 1;
36             }
37         }
38 # endif
39         break;
40     case DLL_THREAD_ATTACH:
41         break;
42     case DLL_THREAD_DETACH:
43         OPENSSL_thread_stop();
44         break;
45     case DLL_PROCESS_DETACH:
46         break;
47     }
48     return (TRUE);
49 }
50 #endif
51