| 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, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 \ | 79 \ |
| 80 /* Returns the size of the object that was read. This is the size of the \ | 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 \ | 81 * storage in the process that the data is read from, and is not the same \ |
| 82 * as the size of the generic struct. */ \ | 82 * as the size of the generic struct. */ \ |
| 83 size_t Size() const { return size_; } \ | 83 size_t Size() const { return size_; } \ |
| 84 \ | 84 \ |
| 85 /* Similar to Size(), but computes the expected size of a structure based \ | 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 \ | 86 * on the process’ bitness. This can be used prior to reading any data \ |
| 87 * from a process. */ \ | 87 * from a process. */ \ |
| 88 static size_t ExpectedSize(ProcessReader* process_reader); \ | 88 static size_t ExpectedSize(ProcessReader* process_reader); \ |
| 89 \ | 89 |
| 90 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ |
| 91 member_type member_name __VA_ARGS__; |
| 92 |
| 93 #define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field) \ |
| 90 /* Similar to ExpectedSize(), but computes the expected size of a \ | 94 /* Similar to ExpectedSize(), but computes the expected size of a \ |
| 91 * structure based on the process’ bitness and a custom value, such as a \ | 95 * structure based on the process’ bitness and a custom value, such as a \ |
| 92 * structure version number. This can be used prior to reading any data \ | 96 * structure version number. This can be used prior to reading any data \ |
| 93 * from a process. */ \ | 97 * from a process. */ \ |
| 94 static size_t ExpectedSizeForVersion(ProcessReader* process_reader, \ | 98 static size_t ExpectedSizeForVersion( \ |
| 95 uint64_t version); | 99 ProcessReader* process_reader, \ |
| 96 | 100 decltype(struct_name::version_field) version); |
| 97 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ | |
| 98 member_type member_name __VA_ARGS__; | |
| 99 | 101 |
| 100 #define PROCESS_TYPE_STRUCT_END(struct_name) \ | 102 #define PROCESS_TYPE_STRUCT_END(struct_name) \ |
| 101 private: \ | 103 private: \ |
| 102 /* The static form of Read(). Populates the struct at |generic|. */ \ | 104 /* The static form of Read(). Populates the struct at |generic|. */ \ |
| 103 static bool ReadInto(ProcessReader* process_reader, \ | 105 static bool ReadInto(ProcessReader* process_reader, \ |
| 104 mach_vm_address_t address, \ | 106 mach_vm_address_t address, \ |
| 105 struct_name* generic); \ | 107 struct_name* generic); \ |
| 106 \ | 108 \ |
| 107 template <typename T> \ | 109 template <typename T> \ |
| 108 static bool ReadIntoInternal(ProcessReader* process_reader, \ | 110 static bool ReadIntoInternal(ProcessReader* process_reader, \ |
| 109 mach_vm_address_t address, \ | 111 mach_vm_address_t address, \ |
| 110 struct_name* generic); \ | 112 struct_name* generic); \ |
| 111 template <typename T> \ | 113 template <typename T> \ |
| 112 static bool ReadArrayIntoInternal(ProcessReader* process_reader, \ | 114 static bool ReadArrayIntoInternal(ProcessReader* process_reader, \ |
| 113 mach_vm_address_t address, \ | 115 mach_vm_address_t address, \ |
| 114 size_t count, \ | 116 size_t count, \ |
| 115 struct_name* generic); \ | 117 struct_name* generic); \ |
| 116 size_t size_; \ | 118 size_t size_; \ |
| 117 }; \ | 119 }; \ |
| 118 } /* namespace process_types */ \ | 120 } /* namespace process_types */ \ |
| 119 } /* namespace crashpad */ | 121 } /* namespace crashpad */ |
| 120 | 122 |
| 121 #include "snapshot/mac/process_types/all.proctype" | 123 #include "snapshot/mac/process_types/all.proctype" |
| 122 | 124 |
| 123 #undef PROCESS_TYPE_STRUCT_BEGIN | 125 #undef PROCESS_TYPE_STRUCT_BEGIN |
| 124 #undef PROCESS_TYPE_STRUCT_MEMBER | 126 #undef PROCESS_TYPE_STRUCT_MEMBER |
| 127 #undef PROCESS_TYPE_STRUCT_VERSIONED |
| 125 #undef PROCESS_TYPE_STRUCT_END | 128 #undef PROCESS_TYPE_STRUCT_END |
| 126 #undef PROCESS_TYPE_STRUCT_DECLARE | 129 #undef PROCESS_TYPE_STRUCT_DECLARE |
| 127 | 130 |
| 128 // Declare the templatized crashpad::process_types::internal::struct_name<> | 131 // Declare the templatized crashpad::process_types::internal::struct_name<> |
| 129 // structs. These are the 32-bit and 64-bit specific structs that describe the | 132 // structs. These are the 32-bit and 64-bit specific structs that describe the |
| 130 // layout of objects in another process. This is repeated instead of being | 133 // layout of objects in another process. This is repeated instead of being |
| 131 // shared with the generic declaration above because both the generic and | 134 // shared with the generic declaration above because both the generic and |
| 132 // templatized specific structs need all of the struct members declared. | 135 // templatized specific structs need all of the struct members declared. |
| 133 // | 136 // |
| 134 // | |
| 135 // GenericizeInto() translates a struct from the representation used in the | 137 // GenericizeInto() translates a struct from the representation used in the |
| 136 // remote process into the generic form. | 138 // remote process into the generic form. |
| 137 #define PROCESS_TYPE_STRUCT_DECLARE_INTERNAL 1 | 139 #define PROCESS_TYPE_STRUCT_DECLARE_INTERNAL 1 |
| 138 | 140 |
| 139 #define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \ | 141 #define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \ |
| 140 namespace crashpad { \ | 142 namespace crashpad { \ |
| 141 namespace process_types { \ | 143 namespace process_types { \ |
| 142 namespace internal { \ | 144 namespace internal { \ |
| 143 template <typename Traits> \ | 145 template <typename Traits> \ |
| 144 struct struct_name { \ | 146 struct struct_name { \ |
| 145 public: \ | 147 public: \ |
| 146 using Long = typename Traits::Long; \ | 148 using Long = typename Traits::Long; \ |
| 147 using ULong = typename Traits::ULong; \ | 149 using ULong = typename Traits::ULong; \ |
| 148 using Pointer = typename Traits::Pointer; \ | 150 using Pointer = typename Traits::Pointer; \ |
| 149 using IntPtr = typename Traits::IntPtr; \ | 151 using IntPtr = typename Traits::IntPtr; \ |
| 150 using UIntPtr = typename Traits::UIntPtr; \ | 152 using UIntPtr = typename Traits::UIntPtr; \ |
| 151 using Reserved64Only = typename Traits::Reserved64Only; \ | 153 using Reserved64Only = typename Traits::Reserved64Only; \ |
| 152 \ | 154 \ |
| 153 /* Read(), ReadArrayInto(), Size(), and ExpectedSizeForVersion() are as in \ | 155 /* Read(), ReadArrayInto(), and Size() are as in the generic user-visible \ |
| 154 * the generic user-visible struct above. */ \ | 156 * struct above. */ \ |
| 155 bool Read(ProcessReader* process_reader, mach_vm_address_t address) { \ | 157 bool Read(ProcessReader* process_reader, mach_vm_address_t address) { \ |
| 156 return ReadInto(process_reader, address, this); \ | 158 return ReadInto(process_reader, address, this); \ |
| 157 } \ | 159 } \ |
| 158 static bool ReadArrayInto(ProcessReader* process_reader, \ | 160 static bool ReadArrayInto(ProcessReader* process_reader, \ |
| 159 mach_vm_address_t address, \ | 161 mach_vm_address_t address, \ |
| 160 size_t count, \ | 162 size_t count, \ |
| 161 struct_name<Traits>* specific); \ | 163 struct_name<Traits>* specific); \ |
| 162 static size_t Size() { return sizeof(struct_name<Traits>); } \ | 164 static size_t Size() { return sizeof(struct_name<Traits>); } \ |
| 163 static size_t ExpectedSizeForVersion(uint64_t version); \ | |
| 164 \ | 165 \ |
| 165 /* Translates a struct from the representation used in the remote process \ | 166 /* Translates a struct from the representation used in the remote process \ |
| 166 * into the generic form. */ \ | 167 * into the generic form. */ \ |
| 167 void GenericizeInto(process_types::struct_name* generic, \ | 168 void GenericizeInto(process_types::struct_name* generic, \ |
| 168 size_t* specific_size); | 169 size_t* specific_size); |
| 169 | 170 |
| 170 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ | 171 #define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \ |
| 171 member_type member_name __VA_ARGS__; | 172 member_type member_name __VA_ARGS__; |
| 172 | 173 |
| 174 #define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field) \ |
| 175 /* ExpectedSizeForVersion() is as in the generic user-visible struct \ |
| 176 * above. */ \ |
| 177 static size_t ExpectedSizeForVersion( \ |
| 178 decltype(struct_name::version_field) version); |
| 179 |
| 173 #define PROCESS_TYPE_STRUCT_END(struct_name) \ | 180 #define PROCESS_TYPE_STRUCT_END(struct_name) \ |
| 174 private: \ | 181 private: \ |
| 175 /* ReadInto() is as in the generic user-visible struct above. */ \ | 182 /* ReadInto() is as in the generic user-visible struct above. */ \ |
| 176 static bool ReadInto(ProcessReader* process_reader, \ | 183 static bool ReadInto(ProcessReader* process_reader, \ |
| 177 mach_vm_address_t address, \ | 184 mach_vm_address_t address, \ |
| 178 struct_name<Traits>* specific); \ | 185 struct_name<Traits>* specific); \ |
| 179 }; \ | 186 }; \ |
| 180 } /* namespace internal */ \ | 187 } /* namespace internal */ \ |
| 181 } /* namespace process_types */ \ | 188 } /* namespace process_types */ \ |
| 182 } /* namespace crashpad */ | 189 } /* namespace crashpad */ |
| 183 | 190 |
| 184 #include "snapshot/mac/process_types/all.proctype" | 191 #include "snapshot/mac/process_types/all.proctype" |
| 185 | 192 |
| 186 #undef PROCESS_TYPE_STRUCT_BEGIN | 193 #undef PROCESS_TYPE_STRUCT_BEGIN |
| 187 #undef PROCESS_TYPE_STRUCT_MEMBER | 194 #undef PROCESS_TYPE_STRUCT_MEMBER |
| 195 #undef PROCESS_TYPE_STRUCT_VERSIONED |
| 188 #undef PROCESS_TYPE_STRUCT_END | 196 #undef PROCESS_TYPE_STRUCT_END |
| 189 #undef PROCESS_TYPE_STRUCT_DECLARE_INTERNAL | 197 #undef PROCESS_TYPE_STRUCT_DECLARE_INTERNAL |
| 190 | 198 |
| 191 #endif // CRASHPAD_SNAPSHOT_MAC_PROCESS_TYPES_H_ | 199 #endif // CRASHPAD_SNAPSHOT_MAC_PROCESS_TYPES_H_ |
| OLD | NEW |