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