com_init_check_hook.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_WIN_COM_INIT_CHECK_HOOK_H_
  5. #define BASE_WIN_COM_INIT_CHECK_HOOK_H_
  6. #include "base/base_export.h"
  7. #include "base/check_op.h"
  8. #include "base/macros.h"
  9. #include "build/build_config.h"
  10. namespace device {
  11. class XrDeviceService;
  12. } // namespace device
  13. namespace base {
  14. namespace win {
  15. // Hotpatching is only supported in Intel 32-bit x86 processors because Windows
  16. // binaries contain a convenient 2 byte hotpatch noop. This doesn't exist in
  17. // 64-bit binaries.
  18. #if DCHECK_IS_ON() && defined(ARCH_CPU_X86_FAMILY) && \
  19. defined(ARCH_CPU_32_BITS) && !defined(OFFICIAL_BUILD) && \
  20. !defined(COM_INIT_CHECK_HOOK_DISABLED) // See crbug/737090 for details.
  21. #define COM_INIT_CHECK_HOOK_ENABLED
  22. #endif
  23. // Manages the installation of consistency DCHECK hooks of COM APIs that require
  24. // COM to be initialized and only works if COM_INIT_CHECK_HOOK_ENABLED is
  25. // defined. Care should be taken if this is instantiated with multiple threads
  26. // running as the hotpatch does not apply atomically.
  27. class BASE_EXPORT ComInitCheckHook {
  28. public:
  29. ComInitCheckHook();
  30. ~ComInitCheckHook();
  31. private:
  32. // For components that cannot use COM_INIT_CHECK_HOOK_DISABLED, call
  33. // DisableCOMChecksForProcess() below. This should only be for code that calls
  34. // into Windows components that don't explicitly initialize the MTA in the
  35. // Windows thread pool.
  36. friend class device::XrDeviceService;
  37. static void DisableCOMChecksForProcess();
  38. DISALLOW_COPY_AND_ASSIGN(ComInitCheckHook);
  39. };
  40. } // namespace win
  41. } // namespace base
  42. #endif // BASE_WIN_COM_INIT_CHECK_HOOK_H_