Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | /* * Copyright (c) 1998-2016 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * Changes to this API are expected. */ #ifndef _IOKIT_IOUSERCLIENT_H #define _IOKIT_IOUSERCLIENT_H #include <IOKit/IOTypes.h> #include <IOKit/IOService.h> #include <IOKit/OSMessageNotification.h> #if IOKITSTATS #include <IOKit/IOStatisticsPrivate.h> #endif #define _IOUSERCLIENT_SENDASYNCRESULT64WITHOPTIONS_ 1 enum { kIOUCTypeMask = 0x0000000f, kIOUCScalarIScalarO = 0, kIOUCScalarIStructO = 2, kIOUCStructIStructO = 3, kIOUCScalarIStructI = 4, kIOUCForegroundOnly = 0x00000010, }; /*! @enum @abstract Constant to denote a variable length structure argument to IOUserClient. @constant kIOUCVariableStructureSize Use in the structures IOExternalMethod, IOExternalAsyncMethod, IOExternalMethodDispatch to specify the size of the structure is variable. */ enum { kIOUCVariableStructureSize = 0xffffffff }; typedef IOReturn (IOService::*IOMethod)(void * p1, void * p2, void * p3, void * p4, void * p5, void * p6 ); typedef IOReturn (IOService::*IOAsyncMethod)(OSAsyncReference asyncRef, void * p1, void * p2, void * p3, void * p4, void * p5, void * p6 ); typedef IOReturn (IOService::*IOTrap)(void * p1, void * p2, void * p3, void * p4, void * p5, void * p6 ); struct IOExternalMethod { IOService * object; IOMethod func; IOOptionBits flags; IOByteCount count0; IOByteCount count1; }; struct IOExternalAsyncMethod { IOService * object; IOAsyncMethod func; IOOptionBits flags; IOByteCount count0; IOByteCount count1; }; struct IOExternalTrap { IOService * object; IOTrap func; }; enum { kIOUserNotifyMaxMessageSize = 64 }; enum { kIOUserNotifyOptionCanDrop = 0x1 /* Fail if queue is full, rather than infinitely queuing. */ }; // keys for clientHasPrivilege #define kIOClientPrivilegeAdministrator "root" #define kIOClientPrivilegeLocalUser "local" #define kIOClientPrivilegeForeground "foreground" /*! @enum @abstract Constants to specify the maximum number of scalar arguments in the IOExternalMethodArguments structure. These constants are documentary since the scalarInputCount, scalarOutputCount fields reflect the actual number passed. @constant kIOExternalMethodScalarInputCountMax The maximum number of scalars able to passed on input. @constant kIOExternalMethodScalarOutputCountMax The maximum number of scalars able to passed on output. */ enum { kIOExternalMethodScalarInputCountMax = 16, kIOExternalMethodScalarOutputCountMax = 16, }; struct IOExternalMethodArguments { uint32_t version; uint32_t selector; mach_port_t asyncWakePort; io_user_reference_t * asyncReference; uint32_t asyncReferenceCount; const uint64_t * scalarInput; uint32_t scalarInputCount; const void * structureInput; uint32_t structureInputSize; IOMemoryDescriptor * structureInputDescriptor; uint64_t * scalarOutput; uint32_t scalarOutputCount; void * structureOutput; uint32_t structureOutputSize; IOMemoryDescriptor * structureOutputDescriptor; uint32_t structureOutputDescriptorSize; uint32_t __reservedA; OSObject ** structureVariableOutputData; uint32_t __reserved[30]; }; typedef IOReturn (*IOExternalMethodAction)(OSObject * target, void * reference, IOExternalMethodArguments * arguments); struct IOExternalMethodDispatch { IOExternalMethodAction function; uint32_t checkScalarInputCount; uint32_t checkStructureInputSize; uint32_t checkScalarOutputCount; uint32_t checkStructureOutputSize; }; enum { #define IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION 2 kIOExternalMethodArgumentsCurrentVersion = IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION }; /*! @class IOUserClient @abstract Provides a basis for communication between client applications and I/O Kit objects. */ class IOUserClient : public IOService { OSDeclareAbstractStructors(IOUserClient) #if IOKITSTATS friend class IOStatistics; #endif protected: /*! @struct ExpansionData @discussion This structure will be used to expand the capablilties of this class in the future. */ struct ExpansionData { #if IOKITSTATS IOUserClientCounter *counter; #else void *iokitstatsReserved; #endif }; /*! @var reserved Reserved for future use. (Internal use only) */ APPLE_KEXT_WSHADOW_PUSH; ExpansionData * reserved; APPLE_KEXT_WSHADOW_POP; bool reserve(); #ifdef XNU_KERNEL_PRIVATE public: OSSet * mappings; UInt8 sharedInstance; UInt8 closed; UInt8 __ipcFinal; UInt8 __reservedA[1]; volatile SInt32 __ipc; queue_head_t owners; IOLock * lock; #if __LP64__ void * __reserved[4]; #else void * __reserved[3]; #endif #else /* XNU_KERNEL_PRIVATE */ private: void * __reserved[9]; #endif /* XNU_KERNEL_PRIVATE */ public: virtual IOReturn externalMethod( uint32_t selector, IOExternalMethodArguments * arguments, IOExternalMethodDispatch * dispatch = 0, OSObject * target = 0, void * reference = 0 ); virtual IOReturn registerNotificationPort( mach_port_t port, UInt32 type, io_user_reference_t refCon); private: #if __LP64__ OSMetaClassDeclareReservedUnused(IOUserClient, 0); OSMetaClassDeclareReservedUnused(IOUserClient, 1); #else OSMetaClassDeclareReservedUsed(IOUserClient, 0); OSMetaClassDeclareReservedUsed(IOUserClient, 1); #endif OSMetaClassDeclareReservedUnused(IOUserClient, 2); OSMetaClassDeclareReservedUnused(IOUserClient, 3); OSMetaClassDeclareReservedUnused(IOUserClient, 4); OSMetaClassDeclareReservedUnused(IOUserClient, 5); OSMetaClassDeclareReservedUnused(IOUserClient, 6); OSMetaClassDeclareReservedUnused(IOUserClient, 7); OSMetaClassDeclareReservedUnused(IOUserClient, 8); OSMetaClassDeclareReservedUnused(IOUserClient, 9); OSMetaClassDeclareReservedUnused(IOUserClient, 10); OSMetaClassDeclareReservedUnused(IOUserClient, 11); OSMetaClassDeclareReservedUnused(IOUserClient, 12); OSMetaClassDeclareReservedUnused(IOUserClient, 13); OSMetaClassDeclareReservedUnused(IOUserClient, 14); OSMetaClassDeclareReservedUnused(IOUserClient, 15); #ifdef XNU_KERNEL_PRIVATE /* Available within xnu source only */ public: static void initialize( void ); static void destroyUserReferences( OSObject * obj ); static bool finalizeUserReferences( OSObject * obj ); IOMemoryMap * mapClientMemory64( IOOptionBits type, task_t task, IOOptionBits mapFlags = kIOMapAnywhere, mach_vm_address_t atAddress = 0 ); IOReturn registerOwner(task_t task); void noMoreSenders(void); #endif /* XNU_KERNEL_PRIVATE */ protected: static IOReturn sendAsyncResult(OSAsyncReference reference, IOReturn result, void *args[], UInt32 numArgs); static void setAsyncReference(OSAsyncReference asyncRef, mach_port_t wakePort, void *callback, void *refcon); static IOReturn sendAsyncResult64(OSAsyncReference64 reference, IOReturn result, io_user_reference_t args[], UInt32 numArgs); /*! @function sendAsyncResult64WithOptions @abstract Send a notification as with sendAsyncResult, but with finite queueing. @discussion IOUserClient::sendAsyncResult64() will infitely queue messages if the client is not processing them in a timely fashion. This variant will not, for simple handling of situations where clients may be expected to stop processing messages. */ static IOReturn sendAsyncResult64WithOptions(OSAsyncReference64 reference, IOReturn result, io_user_reference_t args[], UInt32 numArgs, IOOptionBits options); static void setAsyncReference64(OSAsyncReference64 asyncRef, mach_port_t wakePort, mach_vm_address_t callback, io_user_reference_t refcon); static void setAsyncReference64(OSAsyncReference64 asyncRef, mach_port_t wakePort, mach_vm_address_t callback, io_user_reference_t refcon, task_t task); public: static IOReturn clientHasAuthorization( task_t task, IOService * service ); static IOReturn clientHasPrivilege( void * securityToken, const char * privilegeName ); static OSObject * copyClientEntitlement( task_t task, const char * entitlement ); /*! @function releaseAsyncReference64 @abstract Release the mach_port_t reference held within the OSAsyncReference64 structure. @discussion The OSAsyncReference64 structure passed to async methods holds a reference to the wakeup mach port, which should be released to balance each async method call. Behavior is undefined if these calls are not correctly balanced. @param reference The reference passed to the subclass IOAsyncMethod, or externalMethod() in the IOExternalMethodArguments.asyncReference field. @result A return code. */ static IOReturn releaseAsyncReference64(OSAsyncReference64 reference); /*! @function releaseNotificationPort @abstract Release the mach_port_t passed to registerNotificationPort(). @discussion The mach_port_t passed to the registerNotificationPort() methods should be released to balance each call to registerNotificationPort(). Behavior is undefined if these calls are not correctly balanced. @param port The mach_port_t argument previously passed to the subclass implementation of registerNotificationPort(). @result A return code. */ static IOReturn releaseNotificationPort(mach_port_t port); virtual bool init() APPLE_KEXT_OVERRIDE; virtual bool init( OSDictionary * dictionary ) APPLE_KEXT_OVERRIDE; // Currently ignores the all args, just passes up to IOService::init() virtual bool initWithTask( task_t owningTask, void * securityToken, UInt32 type, OSDictionary * properties); virtual bool initWithTask( task_t owningTask, void * securityToken, UInt32 type); virtual void free() APPLE_KEXT_OVERRIDE; virtual IOReturn clientClose( void ); virtual IOReturn clientDied( void ); virtual IOService * getService( void ); virtual IOReturn registerNotificationPort( mach_port_t port, UInt32 type, UInt32 refCon ); virtual IOReturn getNotificationSemaphore( UInt32 notification_type, semaphore_t * semaphore ); virtual IOReturn connectClient( IOUserClient * client ); // memory will be released by user client when last map is destroyed virtual IOReturn clientMemoryForType( UInt32 type, IOOptionBits * options, IOMemoryDescriptor ** memory ); #if !__LP64__ private: APPLE_KEXT_COMPATIBILITY_VIRTUAL IOMemoryMap * mapClientMemory( IOOptionBits type, task_t task, IOOptionBits mapFlags = kIOMapAnywhere, IOVirtualAddress atAddress = 0 ); #endif static IOReturn _sendAsyncResult64(OSAsyncReference64 reference, IOReturn result, io_user_reference_t args[], UInt32 numArgs, IOOptionBits options); public: /*! @function removeMappingForDescriptor Remove the first mapping created from the memory descriptor returned by clientMemoryForType() from IOUserClient's list of mappings. If such a mapping exists, it is retained and the reference currently held by IOUserClient is returned to the caller. @param memory The memory descriptor instance previously returned by the implementation of clientMemoryForType(). @result A reference to the first IOMemoryMap instance found in the list of mappings created by IOUserClient from that passed memory descriptor is returned, or zero if none exist. The caller should release this reference. */ IOMemoryMap * removeMappingForDescriptor(IOMemoryDescriptor * memory); /*! @function exportObjectToClient Make an arbitrary OSObject available to the client task. @param task The task. @param obj The object we want to export to the client. @param clientObj Returned value is the client's port name. */ virtual IOReturn exportObjectToClient(task_t task, OSObject *obj, io_object_t *clientObj); #if KERNEL_PRIVATE /*! @function copyPortNameForObjectInTask Make an arbitrary OSObject available to the client task as a port name. The port does not respond to any IOKit IPC calls. @param task The task. @param object The object we want to export to the client. The port holds a reference on the object, this function does not consume any reference on the object. @param port_name Returned value is the task's port name. It has one send right created by this function. @result A return code. */ static IOReturn copyPortNameForObjectInTask(task_t task, OSObject *object, mach_port_name_t * port_name); /*! @function copyObjectForPortNameInTask Look up an OSObject given a task's port name created with copyPortNameForObjectInTask(). @param task The task. @param port_name The task's port name. This function does not consume any reference on the port name. @param object If the port name is valid, a reference to the object is returned. It should be released by the caller. @result A return code. */ static IOReturn copyObjectForPortNameInTask(task_t task, mach_port_name_t port_name, OSObject **object); /*! @function adjustPortNameReferencesInTask Adjust the send rights for a port name created with copyPortNameForObjectInTask(). @param task The task. @param port_name The task's port name. @param delta Signed value change to the number of user references. @result A return code. */ static IOReturn adjustPortNameReferencesInTask(task_t task, mach_port_name_t port_name, mach_port_delta_t delta); #define IOUC_COPYPORTNAMEFOROBJECTINTASK 1 #endif /* KERNEL_PRIVATE */ // Old methods for accessing method vector backward compatiblility only virtual IOExternalMethod * getExternalMethodForIndex( UInt32 index ) APPLE_KEXT_DEPRECATED; virtual IOExternalAsyncMethod * getExternalAsyncMethodForIndex( UInt32 index ) APPLE_KEXT_DEPRECATED; // Methods for accessing method vector. virtual IOExternalMethod * getTargetAndMethodForIndex( IOService ** targetP, UInt32 index ); virtual IOExternalAsyncMethod * getAsyncTargetAndMethodForIndex( IOService ** targetP, UInt32 index ); // Methods for accessing trap vector - old and new style virtual IOExternalTrap * getExternalTrapForIndex( UInt32 index ) APPLE_KEXT_DEPRECATED; virtual IOExternalTrap * getTargetAndTrapForIndex( IOService **targetP, UInt32 index ); }; #endif /* ! _IOKIT_IOUSERCLIENT_H */ |