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, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 DCHECK_GE(user_address, vm_address); | 61 DCHECK_GE(user_address, vm_address); |
62 DCHECK_LE(user_address, vm_end); | 62 DCHECK_LE(user_address, vm_end); |
63 DCHECK_GE(user_end, vm_address); | 63 DCHECK_GE(user_end, vm_address); |
64 DCHECK_LE(user_end, vm_end); | 64 DCHECK_LE(user_end, vm_end); |
65 } | 65 } |
66 | 66 |
67 TaskMemory::TaskMemory(task_t task) : task_(task) { | 67 TaskMemory::TaskMemory(task_t task) : task_(task) { |
68 } | 68 } |
69 | 69 |
70 bool TaskMemory::Read(mach_vm_address_t address, size_t size, void* buffer) { | 70 bool TaskMemory::Read(mach_vm_address_t address, size_t size, void* buffer) { |
71 scoped_ptr<MappedMemory> memory = ReadMapped(address, size); | 71 std::unique_ptr<MappedMemory> memory = ReadMapped(address, size); |
72 if (!memory) { | 72 if (!memory) { |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 memcpy(buffer, memory->data(), size); | 76 memcpy(buffer, memory->data(), size); |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 scoped_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped( | 80 std::unique_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped( |
81 mach_vm_address_t address, size_t size) { | 81 mach_vm_address_t address, |
| 82 size_t size) { |
82 if (size == 0) { | 83 if (size == 0) { |
83 return scoped_ptr<MappedMemory>(new MappedMemory(0, 0, 0, 0)); | 84 return std::unique_ptr<MappedMemory>(new MappedMemory(0, 0, 0, 0)); |
84 } | 85 } |
85 | 86 |
86 mach_vm_address_t region_address = mach_vm_trunc_page(address); | 87 mach_vm_address_t region_address = mach_vm_trunc_page(address); |
87 mach_vm_size_t region_size = | 88 mach_vm_size_t region_size = |
88 mach_vm_round_page(address - region_address + size); | 89 mach_vm_round_page(address - region_address + size); |
89 | 90 |
90 vm_offset_t region; | 91 vm_offset_t region; |
91 mach_msg_type_number_t region_count; | 92 mach_msg_type_number_t region_count; |
92 kern_return_t kr = | 93 kern_return_t kr = |
93 mach_vm_read(task_, region_address, region_size, ®ion, ®ion_count); | 94 mach_vm_read(task_, region_address, region_size, ®ion, ®ion_count); |
94 if (kr != KERN_SUCCESS) { | 95 if (kr != KERN_SUCCESS) { |
95 MACH_LOG(WARNING, kr) << base::StringPrintf( | 96 MACH_LOG(WARNING, kr) << base::StringPrintf( |
96 "mach_vm_read(0x%llx, 0x%llx)", region_address, region_size); | 97 "mach_vm_read(0x%llx, 0x%llx)", region_address, region_size); |
97 return scoped_ptr<MappedMemory>(); | 98 return std::unique_ptr<MappedMemory>(); |
98 } | 99 } |
99 | 100 |
100 DCHECK_EQ(region_count, region_size); | 101 DCHECK_EQ(region_count, region_size); |
101 return scoped_ptr<MappedMemory>( | 102 return std::unique_ptr<MappedMemory>( |
102 new MappedMemory(region, region_size, address - region_address, size)); | 103 new MappedMemory(region, region_size, address - region_address, size)); |
103 } | 104 } |
104 | 105 |
105 bool TaskMemory::ReadCString(mach_vm_address_t address, std::string* string) { | 106 bool TaskMemory::ReadCString(mach_vm_address_t address, std::string* string) { |
106 return ReadCStringInternal(address, false, 0, string); | 107 return ReadCStringInternal(address, false, 0, string); |
107 } | 108 } |
108 | 109 |
109 bool TaskMemory::ReadCStringSizeLimited(mach_vm_address_t address, | 110 bool TaskMemory::ReadCStringSizeLimited(mach_vm_address_t address, |
110 mach_vm_size_t size, | 111 mach_vm_size_t size, |
111 std::string* string) { | 112 std::string* string) { |
(...skipping 11 matching lines...) Expand all Loading... |
123 } | 124 } |
124 } else { | 125 } else { |
125 size = PAGE_SIZE; | 126 size = PAGE_SIZE; |
126 } | 127 } |
127 | 128 |
128 std::string local_string; | 129 std::string local_string; |
129 mach_vm_address_t read_address = address; | 130 mach_vm_address_t read_address = address; |
130 do { | 131 do { |
131 mach_vm_size_t read_length = | 132 mach_vm_size_t read_length = |
132 std::min(size, PAGE_SIZE - (read_address % PAGE_SIZE)); | 133 std::min(size, PAGE_SIZE - (read_address % PAGE_SIZE)); |
133 scoped_ptr<MappedMemory> read_region = | 134 std::unique_ptr<MappedMemory> read_region = |
134 ReadMapped(read_address, read_length); | 135 ReadMapped(read_address, read_length); |
135 if (!read_region) { | 136 if (!read_region) { |
136 return false; | 137 return false; |
137 } | 138 } |
138 | 139 |
139 const char* read_region_data = | 140 const char* read_region_data = |
140 reinterpret_cast<const char*>(read_region->data()); | 141 reinterpret_cast<const char*>(read_region->data()); |
141 size_t read_region_data_length = strnlen(read_region_data, read_length); | 142 size_t read_region_data_length = strnlen(read_region_data, read_length); |
142 local_string.append(read_region_data, read_region_data_length); | 143 local_string.append(read_region_data, read_region_data_length); |
143 if (read_region_data_length < read_length) { | 144 if (read_region_data_length < read_length) { |
144 string->swap(local_string); | 145 string->swap(local_string); |
145 return true; | 146 return true; |
146 } | 147 } |
147 | 148 |
148 if (has_size) { | 149 if (has_size) { |
149 size -= read_length; | 150 size -= read_length; |
150 } | 151 } |
151 read_address = mach_vm_trunc_page(read_address + read_length); | 152 read_address = mach_vm_trunc_page(read_address + read_length); |
152 } while ((!has_size || size > 0) && read_address > address); | 153 } while ((!has_size || size > 0) && read_address > address); |
153 | 154 |
154 LOG(WARNING) << base::StringPrintf("unterminated string at 0x%llx", address); | 155 LOG(WARNING) << base::StringPrintf("unterminated string at 0x%llx", address); |
155 return false; | 156 return false; |
156 } | 157 } |
157 | 158 |
158 } // namespace crashpad | 159 } // namespace crashpad |
OLD | NEW |