| 1 | /* iig(DriverKit-286 Mar 29 2024 10:27:09) generated from IOMemoryDescriptor.iig */ |
| 2 | |
| 3 | #undef IIG_IMPLEMENTATION |
| 4 | #define IIG_IMPLEMENTATION IOMemoryDescriptor.iig |
| 5 | |
| 6 | #if KERNEL |
| 7 | #include <libkern/c++/OSString.h> |
| 8 | #else |
| 9 | #include <DriverKit/DriverKit.h> |
| 10 | #endif /* KERNEL */ |
| 11 | #include <DriverKit/IOReturn.h> |
| 12 | #include <DriverKit/IOMemoryDescriptor.h> |
| 13 | |
| 14 | /* @iig implementation */ |
| 15 | #include <DriverKit/IOService.h> |
| 16 | /* @iig end */ |
| 17 | |
| 18 | |
| 19 | #if __has_builtin(__builtin_load_member_function_pointer) |
| 20 | #define SimpleMemberFunctionCast(cfnty, self, func) (cfnty)__builtin_load_member_function_pointer(self, func) |
| 21 | #else |
| 22 | #define SimpleMemberFunctionCast(cfnty, self, func) ({ union { typeof(func) memfun; cfnty cfun; } pair; pair.memfun = func; pair.cfun; }) |
| 23 | #endif |
| 24 | |
| 25 | |
| 26 | struct IOMemoryDescriptor__CopyState_Msg_Content |
| 27 | { |
| 28 | IORPCMessage __hdr; |
| 29 | OSObjectRef __object; |
| 30 | }; |
| 31 | #pragma pack(4) |
| 32 | struct IOMemoryDescriptor__CopyState_Msg |
| 33 | { |
| 34 | IORPCMessageMach mach; |
| 35 | mach_msg_port_descriptor_t __object__descriptor; |
| 36 | IOMemoryDescriptor__CopyState_Msg_Content content; |
| 37 | }; |
| 38 | #pragma pack() |
| 39 | #define IOMemoryDescriptor__CopyState_Msg_ObjRefs (1) |
| 40 | |
| 41 | struct IOMemoryDescriptor__CopyState_Rpl_Content |
| 42 | { |
| 43 | IORPCMessage __hdr; |
| 44 | _IOMDPrivateState state; |
| 45 | }; |
| 46 | #pragma pack(4) |
| 47 | struct IOMemoryDescriptor__CopyState_Rpl |
| 48 | { |
| 49 | IORPCMessageMach mach; |
| 50 | IOMemoryDescriptor__CopyState_Rpl_Content content; |
| 51 | }; |
| 52 | #pragma pack() |
| 53 | #define IOMemoryDescriptor__CopyState_Rpl_ObjRefs (0) |
| 54 | |
| 55 | |
| 56 | typedef union |
| 57 | { |
| 58 | const IORPC rpc; |
| 59 | struct |
| 60 | { |
| 61 | const struct IOMemoryDescriptor__CopyState_Msg * message; |
| 62 | struct IOMemoryDescriptor__CopyState_Rpl * reply; |
| 63 | uint32_t sendSize; |
| 64 | uint32_t replySize; |
| 65 | }; |
| 66 | } |
| 67 | IOMemoryDescriptor__CopyState_Invocation; |
| 68 | struct IOMemoryDescriptor_CreateMapping_Msg_Content |
| 69 | { |
| 70 | IORPCMessage __hdr; |
| 71 | OSObjectRef __object; |
| 72 | uint64_t options; |
| 73 | uint64_t address; |
| 74 | uint64_t offset; |
| 75 | uint64_t length; |
| 76 | uint64_t alignment; |
| 77 | }; |
| 78 | #pragma pack(4) |
| 79 | struct IOMemoryDescriptor_CreateMapping_Msg |
| 80 | { |
| 81 | IORPCMessageMach mach; |
| 82 | mach_msg_port_descriptor_t __object__descriptor; |
| 83 | IOMemoryDescriptor_CreateMapping_Msg_Content content; |
| 84 | }; |
| 85 | #pragma pack() |
| 86 | #define IOMemoryDescriptor_CreateMapping_Msg_ObjRefs (1) |
| 87 | |
| 88 | struct IOMemoryDescriptor_CreateMapping_Rpl_Content |
| 89 | { |
| 90 | IORPCMessage __hdr; |
| 91 | OSObjectRef map; |
| 92 | }; |
| 93 | #pragma pack(4) |
| 94 | struct IOMemoryDescriptor_CreateMapping_Rpl |
| 95 | { |
| 96 | IORPCMessageMach mach; |
| 97 | mach_msg_port_descriptor_t map__descriptor; |
| 98 | IOMemoryDescriptor_CreateMapping_Rpl_Content content; |
| 99 | }; |
| 100 | #pragma pack() |
| 101 | #define IOMemoryDescriptor_CreateMapping_Rpl_ObjRefs (1) |
| 102 | |
| 103 | |
| 104 | typedef union |
| 105 | { |
| 106 | const IORPC rpc; |
| 107 | struct |
| 108 | { |
| 109 | const struct IOMemoryDescriptor_CreateMapping_Msg * message; |
| 110 | struct IOMemoryDescriptor_CreateMapping_Rpl * reply; |
| 111 | uint32_t sendSize; |
| 112 | uint32_t replySize; |
| 113 | }; |
| 114 | } |
| 115 | IOMemoryDescriptor_CreateMapping_Invocation; |
| 116 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg_Content |
| 117 | { |
| 118 | IORPCMessage __hdr; |
| 119 | OSObjectRef __object; |
| 120 | OSObjectRef ofDescriptor; |
| 121 | uint64_t memoryDescriptorCreateOptions; |
| 122 | uint64_t offset; |
| 123 | uint64_t length; |
| 124 | }; |
| 125 | #pragma pack(4) |
| 126 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg |
| 127 | { |
| 128 | IORPCMessageMach mach; |
| 129 | mach_msg_port_descriptor_t __object__descriptor; |
| 130 | mach_msg_port_descriptor_t ofDescriptor__descriptor; |
| 131 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg_Content content; |
| 132 | }; |
| 133 | #pragma pack() |
| 134 | #define IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg_ObjRefs (2) |
| 135 | |
| 136 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl_Content |
| 137 | { |
| 138 | IORPCMessage __hdr; |
| 139 | OSObjectRef memory; |
| 140 | }; |
| 141 | #pragma pack(4) |
| 142 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl |
| 143 | { |
| 144 | IORPCMessageMach mach; |
| 145 | mach_msg_port_descriptor_t memory__descriptor; |
| 146 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl_Content content; |
| 147 | }; |
| 148 | #pragma pack() |
| 149 | #define IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl_ObjRefs (1) |
| 150 | |
| 151 | |
| 152 | typedef union |
| 153 | { |
| 154 | const IORPC rpc; |
| 155 | struct |
| 156 | { |
| 157 | const struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg * message; |
| 158 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl * reply; |
| 159 | uint32_t sendSize; |
| 160 | uint32_t replySize; |
| 161 | }; |
| 162 | } |
| 163 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Invocation; |
| 164 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg_Content |
| 165 | { |
| 166 | IORPCMessage __hdr; |
| 167 | OSObjectRef __object; |
| 168 | OSObjectRef __withDescriptors[32]; |
| 169 | uint64_t memoryDescriptorCreateOptions; |
| 170 | uint32_t withDescriptorsCount; |
| 171 | }; |
| 172 | #pragma pack(4) |
| 173 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg |
| 174 | { |
| 175 | IORPCMessageMach mach; |
| 176 | mach_msg_port_descriptor_t __object__descriptor; |
| 177 | mach_msg_port_descriptor_t withDescriptors__descriptor[32]; |
| 178 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg_Content content; |
| 179 | }; |
| 180 | #pragma pack() |
| 181 | #define IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg_ObjRefs (33) |
| 182 | |
| 183 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl_Content |
| 184 | { |
| 185 | IORPCMessage __hdr; |
| 186 | OSObjectRef memory; |
| 187 | }; |
| 188 | #pragma pack(4) |
| 189 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl |
| 190 | { |
| 191 | IORPCMessageMach mach; |
| 192 | mach_msg_port_descriptor_t memory__descriptor; |
| 193 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl_Content content; |
| 194 | }; |
| 195 | #pragma pack() |
| 196 | #define IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl_ObjRefs (1) |
| 197 | |
| 198 | |
| 199 | typedef union |
| 200 | { |
| 201 | const IORPC rpc; |
| 202 | struct |
| 203 | { |
| 204 | const struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg * message; |
| 205 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl * reply; |
| 206 | uint32_t sendSize; |
| 207 | uint32_t replySize; |
| 208 | }; |
| 209 | } |
| 210 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Invocation; |
| 211 | #if !KERNEL |
| 212 | extern OSMetaClass * gOSContainerMetaClass; |
| 213 | extern OSMetaClass * gOSDataMetaClass; |
| 214 | extern OSMetaClass * gOSNumberMetaClass; |
| 215 | extern OSMetaClass * gOSStringMetaClass; |
| 216 | extern OSMetaClass * gOSBooleanMetaClass; |
| 217 | extern OSMetaClass * gOSDictionaryMetaClass; |
| 218 | extern OSMetaClass * gOSArrayMetaClass; |
| 219 | extern OSMetaClass * gOSSetMetaClass; |
| 220 | extern OSMetaClass * gOSOrderedSetMetaClass; |
| 221 | extern OSMetaClass * gIODispatchQueueMetaClass; |
| 222 | extern OSMetaClass * gIOServiceMetaClass; |
| 223 | extern OSMetaClass * gIOMemoryMapMetaClass; |
| 224 | #endif /* !KERNEL */ |
| 225 | |
| 226 | #if !KERNEL |
| 227 | |
| 228 | #define IOMemoryDescriptor_QueueNames "" |
| 229 | |
| 230 | #define IOMemoryDescriptor_MethodNames "" |
| 231 | |
| 232 | #define IOMemoryDescriptorMetaClass_MethodNames "" |
| 233 | |
| 234 | struct OSClassDescription_IOMemoryDescriptor_t |
| 235 | { |
| 236 | OSClassDescription base; |
| 237 | uint64_t methodOptions[2 * 0]; |
| 238 | uint64_t metaMethodOptions[2 * 0]; |
| 239 | char queueNames[sizeof(IOMemoryDescriptor_QueueNames)]; |
| 240 | char methodNames[sizeof(IOMemoryDescriptor_MethodNames)]; |
| 241 | char metaMethodNames[sizeof(IOMemoryDescriptorMetaClass_MethodNames)]; |
| 242 | }; |
| 243 | |
| 244 | const struct OSClassDescription_IOMemoryDescriptor_t |
| 245 | OSClassDescription_IOMemoryDescriptor = |
| 246 | { |
| 247 | .base = |
| 248 | { |
| 249 | .descriptionSize = sizeof(OSClassDescription_IOMemoryDescriptor_t), |
| 250 | .name = "IOMemoryDescriptor" , |
| 251 | .superName = "OSObject" , |
| 252 | .methodOptionsSize = 2 * sizeof(uint64_t) * 0, |
| 253 | .methodOptionsOffset = __builtin_offsetof(struct OSClassDescription_IOMemoryDescriptor_t, methodOptions), |
| 254 | .metaMethodOptionsSize = 2 * sizeof(uint64_t) * 0, |
| 255 | .metaMethodOptionsOffset = __builtin_offsetof(struct OSClassDescription_IOMemoryDescriptor_t, metaMethodOptions), |
| 256 | .queueNamesSize = sizeof(IOMemoryDescriptor_QueueNames), |
| 257 | .queueNamesOffset = __builtin_offsetof(struct OSClassDescription_IOMemoryDescriptor_t, queueNames), |
| 258 | .methodNamesSize = sizeof(IOMemoryDescriptor_MethodNames), |
| 259 | .methodNamesOffset = __builtin_offsetof(struct OSClassDescription_IOMemoryDescriptor_t, methodNames), |
| 260 | .metaMethodNamesSize = sizeof(IOMemoryDescriptorMetaClass_MethodNames), |
| 261 | .metaMethodNamesOffset = __builtin_offsetof(struct OSClassDescription_IOMemoryDescriptor_t, metaMethodNames), |
| 262 | .flags = 1*kOSClassCanRemote, |
| 263 | }, |
| 264 | .methodOptions = |
| 265 | { |
| 266 | }, |
| 267 | .metaMethodOptions = |
| 268 | { |
| 269 | }, |
| 270 | .queueNames = IOMemoryDescriptor_QueueNames, |
| 271 | .methodNames = IOMemoryDescriptor_MethodNames, |
| 272 | .metaMethodNames = IOMemoryDescriptorMetaClass_MethodNames, |
| 273 | }; |
| 274 | |
| 275 | OSMetaClass * gIOMemoryDescriptorMetaClass; |
| 276 | |
| 277 | static kern_return_t |
| 278 | IOMemoryDescriptor_New(OSMetaClass * instance); |
| 279 | |
| 280 | const OSClassLoadInformation |
| 281 | IOMemoryDescriptor_Class = |
| 282 | { |
| 283 | .description = &OSClassDescription_IOMemoryDescriptor.base, |
| 284 | .metaPointer = &gIOMemoryDescriptorMetaClass, |
| 285 | .version = 1, |
| 286 | .instanceSize = sizeof(IOMemoryDescriptor), |
| 287 | |
| 288 | .New = &IOMemoryDescriptor_New, |
| 289 | }; |
| 290 | |
| 291 | extern const void * const |
| 292 | gIOMemoryDescriptor_Declaration; |
| 293 | const void * const |
| 294 | gIOMemoryDescriptor_Declaration |
| 295 | __attribute__((visibility("hidden" ),section("__DATA_CONST,__osclassinfo,regular,no_dead_strip" ),no_sanitize("address" ))) |
| 296 | = &IOMemoryDescriptor_Class; |
| 297 | |
| 298 | static kern_return_t |
| 299 | IOMemoryDescriptor_New(OSMetaClass * instance) |
| 300 | { |
| 301 | if (!new(instance) IOMemoryDescriptorMetaClass) return (kIOReturnNoMemory); |
| 302 | return (kIOReturnSuccess); |
| 303 | } |
| 304 | |
| 305 | kern_return_t |
| 306 | IOMemoryDescriptorMetaClass::New(OSObject * instance) |
| 307 | { |
| 308 | if (!new(instance) IOMemoryDescriptor) return (kIOReturnNoMemory); |
| 309 | return (kIOReturnSuccess); |
| 310 | } |
| 311 | |
| 312 | #endif /* !KERNEL */ |
| 313 | |
| 314 | kern_return_t |
| 315 | IOMemoryDescriptor::Dispatch(const IORPC rpc) |
| 316 | { |
| 317 | return _Dispatch(self: this, rpc); |
| 318 | } |
| 319 | |
| 320 | kern_return_t |
| 321 | IOMemoryDescriptor::_Dispatch(IOMemoryDescriptor * self, const IORPC rpc) |
| 322 | { |
| 323 | kern_return_t ret = kIOReturnUnsupported; |
| 324 | IORPCMessage * msg = IORPCMessageFromMach(msg: rpc.message, reply: false); |
| 325 | |
| 326 | switch (msg->msgid) |
| 327 | { |
| 328 | #if KERNEL |
| 329 | case IOMemoryDescriptor__CopyState_ID: |
| 330 | { |
| 331 | ret = IOMemoryDescriptor::_CopyState_Invoke(rpc, target: self, SimpleMemberFunctionCast(IOMemoryDescriptor::_CopyState_Handler, *self, &IOMemoryDescriptor::_CopyState_Impl)); |
| 332 | break; |
| 333 | } |
| 334 | #endif /* !KERNEL */ |
| 335 | #if KERNEL |
| 336 | case IOMemoryDescriptor_CreateMapping_ID: |
| 337 | { |
| 338 | ret = IOMemoryDescriptor::CreateMapping_Invoke(rpc, target: self, SimpleMemberFunctionCast(IOMemoryDescriptor::CreateMapping_Handler, *self, &IOMemoryDescriptor::CreateMapping_Impl)); |
| 339 | break; |
| 340 | } |
| 341 | #endif /* !KERNEL */ |
| 342 | |
| 343 | default: |
| 344 | ret = OSObject::_Dispatch(self, rpc); |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | return (ret); |
| 349 | } |
| 350 | |
| 351 | #if KERNEL |
| 352 | kern_return_t |
| 353 | IOMemoryDescriptor::MetaClass::Dispatch(const IORPC rpc) |
| 354 | { |
| 355 | #else /* KERNEL */ |
| 356 | kern_return_t |
| 357 | IOMemoryDescriptorMetaClass::Dispatch(const IORPC rpc) |
| 358 | { |
| 359 | #endif /* !KERNEL */ |
| 360 | |
| 361 | kern_return_t ret = kIOReturnUnsupported; |
| 362 | IORPCMessage * msg = IORPCMessageFromMach(msg: rpc.message, reply: false); |
| 363 | |
| 364 | switch (msg->msgid) |
| 365 | { |
| 366 | #if KERNEL |
| 367 | case IOMemoryDescriptor_CreateSubMemoryDescriptor_ID: |
| 368 | ret = IOMemoryDescriptor::CreateSubMemoryDescriptor_Invoke(rpc, func: &IOMemoryDescriptor::CreateSubMemoryDescriptor_Impl); |
| 369 | break; |
| 370 | #endif /* !KERNEL */ |
| 371 | #if KERNEL |
| 372 | case IOMemoryDescriptor_CreateWithMemoryDescriptors_ID: |
| 373 | ret = IOMemoryDescriptor::CreateWithMemoryDescriptors_Invoke(rpc, func: &IOMemoryDescriptor::CreateWithMemoryDescriptors_Impl); |
| 374 | break; |
| 375 | #endif /* !KERNEL */ |
| 376 | |
| 377 | default: |
| 378 | ret = OSMetaClassBase::Dispatch(rpc); |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | return (ret); |
| 383 | } |
| 384 | |
| 385 | kern_return_t |
| 386 | IOMemoryDescriptor::_CopyState( |
| 387 | _IOMDPrivateState * state, |
| 388 | OSDispatchMethod supermethod) |
| 389 | { |
| 390 | kern_return_t ret; |
| 391 | union |
| 392 | { |
| 393 | IOMemoryDescriptor__CopyState_Msg msg; |
| 394 | struct |
| 395 | { |
| 396 | IOMemoryDescriptor__CopyState_Rpl rpl; |
| 397 | mach_msg_max_trailer_t trailer; |
| 398 | } rpl; |
| 399 | } buf; |
| 400 | struct IOMemoryDescriptor__CopyState_Msg * msg = &buf.msg; |
| 401 | struct IOMemoryDescriptor__CopyState_Rpl * rpl = &buf.rpl.rpl; |
| 402 | |
| 403 | memset(s: msg, c: 0, n: sizeof(struct IOMemoryDescriptor__CopyState_Msg)); |
| 404 | msg->mach.msgh.msgh_id = kIORPCVersion190615; |
| 405 | msg->mach.msgh.msgh_size = sizeof(*msg); |
| 406 | msg->content.__hdr.flags = 0*kIORPCMessageOneway |
| 407 | | 1*kIORPCMessageSimpleReply |
| 408 | | 0*kIORPCMessageLocalHost |
| 409 | | 0*kIORPCMessageOnqueue; |
| 410 | msg->content.__hdr.msgid = IOMemoryDescriptor__CopyState_ID; |
| 411 | msg->content.__object = (OSObjectRef) this; |
| 412 | msg->content.__hdr.objectRefs = IOMemoryDescriptor__CopyState_Msg_ObjRefs; |
| 413 | msg->mach.msgh_body.msgh_descriptor_count = 1; |
| 414 | |
| 415 | msg->__object__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 416 | |
| 417 | IORPC rpc = { .message = &buf.msg.mach, .reply = &buf.rpl.rpl.mach, .sendSize = sizeof(buf.msg), .replySize = sizeof(buf.rpl) }; |
| 418 | if (supermethod) ret = supermethod((OSObject *)this, rpc); |
| 419 | else ret = ((OSObject *)this)->Invoke(rpc); |
| 420 | |
| 421 | if (kIOReturnSuccess == ret) |
| 422 | do { |
| 423 | { |
| 424 | if (rpl->mach.msgh.msgh_size != sizeof(*rpl)) { ret = kIOReturnIPCError; break; }; |
| 425 | if (rpl->content.__hdr.msgid != IOMemoryDescriptor__CopyState_ID) { ret = kIOReturnIPCError; break; }; |
| 426 | if (rpl->mach.msgh_body.msgh_descriptor_count != 0) { ret = kIOReturnIPCError; break; }; |
| 427 | if (IOMemoryDescriptor__CopyState_Rpl_ObjRefs != rpl->content.__hdr.objectRefs) { ret = kIOReturnIPCError; break; }; |
| 428 | } |
| 429 | } |
| 430 | while (false); |
| 431 | if (kIOReturnSuccess == ret) |
| 432 | { |
| 433 | if (state) *state = rpl->content.state; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | return (ret); |
| 438 | } |
| 439 | |
| 440 | kern_return_t |
| 441 | IOMemoryDescriptor::CreateMapping( |
| 442 | uint64_t options, |
| 443 | uint64_t address, |
| 444 | uint64_t offset, |
| 445 | uint64_t length, |
| 446 | uint64_t alignment, |
| 447 | IOMemoryMap ** map, |
| 448 | OSDispatchMethod supermethod) |
| 449 | { |
| 450 | kern_return_t ret; |
| 451 | union |
| 452 | { |
| 453 | IOMemoryDescriptor_CreateMapping_Msg msg; |
| 454 | struct |
| 455 | { |
| 456 | IOMemoryDescriptor_CreateMapping_Rpl rpl; |
| 457 | mach_msg_max_trailer_t trailer; |
| 458 | } rpl; |
| 459 | } buf; |
| 460 | struct IOMemoryDescriptor_CreateMapping_Msg * msg = &buf.msg; |
| 461 | struct IOMemoryDescriptor_CreateMapping_Rpl * rpl = &buf.rpl.rpl; |
| 462 | |
| 463 | memset(s: msg, c: 0, n: sizeof(struct IOMemoryDescriptor_CreateMapping_Msg)); |
| 464 | msg->mach.msgh.msgh_id = kIORPCVersion190615; |
| 465 | msg->mach.msgh.msgh_size = sizeof(*msg); |
| 466 | msg->content.__hdr.flags = 0*kIORPCMessageOneway |
| 467 | | 0*kIORPCMessageSimpleReply |
| 468 | | 0*kIORPCMessageLocalHost |
| 469 | | 0*kIORPCMessageOnqueue; |
| 470 | msg->content.__hdr.msgid = IOMemoryDescriptor_CreateMapping_ID; |
| 471 | msg->content.__object = (OSObjectRef) this; |
| 472 | msg->content.__hdr.objectRefs = IOMemoryDescriptor_CreateMapping_Msg_ObjRefs; |
| 473 | msg->mach.msgh_body.msgh_descriptor_count = 1; |
| 474 | |
| 475 | msg->__object__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 476 | |
| 477 | msg->content.options = options; |
| 478 | |
| 479 | msg->content.address = address; |
| 480 | |
| 481 | msg->content.offset = offset; |
| 482 | |
| 483 | msg->content.length = length; |
| 484 | |
| 485 | msg->content.alignment = alignment; |
| 486 | |
| 487 | IORPC rpc = { .message = &buf.msg.mach, .reply = &buf.rpl.rpl.mach, .sendSize = sizeof(buf.msg), .replySize = sizeof(buf.rpl) }; |
| 488 | if (supermethod) ret = supermethod((OSObject *)this, rpc); |
| 489 | else ret = ((OSObject *)this)->Invoke(rpc); |
| 490 | |
| 491 | if (kIOReturnSuccess == ret) |
| 492 | do { |
| 493 | { |
| 494 | if (rpl->mach.msgh.msgh_size != sizeof(*rpl)) { ret = kIOReturnIPCError; break; }; |
| 495 | if (rpl->content.__hdr.msgid != IOMemoryDescriptor_CreateMapping_ID) { ret = kIOReturnIPCError; break; }; |
| 496 | if (rpl->mach.msgh_body.msgh_descriptor_count != 1) { ret = kIOReturnIPCError; break; }; |
| 497 | if (IOMemoryDescriptor_CreateMapping_Rpl_ObjRefs != rpl->content.__hdr.objectRefs) { ret = kIOReturnIPCError; break; }; |
| 498 | } |
| 499 | } |
| 500 | while (false); |
| 501 | if (kIOReturnSuccess == ret) |
| 502 | { |
| 503 | *map = OSDynamicCast(IOMemoryMap, (OSObject *) rpl->content.map); |
| 504 | if (rpl->content.map && !*map) ret = kIOReturnBadArgument; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | return (ret); |
| 509 | } |
| 510 | |
| 511 | kern_return_t |
| 512 | IOMemoryDescriptor::CreateSubMemoryDescriptor( |
| 513 | uint64_t memoryDescriptorCreateOptions, |
| 514 | uint64_t offset, |
| 515 | uint64_t length, |
| 516 | IOMemoryDescriptor * ofDescriptor, |
| 517 | IOMemoryDescriptor ** memory) |
| 518 | { |
| 519 | kern_return_t ret; |
| 520 | union |
| 521 | { |
| 522 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg msg; |
| 523 | struct |
| 524 | { |
| 525 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl rpl; |
| 526 | mach_msg_max_trailer_t trailer; |
| 527 | } rpl; |
| 528 | } buf; |
| 529 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg * msg = &buf.msg; |
| 530 | struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl * rpl = &buf.rpl.rpl; |
| 531 | |
| 532 | memset(s: msg, c: 0, n: sizeof(struct IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg)); |
| 533 | msg->mach.msgh.msgh_id = kIORPCVersion190615; |
| 534 | msg->mach.msgh.msgh_size = sizeof(*msg); |
| 535 | msg->content.__hdr.flags = 0*kIORPCMessageOneway |
| 536 | | 0*kIORPCMessageSimpleReply |
| 537 | | 0*kIORPCMessageLocalHost |
| 538 | | 0*kIORPCMessageOnqueue; |
| 539 | msg->content.__hdr.msgid = IOMemoryDescriptor_CreateSubMemoryDescriptor_ID; |
| 540 | msg->content.__object = (OSObjectRef) OSTypeID(IOMemoryDescriptor); |
| 541 | msg->content.__hdr.objectRefs = IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg_ObjRefs; |
| 542 | msg->mach.msgh_body.msgh_descriptor_count = 2; |
| 543 | |
| 544 | msg->__object__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 545 | |
| 546 | msg->content.memoryDescriptorCreateOptions = memoryDescriptorCreateOptions; |
| 547 | |
| 548 | msg->content.offset = offset; |
| 549 | |
| 550 | msg->content.length = length; |
| 551 | |
| 552 | msg->ofDescriptor__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 553 | msg->content.ofDescriptor = (OSObjectRef) ofDescriptor; |
| 554 | |
| 555 | IORPC rpc = { .message = &buf.msg.mach, .reply = &buf.rpl.rpl.mach, .sendSize = sizeof(buf.msg), .replySize = sizeof(buf.rpl) }; |
| 556 | ret = OSMTypeID(IOMemoryDescriptor)->Invoke(rpc); |
| 557 | |
| 558 | if (kIOReturnSuccess == ret) |
| 559 | do { |
| 560 | { |
| 561 | if (rpl->mach.msgh.msgh_size != sizeof(*rpl)) { ret = kIOReturnIPCError; break; }; |
| 562 | if (rpl->content.__hdr.msgid != IOMemoryDescriptor_CreateSubMemoryDescriptor_ID) { ret = kIOReturnIPCError; break; }; |
| 563 | if (rpl->mach.msgh_body.msgh_descriptor_count != 1) { ret = kIOReturnIPCError; break; }; |
| 564 | if (IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl_ObjRefs != rpl->content.__hdr.objectRefs) { ret = kIOReturnIPCError; break; }; |
| 565 | } |
| 566 | } |
| 567 | while (false); |
| 568 | if (kIOReturnSuccess == ret) |
| 569 | { |
| 570 | *memory = OSDynamicCast(IOMemoryDescriptor, (OSObject *) rpl->content.memory); |
| 571 | if (rpl->content.memory && !*memory) ret = kIOReturnBadArgument; |
| 572 | } |
| 573 | |
| 574 | |
| 575 | return (ret); |
| 576 | } |
| 577 | |
| 578 | kern_return_t |
| 579 | IOMemoryDescriptor::CreateWithMemoryDescriptors( |
| 580 | uint64_t memoryDescriptorCreateOptions, |
| 581 | uint32_t withDescriptorsCount, |
| 582 | IOMemoryDescriptor ** const withDescriptors, |
| 583 | IOMemoryDescriptor ** memory) |
| 584 | { |
| 585 | kern_return_t ret; |
| 586 | union |
| 587 | { |
| 588 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg msg; |
| 589 | struct |
| 590 | { |
| 591 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl rpl; |
| 592 | mach_msg_max_trailer_t trailer; |
| 593 | } rpl; |
| 594 | } buf; |
| 595 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg * msg = &buf.msg; |
| 596 | struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl * rpl = &buf.rpl.rpl; |
| 597 | |
| 598 | memset(s: msg, c: 0, n: sizeof(struct IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg)); |
| 599 | msg->mach.msgh.msgh_id = kIORPCVersion190615; |
| 600 | msg->mach.msgh.msgh_size = sizeof(*msg); |
| 601 | msg->content.__hdr.flags = 0*kIORPCMessageOneway |
| 602 | | 0*kIORPCMessageSimpleReply |
| 603 | | 0*kIORPCMessageLocalHost |
| 604 | | 0*kIORPCMessageOnqueue; |
| 605 | msg->content.__hdr.msgid = IOMemoryDescriptor_CreateWithMemoryDescriptors_ID; |
| 606 | msg->content.__object = (OSObjectRef) OSTypeID(IOMemoryDescriptor); |
| 607 | msg->content.__hdr.objectRefs = IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg_ObjRefs; |
| 608 | msg->mach.msgh_body.msgh_descriptor_count = 33; |
| 609 | |
| 610 | msg->__object__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 611 | |
| 612 | msg->content.memoryDescriptorCreateOptions = memoryDescriptorCreateOptions; |
| 613 | |
| 614 | msg->content.withDescriptorsCount = withDescriptorsCount; |
| 615 | |
| 616 | for (unsigned int idx = 0; idx < 32; idx++) msg->withDescriptors__descriptor[idx].type = MACH_MSG_PORT_DESCRIPTOR; |
| 617 | if (withDescriptorsCount > (sizeof(msg->content.__withDescriptors) / sizeof(msg->content.__withDescriptors[0]))) return kIOReturnOverrun; |
| 618 | bcopy(src: withDescriptors, dst: &msg->content.__withDescriptors[0], n: withDescriptorsCount * sizeof(msg->content.__withDescriptors[0])); |
| 619 | |
| 620 | IORPC rpc = { .message = &buf.msg.mach, .reply = &buf.rpl.rpl.mach, .sendSize = sizeof(buf.msg), .replySize = sizeof(buf.rpl) }; |
| 621 | ret = OSMTypeID(IOMemoryDescriptor)->Invoke(rpc); |
| 622 | |
| 623 | if (kIOReturnSuccess == ret) |
| 624 | do { |
| 625 | { |
| 626 | if (rpl->mach.msgh.msgh_size != sizeof(*rpl)) { ret = kIOReturnIPCError; break; }; |
| 627 | if (rpl->content.__hdr.msgid != IOMemoryDescriptor_CreateWithMemoryDescriptors_ID) { ret = kIOReturnIPCError; break; }; |
| 628 | if (rpl->mach.msgh_body.msgh_descriptor_count != 1) { ret = kIOReturnIPCError; break; }; |
| 629 | if (IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl_ObjRefs != rpl->content.__hdr.objectRefs) { ret = kIOReturnIPCError; break; }; |
| 630 | } |
| 631 | } |
| 632 | while (false); |
| 633 | if (kIOReturnSuccess == ret) |
| 634 | { |
| 635 | *memory = OSDynamicCast(IOMemoryDescriptor, (OSObject *) rpl->content.memory); |
| 636 | if (rpl->content.memory && !*memory) ret = kIOReturnBadArgument; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | return (ret); |
| 641 | } |
| 642 | |
| 643 | kern_return_t |
| 644 | IOMemoryDescriptor::_CopyState_Invoke(const IORPC _rpc, |
| 645 | OSMetaClassBase * target, |
| 646 | _CopyState_Handler func) |
| 647 | { |
| 648 | IOMemoryDescriptor__CopyState_Invocation rpc = { .rpc: _rpc }; |
| 649 | kern_return_t ret; |
| 650 | |
| 651 | if (1 != rpc.message->mach.msgh_body.msgh_descriptor_count) return (kIOReturnIPCError); |
| 652 | if (IOMemoryDescriptor__CopyState_Msg_ObjRefs != rpc.message->content.__hdr.objectRefs) return (kIOReturnIPCError); |
| 653 | if (rpc.message != NULL && rpc.sendSize < sizeof(IOMemoryDescriptor__CopyState_Msg)) return (kIOReturnIPCError); |
| 654 | if (rpc.reply != NULL && rpc.replySize < sizeof(IOMemoryDescriptor__CopyState_Rpl)) return (kIOReturnIPCError); |
| 655 | |
| 656 | ret = (*func)(target, |
| 657 | &rpc.reply->content.state); |
| 658 | |
| 659 | if (kIOReturnSuccess != ret) return (ret); |
| 660 | |
| 661 | rpc.reply->content.__hdr.msgid = IOMemoryDescriptor__CopyState_ID; |
| 662 | rpc.reply->content.__hdr.flags = kIORPCMessageOneway; |
| 663 | rpc.reply->mach.msgh.msgh_id = kIORPCVersion190615Reply; |
| 664 | rpc.reply->mach.msgh.msgh_size = sizeof(*rpc.reply); |
| 665 | rpc.reply->mach.msgh_body.msgh_descriptor_count = 0; |
| 666 | rpc.reply->content.__hdr.objectRefs = IOMemoryDescriptor__CopyState_Rpl_ObjRefs; |
| 667 | |
| 668 | return (ret); |
| 669 | } |
| 670 | |
| 671 | kern_return_t |
| 672 | IOMemoryDescriptor::CreateMapping_Invoke(const IORPC _rpc, |
| 673 | OSMetaClassBase * target, |
| 674 | CreateMapping_Handler func) |
| 675 | { |
| 676 | IOMemoryDescriptor_CreateMapping_Invocation rpc = { .rpc: _rpc }; |
| 677 | kern_return_t ret; |
| 678 | |
| 679 | if (1 != rpc.message->mach.msgh_body.msgh_descriptor_count) return (kIOReturnIPCError); |
| 680 | if (IOMemoryDescriptor_CreateMapping_Msg_ObjRefs != rpc.message->content.__hdr.objectRefs) return (kIOReturnIPCError); |
| 681 | if (rpc.message != NULL && rpc.sendSize < sizeof(IOMemoryDescriptor_CreateMapping_Msg)) return (kIOReturnIPCError); |
| 682 | if (rpc.reply != NULL && rpc.replySize < sizeof(IOMemoryDescriptor_CreateMapping_Rpl)) return (kIOReturnIPCError); |
| 683 | |
| 684 | ret = (*func)(target, |
| 685 | rpc.message->content.options, |
| 686 | rpc.message->content.address, |
| 687 | rpc.message->content.offset, |
| 688 | rpc.message->content.length, |
| 689 | rpc.message->content.alignment, |
| 690 | (IOMemoryMap **)&rpc.reply->content.map); |
| 691 | |
| 692 | if (kIOReturnSuccess != ret) return (ret); |
| 693 | |
| 694 | rpc.reply->content.__hdr.msgid = IOMemoryDescriptor_CreateMapping_ID; |
| 695 | rpc.reply->content.__hdr.flags = kIORPCMessageOneway; |
| 696 | rpc.reply->mach.msgh.msgh_id = kIORPCVersion190615Reply; |
| 697 | rpc.reply->mach.msgh.msgh_size = sizeof(*rpc.reply); |
| 698 | rpc.reply->mach.msgh_body.msgh_descriptor_count = 1; |
| 699 | rpc.reply->content.__hdr.objectRefs = IOMemoryDescriptor_CreateMapping_Rpl_ObjRefs; |
| 700 | rpc.reply->map__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 701 | |
| 702 | return (ret); |
| 703 | } |
| 704 | |
| 705 | kern_return_t |
| 706 | IOMemoryDescriptor::CreateSubMemoryDescriptor_Invoke(const IORPC _rpc, |
| 707 | CreateSubMemoryDescriptor_Handler func) |
| 708 | { |
| 709 | IOMemoryDescriptor_CreateSubMemoryDescriptor_Invocation rpc = { .rpc: _rpc }; |
| 710 | kern_return_t ret; |
| 711 | IOMemoryDescriptor * ofDescriptor; |
| 712 | |
| 713 | if (2 != rpc.message->mach.msgh_body.msgh_descriptor_count) return (kIOReturnIPCError); |
| 714 | if (IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg_ObjRefs != rpc.message->content.__hdr.objectRefs) return (kIOReturnIPCError); |
| 715 | if (rpc.message != NULL && rpc.sendSize < sizeof(IOMemoryDescriptor_CreateSubMemoryDescriptor_Msg)) return (kIOReturnIPCError); |
| 716 | if (rpc.reply != NULL && rpc.replySize < sizeof(IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl)) return (kIOReturnIPCError); |
| 717 | ofDescriptor = OSDynamicCast(IOMemoryDescriptor, (OSObject *) rpc.message->content.ofDescriptor); |
| 718 | if (!ofDescriptor && rpc.message->content.ofDescriptor) return (kIOReturnBadArgument); |
| 719 | |
| 720 | ret = (*func)( rpc.message->content.memoryDescriptorCreateOptions, |
| 721 | rpc.message->content.offset, |
| 722 | rpc.message->content.length, |
| 723 | ofDescriptor, |
| 724 | (IOMemoryDescriptor **)&rpc.reply->content.memory); |
| 725 | |
| 726 | if (kIOReturnSuccess != ret) return (ret); |
| 727 | |
| 728 | rpc.reply->content.__hdr.msgid = IOMemoryDescriptor_CreateSubMemoryDescriptor_ID; |
| 729 | rpc.reply->content.__hdr.flags = kIORPCMessageOneway; |
| 730 | rpc.reply->mach.msgh.msgh_id = kIORPCVersion190615Reply; |
| 731 | rpc.reply->mach.msgh.msgh_size = sizeof(*rpc.reply); |
| 732 | rpc.reply->mach.msgh_body.msgh_descriptor_count = 1; |
| 733 | rpc.reply->content.__hdr.objectRefs = IOMemoryDescriptor_CreateSubMemoryDescriptor_Rpl_ObjRefs; |
| 734 | rpc.reply->memory__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 735 | |
| 736 | return (ret); |
| 737 | } |
| 738 | |
| 739 | kern_return_t |
| 740 | IOMemoryDescriptor::CreateWithMemoryDescriptors_Invoke(const IORPC _rpc, |
| 741 | CreateWithMemoryDescriptors_Handler func) |
| 742 | { |
| 743 | IOMemoryDescriptor_CreateWithMemoryDescriptors_Invocation rpc = { .rpc: _rpc }; |
| 744 | kern_return_t ret; |
| 745 | uint32_t withDescriptorsCount = (sizeof(rpc.message->content.__withDescriptors) / sizeof(rpc.message->content.__withDescriptors[0])); |
| 746 | if (withDescriptorsCount > rpc.message->content.withDescriptorsCount) withDescriptorsCount = rpc.message->content.withDescriptorsCount; |
| 747 | #if !__LP64__ |
| 748 | IOMemoryDescriptor * withDescriptors[32] = {}; |
| 749 | #else /* !__LP64__ */ |
| 750 | IOMemoryDescriptor ** withDescriptors; |
| 751 | #endif /* __LP64__ */ |
| 752 | |
| 753 | if (33 != rpc.message->mach.msgh_body.msgh_descriptor_count) return (kIOReturnIPCError); |
| 754 | if (IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg_ObjRefs != rpc.message->content.__hdr.objectRefs) return (kIOReturnIPCError); |
| 755 | if (rpc.message != NULL && rpc.sendSize < sizeof(IOMemoryDescriptor_CreateWithMemoryDescriptors_Msg)) return (kIOReturnIPCError); |
| 756 | if (rpc.reply != NULL && rpc.replySize < sizeof(IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl)) return (kIOReturnIPCError); |
| 757 | #if !__LP64__ |
| 758 | for (unsigned int idx = 0; idx < withDescriptorsCount; idx++) |
| 759 | { |
| 760 | withDescriptors[idx] = (IOMemoryDescriptor *)(uintptr_t)rpc.message->content.__withDescriptors[idx]; |
| 761 | } |
| 762 | #else /* !__LP64__ */ |
| 763 | withDescriptors = (IOMemoryDescriptor **)(uintptr_t) &rpc.message->content.__withDescriptors[0]; |
| 764 | #endif /* __LP64__ */ |
| 765 | for (unsigned int idx = 0; idx < withDescriptorsCount; idx++) |
| 766 | { |
| 767 | if (withDescriptors[idx] && !OSDynamicCast(IOMemoryDescriptor, withDescriptors[idx])) return (kIOReturnBadArgument); |
| 768 | } |
| 769 | |
| 770 | ret = (*func)( rpc.message->content.memoryDescriptorCreateOptions, |
| 771 | withDescriptorsCount, |
| 772 | withDescriptors, |
| 773 | (IOMemoryDescriptor **)&rpc.reply->content.memory); |
| 774 | |
| 775 | if (kIOReturnSuccess != ret) return (ret); |
| 776 | |
| 777 | rpc.reply->content.__hdr.msgid = IOMemoryDescriptor_CreateWithMemoryDescriptors_ID; |
| 778 | rpc.reply->content.__hdr.flags = kIORPCMessageOneway; |
| 779 | rpc.reply->mach.msgh.msgh_id = kIORPCVersion190615Reply; |
| 780 | rpc.reply->mach.msgh.msgh_size = sizeof(*rpc.reply); |
| 781 | rpc.reply->mach.msgh_body.msgh_descriptor_count = 1; |
| 782 | rpc.reply->content.__hdr.objectRefs = IOMemoryDescriptor_CreateWithMemoryDescriptors_Rpl_ObjRefs; |
| 783 | rpc.reply->memory__descriptor.type = MACH_MSG_PORT_DESCRIPTOR; |
| 784 | |
| 785 | return (ret); |
| 786 | } |
| 787 | |
| 788 | |
| 789 | |
| 790 | |