OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_WIN_PROCESS_STRUCTS_H_ |
| 16 #define CRASHPAD_UTIL_WIN_PROCESS_STRUCTS_H_ |
| 17 |
| 18 #include <windows.h> |
| 19 |
| 20 namespace crashpad { |
| 21 namespace process_types { |
| 22 |
| 23 namespace internal { |
| 24 |
| 25 struct Traits32 { |
| 26 using Pad = DWORD; |
| 27 using UnsignedIntegral = DWORD; |
| 28 using Pointer = DWORD; |
| 29 }; |
| 30 |
| 31 struct Traits64 { |
| 32 using Pad = DWORD64; |
| 33 using UnsignedIntegral = DWORD64; |
| 34 using Pointer = DWORD64; |
| 35 }; |
| 36 |
| 37 } // namespace internal |
| 38 |
| 39 //! \{ |
| 40 |
| 41 //! \brief Selected structures from winternl.h, ntddk.h, and `dt ntdll!xxx`, |
| 42 //! customized to have both x86 and x64 sizes available. |
| 43 //! |
| 44 //! The structure and field names follow the Windows names for clarity. We do, |
| 45 //! however, use plain integral types rather than pointer types. This is both |
| 46 //! easier to define, and avoids accidentally treating them as pointers into the |
| 47 //! current address space. |
| 48 //! |
| 49 //! The templates below should be instantiated with either internal::Traits32 |
| 50 //! for structures targeting x86, or internal::Traits64 for x64. |
| 51 |
| 52 // We set packing to 1 so that we can explicitly control the layout to make it |
| 53 // match the OS defined structures. |
| 54 #pragma pack(push, 1) |
| 55 |
| 56 template <class Traits> |
| 57 struct PROCESS_BASIC_INFORMATION { |
| 58 union { |
| 59 DWORD ExitStatus; |
| 60 typename Traits::Pad padding_for_x64_0; |
| 61 }; |
| 62 typename Traits::Pointer PebBaseAddress; |
| 63 typename Traits::UnsignedIntegral AffinityMask; |
| 64 union { |
| 65 DWORD BasePriority; |
| 66 typename Traits::Pad padding_for_x64_1; |
| 67 }; |
| 68 typename Traits::UnsignedIntegral UniqueProcessId; |
| 69 typename Traits::UnsignedIntegral InheritedFromUniqueProcessId; |
| 70 }; |
| 71 |
| 72 template <class Traits> |
| 73 struct LIST_ENTRY { |
| 74 typename Traits::Pointer Flink; |
| 75 typename Traits::Pointer Blink; |
| 76 }; |
| 77 |
| 78 template <class Traits> |
| 79 struct UNICODE_STRING { |
| 80 union { |
| 81 struct { |
| 82 USHORT Length; |
| 83 USHORT MaximumLength; |
| 84 }; |
| 85 typename Traits::Pad padding_for_x64; |
| 86 }; |
| 87 typename Traits::Pointer Buffer; |
| 88 }; |
| 89 |
| 90 template <class Traits> |
| 91 struct PEB_LDR_DATA { |
| 92 ULONG Length; |
| 93 DWORD Initialized; |
| 94 typename Traits::Pointer SsHandle; |
| 95 LIST_ENTRY<Traits> InLoadOrderModuleList; |
| 96 LIST_ENTRY<Traits> InMemoryOrderModuleList; |
| 97 LIST_ENTRY<Traits> InInitializationOrderModuleList; |
| 98 }; |
| 99 |
| 100 template <class Traits> |
| 101 struct LDR_DATA_TABLE_ENTRY { |
| 102 LIST_ENTRY<Traits> InLoadOrderLinks; |
| 103 LIST_ENTRY<Traits> InMemoryOrderLinks; |
| 104 LIST_ENTRY<Traits> InInitializationOrderLinks; |
| 105 typename Traits::Pointer DllBase; |
| 106 typename Traits::Pointer EntryPoint; |
| 107 union { |
| 108 ULONG SizeOfImage; |
| 109 typename Traits::Pad padding_for_x64; |
| 110 }; |
| 111 UNICODE_STRING<Traits> FullDllName; |
| 112 UNICODE_STRING<Traits> BaseDllName; |
| 113 ULONG Flags; |
| 114 USHORT ObsoleteLoadCount; |
| 115 USHORT TlsIndex; |
| 116 LIST_ENTRY<Traits> HashLinks; |
| 117 ULONG TimeDateStamp; |
| 118 }; |
| 119 |
| 120 template <class Traits> |
| 121 struct CURDIR { |
| 122 UNICODE_STRING<Traits> DosPath; |
| 123 typename Traits::Pointer Handle; |
| 124 }; |
| 125 |
| 126 template <class Traits> |
| 127 struct STRING { |
| 128 union { |
| 129 struct { |
| 130 DWORD Length; |
| 131 DWORD MaximumLength; |
| 132 }; |
| 133 typename Traits::Pad padding_for_x64; |
| 134 }; |
| 135 typename Traits::Pointer Buffer; |
| 136 }; |
| 137 |
| 138 template <class Traits> |
| 139 struct RTL_DRIVE_LETTER_CURDIR { |
| 140 WORD Flags; |
| 141 WORD Length; |
| 142 DWORD TimeStamp; |
| 143 STRING<Traits> DosPath; |
| 144 }; |
| 145 |
| 146 template <class Traits> |
| 147 struct RTL_USER_PROCESS_PARAMETERS { |
| 148 DWORD MaximumLength; |
| 149 DWORD Length; |
| 150 DWORD Flags; |
| 151 DWORD DebugFlags; |
| 152 typename Traits::Pointer ConsoleHandle; |
| 153 union { |
| 154 DWORD ConsoleFlags; |
| 155 typename Traits::Pad padding_for_x64; |
| 156 }; |
| 157 typename Traits::Pointer StandardInput; |
| 158 typename Traits::Pointer StandardOutput; |
| 159 typename Traits::Pointer StandardError; |
| 160 CURDIR<Traits> CurrentDirectory; |
| 161 UNICODE_STRING<Traits> DllPath; |
| 162 UNICODE_STRING<Traits> ImagePathName; |
| 163 UNICODE_STRING<Traits> CommandLine; |
| 164 typename Traits::Pointer Environment; |
| 165 DWORD StartingX; |
| 166 DWORD StartingY; |
| 167 DWORD CountX; |
| 168 DWORD CountY; |
| 169 DWORD CountCharsX; |
| 170 DWORD CountCharsY; |
| 171 DWORD FillAttribute; |
| 172 DWORD WindowFlags; |
| 173 DWORD ShowWindowFlags; |
| 174 UNICODE_STRING<Traits> WindowTitle; |
| 175 UNICODE_STRING<Traits> DesktopInfo; |
| 176 UNICODE_STRING<Traits> ShellInfo; |
| 177 UNICODE_STRING<Traits> RuntimeData; |
| 178 RTL_DRIVE_LETTER_CURDIR<Traits> CurrentDirectores[32]; // sic. |
| 179 }; |
| 180 |
| 181 template <class T> |
| 182 struct GdiHandleBufferCountForBitness; |
| 183 |
| 184 template <> |
| 185 struct GdiHandleBufferCountForBitness<internal::Traits32> { |
| 186 enum { value = 34 }; |
| 187 }; |
| 188 template <> |
| 189 struct GdiHandleBufferCountForBitness<internal::Traits64> { |
| 190 enum { value = 60 }; |
| 191 }; |
| 192 |
| 193 template <class Traits> |
| 194 struct PEB { |
| 195 union { |
| 196 struct { |
| 197 BYTE InheritedAddressSpace; |
| 198 BYTE ReadImageFileExecOptions; |
| 199 BYTE BeingDebugged; |
| 200 BYTE BitField; |
| 201 }; |
| 202 typename Traits::Pad padding_for_x64_0; |
| 203 }; |
| 204 typename Traits::Pointer Mutant; |
| 205 typename Traits::Pointer ImageBaseAddress; |
| 206 typename Traits::Pointer Ldr; |
| 207 typename Traits::Pointer ProcessParameters; |
| 208 typename Traits::Pointer SubSystemData; |
| 209 typename Traits::Pointer ProcessHeap; |
| 210 typename Traits::Pointer FastPebLock; |
| 211 typename Traits::Pointer AtlThunkSListPtr; |
| 212 typename Traits::Pointer IFEOKey; |
| 213 union { |
| 214 DWORD CrossProcessFlags; |
| 215 typename Traits::Pad padding_for_x64_1; |
| 216 }; |
| 217 typename Traits::Pointer KernelCallbackTable; |
| 218 DWORD SystemReserved; |
| 219 DWORD AtlThunkSListPtr32; |
| 220 typename Traits::Pointer ApiSetMap; |
| 221 union { |
| 222 DWORD TlsExpansionCounter; |
| 223 typename Traits::Pad padding_for_x64_2; |
| 224 }; |
| 225 typename Traits::Pointer TlsBitmap; |
| 226 DWORD TlsBitmapBits[2]; |
| 227 typename Traits::Pointer ReadOnlySharedMemoryBase; |
| 228 typename Traits::Pointer SparePvoid0; |
| 229 typename Traits::Pointer ReadOnlyStaticServerData; |
| 230 typename Traits::Pointer AnsiCodePageData; |
| 231 typename Traits::Pointer OemCodePageData; |
| 232 typename Traits::Pointer UnicodeCaseTableData; |
| 233 DWORD NumberOfProcessors; |
| 234 DWORD NtGlobalFlag; |
| 235 LARGE_INTEGER CriticalSectionTimeout; |
| 236 typename Traits::UnsignedIntegral HeapSegmentReserve; |
| 237 typename Traits::UnsignedIntegral HeapSegmentCommit; |
| 238 typename Traits::UnsignedIntegral HeapDeCommitTotalFreeThreshold; |
| 239 typename Traits::UnsignedIntegral HeapDeCommitFreeBlockThreshold; |
| 240 DWORD NumberOfHeaps; |
| 241 DWORD MaximumNumberOfHeaps; |
| 242 typename Traits::Pointer ProcessHeaps; |
| 243 typename Traits::Pointer GdiSharedHandleTable; |
| 244 typename Traits::Pointer ProcessStarterHelper; |
| 245 DWORD GdiDCAttributeList; |
| 246 typename Traits::Pointer LoaderLock; |
| 247 DWORD OSMajorVersion; |
| 248 DWORD OSMinorVersion; |
| 249 WORD OSBuildNumber; |
| 250 WORD OSCSDVersion; |
| 251 DWORD OSPlatformId; |
| 252 DWORD ImageSubsystem; |
| 253 DWORD ImageSubsystemMajorVersion; |
| 254 union { |
| 255 DWORD ImageSubsystemMinorVersion; |
| 256 typename Traits::Pad padding_for_x64_3; |
| 257 }; |
| 258 typename Traits::UnsignedIntegral ActiveProcessAffinityMask; |
| 259 DWORD GdiHandleBuffer[GdiHandleBufferCountForBitness<Traits>::value]; |
| 260 typename Traits::Pointer PostProcessInitRoutine; |
| 261 typename Traits::Pointer TlsExpansionBitmap; |
| 262 DWORD TlsExpansionBitmapBits[32]; |
| 263 union { |
| 264 DWORD SessionId; |
| 265 typename Traits::Pad padding_for_x64_4; |
| 266 }; |
| 267 ULARGE_INTEGER AppCompatFlags; |
| 268 ULARGE_INTEGER AppCompatFlagsUser; |
| 269 typename Traits::Pointer pShimData; |
| 270 typename Traits::Pointer AppCompatInfo; |
| 271 UNICODE_STRING<Traits> CSDVersion; |
| 272 typename Traits::Pointer ActivationContextData; |
| 273 typename Traits::Pointer ProcessAssemblyStorageMap; |
| 274 typename Traits::Pointer SystemDefaultActivationContextData; |
| 275 typename Traits::Pointer SystemAssemblyStorageMap; |
| 276 typename Traits::UnsignedIntegral MinimumStackCommit; |
| 277 typename Traits::Pointer FlsCallback; |
| 278 LIST_ENTRY<Traits> FlsListHead; |
| 279 typename Traits::Pointer FlsBitmap; |
| 280 DWORD FlsBitmapBits[4]; |
| 281 DWORD FlsHighIndex; |
| 282 }; |
| 283 |
| 284 #pragma pack(pop) |
| 285 |
| 286 //! \} |
| 287 |
| 288 } // namespace process_types |
| 289 } // namespace crashpad |
| 290 |
| 291 #endif // CRASHPAD_UTIL_WIN_PROCESS_STRUCTS_H_ |
OLD | NEW |