- /*
- * XXXXX Set manually for now ...
- * No, why even bother, since the effort is wasted?
- *
- { mach_msg_format_0_trailer_t *trailer = (mach_msg_format_0_trailer_t *)
- ((vm_offset_t)&kmsg->ikm_header + kmsg->ikm_header.msgh_size);
- trailer->msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
- trailer->msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
+ /*
+ * Check to see how much of the message/trailer can be received.
+ * We chose the maximum trailer that will fit, since we don't
+ * have options telling us which trailer elements the caller needed.
+ */
+ if (rcv_size >= kmsg->ikm_header->msgh_size) {
+ mach_msg_format_0_trailer_t *trailer = (mach_msg_format_0_trailer_t *)
+ ((vm_offset_t)kmsg->ikm_header + kmsg->ikm_header->msgh_size);
+
+ if (rcv_size >= kmsg->ikm_header->msgh_size + MAX_TRAILER_SIZE) {
+ /* Enough room for a maximum trailer */
+ trailer->msgh_trailer_size = MAX_TRAILER_SIZE;
+ }
+ else if (rcv_size < kmsg->ikm_header->msgh_size +
+ trailer->msgh_trailer_size) {
+ /* no room for even the basic (default) trailer */
+ trailer->msgh_trailer_size = 0;
+ }
+ assert(trailer->msgh_trailer_type == MACH_MSG_TRAILER_FORMAT_0);
+ rcv_size = kmsg->ikm_header->msgh_size + trailer->msgh_trailer_size;
+ mr = MACH_MSG_SUCCESS;
+ } else {
+ mr = MACH_RCV_TOO_LARGE;