dllmain.c 1.8 KB

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