| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/mac/process_types.h" | |
| 16 | |
| 17 #include <string.h> | |
| 18 | |
| 19 #include "util/mac/process_types/internal.h" | |
| 20 #include "util/mach/task_memory.h" | |
| 21 | |
| 22 namespace crashpad { | |
| 23 namespace process_types { | |
| 24 namespace internal { | |
| 25 | |
| 26 template <typename Traits> | |
| 27 bool dyld_all_image_infos<Traits>::ReadInto( | |
| 28 ProcessReader* process_reader, | |
| 29 mach_vm_address_t address, | |
| 30 dyld_all_image_infos<Traits>* specific) { | |
| 31 TaskMemory* task_memory = process_reader->Memory(); | |
| 32 if (!task_memory->Read( | |
| 33 address, sizeof(specific->version), &specific->version)) { | |
| 34 return false; | |
| 35 } | |
| 36 | |
| 37 mach_vm_size_t size; | |
| 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 | |
| 68 if (!task_memory->Read(address, size, specific)) { | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 // Zero out the rest of the structure in case anything accesses fields without | |
| 73 // checking the version. | |
| 74 size_t remaining = sizeof(*specific) - size; | |
| 75 if (remaining > 0) { | |
| 76 char* start = reinterpret_cast<char*>(specific) + size; | |
| 77 memset(start, 0, remaining); | |
| 78 } | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 #define PROCESS_TYPE_FLAVOR_TRAITS(lp_bits) \ | |
| 84 template bool dyld_all_image_infos<Traits##lp_bits>::ReadInto( \ | |
| 85 ProcessReader*, \ | |
| 86 mach_vm_address_t, \ | |
| 87 dyld_all_image_infos<Traits##lp_bits>*); | |
| 88 | |
| 89 #include "util/mac/process_types/flavors.h" | |
| 90 | |
| 91 #undef PROCESS_TYPE_FLAVOR_TRAITS | |
| 92 | |
| 93 } // namespace internal | |
| 94 } // namespace process_types | |
| 95 } // namespace crashpad | |
| OLD | NEW |