/*
- * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#include <sys/appleapiopts.h>
-#ifdef __APPLE_API_UNSTABLE
+#include <sys/_types.h>
+#include <sys/cdefs.h>
+
+/*
+ * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined when this
+ * header is included
+ */
#include <sys/ipc.h>
/*
- * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
- * are as defined by the SV API Intel 386 Processor Supplement.
+ * [XSI] The pid_t, time_t, key_t, size_t, and ssize_t types shall be
+ * defined as described in <sys/types.h>.
+ *
+ * NOTE: The definition of the key_t type is implicit from the
+ * inclusion of <sys/ipc.h>
+ */
+#ifndef _PID_T
+typedef __darwin_pid_t pid_t;
+#define _PID_T
+#endif
+
+#ifndef _TIME_T
+#define _TIME_T
+typedef __darwin_time_t time_t;
+#endif
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
+#endif
+
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef __darwin_ssize_t ssize_t;
+#endif
+
+/* [XSI] Used for the number of messages in the message queue */
+typedef unsigned long msgqnum_t;
+
+/* [XSI] Used for the number of bytes allowed in a message queue */
+typedef unsigned long msglen_t;
+
+
+/*
+ * Possible values for the fifth parameter to msgrcv(), in addition to the
+ * IPC_NOWAIT flag, which is permitted.
*/
+#define MSG_NOERROR 010000 /* [XSI] No error if big message */
+
-#define MSG_NOERROR 010000 /* don't complain about too long msgs */
-
-struct msqid_ds {
- struct ipc_perm msg_perm; /* msg queue permission bits */
- struct msg *msg_first; /* first message in the queue */
- struct msg *msg_last; /* last message in the queue */
- u_long msg_cbytes; /* number of bytes in use on the queue */
- u_long msg_qnum; /* number of msgs in the queue */
- u_long msg_qbytes; /* max # of bytes on the queue */
- pid_t msg_lspid; /* pid of last msgsnd() */
- pid_t msg_lrpid; /* pid of last msgrcv() */
- time_t msg_stime; /* time of last msgsnd() */
- long msg_pad1;
- time_t msg_rtime; /* time of last msgrcv() */
- long msg_pad2;
- time_t msg_ctime; /* time of last msgctl() */
- long msg_pad3;
- long msg_pad4[4];
+/*
+ * Technically, we should force all code references to the new structure
+ * definition, not in just the standards conformance case, and leave the
+ * legacy interface there for binary compatibility only. Currently, we
+ * are only forcing this for programs requesting standards conformance.
+ */
+#if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
+/*
+ * Structure used internally.
+ *
+ * Structure whose address is passed as the third parameter to msgctl()
+ * when the second parameter is IPC_SET or IPC_STAT. In the case of the
+ * IPC_SET command, only the msg_perm.{uid|gid|perm} and msg_qbytes are
+ * honored. In the case of IPC_STAT, only the fields indicated as [XSI]
+ * mandated fields are guaranteed to meaningful: DO NOT depend on the
+ * contents of the other fields.
+ *
+ * NOTES: Reserved fields are not preserved across IPC_SET/IPC_STAT.
+ */
+struct __msqid_ds_new {
+ struct __ipc_perm_new msg_perm; /* [XSI] msg queue permissions */
+ __int32_t msg_first; /* RESERVED: kernel use only */
+ __int32_t msg_last; /* RESERVED: kernel use only */
+ msglen_t msg_cbytes; /* # of bytes on the queue */
+ msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */
+ msglen_t msg_qbytes; /* [XSI] max bytes on the queue */
+ pid_t msg_lspid; /* [XSI] pid of last msgsnd() */
+ pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */
+ time_t msg_stime; /* [XSI] time of last msgsnd() */
+ __int32_t msg_pad1; /* RESERVED: DO NOT USE */
+ time_t msg_rtime; /* [XSI] time of last msgrcv() */
+ __int32_t msg_pad2; /* RESERVED: DO NOT USE */
+ time_t msg_ctime; /* [XSI] time of last msgctl() */
+ __int32_t msg_pad3; /* RESERVED: DO NOT USE */
+ __int32_t msg_pad4[4]; /* RESERVED: DO NOT USE */
+};
+#define msqid_ds __msqid_ds_new
+#else /* !_POSIX_C_SOURCE */
+#define msqid_ds __msqid_ds_old
+#endif /* !_POSIX_C_SOURCE */
+
+#if !defined(__POSIX_C_SOURCE) && !defined(__LP64__)
+struct __msqid_ds_old {
+ struct __ipc_perm_old msg_perm; /* [XSI] msg queue permissions */
+ __int32_t msg_first; /* RESERVED: kernel use only */
+ __int32_t msg_last; /* RESERVED: kernel use only */
+ msglen_t msg_cbytes; /* # of bytes on the queue */
+ msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */
+ msglen_t msg_qbytes; /* [XSI] max bytes on the queue */
+ pid_t msg_lspid; /* [XSI] pid of last msgsnd() */
+ pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */
+ time_t msg_stime; /* [XSI] time of last msgsnd() */
+ __int32_t msg_pad1; /* RESERVED: DO NOT USE */
+ time_t msg_rtime; /* [XSI] time of last msgrcv() */
+ __int32_t msg_pad2; /* RESERVED: DO NOT USE */
+ time_t msg_ctime; /* [XSI] time of last msgctl() */
+ __int32_t msg_pad3; /* RESERVED: DO NOT USE */
+ __int32_t msg_pad4[4]; /* RESERVED: DO NOT USE */
};
+#endif /* !_POSIX_C_SOURCE */
+
+#ifdef KERNEL
+#ifdef __APPLE_API_PRIVATE
+#include <machine/types.h>
+
+// LP64todo - should this move?
+
+#if __DARWIN_ALIGN_NATURAL
+#pragma options align=natural
+#endif
+
+struct user_msqid_ds {
+ struct ipc_perm msg_perm; /* [XSI] msg queue permissions */
+ struct msg *msg_first; /* first message in the queue */
+ struct msg *msg_last; /* last message in the queue */
+ msglen_t msg_cbytes; /* # of bytes on the queue */
+ msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */
+ msglen_t msg_qbytes; /* [XSI] max bytes on the queue */
+ pid_t msg_lspid; /* [XSI] pid of last msgsnd() */
+ pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */
+ user_time_t msg_stime; /* [XSI] time of last msgsnd() */
+ __int32_t msg_pad1; /* RESERVED: DO NOT USE */
+ user_time_t msg_rtime; /* [XSI] time of last msgrcv() */
+ __int32_t msg_pad2; /* RESERVED: DO NOT USE */
+ user_time_t msg_ctime; /* [XSI] time of last msgctl() */
+ __int32_t msg_pad3; /* RESERVED: DO NOT USE */
+ __int32_t msg_pad4[4];
+};
+
+#if __DARWIN_ALIGN_NATURAL
+#pragma options align=reset
+#endif
+
+#endif /* __APPLE_API_PRIVATE */
+#endif /* KERNEL */
+
+
+#ifndef _POSIX_C_SOURCE
+#ifdef __APPLE_API_UNSTABLE
+/* XXX kernel only; protect with macro later */
struct msg {
- struct msg *msg_next; /* next msg in the chain */
- long msg_type; /* type of this message */
- /* >0 -> type of this message */
- /* 0 -> free header */
- u_short msg_ts; /* size of this message */
- short msg_spot; /* location of start of msg in buffer */
+ struct msg *msg_next; /* next msg in the chain */
+ long msg_type; /* type of this message */
+ /* >0 -> type of this message */
+ /* 0 -> free header */
+ unsigned short msg_ts; /* size of this message */
+ short msg_spot; /* location of msg start in buffer */
};
/*
- * Structure describing a message. The SVID doesn't suggest any
- * particular name for this structure. There is a reference in the
- * msgop man page that reads "The structure mymsg is an example of what
- * this user defined buffer might look like, and includes the following
- * members:". This sentence is followed by two lines equivalent
- * to the mtype and mtext field declarations below. It isn't clear
- * if "mymsg" refers to the naem of the structure type or the name of an
- * instance of the structure...
+ * Example structure describing a message whose address is to be passed as
+ * the second argument to the functions msgrcv() and msgsnd(). The only
+ * actual hard requirement is that the first field be of type long, and
+ * contain the message type. The user is encouraged to define their own
+ * application specific structure; this definition is included solely for
+ * backward compatability with existing source code.
*/
struct mymsg {
long mtype; /* message type (+ve integer) */
/* 0..(MSGSEG-1) -> index of next segment */
};
+/* The following four externs really, really need to die; should be static */
extern char *msgpool; /* MSGMAX byte long msg buffer pool */
extern struct msgmap *msgmaps; /* MSGSEG msgmap structures */
extern struct msg *msghdrs; /* MSGTQL msg headers */
-extern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
+extern struct user_msqid_ds *msqids; /* MSGMNI user_msqid_ds struct's */
#define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
-#endif /* KERNEL */
+#endif /* KERNEL */
+#endif /* __APPLE_API_UNSTABLE */
+#endif /* !_POSIX_C_SOURCE */
#ifndef KERNEL
-#include <sys/cdefs.h>
__BEGIN_DECLS
-int msgsys __P((int, ...));
-int msgctl __P((int, int, struct msqid_ds *));
-int msgget __P((key_t, int));
-int msgsnd __P((int, void *, size_t, int));
-int msgrcv __P((int, void*, size_t, long, int));
+#ifndef _POSIX_C_SOURCE
+int msgsys(int, ...);
+#endif /* !_POSIX_C_SOURCE */
+int msgctl(int, int, struct msqid_ds *) __DARWIN_ALIAS(msgctl);
+int msgget(key_t, int);
+ssize_t msgrcv(int, void *, size_t, long, int);
+int msgsnd(int, const void *, size_t, int);
__END_DECLS
+
#endif /* !KERNEL */
-#endif /* __APPLE_API_UNSTABLE */
#endif /* !_SYS_MSG_H_ */