1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/range_map.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 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 +// range_map.h: Range maps. 1.34 +// 1.35 +// A range map associates a range of addresses with a specific object. This 1.36 +// is useful when certain objects of variable size are located within an 1.37 +// address space. The range map makes it simple to determine which object is 1.38 +// associated with a specific address, which may be any address within the 1.39 +// range associated with an object. 1.40 +// 1.41 +// Author: Mark Mentovai 1.42 + 1.43 +#ifndef PROCESSOR_RANGE_MAP_H__ 1.44 +#define PROCESSOR_RANGE_MAP_H__ 1.45 + 1.46 + 1.47 +#include <map> 1.48 + 1.49 + 1.50 +namespace google_breakpad { 1.51 + 1.52 +// Forward declarations (for later friend declarations of specialized template). 1.53 +template<class, class> class RangeMapSerializer; 1.54 + 1.55 +template<typename AddressType, typename EntryType> 1.56 +class RangeMap { 1.57 + public: 1.58 + RangeMap() : map_() {} 1.59 + 1.60 + // Inserts a range into the map. Returns false for a parameter error, 1.61 + // or if the location of the range would conflict with a range already 1.62 + // stored in the map. 1.63 + bool StoreRange(const AddressType &base, 1.64 + const AddressType &size, 1.65 + const EntryType &entry); 1.66 + 1.67 + // Locates the range encompassing the supplied address. If there is 1.68 + // no such range, returns false. entry_base and entry_size, if non-NULL, 1.69 + // are set to the base and size of the entry's range. 1.70 + bool RetrieveRange(const AddressType &address, EntryType *entry, 1.71 + AddressType *entry_base, AddressType *entry_size) const; 1.72 + 1.73 + // Locates the range encompassing the supplied address, if one exists. 1.74 + // If no range encompasses the supplied address, locates the nearest range 1.75 + // to the supplied address that is lower than the address. Returns false 1.76 + // if no range meets these criteria. entry_base and entry_size, if 1.77 + // non-NULL, are set to the base and size of the entry's range. 1.78 + bool RetrieveNearestRange(const AddressType &address, EntryType *entry, 1.79 + AddressType *entry_base, AddressType *entry_size) 1.80 + const; 1.81 + 1.82 + // Treating all ranges as a list ordered by the address spaces that they 1.83 + // occupy, locates the range at the index specified by index. Returns 1.84 + // false if index is larger than the number of ranges stored. entry_base 1.85 + // and entry_size, if non-NULL, are set to the base and size of the entry's 1.86 + // range. 1.87 + // 1.88 + // RetrieveRangeAtIndex is not optimized for speedy operation. 1.89 + bool RetrieveRangeAtIndex(int index, EntryType *entry, 1.90 + AddressType *entry_base, AddressType *entry_size) 1.91 + const; 1.92 + 1.93 + // Returns the number of ranges stored in the RangeMap. 1.94 + int GetCount() const; 1.95 + 1.96 + // Empties the range map, restoring it to the state it was when it was 1.97 + // initially created. 1.98 + void Clear(); 1.99 + 1.100 + private: 1.101 + // Friend declarations. 1.102 + friend class ModuleComparer; 1.103 + friend class RangeMapSerializer<AddressType, EntryType>; 1.104 + 1.105 + class Range { 1.106 + public: 1.107 + Range(const AddressType &base, const EntryType &entry) 1.108 + : base_(base), entry_(entry) {} 1.109 + 1.110 + AddressType base() const { return base_; } 1.111 + EntryType entry() const { return entry_; } 1.112 + 1.113 + private: 1.114 + // The base address of the range. The high address does not need to 1.115 + // be stored, because RangeMap uses it as the key to the map. 1.116 + const AddressType base_; 1.117 + 1.118 + // The entry corresponding to a range. 1.119 + const EntryType entry_; 1.120 + }; 1.121 + 1.122 + // Convenience types. 1.123 + typedef std::map<AddressType, Range> AddressToRangeMap; 1.124 + typedef typename AddressToRangeMap::const_iterator MapConstIterator; 1.125 + typedef typename AddressToRangeMap::value_type MapValue; 1.126 + 1.127 + // Maps the high address of each range to a EntryType. 1.128 + AddressToRangeMap map_; 1.129 +}; 1.130 + 1.131 + 1.132 +} // namespace google_breakpad 1.133 + 1.134 + 1.135 +#endif // PROCESSOR_RANGE_MAP_H__