FreeBSD/Linux Kernel Cross Reference
sys/sys/msg.h
1 /* $OpenBSD: msg.h,v 1.20 2022/09/16 15:57:23 mbuhl 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 struct msqid_ds {
36 struct ipc_perm msg_perm; /* msg queue permission bits */
37 struct msg *msg_first; /* first message in the queue */
38 struct msg *msg_last; /* last message in the queue */
39 unsigned long msg_cbytes; /* number of bytes in use on the queue */
40 unsigned long msg_qnum; /* number of msgs in the queue */
41 unsigned long msg_qbytes; /* max # of bytes on the queue */
42 pid_t msg_lspid; /* pid of last msgsnd() */
43 pid_t msg_lrpid; /* pid of last msgrcv() */
44 time_t msg_stime; /* time of last msgsnd() */
45 long msg_pad1;
46 time_t msg_rtime; /* time of last msgrcv() */
47 long msg_pad2;
48 time_t msg_ctime; /* time of last msgctl() */
49 long msg_pad3;
50 long msg_pad4[4];
51 };
52
53 #ifdef _KERNEL
54 #include <sys/queue.h>
55
56 struct msg {
57 long msg_type;
58 size_t msg_len;
59 struct mbuf *msg_data;
60
61 TAILQ_ENTRY(msg) msg_next;
62 };
63
64 struct que {
65 struct msqid_ds msqid_ds;
66 int que_ix; /* pseudo-index */
67 int que_flags;
68 int que_references;
69
70 TAILQ_ENTRY(que) que_next;
71 TAILQ_HEAD(, msg) que_msgs;
72 };
73
74 /* for que_flags */
75 #define MSGQ_READERS 0x01
76 #define MSGQ_WRITERS 0x02
77 #define MSGQ_DYING 0x04
78
79 #define QREF(q) (q)->que_references++
80
81 #define QRELE(q) do { \
82 if (--(q)->que_references == 0 && (q)->que_flags & MSGQ_DYING) \
83 wakeup_one(&(q)->que_references); \
84 } while (0)
85 #endif
86
87 /*
88 * Structure describing a message. The SVID doesn't suggest any
89 * particular name for this structure. There is a reference in the
90 * msgop man page that reads "The structure mymsg is an example of what
91 * this user defined buffer might look like, and includes the following
92 * members:". This sentence is followed by two lines equivalent
93 * to the mtype and mtext field declarations below. It isn't clear
94 * if "mymsg" refers to the name of the structure type or the name of an
95 * instance of the structure...
96 */
97 struct mymsg {
98 long mtype; /* message type (+ve integer) */
99 char mtext[1]; /* message body */
100 };
101
102
103 #ifdef _KERNEL
104 /*
105 * Based on the configuration parameters described in an SVR2 (yes, two)
106 * config(1m) man page.
107 *
108 * Each message is broken up and stored in segments that are msgssz bytes
109 * long. For efficiency reasons, this should be a power of two. Also,
110 * it doesn't make sense if it is less than 8 or greater than about 256.
111 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
112 * two between 8 and 1024 inclusive (and panic's if it isn't).
113 */
114 struct msginfo {
115 int msgmax, /* max chars in a message */
116 msgmni, /* max message queue identifiers */
117 msgmnb, /* max chars in a queue */
118 msgtql, /* max messages in system */
119 msgssz, /* size of a message segment (see notes above) */
120 msgseg; /* number of message segments */
121 };
122 #ifdef SYSVMSG
123 extern struct msginfo msginfo;
124 #endif
125
126 int sysctl_sysvmsg(int *, u_int, void *, size_t *);
127
128 struct msg_sysctl_info {
129 struct msginfo msginfo;
130 struct msqid_ds msgids[1];
131 };
132
133 #ifndef MSGSSZ
134 #define MSGSSZ 8 /* Each segment must be 2^N long */
135 #endif
136 #ifndef MSGSEG
137 #define MSGSEG 2048 /* must be less than 32767 */
138 #endif
139 #undef MSGMAX /* ALWAYS compute MSGMAX! */
140 #define MSGMAX (MSGSSZ*MSGSEG)
141 #ifndef MSGMNB
142 #define MSGMNB 2048 /* max # of bytes in a queue */
143 #endif
144 #ifndef MSGMNI
145 #define MSGMNI 40
146 #endif
147 #ifndef MSGTQL
148 #define MSGTQL 40
149 #endif
150
151 /*
152 * macros to convert between msqid_ds's and msqid's.
153 * XXX unused, going away
154 */
155 #define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
156 #define MSQID_IX(id) ((id) & 0xffff)
157 #define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
158 #endif
159
160
161 #ifndef _KERNEL
162 __BEGIN_DECLS
163 int msgctl(int, int, struct msqid_ds *);
164 int msgget(key_t, int);
165 int msgsnd(int, const void *, size_t, int);
166 int msgrcv(int, void *, size_t, long, int);
167 __END_DECLS
168 #else
169 struct proc;
170
171 void msginit(void);
172 #endif /* !_KERNEL */
173
174 #endif /* !_SYS_MSG_H_ */
Cache object: c68b7f9cca0513e1db8b0c95786e90a9
|