EtwTraceCore.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "CommonCorePch.h"
  6. #include "Core/EtwTraceCore.h"
  7. #ifdef ENABLE_JS_ETW
  8. #ifndef ENABLE_JS_LTTNG
  9. extern "C" {
  10. ETW_INLINE
  11. VOID EtwCallback(
  12. ULONG controlCode,
  13. PVOID callbackContext)
  14. {
  15. EtwCallbackApi::OnSessionChange(controlCode, callbackContext);
  16. }
  17. }
  18. bool EtwTraceCore::s_registered = false;
  19. //
  20. // Registers the ETW provider - this is usually done on Jscript DLL load
  21. // After registration, we will receive callbacks when ETW tracing is enabled/disabled.
  22. //
  23. void EtwTraceCore::Register()
  24. {
  25. if (!s_registered)
  26. {
  27. s_registered = true;
  28. #ifdef NTBUILD
  29. JS_ETW(EventRegisterMicrosoft_IE());
  30. #endif
  31. JS_ETW(EventRegisterMicrosoft_JScript());
  32. #ifdef NTBUILD
  33. JS_ETW(EventRegisterMicrosoft_JScript_Internal());
  34. #endif
  35. // This will be used to distinguish the provider we are getting the callback for.
  36. PROVIDER_JSCRIPT9_Context.RegistrationHandle = Microsoft_JScriptHandle;
  37. #ifdef NTBUILD
  38. BERP_IE_Context.RegistrationHandle = Microsoft_IEHandle;
  39. #endif
  40. }
  41. }
  42. //
  43. // Unregister to ensure we do not get callbacks.
  44. //
  45. void EtwTraceCore::UnRegister()
  46. {
  47. if (s_registered)
  48. {
  49. s_registered = false;
  50. #ifdef NTBUILD
  51. JS_ETW(EventUnregisterMicrosoft_IE());
  52. #endif
  53. JS_ETW(EventUnregisterMicrosoft_JScript());
  54. #ifdef NTBUILD
  55. JS_ETW(EventUnregisterMicrosoft_JScript_Internal());
  56. #endif
  57. }
  58. }
  59. #endif // !ENABLE_JS_LTTNG
  60. #endif // ENABLE_JS_ETW