]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ipc/ipc_kmsg.h
xnu-1504.9.37.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_kmsg.h
index b838576335501f2e4bdabc68bd92473662124930..8687cafbfb115f2cc88fa0822d289f2ff4eca82c 100644 (file)
@@ -1,16 +1,19 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 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. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * 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.
+ * 
+ * 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
@@ -20,7 +23,7 @@
  * 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>
 
 /*
  *     of the message.
  */
 
+struct ipc_labelh;
 
-typedef struct ipc_kmsg {
+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;
+       struct ipc_labelh *ikm_sender;
+       mach_msg_header_t *ikm_header;
+};
 
-#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))
@@ -111,8 +124,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)
@@ -133,11 +147,11 @@ MACRO_BEGIN                                                               \
        ip_release(port);                                               \
 MACRO_END
 
-
 #define        ikm_init(kmsg, size)                                            \
 MACRO_BEGIN                                                            \
        (kmsg)->ikm_size = (size);                                      \
        (kmsg)->ikm_prealloc = IP_NULL;                                 \
+        (kmsg)->ikm_sender = NULL;                                     \
        assert((kmsg)->ikm_prev = (kmsg)->ikm_next = IKM_BOGUS);        \
 MACRO_END
 
@@ -148,6 +162,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;
 };
@@ -229,55 +249,13 @@ MACRO_BEGIN                                                               \
        }                                                               \
 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
+       ipc_kmsg_send((kmsg), MACH_SEND_ALWAYS, MACH_MSG_TIMEOUT_NONE)
 
-#endif /* MACH_ASSERT */
 
 /* Allocate a kernel message */
 extern ipc_kmsg_t ipc_kmsg_alloc(
@@ -291,19 +269,27 @@ extern void ipc_kmsg_free(
 extern void ipc_kmsg_destroy(
        ipc_kmsg_t      kmsg);
 
+/* destroy kernel message and a reference on the dest */
+extern void ipc_kmsg_destroy_dest(
+       ipc_kmsg_t      kmsg);
+
 /* 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);
 
@@ -317,11 +303,11 @@ 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,
+       mach_vm_address_t       msg_addr,
        ipc_kmsg_t              kmsg,
        mach_msg_size_t         size);
 
@@ -348,6 +334,11 @@ extern mach_msg_return_t ipc_kmsg_copyin(
 extern void ipc_kmsg_copyin_from_kernel(
        ipc_kmsg_t              kmsg);
 
+#if IKM_SUPPORT_LEGACY
+extern void 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,
@@ -384,6 +375,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,
@@ -394,9 +390,15 @@ 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,
+#if IKM_SUPPORT_LEGACY
+extern void ipc_kmsg_copyout_to_kernel_legacy(
+       ipc_kmsg_t              kmsg,
+       ipc_space_t             space);
+#endif
+
+/* get a scatter list and check consistency */
+extern mach_msg_body_t *ipc_kmsg_get_scatter(
+        mach_vm_address_t       msg_addr,
         mach_msg_size_t         slist_size,
         ipc_kmsg_t              kmsg);
 
@@ -405,17 +407,5 @@ 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);
-
-/* Do a formatted dump of a user message */
-extern void ipc_msg_print(
-       mach_msg_header_t       *msgh);
-
-#endif /* MACH_KDB */
-
 #endif /* _IPC_IPC_KMSG_H_ */
+