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 "snapshot/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 "client/crashpad_info.h" |
26 #include "snapshot/mac/mach_o_image_segment_reader.h" | 27 #include "snapshot/mac/mach_o_image_segment_reader.h" |
27 #include "snapshot/mac/mach_o_image_symbol_table_reader.h" | 28 #include "snapshot/mac/mach_o_image_symbol_table_reader.h" |
28 #include "snapshot/mac/process_reader.h" | 29 #include "snapshot/mac/process_reader.h" |
29 #include "util/mac/checked_mach_address_range.h" | 30 #include "util/mac/checked_mach_address_range.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const uint32_t kInvalidSegmentIndex = std::numeric_limits<uint32_t>::max(); | 34 const uint32_t kInvalidSegmentIndex = std::numeric_limits<uint32_t>::max(); |
34 | 35 |
35 } // namespace | 36 } // namespace |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 448 |
448 // In case this was a weird dylib without an LC_ID_DYLIB command. | 449 // In case this was a weird dylib without an LC_ID_DYLIB command. |
449 return 0; | 450 return 0; |
450 } | 451 } |
451 | 452 |
452 void MachOImageReader::UUID(crashpad::UUID* uuid) const { | 453 void MachOImageReader::UUID(crashpad::UUID* uuid) const { |
453 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 454 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
454 memcpy(uuid, &uuid_, sizeof(uuid_)); | 455 memcpy(uuid, &uuid_, sizeof(uuid_)); |
455 } | 456 } |
456 | 457 |
| 458 bool MachOImageReader::GetCrashpadInfo( |
| 459 process_types::CrashpadInfo* crashpad_info) const { |
| 460 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 461 |
| 462 mach_vm_address_t crashpad_info_address; |
| 463 const process_types::section* crashpad_info_section = |
| 464 GetSectionByName(SEG_DATA, "__crashpad_info", &crashpad_info_address); |
| 465 if (!crashpad_info_section) { |
| 466 return false; |
| 467 } |
| 468 |
| 469 if (crashpad_info_section->size < |
| 470 crashpad_info->ExpectedSize(process_reader_)) { |
| 471 LOG(WARNING) << "small crashpad info section size " |
| 472 << crashpad_info_section->size << module_info_; |
| 473 return false; |
| 474 } |
| 475 |
| 476 if (!crashpad_info->Read(process_reader_, crashpad_info_address)) { |
| 477 LOG(WARNING) << "could not read crashpad info" << module_info_; |
| 478 return false; |
| 479 } |
| 480 |
| 481 if (crashpad_info->signature != CrashpadInfo::kSignature || |
| 482 crashpad_info->size != crashpad_info_section->size || |
| 483 crashpad_info->version < 1) { |
| 484 LOG(WARNING) << "unexpected crashpad info data" << module_info_; |
| 485 return false; |
| 486 } |
| 487 |
| 488 return true; |
| 489 } |
| 490 |
457 template <typename T> | 491 template <typename T> |
458 bool MachOImageReader::ReadLoadCommand(mach_vm_address_t load_command_address, | 492 bool MachOImageReader::ReadLoadCommand(mach_vm_address_t load_command_address, |
459 const std::string& load_command_info, | 493 const std::string& load_command_info, |
460 uint32_t expected_load_command_id, | 494 uint32_t expected_load_command_id, |
461 T* load_command) { | 495 T* load_command) { |
462 if (!load_command->Read(process_reader_, load_command_address)) { | 496 if (!load_command->Read(process_reader_, load_command_address)) { |
463 LOG(WARNING) << "could not read load command" << load_command_info; | 497 LOG(WARNING) << "could not read load command" << load_command_info; |
464 return false; | 498 return false; |
465 } | 499 } |
466 | 500 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 linkedit_segment, | 696 linkedit_segment, |
663 module_info_)) { | 697 module_info_)) { |
664 symbol_table_.reset(); | 698 symbol_table_.reset(); |
665 return; | 699 return; |
666 } | 700 } |
667 | 701 |
668 symbol_table_initialized_.set_valid(); | 702 symbol_table_initialized_.set_valid(); |
669 } | 703 } |
670 | 704 |
671 } // namespace crashpad | 705 } // namespace crashpad |
OLD | NEW |