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.

224 lines
3.7 KiB

  1. /*
  2. ************************************************************************
  3. Copyright (c) 1996-1997 Microsoft Corporation
  4. Module Name:
  5. gpcmain.c
  6. Abstract:
  7. This file contains initialization stuff for the GPC
  8. Author:
  9. Ofer Bar - April 15, 1997
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. ************************************************************************
  14. */
  15. #include "gpcpre.h"
  16. #if DBG
  17. ULONG DebugFlags = PATTERN | RHIZOME
  18. | LOCKS | CLASSIFY
  19. | BLOB | MEMORY | IOCTL
  20. | CLIENT | MAPHAND | CLASSHAND | PAT_TIMER;
  21. ULONG DbgPrintFlags = 0;
  22. ULONG BytesAllocated = 0;
  23. NDIS_SPIN_LOCK LogLock;
  24. //extern LOG Log;
  25. LOG Log = {0, NULL, NULL, 0};
  26. //
  27. // Forward definition
  28. //
  29. #if 0
  30. ULONG
  31. StrLen(
  32. IN UCHAR *Ptr
  33. );
  34. #endif
  35. NTSTATUS
  36. InitializeLog(
  37. VOID
  38. )
  39. {
  40. NTSTATUS Status = STATUS_SUCCESS;
  41. //
  42. // allocate memory for it
  43. //
  44. Log.Buffer = (PROW)ExAllocatePoolWithTag(NonPagedPool,
  45. (LOGSIZE+4) * sizeof(ROW),
  46. DebugTag);
  47. if (Log.Buffer) {
  48. Log.Index = 0;
  49. Log.Wraps = 0;
  50. Log.Current = Log.Buffer;
  51. NdisAllocateSpinLock(&LogLock);
  52. } else {
  53. Status = STATUS_NO_MEMORY;
  54. }
  55. return Status;
  56. }
  57. VOID
  58. FreeDebugLog(VOID)
  59. {
  60. ExFreePool(Log.Buffer);
  61. Log.Buffer = NULL;
  62. }
  63. #if 0
  64. ULONG
  65. StrLen(
  66. IN UCHAR *Ptr
  67. )
  68. /*++
  69. Routine Description:
  70. This function does a strlen - so that we don't have to enable intrinsics.
  71. Arguments:
  72. Ptr - a ptr to the string
  73. Return Value:
  74. - the number of characters.
  75. --*/
  76. {
  77. ULONG Count = 0;
  78. while (*Ptr++) {
  79. Count++;
  80. }
  81. return( Count );
  82. }
  83. #endif
  84. VOID
  85. TraceRtn(
  86. IN UCHAR *File,
  87. IN ULONG Line,
  88. IN UCHAR *FuncName,
  89. IN ULONG_PTR Param1,
  90. IN ULONG_PTR Param2,
  91. IN ULONG Param3,
  92. IN ULONG Param4,
  93. IN ULONG Mask
  94. )
  95. /*++
  96. Routine Description:
  97. This function logs the file and line number along with 3 other parameters
  98. into a circular buffer and possibly to the debug terminal.
  99. Arguments:
  100. Return Value:
  101. --*/
  102. {
  103. NTSTATUS status;
  104. PROW pEntry;
  105. PUCHAR pFile, p;
  106. LONG l, m;
  107. if (!Log.Buffer)
  108. {
  109. return;
  110. }
  111. NdisAcquireSpinLock(&LogLock);
  112. pEntry = &Log.Buffer[Log.Index];
  113. p = File;
  114. pFile = p + strlen(File) - 1;
  115. while (*pFile != '\\' && p != pFile) {
  116. pFile--;
  117. }
  118. //pFile = (PUCHAR)strrchr((CONST CHAR * )File,'\\');
  119. pFile++;
  120. RtlZeroMemory(&pEntry->Row[0], LOGWIDTH);
  121. l = strlen(pFile);
  122. RtlCopyMemory(&pEntry->Row[0], pFile, min(l,LOGWIDTH));
  123. if (l+3 < LOGWIDTH) {
  124. pEntry->Row[l+0] = ' ';
  125. pEntry->Row[l+1] = '%';
  126. pEntry->Row[l+2] = 'd';
  127. pEntry->Row[l+3] = ' ';
  128. }
  129. if (l+4 < LOGWIDTH) {
  130. m = strlen(FuncName);
  131. RtlCopyMemory(&pEntry->Row[l+4], FuncName, min(m,LOGWIDTH-(l+4)));
  132. }
  133. pEntry->Line = Line;
  134. pEntry->Time = GetTime();
  135. pEntry->P1 = Param1;
  136. pEntry->P2 = Param2;
  137. pEntry->P3 = Param3;
  138. pEntry->P4 = Param4;
  139. //++Log.Current;
  140. if (++(Log.Index) >= LOGSIZE)
  141. {
  142. Log.Index = 0;
  143. Log.Wraps++;
  144. Log.Current = Log.Buffer;
  145. }
  146. if (DebugFlags & KD_PRINT) {
  147. KdPrint(( pEntry->Row, Line ));
  148. KdPrint(( " %p %p %d %d\n", Param1, Param2, Param3, Param4 ));
  149. }
  150. NdisReleaseSpinLock(&LogLock);
  151. }
  152. #endif // DBG