Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_DEBUG_PROFILER_H |
michael@0 | 6 | #define BASE_DEBUG_PROFILER_H |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | |
michael@0 | 10 | #include "base/base_export.h" |
michael@0 | 11 | #include "base/basictypes.h" |
michael@0 | 12 | |
michael@0 | 13 | // The Profiler functions allow usage of the underlying sampling based |
michael@0 | 14 | // profiler. If the application has not been built with the necessary |
michael@0 | 15 | // flags (-DENABLE_PROFILING and not -DNO_TCMALLOC) then these functions |
michael@0 | 16 | // are noops. |
michael@0 | 17 | namespace base { |
michael@0 | 18 | namespace debug { |
michael@0 | 19 | |
michael@0 | 20 | // Start profiling with the supplied name. |
michael@0 | 21 | // {pid} will be replaced by the process' pid and {count} will be replaced |
michael@0 | 22 | // by the count of the profile run (starts at 1 with each process). |
michael@0 | 23 | BASE_EXPORT void StartProfiling(const std::string& name); |
michael@0 | 24 | |
michael@0 | 25 | // Stop profiling and write out data. |
michael@0 | 26 | BASE_EXPORT void StopProfiling(); |
michael@0 | 27 | |
michael@0 | 28 | // Force data to be written to file. |
michael@0 | 29 | BASE_EXPORT void FlushProfiling(); |
michael@0 | 30 | |
michael@0 | 31 | // Returns true if process is being profiled. |
michael@0 | 32 | BASE_EXPORT bool BeingProfiled(); |
michael@0 | 33 | |
michael@0 | 34 | // Reset profiling after a fork, which disables timers. |
michael@0 | 35 | BASE_EXPORT void RestartProfilingAfterFork(); |
michael@0 | 36 | |
michael@0 | 37 | // Returns true iff this executable is instrumented with the Syzygy profiler. |
michael@0 | 38 | BASE_EXPORT bool IsBinaryInstrumented(); |
michael@0 | 39 | |
michael@0 | 40 | // There's a class of profilers that use "return address swizzling" to get a |
michael@0 | 41 | // hook on function exits. This class of profilers uses some form of entry hook, |
michael@0 | 42 | // like e.g. binary instrumentation, or a compiler flag, that calls a hook each |
michael@0 | 43 | // time a function is invoked. The hook then switches the return address on the |
michael@0 | 44 | // stack for the address of an exit hook function, and pushes the original |
michael@0 | 45 | // return address to a shadow stack of some type. When in due course the CPU |
michael@0 | 46 | // executes a return to the exit hook, the exit hook will do whatever work it |
michael@0 | 47 | // does on function exit, then arrange to return to the original return address. |
michael@0 | 48 | // This class of profiler does not play well with programs that look at the |
michael@0 | 49 | // return address, as does e.g. V8. V8 uses the return address to certain |
michael@0 | 50 | // runtime functions to find the JIT code that called it, and from there finds |
michael@0 | 51 | // the V8 data structures associated to the JS function involved. |
michael@0 | 52 | // A return address resolution function is used to fix this. It allows such |
michael@0 | 53 | // programs to resolve a location on stack where a return address originally |
michael@0 | 54 | // resided, to the shadow stack location where the profiler stashed it. |
michael@0 | 55 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
michael@0 | 56 | uintptr_t return_addr_location); |
michael@0 | 57 | |
michael@0 | 58 | // This type declaration must match V8's FunctionEntryHook. |
michael@0 | 59 | typedef void (*DynamicFunctionEntryHook)(uintptr_t function, |
michael@0 | 60 | uintptr_t return_addr_location); |
michael@0 | 61 | |
michael@0 | 62 | // The functions below here are to support profiling V8-generated code. |
michael@0 | 63 | // V8 has provisions for generating a call to an entry hook for newly generated |
michael@0 | 64 | // JIT code, and it can push symbol information on code generation and advise |
michael@0 | 65 | // when the garbage collector moves code. The functions declarations below here |
michael@0 | 66 | // make glue between V8's facilities and a profiler. |
michael@0 | 67 | |
michael@0 | 68 | // This type declaration must match V8's FunctionEntryHook. |
michael@0 | 69 | typedef void (*DynamicFunctionEntryHook)(uintptr_t function, |
michael@0 | 70 | uintptr_t return_addr_location); |
michael@0 | 71 | |
michael@0 | 72 | typedef void (*AddDynamicSymbol)(const void* address, |
michael@0 | 73 | size_t length, |
michael@0 | 74 | const char* name, |
michael@0 | 75 | size_t name_len); |
michael@0 | 76 | typedef void (*MoveDynamicSymbol)(const void* address, const void* new_address); |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | // If this binary is instrumented and the instrumentation supplies a function |
michael@0 | 80 | // for each of those purposes, find and return the function in question. |
michael@0 | 81 | // Otherwise returns NULL. |
michael@0 | 82 | BASE_EXPORT ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc(); |
michael@0 | 83 | BASE_EXPORT DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc(); |
michael@0 | 84 | BASE_EXPORT AddDynamicSymbol GetProfilerAddDynamicSymbolFunc(); |
michael@0 | 85 | BASE_EXPORT MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc(); |
michael@0 | 86 | |
michael@0 | 87 | } // namespace debug |
michael@0 | 88 | } // namespace base |
michael@0 | 89 | |
michael@0 | 90 | #endif // BASE_DEBUG_DEBUGGER_H |