]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ipc/ipc_kmsg.h
xnu-4903.231.4.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_kmsg.h
index 9ebb1402d043cc206d8eed1b55030d2e3374e84b..f5598615f557d06f84f9f0aafb934a376c74f61a 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
  * any improvements or extensions that they make and grant Carnegie Mellon
  * the rights to redistribute these changes.
  */
+/*
+ * NOTICE: This file was modified by McAfee Research in 2004 to introduce
+ * support for mandatory and extensible security protections.  This notice
+ * is included in support of clause 2.2 (b) of the Apple Public License,
+ * Version 2.0.
+ * Copyright (c) 2005 SPARTA, Inc.
+ */
 /*
  */
 /*
 #ifndef        _IPC_IPC_KMSG_H_
 #define _IPC_IPC_KMSG_H_
 
-#include <cpus.h>
-
 #include <mach/vm_types.h>
 #include <mach/message.h>
+#include <kern/kern_types.h>
 #include <kern/assert.h>
-#include <kern/cpu_number.h>
 #include <kern/macro_help.h>
-#include <kern/kalloc.h>
+#include <ipc/ipc_types.h>
 #include <ipc/ipc_object.h>
+#include <sys/kdebug.h>
 
 /*
  *     This structure is only the header for a kmsg buffer;
  *
  *     The ikm_header.msgh_remote_port field is the destination
  *     of the message.
+ *
+ *     sync_qos and special_port_qos stores the qos for prealloced
+ *     port, this fields could be deleted once we remove ip_prealloc.
  */
 
+struct ipc_kmsg {
+       mach_msg_size_t            ikm_size;
+       struct ipc_kmsg            *ikm_next;        /* next message on port/discard queue */
+       struct ipc_kmsg            *ikm_prev;        /* prev message on port/discard queue */
+       mach_msg_header_t          *ikm_header;
+       ipc_port_t                 ikm_prealloc;     /* port we were preallocated from */
+       ipc_port_t                 ikm_voucher;      /* voucher port carried */
+       mach_msg_priority_t        ikm_qos;          /* qos of this kmsg */
+       mach_msg_priority_t        ikm_qos_override; /* qos override on this kmsg */
+       struct ipc_importance_elem *ikm_importance;  /* inherited from */
+       queue_chain_t              ikm_inheritance;  /* inherited from link */
+       struct turnstile           *ikm_turnstile;   /* send turnstile for ikm_prealloc port */
+#if MACH_FLIPC
+       struct mach_node           *ikm_node;        /* Originating node - needed for ack */
+#endif
+};
 
-typedef struct ipc_kmsg {
-       struct ipc_kmsg *ikm_next;
-       struct ipc_kmsg *ikm_prev;
-       ipc_port_t ikm_prealloc;        /* port we were preallocated from */
-       mach_msg_size_t ikm_size;
-       mach_msg_header_t ikm_header;
-} *ipc_kmsg_t;
-
-#define        IKM_NULL                ((ipc_kmsg_t) 0)
+#if defined(__i386__) || defined(__arm__)
+#define        IKM_SUPPORT_LEGACY      1
+#else
+#define        IKM_SUPPORT_LEGACY      0
+#endif
 
-#define        IKM_OVERHEAD                                                    \
-               (sizeof(struct ipc_kmsg) - sizeof(mach_msg_header_t))
+#define        IKM_OVERHEAD            (sizeof(struct ipc_kmsg))
 
 #define        ikm_plus_overhead(size) ((mach_msg_size_t)((size) + IKM_OVERHEAD))
 #define        ikm_less_overhead(size) ((mach_msg_size_t)((size) - IKM_OVERHEAD))
@@ -108,8 +134,9 @@ typedef struct ipc_kmsg {
  *     The size of the kernel message buffers that will be cached.
  *     IKM_SAVED_KMSG_SIZE includes overhead; IKM_SAVED_MSG_SIZE doesn't.
  */
-
-#define        IKM_SAVED_MSG_SIZE      ikm_less_overhead(256)
+extern zone_t ipc_kmsg_zone;
+#define        IKM_SAVED_KMSG_SIZE     256
+#define        IKM_SAVED_MSG_SIZE      ikm_less_overhead(IKM_SAVED_KMSG_SIZE)
 
 #define        ikm_prealloc_inuse_port(kmsg)                                   \
        ((kmsg)->ikm_prealloc)
@@ -119,8 +146,9 @@ typedef struct ipc_kmsg {
 
 #define        ikm_prealloc_set_inuse(kmsg, port)                              \
 MACRO_BEGIN                                                            \
-       assert(port != IP_NULL);                                        \
-       (kmsg)->ikm_prealloc = port;                                    \
+       assert((port) != IP_NULL);                                      \
+       (kmsg)->ikm_prealloc = (port);                                  \
+       ip_reference(port);                                             \
 MACRO_END
 
 #define ikm_prealloc_clear_inuse(kmsg, port)                           \
@@ -128,12 +156,27 @@ MACRO_BEGIN                                                               \
        (kmsg)->ikm_prealloc = IP_NULL;                                 \
 MACRO_END
 
+#if MACH_FLIPC
+#define ikm_flipc_init(kmsg) (kmsg)->ikm_node = MACH_NODE_NULL
+#else
+#define ikm_flipc_init(kmsg)
+#endif
+
+#define        ikm_init(kmsg, size)                                    \
+MACRO_BEGIN                                                     \
+       (kmsg)->ikm_size = (size);                                  \
+       (kmsg)->ikm_prealloc = IP_NULL;                             \
+       (kmsg)->ikm_voucher = IP_NULL;                              \
+       (kmsg)->ikm_importance = IIE_NULL;                          \
+       ikm_qos_init(kmsg);                                         \
+       ikm_flipc_init(kmsg);                                       \
+       assert((kmsg)->ikm_prev = (kmsg)->ikm_next = IKM_BOGUS);    \
+MACRO_END
 
-#define        ikm_init(kmsg, size)                                            \
-MACRO_BEGIN                                                            \
-       (kmsg)->ikm_size = (size);                                      \
-       (kmsg)->ikm_prealloc = IP_NULL;                                 \
-       assert((kmsg)->ikm_prev = (kmsg)->ikm_next = IKM_BOGUS);        \
+#define ikm_qos_init(kmsg)                                              \
+MACRO_BEGIN                                                             \
+        (kmsg)->ikm_qos = MACH_MSG_PRIORITY_UNSPECIFIED;                \
+        (kmsg)->ikm_qos_override = MACH_MSG_PRIORITY_UNSPECIFIED;       \
 MACRO_END
 
 #define        ikm_check_init(kmsg, size)                                      \
@@ -143,6 +186,12 @@ MACRO_BEGIN                                                                \
        assert((kmsg)->ikm_next == IKM_BOGUS);                          \
 MACRO_END
 
+#define ikm_set_header(kmsg, mtsize)                                   \
+MACRO_BEGIN                                                            \
+       (kmsg)->ikm_header = (mach_msg_header_t *)                      \
+       ((vm_offset_t)((kmsg) + 1) + (kmsg)->ikm_size - (mtsize));      \
+MACRO_END
+
 struct ipc_kmsg_queue {
        struct ipc_kmsg *ikmq_base;
 };
@@ -168,6 +217,15 @@ extern void ipc_kmsg_enqueue(
        ipc_kmsg_queue_t        queue,
        ipc_kmsg_t              kmsg);
 
+extern boolean_t ipc_kmsg_enqueue_qos(
+       ipc_kmsg_queue_t        queue,
+       ipc_kmsg_t              kmsg);
+
+extern boolean_t ipc_kmsg_override_qos(
+       ipc_kmsg_queue_t    queue,
+       ipc_kmsg_t          kmsg,
+       mach_msg_priority_t override);
+
 /* Dequeue and return a kmsg */
 extern ipc_kmsg_t ipc_kmsg_dequeue(
        ipc_kmsg_queue_t        queue);
@@ -177,6 +235,11 @@ extern void ipc_kmsg_rmqueue(
        ipc_kmsg_queue_t        queue,
        ipc_kmsg_t              kmsg);
 
+/* Pull the (given) first kmsg out of a queue */
+extern void ipc_kmsg_rmqueue_first(
+       ipc_kmsg_queue_t        queue,
+       ipc_kmsg_t      kmsg);
+
 #define        ipc_kmsg_queue_first(queue)             ((queue)->ikmq_base)
 
 /* Return the kmsg following the given kmsg */
@@ -184,96 +247,6 @@ extern ipc_kmsg_t ipc_kmsg_queue_next(
        ipc_kmsg_queue_t        queue,
        ipc_kmsg_t              kmsg);
 
-#define        ipc_kmsg_rmqueue_first_macro(queue, kmsg)                       \
-MACRO_BEGIN                                                            \
-       register ipc_kmsg_t _next;                                      \
-                                                                       \
-       assert((queue)->ikmq_base == (kmsg));                           \
-                                                                       \
-       _next = (kmsg)->ikm_next;                                       \
-       if (_next == (kmsg)) {                                          \
-               assert((kmsg)->ikm_prev == (kmsg));                     \
-               (queue)->ikmq_base = IKM_NULL;                          \
-       } else {                                                        \
-               register ipc_kmsg_t _prev = (kmsg)->ikm_prev;           \
-                                                                       \
-               (queue)->ikmq_base = _next;                             \
-               _next->ikm_prev = _prev;                                \
-               _prev->ikm_next = _next;                                \
-       }                                                               \
-       /* XXX Debug paranoia ASSIGNMENTS */                            \
-       assert(kmsg->ikm_next = IKM_BOGUS);                             \
-       assert(kmsg->ikm_prev = IKM_BOGUS);                             \
-MACRO_END
-
-#define        ipc_kmsg_enqueue_macro(queue, kmsg)                             \
-MACRO_BEGIN                                                            \
-       register ipc_kmsg_t _first = (queue)->ikmq_base;                \
-                                                                       \
-       if (_first == IKM_NULL) {                                       \
-               (queue)->ikmq_base = (kmsg);                            \
-               (kmsg)->ikm_next = (kmsg);                              \
-               (kmsg)->ikm_prev = (kmsg);                              \
-       } else {                                                        \
-               register ipc_kmsg_t _last = _first->ikm_prev;           \
-                                                                       \
-               (kmsg)->ikm_next = _first;                              \
-               (kmsg)->ikm_prev = _last;                               \
-               _first->ikm_prev = (kmsg);                              \
-               _last->ikm_next = (kmsg);                               \
-       }                                                               \
-MACRO_END
-
-/* scatter list macros */
-
-#define SKIP_PORT_DESCRIPTORS(s, e)                                    \
-MACRO_BEGIN                                                            \
-       if ((s) != MACH_MSG_DESCRIPTOR_NULL) {                          \
-               while ((s) < (e)) {                                     \
-                       if ((s)->type.type != MACH_MSG_PORT_DESCRIPTOR) \
-                               break;                                  \
-                       (s)++;                                          \
-               }                                                       \
-               if ((s) >= (e))                                         \
-                       (s) = MACH_MSG_DESCRIPTOR_NULL;                 \
-       }                                                               \
-MACRO_END
-
-#define INCREMENT_SCATTER(s)                                           \
-MACRO_BEGIN                                                            \
-       if ((s) != MACH_MSG_DESCRIPTOR_NULL) {                          \
-               (s)++;                                                  \
-       }                                                               \
-MACRO_END
-
-/*
- *     extern void
- *     ipc_kmsg_send_always(ipc_kmsg_t);
- *
- *     Unfortunately, to avoid warnings/lint about unused variables
- *     when assertions are turned off, we need two versions of this.
- */
-#if    MACH_ASSERT
-
-#define        ipc_kmsg_send_always(kmsg)                                      \
-MACRO_BEGIN                                                            \
-       mach_msg_return_t mr;                                           \
-                                                                       \
-       mr = ipc_kmsg_send((kmsg), MACH_SEND_ALWAYS,                    \
-                            MACH_MSG_TIMEOUT_NONE);                    \
-       assert(mr == MACH_MSG_SUCCESS);                                 \
-MACRO_END
-
-#else  /* MACH_ASSERT */
-
-#define        ipc_kmsg_send_always(kmsg)                                      \
-MACRO_BEGIN                                                            \
-       (void) ipc_kmsg_send((kmsg), MACH_SEND_ALWAYS,                  \
-                              MACH_MSG_TIMEOUT_NONE);                  \
-MACRO_END
-
-#endif /* MACH_ASSERT */
-
 /* Allocate a kernel message */
 extern ipc_kmsg_t ipc_kmsg_alloc(
         mach_msg_size_t size);
@@ -286,19 +259,30 @@ extern void ipc_kmsg_free(
 extern void ipc_kmsg_destroy(
        ipc_kmsg_t      kmsg);
 
+/* Enqueue kernel message for deferred destruction */
+extern boolean_t ipc_kmsg_delayed_destroy(
+       ipc_kmsg_t kmsg);
+
+/* Process all the delayed message destroys */
+extern void ipc_kmsg_reap_delayed(void);
+
 /* Preallocate a kernel message buffer */
+extern ipc_kmsg_t ipc_kmsg_prealloc(
+       mach_msg_size_t size);
+
+/* bind a preallocated message buffer to a port */
 extern void ipc_kmsg_set_prealloc(
        ipc_kmsg_t      kmsg,
        ipc_port_t      port);
 
-/* Clear a kernel message buffer */
+/* Clear preallocated message buffer binding */
 extern void ipc_kmsg_clear_prealloc(
        ipc_kmsg_t      kmsg,
        ipc_port_t      port);
 
 /* Allocate a kernel message buffer and copy a user message to the buffer */
 extern mach_msg_return_t ipc_kmsg_get(
-       mach_msg_header_t       *msg,
+       mach_vm_address_t       msg_addr, 
        mach_msg_size_t         size,
        ipc_kmsg_t              *kmsgp);
 
@@ -312,13 +296,16 @@ extern mach_msg_return_t ipc_kmsg_get_from_kernel(
 extern mach_msg_return_t ipc_kmsg_send(
        ipc_kmsg_t              kmsg,
        mach_msg_option_t       option,
-       mach_msg_timeout_t      timeout);
+       mach_msg_timeout_t      timeout_val);
 
 /* Copy a kernel message buffer to a user message */
 extern mach_msg_return_t ipc_kmsg_put(
-       mach_msg_header_t       *msg,
        ipc_kmsg_t              kmsg,
-       mach_msg_size_t         size);
+       mach_msg_option_t       option,
+       mach_vm_address_t       rcv_addr,
+       mach_msg_size_t         rcv_size,
+       mach_msg_size_t         trailer_size,
+       mach_msg_size_t         *size);
 
 /* Copy a kernel message buffer to a kernel message */
 extern void ipc_kmsg_put_to_kernel(
@@ -328,26 +315,33 @@ extern void ipc_kmsg_put_to_kernel(
 
 /* Copyin port rights in the header of a message */
 extern mach_msg_return_t ipc_kmsg_copyin_header(
-       mach_msg_header_t       *msg,
+       ipc_kmsg_t              kmsg,
        ipc_space_t             space,
-       mach_port_name_t        notify);
+       mach_msg_priority_t override,
+       mach_msg_option_t       *optionp);
 
 /* Copyin port rights and out-of-line memory from a user message */
 extern mach_msg_return_t ipc_kmsg_copyin(
        ipc_kmsg_t              kmsg,
        ipc_space_t             space,
        vm_map_t                map,
-       mach_port_name_t        notify);
+       mach_msg_priority_t override,
+       mach_msg_option_t       *optionp);
 
 /* Copyin port rights and out-of-line memory from a kernel message */
-extern void ipc_kmsg_copyin_from_kernel(
+extern mach_msg_return_t ipc_kmsg_copyin_from_kernel(
        ipc_kmsg_t              kmsg);
 
+#if IKM_SUPPORT_LEGACY
+extern mach_msg_return_t ipc_kmsg_copyin_from_kernel_legacy(
+       ipc_kmsg_t      kmsg);
+#endif
+
 /* Copyout port rights in the header of a message */
 extern mach_msg_return_t ipc_kmsg_copyout_header(
-       mach_msg_header_t       *msg,
+       ipc_kmsg_t              kmsg,
        ipc_space_t             space,
-       mach_port_name_t        notify);
+       mach_msg_option_t       option);
 
 /* Copyout a port right returning a name */
 extern mach_msg_return_t ipc_kmsg_copyout_object(
@@ -361,8 +355,8 @@ extern mach_msg_return_t ipc_kmsg_copyout(
        ipc_kmsg_t              kmsg,
        ipc_space_t             space,
        vm_map_t                map,
-       mach_port_name_t        notify,
-       mach_msg_body_t         *slist);
+       mach_msg_body_t         *slist,
+       mach_msg_option_t       option);
 
 /* Copyout port rights and out-of-line memory from the body of a message */
 extern mach_msg_return_t ipc_kmsg_copyout_body(
@@ -379,6 +373,11 @@ extern mach_msg_return_t ipc_kmsg_copyout_pseudo(
        vm_map_t                map,
        mach_msg_body_t         *slist);
 
+/* Compute size of message as copied out to the specified space/map */
+extern mach_msg_size_t ipc_kmsg_copyout_size(
+       ipc_kmsg_t              kmsg,
+       vm_map_t                map);
+
 /* Copyout the destination port in the message */
 extern void ipc_kmsg_copyout_dest( 
        ipc_kmsg_t              kmsg,
@@ -389,28 +388,24 @@ extern void ipc_kmsg_copyout_to_kernel(
        ipc_kmsg_t              kmsg,
        ipc_space_t             space);
 
-/* copyin a scatter list and check consistency */
-extern mach_msg_body_t *ipc_kmsg_copyin_scatter(
-        mach_msg_header_t       *msg,
-        mach_msg_size_t         slist_size,
-        ipc_kmsg_t              kmsg);
-
-/* free a scatter list */
-extern void ipc_kmsg_free_scatter(
-        mach_msg_body_t        *slist,
-        mach_msg_size_t                slist_size);
-
-#include <mach_kdb.h>
-#if    MACH_KDB
-
-/* Do a formatted dump of a kernel message */
-extern void ipc_kmsg_print(
-       ipc_kmsg_t      kmsg);
+#if IKM_SUPPORT_LEGACY
+extern void ipc_kmsg_copyout_to_kernel_legacy(
+       ipc_kmsg_t              kmsg,
+       ipc_space_t             space);
+#endif
 
-/* Do a formatted dump of a user message */
-extern void ipc_msg_print(
-       mach_msg_header_t       *msgh);
+extern mach_msg_trailer_size_t
+ipc_kmsg_add_trailer(ipc_kmsg_t kmsg, ipc_space_t space, 
+               mach_msg_option_t option, thread_t thread, 
+               mach_port_seqno_t seqno, boolean_t minimal_trailer,
+               mach_vm_offset_t context);
 
-#endif /* MACH_KDB */
+#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
+extern void ipc_kmsg_trace_send(ipc_kmsg_t kmsg,
+                               mach_msg_option_t option);
+#else
+#define ipc_kmsg_trace_send(a,b) do { } while (0)
+#endif
 
 #endif /* _IPC_IPC_KMSG_H_ */
+