| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/win/current_module.h" |
| 9 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
| 10 | 11 |
| 11 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | |
| 12 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
| 13 | |
| 14 namespace base { | 12 namespace base { |
| 15 namespace win { | 13 namespace win { |
| 16 namespace testing { | 14 namespace testing { |
| 17 | 15 |
| 18 extern "C" bool __declspec(dllexport) RunTest(); | 16 extern "C" bool __declspec(dllexport) RunTest(); |
| 19 | 17 |
| 20 namespace { | 18 namespace { |
| 21 | 19 |
| 22 struct ThreadParams { | 20 struct ThreadParams { |
| 23 HANDLE ready_event; | 21 HANDLE ready_event; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); | 86 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); |
| 89 if (!handle) | 87 if (!handle) |
| 90 return false; | 88 return false; |
| 91 ScopedHandle handle_holder(handle); | 89 ScopedHandle handle_holder(handle); |
| 92 | 90 |
| 93 HMODULE verifier_module = GetHandleVerifierModuleForTesting(); | 91 HMODULE verifier_module = GetHandleVerifierModuleForTesting(); |
| 94 if (!verifier_module) | 92 if (!verifier_module) |
| 95 return false; | 93 return false; |
| 96 | 94 |
| 97 // Get my module | 95 // Get my module |
| 98 HMODULE my_module = reinterpret_cast<HMODULE>(&__ImageBase); | 96 HMODULE my_module = CURRENT_MODULE(); |
| 99 if (!my_module) | 97 if (!my_module) |
| 100 return false; | 98 return false; |
| 101 | 99 |
| 102 HMODULE main_module = ::GetModuleHandle(NULL); | 100 HMODULE main_module = ::GetModuleHandle(NULL); |
| 103 | 101 |
| 104 #if defined(COMPONENT_BUILD) | 102 #if defined(COMPONENT_BUILD) |
| 105 // In a component build ActiveVerifier will always be created inside base.dll | 103 // In a component build ActiveVerifier will always be created inside base.dll |
| 106 // as the code always lives there. | 104 // as the code always lives there. |
| 107 if (verifier_module == my_module || verifier_module == main_module) | 105 if (verifier_module == my_module || verifier_module == main_module) |
| 108 return false; | 106 return false; |
| 109 #else | 107 #else |
| 110 // In a non-component build, ActiveVerifier should always be created in the | 108 // In a non-component build, ActiveVerifier should always be created in the |
| 111 // version of base linked with the main executable. | 109 // version of base linked with the main executable. |
| 112 if (verifier_module == my_module || verifier_module != main_module) | 110 if (verifier_module == my_module || verifier_module != main_module) |
| 113 return false; | 111 return false; |
| 114 #endif | 112 #endif |
| 115 return true; | 113 return true; |
| 116 } | 114 } |
| 117 | 115 |
| 118 } // namespace | 116 } // namespace |
| 119 | 117 |
| 120 bool RunTest() { | 118 bool RunTest() { |
| 121 return InternalRunThreadTest() && InternalRunLocationTest(); | 119 return InternalRunThreadTest() && InternalRunLocationTest(); |
| 122 } | 120 } |
| 123 | 121 |
| 124 } // testing | 122 } // testing |
| 125 } // win | 123 } // win |
| 126 } // base | 124 } // base |
| OLD | NEW |