2 * Copyright (c) 2019 Apple 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 #ifndef _IOUSERSERVER_H
31 #define _IOUSERSERVER_H
33 #include <IOKit/IORPC.h>
35 #define kIOUserClassKey "IOUserClass"
36 #define kIOUserServerClassKey "IOUserServer"
37 #define kIOUserServerNameKey "IOUserServerName"
38 #define kIOUserServerTagKey "IOUserServerTag"
39 // the expected cdhash value of the userspace driver executable
40 #define kIOUserServerCDHashKey "IOUserServerCDHash"
45 kIOKitUserServerClientType
= 0x99000003,
49 kIOUserServerMethodRegisterClass
= 0x0001000,
50 kIOUserServerMethodStart
= 0x0001001,
51 kIOUserServerMethodRegister
= 0x0001002,
55 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
59 #define OSObject_Instantiate_ID 0x0000000100000001ULL
62 kOSObjectRPCRemote
= 0x00000001,
63 kOSObjectRPCKernel
= 0x00000002,
66 struct OSObject_Instantiate_Msg_Content
{
71 struct OSObject_Instantiate_Rpl_Content
{
73 kern_return_t __result
;
81 struct OSObject_Instantiate_Msg
{
82 IORPCMessageMach mach
;
83 mach_msg_port_descriptor_t __object__descriptor
;
84 OSObject_Instantiate_Msg_Content content
;
86 struct OSObject_Instantiate_Rpl
{
87 IORPCMessageMach mach
;
88 OSObject_Instantiate_Rpl_Content content
;
92 typedef uint64_t IOTrapMessageBuffer
[256];
94 #endif /* DRIVERKIT_PRIVATE */
96 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
97 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
99 #ifdef XNU_KERNEL_PRIVATE
101 #include <IOKit/IOService.h>
102 #include <IOKit/IOUserClient.h>
103 #include <DriverKit/IOUserServer.h>
104 #include <libkern/c++/OSKext.h>
107 class OSUserMetaClass
;
108 class IODispatchQueue
;
109 class IODispatchSource
;
110 class IOInterruptDispatchSource
;
111 class IOTimerDispatchSource
;
114 struct OSObjectUserVars
{
115 IOUserServer
* userServer
;
116 IODispatchQueue
** queueArray
;
117 OSUserMetaClass
* userMeta
;
118 OSArray
* openProviders
;
126 uint32_t powerOverride
;
129 extern IOLock
* gIOUserServerLock
;
131 typedef struct ipc_kmsg
* ipc_kmsg_t
;
133 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
135 namespace IOServicePH
137 void serverAdd(IOUserServer
* server
);
138 void serverRemove(IOUserServer
* server
);
139 void serverAck(IOUserServer
* server
);
142 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
144 class IOUserServer
: public IOUserClient
146 OSDeclareDefaultStructorsWithDispatch(IOUserServer
);
149 IOSimpleLock
* fInterruptLock
;
151 OSDictionary
* fEntitlements
;
152 OSDictionary
* fClasses
;
153 IODispatchQueue
* fRootQueue
;
156 uint64_t fPowerStates
;
157 uint8_t fRootNotifier
;
158 uint8_t fSystemPowerAck
;
163 static IOUserClient
* withTask(task_t owningTask
);
164 virtual IOReturn
clientClose(void) APPLE_KEXT_OVERRIDE
;
165 virtual bool finalize(IOOptionBits options
) APPLE_KEXT_OVERRIDE
;
166 virtual void stop(IOService
* provider
) APPLE_KEXT_OVERRIDE
;
167 virtual void free() APPLE_KEXT_OVERRIDE
;
169 virtual IOReturn
setProperties(OSObject
* properties
) APPLE_KEXT_OVERRIDE
;
170 virtual IOReturn
externalMethod(uint32_t selector
, IOExternalMethodArguments
* args
,
171 IOExternalMethodDispatch
* dispatch
,
172 OSObject
* target
, void * reference
) APPLE_KEXT_OVERRIDE
;
174 virtual IOExternalTrap
* getTargetAndTrapForIndex(IOService
** targetP
, UInt32 index
) APPLE_KEXT_OVERRIDE
;
176 IOReturn
serviceAttach(IOService
* service
, IOService
* provider
);
177 IOReturn
serviceStop(IOService
* service
, IOService
* provider
);
178 void serviceFree(IOService
* service
);
179 IOReturn
serviceStarted(IOService
* service
, IOService
* provider
, bool result
);
180 static void serviceWillTerminate(IOService
* client
, IOService
* provider
, IOOptionBits options
);
181 static void serviceDidTerminate(IOService
* client
, IOService
* provider
, IOOptionBits options
, bool * defer
);
182 static void serviceDidStop(IOService
* client
, IOService
* provider
);
183 IOReturn
serviceOpen(IOService
* provider
, IOService
* client
);
184 IOReturn
serviceClose(IOService
* provider
, IOService
* client
);
185 IOReturn
serviceNewUserClient(IOService
* service
, task_t owningTask
, void * securityID
,
186 uint32_t type
, OSDictionary
* properties
, IOUserClient
** handler
);
187 IOReturn
exit(const char * reason
);
189 bool serviceMatchesCDHash(IOService
*service
);
190 bool checkEntitlements(IOService
* provider
, IOService
* dext
);
191 bool checkEntitlements(OSDictionary
* entitlements
, OSObject
* prop
,
192 IOService
* provider
, IOService
* dext
);
194 void setTaskLoadTag(OSKext
*kext
);
195 void setDriverKitUUID(OSKext
*kext
);
196 void systemPower(bool powerOff
);
197 IOReturn
setPowerState(unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
198 IOReturn
powerStateWillChangeTo(IOPMPowerFlags flags
, unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
199 IOReturn
powerStateDidChangeTo(IOPMPowerFlags flags
, unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
201 IOPStrings
* copyInStringArray(const char * string
, uint32_t userSize
);
202 uint32_t stringArrayIndex(IOPStrings
* array
, const char * look
);
203 IOReturn
registerClass(OSClassDescription
* desc
, uint32_t size
, OSUserMetaClass
** cls
);
204 IOReturn
setRootQueue(IODispatchQueue
* queue
);
206 OSObjectUserVars
* varsForObject(OSObject
* obj
);
207 LIBKERN_RETURNS_NOT_RETAINED IODispatchQueue
* queueForObject(OSObject
* obj
, uint64_t msgid
);
209 static ipc_port_t
copySendRightForObject(OSObject
* object
, natural_t
/* ipc_kobject_type_t */ type
);
210 static OSObject
* copyObjectForSendRight(ipc_port_t port
, natural_t
/* ipc_kobject_type_t */ type
);
212 IOReturn
copyOutObjects(IORPCMessageMach
* mach
, IORPCMessage
* message
,
213 size_t size
, bool consume
);
214 IOReturn
copyInObjects(IORPCMessageMach
* mach
, IORPCMessage
* message
,
215 size_t size
, bool copyObjects
, bool consumePorts
);
217 IOReturn
consumeObjects(IORPCMessage
* message
, size_t messageSize
);
219 IOReturn
objectInstantiate(OSObject
* obj
, IORPC rpc
, IORPCMessage
* message
);
220 IOReturn
kernelDispatch(OSObject
* obj
, IORPC rpc
);
221 static OSObject
* target(OSAction
* action
, IORPCMessage
* message
);
223 IOReturn
rpc(IORPC rpc
);
224 IOReturn
server(ipc_kmsg_t requestkmsg
, ipc_kmsg_t
* preply
);
225 kern_return_t
waitInterruptTrap(void * p1
, void * p2
, void * p3
, void * p4
, void * p5
, void * p6
);
228 extern "C" kern_return_t
229 IOUserServerUEXTTrap(OSObject
* object
, void * p1
, void * p2
, void * p3
, void * p4
, void * p5
, void * p6
);
231 #endif /* XNU_KERNEL_PRIVATE */
232 #endif /* _IOUSERSERVER_H */