OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/debug/profiler.h" | 5 #include "base/debug/profiler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { | 81 ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { |
82 return NULL; | 82 return NULL; |
83 } | 83 } |
84 | 84 |
85 #else // defined(OS_WIN) | 85 #else // defined(OS_WIN) |
86 | 86 |
87 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 87 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
88 extern "C" IMAGE_DOS_HEADER __ImageBase; | 88 extern "C" IMAGE_DOS_HEADER __ImageBase; |
89 | 89 |
90 bool IsBinaryInstrumented() { | 90 bool IsBinaryInstrumented() { |
91 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); | 91 enum InstrumentationCheckState { |
92 base::win::PEImage image(this_module); | 92 UNINITIALIZED, |
93 INSTRUMENTED_IMAGE, | |
94 NON_INSTRUMENTED_IMAGE, | |
95 }; | |
93 | 96 |
94 // This should be self-evident, soon as we're executing. | 97 static InstrumentationCheckState state = UNINITIALIZED; |
95 DCHECK(image.VerifyMagic()); | |
96 | 98 |
97 // Syzygy-instrumented binaries contain a PE image section named ".thunks", | 99 if (state == UNINITIALIZED) { |
98 // and all Syzygy-modified binaries contain the ".syzygy" image section. | 100 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
99 // This is a very fast check, as it only looks at the image header. | 101 base::win::PEImage image(this_module); |
100 return (image.GetImageSectionHeaderByName(".thunks") != NULL) && | 102 |
101 (image.GetImageSectionHeaderByName(".syzygy") != NULL); | 103 // This should be self-evident, soon as we're executing. |
jar (doing other things)
2012/05/30 19:41:23
nit: This was a strange comment.
Are you saying in
Sigurður Ásgeirsson
2012/05/30 20:52:12
Done.
| |
104 DCHECK(image.VerifyMagic()); | |
105 | |
106 // Syzygy-instrumented binaries contain a PE image section named ".thunks", | |
107 // and all Syzygy-modified binaries contain the ".syzygy" image section. | |
108 // This is a very fast check, as it only looks at the image header. | |
109 if ((image.GetImageSectionHeaderByName(".thunks") != NULL) && | |
110 (image.GetImageSectionHeaderByName(".syzygy") != NULL)) { | |
111 state = INSTRUMENTED_IMAGE; | |
112 } else { | |
113 state = NON_INSTRUMENTED_IMAGE; | |
114 } | |
115 } | |
116 DCHECK(state != UNINITIALIZED); | |
117 | |
118 return state == INSTRUMENTED_IMAGE; | |
102 } | 119 } |
103 | 120 |
104 // Callback function to PEImage::EnumImportChunks. | 121 // Callback function to PEImage::EnumImportChunks. |
105 static bool FindResolutionFunctionInImports( | 122 static bool FindResolutionFunctionInImports( |
106 const base::win::PEImage &image, const char* module_name, | 123 const base::win::PEImage &image, const char* module_name, |
107 PIMAGE_THUNK_DATA unused_name_table, PIMAGE_THUNK_DATA import_address_table, | 124 PIMAGE_THUNK_DATA unused_name_table, PIMAGE_THUNK_DATA import_address_table, |
108 PVOID cookie) { | 125 PVOID cookie) { |
109 // Our import address table contains pointers to the functions we import | 126 // Our import address table contains pointers to the functions we import |
110 // at this point. Let's retrieve the first such function and use it to | 127 // at this point. Let's retrieve the first such function and use it to |
111 // find the module this import was resolved to by the loader. | 128 // find the module this import was resolved to by the loader. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 ReturnAddressLocationResolver resolver_func = NULL; | 168 ReturnAddressLocationResolver resolver_func = NULL; |
152 image.EnumImportChunks(FindResolutionFunctionInImports, &resolver_func); | 169 image.EnumImportChunks(FindResolutionFunctionInImports, &resolver_func); |
153 | 170 |
154 return resolver_func; | 171 return resolver_func; |
155 } | 172 } |
156 | 173 |
157 #endif // defined(OS_WIN) | 174 #endif // defined(OS_WIN) |
158 | 175 |
159 } // namespace debug | 176 } // namespace debug |
160 } // namespace base | 177 } // namespace base |
OLD | NEW |