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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/cfi_frame_info-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +// -*- mode: C++ -*-
     1.5 +
     1.6 +// Copyright (c) 2010, Google Inc.
     1.7 +// All rights reserved.
     1.8 +//
     1.9 +// Redistribution and use in source and binary forms, with or without
    1.10 +// modification, are permitted provided that the following conditions are
    1.11 +// met:
    1.12 +//
    1.13 +//     * Redistributions of source code must retain the above copyright
    1.14 +// notice, this list of conditions and the following disclaimer.
    1.15 +//     * Redistributions in binary form must reproduce the above
    1.16 +// copyright notice, this list of conditions and the following disclaimer
    1.17 +// in the documentation and/or other materials provided with the
    1.18 +// distribution.
    1.19 +//     * Neither the name of Google Inc. nor the names of its
    1.20 +// contributors may be used to endorse or promote products derived from
    1.21 +// this software without specific prior written permission.
    1.22 +//
    1.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +
    1.35 +// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    1.36 +
    1.37 +// cfi_frame_info-inl.h: Definitions for cfi_frame_info.h inlined functions.
    1.38 +
    1.39 +#ifndef PROCESSOR_CFI_FRAME_INFO_INL_H_
    1.40 +#define PROCESSOR_CFI_FRAME_INFO_INL_H_
    1.41 +
    1.42 +#include <string.h>
    1.43 +
    1.44 +namespace google_breakpad {
    1.45 +
    1.46 +template <typename RegisterValueType, class RawContextType>
    1.47 +bool SimpleCFIWalker<RegisterValueType, RawContextType>::FindCallerRegisters(
    1.48 +    const MemoryRegion &memory,
    1.49 +    const CFIFrameInfo &cfi_frame_info,
    1.50 +    const RawContextType &callee_context,
    1.51 +    int callee_validity,
    1.52 +    RawContextType *caller_context,
    1.53 +    int *caller_validity) const {
    1.54 +  typedef CFIFrameInfo::RegisterValueMap<RegisterValueType> ValueMap;
    1.55 +  ValueMap callee_registers;
    1.56 +  ValueMap caller_registers;
    1.57 +
    1.58 +  // Populate callee_registers with register values from callee_context.
    1.59 +  for (size_t i = 0; i < map_size_; i++) {
    1.60 +    const RegisterSet &r = register_map_[i];
    1.61 +    if (callee_validity & r.validity_flag)
    1.62 +      callee_registers.set(r.name, callee_context.*r.context_member);
    1.63 +  }
    1.64 +
    1.65 +  // Apply the rules, and see what register values they yield.
    1.66 +  if (!cfi_frame_info
    1.67 +       .FindCallerRegs<RegisterValueType>(callee_registers, memory,
    1.68 +                                          &caller_registers))
    1.69 +    return false;
    1.70 +
    1.71 +  // Populate *caller_context with the values the rules placed in
    1.72 +  // caller_registers.
    1.73 +  memset(caller_context, 0xda, sizeof(*caller_context));
    1.74 +  *caller_validity = 0;
    1.75 +  for (size_t i = 0; i < map_size_; i++) {
    1.76 +    const RegisterSet &r = register_map_[i];
    1.77 +
    1.78 +    // Did the rules provide a value for this register by its name?
    1.79 +    bool found = false;
    1.80 +    RegisterValueType v = caller_registers.get(&found, r.name);
    1.81 +    if (found) {
    1.82 +      caller_context->*r.context_member = v;
    1.83 +      *caller_validity |= r.validity_flag;
    1.84 +      continue;
    1.85 +    }
    1.86 +
    1.87 +    // Did the rules provide a value for this register under its
    1.88 +    // alternate name?
    1.89 +    if (r.alternate_name) {
    1.90 +      found = false;
    1.91 +      v = caller_registers.get(&found, r.alternate_name);
    1.92 +      if (found) {
    1.93 +        caller_context->*r.context_member = v;
    1.94 +        *caller_validity |= r.validity_flag;
    1.95 +        continue;
    1.96 +      }
    1.97 +    }
    1.98 +
    1.99 +    // Is this a callee-saves register? The walker assumes that these
   1.100 +    // still hold the caller's value if the CFI doesn't mention them.
   1.101 +    //
   1.102 +    // Note that other frame walkers may fail to recover callee-saves
   1.103 +    // registers; for example, the x86 "traditional" strategy only
   1.104 +    // recovers %eip, %esp, and %ebp, even though %ebx, %esi, and %edi
   1.105 +    // are callee-saves, too. It is not correct to blindly set the
   1.106 +    // valid bit for all callee-saves registers, without first
   1.107 +    // checking its validity bit in the callee.
   1.108 +    if (r.callee_saves && (callee_validity & r.validity_flag) != 0) {
   1.109 +      caller_context->*r.context_member = callee_context.*r.context_member;
   1.110 +      *caller_validity |= r.validity_flag;
   1.111 +      continue;
   1.112 +    }
   1.113 +
   1.114 +    // Otherwise, the register's value is unknown.
   1.115 +  }
   1.116 +
   1.117 +  return true;
   1.118 +}
   1.119 +
   1.120 +} // namespace google_breakpad
   1.121 +
   1.122 +#endif // PROCESSOR_CFI_FRAME_INFO_INL_H_

mercurial