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.

194 lines
6.2 KiB

  1. `**********************************************************************`
  2. `* This is a template file for tracewpp preprocessor *`
  3. `* If you need to use a custom version of this file in your project *`
  4. `* Please clone it from this one and point WPP to it by specifying *`
  5. `* -gen:{yourfile} option on RUN_WPP line in your sources file *`
  6. `* *`
  7. `* This specific header is km-w2k.tpl and is used to define tracing *`
  8. `* applications which must also run under Windows 2000 *`
  9. `* *`
  10. `* Copyright 1999-2001 Microsoft Corporation. All Rights Reserved. *`
  11. `**********************************************************************`
  12. //`Compiler.Checksum` Generated File. Do not edit.
  13. // File created by `Compiler.Name` compiler version `Compiler.Version`-`Compiler.Timestamp`
  14. // on `System.Date` at `System.Time` UTC from a template `TemplateFile`
  15. #define WPP_TRACE_W2K_COMPATABILITY
  16. #define WPP_TRACE W2kTraceMessage
  17. #ifdef WPP_TRACE_W2K_COMPATABILITY
  18. #define WPP_TRACE_OPTIONS 0
  19. #pragma warning(disable: 4201)
  20. #include <stddef.h>
  21. #include <stdarg.h>
  22. #include <ntddk.h>
  23. #include <wmistr.h>
  24. #include <evntrace.h>
  25. #ifndef WPP_POOLTAG
  26. #define WPP_POOLTAG 'ECTS'
  27. #endif
  28. #ifndef WPP_POOLTYPE
  29. #define WPP_POOLTYPE PagedPool
  30. #endif
  31. #if defined(__cplusplus)
  32. extern "C" {
  33. #endif
  34. #ifndef WPP_MAX_MOF_FIELDS
  35. #define WPP_MAX_MOF_FIELDS 8
  36. #endif
  37. typedef struct _TRACE_BUFFER {
  38. EVENT_TRACE_HEADER Header;
  39. MOF_FIELD MofField[WPP_MAX_MOF_FIELDS+1];
  40. } TRACE_BUFFER;
  41. #ifndef TRACE_MESSAGE_MAXIMUM_SIZE
  42. #define TRACE_MESSAGE_MAXIMUM_SIZE 8*1024
  43. #endif
  44. NTSTATUS W2kTraceMessage(IN TRACEHANDLE LoggerHandle, IN ULONG TraceOptions, IN LPGUID MessageGuid, IN USHORT MessageNumber, ...) ;
  45. #if defined(__cplusplus)
  46. };
  47. #endif
  48. `IF FOUND WPP_INIT_TRACING`
  49. NTSTATUS W2kTraceMessage(IN TRACEHANDLE LoggerHandle, IN ULONG TraceOptions, IN LPGUID MessageGuid, IN USHORT MessageNumber, ...)
  50. {
  51. size_t uiBytes, uiArgCount ;
  52. va_list ap ;
  53. PVOID source ;
  54. size_t uiElemBytes = 0, uiTotSize, uiOffset ;
  55. NTSTATUS ulResult = STATUS_SUCCESS ;
  56. TRACE_BUFFER TraceBuf;
  57. void *pData=NULL;
  58. TraceOptions; // unused
  59. RtlZeroMemory(&(TraceBuf.Header), sizeof(EVENT_TRACE_HEADER));
  60. //Fill in header fields
  61. ((PWNODE_HEADER)&(TraceBuf.Header))->HistoricalContext = LoggerHandle;
  62. TraceBuf.Header.GuidPtr = (ULONGLONG)MessageGuid ;
  63. TraceBuf.Header.Flags = WNODE_FLAG_TRACED_GUID |WNODE_FLAG_USE_GUID_PTR|WNODE_FLAG_USE_MOF_PTR ;
  64. //Type is 0xFF to indicate that the first data is the MessageNumber
  65. TraceBuf.Header.Class.Type = 0xFF ;
  66. //The first Mof data is the Message Number
  67. TraceBuf.MofField[0].DataPtr = (ULONGLONG)&MessageNumber;
  68. TraceBuf.MofField[0].Length = sizeof(USHORT);
  69. // Determine the number bytes to follow header
  70. uiBytes = 0 ; // For Count of Bytes
  71. uiArgCount = 0 ; // For Count of Arguments
  72. va_start(ap, MessageNumber) ;
  73. while ((source = va_arg (ap, PVOID)) != NULL)
  74. {
  75. uiElemBytes = va_arg (ap, size_t) ;
  76. uiBytes += uiElemBytes ;
  77. uiArgCount++ ;
  78. if (uiArgCount <= WPP_MAX_MOF_FIELDS)
  79. {
  80. TraceBuf.MofField[uiArgCount].DataPtr = (ULONGLONG)source;
  81. TraceBuf.MofField[uiArgCount].Length = (ULONG)uiElemBytes;
  82. }
  83. }
  84. va_end(ap) ;
  85. if (uiBytes > TRACE_MESSAGE_MAXIMUM_SIZE)
  86. {
  87. return STATUS_UNSUCCESSFUL;
  88. }
  89. //This occurs infrequently
  90. if (uiArgCount > WPP_MAX_MOF_FIELDS)
  91. {
  92. //Allocate the blob to hold the data
  93. pData = ExAllocatePoolWithTag(WPP_POOLTYPE,uiBytes,WPP_POOLTAG) ;
  94. if (pData == NULL)
  95. {
  96. return STATUS_NO_MEMORY;
  97. }
  98. TraceBuf.MofField[1].DataPtr = (ULONGLONG)pData;
  99. TraceBuf.MofField[1].Length = uiBytes;
  100. uiOffset = 0 ;
  101. uiElemBytes = 0 ;
  102. va_start(ap, MessageNumber) ;
  103. while ((source = va_arg (ap, PVOID)) != NULL)
  104. {
  105. uiElemBytes = va_arg (ap, size_t) ;
  106. memcpy((char*)pData + uiOffset, source, uiElemBytes) ;
  107. uiOffset += uiElemBytes ;
  108. }
  109. va_end(ap) ;
  110. //Fill in the total size (header + 2 mof fields)
  111. TraceBuf.Header.Size = sizeof(EVENT_TRACE_HEADER) + 2*sizeof(MOF_FIELD);
  112. }
  113. else
  114. {
  115. //Fill in the total size (header + mof fields)
  116. TraceBuf.Header.Size = sizeof(EVENT_TRACE_HEADER) + (uiArgCount+1)*sizeof(MOF_FIELD);
  117. }
  118. ulResult = IoWMIWriteEvent(&TraceBuf.Header) ;
  119. if (pData) ExFreePool(pData);
  120. return ulResult ;
  121. }
  122. `ENDIF`
  123. //
  124. // Public routines to break down the Loggerhandle
  125. //
  126. #define KERNEL_LOGGER_ID 0xFFFF // USHORT only
  127. #if(_WIN32_WINNT >= 0x0501)
  128. typedef struct _TRACE_ENABLE_CONTEXT {
  129. USHORT LoggerId; // Actual Id of the logger
  130. UCHAR Level; // Enable level passed by control caller
  131. UCHAR InternalFlag; // Reserved
  132. ULONG EnableFlags; // Enable flags passed by control caller
  133. } TRACE_ENABLE_CONTEXT, *PTRACE_ENABLE_CONTEXT;
  134. #endif
  135. #define WmiGetLoggerId(LoggerContext) \
  136. (((PTRACE_ENABLE_CONTEXT) (&LoggerContext))->LoggerId == \
  137. (USHORT)KERNEL_LOGGER_ID) ? \
  138. KERNEL_LOGGER_ID : \
  139. ((PTRACE_ENABLE_CONTEXT) (&LoggerContext))->LoggerId
  140. #define WmiGetLoggerEnableFlags(LoggerContext) \
  141. ((PTRACE_ENABLE_CONTEXT) (&LoggerContext))->EnableFlags
  142. #define WmiGetLoggerEnableLevel(LoggerContext) \
  143. ((PTRACE_ENABLE_CONTEXT) (&LoggerContext))->Level
  144. #endif // #ifdef WPP_TRACE_W2K_COMPATABILITY
  145. `INCLUDE km-header.tpl`
  146. `INCLUDE control.tpl`
  147. `INCLUDE trmacro.tpl`
  148. `IF FOUND WPP_INIT_TRACING`
  149. #define WPPINIT_EXPORT
  150. `INCLUDE km-init.tpl`
  151. `ENDIF`