toolkit/crashreporter/google-breakpad/src/processor/contained_range_map.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/contained_range_map.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +// Copyright (c) 2006, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// contained_range_map.h: Hierarchically-organized range maps.
    1.34 +//
    1.35 +// A contained range map is similar to a standard range map, except it allows
    1.36 +// objects to be organized hierarchically.  A contained range map allows
    1.37 +// objects to contain other objects.  It is not sensitive to the order that
    1.38 +// objects are added to the map: larger, more general, containing objects
    1.39 +// may be added either before or after smaller, more specific, contained
    1.40 +// ones.
    1.41 +//
    1.42 +// Contained range maps guarantee that each object may only contain smaller
    1.43 +// objects than itself, and that a parent object may only contain child
    1.44 +// objects located entirely within the parent's address space.  Attempts
    1.45 +// to introduce objects (via StoreRange) that violate these rules will fail.
    1.46 +// Retrieval (via RetrieveRange) always returns the most specific (smallest)
    1.47 +// object that contains the address being queried.  Note that while it is
    1.48 +// not possible to insert two objects into a map that have exactly the same
    1.49 +// geometry (base address and size), it is possible to completely mask a
    1.50 +// larger object by inserting smaller objects that entirely fill the larger
    1.51 +// object's address space.
    1.52 +//
    1.53 +// Internally, contained range maps are implemented as a tree.  Each tree
    1.54 +// node except for the root node describes an object in the map.  Each node
    1.55 +// maintains its list of children in a map similar to a standard range map,
    1.56 +// keyed by the highest address that each child occupies.  Each node's
    1.57 +// children occupy address ranges entirely within the node.  The root node
    1.58 +// is the only node directly accessible to the user, and represents the
    1.59 +// entire address space.
    1.60 +//
    1.61 +// Author: Mark Mentovai
    1.62 +
    1.63 +#ifndef PROCESSOR_CONTAINED_RANGE_MAP_H__
    1.64 +#define PROCESSOR_CONTAINED_RANGE_MAP_H__
    1.65 +
    1.66 +
    1.67 +#include <map>
    1.68 +
    1.69 +
    1.70 +namespace google_breakpad {
    1.71 +
    1.72 +// Forward declarations (for later friend declarations of specialized template).
    1.73 +template<class, class> class ContainedRangeMapSerializer;
    1.74 +
    1.75 +template<typename AddressType, typename EntryType>
    1.76 +class ContainedRangeMap {
    1.77 + public:
    1.78 +  // The default constructor creates a ContainedRangeMap with no geometry
    1.79 +  // and no entry, and as such is only suitable for the root node of a
    1.80 +  // ContainedRangeMap tree.
    1.81 +  ContainedRangeMap() : base_(), entry_(), map_(NULL) {}
    1.82 +
    1.83 +  ~ContainedRangeMap();
    1.84 +
    1.85 +  // Inserts a range into the map.  If the new range is encompassed by
    1.86 +  // an existing child range, the new range is passed into the child range's
    1.87 +  // StoreRange method.  If the new range encompasses any existing child
    1.88 +  // ranges, those child ranges are moved to the new range, becoming
    1.89 +  // grandchildren of this ContainedRangeMap.  Returns false for a
    1.90 +  // parameter error, or if the ContainedRangeMap hierarchy guarantees
    1.91 +  // would be violated.
    1.92 +  bool StoreRange(const AddressType &base,
    1.93 +                  const AddressType &size,
    1.94 +                  const EntryType &entry);
    1.95 +
    1.96 +  // Retrieves the most specific (smallest) descendant range encompassing
    1.97 +  // the specified address.  This method will only return entries held by
    1.98 +  // child ranges, and not the entry contained by |this|.  This is necessary
    1.99 +  // to support a sparsely-populated root range.  If no descendant range
   1.100 +  // encompasses the address, returns false.
   1.101 +  bool RetrieveRange(const AddressType &address, EntryType *entry) const;
   1.102 +
   1.103 +  // Removes all children.  Note that Clear only removes descendants,
   1.104 +  // leaving the node on which it is called intact.  Because the only
   1.105 +  // meaningful things contained by a root node are descendants, this
   1.106 +  // is sufficient to restore an entire ContainedRangeMap to its initial
   1.107 +  // empty state when called on the root node.
   1.108 +  void Clear();
   1.109 +
   1.110 + private:
   1.111 +  friend class ContainedRangeMapSerializer<AddressType, EntryType>;
   1.112 +  friend class ModuleComparer;
   1.113 +
   1.114 +  // AddressToRangeMap stores pointers.  This makes reparenting simpler in
   1.115 +  // StoreRange, because it doesn't need to copy entire objects.
   1.116 +  typedef std::map<AddressType, ContainedRangeMap *> AddressToRangeMap;
   1.117 +  typedef typename AddressToRangeMap::const_iterator MapConstIterator;
   1.118 +  typedef typename AddressToRangeMap::iterator MapIterator;
   1.119 +  typedef typename AddressToRangeMap::value_type MapValue;
   1.120 +
   1.121 +  // Creates a new ContainedRangeMap with the specified base address, entry,
   1.122 +  // and initial child map, which may be NULL.  This is only used internally
   1.123 +  // by ContainedRangeMap when it creates a new child.
   1.124 +  ContainedRangeMap(const AddressType &base, const EntryType &entry,
   1.125 +                    AddressToRangeMap *map)
   1.126 +      : base_(base), entry_(entry), map_(map) {}
   1.127 +
   1.128 +  // The base address of this range.  The high address does not need to
   1.129 +  // be stored, because it is used as the key to an object in its parent's
   1.130 +  // map, and all ContainedRangeMaps except for the root range are contained
   1.131 +  // within maps.  The root range does not actually contain an entry, so its
   1.132 +  // base_ field is meaningless, and the fact that it has no parent and thus
   1.133 +  // no key is unimportant.  For this reason, the base_ field should only be
   1.134 +  // is accessed on child ContainedRangeMap objects, and never on |this|.
   1.135 +  const AddressType base_;
   1.136 +
   1.137 +  // The entry corresponding to this range.  The root range does not
   1.138 +  // actually contain an entry, so its entry_ field is meaningless.  For
   1.139 +  // this reason, the entry_ field should only be accessed on child
   1.140 +  // ContainedRangeMap objects, and never on |this|.
   1.141 +  const EntryType entry_;
   1.142 +
   1.143 +  // The map containing child ranges, keyed by each child range's high
   1.144 +  // address.  This is a pointer to avoid allocating map structures for
   1.145 +  // leaf nodes, where they are not needed.
   1.146 +  AddressToRangeMap *map_;
   1.147 +};
   1.148 +
   1.149 +
   1.150 +}  // namespace google_breakpad
   1.151 +
   1.152 +
   1.153 +#endif  // PROCESSOR_CONTAINED_RANGE_MAP_H__

mercurial