]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/msg.h
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */
31 * SVID compatible msg.h file
33 * Author: Daniel Boulet
35 * Copyright 1993 Daniel Boulet and RTMX Inc.
37 * This system call was implemented by Daniel Boulet under contract from RTMX.
39 * Redistribution and use in source forms, with and without modification,
40 * are permitted provided that this entire comment appears intact.
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.
46 * This software is provided ``AS IS'' without any warranties of any kind.
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,
58 #include <sys/appleapiopts.h>
60 #include <sys/_types.h>
61 #include <sys/cdefs.h>
64 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined when this
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>.
74 * NOTE: The definition of the key_t type is implicit from the
75 * inclusion of <sys/ipc.h>
78 typedef __darwin_pid_t pid_t
;
84 typedef __darwin_time_t
time_t;
89 typedef __darwin_size_t
size_t;
94 typedef __darwin_ssize_t ssize_t
;
97 /* [XSI] Used for the number of messages in the message queue */
98 typedef unsigned long msgqnum_t
;
99 typedef unsigned long long user_msgqnum_t
;
101 /* [XSI] Used for the number of bytes allowed in a message queue */
102 typedef unsigned long msglen_t
;
103 typedef unsigned long long user_msglen_t
;
107 * Possible values for the fifth parameter to msgrcv(), in addition to the
108 * IPC_NOWAIT flag, which is permitted.
110 #define MSG_NOERROR 010000 /* [XSI] No error if big message */
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.
119 #if __DARWIN_UNIX03 || defined(KERNEL)
122 * Structure used internally.
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.
131 * NOTES: Reserved fields are not preserved across IPC_SET/IPC_STAT.
133 #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
136 #define msqid_ds __msqid_ds_new
137 struct __msqid_ds_new
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 */
157 #else /* !__DARWIN_UNIX03 */
158 #define msqid_ds __msqid_ds_old
159 #endif /* !__DARWIN_UNIX03 */
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 */
179 #endif /* !__DARWIN_UNIX03 */
182 #ifdef __APPLE_API_PRIVATE
183 #include <machine/types.h>
185 #if __DARWIN_ALIGN_NATURAL
186 #pragma options align=natural
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 */
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 */
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];
207 #if __DARWIN_ALIGN_NATURAL
208 #pragma options align=reset
214 * Kernel wrapper for the user-level structure
216 struct msqid_kernel
{
217 struct user_msqid_ds u
;
218 struct label
*label
; /* MAC framework label */
221 #endif /* __APPLE_API_PRIVATE */
225 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
226 #ifdef __APPLE_API_UNSTABLE
227 /* XXX kernel only; protect with macro later */
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 */
236 struct label
*label
; /* MAC label */
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.
248 long mtype
; /* message type (+ve integer) */
249 char mtext
[1]; /* message body */
253 * Based on the configuration parameters described in an SVR2 (yes, two)
254 * config(1m) man page.
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).
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 */
271 extern struct msginfo msginfo
;
274 #define MSGSSZ 8 /* Each segment must be 2^N long */
277 #define MSGSEG 2048 /* must be less than 32767 */
279 #define MSGMAX (MSGSSZ*MSGSEG)
281 #define MSGMNB 2048 /* max # of bytes in a queue */
291 * macros to convert between msqid_ds's and msqid's.
292 * (specific to this implementation)
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)
299 * The rest of this file is specific to this particular implementation.
304 * Stuff allocated in machdep.h
307 short next
; /* next segment in buffer */
308 /* -1 -> available */
309 /* 0..(MSGSEG-1) -> index of next segment */
312 /* The following four externs really, really need to die; should be static */
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 */
316 extern struct msqid_kernel
*msqids
; /* MSGMNI user_msqid_ds struct's */
318 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
321 #endif /* __APPLE_API_UNSTABLE */
322 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
327 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
328 int msgsys(int, ...);
329 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
330 int msgctl(int, int, struct msqid_ds
*) __DARWIN_ALIAS(msgctl
);
331 int msgget(key_t
, int);
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
);
338 #endif /* !_SYS_MSG_H_ */