]>
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@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
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 | |
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. | |
8f6c56a5 | 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 | */ | |
77 | #ifndef _PID_T | |
78 | typedef __darwin_pid_t pid_t; | |
79 | #define _PID_T | |
80 | #endif | |
81 | ||
82 | #ifndef _TIME_T | |
83 | #define _TIME_T | |
84 | typedef __darwin_time_t time_t; | |
85 | #endif | |
86 | ||
87 | #ifndef _SIZE_T | |
88 | #define _SIZE_T | |
89 | typedef __darwin_size_t size_t; | |
90 | #endif | |
91 | ||
92 | #ifndef _SSIZE_T | |
93 | #define _SSIZE_T | |
94 | typedef __darwin_ssize_t ssize_t; | |
95 | #endif | |
96 | ||
97 | /* [XSI] Used for the number of messages in the message queue */ | |
98 | typedef unsigned long msgqnum_t; | |
2d21ac55 | 99 | typedef unsigned long long user_msgqnum_t; |
91447636 A |
100 | |
101 | /* [XSI] Used for the number of bytes allowed in a message queue */ | |
102 | typedef unsigned long msglen_t; | |
2d21ac55 | 103 | typedef unsigned long long user_msglen_t; |
91447636 A |
104 | |
105 | ||
106 | /* | |
107 | * Possible values for the fifth parameter to msgrcv(), in addition to the | |
108 | * IPC_NOWAIT flag, which is permitted. | |
1c79356b | 109 | */ |
91447636 A |
110 | #define MSG_NOERROR 010000 /* [XSI] No error if big message */ |
111 | ||
1c79356b | 112 | |
91447636 A |
113 | /* |
114 | * Technically, we should force all code references to the new structure | |
115 | * definition, not in just the standards conformance case, and leave the | |
116 | * legacy interface there for binary compatibility only. Currently, we | |
117 | * are only forcing this for programs requesting standards conformance. | |
118 | */ | |
2d21ac55 A |
119 | #if __DARWIN_UNIX03 || defined(KERNEL) |
120 | #pragma pack(4) | |
91447636 A |
121 | /* |
122 | * Structure used internally. | |
123 | * | |
124 | * Structure whose address is passed as the third parameter to msgctl() | |
125 | * when the second parameter is IPC_SET or IPC_STAT. In the case of the | |
126 | * IPC_SET command, only the msg_perm.{uid|gid|perm} and msg_qbytes are | |
127 | * honored. In the case of IPC_STAT, only the fields indicated as [XSI] | |
128 | * mandated fields are guaranteed to meaningful: DO NOT depend on the | |
129 | * contents of the other fields. | |
130 | * | |
131 | * NOTES: Reserved fields are not preserved across IPC_SET/IPC_STAT. | |
132 | */ | |
2d21ac55 A |
133 | #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)) |
134 | struct msqid_ds | |
135 | #else | |
136 | #define msqid_ds __msqid_ds_new | |
137 | struct __msqid_ds_new | |
138 | #endif | |
139 | { | |
91447636 A |
140 | struct __ipc_perm_new msg_perm; /* [XSI] msg queue permissions */ |
141 | __int32_t msg_first; /* RESERVED: kernel use only */ | |
142 | __int32_t msg_last; /* RESERVED: kernel use only */ | |
143 | msglen_t msg_cbytes; /* # of bytes on the queue */ | |
144 | msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */ | |
145 | msglen_t msg_qbytes; /* [XSI] max bytes on the queue */ | |
146 | pid_t msg_lspid; /* [XSI] pid of last msgsnd() */ | |
147 | pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */ | |
148 | time_t msg_stime; /* [XSI] time of last msgsnd() */ | |
149 | __int32_t msg_pad1; /* RESERVED: DO NOT USE */ | |
150 | time_t msg_rtime; /* [XSI] time of last msgrcv() */ | |
151 | __int32_t msg_pad2; /* RESERVED: DO NOT USE */ | |
152 | time_t msg_ctime; /* [XSI] time of last msgctl() */ | |
153 | __int32_t msg_pad3; /* RESERVED: DO NOT USE */ | |
154 | __int32_t msg_pad4[4]; /* RESERVED: DO NOT USE */ | |
155 | }; | |
2d21ac55 A |
156 | #pragma pack() |
157 | #else /* !__DARWIN_UNIX03 */ | |
91447636 | 158 | #define msqid_ds __msqid_ds_old |
2d21ac55 | 159 | #endif /* !__DARWIN_UNIX03 */ |
91447636 | 160 | |
2d21ac55 | 161 | #if !__DARWIN_UNIX03 |
91447636 A |
162 | struct __msqid_ds_old { |
163 | struct __ipc_perm_old msg_perm; /* [XSI] msg queue permissions */ | |
164 | __int32_t msg_first; /* RESERVED: kernel use only */ | |
165 | __int32_t msg_last; /* RESERVED: kernel use only */ | |
166 | msglen_t msg_cbytes; /* # of bytes on the queue */ | |
167 | msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */ | |
168 | msglen_t msg_qbytes; /* [XSI] max bytes on the queue */ | |
169 | pid_t msg_lspid; /* [XSI] pid of last msgsnd() */ | |
170 | pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */ | |
171 | time_t msg_stime; /* [XSI] time of last msgsnd() */ | |
172 | __int32_t msg_pad1; /* RESERVED: DO NOT USE */ | |
173 | time_t msg_rtime; /* [XSI] time of last msgrcv() */ | |
174 | __int32_t msg_pad2; /* RESERVED: DO NOT USE */ | |
175 | time_t msg_ctime; /* [XSI] time of last msgctl() */ | |
176 | __int32_t msg_pad3; /* RESERVED: DO NOT USE */ | |
177 | __int32_t msg_pad4[4]; /* RESERVED: DO NOT USE */ | |
1c79356b | 178 | }; |
2d21ac55 | 179 | #endif /* !__DARWIN_UNIX03 */ |
91447636 A |
180 | |
181 | #ifdef KERNEL | |
182 | #ifdef __APPLE_API_PRIVATE | |
183 | #include <machine/types.h> | |
184 | ||
91447636 A |
185 | #if __DARWIN_ALIGN_NATURAL |
186 | #pragma options align=natural | |
187 | #endif | |
188 | ||
189 | struct user_msqid_ds { | |
190 | struct ipc_perm msg_perm; /* [XSI] msg queue permissions */ | |
191 | struct msg *msg_first; /* first message in the queue */ | |
192 | struct msg *msg_last; /* last message in the queue */ | |
2d21ac55 A |
193 | user_msglen_t msg_cbytes; /* # of bytes on the queue */ |
194 | user_msgqnum_t msg_qnum; /* [XSI] number of msgs on the queue */ | |
195 | user_msglen_t msg_qbytes; /* [XSI] max bytes on the queue */ | |
91447636 A |
196 | pid_t msg_lspid; /* [XSI] pid of last msgsnd() */ |
197 | pid_t msg_lrpid; /* [XSI] pid of last msgrcv() */ | |
198 | user_time_t msg_stime; /* [XSI] time of last msgsnd() */ | |
199 | __int32_t msg_pad1; /* RESERVED: DO NOT USE */ | |
200 | user_time_t msg_rtime; /* [XSI] time of last msgrcv() */ | |
201 | __int32_t msg_pad2; /* RESERVED: DO NOT USE */ | |
202 | user_time_t msg_ctime; /* [XSI] time of last msgctl() */ | |
203 | __int32_t msg_pad3; /* RESERVED: DO NOT USE */ | |
204 | __int32_t msg_pad4[4]; | |
205 | }; | |
206 | ||
207 | #if __DARWIN_ALIGN_NATURAL | |
208 | #pragma options align=reset | |
209 | #endif | |
210 | ||
2d21ac55 A |
211 | struct label; |
212 | ||
213 | /* | |
214 | * Kernel wrapper for the user-level structure | |
215 | */ | |
216 | struct msqid_kernel { | |
217 | struct user_msqid_ds u; | |
218 | struct label *label; /* MAC framework label */ | |
219 | }; | |
220 | ||
91447636 A |
221 | #endif /* __APPLE_API_PRIVATE */ |
222 | #endif /* KERNEL */ | |
223 | ||
224 | ||
2d21ac55 | 225 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
91447636 A |
226 | #ifdef __APPLE_API_UNSTABLE |
227 | /* XXX kernel only; protect with macro later */ | |
1c79356b A |
228 | |
229 | struct msg { | |
91447636 A |
230 | struct msg *msg_next; /* next msg in the chain */ |
231 | long msg_type; /* type of this message */ | |
232 | /* >0 -> type of this message */ | |
233 | /* 0 -> free header */ | |
234 | unsigned short msg_ts; /* size of this message */ | |
235 | short msg_spot; /* location of msg start in buffer */ | |
2d21ac55 | 236 | struct label *label; /* MAC label */ |
1c79356b A |
237 | }; |
238 | ||
239 | /* | |
91447636 A |
240 | * Example structure describing a message whose address is to be passed as |
241 | * the second argument to the functions msgrcv() and msgsnd(). The only | |
242 | * actual hard requirement is that the first field be of type long, and | |
243 | * contain the message type. The user is encouraged to define their own | |
244 | * application specific structure; this definition is included solely for | |
245 | * backward compatability with existing source code. | |
1c79356b A |
246 | */ |
247 | struct mymsg { | |
248 | long mtype; /* message type (+ve integer) */ | |
249 | char mtext[1]; /* message body */ | |
250 | }; | |
251 | ||
252 | /* | |
253 | * Based on the configuration parameters described in an SVR2 (yes, two) | |
254 | * config(1m) man page. | |
255 | * | |
256 | * Each message is broken up and stored in segments that are msgssz bytes | |
257 | * long. For efficiency reasons, this should be a power of two. Also, | |
258 | * it doesn't make sense if it is less than 8 or greater than about 256. | |
259 | * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of | |
260 | * two between 8 and 1024 inclusive (and panic's if it isn't). | |
261 | */ | |
262 | struct msginfo { | |
263 | int msgmax, /* max chars in a message */ | |
264 | msgmni, /* max message queue identifiers */ | |
265 | msgmnb, /* max chars in a queue */ | |
266 | msgtql, /* max messages in system */ | |
267 | msgssz, /* size of a message segment (see notes above) */ | |
268 | msgseg; /* number of message segments */ | |
269 | }; | |
270 | #ifdef KERNEL | |
271 | extern struct msginfo msginfo; | |
272 | ||
273 | #ifndef MSGSSZ | |
274 | #define MSGSSZ 8 /* Each segment must be 2^N long */ | |
275 | #endif | |
276 | #ifndef MSGSEG | |
277 | #define MSGSEG 2048 /* must be less than 32767 */ | |
278 | #endif | |
279 | #define MSGMAX (MSGSSZ*MSGSEG) | |
280 | #ifndef MSGMNB | |
281 | #define MSGMNB 2048 /* max # of bytes in a queue */ | |
282 | #endif | |
283 | #ifndef MSGMNI | |
284 | #define MSGMNI 40 | |
285 | #endif | |
286 | #ifndef MSGTQL | |
287 | #define MSGTQL 40 | |
288 | #endif | |
289 | ||
290 | /* | |
291 | * macros to convert between msqid_ds's and msqid's. | |
292 | * (specific to this implementation) | |
293 | */ | |
294 | #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000)) | |
295 | #define MSQID_IX(id) ((id) & 0xffff) | |
296 | #define MSQID_SEQ(id) (((id) >> 16) & 0xffff) | |
297 | ||
298 | /* | |
299 | * The rest of this file is specific to this particular implementation. | |
300 | */ | |
301 | ||
302 | ||
303 | /* | |
304 | * Stuff allocated in machdep.h | |
305 | */ | |
306 | struct msgmap { | |
307 | short next; /* next segment in buffer */ | |
308 | /* -1 -> available */ | |
309 | /* 0..(MSGSEG-1) -> index of next segment */ | |
310 | }; | |
311 | ||
91447636 | 312 | /* The following four externs really, really need to die; should be static */ |
1c79356b A |
313 | extern char *msgpool; /* MSGMAX byte long msg buffer pool */ |
314 | extern struct msgmap *msgmaps; /* MSGSEG msgmap structures */ | |
315 | extern struct msg *msghdrs; /* MSGTQL msg headers */ | |
2d21ac55 | 316 | extern struct msqid_kernel *msqids; /* MSGMNI user_msqid_ds struct's */ |
1c79356b A |
317 | |
318 | #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */ | |
319 | ||
91447636 A |
320 | #endif /* KERNEL */ |
321 | #endif /* __APPLE_API_UNSTABLE */ | |
2d21ac55 | 322 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
323 | |
324 | #ifndef KERNEL | |
1c79356b A |
325 | |
326 | __BEGIN_DECLS | |
2d21ac55 | 327 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
91447636 | 328 | int msgsys(int, ...); |
2d21ac55 | 329 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
91447636 A |
330 | int msgctl(int, int, struct msqid_ds *) __DARWIN_ALIAS(msgctl); |
331 | int msgget(key_t, int); | |
2d21ac55 A |
332 | ssize_t msgrcv(int, void *, size_t, long, int) __DARWIN_ALIAS_C(msgrcv); |
333 | int msgsnd(int, const void *, size_t, int) __DARWIN_ALIAS_C(msgsnd); | |
1c79356b | 334 | __END_DECLS |
91447636 | 335 | |
1c79356b A |
336 | #endif /* !KERNEL */ |
337 | ||
338 | #endif /* !_SYS_MSG_H_ */ | |
2d21ac55 A |
339 | |
340 |