Windows NT 4.0 source code leak
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.

115 lines
2.0 KiB

4 years ago
  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. #pragma hdrstop
  12. #define BugCheckFileId SRV_FILE_LOCKCODE
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text( PAGE, SrvReferenceUnlockableCodeSection )
  15. #pragma alloc_text( PAGE, SrvDereferenceUnlockableCodeSection )
  16. #endif
  17. VOID
  18. SrvReferenceUnlockableCodeSection (
  19. IN ULONG CodeSection
  20. )
  21. {
  22. PSECTION_DESCRIPTOR section = &SrvSectionInfo[CodeSection];
  23. ULONG oldCount;
  24. //
  25. // Lock the lockable code database.
  26. //
  27. ACQUIRE_LOCK( &SrvUnlockableCodeLock );
  28. //
  29. // Increment the reference count for the section.
  30. //
  31. oldCount = section->ReferenceCount++;
  32. if ( oldCount == 0 ) {
  33. //
  34. // This is the first reference to the section. Lock it.
  35. //
  36. ASSERT( section->Handle == NULL );
  37. section->Handle = MmLockPagableCodeSection( section->Base );
  38. } else {
  39. //
  40. // This is not the first reference to the section. The section
  41. // had better be locked!
  42. //
  43. ASSERT( section->Handle != NULL );
  44. }
  45. RELEASE_LOCK( &SrvUnlockableCodeLock );
  46. return;
  47. } // SrvReferenceUnlockableCodeSection
  48. VOID
  49. SrvDereferenceUnlockableCodeSection (
  50. IN ULONG CodeSection
  51. )
  52. {
  53. PSECTION_DESCRIPTOR section = &SrvSectionInfo[CodeSection];
  54. ULONG newCount;
  55. //
  56. // Lock the lockable code database.
  57. //
  58. ACQUIRE_LOCK( &SrvUnlockableCodeLock );
  59. ASSERT( section->Handle != NULL );
  60. //
  61. // Decrement the reference count for the section.
  62. //
  63. newCount = --section->ReferenceCount;
  64. if ( newCount == 0 ) {
  65. //
  66. // This is the last reference to the section. Unlock it.
  67. //
  68. MmUnlockPagableImageSection( section->Handle );
  69. section->Handle = NULL;
  70. }
  71. RELEASE_LOCK( &SrvUnlockableCodeLock );
  72. return;
  73. } // SrvDereferenceUnlockableCodeSection