1 /* $NetBSD: msg.h,v 1.13 2000/06/02 15:53:05 simonb 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/ipc.h> 63 64 #ifdef _KERNEL 65 struct __msg { 66 struct __msg *msg_next; /* next msg in the chain */ 67 long msg_type; /* type of this message */ 68 /* >0 -> type of this message */ 69 /* 0 -> free header */ 70 u_short msg_ts; /* size of this message */ 71 short msg_spot; /* location of start of msg in buffer */ 72 }; 73 #endif /* _KERNEL */ 74 75 #define MSG_NOERROR 010000 /* don't complain about too long msgs */ 76 77 typedef unsigned long msgqnum_t; 78 typedef size_t msglen_t; 79 80 struct msqid_ds { 81 struct ipc_perm msg_perm; /* operation permission strucure */ 82 msgqnum_t msg_qnum; /* number of messages in the queue */ 83 msglen_t msg_qbytes; /* max # of bytes in the queue */ 84 pid_t msg_lspid; /* process ID of last msgsend() */ 85 pid_t msg_lrpid; /* process ID of last msgrcv() */ 86 time_t msg_stime; /* time of last msgsend() */ 87 time_t msg_rtime; /* time of last msgrcv() */ 88 time_t msg_ctime; /* time of last change */ 89 90 /* 91 * These members are private and used only in the internal 92 * implementation of this interface. 93 */ 94 struct __msg *_msg_first; /* first message in the queue */ 95 struct __msg *_msg_last; /* last message in the queue */ 96 msglen_t _msg_cbytes; /* # of bytes currently in queue */ 97 }; 98 99 #ifdef _KERNEL 100 /* 101 * Old message queue data structure used before NetBSD 1.5. 102 */ 103 struct msqid_ds14 { 104 struct ipc_perm14 msg_perm; /* msg queue permission bits */ 105 struct __msg *msg_first; /* first message in the queue */ 106 struct __msg *msg_last; /* last message in the queue */ 107 u_long msg_cbytes; /* number of bytes in use on the queue */ 108 u_long msg_qnum; /* number of msgs in the queue */ 109 u_long msg_qbytes; /* max # of bytes on the queue */ 110 pid_t msg_lspid; /* pid of last msgsnd() */ 111 pid_t msg_lrpid; /* pid of last msgrcv() */ 112 time_t msg_stime; /* time of last msgsnd() */ 113 long msg_pad1; 114 time_t msg_rtime; /* time of last msgrcv() */ 115 long msg_pad2; 116 time_t msg_ctime; /* time of last msgctl() */ 117 long msg_pad3; 118 long msg_pad4[4]; 119 }; 120 #endif 121 122 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 123 /* 124 * Based on the configuration parameters described in an SVR2 (yes, two) 125 * config(1m) man page. 126 * 127 * Each message is broken up and stored in segments that are msgssz bytes 128 * long. For efficiency reasons, this should be a power of two. Also, 129 * it doesn't make sense if it is less than 8 or greater than about 256. 130 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of 131 * two between 8 and 1024 inclusive (and panic's if it isn't). 132 */ 133 struct msginfo { 134 int32_t msgmax; /* max chars in a message */ 135 int32_t msgmni; /* max message queue identifiers */ 136 int32_t msgmnb; /* max chars in a queue */ 137 int32_t msgtql; /* max messages in system */ 138 int32_t msgssz; /* size of a message segment 139 (see notes above) */ 140 int32_t msgseg; /* number of message segments */ 141 }; 142 143 /* Warning: 64-bit structure padding is needed here */ 144 struct msgid_ds_sysctl { 145 struct ipc_perm_sysctl msg_perm; 146 u_int64_t msg_qnum; 147 u_int64_t msg_qbytes; 148 u_int64_t _msg_cbytes; 149 pid_t msg_lspid; 150 pid_t msg_lrpid; 151 time_t msg_stime; 152 time_t msg_rtime; 153 time_t msg_ctime; 154 int32_t pad; 155 }; 156 struct msg_sysctl_info { 157 struct msginfo msginfo; 158 struct msgid_ds_sysctl msgids[1]; 159 }; 160 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 161 162 #ifdef _KERNEL 163 164 #ifndef MSGSSZ 165 #define MSGSSZ 8 /* Each segment must be 2^N long */ 166 #endif 167 #ifndef MSGSEG 168 #define MSGSEG 2048 /* must be less than 32767 */ 169 #endif 170 #undef MSGMAX /* ALWAYS compute MGSMAX! */ 171 #define MSGMAX (MSGSSZ*MSGSEG) 172 #ifndef MSGMNB 173 #define MSGMNB 2048 /* max # of bytes in a queue */ 174 #endif 175 #ifndef MSGMNI 176 #define MSGMNI 40 177 #endif 178 #ifndef MSGTQL 179 #define MSGTQL 40 180 #endif 181 182 /* 183 * macros to convert between msqid_ds's and msqid's. 184 */ 185 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm._seq << 16) & 0xffff0000)) 186 #define MSQID_IX(id) ((id) & 0xffff) 187 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff) 188 189 /* 190 * Stuff allocated in machdep.h 191 */ 192 struct msgmap { 193 short next; /* next segment in buffer */ 194 /* -1 -> available */ 195 /* 0..(MSGSEG-1) -> index of next segment */ 196 }; 197 198 extern struct msginfo msginfo; 199 extern char *msgpool; /* MSGMAX byte long msg buffer pool */ 200 extern struct msgmap *msgmaps; /* MSGSEG msgmap structures */ 201 extern struct __msg *msghdrs; /* MSGTQL msg headers */ 202 extern struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */ 203 204 #define MSG_LOCKED 01000 /* Is this msqid_ds locked? */ 205 206 #endif /* _KERNEL */ 207 208 #ifndef _KERNEL 209 #include <sys/cdefs.h> 210 211 __BEGIN_DECLS 212 int msgctl __P((int, int, struct msqid_ds *)) __RENAME(__msgctl13); 213 int msgget __P((key_t, int)); 214 int msgsnd __P((int, const void *, size_t, int)); 215 ssize_t msgrcv __P((int, void *, size_t, long, int)); 216 __END_DECLS 217 #else 218 struct proc; 219 220 void msginit __P((void)); 221 int msgctl1 __P((struct proc *, int, int, struct msqid_ds *)); 222 #endif /* !_KERNEL */ 223 224 #endif /* !_SYS_MSG_H_ */ 225