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 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 30 * 31 * HISTORY 32 * 33 */ 34 35 36 #ifndef _IOKIT_IOSERVICEPRIVATE_H 37 #define _IOKIT_IOSERVICEPRIVATE_H 38 39 // options for getExistingServices() 40 enum { 41 kIONotifyOnce = 0x00000001, 42 kIOServiceExistingSet = 0x00000002, 43 kIOServiceChangesOK = 0x00000004, 44 kIOServiceInternalDone = 0x00000008, 45 kIOServiceClassDone = 0x00000010, 46 }; 47 48 // masks for __state[1] 49 enum { 50 kIOServiceBusyStateMask = 0x000003ff, 51 kIOServiceBusyMax = 1023, 52 kIOServiceNeedConfigState = 0x80000000, 53 kIOServiceSynchronousState = 0x40000000, 54 kIOServiceModuleStallState = 0x20000000, 55 kIOServiceBusyWaiterState = 0x10000000, 56 57 kIOServiceSyncPubState = 0x08000000, 58 kIOServiceConfigState = 0x04000000, 59 kIOServiceStartState = 0x02000000, 60 kIOServiceTermPhase2State = 0x01000000, 61 kIOServiceTermPhase3State = 0x00800000, 62 kIOServiceTermPhase1State = 0x00400000, 63 kIOServiceTerm1WaiterState = 0x00200000, 64 kIOServiceRecursing = 0x00100000, 65 kIOServiceNeedWillTerminate = 0x00080000, 66 kIOServiceWaitDetachState = 0x00040000, 67 kIOServiceConfigRunning = 0x00020000, 68 kIOServiceFinalized = 0x00010000, 69 70 kIOServiceRematchOnDetach = 0x00008000, 71 kIOServiceUserUnhidden = 0x00004000, 72 kIOServiceTermPhase2ReadyState = 0x00002000, 73 // kIOServiceX3 = 0x00001000, 74 // kIOServiceX4 = 0x00000800, 75 // kIOServiceX5 = 0x00000400, 76 }; 77 78 extern const OSSymbol * gIOServiceNotificationUserKey; 79 80 81 // notify state 82 enum { 83 kIOServiceNotifyEnable = 0x00000001, 84 kIOServiceNotifyWaiter = 0x00000002, 85 kIOServiceNotifyBlock = 0x00000004 86 }; 87 88 struct _IOServiceNotifierInvocation { 89 IOThread thread; 90 queue_chain_t link; 91 }; 92 93 class _IOServiceNotifier : public IONotifier 94 { 95 friend class IOService; 96 97 OSDeclareDefaultStructors(_IOServiceNotifier); 98 99 public: 100 OSOrderedSet * whence; 101 102 OSDictionary * matching; 103 const OSSymbol * type; 104 IOServiceMatchingNotificationHandler handler; 105 IOServiceNotificationHandler compatHandler; 106 void * target; 107 void * ref; 108 SInt32 priority; 109 queue_head_t handlerInvocations; 110 IOOptionBits state; 111 112 virtual void free() APPLE_KEXT_OVERRIDE; 113 virtual void remove() APPLE_KEXT_OVERRIDE; 114 virtual bool disable() APPLE_KEXT_OVERRIDE; 115 virtual void enable( bool was ) APPLE_KEXT_OVERRIDE; 116 virtual void wait(); 117 }; 118 119 class _IOServiceInterestNotifier : public IONotifier 120 { 121 friend class IOService; 122 123 OSDeclareDefaultStructors(_IOServiceInterestNotifier); 124 125 public: 126 queue_chain_t chain; 127 128 IOServiceInterestHandler handler; 129 void * target; 130 void * ref; 131 queue_head_t handlerInvocations; 132 IOOptionBits state; 133 134 virtual void free() APPLE_KEXT_OVERRIDE; 135 virtual void remove() APPLE_KEXT_OVERRIDE; 136 virtual bool disable() APPLE_KEXT_OVERRIDE; 137 virtual void enable( bool was ) APPLE_KEXT_OVERRIDE; 138 virtual void wait(); 139 virtual bool init() APPLE_KEXT_OVERRIDE; 140 }; 141 142 class _IOServiceNullNotifier : public IONotifier 143 { 144 OSDeclareDefaultStructors(_IOServiceNullNotifier); 145 146 public: 147 virtual void taggedRetain(const void *tag) const APPLE_KEXT_OVERRIDE; 148 virtual void taggedRelease(const void *tag, const int when) const APPLE_KEXT_OVERRIDE; 149 virtual void free() APPLE_KEXT_OVERRIDE; 150 virtual void remove() APPLE_KEXT_OVERRIDE; 151 virtual bool disable() APPLE_KEXT_OVERRIDE; 152 virtual void enable( bool was ) APPLE_KEXT_OVERRIDE; 153 virtual void wait(); 154 }; 155 156 class _IOConfigThread : public OSObject 157 { 158 friend class IOService; 159 160 OSDeclareDefaultStructors(_IOConfigThread); 161 162 public: 163 static void configThread( const char * name ); 164 static void main( void * arg, wait_result_t result ); 165 }; 166 167 enum { 168 kMaxConfigThreads = CONFIG_MAX_THREADS, 169 }; 170 171 enum { 172 kMatchNubJob = 10, 173 }; 174 175 class _IOServiceJob : public OSObject 176 { 177 friend class IOService; 178 179 OSDeclareDefaultStructors(_IOServiceJob); 180 181 public: 182 int type; 183 IOService * nub; 184 IOOptionBits options; 185 186 static LIBKERN_RETURNS_NOT_RETAINED _IOServiceJob * startJob( IOService * nub, int type, 187 IOOptionBits options = 0 ); 188 static void pingConfig( LIBKERN_CONSUMED class _IOServiceJob * job ); 189 }; 190 191 class IOResources : public IOService 192 { 193 friend class IOService; 194 195 OSDeclareDefaultStructors(IOResources); 196 197 public: 198 static IOService * resources( void ); 199 virtual bool init( OSDictionary * dictionary = NULL ) APPLE_KEXT_OVERRIDE; 200 virtual IOReturn newUserClient(task_t owningTask, void * securityID, 201 UInt32 type, OSDictionary * properties, 202 IOUserClient ** handler) APPLE_KEXT_OVERRIDE; 203 virtual IOWorkLoop * getWorkLoop() const APPLE_KEXT_OVERRIDE; 204 virtual bool matchPropertyTable( OSDictionary * table ) APPLE_KEXT_OVERRIDE; 205 virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE; 206 }; 207 208 class IOUserResources : public IOService 209 { 210 friend class IOService; 211 212 OSDeclareDefaultStructors(IOUserResources); 213 214 public: 215 static IOService * resources( void ); 216 virtual bool init( OSDictionary * dictionary = NULL ) APPLE_KEXT_OVERRIDE; 217 virtual IOReturn newUserClient(task_t owningTask, void * securityID, 218 UInt32 type, OSDictionary * properties, 219 IOUserClient ** handler) APPLE_KEXT_OVERRIDE; 220 virtual IOWorkLoop * getWorkLoop() const APPLE_KEXT_OVERRIDE; 221 virtual bool matchPropertyTable( OSDictionary * table ) APPLE_KEXT_OVERRIDE; 222 virtual IOReturn powerStateWillChangeTo(IOPMPowerFlags flags, unsigned long state, IOService * service) APPLE_KEXT_OVERRIDE; 223 }; 224 225 class _IOOpenServiceIterator : public OSIterator 226 { 227 friend class IOService; 228 229 OSDeclareDefaultStructors(_IOOpenServiceIterator); 230 231 OSIterator * iter; 232 const IOService * client; 233 const IOService * provider; 234 IOService * last; 235 236 public: 237 static OSIterator * iterator(LIBKERN_CONSUMED OSIterator * _iter, 238 const IOService * client, 239 const IOService * provider ); 240 virtual void free() APPLE_KEXT_OVERRIDE; 241 virtual void reset() APPLE_KEXT_OVERRIDE; 242 virtual bool isValid() APPLE_KEXT_OVERRIDE; 243 virtual OSObject * getNextObject() APPLE_KEXT_OVERRIDE; 244 }; 245 246 class IOExclaveProxy : public IOService 247 { 248 OSDeclareDefaultStructors(IOExclaveProxy); 249 250 IOExclaveProxyState * exclaveState; 251 252 bool start(IOService * provider) APPLE_KEXT_OVERRIDE; 253 }; 254 255 class _IOServiceStateNotification : public IOService 256 { 257 friend class IOService; 258 259 IOLock * fLock; 260 OSDictionary * fItems; 261 262 OSDeclareDefaultStructors(_IOServiceStateNotification); 263 264 public: 265 }; 266 267 268 269 extern const OSSymbol * gIOConsoleUsersKey; 270 extern const OSSymbol * gIOConsoleSessionUIDKey; 271 extern const OSSymbol * gIOConsoleSessionAuditIDKey; 272 extern const OSSymbol * gIOConsoleSessionOnConsoleKey; 273 extern const OSSymbol * gIOConsoleSessionSecureInputPIDKey; 274 275 extern "C" bool 276 IOSystemStateAOT(void); 277 278 enum { 279 kIOServiceSystemStateOffPhase1 = (1U << 4) | 1, 280 kIOServiceSystemStateOffPhase2 = (1U << 4) | 2, 281 kIOServiceSystemStateAOT = (2U << 4), 282 kIOServiceSystemStateOn = (3U << 4) 283 #define IsIOServiceSystemStateOff(state) ((state) < kIOServiceSystemStateAOT) 284 }; 285 286 #endif /* ! _IOKIT_IOSERVICEPRIVATE_H */ 287