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.

226 lines
6.8 KiB

  1. `**********************************************************************`
  2. `* This is an include template file for tracewpp preprocessor. *`
  3. `* *`
  4. `* Copyright 1999-2001 Microsoft Corporation. All Rights Reserved. *`
  5. `**********************************************************************`
  6. // template `TemplateFile`
  7. //
  8. // Defines a set of functions that simplifies
  9. // kernel mode registration for tracing
  10. //
  11. #define WMIREG_FLAG_CALLBACK 0x80000000 // not exposed in DDK
  12. #ifndef WPPINIT_EXPORT
  13. # define WPPINIT_EXPORT
  14. #endif
  15. WPPINIT_EXPORT
  16. NTSTATUS
  17. WppTraceCallback(
  18. IN UCHAR minorFunction,
  19. IN PVOID DataPath,
  20. IN ULONG BufferLength,
  21. IN PVOID Buffer,
  22. IN PVOID Context,
  23. OUT PULONG Size
  24. )
  25. /*++
  26. Routine Description:
  27. Callback routine for IoWMIRegistrationControl.
  28. Arguments:
  29. Return Value:
  30. status
  31. Comments:
  32. if return value is STATUS_BUFFER_TOO_SMALL and BufferLength >= 4,
  33. then first ulong of buffer contains required size
  34. --*/
  35. {
  36. WPP_PROJECT_CONTROL_BLOCK *cb = (WPP_PROJECT_CONTROL_BLOCK*)Context;
  37. NTSTATUS status = STATUS_SUCCESS;
  38. UNREFERENCED_PARAMETER(DataPath);
  39. // DbgPrintEx(XX_FLTR, DPFLTR_TRACE_LEVEL,
  40. // "%!FUNC!(%!SYSCTRL!) %p", minorFunction, Context);
  41. *Size = 0;
  42. switch(minorFunction)
  43. {
  44. case IRP_MN_REGINFO:
  45. {
  46. PWMIREGINFOW wmiRegInfo;
  47. PCUNICODE_STRING regPath;
  48. PWCHAR stringPtr;
  49. ULONG registryPathOffset;
  50. ULONG bufferNeeded;
  51. UNICODE_STRING nullRegistryPath;
  52. regPath = cb->Registration.RegistryPath;
  53. if (regPath == NULL)
  54. {
  55. // No registry path specified. This is a bad thing for
  56. // the device to do, but is not fatal
  57. RtlInitUnicodeString(&nullRegistryPath, NULL);
  58. regPath = &nullRegistryPath;
  59. }
  60. registryPathOffset = FIELD_OFFSET(WMIREGINFOW, WmiRegGuid)
  61. + 1 * sizeof(WMIREGGUIDW);
  62. bufferNeeded = registryPathOffset +
  63. regPath->Length + sizeof(USHORT);
  64. if (bufferNeeded <= BufferLength)
  65. {
  66. RtlZeroMemory(Buffer, BufferLength);
  67. wmiRegInfo = (PWMIREGINFO)Buffer;
  68. wmiRegInfo->BufferSize = bufferNeeded;
  69. wmiRegInfo->RegistryPath = registryPathOffset;
  70. wmiRegInfo->GuidCount = 1;
  71. wmiRegInfo->WmiRegGuid[0].Guid = *cb->Registration.ControlGuid;
  72. wmiRegInfo->WmiRegGuid[0].Flags =
  73. WMIREG_FLAG_TRACE_CONTROL_GUID | WMIREG_FLAG_TRACED_GUID;
  74. stringPtr = (PWCHAR)((PUCHAR)Buffer + registryPathOffset);
  75. *stringPtr++ = regPath->Length;
  76. RtlCopyMemory(stringPtr,
  77. regPath->Buffer,
  78. regPath->Length);
  79. status = STATUS_SUCCESS;
  80. *Size = bufferNeeded;
  81. } else {
  82. status = STATUS_BUFFER_TOO_SMALL;
  83. if (BufferLength >= sizeof(ULONG)) {
  84. *((PULONG)Buffer) = bufferNeeded;
  85. *Size = sizeof(ULONG);
  86. }
  87. }
  88. break;
  89. }
  90. case IRP_MN_ENABLE_EVENTS:
  91. case IRP_MN_DISABLE_EVENTS:
  92. {
  93. PWNODE_HEADER Wnode = (PWNODE_HEADER)Buffer;
  94. ULONG Level;
  95. ULONG ReturnLength ;
  96. if (cb == NULL )
  97. {
  98. status = STATUS_WMI_GUID_NOT_FOUND;
  99. break;
  100. }
  101. if (BufferLength >= sizeof(WNODE_HEADER)) {
  102. status = STATUS_SUCCESS;
  103. if (minorFunction == IRP_MN_DISABLE_EVENTS) {
  104. cb->Control.Level = 0;
  105. cb->Control.Flags[0] = 0;
  106. cb->Control.Logger = 0;
  107. } else {
  108. TRACEHANDLE lh;
  109. lh = (TRACEHANDLE)( Wnode->HistoricalContext );
  110. cb->Control.Logger = lh;
  111. if ((status = WmiQueryTraceInformation( TraceEnableLevelClass,
  112. &Level,
  113. sizeof(Level),
  114. &ReturnLength,
  115. (PVOID)Wnode)) == STATUS_SUCCESS)
  116. {
  117. cb->Control.Level = (UCHAR)Level;
  118. }
  119. status = WmiQueryTraceInformation( TraceEnableFlagsClass,
  120. &cb->Control.Flags[0],
  121. sizeof(cb->Control.Flags[0]),
  122. &ReturnLength,
  123. (PVOID)Wnode);
  124. }
  125. } else {
  126. status = STATUS_INVALID_PARAMETER;
  127. }
  128. break;
  129. }
  130. case IRP_MN_ENABLE_COLLECTION:
  131. case IRP_MN_DISABLE_COLLECTION:
  132. {
  133. status = STATUS_SUCCESS;
  134. break;
  135. }
  136. case IRP_MN_QUERY_ALL_DATA:
  137. case IRP_MN_QUERY_SINGLE_INSTANCE:
  138. case IRP_MN_CHANGE_SINGLE_INSTANCE:
  139. case IRP_MN_CHANGE_SINGLE_ITEM:
  140. case IRP_MN_EXECUTE_METHOD:
  141. {
  142. status = STATUS_INVALID_DEVICE_REQUEST;
  143. break;
  144. }
  145. default:
  146. {
  147. status = STATUS_INVALID_DEVICE_REQUEST;
  148. break;
  149. }
  150. }
  151. // DbgPrintEx(XX_FLTR, DPFLTR_TRACE_LEVEL,
  152. // "%!FUNC!(%!SYSCTRL!) => %!status! (size = %d)", minorFunction, status, *Size);
  153. return(status);
  154. }
  155. WPPINIT_EXPORT
  156. void WppInitKm(
  157. IN PUNICODE_STRING RegistryPath,
  158. IN OUT WPP_REGISTRATION_BLOCK* WppReg
  159. )
  160. {
  161. RegistryPath; // unused
  162. while(WppReg) {
  163. WPP_TRACE_CONTROL_BLOCK *cb = (WPP_TRACE_CONTROL_BLOCK*)WppReg;
  164. WppReg -> Callback = WppTraceCallback;
  165. WppReg -> RegistryPath = NULL;
  166. cb -> FlagsLen = WppReg -> FlagsLen;
  167. cb -> Level = 0;
  168. cb -> Flags[0] = 0;
  169. IoWMIRegistrationControl((PDEVICE_OBJECT)WppReg,
  170. WMIREG_ACTION_REGISTER | WMIREG_FLAG_CALLBACK);
  171. WppReg = WppReg->Next;
  172. }
  173. }
  174. WPPINIT_EXPORT
  175. void WppCleanupKm(
  176. WPP_REGISTRATION_BLOCK* WppReg
  177. )
  178. {
  179. while (WppReg) {
  180. IoWMIRegistrationControl((PDEVICE_OBJECT)WppReg,
  181. WMIREG_ACTION_DEREGISTER | WMIREG_FLAG_CALLBACK);
  182. WppReg = WppReg -> Next;
  183. }
  184. }