2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * Changes to this API are expected.
33 #ifndef _IOKIT_IOUSERCLIENT_H
34 #define _IOKIT_IOUSERCLIENT_H
36 #include <IOKit/IOTypes.h>
37 #include <IOKit/IOService.h>
38 #include <IOKit/OSMessageNotification.h>
41 #include <IOKit/IOStatisticsPrivate.h>
45 kIOUCTypeMask
= 0x0000000f,
46 kIOUCScalarIScalarO
= 0,
47 kIOUCScalarIStructO
= 2,
48 kIOUCStructIStructO
= 3,
49 kIOUCScalarIStructI
= 4,
51 kIOUCForegroundOnly
= 0x00000010,
55 @abstract Constant to denote a variable length structure argument to IOUserClient.
56 @constant kIOUCVariableStructureSize Use in the structures IOExternalMethod, IOExternalAsyncMethod, IOExternalMethodDispatch to specify the size of the structure is variable.
59 kIOUCVariableStructureSize
= 0xffffffff
63 typedef IOReturn (IOService::*IOMethod
)(void * p1
, void * p2
, void * p3
,
64 void * p4
, void * p5
, void * p6
);
66 typedef IOReturn (IOService::*IOAsyncMethod
)(OSAsyncReference asyncRef
,
67 void * p1
, void * p2
, void * p3
,
68 void * p4
, void * p5
, void * p6
);
70 typedef IOReturn (IOService::*IOTrap
)(void * p1
, void * p2
, void * p3
,
71 void * p4
, void * p5
, void * p6
);
73 struct IOExternalMethod
{
81 struct IOExternalAsyncMethod
{
89 struct IOExternalTrap
{
95 kIOUserNotifyMaxMessageSize
= 64
98 // keys for clientHasPrivilege
99 #define kIOClientPrivilegeAdministrator "root"
100 #define kIOClientPrivilegeLocalUser "local"
101 #define kIOClientPrivilegeForeground "foreground"
104 @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.
105 @constant kIOExternalMethodScalarInputCountMax The maximum number of scalars able to passed on input.
106 @constant kIOExternalMethodScalarOutputCountMax The maximum number of scalars able to passed on output.
109 kIOExternalMethodScalarInputCountMax
= 16,
110 kIOExternalMethodScalarOutputCountMax
= 16,
114 struct IOExternalMethodArguments
120 mach_port_t asyncWakePort
;
121 io_user_reference_t
* asyncReference
;
122 uint32_t asyncReferenceCount
;
124 const uint64_t * scalarInput
;
125 uint32_t scalarInputCount
;
127 const void * structureInput
;
128 uint32_t structureInputSize
;
130 IOMemoryDescriptor
* structureInputDescriptor
;
132 uint64_t * scalarOutput
;
133 uint32_t scalarOutputCount
;
135 void * structureOutput
;
136 uint32_t structureOutputSize
;
138 IOMemoryDescriptor
* structureOutputDescriptor
;
139 uint32_t structureOutputDescriptorSize
;
141 uint32_t __reserved
[32];
144 typedef IOReturn (*IOExternalMethodAction
)(OSObject
* target
, void * reference
,
145 IOExternalMethodArguments
* arguments
);
146 struct IOExternalMethodDispatch
148 IOExternalMethodAction function
;
149 uint32_t checkScalarInputCount
;
150 uint32_t checkStructureInputSize
;
151 uint32_t checkScalarOutputCount
;
152 uint32_t checkStructureOutputSize
;
156 #define IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION 1
157 kIOExternalMethodArgumentsCurrentVersion
= IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION
163 @abstract Provides a basis for communication between client applications and I/O Kit objects.
167 class IOUserClient
: public IOService
169 OSDeclareAbstractStructors(IOUserClient
)
171 friend class IOStatistics
;
175 /*! @struct ExpansionData
176 @discussion This structure will be used to expand the capablilties of this class in the future.
178 struct ExpansionData
{
180 IOUserClientCounter
*counter
;
182 void *iokitstatsReserved
;
187 Reserved for future use. (Internal use only)
189 ExpansionData
* reserved
;
193 #ifdef XNU_KERNEL_PRIVATE
199 UInt8 sharedInstance
;
200 UInt8 __reservedA
[3];
201 void * __reserved
[7];
204 virtual IOReturn
externalMethod( uint32_t selector
, IOExternalMethodArguments
* arguments
,
205 IOExternalMethodDispatch
* dispatch
= 0, OSObject
* target
= 0, void * reference
= 0 );
207 virtual IOReturn
registerNotificationPort(
208 mach_port_t port
, UInt32 type
, io_user_reference_t refCon
);
212 OSMetaClassDeclareReservedUnused(IOUserClient
, 0);
213 OSMetaClassDeclareReservedUnused(IOUserClient
, 1);
215 OSMetaClassDeclareReservedUsed(IOUserClient
, 0);
216 OSMetaClassDeclareReservedUsed(IOUserClient
, 1);
218 OSMetaClassDeclareReservedUnused(IOUserClient
, 2);
219 OSMetaClassDeclareReservedUnused(IOUserClient
, 3);
220 OSMetaClassDeclareReservedUnused(IOUserClient
, 4);
221 OSMetaClassDeclareReservedUnused(IOUserClient
, 5);
222 OSMetaClassDeclareReservedUnused(IOUserClient
, 6);
223 OSMetaClassDeclareReservedUnused(IOUserClient
, 7);
224 OSMetaClassDeclareReservedUnused(IOUserClient
, 8);
225 OSMetaClassDeclareReservedUnused(IOUserClient
, 9);
226 OSMetaClassDeclareReservedUnused(IOUserClient
, 10);
227 OSMetaClassDeclareReservedUnused(IOUserClient
, 11);
228 OSMetaClassDeclareReservedUnused(IOUserClient
, 12);
229 OSMetaClassDeclareReservedUnused(IOUserClient
, 13);
230 OSMetaClassDeclareReservedUnused(IOUserClient
, 14);
231 OSMetaClassDeclareReservedUnused(IOUserClient
, 15);
233 #ifdef XNU_KERNEL_PRIVATE
234 /* Available within xnu source only */
236 static void initialize( void );
237 static void destroyUserReferences( OSObject
* obj
);
238 IOMemoryMap
* mapClientMemory64( IOOptionBits type
,
240 IOOptionBits mapFlags
= kIOMapAnywhere
,
241 mach_vm_address_t atAddress
= 0 );
245 static IOReturn
sendAsyncResult(OSAsyncReference reference
,
246 IOReturn result
, void *args
[], UInt32 numArgs
);
247 static void setAsyncReference(OSAsyncReference asyncRef
,
248 mach_port_t wakePort
,
249 void *callback
, void *refcon
);
251 static IOReturn
sendAsyncResult64(OSAsyncReference64 reference
,
252 IOReturn result
, io_user_reference_t args
[], UInt32 numArgs
);
253 static void setAsyncReference64(OSAsyncReference64 asyncRef
,
254 mach_port_t wakePort
,
255 mach_vm_address_t callback
, io_user_reference_t refcon
);
258 static IOReturn
clientHasPrivilege( void * securityToken
,
259 const char * privilegeName
);
262 @function releaseAsyncReference64
263 @abstract Release the mach_port_t reference held within the OSAsyncReference64 structure.
264 @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.
265 @param reference The reference passed to the subclass IOAsyncMethod, or externalMethod() in the IOExternalMethodArguments.asyncReference field.
266 @result A return code.
268 static IOReturn
releaseAsyncReference64(OSAsyncReference64 reference
);
270 @function releaseNotificationPort
271 @abstract Release the mach_port_t passed to registerNotificationPort().
272 @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.
273 @param reference The mach_port_t argument previously passed to the subclass implementation of registerNotificationPort().
274 @result A return code.
276 static IOReturn
releaseNotificationPort(mach_port_t port
);
279 virtual bool init( OSDictionary
* dictionary
);
280 // Currently ignores the all args, just passes up to IOService::init()
281 virtual bool initWithTask(
282 task_t owningTask
, void * securityToken
, UInt32 type
,
283 OSDictionary
* properties
);
285 virtual bool initWithTask(
286 task_t owningTask
, void * securityToken
, UInt32 type
);
290 virtual IOReturn
clientClose( void );
291 virtual IOReturn
clientDied( void );
293 virtual IOService
* getService( void );
295 virtual IOReturn
registerNotificationPort(
296 mach_port_t port
, UInt32 type
, UInt32 refCon
);
298 virtual IOReturn
getNotificationSemaphore( UInt32 notification_type
,
299 semaphore_t
* semaphore
);
301 virtual IOReturn
connectClient( IOUserClient
* client
);
303 // memory will be released by user client when last map is destroyed
304 virtual IOReturn
clientMemoryForType( UInt32 type
,
305 IOOptionBits
* options
,
306 IOMemoryDescriptor
** memory
);
310 APPLE_KEXT_COMPATIBILITY_VIRTUAL
311 IOMemoryMap
* mapClientMemory( IOOptionBits type
,
313 IOOptionBits mapFlags
= kIOMapAnywhere
,
314 IOVirtualAddress atAddress
= 0 );
320 @function removeMappingForDescriptor
321 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.
322 @param memory The memory descriptor instance previously returned by the implementation of clientMemoryForType().
323 @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.
325 IOMemoryMap
* removeMappingForDescriptor(IOMemoryDescriptor
* memory
);
328 @function exportObjectToClient
329 Make an arbitrary OSObject available to the client task.
330 @param task The task.
331 @param obj The object we want to export to the client.
332 @param clientObj Returned value is the client's port name.
334 virtual IOReturn
exportObjectToClient(task_t task
,
335 OSObject
*obj
, io_object_t
*clientObj
);
337 // Old methods for accessing method vector backward compatiblility only
338 virtual IOExternalMethod
*
339 getExternalMethodForIndex( UInt32 index
)
340 APPLE_KEXT_DEPRECATED
;
341 virtual IOExternalAsyncMethod
*
342 getExternalAsyncMethodForIndex( UInt32 index
)
343 APPLE_KEXT_DEPRECATED
;
345 // Methods for accessing method vector.
346 virtual IOExternalMethod
*
347 getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
);
348 virtual IOExternalAsyncMethod
*
349 getAsyncTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
);
351 // Methods for accessing trap vector - old and new style
352 virtual IOExternalTrap
*
353 getExternalTrapForIndex( UInt32 index
)
354 APPLE_KEXT_DEPRECATED
;
356 virtual IOExternalTrap
*
357 getTargetAndTrapForIndex( IOService
**targetP
, UInt32 index
);
360 #endif /* ! _IOKIT_IOUSERCLIENT_H */