| 1 | /* |
| 2 | * Copyright (c) 2018 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 _IORPC_H |
| 31 | #define _IORPC_H |
| 32 | |
| 33 | #include <stdint.h> |
| 34 | |
| 35 | #ifndef XNU_PLATFORM_DriverKit |
| 36 | |
| 37 | #include <mach/message.h> |
| 38 | |
| 39 | #else /* !XNU_PLATFORM_DriverKit */ |
| 40 | |
| 41 | #ifndef _MACH_MESSAGE_H_ |
| 42 | #define _MACH_MESSAGE_H_ |
| 43 | |
| 44 | #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive right */ |
| 45 | #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send right(s) */ |
| 46 | #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce right */ |
| 47 | #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send right(s) */ |
| 48 | #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive right */ |
| 49 | #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive right */ |
| 50 | #define MACH_MSG_TYPE_COPY_RECEIVE 22 /* NOT VALID */ |
| 51 | #define MACH_MSG_TYPE_DISPOSE_RECEIVE 24 /* must hold receive right */ |
| 52 | #define MACH_MSG_TYPE_DISPOSE_SEND 25 /* must hold send right(s) */ |
| 53 | #define MACH_MSG_TYPE_DISPOSE_SEND_ONCE 26 /* must hold sendonce right */ |
| 54 | |
| 55 | #define MACH_MSG_TYPE_PORT_NONE 0 |
| 56 | |
| 57 | #define MACH_MSG_PORT_DESCRIPTOR 0 |
| 58 | #define MACH_MSG_OOL_DESCRIPTOR 1 |
| 59 | |
| 60 | typedef unsigned int mach_msg_copy_options_t; |
| 61 | |
| 62 | #define MACH_MSG_PHYSICAL_COPY 0 |
| 63 | #define MACH_MSG_VIRTUAL_COPY 1 |
| 64 | #define MACH_MSG_ALLOCATE 2 |
| 65 | |
| 66 | typedef uint32_t natural_t; |
| 67 | typedef int32_t integer_t; |
| 68 | |
| 69 | typedef unsigned int mach_msg_type_name_t; |
| 70 | typedef unsigned int mach_msg_descriptor_type_t; |
| 71 | |
| 72 | #if KERNEL |
| 73 | typedef void * mach_port_t; |
| 74 | #define MACH_PORT_NULL NULL |
| 75 | #else /* !KERNEL */ |
| 76 | typedef natural_t mach_port_t; |
| 77 | #define MACH_PORT_NULL 0 |
| 78 | #endif /* !KERNEL */ |
| 79 | |
| 80 | typedef natural_t mach_port_name_t; |
| 81 | |
| 82 | typedef unsigned int mach_msg_bits_t; |
| 83 | typedef natural_t mach_msg_size_t; |
| 84 | typedef integer_t mach_msg_id_t; |
| 85 | |
| 86 | #pragma pack(push, 4) |
| 87 | |
| 88 | typedef struct{ |
| 89 | mach_msg_bits_t msgh_bits; |
| 90 | mach_msg_size_t msgh_size; |
| 91 | mach_port_t msgh_remote_port; |
| 92 | mach_port_t msgh_local_port; |
| 93 | mach_port_name_t msgh_voucher_port; |
| 94 | mach_msg_id_t msgh_id; |
| 95 | } mach_msg_header_t; |
| 96 | |
| 97 | typedef struct{ |
| 98 | mach_msg_size_t msgh_descriptor_count; |
| 99 | } mach_msg_body_t; |
| 100 | |
| 101 | typedef struct{ |
| 102 | mach_port_t name; |
| 103 | #if !(defined(KERNEL) && defined(__LP64__)) |
| 104 | // Pad to 8 bytes everywhere except the K64 kernel where mach_port_t is 8 bytes |
| 105 | mach_msg_size_t pad1; |
| 106 | #endif |
| 107 | unsigned int pad2 : 16; |
| 108 | mach_msg_type_name_t disposition : 8; |
| 109 | mach_msg_descriptor_type_t type : 8; |
| 110 | #if defined(KERNEL) |
| 111 | uint32_t pad_end; |
| 112 | #endif |
| 113 | } mach_msg_port_descriptor_t; |
| 114 | |
| 115 | typedef struct{ |
| 116 | void * address; |
| 117 | #if !defined(__LP64__) |
| 118 | mach_msg_size_t size; |
| 119 | #endif |
| 120 | int deallocate: 8; |
| 121 | mach_msg_copy_options_t copy: 8; |
| 122 | unsigned int pad1: 8; |
| 123 | mach_msg_descriptor_type_t type: 8; |
| 124 | #if defined(__LP64__) |
| 125 | mach_msg_size_t size; |
| 126 | #endif |
| 127 | #if defined(KERNEL) && !defined(__LP64__) |
| 128 | uint32_t pad_end; |
| 129 | #endif |
| 130 | } mach_msg_ool_descriptor_t; |
| 131 | |
| 132 | typedef struct{ |
| 133 | unsigned int val[80 / sizeof(int)]; |
| 134 | } mach_msg_max_trailer_t; |
| 135 | |
| 136 | #pragma pack(pop) |
| 137 | |
| 138 | #endif /* _MACH_MESSAGE_H_ */ |
| 139 | |
| 140 | #endif /* XNU_PLATFORM_DriverKit */ |
| 141 | |
| 142 | #if KERNEL |
| 143 | class IOUserServer; |
| 144 | #endif /* KERNEL */ |
| 145 | |
| 146 | typedef uint64_t OSObjectRef; |
| 147 | |
| 148 | enum { |
| 149 | kIORPCVersion190615 = (mach_msg_id_t) 0x4da2b68c, |
| 150 | kIORPCVersion190615Reply = (mach_msg_id_t) 0x4da2b68d, |
| 151 | |
| 152 | #if DRIVERKIT_PRIVATE |
| 153 | kIORPCVersion190501 = (mach_msg_id_t) 0xfe316a7a, |
| 154 | kIORPCVersion190501Reply = (mach_msg_id_t) 0xfe316a7b, |
| 155 | |
| 156 | kIORPCVersionCurrent = kIORPCVersion190615, |
| 157 | kIORPCVersionCurrentReply = kIORPCVersion190615Reply |
| 158 | #endif /* DRIVERKIT_PRIVATE */ |
| 159 | }; |
| 160 | |
| 161 | enum{ |
| 162 | kIORPCMessageRemote = 0x00000001, |
| 163 | kIORPCMessageLocalHost = 0x00000002, |
| 164 | kIORPCMessageKernel = 0x00000004, |
| 165 | kIORPCMessageOneway = 0x00000008, |
| 166 | kIORPCMessageObjectRefs = 0x00000010, |
| 167 | kIORPCMessageOnqueue = 0x00000020, |
| 168 | kIORPCMessageError = 0x00000040, |
| 169 | kIORPCMessageSimpleReply = 0x00000080, |
| 170 | }; |
| 171 | |
| 172 | enum{ |
| 173 | kIORPCMessageIDKernel = (1ULL << 63), |
| 174 | }; |
| 175 | |
| 176 | struct IORPCMessageMach { |
| 177 | mach_msg_header_t msgh; |
| 178 | mach_msg_body_t msgh_body; |
| 179 | mach_msg_port_descriptor_t objects[0]; |
| 180 | }; |
| 181 | typedef struct IORPCMessageMach IORPCMessageMach; |
| 182 | |
| 183 | #pragma pack(push, 4) |
| 184 | struct IORPCMessage { |
| 185 | uint64_t msgid; |
| 186 | uint64_t flags; |
| 187 | uint64_t objectRefs; |
| 188 | OSObjectRef objects[0]; |
| 189 | }; |
| 190 | #pragma pack(pop) |
| 191 | typedef struct IORPCMessage IORPCMessage; |
| 192 | |
| 193 | #ifndef KERNEL |
| 194 | |
| 195 | #if defined(__cplusplus) |
| 196 | extern "C" |
| 197 | #else |
| 198 | extern |
| 199 | #endif |
| 200 | IORPCMessage * |
| 201 | IORPCMessageFromMach(IORPCMessageMach * msg, bool reply); |
| 202 | |
| 203 | #endif /* KERNEL */ |
| 204 | |
| 205 | struct IORPCMessageErrorReturnContent { |
| 206 | IORPCMessage hdr; |
| 207 | kern_return_t result; |
| 208 | uint32_t pad; |
| 209 | }; |
| 210 | typedef struct IORPCMessageErrorReturnContent IORPCMessageErrorReturnContent; |
| 211 | |
| 212 | #pragma pack(4) |
| 213 | struct IORPCMessageErrorReturn { |
| 214 | IORPCMessageMach mach; |
| 215 | IORPCMessageErrorReturnContent content; |
| 216 | }; |
| 217 | #pragma pack() |
| 218 | |
| 219 | |
| 220 | #if defined(__cplusplus) |
| 221 | class OSMetaClassBase; |
| 222 | struct IORPC; |
| 223 | typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase * self, const IORPC rpc); |
| 224 | #endif |
| 225 | |
| 226 | struct IORPC { |
| 227 | IORPCMessageMach * message; |
| 228 | IORPCMessageMach * reply; |
| 229 | uint32_t sendSize; |
| 230 | uint32_t replySize; |
| 231 | #ifdef KERNEL |
| 232 | IORPCMessage * kernelContent; |
| 233 | #endif /* KERNEL */ |
| 234 | }; |
| 235 | typedef struct IORPC IORPC; |
| 236 | |
| 237 | enum { |
| 238 | kOSClassCanRemote = 0x00000001, |
| 239 | }; |
| 240 | |
| 241 | struct OSClassDescription { |
| 242 | uint32_t descriptionSize; |
| 243 | |
| 244 | char name[96]; |
| 245 | char superName[96]; |
| 246 | |
| 247 | uint32_t methodOptionsSize; |
| 248 | uint32_t methodOptionsOffset; |
| 249 | uint32_t metaMethodOptionsSize; |
| 250 | uint32_t metaMethodOptionsOffset; |
| 251 | uint32_t queueNamesSize; |
| 252 | uint32_t queueNamesOffset; |
| 253 | uint32_t methodNamesSize; |
| 254 | uint32_t methodNamesOffset; |
| 255 | uint32_t metaMethodNamesSize; |
| 256 | uint32_t metaMethodNamesOffset; |
| 257 | |
| 258 | uint64_t flags; |
| 259 | |
| 260 | uint64_t resv1[8]; |
| 261 | |
| 262 | uint64_t methodOptions[0]; |
| 263 | uint64_t metaMethodOptions[0]; |
| 264 | |
| 265 | char dispatchNames[0]; |
| 266 | char methodNames[0]; |
| 267 | char metaMethodNames[0]; |
| 268 | }; |
| 269 | |
| 270 | IORPCMessage *IORPCMessageFromMach(IORPCMessageMach * msg, bool reply); |
| 271 | |
| 272 | #endif /* _IORPC_H */ |
| 273 | |