/thirdparty/breakpad/processor/static_contained_range_map-inl.h

http://github.com/tomahawk-player/tomahawk · C Header · 92 lines · 33 code · 16 blank · 43 comment · 6 complexity · b32980ab49ec5a17d7e030a5ae65a07e MD5 · raw file

  1. // Copyright (c) 2010, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // static_contained_range_map-inl.h: Hierarchically-organized range map,
  30. // i.e., StaticContainedRangeMap implementation.
  31. //
  32. // See static_contained_range_map.h for documentation.
  33. //
  34. // Author: Siyang Xie (lambxsy@google.com)
  35. #ifndef PROCESSOR_STATIC_CONTAINED_RANGE_MAP_INL_H__
  36. #define PROCESSOR_STATIC_CONTAINED_RANGE_MAP_INL_H__
  37. #include "processor/static_contained_range_map.h"
  38. #include "processor/logging.h"
  39. namespace google_breakpad {
  40. template<typename AddressType, typename EntryType>
  41. StaticContainedRangeMap<AddressType, EntryType>::StaticContainedRangeMap(
  42. const char *base)
  43. : base_(*(reinterpret_cast<const AddressType*>(base))),
  44. entry_size_(*(reinterpret_cast<const u_int32_t*>(base + sizeof(base_)))),
  45. entry_ptr_(reinterpret_cast<const EntryType *>(
  46. base + sizeof(base_) + sizeof(entry_size_))),
  47. map_(base + sizeof(base_) + sizeof(entry_size_) + entry_size_) {
  48. if (entry_size_ == 0)
  49. entry_ptr_ = NULL;
  50. }
  51. template<typename AddressType, typename EntryType>
  52. bool StaticContainedRangeMap<AddressType, EntryType>::RetrieveRange(
  53. const AddressType &address, const EntryType *&entry) const {
  54. // Get an iterator to the child range whose high address is equal to or
  55. // greater than the supplied address. If the supplied address is higher
  56. // than all of the high addresses in the range, then this range does not
  57. // contain a child at address, so return false. If the supplied address
  58. // is lower than the base address of the child range, then it is not within
  59. // the child range, so return false.
  60. MapConstIterator iterator = map_.lower_bound(address);
  61. if (iterator == map_.end())
  62. return false;
  63. const char *memory_child =
  64. reinterpret_cast<const char*>(iterator.GetValuePtr());
  65. StaticContainedRangeMap child_map(memory_child);
  66. if (address < child_map.base_)
  67. return false;
  68. // The child in iterator->second contains the specified address. Find out
  69. // if it has a more-specific descendant that also contains it. If it does,
  70. // it will set |entry| appropriately. If not, set |entry| to the child.
  71. if (!child_map.RetrieveRange(address, entry))
  72. entry = child_map.entry_ptr_;
  73. return true;
  74. }
  75. } // namespace google_breakpad
  76. #endif // PROCESSOR_STATIC_CONTAINED_RANGE_MAP_INL_H__