xref: /aosp_15_r20/external/google-breakpad/src/processor/static_address_map.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // Copyright 2010 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //     * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 // static_address_map.h: StaticAddressMap.
30 //
31 // StaticAddressMap is a wrapper class of StaticMap, just as AddressMap wraps
32 // std::map.  StaticAddressMap provides read-only Retrieve() operation, similar
33 // as AddressMap.  However, the difference between StaticAddressMap and
34 // AddressMap is that StaticAddressMap does not support dynamic operation
35 // Store() due to the static nature of the underlying StaticMap.
36 //
37 // See address_map.h for reference.
38 //
39 // Author: Siyang Xie ([email protected])
40 
41 #ifndef PROCESSOR_STATIC_ADDRESS_MAP_H__
42 #define PROCESSOR_STATIC_ADDRESS_MAP_H__
43 
44 #include "processor/static_map-inl.h"
45 
46 namespace google_breakpad {
47 
48 // AddressType MUST be a basic type, e.g.: integer types etc
49 // EntryType could be a complex type, so we retrieve its pointer instead.
50 template<typename AddressType, typename EntryType>
51 class StaticAddressMap {
52  public:
StaticAddressMap()53   StaticAddressMap(): map_() { }
StaticAddressMap(const char * map_data)54   explicit StaticAddressMap(const char* map_data): map_(map_data) { }
55 
56   // Locates the entry stored at the highest address less than or equal to
57   // the address argument.  If there is no such range, returns false.  The
58   // entry is returned in entry, which is a required argument.  If
59   // entry_address is not NULL, it will be set to the address that the entry
60   // was stored at.
61   bool Retrieve(const AddressType& address,
62                 const EntryType*& entry, AddressType* entry_address) const;
63 
64  private:
65   friend class ModuleComparer;
66   // Convenience types.
67   typedef StaticAddressMap* SelfPtr;
68   typedef StaticMap<AddressType, EntryType> AddressToEntryMap;
69   typedef typename AddressToEntryMap::const_iterator MapConstIterator;
70 
71   AddressToEntryMap map_;
72 };
73 
74 }  // namespace google_breakpad
75 
76 #endif  // PROCESSOR_STATIC_ADDRESS_MAP_H__
77 
78