toolkit/crashreporter/google-breakpad/src/processor/cfi_frame_info-inl.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // -*- mode: C++ -*-
     3 // Copyright (c) 2010, Google Inc.
     4 // All rights reserved.
     5 //
     6 // Redistribution and use in source and binary forms, with or without
     7 // modification, are permitted provided that the following conditions are
     8 // met:
     9 //
    10 //     * Redistributions of source code must retain the above copyright
    11 // notice, this list of conditions and the following disclaimer.
    12 //     * Redistributions in binary form must reproduce the above
    13 // copyright notice, this list of conditions and the following disclaimer
    14 // in the documentation and/or other materials provided with the
    15 // distribution.
    16 //     * Neither the name of Google Inc. nor the names of its
    17 // contributors may be used to endorse or promote products derived from
    18 // this software without specific prior written permission.
    19 //
    20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    34 // cfi_frame_info-inl.h: Definitions for cfi_frame_info.h inlined functions.
    36 #ifndef PROCESSOR_CFI_FRAME_INFO_INL_H_
    37 #define PROCESSOR_CFI_FRAME_INFO_INL_H_
    39 #include <string.h>
    41 namespace google_breakpad {
    43 template <typename RegisterValueType, class RawContextType>
    44 bool SimpleCFIWalker<RegisterValueType, RawContextType>::FindCallerRegisters(
    45     const MemoryRegion &memory,
    46     const CFIFrameInfo &cfi_frame_info,
    47     const RawContextType &callee_context,
    48     int callee_validity,
    49     RawContextType *caller_context,
    50     int *caller_validity) const {
    51   typedef CFIFrameInfo::RegisterValueMap<RegisterValueType> ValueMap;
    52   ValueMap callee_registers;
    53   ValueMap caller_registers;
    55   // Populate callee_registers with register values from callee_context.
    56   for (size_t i = 0; i < map_size_; i++) {
    57     const RegisterSet &r = register_map_[i];
    58     if (callee_validity & r.validity_flag)
    59       callee_registers.set(r.name, callee_context.*r.context_member);
    60   }
    62   // Apply the rules, and see what register values they yield.
    63   if (!cfi_frame_info
    64        .FindCallerRegs<RegisterValueType>(callee_registers, memory,
    65                                           &caller_registers))
    66     return false;
    68   // Populate *caller_context with the values the rules placed in
    69   // caller_registers.
    70   memset(caller_context, 0xda, sizeof(*caller_context));
    71   *caller_validity = 0;
    72   for (size_t i = 0; i < map_size_; i++) {
    73     const RegisterSet &r = register_map_[i];
    75     // Did the rules provide a value for this register by its name?
    76     bool found = false;
    77     RegisterValueType v = caller_registers.get(&found, r.name);
    78     if (found) {
    79       caller_context->*r.context_member = v;
    80       *caller_validity |= r.validity_flag;
    81       continue;
    82     }
    84     // Did the rules provide a value for this register under its
    85     // alternate name?
    86     if (r.alternate_name) {
    87       found = false;
    88       v = caller_registers.get(&found, r.alternate_name);
    89       if (found) {
    90         caller_context->*r.context_member = v;
    91         *caller_validity |= r.validity_flag;
    92         continue;
    93       }
    94     }
    96     // Is this a callee-saves register? The walker assumes that these
    97     // still hold the caller's value if the CFI doesn't mention them.
    98     //
    99     // Note that other frame walkers may fail to recover callee-saves
   100     // registers; for example, the x86 "traditional" strategy only
   101     // recovers %eip, %esp, and %ebp, even though %ebx, %esi, and %edi
   102     // are callee-saves, too. It is not correct to blindly set the
   103     // valid bit for all callee-saves registers, without first
   104     // checking its validity bit in the callee.
   105     if (r.callee_saves && (callee_validity & r.validity_flag) != 0) {
   106       caller_context->*r.context_member = callee_context.*r.context_member;
   107       *caller_validity |= r.validity_flag;
   108       continue;
   109     }
   111     // Otherwise, the register's value is unknown.
   112   }
   114   return true;
   115 }
   117 } // namespace google_breakpad
   119 #endif // PROCESSOR_CFI_FRAME_INFO_INL_H_

mercurial