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