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.

139 lines
2.5 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Header Name:
  4. tracker.h
  5. Abstract:
  6. Verifier call history tracker.
  7. Author:
  8. Silviu Calinoiu (SilviuC) Jul-11-2002
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #include "verifier.h"
  13. #include "support.h"
  14. #include "tracker.h"
  15. PAVRF_TRACKER
  16. AVrfCreateTracker (
  17. ULONG Size
  18. )
  19. {
  20. PAVRF_TRACKER Tracker;
  21. //
  22. // Do not accept bogus sizes.
  23. //
  24. if (Size <= 1) {
  25. ASSERT (Size > 1);
  26. return NULL;
  27. }
  28. //
  29. // We allocate `Size - 1' tracker entries because we have already
  30. // an entry in the main tracker structure.
  31. //
  32. Tracker = AVrfpAllocate (sizeof(*Tracker) + (Size - 1) * sizeof(AVRF_TRACKER_ENTRY));
  33. if (Tracker == NULL) {
  34. return NULL;
  35. }
  36. //
  37. // We set the size. No other initialization is required since AVrfpAllocate zeroes
  38. // the memory just allocated.
  39. //
  40. Tracker->Size = Size;
  41. return Tracker;
  42. }
  43. VOID
  44. AVrfDestroyTracker (
  45. PAVRF_TRACKER Tracker
  46. )
  47. {
  48. //
  49. // Safety checks.
  50. //
  51. if (Tracker == NULL) {
  52. return;
  53. }
  54. AVrfpFree (Tracker);
  55. }
  56. VOID
  57. AVrfLogInTracker (
  58. PAVRF_TRACKER Tracker,
  59. USHORT EntryType,
  60. PVOID EntryParam1,
  61. PVOID EntryParam2,
  62. PVOID EntryParam3,
  63. PVOID EntryParam4,
  64. PVOID ReturnAddress
  65. )
  66. {
  67. ULONG Index;
  68. USHORT Count;
  69. //
  70. // Safety checks.
  71. //
  72. if (Tracker == NULL) {
  73. return;
  74. }
  75. //
  76. // Get the index for the tracker entry that will be filled.
  77. //
  78. Index = (ULONG)InterlockedIncrement ((PLONG)(&(Tracker->Index)));
  79. Index %= Tracker->Size;
  80. //
  81. // If a null return address is passed then we need to
  82. // walk the stack and get a full stack trace.
  83. //
  84. Tracker->Entry[Index].Type = EntryType;
  85. Tracker->Entry[Index].Info[0] = EntryParam1;
  86. Tracker->Entry[Index].Info[1] = EntryParam2;
  87. Tracker->Entry[Index].Info[2] = EntryParam3;
  88. Tracker->Entry[Index].Info[3] = EntryParam4;
  89. Count = RtlCaptureStackBackTrace (2,
  90. MAX_TRACE_DEPTH,
  91. Tracker->Entry[Index].Trace,
  92. NULL);
  93. if (Count == 0) {
  94. Tracker->Entry[Index].TraceDepth = 1;
  95. Tracker->Entry[Index].Trace[0] = ReturnAddress;
  96. }
  97. else {
  98. Tracker->Entry[Index].TraceDepth = Count;
  99. }
  100. }