- mr = ipc_kmsg_get_from_kernel(msg, send_size, &kmsg);
- if (mr != MACH_MSG_SUCCESS)
- panic("mach_msg");
+ mach_msg_size_t msg_and_trailer_size;
+ mach_msg_max_trailer_t *max_trailer;
+
+ if ((send_size < sizeof(mach_msg_header_t)) || (send_size & 3))
+ return MACH_SEND_MSG_TOO_SMALL;
+
+ if (send_size > MACH_MSG_SIZE_MAX - MAX_TRAILER_SIZE)
+ return MACH_SEND_TOO_LARGE;
+
+ msg_and_trailer_size = send_size + MAX_TRAILER_SIZE;
+ kmsg = ipc_kmsg_alloc(msg_and_trailer_size);
+
+ if (kmsg == IKM_NULL)
+ return MACH_SEND_NO_BUFFER;
+
+ (void) memcpy((void *) kmsg->ikm_header, (const void *) msg, send_size);
+
+ kmsg->ikm_header->msgh_size = send_size;