security/sandbox/chromium/base/location.cc

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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
     3 // found in the LICENSE file.
     5 #include "build/build_config.h"
     7 #if defined(COMPILER_MSVC)
     8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build.
     9 extern "C" {
    10   void* _ReturnAddress();
    11 }
    12 #endif
    14 #include "base/location.h"
    15 #include "base/strings/string_number_conversions.h"
    16 #include "base/strings/stringprintf.h"
    18 namespace tracked_objects {
    20 Location::Location(const char* function_name,
    21                    const char* file_name,
    22                    int line_number,
    23                    const void* program_counter)
    24     : function_name_(function_name),
    25       file_name_(file_name),
    26       line_number_(line_number),
    27       program_counter_(program_counter) {
    28 }
    30 Location::Location()
    31     : function_name_("Unknown"),
    32       file_name_("Unknown"),
    33       line_number_(-1),
    34       program_counter_(NULL) {
    35 }
    37 std::string Location::ToString() const {
    38   return std::string(function_name_) + "@" + file_name_ + ":" +
    39       base::IntToString(line_number_);
    40 }
    42 void Location::Write(bool display_filename, bool display_function_name,
    43                      std::string* output) const {
    44   base::StringAppendF(output, "%s[%d] ",
    45       display_filename ? file_name_ : "line",
    46       line_number_);
    48   if (display_function_name) {
    49     WriteFunctionName(output);
    50     output->push_back(' ');
    51   }
    52 }
    54 void Location::WriteFunctionName(std::string* output) const {
    55   // Translate "<" to "&lt;" for HTML safety.
    56   // TODO(jar): Support ASCII or html for logging in ASCII.
    57   for (const char *p = function_name_; *p; p++) {
    58     switch (*p) {
    59       case '<':
    60         output->append("&lt;");
    61         break;
    63       case '>':
    64         output->append("&gt;");
    65         break;
    67       default:
    68         output->push_back(*p);
    69         break;
    70     }
    71   }
    72 }
    74 //------------------------------------------------------------------------------
    75 LocationSnapshot::LocationSnapshot() : line_number(-1) {
    76 }
    78 LocationSnapshot::LocationSnapshot(
    79     const tracked_objects::Location& location)
    80     : file_name(location.file_name()),
    81       function_name(location.function_name()),
    82       line_number(location.line_number()) {
    83 }
    85 LocationSnapshot::~LocationSnapshot() {
    86 }
    88 //------------------------------------------------------------------------------
    89 #if defined(COMPILER_MSVC)
    90 __declspec(noinline)
    91 #endif
    92 BASE_EXPORT const void* GetProgramCounter() {
    93 #if defined(COMPILER_MSVC)
    94   return _ReturnAddress();
    95 #elif defined(COMPILER_GCC)
    96   return __builtin_extract_return_addr(__builtin_return_address(0));
    97 #endif  // COMPILER_GCC
    99   return NULL;
   100 }
   102 }  // namespace tracked_objects

mercurial