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++/OSPtr.h>
105 #include <libkern/c++/OSKext.h>
108 class OSUserMetaClass
;
109 class IODispatchQueue
;
110 class IODispatchSource
;
111 class IOInterruptDispatchSource
;
112 class IOTimerDispatchSource
;
113 class IOUserServerCheckInToken
;
116 struct OSObjectUserVars
{
117 IOUserServer
* userServer
;
118 IODispatchQueue
** queueArray
;
119 OSUserMetaClass
* userMeta
;
120 OSArray
* openProviders
;
121 IOService
* controllingDriver
;
122 unsigned long willPowerState
;
130 uint32_t powerOverride
;
133 extern IOLock
* gIOUserServerLock
;
135 typedef struct ipc_kmsg
* ipc_kmsg_t
;
137 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
139 namespace IOServicePH
141 void serverAdd(IOUserServer
* server
);
142 void serverRemove(IOUserServer
* server
);
143 void serverAck(IOUserServer
* server
);
144 bool serverSlept(void);
145 void systemHalt(void);
148 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
150 class IOUserServer
: public IOUserClient
152 OSDeclareDefaultStructorsWithDispatch(IOUserServer
);
155 IOSimpleLock
* fInterruptLock
;
157 OSDictionary
* fEntitlements
;
158 OSDictionary
* fClasses
;
159 IODispatchQueue
* fRootQueue
;
162 uint64_t fPowerStates
;
163 uint8_t fRootNotifier
;
164 uint8_t fSystemPowerAck
;
166 IOUserServerCheckInToken
* fCheckInToken
;
170 static IOUserClient
* withTask(task_t owningTask
);
171 virtual IOReturn
clientClose(void) APPLE_KEXT_OVERRIDE
;
172 virtual bool finalize(IOOptionBits options
) APPLE_KEXT_OVERRIDE
;
173 virtual void stop(IOService
* provider
) APPLE_KEXT_OVERRIDE
;
174 virtual void free() APPLE_KEXT_OVERRIDE
;
176 virtual IOReturn
setProperties(OSObject
* properties
) APPLE_KEXT_OVERRIDE
;
177 virtual IOReturn
externalMethod(uint32_t selector
, IOExternalMethodArguments
* args
,
178 IOExternalMethodDispatch
* dispatch
,
179 OSObject
* target
, void * reference
) APPLE_KEXT_OVERRIDE
;
181 virtual IOExternalTrap
* getTargetAndTrapForIndex(IOService
** targetP
, UInt32 index
) APPLE_KEXT_OVERRIDE
;
183 IOReturn
serviceAttach(IOService
* service
, IOService
* provider
);
184 IOReturn
serviceStop(IOService
* service
, IOService
* provider
);
185 void serviceFree(IOService
* service
);
186 IOReturn
serviceStarted(IOService
* service
, IOService
* provider
, bool result
);
187 static void serviceWillTerminate(IOService
* client
, IOService
* provider
, IOOptionBits options
);
188 static void serviceDidTerminate(IOService
* client
, IOService
* provider
, IOOptionBits options
, bool * defer
);
189 static void serviceDidStop(IOService
* client
, IOService
* provider
);
190 IOReturn
serviceOpen(IOService
* provider
, IOService
* client
);
191 IOReturn
serviceClose(IOService
* provider
, IOService
* client
);
192 IOReturn
serviceSetPowerState(IOService
* controllingDriver
, IOService
* service
, IOPMPowerFlags flags
, IOPMPowerStateIndex powerState
);
193 IOReturn
serviceNewUserClient(IOService
* service
, task_t owningTask
, void * securityID
,
194 uint32_t type
, OSDictionary
* properties
, IOUserClient
** handler
);
195 IOReturn
serviceNewUserClient(IOService
* service
, task_t owningTask
, void * securityID
,
196 uint32_t type
, OSDictionary
* properties
, OSSharedPtr
<IOUserClient
>& handler
);
197 IOReturn
exit(const char * reason
);
199 bool serviceMatchesCheckInToken(IOUserServerCheckInToken
*token
);
200 bool checkEntitlements(IOService
* provider
, IOService
* dext
);
201 bool checkEntitlements(OSDictionary
* entitlements
, OSObject
* prop
,
202 IOService
* provider
, IOService
* dext
);
204 void setTaskLoadTag(OSKext
*kext
);
205 void setDriverKitUUID(OSKext
*kext
);
206 void setCheckInToken(IOUserServerCheckInToken
*token
);
207 void systemPower(bool powerOff
);
208 void systemHalt(void);
209 IOReturn
setPowerState(unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
210 IOReturn
powerStateWillChangeTo(IOPMPowerFlags flags
, unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
211 IOReturn
powerStateDidChangeTo(IOPMPowerFlags flags
, unsigned long state
, IOService
* service
) APPLE_KEXT_OVERRIDE
;
213 IOPStrings
* copyInStringArray(const char * string
, uint32_t userSize
);
214 uint32_t stringArrayIndex(IOPStrings
* array
, const char * look
);
215 IOReturn
registerClass(OSClassDescription
* desc
, uint32_t size
, OSUserMetaClass
** cls
);
216 IOReturn
registerClass(OSClassDescription
* desc
, uint32_t size
, OSSharedPtr
<OSUserMetaClass
>& cls
);
217 IOReturn
setRootQueue(IODispatchQueue
* queue
);
219 OSObjectUserVars
* varsForObject(OSObject
* obj
);
220 LIBKERN_RETURNS_NOT_RETAINED IODispatchQueue
* queueForObject(OSObject
* obj
, uint64_t msgid
);
222 static ipc_port_t
copySendRightForObject(OSObject
* object
, natural_t
/* ipc_kobject_type_t */ type
);
223 static OSObject
* copyObjectForSendRight(ipc_port_t port
, natural_t
/* ipc_kobject_type_t */ type
);
225 IOReturn
copyOutObjects(IORPCMessageMach
* mach
, IORPCMessage
* message
,
226 size_t size
, bool consume
);
227 IOReturn
copyInObjects(IORPCMessageMach
* mach
, IORPCMessage
* message
,
228 size_t size
, bool copyObjects
, bool consumePorts
);
230 IOReturn
consumeObjects(IORPCMessage
* message
, size_t messageSize
);
232 IOReturn
objectInstantiate(OSObject
* obj
, IORPC rpc
, IORPCMessage
* message
);
233 IOReturn
kernelDispatch(OSObject
* obj
, IORPC rpc
);
234 static OSObject
* target(OSAction
* action
, IORPCMessage
* message
);
236 IOReturn
rpc(IORPC rpc
);
237 IOReturn
server(ipc_kmsg_t requestkmsg
, ipc_kmsg_t
* preply
);
238 kern_return_t
waitInterruptTrap(void * p1
, void * p2
, void * p3
, void * p4
, void * p5
, void * p6
);
241 typedef void (*IOUserServerCheckInNotificationHandler
)(class IOUserServerCheckInToken
*, void*);
243 class IOUserServerCheckInToken
: public OSObject
245 OSDeclareDefaultStructors(IOUserServerCheckInToken
);
247 static IOUserServerCheckInToken
* create();
248 void setNoSendersNotification(IOUserServerCheckInNotificationHandler handler
, void *handlerArgs
);
249 void clearNotification();
250 static void notifyNoSenders(IOUserServerCheckInToken
* token
);
252 IOUserServerCheckInNotificationHandler handler
;
256 extern "C" kern_return_t
257 IOUserServerUEXTTrap(OSObject
* object
, void * p1
, void * p2
, void * p3
, void * p4
, void * p5
, void * p6
);
259 #endif /* XNU_KERNEL_PRIVATE */
260 #endif /* _IOUSERSERVER_H */