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

Side by Side Diff: util/numeric/checked_address_range.cc

Issue 1052813002: win: make CrashpadInfo retrievable (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 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/numeric/checked_address_range.h"
16
17 #if defined(OS_MACOSX)
18 #include <mach/mach.h>
19 #elif defined(OS_WIN)
20 #include "util/win/address_types.h"
21 #endif // OS_MACOSX
22
23 namespace crashpad {
24
25 template <class ValueType, class SizeType>
26 CheckedAddressRangeGeneric<ValueType, SizeType>::CheckedAddressRangeGeneric()
27 : range_32_(0, 0),
28 #if defined(COMPILER_MSVC)
29 range_64_(0, 0),
30 #endif // COMPILER_MSVC
31 is_64_bit_(false),
32 range_ok_(true) {
33 }
34
35 template <class ValueType, class SizeType>
36 CheckedAddressRangeGeneric<ValueType, SizeType>::CheckedAddressRangeGeneric(
37 bool is_64_bit,
38 ValueType base,
39 SizeType size)
40 #if defined(COMPILER_MSVC)
41 : range_32_(0, 0),
42 range_64_(0, 0)
43 #endif // COMPILER_MSVC
44 {
45 SetRange(is_64_bit, base, size);
46 }
47
48 template <class ValueType, class SizeType>
49 ValueType CheckedAddressRangeGeneric<ValueType, SizeType>::Base() const {
50 return is_64_bit_ ? range_64_.base() : range_32_.base();
51 }
52
53 template <class ValueType, class SizeType>
54 SizeType CheckedAddressRangeGeneric<ValueType, SizeType>::Size() const {
55 return is_64_bit_ ? range_64_.size() : range_32_.size();
56 }
57
58 template <class ValueType, class SizeType>
59 ValueType CheckedAddressRangeGeneric<ValueType, SizeType>::End() const {
60 return is_64_bit_ ? range_64_.end() : range_32_.end();
61 }
62
63 template <class ValueType, class SizeType>
64 bool CheckedAddressRangeGeneric<ValueType, SizeType>::IsValid() const {
65 return range_ok_ && (is_64_bit_ ? range_64_.IsValid() : range_32_.IsValid());
66 }
67
68 template <class ValueType, class SizeType>
69 void CheckedAddressRangeGeneric<ValueType, SizeType>::SetRange(bool is_64_bit,
70 ValueType base,
71 SizeType size) {
72 is_64_bit_ = is_64_bit;
73 if (is_64_bit_) {
74 range_64_.SetRange(base, size);
75 range_ok_ = true;
76 } else {
77 range_32_.SetRange(static_cast<uint32_t>(base),
78 static_cast<uint32_t>(size));
79 range_ok_ = base::IsValueInRangeForNumericType<uint32_t>(base) &&
80 base::IsValueInRangeForNumericType<uint32_t>(size);
81 }
82 }
83
84 template <class ValueType, class SizeType>
85 bool CheckedAddressRangeGeneric<ValueType, SizeType>::ContainsValue(
86 ValueType value) const {
87 DCHECK(range_ok_);
88
89 if (is_64_bit_) {
90 return range_64_.ContainsValue(value);
91 }
92
93 if (!base::IsValueInRangeForNumericType<uint32_t>(value)) {
94 return false;
95 }
96
97 return range_32_.ContainsValue(static_cast<uint32_t>(value));
98 }
99
100 template <class ValueType, class SizeType>
101 bool CheckedAddressRangeGeneric<ValueType, SizeType>::ContainsRange(
102 const CheckedAddressRangeGeneric& that) const {
103 DCHECK_EQ(is_64_bit_, that.is_64_bit_);
104 DCHECK(range_ok_);
105 DCHECK(that.range_ok_);
106
107 return is_64_bit_ ? range_64_.ContainsRange(that.range_64_)
108 : range_32_.ContainsRange(that.range_32_);
109 }
110
111 // Explicit instantiations for the cases we use.
112 #if defined(OS_MACOSX)
113 template class CheckedAddressRangeGeneric<mach_vm_address_t, mach_vm_size_t>;
114 #elif defined(OS_WIN)
115 template class CheckedAddressRangeGeneric<win_vm_address_t, win_vm_size_t>;
116 #endif // OS_MACOSX
117
118 template class CheckedAddressRangeGeneric<uintptr_t, size_t>;
119
120 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698