xref: /xnu-8792.81.2/bsd/sys/msg.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions  * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions  *
4*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions  *
6*19c3b8c2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*19c3b8c2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*19c3b8c2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*19c3b8c2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*19c3b8c2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*19c3b8c2SApple OSS Distributions  *
15*19c3b8c2SApple OSS Distributions  * Please obtain a copy of the License at
16*19c3b8c2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*19c3b8c2SApple OSS Distributions  *
18*19c3b8c2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*19c3b8c2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*19c3b8c2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*19c3b8c2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*19c3b8c2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*19c3b8c2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*19c3b8c2SApple OSS Distributions  * limitations under the License.
25*19c3b8c2SApple OSS Distributions  *
26*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*19c3b8c2SApple OSS Distributions  */
28*19c3b8c2SApple OSS Distributions /*	$NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $	*/
29*19c3b8c2SApple OSS Distributions 
30*19c3b8c2SApple OSS Distributions /*
31*19c3b8c2SApple OSS Distributions  * SVID compatible msg.h file
32*19c3b8c2SApple OSS Distributions  *
33*19c3b8c2SApple OSS Distributions  * Author:  Daniel Boulet
34*19c3b8c2SApple OSS Distributions  *
35*19c3b8c2SApple OSS Distributions  * Copyright 1993 Daniel Boulet and RTMX Inc.
36*19c3b8c2SApple OSS Distributions  *
37*19c3b8c2SApple OSS Distributions  * This system call was implemented by Daniel Boulet under contract from RTMX.
38*19c3b8c2SApple OSS Distributions  *
39*19c3b8c2SApple OSS Distributions  * Redistribution and use in source forms, with and without modification,
40*19c3b8c2SApple OSS Distributions  * are permitted provided that this entire comment appears intact.
41*19c3b8c2SApple OSS Distributions  *
42*19c3b8c2SApple OSS Distributions  * Redistribution in binary form may occur without any restrictions.
43*19c3b8c2SApple OSS Distributions  * Obviously, it would be nice if you gave credit where credit is due
44*19c3b8c2SApple OSS Distributions  * but requiring it would be too onerous.
45*19c3b8c2SApple OSS Distributions  *
46*19c3b8c2SApple OSS Distributions  * This software is provided ``AS IS'' without any warranties of any kind.
47*19c3b8c2SApple OSS Distributions  */
48*19c3b8c2SApple OSS Distributions /*
49*19c3b8c2SApple OSS Distributions  * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
50*19c3b8c2SApple OSS Distributions  * support for mandatory and extensible security protections.  This notice
51*19c3b8c2SApple OSS Distributions  * is included in support of clause 2.2 (b) of the Apple Public License,
52*19c3b8c2SApple OSS Distributions  * Version 2.0.
53*19c3b8c2SApple OSS Distributions  */
54*19c3b8c2SApple OSS Distributions 
55*19c3b8c2SApple OSS Distributions #ifndef _SYS_MSG_H_
56*19c3b8c2SApple OSS Distributions #define _SYS_MSG_H_
57*19c3b8c2SApple OSS Distributions 
58*19c3b8c2SApple OSS Distributions #include <sys/appleapiopts.h>
59*19c3b8c2SApple OSS Distributions 
60*19c3b8c2SApple OSS Distributions #include <sys/_types.h>
61*19c3b8c2SApple OSS Distributions #include <sys/cdefs.h>
62*19c3b8c2SApple OSS Distributions 
63*19c3b8c2SApple OSS Distributions /*
64*19c3b8c2SApple OSS Distributions  * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined when this
65*19c3b8c2SApple OSS Distributions  * header is included
66*19c3b8c2SApple OSS Distributions  */
67*19c3b8c2SApple OSS Distributions #include <sys/ipc.h>
68*19c3b8c2SApple OSS Distributions 
69*19c3b8c2SApple OSS Distributions 
70*19c3b8c2SApple OSS Distributions /*
71*19c3b8c2SApple OSS Distributions  * [XSI] The pid_t, time_t, key_t, size_t, and ssize_t types shall be
72*19c3b8c2SApple OSS Distributions  * defined as described in <sys/types.h>.
73*19c3b8c2SApple OSS Distributions  *
74*19c3b8c2SApple OSS Distributions  * NOTE:	The definition of the key_t type is implicit from the
75*19c3b8c2SApple OSS Distributions  *		inclusion of <sys/ipc.h>
76*19c3b8c2SApple OSS Distributions  */
77*19c3b8c2SApple OSS Distributions #include <sys/_types/_pid_t.h>
78*19c3b8c2SApple OSS Distributions #include <sys/_types/_time_t.h>
79*19c3b8c2SApple OSS Distributions #include <sys/_types/_size_t.h>
80*19c3b8c2SApple OSS Distributions #include <sys/_types/_ssize_t.h>
81*19c3b8c2SApple OSS Distributions 
82*19c3b8c2SApple OSS Distributions /* [XSI] Used for the number of messages in the message queue */
83*19c3b8c2SApple OSS Distributions typedef unsigned long           msgqnum_t;
84*19c3b8c2SApple OSS Distributions 
85*19c3b8c2SApple OSS Distributions /* [XSI] Used for the number of bytes allowed in a message queue */
86*19c3b8c2SApple OSS Distributions typedef unsigned long           msglen_t;
87*19c3b8c2SApple OSS Distributions 
88*19c3b8c2SApple OSS Distributions /*
89*19c3b8c2SApple OSS Distributions  * Possible values for the fifth parameter to msgrcv(), in addition to the
90*19c3b8c2SApple OSS Distributions  * IPC_NOWAIT flag, which is permitted.
91*19c3b8c2SApple OSS Distributions  */
92*19c3b8c2SApple OSS Distributions #define MSG_NOERROR     010000          /* [XSI] No error if big message */
93*19c3b8c2SApple OSS Distributions 
94*19c3b8c2SApple OSS Distributions 
95*19c3b8c2SApple OSS Distributions /*
96*19c3b8c2SApple OSS Distributions  * Technically, we should force all code references to the new structure
97*19c3b8c2SApple OSS Distributions  * definition, not in just the standards conformance case, and leave the
98*19c3b8c2SApple OSS Distributions  * legacy interface there for binary compatibility only.  Currently, we
99*19c3b8c2SApple OSS Distributions  * are only forcing this for programs requesting standards conformance.
100*19c3b8c2SApple OSS Distributions  */
101*19c3b8c2SApple OSS Distributions #if __DARWIN_UNIX03 || defined(KERNEL)
102*19c3b8c2SApple OSS Distributions #pragma pack(4)
103*19c3b8c2SApple OSS Distributions /*
104*19c3b8c2SApple OSS Distributions  * Structure used internally.
105*19c3b8c2SApple OSS Distributions  *
106*19c3b8c2SApple OSS Distributions  * Structure whose address is passed as the third parameter to msgctl()
107*19c3b8c2SApple OSS Distributions  * when the second parameter is IPC_SET or IPC_STAT.  In the case of the
108*19c3b8c2SApple OSS Distributions  * IPC_SET command, only the msg_perm.{uid|gid|perm} and msg_qbytes are
109*19c3b8c2SApple OSS Distributions  * honored.  In the case of IPC_STAT, only the fields indicated as [XSI]
110*19c3b8c2SApple OSS Distributions  * mandated fields are guaranteed to meaningful: DO NOT depend on the
111*19c3b8c2SApple OSS Distributions  * contents of the other fields.
112*19c3b8c2SApple OSS Distributions  *
113*19c3b8c2SApple OSS Distributions  * NOTES:	Reserved fields are not preserved across IPC_SET/IPC_STAT.
114*19c3b8c2SApple OSS Distributions  */
115*19c3b8c2SApple OSS Distributions #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
116*19c3b8c2SApple OSS Distributions struct msqid_ds
117*19c3b8c2SApple OSS Distributions #else
118*19c3b8c2SApple OSS Distributions #define msqid_ds        __msqid_ds_new
119*19c3b8c2SApple OSS Distributions struct __msqid_ds_new
120*19c3b8c2SApple OSS Distributions #endif
121*19c3b8c2SApple OSS Distributions {
122*19c3b8c2SApple OSS Distributions 	struct __ipc_perm_new   msg_perm; /* [XSI] msg queue permissions */
123*19c3b8c2SApple OSS Distributions 	__int32_t       msg_first;      /* RESERVED: kernel use only */
124*19c3b8c2SApple OSS Distributions 	__int32_t       msg_last;       /* RESERVED: kernel use only */
125*19c3b8c2SApple OSS Distributions 	msglen_t        msg_cbytes;     /* # of bytes on the queue */
126*19c3b8c2SApple OSS Distributions 	msgqnum_t       msg_qnum;       /* [XSI] number of msgs on the queue */
127*19c3b8c2SApple OSS Distributions 	msglen_t        msg_qbytes;     /* [XSI] max bytes on the queue */
128*19c3b8c2SApple OSS Distributions 	pid_t           msg_lspid;      /* [XSI] pid of last msgsnd() */
129*19c3b8c2SApple OSS Distributions 	pid_t           msg_lrpid;      /* [XSI] pid of last msgrcv() */
130*19c3b8c2SApple OSS Distributions 	time_t          msg_stime;      /* [XSI] time of last msgsnd() */
131*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad1;       /* RESERVED: DO NOT USE */
132*19c3b8c2SApple OSS Distributions 	time_t          msg_rtime;      /* [XSI] time of last msgrcv() */
133*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad2;       /* RESERVED: DO NOT USE */
134*19c3b8c2SApple OSS Distributions 	time_t          msg_ctime;      /* [XSI] time of last msgctl() */
135*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad3;       /* RESERVED: DO NOT USE */
136*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad4[4];    /* RESERVED: DO NOT USE */
137*19c3b8c2SApple OSS Distributions };
138*19c3b8c2SApple OSS Distributions #pragma pack()
139*19c3b8c2SApple OSS Distributions #else   /* !__DARWIN_UNIX03 */
140*19c3b8c2SApple OSS Distributions #define msqid_ds        __msqid_ds_old
141*19c3b8c2SApple OSS Distributions #endif  /* !__DARWIN_UNIX03 */
142*19c3b8c2SApple OSS Distributions 
143*19c3b8c2SApple OSS Distributions #if !__DARWIN_UNIX03
144*19c3b8c2SApple OSS Distributions struct __msqid_ds_old {
145*19c3b8c2SApple OSS Distributions 	struct __ipc_perm_old   msg_perm; /* [XSI] msg queue permissions */
146*19c3b8c2SApple OSS Distributions 	__int32_t       msg_first;      /* RESERVED: kernel use only */
147*19c3b8c2SApple OSS Distributions 	__int32_t       msg_last;       /* RESERVED: kernel use only */
148*19c3b8c2SApple OSS Distributions 	msglen_t        msg_cbytes;     /* # of bytes on the queue */
149*19c3b8c2SApple OSS Distributions 	msgqnum_t       msg_qnum;       /* [XSI] number of msgs on the queue */
150*19c3b8c2SApple OSS Distributions 	msglen_t        msg_qbytes;     /* [XSI] max bytes on the queue */
151*19c3b8c2SApple OSS Distributions 	pid_t           msg_lspid;      /* [XSI] pid of last msgsnd() */
152*19c3b8c2SApple OSS Distributions 	pid_t           msg_lrpid;      /* [XSI] pid of last msgrcv() */
153*19c3b8c2SApple OSS Distributions 	time_t          msg_stime;      /* [XSI] time of last msgsnd() */
154*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad1;       /* RESERVED: DO NOT USE */
155*19c3b8c2SApple OSS Distributions 	time_t          msg_rtime;      /* [XSI] time of last msgrcv() */
156*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad2;       /* RESERVED: DO NOT USE */
157*19c3b8c2SApple OSS Distributions 	time_t          msg_ctime;      /* [XSI] time of last msgctl() */
158*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad3;       /* RESERVED: DO NOT USE */
159*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad4[4];    /* RESERVED: DO NOT USE */
160*19c3b8c2SApple OSS Distributions };
161*19c3b8c2SApple OSS Distributions #endif  /* !__DARWIN_UNIX03 */
162*19c3b8c2SApple OSS Distributions 
163*19c3b8c2SApple OSS Distributions #ifdef KERNEL
164*19c3b8c2SApple OSS Distributions #ifdef __APPLE_API_PRIVATE
165*19c3b8c2SApple OSS Distributions #include <machine/types.h>
166*19c3b8c2SApple OSS Distributions 
167*19c3b8c2SApple OSS Distributions #if __DARWIN_ALIGN_NATURAL
168*19c3b8c2SApple OSS Distributions #pragma options align=natural
169*19c3b8c2SApple OSS Distributions #endif
170*19c3b8c2SApple OSS Distributions 
171*19c3b8c2SApple OSS Distributions typedef user_ulong_t    user_msgqnum_t;
172*19c3b8c2SApple OSS Distributions typedef user64_ulong_t  user64_msgqnum_t;
173*19c3b8c2SApple OSS Distributions typedef user32_ulong_t  user32_msgqnum_t;
174*19c3b8c2SApple OSS Distributions 
175*19c3b8c2SApple OSS Distributions typedef user_ulong_t    user_msglen_t;
176*19c3b8c2SApple OSS Distributions typedef user64_ulong_t  user64_msglen_t;
177*19c3b8c2SApple OSS Distributions typedef user32_ulong_t  user32_msglen_t;
178*19c3b8c2SApple OSS Distributions 
179*19c3b8c2SApple OSS Distributions /* kernel version */
180*19c3b8c2SApple OSS Distributions struct user_msqid_ds {
181*19c3b8c2SApple OSS Distributions 	struct ipc_perm msg_perm;       /* [XSI] msg queue permissions */
182*19c3b8c2SApple OSS Distributions 	struct msg      *msg_first;     /* first message in the queue */
183*19c3b8c2SApple OSS Distributions 	struct msg      *msg_last;      /* last message in the queue */
184*19c3b8c2SApple OSS Distributions 	user_msglen_t   msg_cbytes;     /* # of bytes on the queue */
185*19c3b8c2SApple OSS Distributions 	user_msgqnum_t  msg_qnum;       /* [XSI] number of msgs on the queue */
186*19c3b8c2SApple OSS Distributions 	user_msglen_t   msg_qbytes;     /* [XSI] max bytes on the queue */
187*19c3b8c2SApple OSS Distributions 	pid_t           msg_lspid;      /* [XSI] pid of last msgsnd() */
188*19c3b8c2SApple OSS Distributions 	pid_t           msg_lrpid;      /* [XSI] pid of last msgrcv() */
189*19c3b8c2SApple OSS Distributions 	user_time_t     msg_stime;      /* [XSI] time of last msgsnd() */
190*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad1;       /* RESERVED: DO NOT USE */
191*19c3b8c2SApple OSS Distributions 	user_time_t     msg_rtime;      /* [XSI] time of last msgrcv() */
192*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad2;       /* RESERVED: DO NOT USE */
193*19c3b8c2SApple OSS Distributions 	user_time_t     msg_ctime;      /* [XSI] time of last msgctl() */
194*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad3;       /* RESERVED: DO NOT USE */
195*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad4[4];
196*19c3b8c2SApple OSS Distributions };
197*19c3b8c2SApple OSS Distributions 
198*19c3b8c2SApple OSS Distributions /*
199*19c3b8c2SApple OSS Distributions  * user64 version - this structure only has to be correct if
200*19c3b8c2SApple OSS Distributions  * compiled LP64, because the 32 bit kernel doesn't need it
201*19c3b8c2SApple OSS Distributions  */
202*19c3b8c2SApple OSS Distributions struct user64_msqid_ds {
203*19c3b8c2SApple OSS Distributions 	struct ipc_perm msg_perm;       /* [XSI] msg queue permissions */
204*19c3b8c2SApple OSS Distributions 	__int32_t       msg_first;      /* RESERVED: kernel use only */
205*19c3b8c2SApple OSS Distributions 	__int32_t       msg_last;       /* RESERVED: kernel use only */
206*19c3b8c2SApple OSS Distributions 	user64_msglen_t msg_cbytes;     /* # of bytes on the queue */
207*19c3b8c2SApple OSS Distributions 	user64_msgqnum_t        msg_qnum;       /* [XSI] number of msgs on the queue */
208*19c3b8c2SApple OSS Distributions 	user64_msglen_t msg_qbytes;     /* [XSI] max bytes on the queue */
209*19c3b8c2SApple OSS Distributions 	pid_t           msg_lspid;      /* [XSI] pid of last msgsnd() */
210*19c3b8c2SApple OSS Distributions 	pid_t           msg_lrpid;      /* [XSI] pid of last msgrcv() */
211*19c3b8c2SApple OSS Distributions 	user64_time_t   msg_stime;      /* [XSI] time of last msgsnd() */
212*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad1;       /* RESERVED: DO NOT USE */
213*19c3b8c2SApple OSS Distributions 	user64_time_t   msg_rtime;      /* [XSI] time of last msgrcv() */
214*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad2;       /* RESERVED: DO NOT USE */
215*19c3b8c2SApple OSS Distributions 	user64_time_t   msg_ctime;      /* [XSI] time of last msgctl() */
216*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad3;       /* RESERVED: DO NOT USE */
217*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad4[4];
218*19c3b8c2SApple OSS Distributions } __attribute__((__packed__));
219*19c3b8c2SApple OSS Distributions 
220*19c3b8c2SApple OSS Distributions struct user32_msqid_ds {
221*19c3b8c2SApple OSS Distributions 	struct __ipc_perm_new   msg_perm; /* [XSI] msg queue permissions */
222*19c3b8c2SApple OSS Distributions 	__int32_t       msg_first;      /* RESERVED: kernel use only */
223*19c3b8c2SApple OSS Distributions 	__int32_t       msg_last;       /* RESERVED: kernel use only */
224*19c3b8c2SApple OSS Distributions 	user32_msglen_t msg_cbytes;     /* # of bytes on the queue */
225*19c3b8c2SApple OSS Distributions 	user32_msgqnum_t        msg_qnum;       /* [XSI] number of msgs on the queue */
226*19c3b8c2SApple OSS Distributions 	user32_msglen_t msg_qbytes;     /* [XSI] max bytes on the queue */
227*19c3b8c2SApple OSS Distributions 	pid_t           msg_lspid;      /* [XSI] pid of last msgsnd() */
228*19c3b8c2SApple OSS Distributions 	pid_t           msg_lrpid;      /* [XSI] pid of last msgrcv() */
229*19c3b8c2SApple OSS Distributions 	user32_time_t           msg_stime;      /* [XSI] time of last msgsnd() */
230*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad1;       /* RESERVED: DO NOT USE */
231*19c3b8c2SApple OSS Distributions 	user32_time_t           msg_rtime;      /* [XSI] time of last msgrcv() */
232*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad2;       /* RESERVED: DO NOT USE */
233*19c3b8c2SApple OSS Distributions 	user32_time_t           msg_ctime;      /* [XSI] time of last msgctl() */
234*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad3;       /* RESERVED: DO NOT USE */
235*19c3b8c2SApple OSS Distributions 	__int32_t       msg_pad4[4];    /* RESERVED: DO NOT USE */
236*19c3b8c2SApple OSS Distributions };
237*19c3b8c2SApple OSS Distributions 
238*19c3b8c2SApple OSS Distributions #if __DARWIN_ALIGN_NATURAL
239*19c3b8c2SApple OSS Distributions #pragma options align=reset
240*19c3b8c2SApple OSS Distributions #endif
241*19c3b8c2SApple OSS Distributions 
242*19c3b8c2SApple OSS Distributions struct label;
243*19c3b8c2SApple OSS Distributions 
244*19c3b8c2SApple OSS Distributions /*
245*19c3b8c2SApple OSS Distributions  * Kernel wrapper for the user-level structure
246*19c3b8c2SApple OSS Distributions  */
247*19c3b8c2SApple OSS Distributions struct msqid_kernel {
248*19c3b8c2SApple OSS Distributions 	struct  user_msqid_ds u;
249*19c3b8c2SApple OSS Distributions 	struct  label *label;   /* MAC framework label */
250*19c3b8c2SApple OSS Distributions };
251*19c3b8c2SApple OSS Distributions 
252*19c3b8c2SApple OSS Distributions #endif  /* __APPLE_API_PRIVATE */
253*19c3b8c2SApple OSS Distributions #endif  /* KERNEL */
254*19c3b8c2SApple OSS Distributions 
255*19c3b8c2SApple OSS Distributions 
256*19c3b8c2SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
257*19c3b8c2SApple OSS Distributions #ifdef __APPLE_API_UNSTABLE
258*19c3b8c2SApple OSS Distributions /* XXX kernel only; protect with macro later */
259*19c3b8c2SApple OSS Distributions 
260*19c3b8c2SApple OSS Distributions struct msg {
261*19c3b8c2SApple OSS Distributions 	struct msg      *msg_next;      /* next msg in the chain */
262*19c3b8c2SApple OSS Distributions 	long            msg_type;       /* type of this message */
263*19c3b8c2SApple OSS Distributions 	                                /* >0 -> type of this message */
264*19c3b8c2SApple OSS Distributions 	                                /* 0 -> free header */
265*19c3b8c2SApple OSS Distributions 	unsigned short  msg_ts;         /* size of this message */
266*19c3b8c2SApple OSS Distributions 	short           msg_spot;       /* location of msg start in buffer */
267*19c3b8c2SApple OSS Distributions 	struct label    *label;         /* MAC label */
268*19c3b8c2SApple OSS Distributions };
269*19c3b8c2SApple OSS Distributions 
270*19c3b8c2SApple OSS Distributions /*
271*19c3b8c2SApple OSS Distributions  * Example structure describing a message whose address is to be passed as
272*19c3b8c2SApple OSS Distributions  * the second argument to the functions msgrcv() and msgsnd().  The only
273*19c3b8c2SApple OSS Distributions  * actual hard requirement is that the first field be of type long, and
274*19c3b8c2SApple OSS Distributions  * contain the message type.  The user is encouraged to define their own
275*19c3b8c2SApple OSS Distributions  * application specific structure; this definition is included solely for
276*19c3b8c2SApple OSS Distributions  * backward compatability with existing source code.
277*19c3b8c2SApple OSS Distributions  */
278*19c3b8c2SApple OSS Distributions struct mymsg {
279*19c3b8c2SApple OSS Distributions 	long    mtype;          /* message type (+ve integer) */
280*19c3b8c2SApple OSS Distributions 	char    mtext[1];       /* message body */
281*19c3b8c2SApple OSS Distributions };
282*19c3b8c2SApple OSS Distributions 
283*19c3b8c2SApple OSS Distributions /*
284*19c3b8c2SApple OSS Distributions  * Based on the configuration parameters described in an SVR2 (yes, two)
285*19c3b8c2SApple OSS Distributions  * config(1m) man page.
286*19c3b8c2SApple OSS Distributions  *
287*19c3b8c2SApple OSS Distributions  * Each message is broken up and stored in segments that are msgssz bytes
288*19c3b8c2SApple OSS Distributions  * long.  For efficiency reasons, this should be a power of two.  Also,
289*19c3b8c2SApple OSS Distributions  * it doesn't make sense if it is less than 8 or greater than about 256.
290*19c3b8c2SApple OSS Distributions  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
291*19c3b8c2SApple OSS Distributions  * two between 8 and 1024 inclusive (and panic's if it isn't).
292*19c3b8c2SApple OSS Distributions  */
293*19c3b8c2SApple OSS Distributions struct msginfo {
294*19c3b8c2SApple OSS Distributions 	int     msgmax,         /* max chars in a message */
295*19c3b8c2SApple OSS Distributions 	    msgmni,             /* max message queue identifiers */
296*19c3b8c2SApple OSS Distributions 	    msgmnb,             /* max chars in a queue */
297*19c3b8c2SApple OSS Distributions 	    msgtql,             /* max messages in system */
298*19c3b8c2SApple OSS Distributions 	    msgssz,             /* size of a message segment (see notes above) */
299*19c3b8c2SApple OSS Distributions 	    msgseg;             /* number of message segments */
300*19c3b8c2SApple OSS Distributions };
301*19c3b8c2SApple OSS Distributions #ifdef KERNEL
302*19c3b8c2SApple OSS Distributions extern struct msginfo   msginfo;
303*19c3b8c2SApple OSS Distributions 
304*19c3b8c2SApple OSS Distributions #ifndef MSGSSZ
305*19c3b8c2SApple OSS Distributions #define MSGSSZ  8               /* Each segment must be 2^N long */
306*19c3b8c2SApple OSS Distributions #endif
307*19c3b8c2SApple OSS Distributions #ifndef MSGSEG
308*19c3b8c2SApple OSS Distributions #define MSGSEG  2048            /* must be less than 32767 */
309*19c3b8c2SApple OSS Distributions #endif
310*19c3b8c2SApple OSS Distributions #define MSGMAX  (MSGSSZ*MSGSEG)
311*19c3b8c2SApple OSS Distributions #ifndef MSGMNB
312*19c3b8c2SApple OSS Distributions #define MSGMNB  2048            /* max # of bytes in a queue */
313*19c3b8c2SApple OSS Distributions #endif
314*19c3b8c2SApple OSS Distributions #ifndef MSGMNI
315*19c3b8c2SApple OSS Distributions #define MSGMNI  40
316*19c3b8c2SApple OSS Distributions #endif
317*19c3b8c2SApple OSS Distributions #ifndef MSGTQL
318*19c3b8c2SApple OSS Distributions #define MSGTQL  40
319*19c3b8c2SApple OSS Distributions #endif
320*19c3b8c2SApple OSS Distributions 
321*19c3b8c2SApple OSS Distributions /*
322*19c3b8c2SApple OSS Distributions  * macros to convert between msqid_ds's and msqid's.
323*19c3b8c2SApple OSS Distributions  * (specific to this implementation)
324*19c3b8c2SApple OSS Distributions  */
325*19c3b8c2SApple OSS Distributions #define MSQID(ix, ds)    ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
326*19c3b8c2SApple OSS Distributions #define MSQID_IX(id)    ((id) & 0xffff)
327*19c3b8c2SApple OSS Distributions #define MSQID_SEQ(id)   (((id) >> 16) & 0xffff)
328*19c3b8c2SApple OSS Distributions 
329*19c3b8c2SApple OSS Distributions /*
330*19c3b8c2SApple OSS Distributions  * The rest of this file is specific to this particular implementation.
331*19c3b8c2SApple OSS Distributions  */
332*19c3b8c2SApple OSS Distributions 
333*19c3b8c2SApple OSS Distributions 
334*19c3b8c2SApple OSS Distributions /*
335*19c3b8c2SApple OSS Distributions  * Stuff allocated in machdep.h
336*19c3b8c2SApple OSS Distributions  */
337*19c3b8c2SApple OSS Distributions struct msgmap {
338*19c3b8c2SApple OSS Distributions 	short   next;           /* next segment in buffer */
339*19c3b8c2SApple OSS Distributions 	                        /* -1 -> available */
340*19c3b8c2SApple OSS Distributions 	                        /* 0..(MSGSEG-1) -> index of next segment */
341*19c3b8c2SApple OSS Distributions };
342*19c3b8c2SApple OSS Distributions 
343*19c3b8c2SApple OSS Distributions /* The following four externs really, really need to die; should be static */
344*19c3b8c2SApple OSS Distributions extern char *msgpool;           /* MSGMAX byte long msg buffer pool */
345*19c3b8c2SApple OSS Distributions extern struct msgmap *msgmaps;  /* MSGSEG msgmap structures */
346*19c3b8c2SApple OSS Distributions extern struct msg *msghdrs;     /* MSGTQL msg headers */
347*19c3b8c2SApple OSS Distributions extern struct msqid_kernel *msqids;     /* MSGMNI user_msqid_ds struct's */
348*19c3b8c2SApple OSS Distributions 
349*19c3b8c2SApple OSS Distributions #define MSG_LOCKED      01000   /* Is this msqid_ds locked? */
350*19c3b8c2SApple OSS Distributions 
351*19c3b8c2SApple OSS Distributions #endif  /* KERNEL */
352*19c3b8c2SApple OSS Distributions #endif  /* __APPLE_API_UNSTABLE */
353*19c3b8c2SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
354*19c3b8c2SApple OSS Distributions 
355*19c3b8c2SApple OSS Distributions #ifndef KERNEL
356*19c3b8c2SApple OSS Distributions 
357*19c3b8c2SApple OSS Distributions __BEGIN_DECLS
358*19c3b8c2SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
359*19c3b8c2SApple OSS Distributions int msgsys(int, ...);
360*19c3b8c2SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
361*19c3b8c2SApple OSS Distributions int msgctl(int, int, struct msqid_ds *) __DARWIN_ALIAS(msgctl);
362*19c3b8c2SApple OSS Distributions int msgget(key_t, int);
363*19c3b8c2SApple OSS Distributions ssize_t msgrcv(int, void *, size_t, long, int) __DARWIN_ALIAS_C(msgrcv);
364*19c3b8c2SApple OSS Distributions int msgsnd(int, const void *, size_t, int) __DARWIN_ALIAS_C(msgsnd);
365*19c3b8c2SApple OSS Distributions __END_DECLS
366*19c3b8c2SApple OSS Distributions 
367*19c3b8c2SApple OSS Distributions #endif /* !KERNEL */
368*19c3b8c2SApple OSS Distributions 
369*19c3b8c2SApple OSS Distributions #endif /* !_SYS_MSG_H_ */
370