Rich Salz | b132225 | 2016-05-17 14:52:22 -0400 | [diff] [blame] | 1 | /* |
Pauli | 677963e | 2017-08-18 13:52:46 +1000 | [diff] [blame] | 2 | * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. |
Rich Salz | b132225 | 2016-05-17 14:52:22 -0400 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use |
| 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
| 8 | */ |
| 9 | |
Pauli | 677963e | 2017-08-18 13:52:46 +1000 | [diff] [blame] | 10 | #include "e_os.h" |
Pauli | 07016a8 | 2017-08-24 09:05:07 +1000 | [diff] [blame] | 11 | #include "internal/cryptlib_int.h" |
Richard Levitte | 84af71a | 2016-03-29 16:48:02 +0200 | [diff] [blame] | 12 | |
| 13 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 14 | # ifdef __CYGWIN__ |
| 15 | /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */ |
| 16 | # include <windows.h> |
| 17 | /* |
| 18 | * this has side-effect of _WIN32 getting defined, which otherwise is |
| 19 | * mutually exclusive with __CYGWIN__... |
| 20 | */ |
| 21 | # endif |
| 22 | |
| 23 | /* |
| 24 | * All we really need to do is remove the 'error' state when a thread |
| 25 | * detaches |
| 26 | */ |
| 27 | |
| 28 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); |
| 29 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) |
| 30 | { |
| 31 | switch (fdwReason) { |
| 32 | case DLL_PROCESS_ATTACH: |
| 33 | OPENSSL_cpuid_setup(); |
| 34 | # if defined(_WIN32_WINNT) |
| 35 | { |
| 36 | IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *) hinstDLL; |
| 37 | IMAGE_NT_HEADERS *nt_headers; |
| 38 | |
| 39 | if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) { |
| 40 | nt_headers = (IMAGE_NT_HEADERS *) ((char *)dos_header |
| 41 | + dos_header->e_lfanew); |
| 42 | if (nt_headers->Signature == IMAGE_NT_SIGNATURE && |
| 43 | hinstDLL != |
| 44 | (HINSTANCE) (nt_headers->OptionalHeader.ImageBase)) |
| 45 | OPENSSL_NONPIC_relocated = 1; |
| 46 | } |
| 47 | } |
| 48 | # endif |
| 49 | break; |
| 50 | case DLL_THREAD_ATTACH: |
| 51 | break; |
| 52 | case DLL_THREAD_DETACH: |
| 53 | OPENSSL_thread_stop(); |
| 54 | break; |
| 55 | case DLL_PROCESS_DETACH: |
| 56 | break; |
| 57 | } |
KaoruToda | 26a7d93 | 2017-10-17 23:04:09 +0900 | [diff] [blame] | 58 | return TRUE; |
Richard Levitte | 84af71a | 2016-03-29 16:48:02 +0200 | [diff] [blame] | 59 | } |
| 60 | #endif |
| 61 | |