1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1987 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984 AT&T */ 28 /* All Rights Reserved */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * IPC Message Facility. 34 */ 35 36 #ifndef _sys_msg_h 37 #define _sys_msg_h 38 39 /* 40 * Message Operation Flags. 41 */ 42 #define MSG_NOERROR 010000 /* no error if big message */ 43 44 /* 45 * Structure Definitions. 46 */ 47 48 /* 49 * There is one msg queue id data structure for each q in the system. 50 */ 51 52 struct msqid_ds { 53 struct ipc_perm msg_perm; /* operation permission struct */ 54 struct msg *msg_first; /* ptr to first message on q */ 55 struct msg *msg_last; /* ptr to last message on q */ 56 ushort msg_cbytes; /* current # bytes on q */ 57 ushort msg_qnum; /* # of messages on q */ 58 ushort msg_qbytes; /* max # of bytes on q */ 59 ushort msg_lspid; /* pid of last msgsnd */ 60 ushort msg_lrpid; /* pid of last msgrcv */ 61 time_t msg_stime; /* last msgsnd time */ 62 time_t msg_rtime; /* last msgrcv time */ 63 time_t msg_ctime; /* last change time */ 64 }; 65 66 /* 67 * User message buffer template for msgsnd and msgrcv system calls. 68 */ 69 70 /* HACK :: change the name when compiling the kernel to avoid conflicts */ 71 #ifdef KERNEL 72 struct ipcmsgbuf { 73 #else 74 struct msgbuf { 75 #endif KERNEL 76 long mtype; /* message type */ 77 char mtext[1]; /* message text */ 78 }; 79 80 /* 81 * There is one msg structure for each message that may be in the system. 82 */ 83 84 struct msg { 85 struct msg *msg_next; /* ptr to next message on q */ 86 long msg_type; /* message type */ 87 ushort msg_ts; /* message text size */ 88 ushort msg_spot; /* message text map address */ 89 }; 90 91 92 93 #ifdef KERNEL 94 /* 95 * Implementation Constants. 96 */ 97 98 #define PMSG (PZERO + 2) /* message facility sleep priority */ 99 100 /* 101 * Permission Definitions. 102 */ 103 104 #define MSG_R 0400 /* read permission */ 105 #define MSG_W 0200 /* write permission */ 106 107 /* 108 * ipc_perm Mode Definitions. 109 */ 110 111 #define MSG_RWAIT 001000 /* a reader is waiting for a message */ 112 #define MSG_WWAIT 002000 /* a writer is waiting to send */ 113 #define MSG_LOCKED 004000 /* msqid locked */ 114 #define MSG_LOCKWAIT 010000 /* msqid wanted */ 115 116 /* define resource locking macros */ 117 #define MSGWAKEUP(addr) { \ 118 curpri = PMSG; \ 119 wakeup((caddr_t)(addr)); \ 120 } 121 122 #define MSGLOCK(qp) { \ 123 while ((qp)->msg_perm.mode & MSG_LOCKED) { \ 124 (qp)->msg_perm.mode |= MSG_LOCKWAIT; \ 125 if (sleep((caddr_t)(qp), PMSG | PCATCH)) { \ 126 (qp)->msg_perm.mode &= ~MSG_LOCKWAIT; \ 127 u.u_error = EINTR; \ 128 return (NULL); \ 129 } \ 130 } \ 131 (qp)->msg_perm.mode |= MSG_LOCKED; \ 132 } 133 134 #define MSGUNLOCK(qp) { \ 135 (qp)->msg_perm.mode &= ~MSG_LOCKED; \ 136 if ((qp)->msg_perm.mode & MSG_LOCKWAIT) { \ 137 (qp)->msg_perm.mode &= ~MSG_LOCKWAIT; \ 138 MSGWAKEUP(qp); \ 139 } \ 140 } 141 142 143 /* 144 * Message information structure. 145 */ 146 147 struct msginfo { 148 int msgmap, /* # of entries in msg map */ 149 msgmax, /* max message size */ 150 msgmnb, /* max # bytes on queue */ 151 msgmni, /* # of message queue identifiers */ 152 msgssz, /* msg segment size (should be word size multiple) */ 153 msgtql; /* # of system message headers */ 154 ushort msgseg; /* # of msg segments (MUST BE < 32768) */ 155 }; 156 struct msginfo msginfo; /* message parameters */ 157 158 159 /* 160 * Configuration Parameters 161 * These parameters are tuned by editing the system configuration file. 162 * The following lines establish the default values. 163 */ 164 #ifndef MSGPOOL 165 #define MSGPOOL 8 /* size, in kilobytes, of message pool */ 166 #endif 167 #ifndef MSGMNB 168 #define MSGMNB 2048 /* default max number of bytes on a queue */ 169 #endif 170 #ifndef MSGMNI 171 #define MSGMNI 50 /* number of message queue identifiers */ 172 #endif 173 #ifndef MSGTQL 174 #define MSGTQL 50 /* # of system message headers */ 175 #endif 176 177 /* The following parameters are assumed not to require tuning */ 178 #ifndef MSGMAP 179 #define MSGMAP 100 /* number of entries in msg map */ 180 #endif 181 #ifndef MSGMAX 182 #define MSGMAX (MSGPOOL * 1024) /* max message size (in bytes) */ 183 #endif 184 #ifndef MSGSSZ 185 #define MSGSSZ 8 /* msg segment size (should be word size multiple) */ 186 #endif 187 #define MSGSEG ((MSGPOOL * 1024) / MSGSSZ) /* # segments (MUST BE < 32768) */ 188 189 190 /* 191 * Structures allocated in machdep.c 192 */ 193 char *msg; /* base address of message buffer */ 194 struct map *msgmap; /* msg allocation map */ 195 struct msg *msgh; /* message headers */ 196 struct msqid_ds *msgque; /* msg queue headers */ 197 198 #endif KERNEL 199 200 #endif /*!_sys_msg_h*/ 201