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.

116 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. lockcode.c
  5. Abstract:
  6. Author:
  7. Chuck Lenzmeier (chuckl) 30-Jan-1994
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. #include "lockcode.tmh"
  12. #pragma hdrstop
  13. #define BugCheckFileId SRV_FILE_LOCKCODE
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text( PAGE, SrvReferenceUnlockableCodeSection )
  16. #pragma alloc_text( PAGE, SrvDereferenceUnlockableCodeSection )
  17. #endif
  18. VOID
  19. SrvReferenceUnlockableCodeSection (
  20. IN ULONG CodeSection
  21. )
  22. {
  23. PSECTION_DESCRIPTOR section = &SrvSectionInfo[CodeSection];
  24. ULONG oldCount;
  25. //
  26. // Lock the lockable code database.
  27. //
  28. ACQUIRE_LOCK( &SrvUnlockableCodeLock );
  29. //
  30. // Increment the reference count for the section.
  31. //
  32. oldCount = section->ReferenceCount++;
  33. if ( oldCount == 0 ) {
  34. //
  35. // This is the first reference to the section. Lock it.
  36. //
  37. ASSERT( section->Handle == NULL );
  38. section->Handle = MmLockPagableCodeSection( section->Base );
  39. } else {
  40. //
  41. // This is not the first reference to the section. The section
  42. // had better be locked!
  43. //
  44. ASSERT( section->Handle != NULL );
  45. }
  46. RELEASE_LOCK( &SrvUnlockableCodeLock );
  47. return;
  48. } // SrvReferenceUnlockableCodeSection
  49. VOID
  50. SrvDereferenceUnlockableCodeSection (
  51. IN ULONG CodeSection
  52. )
  53. {
  54. PSECTION_DESCRIPTOR section = &SrvSectionInfo[CodeSection];
  55. ULONG newCount;
  56. //
  57. // Lock the lockable code database.
  58. //
  59. ACQUIRE_LOCK( &SrvUnlockableCodeLock );
  60. ASSERT( section->Handle != NULL );
  61. //
  62. // Decrement the reference count for the section.
  63. //
  64. newCount = --section->ReferenceCount;
  65. if ( newCount == 0 ) {
  66. //
  67. // This is the last reference to the section. Unlock it.
  68. //
  69. MmUnlockPagableImageSection( section->Handle );
  70. section->Handle = NULL;
  71. }
  72. RELEASE_LOCK( &SrvUnlockableCodeLock );
  73. return;
  74. } // SrvDereferenceUnlockableCodeSection