]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/mach/message.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / mach / message.h
index 003373bc82d83f5fcd168e53580c77cb92efa1b6..77f71a4e1de83d096e5c5eabadff5027abcb03cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
 #ifndef        _MACH_MESSAGE_H_
 #define _MACH_MESSAGE_H_
 
-#ifdef MACH_KERNEL
-/* Have to have MIG parameter check for kernel */
-#define TypeCheck 1
-#define _MIG_KERNEL_SPECIFIC_CODE_ 1
-#endif /* MACH_KERNEL */
-
-#include <mach/kern_return.h>
+#include <stdint.h>
 #include <mach/port.h>
+#include <mach/boolean.h>
+#include <mach/kern_return.h>
+#include <mach/machine/vm_types.h>
 
+#include <sys/cdefs.h>
 
 /*
  *  The timeout mechanism uses mach_msg_timeout_t values,
@@ -183,7 +181,6 @@ typedef unsigned int mach_msg_copy_options_t;
 #define MACH_MSG_OVERWRITE             3
 #ifdef  MACH_KERNEL
 #define MACH_MSG_KALLOC_COPY_T         4
-#define MACH_MSG_PAGE_LIST_COPY_T      5
 #endif  /* MACH_KERNEL */
 
 typedef unsigned int mach_msg_descriptor_type_t;
@@ -193,10 +190,11 @@ typedef unsigned int mach_msg_descriptor_type_t;
 #define MACH_MSG_OOL_PORTS_DESCRIPTOR          2
 #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR       3
 
+#pragma pack(4)
 
 typedef struct
 {
-  void*                                pad1;
+  natural_t                    pad1;
   mach_msg_size_t              pad2;
   unsigned int                 pad3 : 24;
   mach_msg_descriptor_type_t   type : 8;
@@ -213,24 +211,79 @@ typedef struct
 
 typedef struct
 {
-  void* address;
+  uint32_t                     address;
   mach_msg_size_t              size;
   boolean_t                    deallocate: 8;
   mach_msg_copy_options_t       copy: 8;
   unsigned int                 pad1: 8;
   mach_msg_descriptor_type_t    type: 8;
+} mach_msg_ool_descriptor32_t;
+
+typedef struct
+{
+  uint64_t                     address;
+  boolean_t                    deallocate: 8;
+  mach_msg_copy_options_t       copy: 8;
+  unsigned int                 pad1: 8;
+  mach_msg_descriptor_type_t    type: 8;
+  mach_msg_size_t              size;
+} mach_msg_ool_descriptor64_t;
+
+typedef struct
+{
+  void*                                address;
+#if !defined(__LP64__)
+  mach_msg_size_t              size;
+#endif
+  boolean_t                    deallocate: 8;
+  mach_msg_copy_options_t       copy: 8;
+  unsigned int                 pad1: 8;
+  mach_msg_descriptor_type_t    type: 8;
+#if defined(__LP64__)
+  mach_msg_size_t              size;
+#endif
 } mach_msg_ool_descriptor_t;
 
+typedef struct
+{
+  uint32_t                     address;
+  mach_msg_size_t              count;
+  boolean_t                    deallocate: 8;
+  mach_msg_copy_options_t       copy: 8;
+  mach_msg_type_name_t         disposition : 8;
+  mach_msg_descriptor_type_t   type : 8;
+} mach_msg_ool_ports_descriptor32_t;
+
+typedef struct
+{
+  uint64_t                     address;
+  boolean_t                    deallocate: 8;
+  mach_msg_copy_options_t       copy: 8;
+  mach_msg_type_name_t         disposition : 8;
+  mach_msg_descriptor_type_t   type : 8;
+  mach_msg_size_t              count;
+} mach_msg_ool_ports_descriptor64_t;
+
 typedef struct
 {
   void*                                address;
+#if !defined(__LP64__)
   mach_msg_size_t              count;
+#endif
   boolean_t                    deallocate: 8;
   mach_msg_copy_options_t       copy: 8;
   mach_msg_type_name_t         disposition : 8;
   mach_msg_descriptor_type_t   type : 8;
+#if defined(__LP64__)
+  mach_msg_size_t              count;
+#endif
 } mach_msg_ool_ports_descriptor_t;
 
+/*
+ * LP64support - This union definition is not really
+ * appropriate in LP64 mode because not all descriptors
+ * are of the same size in that environment.
+ */
 typedef union
 {
   mach_msg_port_descriptor_t           port;
@@ -297,15 +350,59 @@ typedef struct
   security_token_t             msgh_sender;
 } mach_msg_security_trailer_t;
 
-typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t;
+/*
+ * The audit token is an opaque token which identifies
+ * Mach tasks and senders of Mach messages as subjects
+ * to the BSM audit system.  Only the appropriate BSM
+ * library routines should be used to interpret the
+ * contents of the audit token as the representation
+ * of the subject identity within the token may change
+ * over time.
+ */
+typedef struct
+{
+  unsigned int                 val[8];
+} audit_token_t;
+
+typedef struct 
+{
+  mach_msg_trailer_type_t      msgh_trailer_type;
+  mach_msg_trailer_size_t      msgh_trailer_size;
+  mach_port_seqno_t            msgh_seqno;
+  security_token_t             msgh_sender;
+  audit_token_t                        msgh_audit;
+} mach_msg_audit_trailer_t;
 
-#define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
 #define MACH_MSG_TRAILER_MINIMUM_SIZE  sizeof(mach_msg_trailer_t)
-#define MAX_TRAILER_SIZE              MACH_MSG_TRAILER_FORMAT_0_SIZE   
+
+/*
+ * These values can change from release to release - but clearly
+ * code cannot request additional trailer elements one was not
+ * compiled to understand.  Therefore, it is safe to use this
+ * constant when the same module specified the receive options.
+ * Otherwise, you run the risk that the options requested by
+ * another module may exceed the local modules notion of
+ * MAX_TRAILER_SIZE.
+ */
+typedef mach_msg_audit_trailer_t mach_msg_max_trailer_t;
+#define MAX_TRAILER_SIZE sizeof(mach_msg_max_trailer_t)
+
+/*
+ * Legacy requirements keep us from ever updating these defines (even
+ * when the format_0 trailers gain new option data fields in the future).
+ * Therefore, they shouldn't be used going forward.  Instead, the sizes
+ * should be compared against the specific element size requested using
+ * REQUESTED_TRAILER_SIZE.
+ */
+typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t;
+#define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
 
 #define   KERNEL_SECURITY_TOKEN_VALUE  { {0, 1} }
 extern security_token_t KERNEL_SECURITY_TOKEN;
 
+#define   KERNEL_AUDIT_TOKEN_VALUE  { {0, 0, 0, 0, 0, 0, 0, 0} }
+extern audit_token_t KERNEL_AUDIT_TOKEN;
+
 typedef        integer_t mach_msg_options_t;
 
 typedef struct
@@ -325,6 +422,8 @@ typedef union
   mach_msg_empty_rcv_t rcv;
 } mach_msg_empty_t;
 
+#pragma pack()
+
 /* utility to round the message size - will become machine dependent */
 #define round_msg(x)   (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
                                ~(sizeof (natural_t) - 1))
@@ -339,12 +438,8 @@ typedef union
  *  Compatibility definitions, for code written
  *  when there was a msgh_kind instead of msgh_seqno.
  */
-
 #define MACH_MSGH_KIND_NORMAL          0x00000000
-#if    0
-/* code using this is likely to break, so better not to have it defined */
 #define MACH_MSGH_KIND_NOTIFICATION    0x00000001
-#endif
 #define        msgh_kind                       msgh_seqno
 #define mach_msg_kind_t                        mach_port_seqno_t
 
@@ -444,16 +539,22 @@ typedef integer_t mach_msg_option_t;
 #define MACH_RCV_TRAILER_NULL   0
 #define MACH_RCV_TRAILER_SEQNO  1
 #define MACH_RCV_TRAILER_SENDER 2
+#define MACH_RCV_TRAILER_AUDIT  3
 
 #define MACH_RCV_TRAILER_TYPE(x)     (((x) & 0xf) << 28) 
 #define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24)  
 #define MACH_RCV_TRAILER_MASK       ((0xff << 24))
 
-extern mach_msg_trailer_size_t trailer_size[];
-
 #define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf)
-#define REQUESTED_TRAILER_SIZE(y) (trailer_size[GET_RCV_ELEMENTS(y)])
-
+#define REQUESTED_TRAILER_SIZE(y)                              \
+       ((mach_msg_trailer_size_t)                              \
+        ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ?      \
+         sizeof(mach_msg_trailer_t) :                          \
+         ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ?    \
+          sizeof(mach_msg_seqno_trailer_t) :                   \
+         ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ?   \
+          sizeof(mach_msg_security_trailer_t) :                \
+          sizeof(mach_msg_audit_trailer_t)))))
 /*
  *  Much code assumes that mach_msg_return_t == kern_return_t.
  *  This definition is useful for descriptive purposes.
@@ -512,7 +613,7 @@ typedef kern_return_t mach_msg_return_t;
 #define MACH_SEND_INVALID_TRAILER      0x10000011
                /* The trailer to be sent does not match kernel format. */
 #define MACH_SEND_INVALID_RT_OOL_SIZE  0x10000015
-               /* The OOL buffer size is too large for RT behavior */
+               /* compatibility: no longer a returned error */
 
 #define MACH_RCV_IN_PROGRESS           0x10004001
                /* Thread is waiting for receive.  (Internal use only.) */
@@ -525,7 +626,7 @@ typedef kern_return_t mach_msg_return_t;
 #define MACH_RCV_INTERRUPTED           0x10004005
                /* Software interrupt. */
 #define MACH_RCV_PORT_CHANGED          0x10004006
-               /* Port moved into a set during the receive. */
+               /* compatibility: no longer a returned error */
 #define MACH_RCV_INVALID_NOTIFY                0x10004007
                /* Bogus notify port argument. */
 #define MACH_RCV_INVALID_DATA          0x10004008
@@ -533,7 +634,7 @@ typedef kern_return_t mach_msg_return_t;
 #define MACH_RCV_PORT_DIED             0x10004009
                /* Port/set was sent away/died during receive. */
 #define        MACH_RCV_IN_SET                 0x1000400a
-               /* Port is a member of a port set. */
+               /* compatibility: no longer a returned error */
 #define        MACH_RCV_HEADER_ERROR           0x1000400b
                /* Error receiving message header.  See special bits. */
 #define        MACH_RCV_BODY_ERROR             0x1000400c
@@ -547,16 +648,25 @@ typedef kern_return_t mach_msg_return_t;
 #define MACH_RCV_IN_PROGRESS_TIMED      0x10004011
                 /* Waiting for receive with timeout. (Internal use only.) */
 
-extern mach_msg_return_t       mach_msg_overwrite_trap(
-                                       mach_msg_header_t *msg,
-                                       mach_msg_option_t option,
-                                       mach_msg_size_t send_size,
-                                       mach_msg_size_t rcv_size,
-                                       mach_port_name_t rcv_name,
-                                       mach_msg_timeout_t timeout,
-                                       mach_port_name_t notify,
-                                       mach_msg_header_t *rcv_msg,
-                                       mach_msg_size_t rcv_limit);
+
+__BEGIN_DECLS
+
+/*
+ *     Routine:        mach_msg_overwrite
+ *     Purpose:
+ *             Send and/or receive a message.  If the message operation
+ *             is interrupted, and the user did not request an indication
+ *             of that fact, then restart the appropriate parts of the
+ *             operation silently (trap version does not restart).
+ *
+ *             Distinct send and receive buffers may be specified.  If
+ *             no separate receive buffer is specified, the msg parameter
+ *             will be used for both send and receive operations.
+ *
+ *             In addition to a distinct receive buffer, that buffer may
+ *             already contain scatter control information to direct the
+ *             receiving of the message.
+ */
 
 extern mach_msg_return_t       mach_msg_overwrite(
                                        mach_msg_header_t *msg,
@@ -569,15 +679,16 @@ extern mach_msg_return_t  mach_msg_overwrite(
                                        mach_msg_header_t *rcv_msg,
                                        mach_msg_size_t rcv_limit);
 
-extern mach_msg_return_t       mach_msg_trap(
-                                       mach_msg_header_t *msg,
-                                       mach_msg_option_t option,
-                                       mach_msg_size_t send_size,
-                                       mach_msg_size_t rcv_size,
-                                       mach_port_name_t rcv_name,
-                                       mach_msg_timeout_t timeout,
-                                       mach_port_name_t notify);
+#ifndef        KERNEL
 
+/*
+ *     Routine:        mach_msg
+ *     Purpose:
+ *             Send and/or receive a message.  If the message operation
+ *             is interrupted, and the user did not request an indication
+ *             of that fact, then restart the appropriate parts of the
+ *             operation silently (trap version does not restart).
+ */
 extern mach_msg_return_t       mach_msg(
                                        mach_msg_header_t *msg,
                                        mach_msg_option_t option,
@@ -587,4 +698,8 @@ extern mach_msg_return_t    mach_msg(
                                        mach_msg_timeout_t timeout,
                                        mach_port_name_t notify);
 
+#endif /* KERNEL */
+
+__END_DECLS
+
 #endif /* _MACH_MESSAGE_H_ */