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
41class IOKitDiagnostics : public OSObject
42{
43 OSDeclareDefaultStructors(IOKitDiagnostics);
44
45public:
46 static OSObject * diagnostics( void );
47 virtual bool serialize(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
48private:
49 static void updateOffset( OSDictionary * dict,
50 UInt64 value, const char * name );
51};
52
53#endif /* __cplusplus */
54
55enum {
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
95enum {
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};
117
118enum {
119 kIOTraceInterrupts = 0x00000001ULL, // Trace primary interrupts
120 kIOTraceWorkLoops = 0x00000002ULL, // Trace workloop activity
121 kIOTraceEventSources = 0x00000004ULL, // Trace non-passive event sources
122 kIOTraceIntEventSource = 0x00000008ULL, // Trace IOIES and IOFIES sources
123 kIOTraceCommandGates = 0x00000010ULL, // Trace command gate activity
124 kIOTraceTimers = 0x00000020ULL, // Trace timer event source activity
125
126 kIOTracePowerMgmt = 0x00000400ULL, // Trace power management changes
127
128 kIOTraceIOService = 0x00080000ULL, // registerService/termination
129
130 kIOTraceCompatBootArgs = kIOTraceIOService | kIOTracePowerMgmt
131};
132
133enum {
134 kIODKEnable = 0x00000001ULL,
135 kIODKLogSetup = 0x00000002ULL,
136 kIODKLogIPC = 0x00000004ULL,
137 kIODKLogPM = 0x00000008ULL,
138 kIODKLogMessages = 0x00000010ULL,
139
140 kIODKDisablePM = 0x000000100ULL,
141 kIODKDisableDextLaunch = 0x00001000ULL,
142 kIODKDisableDextTag = 0x00002000ULL,
143 kIODKDisableCDHashChecking = 0x00004000ULL,
144 kIODKDisableEntitlementChecking = 0x00008000ULL,
145 kIODKDisableCheckInTokenVerification = 0x00010000ULL,
146};
147
148#if XNU_KERNEL_PRIVATE
149
150#define DKLOG(fmt, args...) { IOLog("DK: " fmt, ## args); }
151#define DKS "%s-0x%qx"
152#define DKN(s) s->getName(), s->getRegistryEntryID()
153
154#ifdef IOKITDEBUG
155#define DEBUG_INIT_VALUE IOKITDEBUG
156#else
157// Enable IOWaitQuiet panics except on KASAN. These panics can only
158// be triggered by specially entitled entities granted the privilege
159// to panic on a registry quiesce timeout.
160#if KASAN
161#define DEBUG_INIT_VALUE 0
162#else /* !KASAN */
163#define DEBUG_INIT_VALUE kIOWaitQuietPanics
164#endif /* KASAN */
165#endif
166
167#endif /* XNU_KERNEL_PRIVATE */
168
169extern SInt64 gIOKitDebug;
170extern SInt64 gIOKitTrace;
171extern SInt64 gIODKDebug;
172
173#ifdef __cplusplus
174
175typedef kern_return_t (*IOCoreAnalyticsSendEventProc)(
176 uint64_t options,
177 OSString * eventName,
178 OSDictionary * eventPayload);
179
180#if XNU_KERNEL_PRIVATE
181extern IOCoreAnalyticsSendEventProc gIOCoreAnalyticsSendEventProc;
182#endif /* XNU_KERNEL_PRIVATE */
183
184#endif /* __cplusplus */
185
186#ifdef __cplusplus
187extern "C" {
188#endif
189
190#ifdef __cplusplus
191class IORegistryPlane;
192#endif
193
194extern void IOPrintPlane(
195#ifdef __cplusplus
196 const IORegistryPlane * plane
197#else
198 const struct IORegistryPlane * plane
199#endif
200 );
201#ifndef _OSCPPDEBUG_H
202extern void OSPrintMemory( void );
203#endif
204#define IOPrintMemory OSPrintMemory
205
206#if defined(KERNEL) && defined(__cplusplus)
207kern_return_t
208IOSetCoreAnalyticsSendEventProc(IOCoreAnalyticsSendEventProc proc);
209#endif /* defined(KERNEL) && defined(__cplusplus) */
210
211#define kIOKitDiagnosticsClientClassName "IOKitDiagnosticsClient"
212
213enum{
214 kIOKitDiagnosticsClientType = 0x99000002
215};
216
217
218struct IOKitDiagnosticsParameters {
219 size_t size;
220 uint64_t value;
221 uint32_t options;
222 uint32_t tag;
223 uint32_t zsize;
224 uint32_t reserved[8];
225};
226typedef struct IOKitDiagnosticsParameters IOKitDiagnosticsParameters;
227
228enum{
229 kIOTrackingCallSiteBTs = 16,
230};
231
232struct IOTrackingCallSiteInfo {
233 uint32_t count;
234 pid_t addressPID;
235 mach_vm_address_t address;
236 mach_vm_size_t size[2];
237 pid_t btPID;
238 mach_vm_address_t bt[2][kIOTrackingCallSiteBTs];
239};
240
241#define kIOMallocTrackingName "IOMalloc"
242#define kIOWireTrackingName "IOWire"
243#define kIOMapTrackingName "IOMap"
244
245#if XNU_KERNEL_PRIVATE && IOTRACKING
246
247struct IOTrackingQueue;
248struct IOTrackingCallSite;
249
250struct IOTracking {
251 queue_chain_t link;
252 IOTrackingCallSite * site;
253#if !defined(__LP64__)
254 uint32_t flags;
255#endif
256};
257
258struct IOTrackingAddress {
259 IOTracking tracking;
260 uintptr_t address;
261 size_t size;
262#if defined(__LP64__)
263 uint32_t flags;
264#endif
265};
266
267struct IOTrackingUser {
268 queue_chain_t link;
269 pid_t btPID;
270 uint8_t user32;
271 uint8_t userCount;
272 uintptr_t bt[kIOTrackingCallSiteBTs];
273 uintptr_t btUser[kIOTrackingCallSiteBTs];
274};
275
276enum{
277 kIOTrackingQueueTypeDefaultOn = 0x00000001,
278 kIOTrackingQueueTypeAlloc = 0x00000002,
279 kIOTrackingQueueTypeMap = 0x00000004,
280 kIOTrackingQueueTypeUser = 0x00000008,
281};
282
283
284void IOTrackingInit(void);
285IOTrackingQueue * IOTrackingQueueAlloc(const char * name, uintptr_t btEntry,
286 size_t allocSize, size_t minCaptureSize,
287 uint32_t type, uint32_t numSiteQs);
288void IOTrackingQueueFree(IOTrackingQueue * head);
289void IOTrackingQueueCollectUser(IOTrackingQueue * queue);
290void IOTrackingAdd(IOTrackingQueue * head, IOTracking * mem, size_t size, bool address, vm_tag_t tag);
291void IOTrackingRemove(IOTrackingQueue * head, IOTracking * mem, size_t size);
292void IOTrackingRemoveAddress(IOTrackingQueue * head, IOTrackingAddress * mem, size_t size);
293void IOTrackingAddUser(IOTrackingQueue * queue, IOTrackingUser * mem, vm_size_t size);
294void IOTrackingRemoveUser(IOTrackingQueue * head, IOTrackingUser * tracking);
295
296void IOTrackingAlloc(IOTrackingQueue * head, uintptr_t address, size_t size);
297void IOTrackingFree(IOTrackingQueue * head, uintptr_t address, size_t size);
298void IOTrackingReset(IOTrackingQueue * head);
299void IOTrackingAccumSize(IOTrackingQueue * head, IOTracking * mem, size_t size);
300kern_return_t IOTrackingDebug(uint32_t selector, uint32_t options,
301 const char * names, size_t namesLen,
302 size_t size, OSObject ** result);
303
304extern IOTrackingQueue * gIOMallocTracking;
305extern IOTrackingQueue * gIOWireTracking;
306extern IOTrackingQueue * gIOMapTracking;
307
308#endif /* XNU_KERNEL_PRIVATE && IOTRACKING */
309
310enum{
311 kIOTrackingLeakScanStart = 0x00000001,
312 kIOTrackingLeakScanEnd = 0x00000002,
313};
314
315extern void (*gIOTrackingLeakScanCallback)(uint32_t notification);
316
317enum{
318 kIOTrackingExcludeNames = 0x00000001,
319};
320
321enum{
322 kIOTrackingGetTracking = 0x00000001,
323 kIOTrackingGetMappings = 0x00000002,
324 kIOTrackingResetTracking = 0x00000003,
325 kIOTrackingStartCapture = 0x00000004,
326 kIOTrackingStopCapture = 0x00000005,
327 kIOTrackingSetMinCaptureSize = 0x00000006,
328 kIOTrackingLeaks = 0x00000007,
329 kIOTrackingInvalid = 0xFFFFFFFE,
330};
331
332
333#ifdef __cplusplus
334} /* extern "C" */
335#endif /* __cplusplus */
336
337#endif /* ! _IOKIT_IOKITDEBUG_H */
338