- msg->head.msgh_bits |= MACH_MSGH_BITS_COMPLEX;
- msg->body.msgh_descriptor_count = 1;
- msg->desc.out_of_line.deallocate = false;
- msg->desc.out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
- msg->desc.out_of_line.address = (void *)bytes;
- msg->desc.out_of_line.size = byteslen;
- msg->desc.out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
- }
- return msg;
+ int32_t size = sizeof(struct __CFMessagePortMachMessage1);
+ struct __CFMessagePortMachMessage1 *msg = CFAllocatorAllocate(kCFAllocatorSystemDefault, size, 0);
+ if (!msg) return NULL;
+ memset(msg, 0, size);
+ msg->base.header.msgh_id = convid;
+ msg->base.header.msgh_size = size;
+ msg->base.header.msgh_remote_port = port;
+ msg->base.header.msgh_local_port = replyPort;
+ msg->base.header.msgh_reserved = 0;
+ msg->base.header.msgh_bits = MACH_MSGH_BITS((reply ? MACH_MSG_TYPE_MOVE_SEND_ONCE : MACH_MSG_TYPE_COPY_SEND), (MACH_PORT_NULL != replyPort ? MACH_MSG_TYPE_MAKE_SEND_ONCE : 0));
+ msg->base.header.msgh_bits |= MACH_MSGH_BITS_COMPLEX;
+ msg->base.body.msgh_descriptor_count = 1;
+ msg->magic = MAGIC;
+ msg->msgid = CFSwapInt32HostToLittle(msgid);
+ msg->byteslen = CFSwapInt32HostToLittle(byteslen);
+ msg->ool.deallocate = false;
+ msg->ool.copy = MACH_MSG_VIRTUAL_COPY;
+ msg->ool.address = (void *)bytes;
+ msg->ool.size = byteslen;
+ msg->ool.type = MACH_MSG_OOL_DESCRIPTOR;
+ return (mach_msg_base_t *)msg;
+ }