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 #ifndef CRASHPAD_UTIL_MAC_PROCESS_TYPES_H_ |
| 16 #define CRASHPAD_UTIL_MAC_PROCESS_TYPES_H_ |
| 17 |
| 18 #include <mach/mach.h> |
| 19 #include <mach-o/dyld_images.h> |
| 20 #include <mach-o/loader.h> |
| 21 #include <stdint.h> |
| 22 #include <sys/types.h> |
| 23 |
| 24 #include "util/mac/process_reader.h" |
| 25 |
| 26 namespace crashpad { |
| 27 namespace process_types { |
| 28 namespace internal { |
| 29 |
| 30 // Some structure definitions differ in 32-bit and 64-bit environments by having |
| 31 // additional “reserved” padding fields present only in the 64-bit environment. |
| 32 // These Reserved64Only* types allow the process_types system to replicate these |
| 33 // structures more precisely. |
| 34 typedef char Reserved64Only32[0]; |
| 35 typedef uint32_t Reserved64Only64; |
| 36 |
| 37 } // namespace internal |
| 38 } // namespace process_types |
| 39 } // namespace crashpad |
| 40 |
| 41 #include "util/mac/process_types/traits.h" |
| 42 |
| 43 // Creates the traits type crashpad::process_types::internal::TraitsGeneric. |
| 44 DECLARE_PROCESS_TYPE_TRAITS_CLASS(Generic, 64) |
| 45 |
| 46 #undef DECLARE_PROCESS_TYPE_TRAITS_CLASS |
| 47 |
| 48 // Declare the crashpad::process_types::struct_name structs. These are the |
| 49 // user-visible generic structs that callers will interact with. They read data |
| 50 // from 32-bit or 64-bit processes by using the specific internal templatized |
| 51 // structs below. |
| 52 #define PROCESS_TYPE_STRUCT_DECLARE 1 |
| 53 |
| 54 #define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \ |
| 55 namespace crashpad { \ |
| 56 namespace process_types { \ |
| 57 struct struct_name { \ |
| 58 public: \ |
| 59 typedef internal::TraitsGeneric::Long Long; \ |
| 60 typedef internal::TraitsGeneric::ULong ULong; \ |
| 61 typedef internal::TraitsGeneric::Pointer Pointer; \ |
| 62 typedef internal::TraitsGeneric::IntPtr IntPtr; \ |
| 63 typedef internal::TraitsGeneric::UIntPtr UIntPtr; \ |
| 64 typedef internal::TraitsGeneric::Reserved64Only Reserved64Only; \ |
| 65 \ |
| 66 /* Initializes an object with data read from |process_reader| at \ |
| 67 * |address|, properly genericized. */ \ |
| 68 bool Read(ProcessReader* process_reader, mach_vm_address_t address) { \ |
| 69 return ReadInto(process_reader, address, this); \ |
| 70 } \ |
| 71 \ |
| 72 /* Reads |count| objects from |process_reader| beginning at |address|, and \ |
| 73 * genericizes the objects. The caller must provide storage for |count| \ |
| 74 * objects in |generic|. */ \ |
| 75 static bool ReadArrayInto(ProcessReader* process_reader, \ |
| 76 mach_vm_address_t address, \ |
| 77 size_t count, \ |
| 78 struct_name* generic); \ |
| 79 \ |
| 80 /* Returns the size of the object that was read. This is the size of the \ |
| 81 * storage in the process that the data is read from, and is not the same \ |
| 82 * as the size of the generic struct. */ \ |
| 83 size_t Size() const { return size_; } \ |
| 84 \ |
| 85 /* Similar to Size(), but computes the expected size of a structure based \ |
| 86 * on the process’ bitness. This can be used prior to reading any data \ |
| 87 * from a process. */ \ |
| 88 static size_t ExpectedSize(ProcessReader* process_reader); |
| 89 |
| 90 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ |
| 91 member_type member_name __VA_ARGS__; |
| 92 |
| 93 #define PROCESS_TYPE_STRUCT_END(struct_name) \ |
| 94 private: \ |
| 95 /* The static form of Read(). Populates the struct at |generic|. */ \ |
| 96 static bool ReadInto(ProcessReader* process_reader, \ |
| 97 mach_vm_address_t address, \ |
| 98 struct_name* generic); \ |
| 99 \ |
| 100 template <typename T> \ |
| 101 static bool ReadIntoInternal(ProcessReader* process_reader, \ |
| 102 mach_vm_address_t address, \ |
| 103 struct_name* generic); \ |
| 104 template <typename T> \ |
| 105 static bool ReadArrayIntoInternal(ProcessReader* process_reader, \ |
| 106 mach_vm_address_t address, \ |
| 107 size_t count, \ |
| 108 struct_name* generic); \ |
| 109 size_t size_; \ |
| 110 }; \ |
| 111 } /* namespace process_types */ \ |
| 112 } /* namespace crashpad */ |
| 113 |
| 114 #include "util/mac/process_types/all.proctype" |
| 115 |
| 116 #undef PROCESS_TYPE_STRUCT_BEGIN |
| 117 #undef PROCESS_TYPE_STRUCT_MEMBER |
| 118 #undef PROCESS_TYPE_STRUCT_END |
| 119 #undef PROCESS_TYPE_STRUCT_DECLARE |
| 120 |
| 121 // Declare the templatized crashpad::process_types::internal::struct_name<> |
| 122 // structs. These are the 32-bit and 64-bit specific structs that describe the |
| 123 // layout of objects in another process. This is repeated instead of being |
| 124 // shared with the generic declaration above because both the generic and |
| 125 // templatized specific structs need all of the struct members declared. |
| 126 // |
| 127 // |
| 128 // GenericizeInto() translates a struct from the representation used in the |
| 129 // remote process into the generic form. |
| 130 #define PROCESS_TYPE_STRUCT_DECLARE_INTERNAL 1 |
| 131 |
| 132 #define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \ |
| 133 namespace crashpad { \ |
| 134 namespace process_types { \ |
| 135 namespace internal { \ |
| 136 template <typename Traits> \ |
| 137 struct struct_name { \ |
| 138 public: \ |
| 139 typedef typename Traits::Long Long; \ |
| 140 typedef typename Traits::ULong ULong; \ |
| 141 typedef typename Traits::Pointer Pointer; \ |
| 142 typedef typename Traits::IntPtr IntPtr; \ |
| 143 typedef typename Traits::UIntPtr UIntPtr; \ |
| 144 typedef typename Traits::Reserved64Only Reserved64Only; \ |
| 145 \ |
| 146 /* Read(), ReadArrayInto(), and Size() are as in the generic user-visible \ |
| 147 * struct above. */ \ |
| 148 bool Read(ProcessReader* process_reader, mach_vm_address_t address) { \ |
| 149 return ReadInto(process_reader, address, this); \ |
| 150 } \ |
| 151 static bool ReadArrayInto(ProcessReader* process_reader, \ |
| 152 mach_vm_address_t address, \ |
| 153 size_t count, \ |
| 154 struct_name<Traits>* specific); \ |
| 155 static size_t Size() { return sizeof(struct_name<Traits>); } \ |
| 156 \ |
| 157 /* Translates a struct from the representation used in the remote process \ |
| 158 * into the generic form. */ \ |
| 159 void GenericizeInto(process_types::struct_name* generic, \ |
| 160 size_t* specific_size); |
| 161 |
| 162 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ |
| 163 member_type member_name __VA_ARGS__; |
| 164 |
| 165 #define PROCESS_TYPE_STRUCT_END(struct_name) \ |
| 166 private: \ |
| 167 /* ReadInto() is as in the generic user-visible struct above. */ \ |
| 168 static bool ReadInto(ProcessReader* process_reader, \ |
| 169 mach_vm_address_t address, \ |
| 170 struct_name<Traits>* specific); \ |
| 171 }; \ |
| 172 } /* namespace internal */ \ |
| 173 } /* namespace process_types */ \ |
| 174 } /* namespace crashpad */ |
| 175 |
| 176 #include "util/mac/process_types/all.proctype" |
| 177 |
| 178 #undef PROCESS_TYPE_STRUCT_BEGIN |
| 179 #undef PROCESS_TYPE_STRUCT_MEMBER |
| 180 #undef PROCESS_TYPE_STRUCT_END |
| 181 #undef PROCESS_TYPE_STRUCT_DECLARE_INTERNAL |
| 182 |
| 183 #endif // CRASHPAD_UTIL_MAC_PROCESS_TYPES_H_ |
OLD | NEW |