| 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/process_types.h" | 15 #include "snapshot/mac/process_types.h" |
| 16 | 16 |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 | 18 |
| 19 #include "base/logging.h" |
| 19 #include "snapshot/mac/process_types/internal.h" | 20 #include "snapshot/mac/process_types/internal.h" |
| 20 #include "util/mach/task_memory.h" | 21 #include "util/mach/task_memory.h" |
| 21 | 22 |
| 22 namespace crashpad { | 23 namespace crashpad { |
| 23 namespace process_types { | 24 namespace process_types { |
| 24 namespace internal { | 25 namespace internal { |
| 25 | 26 |
| 26 template <typename Traits> | 27 template <typename T> |
| 27 bool dyld_all_image_infos<Traits>::ReadInto( | 28 bool ReadIntoVersioned(ProcessReader* process_reader, |
| 28 ProcessReader* process_reader, | 29 mach_vm_address_t address, |
| 29 mach_vm_address_t address, | 30 T* specific) { |
| 30 dyld_all_image_infos<Traits>* specific) { | |
| 31 TaskMemory* task_memory = process_reader->Memory(); | 31 TaskMemory* task_memory = process_reader->Memory(); |
| 32 if (!task_memory->Read( | 32 if (!task_memory->Read( |
| 33 address, sizeof(specific->version), &specific->version)) { | 33 address, sizeof(specific->version), &specific->version)) { |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 | 36 |
| 37 mach_vm_size_t size; | 37 mach_vm_size_t size = T::ExpectedSizeForVersion(specific->version); |
| 38 if (specific->version >= 14) { | |
| 39 size = sizeof(dyld_all_image_infos<Traits>); | |
| 40 } else if (specific->version >= 13) { | |
| 41 size = offsetof(dyld_all_image_infos<Traits>, reserved); | |
| 42 } else if (specific->version >= 12) { | |
| 43 size = offsetof(dyld_all_image_infos<Traits>, sharedCacheUUID); | |
| 44 } else if (specific->version >= 11) { | |
| 45 size = offsetof(dyld_all_image_infos<Traits>, sharedCacheSlide); | |
| 46 } else if (specific->version >= 10) { | |
| 47 size = offsetof(dyld_all_image_infos<Traits>, errorKind); | |
| 48 } else if (specific->version >= 9) { | |
| 49 size = offsetof(dyld_all_image_infos<Traits>, initialImageCount); | |
| 50 } else if (specific->version >= 8) { | |
| 51 size = offsetof(dyld_all_image_infos<Traits>, dyldAllImageInfosAddress); | |
| 52 } else if (specific->version >= 7) { | |
| 53 size = offsetof(dyld_all_image_infos<Traits>, uuidArrayCount); | |
| 54 } else if (specific->version >= 6) { | |
| 55 size = offsetof(dyld_all_image_infos<Traits>, systemOrderFlag); | |
| 56 } else if (specific->version >= 5) { | |
| 57 size = offsetof(dyld_all_image_infos<Traits>, coreSymbolicationShmPage); | |
| 58 } else if (specific->version >= 3) { | |
| 59 size = offsetof(dyld_all_image_infos<Traits>, dyldVersion); | |
| 60 } else if (specific->version >= 2) { | |
| 61 size = offsetof(dyld_all_image_infos<Traits>, jitInfo); | |
| 62 } else if (specific->version >= 1) { | |
| 63 size = offsetof(dyld_all_image_infos<Traits>, libSystemInitialized); | |
| 64 } else { | |
| 65 size = offsetof(dyld_all_image_infos<Traits>, infoArrayCount); | |
| 66 } | |
| 67 | 38 |
| 68 if (!task_memory->Read(address, size, specific)) { | 39 if (!task_memory->Read(address, size, specific)) { |
| 69 return false; | 40 return false; |
| 70 } | 41 } |
| 71 | 42 |
| 72 // Zero out the rest of the structure in case anything accesses fields without | 43 // Zero out the rest of the structure in case anything accesses fields without |
| 73 // checking the version. | 44 // checking the version. |
| 74 size_t remaining = sizeof(*specific) - size; | 45 size_t remaining = sizeof(*specific) - size; |
| 75 if (remaining > 0) { | 46 if (remaining > 0) { |
| 76 char* start = reinterpret_cast<char*>(specific) + size; | 47 char* start = reinterpret_cast<char*>(specific) + size; |
| 77 memset(start, 0, remaining); | 48 memset(start, 0, remaining); |
| 78 } | 49 } |
| 79 | 50 |
| 80 return true; | 51 return true; |
| 81 } | 52 } |
| 82 | 53 |
| 83 #define PROCESS_TYPE_FLAVOR_TRAITS(lp_bits) \ | 54 // static |
| 84 template bool dyld_all_image_infos<Traits##lp_bits>::ReadInto( \ | 55 template <typename Traits> |
| 85 ProcessReader*, \ | 56 size_t dyld_all_image_infos<Traits>::ExpectedSizeForVersion(uint64_t version) { |
| 86 mach_vm_address_t, \ | 57 if (version >= 14) { |
| 87 dyld_all_image_infos<Traits##lp_bits>*); | 58 return sizeof(dyld_all_image_infos<Traits>); |
| 59 } |
| 60 if (version >= 13) { |
| 61 return offsetof(dyld_all_image_infos<Traits>, reserved); |
| 62 } |
| 63 if (version >= 12) { |
| 64 return offsetof(dyld_all_image_infos<Traits>, sharedCacheUUID); |
| 65 } |
| 66 if (version >= 11) { |
| 67 return offsetof(dyld_all_image_infos<Traits>, sharedCacheSlide); |
| 68 } |
| 69 if (version >= 10) { |
| 70 return offsetof(dyld_all_image_infos<Traits>, errorKind); |
| 71 } |
| 72 if (version >= 9) { |
| 73 return offsetof(dyld_all_image_infos<Traits>, initialImageCount); |
| 74 } |
| 75 if (version >= 8) { |
| 76 return offsetof(dyld_all_image_infos<Traits>, dyldAllImageInfosAddress); |
| 77 } |
| 78 if (version >= 7) { |
| 79 return offsetof(dyld_all_image_infos<Traits>, uuidArrayCount); |
| 80 } |
| 81 if (version >= 6) { |
| 82 return offsetof(dyld_all_image_infos<Traits>, systemOrderFlag); |
| 83 } |
| 84 if (version >= 5) { |
| 85 return offsetof(dyld_all_image_infos<Traits>, coreSymbolicationShmPage); |
| 86 } |
| 87 if (version >= 3) { |
| 88 return offsetof(dyld_all_image_infos<Traits>, dyldVersion); |
| 89 } |
| 90 if (version >= 2) { |
| 91 return offsetof(dyld_all_image_infos<Traits>, jitInfo); |
| 92 } |
| 93 if (version >= 1) { |
| 94 return offsetof(dyld_all_image_infos<Traits>, libSystemInitialized); |
| 95 } |
| 96 return offsetof(dyld_all_image_infos<Traits>, infoArrayCount); |
| 97 } |
| 98 |
| 99 // static |
| 100 template <typename Traits> |
| 101 bool dyld_all_image_infos<Traits>::ReadInto( |
| 102 ProcessReader* process_reader, |
| 103 mach_vm_address_t address, |
| 104 dyld_all_image_infos<Traits>* specific) { |
| 105 return ReadIntoVersioned(process_reader, address, specific); |
| 106 } |
| 107 |
| 108 // static |
| 109 template <typename Traits> |
| 110 size_t crashreporter_annotations_t<Traits>::ExpectedSizeForVersion( |
| 111 uint64_t version) { |
| 112 if (version >= 5) { |
| 113 return sizeof(crashreporter_annotations_t<Traits>); |
| 114 } |
| 115 if (version >= 4) { |
| 116 return offsetof(crashreporter_annotations_t<Traits>, unknown_0); |
| 117 } |
| 118 return offsetof(crashreporter_annotations_t<Traits>, message); |
| 119 } |
| 120 |
| 121 // static |
| 122 template <typename Traits> |
| 123 bool crashreporter_annotations_t<Traits>::ReadInto( |
| 124 ProcessReader* process_reader, |
| 125 mach_vm_address_t address, |
| 126 crashreporter_annotations_t<Traits>* specific) { |
| 127 return ReadIntoVersioned(process_reader, address, specific); |
| 128 } |
| 129 |
| 130 #define PROCESS_TYPE_FLAVOR_TRAITS(lp_bits) \ |
| 131 template size_t \ |
| 132 dyld_all_image_infos<Traits##lp_bits>::ExpectedSizeForVersion(uint64_t); \ |
| 133 template bool dyld_all_image_infos<Traits##lp_bits>::ReadInto( \ |
| 134 ProcessReader*, \ |
| 135 mach_vm_address_t, \ |
| 136 dyld_all_image_infos<Traits##lp_bits>*); \ |
| 137 template size_t \ |
| 138 crashreporter_annotations_t<Traits##lp_bits>::ExpectedSizeForVersion( \ |
| 139 uint64_t); \ |
| 140 template bool crashreporter_annotations_t<Traits##lp_bits>::ReadInto( \ |
| 141 ProcessReader*, \ |
| 142 mach_vm_address_t, \ |
| 143 crashreporter_annotations_t<Traits##lp_bits>*); |
| 88 | 144 |
| 89 #include "snapshot/mac/process_types/flavors.h" | 145 #include "snapshot/mac/process_types/flavors.h" |
| 90 | 146 |
| 91 #undef PROCESS_TYPE_FLAVOR_TRAITS | 147 #undef PROCESS_TYPE_FLAVOR_TRAITS |
| 92 | 148 |
| 93 } // namespace internal | 149 } // namespace internal |
| 94 } // namespace process_types | 150 } // namespace process_types |
| 95 } // namespace crashpad | 151 } // namespace crashpad |
| OLD | NEW |