]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ipc/mach_msg.c
xnu-2782.1.97.tar.gz
[apple/xnu.git] / osfmk / ipc / mach_msg.c
index af1ce5928ea93dfa5ffb6e4d49c2eb892f3cb504..a12c7091944902f024593a116e3c1c52c926c650 100644 (file)
@@ -85,7 +85,6 @@
 #include <kern/ipc_mig.h>
 #include <kern/task.h>
 #include <kern/thread.h>
-#include <kern/lock.h>
 #include <kern/sched_prim.h>
 #include <kern/exception.h>
 #include <kern/misc_protos.h>
 #include <ipc/ipc_pset.h>
 #include <ipc/ipc_space.h>
 #include <ipc/ipc_entry.h>
+#include <ipc/ipc_importance.h>
 
 #include <machine/machine_routines.h>
 #include <security/mac_mach_internal.h>
@@ -312,54 +312,25 @@ mach_msg_receive_results(void)
              if (copyout((char *) &self->ith_msize,
                          msg_addr + offsetof(mach_msg_user_header_t, msgh_size),
                          sizeof(mach_msg_size_t)))
-               mr = MACH_RCV_INVALID_DATA;
-             goto out;
+               mr = MACH_RCV_INVALID_DATA;
+           } else {
+
+               /* discard importance in message */
+               ipc_importance_clean(kmsg);
+
+               if (msg_receive_error(kmsg, msg_addr, option, seqno, space)
+                   == MACH_RCV_INVALID_DATA)
+                   mr = MACH_RCV_INVALID_DATA;
            }
-                 
-           if (msg_receive_error(kmsg, msg_addr, option, seqno, space)
-               == MACH_RCV_INVALID_DATA)
-             mr = MACH_RCV_INVALID_DATA;
          }
-         goto out;
+         return mr;
        }
 
 #if IMPORTANCE_INHERITANCE
-       if ((kmsg->ikm_header->msgh_bits & MACH_MSGH_BITS_RAISEIMP) != 0) {
-               __unused int impresult;
-               int sender_pid = -1;
-#if IMPORTANCE_DEBUG
-               sender_pid = ((mach_msg_max_trailer_t *)
-                       ((vm_offset_t)kmsg->ikm_header + round_msg(kmsg->ikm_header->msgh_size)))->msgh_audit.val[5];
-#endif /* IMPORTANCE_DEBUG */
-               ipc_port_t port = kmsg->ikm_header->msgh_remote_port;
-               task_t task_self = current_task();
-
-               ip_lock(port);
-               assert(port->ip_impcount > 0);
-               port->ip_impcount--;
-               ip_unlock(port);
-
-               if (task_self->imp_receiver == 0) {
-                       /*
-                        * The task was never ready to receive importance boost, remove msghbit.
-                        * This can happen when a receive right (which has donor messages) is copied
-                        * out to a non-imp_receiver task (we don't clear the bits on the messages,
-                        * but we did't transfer any boost counts either).
-                        */
-                       kmsg->ikm_header->msgh_bits &= ~MACH_MSGH_BITS_RAISEIMP;
-                       impresult = 0;
-               } else {
-                       /* user will accept responsibility for the importance boost */
-                       task_importance_externalize_assertion(task_self, 1, sender_pid);
-                       impresult = 1;
-               }
 
-#if IMPORTANCE_DEBUG
-               KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, (IMPORTANCE_CODE(IMP_MSG, IMP_MSG_DELV)) | DBG_FUNC_NONE,
-                       sender_pid, audit_token_pid_from_task(task_self),
-                       kmsg->ikm_header->msgh_id, impresult, 0);
-#endif /* IMPORTANCE_DEBUG */
-       }
+       /* adopt/transform any importance attributes carried in the message */
+       ipc_importance_receive(kmsg, option);
+
 #endif  /* IMPORTANCE_INHERITANCE */
 
        trailer_size = ipc_kmsg_add_trailer(kmsg, space, option, self, seqno, FALSE, 
@@ -375,13 +346,16 @@ mach_msg_receive_results(void)
                mach_msg_body_t *slist;
 
                slist = ipc_kmsg_get_scatter(msg_addr, slist_size, kmsg);
-               mr = ipc_kmsg_copyout(kmsg, space, map, slist);
+               mr = ipc_kmsg_copyout(kmsg, space, map, slist, option);
                ipc_kmsg_free_scatter(slist, slist_size);
        } else {
-               mr = ipc_kmsg_copyout(kmsg, space, map, MACH_MSG_BODY_NULL);
+               mr = ipc_kmsg_copyout(kmsg, space, map, MACH_MSG_BODY_NULL, option);
        }
 
        if (mr != MACH_MSG_SUCCESS) {
+               /* already received importance, so have to undo that here */
+               ipc_importance_unreceive(kmsg, option);
+
                if ((mr &~ MACH_MSG_MASK) == MACH_RCV_BODY_ERROR) {
                        if (ipc_kmsg_put(msg_addr, kmsg, kmsg->ikm_header->msgh_size +
                           trailer_size) == MACH_RCV_INVALID_DATA)
@@ -392,13 +366,13 @@ mach_msg_receive_results(void)
                                                == MACH_RCV_INVALID_DATA)
                                mr = MACH_RCV_INVALID_DATA;
                }
-               goto out;
+       } else {
+               mr = ipc_kmsg_put(msg_addr,
+                                 kmsg,
+                                 kmsg->ikm_header->msgh_size + 
+                                 trailer_size);
        }
-       mr = ipc_kmsg_put(msg_addr,
-                         kmsg,
-                         kmsg->ikm_header->msgh_size + 
-                         trailer_size);
- out:
+
        return mr;
 }