1 /* $OpenBSD: msg.h,v 1.21 2024/04/30 17:03:05 op Exp $ */ 2 /* $NetBSD: msg.h,v 1.9 1996/02/09 18:25:18 christos Exp $ */ 3 4 /* 5 * SVID compatible msg.h file 6 * 7 * Author: Daniel Boulet 8 * 9 * Copyright 1993 Daniel Boulet and RTMX Inc. 10 * 11 * This system call was implemented by Daniel Boulet under contract from RTMX. 12 * 13 * Redistribution and use in source forms, with and without modification, 14 * are permitted provided that this entire comment appears intact. 15 * 16 * Redistribution in binary form may occur without any restrictions. 17 * Obviously, it would be nice if you gave credit where credit is due 18 * but requiring it would be too onerous. 19 * 20 * This software is provided ``AS IS'' without any warranties of any kind. 21 */ 22 23 #ifndef _SYS_MSG_H_ 24 #define _SYS_MSG_H_ 25 26 #include <sys/ipc.h> 27 28 /* 29 * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct 30 * are as defined by the SV API Intel 386 Processor Supplement. 31 */ 32 33 #define MSG_NOERROR 010000 /* don't complain about too long msgs */ 34 35 typedef unsigned long msgqnum_t; 36 typedef unsigned long msglen_t; 37 38 struct msqid_ds { 39 struct ipc_perm msg_perm; /* msg queue permission bits */ 40 struct msg *msg_first; /* first message in the queue */ 41 struct msg *msg_last; /* last message in the queue */ 42 msglen_t msg_cbytes; /* number of bytes in use on the queue */ 43 msgqnum_t msg_qnum; /* number of msgs in the queue */ 44 msglen_t msg_qbytes; /* max # of bytes on the queue */ 45 pid_t msg_lspid; /* pid of last msgsnd() */ 46 pid_t msg_lrpid; /* pid of last msgrcv() */ 47 time_t msg_stime; /* time of last msgsnd() */ 48 long msg_pad1; 49 time_t msg_rtime; /* time of last msgrcv() */ 50 long msg_pad2; 51 time_t msg_ctime; /* time of last msgctl() */ 52 long msg_pad3; 53 long msg_pad4[4]; 54 }; 55 56 #ifdef _KERNEL 57 #include <sys/queue.h> 58 59 struct msg { 60 long msg_type; 61 size_t msg_len; 62 struct mbuf *msg_data; 63 64 TAILQ_ENTRY(msg) msg_next; 65 }; 66 67 struct que { 68 struct msqid_ds msqid_ds; 69 int que_ix; /* pseudo-index */ 70 int que_flags; 71 int que_references; 72 73 TAILQ_ENTRY(que) que_next; 74 TAILQ_HEAD(, msg) que_msgs; 75 }; 76 77 /* for que_flags */ 78 #define MSGQ_READERS 0x01 79 #define MSGQ_WRITERS 0x02 80 #define MSGQ_DYING 0x04 81 82 #define QREF(q) (q)->que_references++ 83 84 #define QRELE(q) do { \ 85 if (--(q)->que_references == 0 && (q)->que_flags & MSGQ_DYING) \ 86 wakeup_one(&(q)->que_references); \ 87 } while (0) 88 #endif 89 90 /* 91 * Structure describing a message. The SVID doesn't suggest any 92 * particular name for this structure. There is a reference in the 93 * msgop man page that reads "The structure mymsg is an example of what 94 * this user defined buffer might look like, and includes the following 95 * members:". This sentence is followed by two lines equivalent 96 * to the mtype and mtext field declarations below. It isn't clear 97 * if "mymsg" refers to the name of the structure type or the name of an 98 * instance of the structure... 99 */ 100 struct mymsg { 101 long mtype; /* message type (+ve integer) */ 102 char mtext[1]; /* message body */ 103 }; 104 105 106 #ifdef _KERNEL 107 /* 108 * Based on the configuration parameters described in an SVR2 (yes, two) 109 * config(1m) man page. 110 * 111 * Each message is broken up and stored in segments that are msgssz bytes 112 * long. For efficiency reasons, this should be a power of two. Also, 113 * it doesn't make sense if it is less than 8 or greater than about 256. 114 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of 115 * two between 8 and 1024 inclusive (and panic's if it isn't). 116 */ 117 struct msginfo { 118 int msgmax, /* max chars in a message */ 119 msgmni, /* max message queue identifiers */ 120 msgmnb, /* max chars in a queue */ 121 msgtql, /* max messages in system */ 122 msgssz, /* size of a message segment (see notes above) */ 123 msgseg; /* number of message segments */ 124 }; 125 #ifdef SYSVMSG 126 extern struct msginfo msginfo; 127 #endif 128 129 int sysctl_sysvmsg(int *, u_int, void *, size_t *); 130 131 struct msg_sysctl_info { 132 struct msginfo msginfo; 133 struct msqid_ds msgids[1]; 134 }; 135 136 #ifndef MSGSSZ 137 #define MSGSSZ 8 /* Each segment must be 2^N long */ 138 #endif 139 #ifndef MSGSEG 140 #define MSGSEG 2048 /* must be less than 32767 */ 141 #endif 142 #undef MSGMAX /* ALWAYS compute MSGMAX! */ 143 #define MSGMAX (MSGSSZ*MSGSEG) 144 #ifndef MSGMNB 145 #define MSGMNB 2048 /* max # of bytes in a queue */ 146 #endif 147 #ifndef MSGMNI 148 #define MSGMNI 40 149 #endif 150 #ifndef MSGTQL 151 #define MSGTQL 40 152 #endif 153 154 /* 155 * macros to convert between msqid_ds's and msqid's. 156 * XXX unused, going away 157 */ 158 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000)) 159 #define MSQID_IX(id) ((id) & 0xffff) 160 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff) 161 #endif 162 163 164 #ifndef _KERNEL 165 __BEGIN_DECLS 166 int msgctl(int, int, struct msqid_ds *); 167 int msgget(key_t, int); 168 int msgsnd(int, const void *, size_t, int); 169 int msgrcv(int, void *, size_t, long, int); 170 __END_DECLS 171 #else 172 struct proc; 173 174 void msginit(void); 175 #endif /* !_KERNEL */ 176 177 #endif /* !_SYS_MSG_H_ */ 178