Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Unified Diff: base/debug/profiler.cc

Issue 1446363003: Deleted OS_WIN and all Windows specific files from base. (Closed) Base URL: https://github.com/domokit/mojo.git@base_tests
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/debug/gdi_debug_util_win.cc ('k') | base/debug/stack_trace.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/profiler.cc
diff --git a/base/debug/profiler.cc b/base/debug/profiler.cc
index ed553cdf2939ea68d6ccb7dac4e84aacec7955e2..61148e5c5548d74298338c7421a68d75ebdba1c4 100644
--- a/base/debug/profiler.cc
+++ b/base/debug/profiler.cc
@@ -10,12 +10,8 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#if defined(OS_WIN)
-#include "base/win/pe_image.h"
-#endif // defined(OS_WIN)
-
// TODO(peria): Enable profiling on Windows.
-#if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) && !defined(OS_WIN)
+#if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/gperftools/profiler.h"
#endif
@@ -23,7 +19,7 @@ namespace base {
namespace debug {
// TODO(peria): Enable profiling on Windows.
-#if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC) && !defined(OS_WIN)
+#if defined(ENABLE_PROFILING) && !defined(NO_TCMALLOC)
static int profile_count = 0;
@@ -74,8 +70,6 @@ void RestartProfilingAfterFork() {
#endif
-#if !defined(OS_WIN)
-
bool IsBinaryInstrumented() {
return false;
}
@@ -96,124 +90,6 @@ MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc() {
return NULL;
}
-#else // defined(OS_WIN)
-
-// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
-extern "C" IMAGE_DOS_HEADER __ImageBase;
-
-bool IsBinaryInstrumented() {
- enum InstrumentationCheckState {
- UNINITIALIZED,
- INSTRUMENTED_IMAGE,
- NON_INSTRUMENTED_IMAGE,
- };
-
- static InstrumentationCheckState state = UNINITIALIZED;
-
- if (state == UNINITIALIZED) {
- HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
- base::win::PEImage image(this_module);
-
- // Check to be sure our image is structured as we'd expect.
- DCHECK(image.VerifyMagic());
-
- // Syzygy-instrumented binaries contain a PE image section named ".thunks",
- // and all Syzygy-modified binaries contain the ".syzygy" image section.
- // This is a very fast check, as it only looks at the image header.
- if ((image.GetImageSectionHeaderByName(".thunks") != NULL) &&
- (image.GetImageSectionHeaderByName(".syzygy") != NULL)) {
- state = INSTRUMENTED_IMAGE;
- } else {
- state = NON_INSTRUMENTED_IMAGE;
- }
- }
- DCHECK(state != UNINITIALIZED);
-
- return state == INSTRUMENTED_IMAGE;
-}
-
-namespace {
-
-struct FunctionSearchContext {
- const char* name;
- FARPROC function;
-};
-
-// Callback function to PEImage::EnumImportChunks.
-bool FindResolutionFunctionInImports(
- const base::win::PEImage &image, const char* module_name,
- PIMAGE_THUNK_DATA unused_name_table, PIMAGE_THUNK_DATA import_address_table,
- PVOID cookie) {
- FunctionSearchContext* context =
- reinterpret_cast<FunctionSearchContext*>(cookie);
-
- DCHECK_NE(static_cast<FunctionSearchContext*>(NULL), context);
- DCHECK_EQ(static_cast<FARPROC>(NULL), context->function);
-
- // Our import address table contains pointers to the functions we import
- // at this point. Let's retrieve the first such function and use it to
- // find the module this import was resolved to by the loader.
- const wchar_t* function_in_module =
- reinterpret_cast<const wchar_t*>(import_address_table->u1.Function);
-
- // Retrieve the module by a function in the module.
- const DWORD kFlags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
- HMODULE module = NULL;
- if (!::GetModuleHandleEx(kFlags, function_in_module, &module)) {
- // This can happen if someone IAT patches us to a thunk.
- return true;
- }
-
- // See whether this module exports the function we're looking for.
- FARPROC exported_func = ::GetProcAddress(module, context->name);
- if (exported_func != NULL) {
- // We found it, return the function and terminate the enumeration.
- context->function = exported_func;
- return false;
- }
-
- // Keep going.
- return true;
-}
-
-template <typename FunctionType>
-FunctionType FindFunctionInImports(const char* function_name) {
- if (!IsBinaryInstrumented())
- return NULL;
-
- HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
- base::win::PEImage image(this_module);
-
- FunctionSearchContext ctx = { function_name, NULL };
- image.EnumImportChunks(FindResolutionFunctionInImports, &ctx);
-
- return reinterpret_cast<FunctionType>(ctx.function);
-}
-
-} // namespace
-
-ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() {
- return FindFunctionInImports<ReturnAddressLocationResolver>(
- "ResolveReturnAddressLocation");
-}
-
-DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc() {
- return FindFunctionInImports<DynamicFunctionEntryHook>(
- "OnDynamicFunctionEntry");
-}
-
-AddDynamicSymbol GetProfilerAddDynamicSymbolFunc() {
- return FindFunctionInImports<AddDynamicSymbol>(
- "AddDynamicSymbol");
-}
-
-MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc() {
- return FindFunctionInImports<MoveDynamicSymbol>(
- "MoveDynamicSymbol");
-}
-
-#endif // defined(OS_WIN)
} // namespace debug
} // namespace base
« no previous file with comments | « base/debug/gdi_debug_util_win.cc ('k') | base/debug/stack_trace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698