| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #ifndef CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ | 15 #ifndef CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ |
| 16 #define CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ | 16 #define CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ |
| 17 | 17 |
| 18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 19 | 19 |
| 20 #include "util/numeric/checked_range.h" | 20 #include "util/numeric/checked_range.h" |
| 21 | 21 |
| 22 namespace crashpad { | 22 namespace crashpad { |
| 23 | 23 |
| 24 class ProcessReader; | |
| 25 | |
| 26 //! \brief Ensures that a range, composed of a base and a size, does not | 24 //! \brief Ensures that a range, composed of a base and a size, does not |
| 27 //! overflow the pointer type of the process it describes a range in. | 25 //! overflow the pointer type of the process it describes a range in. |
| 28 //! | 26 //! |
| 29 //! This class checks bases of type `mach_vm_address_t` and sizes of type | 27 //! This class checks bases of type `mach_vm_address_t` and sizes of type |
| 30 //! `mach_vm_address_t` against a process whose pointer type can be determined | 28 //! `mach_vm_address_t` against a process whose pointer type is either 32 or 64 |
| 31 //! from its ProcessReader. | 29 //! bits wide. |
| 32 //! | 30 //! |
| 33 //! Aside from varying the overall range on the basis of a process’ pointer type | 31 //! Aside from varying the overall range on the basis of a process’ pointer type |
| 34 //! width, this class functions very similarly to CheckedRange. | 32 //! width, this class functions very similarly to CheckedRange. |
| 35 class CheckedMachAddressRange { | 33 class CheckedMachAddressRange { |
| 36 public: | 34 public: |
| 37 //! \brief Initializes a default range. | 35 //! \brief Initializes a default range. |
| 38 //! | 36 //! |
| 39 //! The default range has base 0, size 0, and appears to be from a 32-bit | 37 //! The default range has base 0, size 0, and appears to be from a 32-bit |
| 40 //! process. | 38 //! process. |
| 41 CheckedMachAddressRange(); | 39 CheckedMachAddressRange(); |
| 42 | 40 |
| 43 //! \brief Initializes a range. | 41 //! \brief Initializes a range. |
| 44 //! | 42 //! |
| 45 //! See SetRange(). | 43 //! See SetRange(). |
| 46 CheckedMachAddressRange(const ProcessReader* process_reader, | 44 CheckedMachAddressRange(bool is_64_bit, |
| 47 mach_vm_address_t base, | 45 mach_vm_address_t base, |
| 48 mach_vm_size_t size); | 46 mach_vm_size_t size); |
| 49 | 47 |
| 50 //! \brief Sets a range’s fields. | 48 //! \brief Sets a range’s fields. |
| 51 //! | 49 //! |
| 52 //! \param[in] process_reader The ProcessReader that can read the process that | 50 //! \param[in] is_64_bit `true` if \a base and \a size refer to addresses in a |
| 53 //! \a base is a pointer to. | 51 //! 64-bit process; `false` if they refer to addresses in a 32-bit |
| 52 //! process. |
| 54 //! \param[in] base The range’s base address. | 53 //! \param[in] base The range’s base address. |
| 55 //! \param[in] size The range’s size. | 54 //! \param[in] size The range’s size. |
| 56 void SetRange(const ProcessReader* process_reader, | 55 void SetRange(bool is_64_bit, mach_vm_address_t base, mach_vm_size_t size); |
| 57 mach_vm_address_t base, | |
| 58 mach_vm_size_t size); | |
| 59 | 56 |
| 60 //! \brief The range’s base address. | 57 //! \brief The range’s base address. |
| 61 mach_vm_address_t Base() const; | 58 mach_vm_address_t Base() const; |
| 62 | 59 |
| 63 //! \brief The range’s size. | 60 //! \brief The range’s size. |
| 64 mach_vm_size_t Size() const; | 61 mach_vm_size_t Size() const; |
| 65 | 62 |
| 66 //! \brief The range’s end address (its base address plus its size). | 63 //! \brief The range’s end address (its base address plus its size). |
| 67 mach_vm_address_t End() const; | 64 mach_vm_address_t End() const; |
| 68 | 65 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 //! | 90 //! |
| 94 //! \return `true` if `this` address range, the containing address range, | 91 //! \return `true` if `this` address range, the containing address range, |
| 95 //! contains \a that, the contained address range. `false` otherwise. | 92 //! contains \a that, the contained address range. `false` otherwise. |
| 96 //! | 93 //! |
| 97 //! An address range contains another address range when the contained address | 94 //! An address range contains another address range when the contained address |
| 98 //! range’s base is greater than or equal to the containing address range’s | 95 //! range’s base is greater than or equal to the containing address range’s |
| 99 //! base, and the contained address range’s end is less than or equal to the | 96 //! base, and the contained address range’s end is less than or equal to the |
| 100 //! containing address range’s end. | 97 //! containing address range’s end. |
| 101 //! | 98 //! |
| 102 //! This method should only be called on two CheckedMachAddressRange objects | 99 //! This method should only be called on two CheckedMachAddressRange objects |
| 103 //! sharing the same ProcessReader. | 100 //! representing address ranges in the same process. |
| 104 //! | 101 //! |
| 105 //! This method must only be called if IsValid() would return `true` for both | 102 //! This method must only be called if IsValid() would return `true` for both |
| 106 //! CheckedMachAddressRange objects involved. | 103 //! CheckedMachAddressRange objects involved. |
| 107 bool ContainsRange(const CheckedMachAddressRange& that) const; | 104 bool ContainsRange(const CheckedMachAddressRange& that) const; |
| 108 | 105 |
| 109 private: | 106 private: |
| 110 // The field of the union that is expressed is determined by is_64_bit_. | 107 // The field of the union that is expressed is determined by is_64_bit_. |
| 111 union { | 108 union { |
| 112 CheckedRange<uint32_t> range_32_; | 109 CheckedRange<uint32_t> range_32_; |
| 113 CheckedRange<uint64_t> range_64_; | 110 CheckedRange<uint64_t> range_64_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 125 // mach_vm_size_t uniformly, but these types are too wide for the underlying | 122 // mach_vm_size_t uniformly, but these types are too wide for the underlying |
| 126 // pointer and size types in 32-bit processes. | 123 // pointer and size types in 32-bit processes. |
| 127 bool range_ok_; | 124 bool range_ok_; |
| 128 | 125 |
| 129 DISALLOW_COPY_AND_ASSIGN(CheckedMachAddressRange); | 126 DISALLOW_COPY_AND_ASSIGN(CheckedMachAddressRange); |
| 130 }; | 127 }; |
| 131 | 128 |
| 132 } // namespace crashpad | 129 } // namespace crashpad |
| 133 | 130 |
| 134 #endif // CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ | 131 #endif // CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_ |
| OLD | NEW |