EtwTraceCore.cpp 1.6 KB

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