Leaked source code of windows server 2003
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.

169 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name :
  4. kernutil.cpp
  5. Abstract:
  6. Kernel mode utilities
  7. Revision History:
  8. --*/
  9. #include "precomp.hxx"
  10. #define TRC_FILE "kernutil"
  11. #include "trc.h"
  12. NPagedLookasideList *ListEntry::_Lookaside = NULL;
  13. NPagedLookasideList *KernelEvent::_Lookaside = NULL;
  14. BOOL InitializeKernelUtilities()
  15. {
  16. BOOL Success = TRUE;
  17. BEGIN_FN("InitializeKernelUtilities");
  18. if (Success) {
  19. Success = ListEntry::StaticInitialization();
  20. TRC_NRM((TB, "ListEntry::StaticInitialization result: %d", Success));
  21. }
  22. if (Success) {
  23. Success = KernelEvent::StaticInitialization();
  24. TRC_NRM((TB, "KernelEvent::StaticInitialization result: %d", Success));
  25. }
  26. if (Success) {
  27. TRC_NRM((TB, "Successful InitializeKernelUtilities"));
  28. return TRUE;
  29. } else {
  30. TRC_ERR((TB, "Unuccessful InitializeKernelUtilities"));
  31. UninitializeKernelUtilities();
  32. return FALSE;
  33. }
  34. }
  35. VOID UninitializeKernelUtilities()
  36. {
  37. BEGIN_FN("UnitializeKernelUtilities");
  38. ListEntry::StaticUninitialization();
  39. }
  40. KernelResource::KernelResource()
  41. {
  42. NTSTATUS Status;
  43. BEGIN_FN("KernelResource::KernelResource");
  44. SetClassName("KernelResource");
  45. Status = ExInitializeResourceLite(&_Resource);
  46. // DDK documentation says it always returns STATUS_SUCCESS
  47. ASSERT(Status == STATUS_SUCCESS);
  48. }
  49. KernelResource::~KernelResource()
  50. {
  51. NTSTATUS Status;
  52. BEGIN_FN("KernelResource::~KernelResource");
  53. ASSERT(!IsAcquired());
  54. Status = ExDeleteResourceLite(&_Resource);
  55. ASSERT(!NT_ERROR(Status));
  56. }
  57. BOOL DoubleList::CreateEntry(PVOID Node)
  58. {
  59. ListEntry *Entry;
  60. BEGIN_FN("DoubleList::CreateEntry");
  61. // Allocate a new entry
  62. Entry = new ListEntry(Node);
  63. // Insert it in the list
  64. if (Entry != NULL) {
  65. LockExclusive();
  66. InsertTailList(&_List, &Entry->_List);
  67. Unlock();
  68. return TRUE;
  69. } else {
  70. return FALSE;
  71. }
  72. }
  73. VOID DoubleList::RemoveEntry(ListEntry *Entry)
  74. {
  75. BEGIN_FN("DoubleList::RemoveEntry");
  76. ASSERT(_Resource.IsAcquiredExclusive());
  77. RemoveEntryList(&Entry->_List);
  78. delete Entry;
  79. }
  80. ListEntry *DoubleList::First()
  81. {
  82. BEGIN_FN("DoubleList::First");
  83. ASSERT(_Resource.IsAcquiredShared());
  84. if (!IsListEmpty(&_List)) {
  85. return CONTAINING_RECORD(_List.Flink, ListEntry, _List);
  86. } else {
  87. return NULL;
  88. }
  89. }
  90. ListEntry *DoubleList::Next(ListEntry *ListEnum)
  91. {
  92. BEGIN_FN("DoubleList::Next");
  93. //
  94. // Caller should have called BeginEnumeration and therefore the
  95. // resource should be acquired shared
  96. //
  97. ASSERT(_Resource.IsAcquiredShared());
  98. #ifdef DBG
  99. //
  100. // Make sure this ListEnum guy is in the list
  101. //
  102. LIST_ENTRY *ListEntryT;
  103. ListEntryT = &_List;
  104. while (ListEntryT != NULL) {
  105. if (ListEntryT == &ListEnum->_List) {
  106. break;
  107. }
  108. // This is the same loop as below, just to search for the item
  109. if (ListEntryT->Flink != &_List) {
  110. ListEntryT = ListEntryT->Flink;
  111. } else {
  112. ListEntryT = NULL;
  113. }
  114. }
  115. // The passed in ListEnum should have been somewhere in the list
  116. ASSERT(ListEntryT != NULL);
  117. #endif // DBG
  118. if (ListEnum->_List.Flink != &_List) {
  119. //
  120. // Use the CONTAINING_RECORD juju to get back to the pointer which
  121. // is the actual ListEntry
  122. //
  123. return CONTAINING_RECORD(ListEnum->_List.Flink, ListEntry, _List);
  124. } else {
  125. //
  126. // Next item is the list head, so return NULL to end the enumeration
  127. //
  128. return NULL;
  129. }
  130. }