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.

307 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name:
  4. rcadebug.c
  5. Abstract:
  6. This module contains all debug-related code.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. rmachin 2-18-97 stolen from ArvindM's cmadebug file
  11. JameelH 4-18-98 Cleanup
  12. Notes:
  13. --*/
  14. #include <precomp.h>
  15. #define MODULE_NUMBER MODULE_DEBUG
  16. #define _FILENUMBER 'BDCR'
  17. INT RCADebugLevel= RCA_ERROR;
  18. ULONG PXDebugMicos = 0xFF;
  19. #ifdef PERF
  20. LARGE_INTEGER PerfTimeConnRequest;
  21. LARGE_INTEGER PerfTimeSetupSent;
  22. LARGE_INTEGER PerfTimeConnectReceived;
  23. LARGE_INTEGER PerfTimeConnConfirm;
  24. LARGE_INTEGER PerfTimeSetupReceived;
  25. LARGE_INTEGER PerfTimeConnIndication;
  26. LARGE_INTEGER PerfTimeConnResponse;
  27. LARGE_INTEGER PerfTimeConnectSent;
  28. LARGE_INTEGER PerfTimeFrequency;
  29. #endif // PERF
  30. #if DBG
  31. #undef AUDIT_MEM
  32. #define AUDIT_MEM 1
  33. #endif
  34. //
  35. // For debugging only: set this to 0x1 for to enable hardcoded data format, 0x0 otherwise.
  36. //
  37. ULONG g_ulHardcodeDataFormat = 0x0;
  38. //
  39. // For debugging only: set this to some positive value to indicate the buffer size to
  40. // advertise in our AllocatorFraming property handler, and the amount of data to copy
  41. // in the WriteStream handler. If set to zero, this will be ignored.
  42. //
  43. ULONG g_ulBufferSize = 0x0;
  44. #if AUDIT_MEM
  45. PVOID DebugVar1 = (PVOID)NULL;
  46. PRCA_ALLOCATION RCAdMemoryHead = (PRCA_ALLOCATION)NULL;
  47. PVOID DebugVar2 = (PVOID)NULL;
  48. PRCA_ALLOCATION RCAdMemoryTail = (PRCA_ALLOCATION)NULL;
  49. PVOID DebugVar3 = (PVOID)NULL;
  50. ULONG RCAdAllocCount = 0; // how many allocated so far (unfreed)
  51. PVOID DebugVar4 = (PVOID)NULL;
  52. NDIS_SPIN_LOCK RCAdMemoryLock;
  53. BOOLEAN RCAdInitDone = FALSE;
  54. PVOID
  55. RCAAuditAllocMem(
  56. PVOID pPointer,
  57. ULONG Size,
  58. ULONG FileNumber,
  59. ULONG LineNumber
  60. )
  61. {
  62. PVOID pBuffer;
  63. PRCA_ALLOCATION pAllocInfo = NULL;
  64. RCADEBUGP(RCA_VERY_LOUD+50, ("RCAAuditAllocMem(): Enter with size == %lu\n", Size));
  65. if (!RCAdInitDone)
  66. {
  67. RCAInitLock(&RCAdMemoryLock);
  68. DebugVar1 = (PVOID)(UINT_PTR)0x01010101;
  69. DebugVar2 = (PVOID)(UINT_PTR)0xabababab;
  70. DebugVar3 = (PVOID)(UINT_PTR)0xcdcdcdcd;
  71. DebugVar4 = (PVOID)(UINT_PTR)0xefefefef;
  72. RCAdInitDone = TRUE;
  73. }
  74. //pAllocInfo = (PRCA_ALLOCATION)CTEAllocMem(Size+sizeof(RCA_ALLOCATION));
  75. NdisAllocateMemoryWithTag((PVOID *)(&pAllocInfo),
  76. (UINT)(Size + sizeof(RCA_ALLOCATION)),
  77. RCA_TAG);
  78. if (pAllocInfo == (PRCA_ALLOCATION)NULL)
  79. {
  80. RCADEBUGP(RCA_VERY_LOUD+50,
  81. ("RCAAuditAllocMem: file %d, line %d, Size %d failed!\n",
  82. FileNumber, LineNumber, Size));
  83. pBuffer = NULL;
  84. }
  85. else
  86. {
  87. pBuffer = (PVOID)&(pAllocInfo->UserData);
  88. RCAMemSet(pBuffer, 0xc, Size);
  89. pAllocInfo->Signature = RCA_MEMORY_SIGNATURE;
  90. pAllocInfo->FileNumber = FileNumber;
  91. pAllocInfo->LineNumber = LineNumber;
  92. pAllocInfo->Size = Size;
  93. pAllocInfo->Location = (ULONG_PTR)pPointer;
  94. pAllocInfo->Next = (PRCA_ALLOCATION)NULL;
  95. RCAAcquireLock(&RCAdMemoryLock);
  96. pAllocInfo->Prev = RCAdMemoryTail;
  97. if (RCAdMemoryTail == (PRCA_ALLOCATION)NULL)
  98. {
  99. // empty list
  100. RCAdMemoryHead = RCAdMemoryTail = pAllocInfo;
  101. }
  102. else
  103. {
  104. RCAdMemoryTail->Next = pAllocInfo;
  105. }
  106. RCAdMemoryTail = pAllocInfo;
  107. RCAdAllocCount++;
  108. RCAReleaseLock(&RCAdMemoryLock);
  109. }
  110. RCADEBUGP(RCA_VERY_LOUD+100,
  111. ("RCAAuditAllocMem: file %c%c%c%c, line %d, %d bytes, [0x%x] <- 0x%x\n",
  112. (CHAR)(FileNumber & 0xff),
  113. (CHAR)((FileNumber >> 8) & 0xff),
  114. (CHAR)((FileNumber >> 16) & 0xff),
  115. (CHAR)((FileNumber >> 24) & 0xff),
  116. LineNumber, Size, pPointer, pBuffer));
  117. return (pBuffer);
  118. }
  119. VOID
  120. RCAAuditFreeMem(
  121. PVOID Pointer
  122. )
  123. {
  124. PRCA_ALLOCATION pAllocInfo;
  125. pAllocInfo = STRUCT_OF(RCA_ALLOCATION, Pointer, UserData);
  126. if (pAllocInfo->Signature != RCA_MEMORY_SIGNATURE)
  127. {
  128. RCADEBUGP(RCA_ERROR,
  129. ("RCAAuditFreeMem: unknown buffer 0x%x!\n", Pointer));
  130. DbgBreakPoint();
  131. return;
  132. }
  133. RCAAcquireLock(&RCAdMemoryLock);
  134. pAllocInfo->Signature = (ULONG)'DEAD';
  135. if (pAllocInfo->Prev != (PRCA_ALLOCATION)NULL)
  136. {
  137. pAllocInfo->Prev->Next = pAllocInfo->Next;
  138. }
  139. else
  140. {
  141. RCAdMemoryHead = pAllocInfo->Next;
  142. }
  143. if (pAllocInfo->Next != (PRCA_ALLOCATION)NULL)
  144. {
  145. pAllocInfo->Next->Prev = pAllocInfo->Prev;
  146. }
  147. else
  148. {
  149. RCAdMemoryTail = pAllocInfo->Prev;
  150. }
  151. RCAdAllocCount--;
  152. RCAReleaseLock(&RCAdMemoryLock);
  153. NdisFreeMemory(pAllocInfo, 0, 0);
  154. }
  155. #endif // AUDIT_MEM
  156. VOID
  157. RCADumpGUID(
  158. INT DebugLevel,
  159. GUID *Guid
  160. )
  161. /*++
  162. Routine Description:
  163. This routine prints a GUID in human-readable form.
  164. Arguments:
  165. DebugLevel - The debug level that should be set before
  166. the print becomes visible
  167. Guid - The GUID structure to print
  168. Return Value:
  169. (None)
  170. --*/
  171. {
  172. if (DebugLevel <= RCADebugLevel) {
  173. DbgPrint("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  174. Guid->Data1, Guid->Data2,
  175. Guid->Data3, Guid->Data4[0],
  176. Guid->Data4[1], Guid->Data4[2],
  177. Guid->Data4[3], Guid->Data4[4],
  178. Guid->Data4[5], Guid->Data4[6],
  179. Guid->Data4[7]);
  180. };
  181. }
  182. NTSTATUS
  183. RCADumpKsPropertyInfo(
  184. INT DebugLevel,
  185. PIRP pIrp
  186. )
  187. /*++
  188. Routine Description:
  189. This routine prints the property information in stored in an
  190. IOCTL_KS_PROPERTY Irp. This helps to identify which property
  191. is being set/queried by means of the irp.
  192. Arguments:
  193. DebugLevel - The debug level that should be set before
  194. the print becomes visible
  195. pIrp - The IOCTL_KS_PROPERTY Irp
  196. Return Value:
  197. STATUS_SUCCESS if all goes well, or an appropriate error code
  198. otherwise.
  199. --*/
  200. {
  201. PIO_STACK_LOCATION pIrpStack;
  202. ULONG ulInputBufferLength;
  203. NTSTATUS Status = STATUS_SUCCESS;
  204. PKSPROPERTY pProperty;
  205. RCADEBUGP(DebugLevel, ("RCADumpKsPropertyInfo - Enter\n"));
  206. pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
  207. ulInputBufferLength = pIrpStack->Parameters.DeviceIoControl.InputBufferLength;
  208. do {
  209. if (ulInputBufferLength < sizeof(KSPROPERTY)) {
  210. RCADEBUGP(DebugLevel, ("RCADumpKsPropertyInfo: Irp's input buffer is too small\n"));
  211. Status = STATUS_INVALID_BUFFER_SIZE;
  212. break;
  213. }
  214. try {
  215. //
  216. // Validate the pointers if the client is not trusted.
  217. //
  218. if (pIrp->RequestorMode != KernelMode) {
  219. ProbeForRead(pIrpStack->Parameters.DeviceIoControl.Type3InputBuffer,
  220. ulInputBufferLength,
  221. sizeof(BYTE));
  222. }
  223. pProperty = (PKSPROPERTY)pIrpStack->Parameters.DeviceIoControl.Type3InputBuffer;
  224. RCADEBUGP(DebugLevel, ("RCADumpKsPropertyInfo: Property Set == "));
  225. RCADumpGUID(DebugLevel, &pProperty->Set);
  226. RCADEBUGP(DebugLevel, ("\nRcaDumpKsPropertyInfo: Property Id == %lu\n", pProperty->Id));
  227. RCADEBUGP(DebugLevel, ("RCADumpKsPropertyInfo: Property Flags == 0x%x\n", pProperty->Flags));
  228. } except (EXCEPTION_EXECUTE_HANDLER) {
  229. Status = GetExceptionCode();
  230. break;
  231. }
  232. } while (FALSE);
  233. RCADEBUGP(DebugLevel, ("RCADumpKsPropertyInfo - Exit, Returing Status == 0x%x\n",
  234. Status));
  235. return Status;
  236. }