]>
Commit | Line | Data |
---|---|---|
cb323159 A |
1 | /* |
2 | * Copyright (c) 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 | ||
30 | #ifndef _IOUSERSERVER_H | |
31 | #define _IOUSERSERVER_H | |
32 | ||
33 | #include <IOKit/IORPC.h> | |
34 | ||
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" | |
41 | ||
42 | #if DRIVERKIT_PRIVATE | |
43 | ||
44 | enum{ | |
45 | kIOKitUserServerClientType = 0x99000003, | |
46 | }; | |
47 | ||
48 | enum{ | |
49 | kIOUserServerMethodRegisterClass = 0x0001000, | |
50 | kIOUserServerMethodStart = 0x0001001, | |
51 | kIOUserServerMethodRegister = 0x0001002, | |
52 | }; | |
53 | ||
54 | ||
55 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
56 | ||
57 | class OSObject; | |
58 | ||
59 | #define OSObject_Instantiate_ID 0x0000000100000001ULL | |
60 | ||
61 | enum { | |
62 | kOSObjectRPCRemote = 0x00000001, | |
63 | kOSObjectRPCKernel = 0x00000002, | |
64 | }; | |
65 | ||
66 | struct OSObject_Instantiate_Msg_Content { | |
67 | IORPCMessage __hdr; | |
68 | OSObjectRef __object; | |
69 | }; | |
70 | ||
71 | struct OSObject_Instantiate_Rpl_Content { | |
72 | IORPCMessage __hdr; | |
73 | kern_return_t __result; | |
74 | uint32_t __pad; | |
75 | uint64_t flags; | |
76 | char classname[64]; | |
77 | uint64_t methods[0]; | |
78 | }; | |
79 | ||
80 | #pragma pack(4) | |
81 | struct OSObject_Instantiate_Msg { | |
82 | IORPCMessageMach mach; | |
83 | mach_msg_port_descriptor_t __object__descriptor; | |
84 | OSObject_Instantiate_Msg_Content content; | |
85 | }; | |
86 | struct OSObject_Instantiate_Rpl { | |
87 | IORPCMessageMach mach; | |
88 | OSObject_Instantiate_Rpl_Content content; | |
89 | }; | |
90 | #pragma pack() | |
91 | ||
92 | typedef uint64_t IOTrapMessageBuffer[256]; | |
93 | ||
94 | #endif /* DRIVERKIT_PRIVATE */ | |
95 | ||
96 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
97 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
98 | ||
99 | #ifdef XNU_KERNEL_PRIVATE | |
100 | ||
101 | #include <IOKit/IOService.h> | |
102 | #include <IOKit/IOUserClient.h> | |
103 | #include <DriverKit/IOUserServer.h> | |
104 | #include <libkern/c++/OSKext.h> | |
105 | ||
106 | class IOUserServer; | |
107 | class OSUserMetaClass; | |
108 | class IODispatchQueue; | |
109 | class IODispatchSource; | |
110 | class IOInterruptDispatchSource; | |
111 | class IOTimerDispatchSource; | |
112 | struct IOPStrings; | |
113 | ||
114 | struct OSObjectUserVars { | |
115 | IOUserServer * userServer; | |
116 | IODispatchQueue ** queueArray; | |
117 | OSUserMetaClass * userMeta; | |
118 | OSArray * openProviders; | |
119 | bool willTerminate; | |
120 | bool didTerminate; | |
121 | bool serverDied; | |
122 | bool started; | |
123 | bool stopped; | |
124 | bool userServerPM; | |
125 | bool willPower; | |
126 | uint32_t powerOverride; | |
127 | }; | |
128 | ||
129 | extern IOLock * gIOUserServerLock; | |
130 | ||
131 | typedef struct ipc_kmsg * ipc_kmsg_t; | |
132 | ||
133 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
134 | ||
135 | namespace IOServicePH | |
136 | { | |
137 | void serverAdd(IOUserServer * server); | |
138 | void serverRemove(IOUserServer * server); | |
139 | void serverAck(IOUserServer * server); | |
140 | }; | |
141 | ||
142 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
143 | ||
144 | class IOUserServer : public IOUserClient | |
145 | { | |
146 | OSDeclareDefaultStructorsWithDispatch(IOUserServer); | |
147 | ||
148 | IOLock * fLock; | |
149 | IOSimpleLock * fInterruptLock; | |
150 | task_t fOwningTask; | |
151 | OSDictionary * fEntitlements; | |
152 | OSDictionary * fClasses; | |
153 | IODispatchQueue * fRootQueue; | |
154 | OSArray * fServices; | |
155 | ||
156 | uint64_t fPowerStates; | |
157 | uint8_t fRootNotifier; | |
158 | uint8_t fSystemPowerAck; | |
159 | uint8_t fSystemOff; | |
160 | ||
161 | public: | |
162 | ||
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; | |
168 | ||
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; | |
173 | ||
174 | virtual IOExternalTrap * getTargetAndTrapForIndex(IOService ** targetP, UInt32 index) APPLE_KEXT_OVERRIDE; | |
175 | ||
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); | |
188 | ||
189 | bool serviceMatchesCDHash(IOService *service); | |
190 | bool checkEntitlements(IOService * provider, IOService * dext); | |
191 | bool checkEntitlements(OSDictionary * entitlements, OSObject * prop, | |
192 | IOService * provider, IOService * dext); | |
193 | ||
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; | |
200 | ||
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); | |
205 | ||
206 | OSObjectUserVars * varsForObject(OSObject * obj); | |
207 | LIBKERN_RETURNS_NOT_RETAINED IODispatchQueue * queueForObject(OSObject * obj, uint64_t msgid); | |
208 | ||
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); | |
211 | ||
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); | |
216 | ||
217 | IOReturn consumeObjects(IORPCMessage * message, size_t messageSize); | |
218 | ||
219 | IOReturn objectInstantiate(OSObject * obj, IORPC rpc, IORPCMessage * message); | |
220 | IOReturn kernelDispatch(OSObject * obj, IORPC rpc); | |
221 | static OSObject * target(OSAction * action, IORPCMessage * message); | |
222 | ||
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); | |
226 | }; | |
227 | ||
228 | extern "C" kern_return_t | |
229 | IOUserServerUEXTTrap(OSObject * object, void * p1, void * p2, void * p3, void * p4, void * p5, void * p6); | |
230 | ||
231 | #endif /* XNU_KERNEL_PRIVATE */ | |
232 | #endif /* _IOUSERSERVER_H */ |