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