]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/msg.h
f43198c75b28fef3d05c0d5d2df449fa869ecc1b
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */
33 * SVID compatible msg.h file
35 * Author: Daniel Boulet
37 * Copyright 1993 Daniel Boulet and RTMX Inc.
39 * This system call was implemented by Daniel Boulet under contract from RTMX.
41 * Redistribution and use in source forms, with and without modification,
42 * are permitted provided that this entire comment appears intact.
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.
48 * This software is provided ``AS IS'' without any warranties of any kind.
54 #include <sys/appleapiopts.h>
56 #include <sys/_types.h>
57 #include <sys/cdefs.h>
60 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined when this
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>.
70 * NOTE: The definition of the key_t type is implicit from the
71 * inclusion of <sys/ipc.h>
74 typedef __darwin_pid_t pid_t
;
80 typedef __darwin_time_t
time_t;
85 typedef __darwin_size_t
size_t;
90 typedef __darwin_ssize_t ssize_t
;
93 /* [XSI] Used for the number of messages in the message queue */
94 typedef unsigned long msgqnum_t
;
96 /* [XSI] Used for the number of bytes allowed in a message queue */
97 typedef unsigned long msglen_t
;
101 * Possible values for the fifth parameter to msgrcv(), in addition to the
102 * IPC_NOWAIT flag, which is permitted.
104 #define MSG_NOERROR 010000 /* [XSI] No error if big message */
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.
113 #if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
115 * Structure used internally.
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.
124 * NOTES: Reserved fields are not preserved across IPC_SET/IPC_STAT.
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 */
143 #define msqid_ds __msqid_ds_new
144 #else /* !_POSIX_C_SOURCE */
145 #define msqid_ds __msqid_ds_old
146 #endif /* !_POSIX_C_SOURCE */
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 */
166 #endif /* !_POSIX_C_SOURCE */
169 #ifdef __APPLE_API_PRIVATE
170 #include <machine/types.h>
172 // LP64todo - should this move?
174 #if __DARWIN_ALIGN_NATURAL
175 #pragma options align=natural
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];
196 #if __DARWIN_ALIGN_NATURAL
197 #pragma options align=reset
200 #endif /* __APPLE_API_PRIVATE */
204 #ifndef _POSIX_C_SOURCE
205 #ifdef __APPLE_API_UNSTABLE
206 /* XXX kernel only; protect with macro later */
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 */
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.
226 long mtype
; /* message type (+ve integer) */
227 char mtext
[1]; /* message body */
231 * Based on the configuration parameters described in an SVR2 (yes, two)
232 * config(1m) man page.
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).
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 */
249 extern struct msginfo msginfo
;
252 #define MSGSSZ 8 /* Each segment must be 2^N long */
255 #define MSGSEG 2048 /* must be less than 32767 */
257 #define MSGMAX (MSGSSZ*MSGSEG)
259 #define MSGMNB 2048 /* max # of bytes in a queue */
269 * macros to convert between msqid_ds's and msqid's.
270 * (specific to this implementation)
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)
277 * The rest of this file is specific to this particular implementation.
282 * Stuff allocated in machdep.h
285 short next
; /* next segment in buffer */
286 /* -1 -> available */
287 /* 0..(MSGSEG-1) -> index of next segment */
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 */
296 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
299 #endif /* __APPLE_API_UNSTABLE */
300 #endif /* !_POSIX_C_SOURCE */
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);
316 #endif /* !_SYS_MSG_H_ */