1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/debug/profiler.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_DEBUG_PROFILER_H 1.9 +#define BASE_DEBUG_PROFILER_H 1.10 + 1.11 +#include <string> 1.12 + 1.13 +#include "base/base_export.h" 1.14 +#include "base/basictypes.h" 1.15 + 1.16 +// The Profiler functions allow usage of the underlying sampling based 1.17 +// profiler. If the application has not been built with the necessary 1.18 +// flags (-DENABLE_PROFILING and not -DNO_TCMALLOC) then these functions 1.19 +// are noops. 1.20 +namespace base { 1.21 +namespace debug { 1.22 + 1.23 +// Start profiling with the supplied name. 1.24 +// {pid} will be replaced by the process' pid and {count} will be replaced 1.25 +// by the count of the profile run (starts at 1 with each process). 1.26 +BASE_EXPORT void StartProfiling(const std::string& name); 1.27 + 1.28 +// Stop profiling and write out data. 1.29 +BASE_EXPORT void StopProfiling(); 1.30 + 1.31 +// Force data to be written to file. 1.32 +BASE_EXPORT void FlushProfiling(); 1.33 + 1.34 +// Returns true if process is being profiled. 1.35 +BASE_EXPORT bool BeingProfiled(); 1.36 + 1.37 +// Reset profiling after a fork, which disables timers. 1.38 +BASE_EXPORT void RestartProfilingAfterFork(); 1.39 + 1.40 +// Returns true iff this executable is instrumented with the Syzygy profiler. 1.41 +BASE_EXPORT bool IsBinaryInstrumented(); 1.42 + 1.43 +// There's a class of profilers that use "return address swizzling" to get a 1.44 +// hook on function exits. This class of profilers uses some form of entry hook, 1.45 +// like e.g. binary instrumentation, or a compiler flag, that calls a hook each 1.46 +// time a function is invoked. The hook then switches the return address on the 1.47 +// stack for the address of an exit hook function, and pushes the original 1.48 +// return address to a shadow stack of some type. When in due course the CPU 1.49 +// executes a return to the exit hook, the exit hook will do whatever work it 1.50 +// does on function exit, then arrange to return to the original return address. 1.51 +// This class of profiler does not play well with programs that look at the 1.52 +// return address, as does e.g. V8. V8 uses the return address to certain 1.53 +// runtime functions to find the JIT code that called it, and from there finds 1.54 +// the V8 data structures associated to the JS function involved. 1.55 +// A return address resolution function is used to fix this. It allows such 1.56 +// programs to resolve a location on stack where a return address originally 1.57 +// resided, to the shadow stack location where the profiler stashed it. 1.58 +typedef uintptr_t (*ReturnAddressLocationResolver)( 1.59 + uintptr_t return_addr_location); 1.60 + 1.61 +// This type declaration must match V8's FunctionEntryHook. 1.62 +typedef void (*DynamicFunctionEntryHook)(uintptr_t function, 1.63 + uintptr_t return_addr_location); 1.64 + 1.65 +// The functions below here are to support profiling V8-generated code. 1.66 +// V8 has provisions for generating a call to an entry hook for newly generated 1.67 +// JIT code, and it can push symbol information on code generation and advise 1.68 +// when the garbage collector moves code. The functions declarations below here 1.69 +// make glue between V8's facilities and a profiler. 1.70 + 1.71 +// This type declaration must match V8's FunctionEntryHook. 1.72 +typedef void (*DynamicFunctionEntryHook)(uintptr_t function, 1.73 + uintptr_t return_addr_location); 1.74 + 1.75 +typedef void (*AddDynamicSymbol)(const void* address, 1.76 + size_t length, 1.77 + const char* name, 1.78 + size_t name_len); 1.79 +typedef void (*MoveDynamicSymbol)(const void* address, const void* new_address); 1.80 + 1.81 + 1.82 +// If this binary is instrumented and the instrumentation supplies a function 1.83 +// for each of those purposes, find and return the function in question. 1.84 +// Otherwise returns NULL. 1.85 +BASE_EXPORT ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc(); 1.86 +BASE_EXPORT DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc(); 1.87 +BASE_EXPORT AddDynamicSymbol GetProfilerAddDynamicSymbolFunc(); 1.88 +BASE_EXPORT MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc(); 1.89 + 1.90 +} // namespace debug 1.91 +} // namespace base 1.92 + 1.93 +#endif // BASE_DEBUG_DEBUGGER_H