FreeBSD/Linux Kernel Cross Reference
sys/sys/msg.h
1 /* $NetBSD: msg.h,v 1.20 2006/07/23 22:06:14 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * SVID compatible msg.h file
42 *
43 * Author: Daniel Boulet
44 *
45 * Copyright 1993 Daniel Boulet and RTMX Inc.
46 *
47 * This system call was implemented by Daniel Boulet under contract from RTMX.
48 *
49 * Redistribution and use in source forms, with and without modification,
50 * are permitted provided that this entire comment appears intact.
51 *
52 * Redistribution in binary form may occur without any restrictions.
53 * Obviously, it would be nice if you gave credit where credit is due
54 * but requiring it would be too onerous.
55 *
56 * This software is provided ``AS IS'' without any warranties of any kind.
57 */
58
59 #ifndef _SYS_MSG_H_
60 #define _SYS_MSG_H_
61
62 #include <sys/featuretest.h>
63 #include <sys/ipc.h>
64
65 #ifdef _KERNEL
66 struct __msg {
67 struct __msg *msg_next; /* next msg in the chain */
68 long msg_type; /* type of this message */
69 /* >0 -> type of this message */
70 /* 0 -> free header */
71 u_short msg_ts; /* size of this message */
72 short msg_spot; /* location of start of msg in buffer */
73 };
74 #endif /* _KERNEL */
75
76 #define MSG_NOERROR 010000 /* don't complain about too long msgs */
77
78 typedef unsigned long msgqnum_t;
79 typedef size_t msglen_t;
80
81 struct msqid_ds {
82 struct ipc_perm msg_perm; /* operation permission strucure */
83 msgqnum_t msg_qnum; /* number of messages in the queue */
84 msglen_t msg_qbytes; /* max # of bytes in the queue */
85 pid_t msg_lspid; /* process ID of last msgsend() */
86 pid_t msg_lrpid; /* process ID of last msgrcv() */
87 time_t msg_stime; /* time of last msgsend() */
88 time_t msg_rtime; /* time of last msgrcv() */
89 time_t msg_ctime; /* time of last change */
90
91 /*
92 * These members are private and used only in the internal
93 * implementation of this interface.
94 */
95 struct __msg *_msg_first; /* first message in the queue */
96 struct __msg *_msg_last; /* last message in the queue */
97 msglen_t _msg_cbytes; /* # of bytes currently in queue */
98 };
99
100 #if defined(_NETBSD_SOURCE)
101 /*
102 * Based on the configuration parameters described in an SVR2 (yes, two)
103 * config(1m) man page.
104 *
105 * Each message is broken up and stored in segments that are msgssz bytes
106 * long. For efficiency reasons, this should be a power of two. Also,
107 * it doesn't make sense if it is less than 8 or greater than about 256.
108 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
109 * two between 8 and 1024 inclusive (and panic's if it isn't).
110 */
111 struct msginfo {
112 int32_t msgmax; /* max chars in a message */
113 int32_t msgmni; /* max message queue identifiers */
114 int32_t msgmnb; /* max chars in a queue */
115 int32_t msgtql; /* max messages in system */
116 int32_t msgssz; /* size of a message segment
117 (see notes above) */
118 int32_t msgseg; /* number of message segments */
119 };
120
121 /* Warning: 64-bit structure padding is needed here */
122 struct msgid_ds_sysctl {
123 struct ipc_perm_sysctl msg_perm;
124 uint64_t msg_qnum;
125 uint64_t msg_qbytes;
126 uint64_t _msg_cbytes;
127 pid_t msg_lspid;
128 pid_t msg_lrpid;
129 time_t msg_stime;
130 time_t msg_rtime;
131 time_t msg_ctime;
132 int32_t pad;
133 };
134 struct msg_sysctl_info {
135 struct msginfo msginfo;
136 struct msgid_ds_sysctl msgids[1];
137 };
138 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
139
140 #ifdef _KERNEL
141
142 #ifndef MSGSSZ
143 #define MSGSSZ 8 /* Each segment must be 2^N long */
144 #endif
145 #ifndef MSGSEG
146 #define MSGSEG 2048 /* must be less than 32767 */
147 #endif
148 #undef MSGMAX /* ALWAYS compute MGSMAX! */
149 #define MSGMAX (MSGSSZ*MSGSEG)
150 #ifndef MSGMNB
151 #define MSGMNB 2048 /* max # of bytes in a queue */
152 #endif
153 #ifndef MSGMNI
154 #define MSGMNI 40
155 #endif
156 #ifndef MSGTQL
157 #define MSGTQL 40
158 #endif
159
160 /*
161 * macros to convert between msqid_ds's and msqid's.
162 */
163 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm._seq << 16) & 0xffff0000))
164 #define MSQID_IX(id) ((id) & 0xffff)
165 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
166
167 /*
168 * Stuff allocated in machdep.h
169 */
170 struct msgmap {
171 short next; /* next segment in buffer */
172 /* -1 -> available */
173 /* 0..(MSGSEG-1) -> index of next segment */
174 };
175
176 extern struct msginfo msginfo;
177 extern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */
178
179 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */
180
181 #endif /* _KERNEL */
182
183 #ifndef _KERNEL
184 #include <sys/cdefs.h>
185
186 __BEGIN_DECLS
187 int msgctl(int, int, struct msqid_ds *) __RENAME(__msgctl13);
188 int msgget(key_t, int);
189 int msgsnd(int, const void *, size_t, int);
190 ssize_t msgrcv(int, void *, size_t, long, int);
191 __END_DECLS
192 #else
193 #include <sys/systm.h>
194
195 struct proc;
196
197 void msginit(void);
198 int msgctl1(struct lwp *, int, int, struct msqid_ds *);
199 int msgsnd1(struct lwp *, int, const char *, size_t, int, size_t,
200 copyin_t);
201 int msgrcv1(struct lwp *, int, char *, size_t, long, int, size_t,
202 copyout_t, register_t *);
203 #endif /* !_KERNEL */
204
205 #endif /* !_SYS_MSG_H_ */
Cache object: a42a39037d1e05c00e4911f78338eb70
|