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 #include "util/mac/process_reader.h" |
| 20 |
| 21 namespace crashpad { |
| 22 |
| 23 CheckedMachAddressRange::CheckedMachAddressRange() |
| 24 : range_32_(0, 0), is_64_bit_(false), range_ok_(true) { |
| 25 } |
| 26 |
| 27 CheckedMachAddressRange::CheckedMachAddressRange( |
| 28 const ProcessReader* process_reader, |
| 29 mach_vm_address_t base, |
| 30 mach_vm_size_t size) { |
| 31 SetRange(process_reader, base, size); |
| 32 } |
| 33 |
| 34 void CheckedMachAddressRange::SetRange(const ProcessReader* process_reader, |
| 35 mach_vm_address_t base, |
| 36 mach_vm_size_t size) { |
| 37 is_64_bit_ = process_reader->Is64Bit(); |
| 38 if (is_64_bit_) { |
| 39 range_64_.SetRange(base, size); |
| 40 range_ok_ = true; |
| 41 } else { |
| 42 range_32_.SetRange(base, size); |
| 43 range_ok_ = base::IsValueInRangeForNumericType<uint32_t>(base) && |
| 44 base::IsValueInRangeForNumericType<uint32_t>(size); |
| 45 } |
| 46 } |
| 47 |
| 48 mach_vm_address_t CheckedMachAddressRange::Base() const { |
| 49 return is_64_bit_ ? range_64_.base() : range_32_.base(); |
| 50 } |
| 51 |
| 52 mach_vm_size_t CheckedMachAddressRange::Size() const { |
| 53 return is_64_bit_ ? range_64_.size() : range_32_.size(); |
| 54 } |
| 55 |
| 56 mach_vm_address_t CheckedMachAddressRange::End() const { |
| 57 return is_64_bit_ ? range_64_.end() : range_32_.end(); |
| 58 } |
| 59 |
| 60 bool CheckedMachAddressRange::IsValid() const { |
| 61 return range_ok_ && (is_64_bit_ ? range_64_.IsValid() : range_32_.IsValid()); |
| 62 } |
| 63 |
| 64 bool CheckedMachAddressRange::ContainsValue(mach_vm_address_t value) const { |
| 65 DCHECK(range_ok_); |
| 66 |
| 67 if (is_64_bit_) { |
| 68 return range_64_.ContainsValue(value); |
| 69 } |
| 70 |
| 71 if (!base::IsValueInRangeForNumericType<uint32_t>(value)) { |
| 72 return false; |
| 73 } |
| 74 |
| 75 return range_32_.ContainsValue(value); |
| 76 } |
| 77 |
| 78 bool CheckedMachAddressRange::ContainsRange( |
| 79 const CheckedMachAddressRange& that) const { |
| 80 DCHECK_EQ(is_64_bit_, that.is_64_bit_); |
| 81 DCHECK(range_ok_); |
| 82 DCHECK(that.range_ok_); |
| 83 |
| 84 return is_64_bit_ ? range_64_.ContainsRange(that.range_64_) |
| 85 : range_32_.ContainsRange(that.range_32_); |
| 86 } |
| 87 |
| 88 } // namespace crashpad |
OLD | NEW |