Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. dllentry.c
  5. Abstract:
  6. This module contains VdmDbgDllEntry, the entrypoint for
  7. vdmdbg.dll. We don't use CRT to speak of, if that changes
  8. this should be renamed DllMain, which DLLMainCRTStartup calls.
  9. Also in that case DisableThreadLibraryCalls may be inappropriate.
  10. Author:
  11. Dave Hart (davehart) 26-Oct-97 Added DllEntry to fix leak
  12. in repeated load/unloads.
  13. Revision History:
  14. --*/
  15. #include <precomp.h>
  16. #pragma hdrstop
  17. #include <sharewow.h>
  18. BOOL
  19. VdmDbgDllEntry(
  20. IN PVOID DllHandle,
  21. IN ULONG Reason,
  22. IN PCONTEXT Context OPTIONAL
  23. )
  24. /*++
  25. Routine Description:
  26. This function is the "entry point" for the DLL, called with
  27. process and thread attach and detach messages. We disable
  28. thread attach and detach notifications since we don't use them.
  29. The primary reason for this is to clean up open handles to
  30. the shared memory and associated mutex at process detach, so
  31. folks who load and unload vdmdbg.dll repeatedly won't leak.
  32. Arguments:
  33. DllHandle
  34. Reason
  35. Context - Not Used
  36. Return Value:
  37. STATUS_SUCCESS
  38. --*/
  39. {
  40. switch ( Reason ) {
  41. case DLL_PROCESS_ATTACH:
  42. DisableThreadLibraryCalls(DllHandle);
  43. break;
  44. case DLL_PROCESS_DETACH:
  45. //
  46. // Close handles to shared memory and mutex, if we're
  47. // being unloaded from the process (Context/lpReserved
  48. // NULL) as opposed to process shutdown (Context 1)
  49. //
  50. if (! Context) {
  51. if (hSharedWOWMutex) {
  52. CloseHandle(hSharedWOWMutex);
  53. hSharedWOWMutex = NULL;
  54. }
  55. if (lpSharedWOWMem) {
  56. UnmapViewOfFile(lpSharedWOWMem);
  57. lpSharedWOWMem = NULL;
  58. }
  59. if (hSharedWOWMem) {
  60. CloseHandle(hSharedWOWMem);
  61. hSharedWOWMem = NULL;
  62. }
  63. }
  64. break;
  65. default:
  66. break;
  67. }
  68. return TRUE; // FALSE means don't load for DLL_PROCESS_ATTACH
  69. }