1 /* 2 * Copyright (c) 1998-2019 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef _IOKIT_IOKITDEBUG_H 30 #define _IOKIT_IOKITDEBUG_H 31 32 #include <IOKit/IOTypes.h> 33 34 35 #ifdef __cplusplus 36 37 #include <libkern/c++/OSObject.h> 38 #include <libkern/c++/OSDictionary.h> 39 #include <libkern/c++/OSSerialize.h> 40 41 class IOKitDiagnostics : public OSObject 42 { 43 OSDeclareDefaultStructors(IOKitDiagnostics); 44 45 public: 46 static OSObject * diagnostics( void ); 47 virtual bool serialize(OSSerialize *s) const APPLE_KEXT_OVERRIDE; 48 private: 49 static void updateOffset( OSDictionary * dict, 50 UInt64 value, const char * name ); 51 }; 52 53 #endif /* __cplusplus */ 54 55 enum { 56 // loggage 57 kIOLogAttach = 0x00000001ULL, 58 kIOLogProbe = 0x00000002ULL, 59 kIOLogStart = 0x00000004ULL, 60 kIOLogRegister = 0x00000008ULL, 61 kIOLogMatch = 0x00000010ULL, 62 kIOLogConfig = 0x00000020ULL, 63 kIOLogYield = 0x00000040ULL, 64 kIOLogPower = 0x00000080ULL, 65 kIOLogMapping = 0x00000100ULL, 66 kIOLogCatalogue = 0x00000200ULL, 67 kIOLogTracePower = 0x00000400ULL, // Obsolete: Use iotrace=0x00000400ULL to enable now 68 kIOLogDebugPower = 0x00000800ULL, 69 kIOLogServiceTree = 0x00001000ULL, 70 kIOLogDTree = 0x00002000ULL, 71 kIOLogMemory = 0x00004000ULL, 72 kIOLogKextMemory = 0x00008000ULL, 73 kOSLogRegistryMods = 0x00010000ULL,// Log attempts to modify registry collections 74 kIOLogPMRootDomain = 0x00020000ULL, 75 kOSRegistryModsMode = 0x00040000ULL,// Change default registry modification handling - panic vs. log 76 // kIOTraceIOService = 0x00080000ULL, // Obsolete: Use iotrace=0x00080000ULL to enable now 77 kIOLogHibernate = 0x00100000ULL, 78 kIOStatistics = 0x04000000ULL, 79 kIOSleepWakeWdogOff = 0x40000000ULL, 80 kIOKextSpinDump = 0x80000000ULL, 81 82 // debug aids - change behaviour 83 kIONoFreeObjects = 0x00100000ULL, 84 // kIOLogSynchronous = 0x00200000ULL, // IOLog completes synchronously -- obsolete 85 kIOTracking = 0x00400000ULL, 86 kIOWaitQuietPanics = 0x00800000ULL, 87 kIOWaitQuietBeforeRoot = 0x01000000ULL, 88 kIOTrackingBoot = 0x02000000ULL, 89 90 kIOLogExclaves = 0x100000000ULL, 91 92 _kIODebugTopFlag = 0x8000000000000000ULL// force enum to be 64 bits 93 }; 94 95 enum { 96 kIOKitDebugUserOptions = 0 97 | kIOLogAttach 98 | kIOLogProbe 99 | kIOLogStart 100 | kIOLogRegister 101 | kIOLogMatch 102 | kIOLogConfig 103 | kIOLogYield 104 | kIOLogPower 105 | kIOLogMapping 106 | kIOLogCatalogue 107 | kIOLogTracePower 108 | kIOLogDebugPower 109 | kOSLogRegistryMods 110 | kIOLogPMRootDomain 111 | kOSRegistryModsMode 112 | kIOLogHibernate 113 | kIOSleepWakeWdogOff 114 | kIOKextSpinDump 115 | kIOWaitQuietPanics 116 | kIOLogExclaves 117 }; 118 119 enum { 120 kIOTraceInterrupts = 0x00000001ULL, // Trace primary interrupts 121 kIOTraceWorkLoops = 0x00000002ULL, // Trace workloop activity 122 kIOTraceEventSources = 0x00000004ULL, // Trace non-passive event sources 123 kIOTraceIntEventSource = 0x00000008ULL, // Trace IOIES and IOFIES sources 124 kIOTraceCommandGates = 0x00000010ULL, // Trace command gate activity 125 kIOTraceTimers = 0x00000020ULL, // Trace timer event source activity 126 127 kIOTracePowerMgmt = 0x00000400ULL, // Trace power management changes 128 129 kIOTraceIOService = 0x00080000ULL, // registerService/termination 130 131 kIOTraceCompatBootArgs = kIOTraceIOService | kIOTracePowerMgmt 132 }; 133 134 enum { 135 kIODKEnable = 0x00000001ULL, 136 kIODKLogSetup = 0x00000002ULL, 137 kIODKLogIPC = 0x00000004ULL, 138 kIODKLogPM = 0x00000008ULL, 139 kIODKLogMessages = 0x00000010ULL, 140 141 kIODKDisablePM = 0x000000100ULL, 142 kIODKDisableDextLaunch = 0x00001000ULL, 143 kIODKDisableDextTag = 0x00002000ULL, 144 kIODKDisableCDHashChecking = 0x00004000ULL, 145 kIODKDisableEntitlementChecking = 0x00008000ULL, 146 kIODKDisableCheckInTokenVerification = 0x00010000ULL, 147 kIODKDisableIOPMSystemOffPhase2Allow = 0x00020000ULL, 148 }; 149 150 #if XNU_KERNEL_PRIVATE 151 152 #define DKLOG(fmt, args...) { IOLog("DK: " fmt, ## args); } 153 #define DKS "%s-0x%qx" 154 #define DKN(s) s ? s->getName() : "NO-NAME", s ? s->getRegistryEntryID() : UINT64_MAX 155 156 #ifdef IOKITDEBUG 157 #define DEBUG_INIT_VALUE IOKITDEBUG 158 #else 159 // Enable IOWaitQuiet panics except on KASAN. These panics can only 160 // be triggered by specially entitled entities granted the privilege 161 // to panic on a registry quiesce timeout. 162 #if KASAN 163 #define DEBUG_INIT_VALUE 0 164 #else /* !KASAN */ 165 #define DEBUG_INIT_VALUE kIOWaitQuietPanics 166 #endif /* KASAN */ 167 #endif 168 169 #endif /* XNU_KERNEL_PRIVATE */ 170 171 extern SInt64 gIOKitDebug; 172 extern SInt64 gIOKitTrace; 173 extern SInt64 gIODKDebug; 174 175 #ifdef __cplusplus 176 177 typedef kern_return_t (*IOCoreAnalyticsSendEventProc)( 178 uint64_t options, 179 OSString * eventName, 180 OSDictionary * eventPayload); 181 182 #if XNU_KERNEL_PRIVATE 183 extern IOCoreAnalyticsSendEventProc gIOCoreAnalyticsSendEventProc; 184 #endif /* XNU_KERNEL_PRIVATE */ 185 186 #endif /* __cplusplus */ 187 188 #ifdef __cplusplus 189 extern "C" { 190 #endif 191 192 #ifdef __cplusplus 193 class IORegistryPlane; 194 #endif 195 196 extern void IOPrintPlane( 197 #ifdef __cplusplus 198 const IORegistryPlane * plane 199 #else 200 const struct IORegistryPlane * plane 201 #endif 202 ); 203 #ifndef _OSCPPDEBUG_H 204 extern void OSPrintMemory( void ); 205 #endif 206 #define IOPrintMemory OSPrintMemory 207 208 #if defined(KERNEL) && defined(__cplusplus) 209 kern_return_t 210 IOSetCoreAnalyticsSendEventProc(IOCoreAnalyticsSendEventProc proc); 211 #endif /* defined(KERNEL) && defined(__cplusplus) */ 212 213 #define kIOKitDiagnosticsClientClassName "IOKitDiagnosticsClient" 214 215 enum{ 216 kIOKitDiagnosticsClientType = 0x99000002 217 }; 218 219 220 struct IOKitDiagnosticsParameters { 221 size_t size; 222 uint64_t value; 223 uint32_t options; 224 uint32_t tag; 225 uint32_t zsize; 226 uint32_t reserved[8]; 227 }; 228 typedef struct IOKitDiagnosticsParameters IOKitDiagnosticsParameters; 229 230 enum{ 231 kIOTrackingCallSiteBTs = 16, 232 }; 233 234 struct IOTrackingCallSiteInfo { 235 uint32_t count; 236 pid_t addressPID; 237 mach_vm_address_t address; 238 mach_vm_size_t size[2]; 239 pid_t btPID; 240 mach_vm_address_t bt[2][kIOTrackingCallSiteBTs]; 241 }; 242 243 #define kIOMallocTrackingName "IOMalloc" 244 #define kIOWireTrackingName "IOWire" 245 #define kIOMapTrackingName "IOMap" 246 247 #if XNU_KERNEL_PRIVATE && IOTRACKING 248 249 struct IOTrackingQueue; 250 struct IOTrackingCallSite; 251 252 struct IOTracking { 253 queue_chain_t link; 254 IOTrackingCallSite * site; 255 #if !defined(__LP64__) 256 uint32_t flags; 257 #endif 258 }; 259 260 struct IOTrackingAddress { 261 IOTracking tracking; 262 uintptr_t address; 263 size_t size; 264 #if defined(__LP64__) 265 uint32_t flags; 266 #endif 267 }; 268 269 struct IOTrackingUser { 270 queue_chain_t link; 271 pid_t btPID; 272 uint8_t user32; 273 uint8_t userCount; 274 uintptr_t bt[kIOTrackingCallSiteBTs]; 275 uintptr_t btUser[kIOTrackingCallSiteBTs]; 276 }; 277 278 enum{ 279 kIOTrackingQueueTypeDefaultOn = 0x00000001, 280 kIOTrackingQueueTypeAlloc = 0x00000002, 281 kIOTrackingQueueTypeMap = 0x00000004, 282 kIOTrackingQueueTypeUser = 0x00000008, 283 }; 284 285 286 void IOTrackingInit(void); 287 IOTrackingQueue * IOTrackingQueueAlloc(const char * name, uintptr_t btEntry, 288 size_t allocSize, size_t minCaptureSize, 289 uint32_t type, uint32_t numSiteQs); 290 void IOTrackingQueueFree(IOTrackingQueue * head); 291 void IOTrackingQueueCollectUser(IOTrackingQueue * queue); 292 void IOTrackingAdd(IOTrackingQueue * head, IOTracking * mem, size_t size, bool address, vm_tag_t tag); 293 void IOTrackingRemove(IOTrackingQueue * head, IOTracking * mem, size_t size); 294 void IOTrackingRemoveAddress(IOTrackingQueue * head, IOTrackingAddress * mem, size_t size); 295 void IOTrackingAddUser(IOTrackingQueue * queue, IOTrackingUser * mem, vm_size_t size); 296 void IOTrackingRemoveUser(IOTrackingQueue * head, IOTrackingUser * tracking); 297 298 void IOTrackingAlloc(IOTrackingQueue * head, uintptr_t address, size_t size); 299 void IOTrackingFree(IOTrackingQueue * head, uintptr_t address, size_t size); 300 void IOTrackingReset(IOTrackingQueue * head); 301 void IOTrackingAccumSize(IOTrackingQueue * head, IOTracking * mem, size_t size); 302 kern_return_t IOTrackingDebug(uint32_t selector, uint32_t options, 303 const char * names, size_t namesLen, 304 size_t size, OSObject ** result); 305 306 extern IOTrackingQueue * gIOMallocTracking; 307 extern IOTrackingQueue * gIOWireTracking; 308 extern IOTrackingQueue * gIOMapTracking; 309 310 #endif /* XNU_KERNEL_PRIVATE && IOTRACKING */ 311 312 enum{ 313 kIOTrackingLeakScanStart = 0x00000001, 314 kIOTrackingLeakScanEnd = 0x00000002, 315 }; 316 317 extern void (*gIOTrackingLeakScanCallback)(uint32_t notification); 318 319 enum{ 320 kIOTrackingExcludeNames = 0x00000001, 321 }; 322 323 enum{ 324 kIOTrackingGetTracking = 0x00000001, 325 kIOTrackingGetMappings = 0x00000002, 326 kIOTrackingResetTracking = 0x00000003, 327 kIOTrackingStartCapture = 0x00000004, 328 kIOTrackingStopCapture = 0x00000005, 329 kIOTrackingSetMinCaptureSize = 0x00000006, 330 kIOTrackingLeaks = 0x00000007, 331 kIOTrackingInvalid = 0xFFFFFFFE, 332 }; 333 334 335 #ifdef __cplusplus 336 } /* extern "C" */ 337 #endif /* __cplusplus */ 338 339 #endif /* ! _IOKIT_IOKITDEBUG_H */ 340