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