Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: util/mac/checked_mach_address_range.cc

Issue 513453002: Add CheckedMachAddressRange and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « util/mac/checked_mach_address_range.h ('k') | util/mac/checked_mach_address_range_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « util/mac/checked_mach_address_range.h ('k') | util/mac/checked_mach_address_range_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698