| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome_frame/vtable_patch_manager.h" | 5 #include "chrome_frame/vtable_patch_manager.h" |
| 6 | 6 |
| 7 #include <atlcomcli.h> | 7 #include <atlcomcli.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "chrome_frame/function_stub.h" | 15 #include "chrome_frame/function_stub.h" |
| 16 #include "chrome_frame/utils.h" | 16 #include "chrome_frame/pin_module.h" |
| 17 | 17 |
| 18 namespace vtable_patch { | 18 namespace vtable_patch { |
| 19 | 19 |
| 20 // The number of times we retry a patch/unpatch operation in case of | 20 // The number of times we retry a patch/unpatch operation in case of |
| 21 // VM races with other 3rd party software trying to patch the same thing. | 21 // VM races with other 3rd party software trying to patch the same thing. |
| 22 const int kMaxRetries = 3; | 22 const int kMaxRetries = 3; |
| 23 | 23 |
| 24 // We hold a lock over all patching operations to make sure that we don't | 24 // We hold a lock over all patching operations to make sure that we don't |
| 25 // e.g. race on VM operations to the same patches, or to physical pages | 25 // e.g. race on VM operations to the same patches, or to physical pages |
| 26 // shared across different VTABLEs. | 26 // shared across different VTABLEs. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 if (!succeeded) { | 138 if (!succeeded) { |
| 139 FunctionStub::Destroy(stub); | 139 FunctionStub::Destroy(stub); |
| 140 stub = NULL; | 140 stub = NULL; |
| 141 | 141 |
| 142 DLOG(ERROR) << "Failed to patch VTable."; | 142 DLOG(ERROR) << "Failed to patch VTable."; |
| 143 return E_FAIL; | 143 return E_FAIL; |
| 144 } else { | 144 } else { |
| 145 // Success, save the stub we created. | 145 // Success, save the stub we created. |
| 146 it->stub_ = stub; | 146 it->stub_ = stub; |
| 147 PinModule(); | 147 chrome_frame::PinModule(); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 return S_OK; | 151 return S_OK; |
| 152 } | 152 } |
| 153 | 153 |
| 154 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches) { | 154 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches) { |
| 155 base::AutoLock lock(patch_lock_); | 155 base::AutoLock lock(patch_lock_); |
| 156 | 156 |
| 157 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { | 157 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 235 } |
| 236 patch_list_.clear(); | 236 patch_list_.clear(); |
| 237 patch_list_lock_.Release(); | 237 patch_list_lock_.Release(); |
| 238 | 238 |
| 239 return true; | 239 return true; |
| 240 } | 240 } |
| 241 | 241 |
| 242 #endif // disabled DynamicPatchManager | 242 #endif // disabled DynamicPatchManager |
| 243 | 243 |
| 244 } // namespace vtable_patch | 244 } // namespace vtable_patch |
| OLD | NEW |