| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "util/mac/checked_mach_address_range.h" | |
| 16 | |
| 17 #include "base/logging.h" | |
| 18 #include "base/numerics/safe_conversions.h" | |
| 19 | |
| 20 namespace crashpad { | |
| 21 | |
| 22 CheckedMachAddressRange::CheckedMachAddressRange() | |
| 23 : range_32_(0, 0), is_64_bit_(false), range_ok_(true) { | |
| 24 } | |
| 25 | |
| 26 CheckedMachAddressRange::CheckedMachAddressRange( | |
| 27 bool is_64_bit, | |
| 28 mach_vm_address_t base, | |
| 29 mach_vm_size_t size) { | |
| 30 SetRange(is_64_bit, base, size); | |
| 31 } | |
| 32 | |
| 33 void CheckedMachAddressRange::SetRange(bool is_64_bit, | |
| 34 mach_vm_address_t base, | |
| 35 mach_vm_size_t size) { | |
| 36 is_64_bit_ = is_64_bit; | |
| 37 if (is_64_bit_) { | |
| 38 range_64_.SetRange(base, size); | |
| 39 range_ok_ = true; | |
| 40 } else { | |
| 41 range_32_.SetRange(base, size); | |
| 42 range_ok_ = base::IsValueInRangeForNumericType<uint32_t>(base) && | |
| 43 base::IsValueInRangeForNumericType<uint32_t>(size); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 mach_vm_address_t CheckedMachAddressRange::Base() const { | |
| 48 return is_64_bit_ ? range_64_.base() : range_32_.base(); | |
| 49 } | |
| 50 | |
| 51 mach_vm_size_t CheckedMachAddressRange::Size() const { | |
| 52 return is_64_bit_ ? range_64_.size() : range_32_.size(); | |
| 53 } | |
| 54 | |
| 55 mach_vm_address_t CheckedMachAddressRange::End() const { | |
| 56 return is_64_bit_ ? range_64_.end() : range_32_.end(); | |
| 57 } | |
| 58 | |
| 59 bool CheckedMachAddressRange::IsValid() const { | |
| 60 return range_ok_ && (is_64_bit_ ? range_64_.IsValid() : range_32_.IsValid()); | |
| 61 } | |
| 62 | |
| 63 bool CheckedMachAddressRange::ContainsValue(mach_vm_address_t value) const { | |
| 64 DCHECK(range_ok_); | |
| 65 | |
| 66 if (is_64_bit_) { | |
| 67 return range_64_.ContainsValue(value); | |
| 68 } | |
| 69 | |
| 70 if (!base::IsValueInRangeForNumericType<uint32_t>(value)) { | |
| 71 return false; | |
| 72 } | |
| 73 | |
| 74 return range_32_.ContainsValue(value); | |
| 75 } | |
| 76 | |
| 77 bool CheckedMachAddressRange::ContainsRange( | |
| 78 const CheckedMachAddressRange& that) const { | |
| 79 DCHECK_EQ(is_64_bit_, that.is_64_bit_); | |
| 80 DCHECK(range_ok_); | |
| 81 DCHECK(that.range_ok_); | |
| 82 | |
| 83 return is_64_bit_ ? range_64_.ContainsRange(that.range_64_) | |
| 84 : range_32_.ContainsRange(that.range_32_); | |
| 85 } | |
| 86 | |
| 87 } // namespace crashpad | |
| OLD | NEW |