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