EtwTraceCore.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #ifdef ENABLE_JS_ETW
  7. #define PAIR(a,b) a ## b
  8. #ifdef NTBUILD
  9. #define GCETW(e, args) \
  10. if (IsMemProtectMode()) \
  11. { \
  12. PAIR(EventWriteMEMPROTECT_ ## e, args); \
  13. } \
  14. else \
  15. { \
  16. PAIR(EventWriteJSCRIPT_ ## e, args); \
  17. }
  18. #define GCETW_INTERNAL(e, args) \
  19. if (IsMemProtectMode()) \
  20. { \
  21. PAIR(EventWriteMEMPROTECT_ ## e, args); \
  22. } \
  23. else \
  24. { \
  25. PAIR(EventWriteJSCRIPT_ ## e, args); \
  26. }
  27. #define IS_GCETW_Enabled(e) \
  28. (IsMemProtectMode() ? EventEnabledMEMPROTECT_##e() : EventEnabledJSCRIPT_##e())
  29. #define JS_ETW_INTERNAL(s) s
  30. #define EDGE_ETW_INTERNAL(s) s
  31. #else // !NTBUILD
  32. #define GCETW(e, args) \
  33. PAIR(EventWriteJSCRIPT_ ## e, args);
  34. #define IS_GCETW_Enabled(e) EventEnabledJSCRIPT_##e()
  35. #define GCETW_INTERNAL(e, args)
  36. #define JS_ETW_INTERNAL(s)
  37. #define EDGE_ETW_INTERNAL(s)
  38. #endif // !NTBUILD
  39. #define JS_ETW(s) s
  40. #define IS_JS_ETW(s) s
  41. #ifdef ENABLE_JS_LTTNG
  42. #include "jscriptEtw.h"
  43. #else
  44. // C-style callback
  45. extern "C" {
  46. void EtwCallback(
  47. ULONG controlCode,
  48. PVOID callbackContext);
  49. }
  50. class EtwCallbackApi
  51. {
  52. public:
  53. static void OnSessionChange(ULONG controlCode, PVOID callbackContext);
  54. };
  55. // The macro 'MCGEN_PRIVATE_ENABLE_CALLBACK_V2' below should be defined before microsoft-scripting-jscript9events.h
  56. // is included. This is a complier assert to ensure this happens. If this does not happen rundown events will not work.
  57. #ifdef JSCRIPT_METHOD_METHODLOAD_OPCODE
  58. CompileAssert(false)
  59. #endif
  60. // Declaring this macro enables the registration of the callback on DLL attach
  61. #define MCGEN_PRIVATE_ENABLE_CALLBACK_V2(SourceId, ControlCode, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext) \
  62. EtwCallback(ControlCode, CallbackContext)
  63. // Work-around for a bug in the instrumentationevents generator
  64. #pragma prefast(push)
  65. #pragma prefast(disable:__WARNING_USING_UNINIT_VAR, "The ETW data generated from the manifest includes a default null function which uses unintialized memory.")
  66. #include <microsoft-scripting-chakra-instrumentationevents.h>
  67. #ifdef NTBUILD
  68. #include <ieresp_mshtml.h>
  69. #include <microsoft-scripting-jscript9.internalevents.h>
  70. #endif
  71. #pragma prefast(pop)
  72. //
  73. // Encapsulates base routines to initialize ETW tracing in the module
  74. //
  75. class EtwTraceCore
  76. {
  77. public:
  78. static void Register();
  79. static void UnRegister();
  80. static bool s_registered;
  81. };
  82. #endif // ENABLE_JS_LTTNG
  83. #else
  84. #define GCETW(e, ...)
  85. #define IS_GCETW_Enabled(e) false
  86. #define JS_ETW(s)
  87. #define IS_JS_ETW(s) (false)
  88. #define GCETW_INTERNAL(e, args)
  89. #define JS_ETW_INTERNAL(s)
  90. #define EDGE_ETW_INTERNAL(s)
  91. #endif