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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/mac/mach_o_image_reader.h" | 15 #include "snapshot/mac/mach_o_image_reader.h" |
16 | 16 |
17 #include <mach-o/loader.h> | 17 #include <mach-o/loader.h> |
18 #include <mach-o/nlist.h> | 18 #include <mach-o/nlist.h> |
19 #include <string.h> | 19 #include <string.h> |
20 | 20 |
21 #include <limits> | 21 #include <limits> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "snapshot/mac/mach_o_image_segment_reader.h" |
| 27 #include "snapshot/mac/mach_o_image_symbol_table_reader.h" |
| 28 #include "snapshot/mac/process_reader.h" |
26 #include "util/mac/checked_mach_address_range.h" | 29 #include "util/mac/checked_mach_address_range.h" |
27 #include "util/mac/mach_o_image_segment_reader.h" | |
28 #include "util/mac/mach_o_image_symbol_table_reader.h" | |
29 #include "util/mac/process_reader.h" | |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const uint32_t kInvalidSegmentIndex = std::numeric_limits<uint32_t>::max(); | 33 const uint32_t kInvalidSegmentIndex = std::numeric_limits<uint32_t>::max(); |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 namespace crashpad { | 37 namespace crashpad { |
38 | 38 |
39 MachOImageReader::MachOImageReader() | 39 MachOImageReader::MachOImageReader() |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 for (MachOImageSegmentReader* segment : segments_) { | 260 for (MachOImageSegmentReader* segment : segments_) { |
261 segment->SetSlide(slide_); | 261 segment->SetSlide(slide_); |
262 | 262 |
263 // This was already checked for the unslid values while the segments were | 263 // This was already checked for the unslid values while the segments were |
264 // read, but now it’s possible to check the slid values too. The individual | 264 // read, but now it’s possible to check the slid values too. The individual |
265 // sections don’t need to be checked because they were verified to be | 265 // sections don’t need to be checked because they were verified to be |
266 // contained within their respective segments when the segments were read. | 266 // contained within their respective segments when the segments were read. |
267 mach_vm_address_t slid_segment_address = segment->Address(); | 267 mach_vm_address_t slid_segment_address = segment->Address(); |
268 mach_vm_size_t slid_segment_size = segment->Size(); | 268 mach_vm_size_t slid_segment_size = segment->Size(); |
269 CheckedMachAddressRange slid_segment_range( | 269 CheckedMachAddressRange slid_segment_range( |
270 process_reader_, slid_segment_address, slid_segment_size); | 270 process_reader_->Is64Bit(), slid_segment_address, slid_segment_size); |
271 if (!slid_segment_range.IsValid()) { | 271 if (!slid_segment_range.IsValid()) { |
272 LOG(WARNING) << base::StringPrintf( | 272 LOG(WARNING) << base::StringPrintf( |
273 "invalid slid segment range 0x%llx + 0x%llx, " | 273 "invalid slid segment range 0x%llx + 0x%llx, " |
274 "segment ", | 274 "segment ", |
275 slid_segment_address, | 275 slid_segment_address, |
276 slid_segment_size) << segment->Name() << module_info_; | 276 slid_segment_size) << segment->Name() << module_info_; |
277 return false; | 277 return false; |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // There, ld takes symbols that refer to anything in the mach_header[_64] and | 408 // There, ld takes symbols that refer to anything in the mach_header[_64] and |
409 // marks them as being in section 1. Here, section 1 is treated in this same | 409 // marks them as being in section 1. Here, section 1 is treated in this same |
410 // special way as long as it’s in the __TEXT segment that begins at the start | 410 // special way as long as it’s in the __TEXT segment that begins at the start |
411 // of the image, which is normally the case, and as long as the symbol’s value | 411 // of the image, which is normally the case, and as long as the symbol’s value |
412 // is the base of the image. | 412 // is the base of the image. |
413 // | 413 // |
414 // This only happens for PIE executables, because __mh_execute_header needs | 414 // This only happens for PIE executables, because __mh_execute_header needs |
415 // to slide. In non-PIE executables, __mh_execute_header is an absolute | 415 // to slide. In non-PIE executables, __mh_execute_header is an absolute |
416 // symbol. | 416 // symbol. |
417 CheckedMachAddressRange section_range( | 417 CheckedMachAddressRange section_range( |
418 process_reader_, section_address, section->size); | 418 process_reader_->Is64Bit(), section_address, section->size); |
419 if (!section_range.ContainsValue(slid_value) && | 419 if (!section_range.ContainsValue(slid_value) && |
420 !(symbol_info->section == 1 && segment->Name() == SEG_TEXT && | 420 !(symbol_info->section == 1 && segment->Name() == SEG_TEXT && |
421 slid_value == Address())) { | 421 slid_value == Address())) { |
422 std::string section_name_full = | 422 std::string section_name_full = |
423 MachOImageSegmentReader::SegmentAndSectionNameString(section->segname, | 423 MachOImageSegmentReader::SegmentAndSectionNameString(section->segname, |
424 section->sectname); | 424 section->sectname); |
425 LOG(WARNING) << base::StringPrintf( | 425 LOG(WARNING) << base::StringPrintf( |
426 "symbol %s (0x%llx) outside of section %s (0x%llx + " | 426 "symbol %s (0x%llx) outside of section %s (0x%llx + " |
427 "0x%llx)", | 427 "0x%llx)", |
428 name.c_str(), | 428 name.c_str(), |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 linkedit_segment, | 662 linkedit_segment, |
663 module_info_)) { | 663 module_info_)) { |
664 symbol_table_.reset(); | 664 symbol_table_.reset(); |
665 return; | 665 return; |
666 } | 666 } |
667 | 667 |
668 symbol_table_initialized_.set_valid(); | 668 symbol_table_initialized_.set_valid(); |
669 } | 669 } |
670 | 670 |
671 } // namespace crashpad | 671 } // namespace crashpad |
OLD | NEW |