xref: /titanic_50/usr/src/uts/common/sys/msg_impl.h (revision 29e83d4b25fd82feb8e0e0fbe89f7e2a8438533d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_MSG_IMPL_H
27 #define	_SYS_MSG_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/ipc_impl.h>
32 #if defined(_KERNEL) || defined(_KMEMUSER)
33 #include <sys/msg.h>
34 #include <sys/t_lock.h>
35 #include <sys/list.h>
36 #endif
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Argument vectors for the various flavors of msgsys().
44  */
45 
46 #define	MSGGET	0
47 #define	MSGCTL	1
48 #define	MSGRCV	2
49 #define	MSGSND	3
50 #define	MSGIDS	4
51 #define	MSGSNAP	5
52 
53 #if defined(_KERNEL) || defined(_KMEMUSER)
54 
55 typedef struct  msgq_wakeup {
56 	list_node_t	msgw_list;
57 	long		msgw_type;	/* Message type request. */
58 	long		msgw_snd_wake;	/* Type of msg from msgsnd */
59 	kthread_t	*msgw_thrd;	/* Thread waiting */
60 	kcondvar_t	msgw_wake_cv;	/* waiting on this */
61 } msgq_wakeup_t;
62 
63 
64 typedef struct msg_select {
65 	msgq_wakeup_t *(*selection)();
66 	struct msg_select *next_selection;
67 } msg_select_t;
68 
69 /*
70  * There is one msg structure for each message in the system.
71  */
72 struct msg {
73 	list_node_t	msg_node;	/* message list node */
74 	long		msg_type;	/* message type */
75 	size_t		msg_size;	/* message text size */
76 	void		*msg_addr;	/* message text address */
77 	long		msg_flags;	/* message flags */
78 	long		msg_copycnt;	/* current # of copyouts on message */
79 };
80 
81 /*
82  * Per message flags
83  */
84 #define	MSG_RCVCOPY	00001	/* msgrcv is copying out this message */
85 #define	MSG_UNLINKED	00002	/* msg has been unlinked from queue */
86 
87 /*
88  * msg_rcv_cv is now an array of kcondvar_t for performance reason.
89  * We use multiple condition variables (kcondvar_t) to avoid needing
90  * to wake all readers when sending a single message.
91  */
92 
93 #define	MSG_NEG_INTERVAL 8
94 #define	MSG_MAX_QNUM	64
95 #define	MSG_MAX_QNUM_CV	65
96 
97 typedef struct kmsqid {
98 	kipc_perm_t	msg_perm;	/* operation permission struct */
99 	list_t		msg_list;	/* list of messages on q */
100 	msglen_t	msg_cbytes;	/* current # bytes on q */
101 	msgqnum_t	msg_qnum;	/* # of messages on q */
102 	msgqnum_t	msg_qmax;	/* max # of messages on q */
103 	msglen_t	msg_qbytes;	/* max # of bytes on q */
104 	pid_t		msg_lspid;	/* pid of last msgsnd */
105 	pid_t		msg_lrpid;	/* pid of last msgrcv */
106 	time_t		msg_stime;	/* last msgsnd time */
107 	time_t		msg_rtime;	/* last msgrcv time */
108 	time_t		msg_ctime;	/* last change time */
109 	uint_t		msg_snd_cnt;	/* # of waiting senders */
110 	uint_t		msg_rcv_cnt;	/* # of waiting receivers */
111 	uint64_t	msg_lowest_type; /* Smallest type on queue */
112 	/*
113 	 * linked list of routines used to determine what to wake up next.
114 	 * 	msg_fnd_sndr:	Routines for waking up readers waiting
115 	 *			for a message from the sender.
116 	 *	msg_fnd_rdr:	Routines for waking up readers waiting
117 	 *			for a copyout to finish.
118 	 */
119 	msg_select_t	*msg_fnd_sndr;
120 	msg_select_t	*msg_fnd_rdr;
121 	/*
122 	 * Various counts and queues for controlling the sleeping
123 	 * and waking up of processes that are waiting for various
124 	 * message queue events.
125 	 *
126 	 * msg_cpy_block:   List of receiving threads that are blocked because
127 	 *		    the message of choice is being copied out.
128 	 * msg_wait_snd:    List of receiving threads whose type specifier
129 	 *		    is positive or 0 but are blocked because there
130 	 *		    are no matches.
131 	 * msg_wait_snd_ngt:
132 	 *		    List of receiving threads whose type specifier is
133 	 *		    negative message type but are blocked because
134 	 *		    there are no types that qualify.
135 	 */
136 	kcondvar_t	msg_snd_cv;
137 	list_t		msg_cpy_block;
138 	list_t		msg_wait_snd[MSG_MAX_QNUM_CV];
139 	list_t		msg_wait_snd_ngt[MSG_MAX_QNUM_CV];
140 	int		msg_ngt_cnt;	/* # of negative receivers blocked */
141 	char		msg_neg_copy;	/* Neg type copy underway */
142 } kmsqid_t;
143 
144 #endif	/* _KERNEL */
145 
146 #if defined(_SYSCALL32)
147 /*
148  * LP64 view of the ILP32 msgbuf structure
149  */
150 struct ipcmsgbuf32 {
151 	int32_t	mtype;		/* message type */
152 	char	mtext[1];	/* message text */
153 };
154 
155 /*
156  * LP64 view of the ILP32 msgsnap_head and msgsnap_mhead structures
157  */
158 struct msgsnap_head32 {
159 	size32_t msgsnap_size;	/* bytes consumed/required in the buffer */
160 	size32_t msgsnap_nmsg;	/* number of messages in the buffer */
161 };
162 
163 struct msgsnap_mhead32 {
164 	size32_t msgsnap_mlen;	/* number of bytes in message that follows */
165 	int32_t	msgsnap_mtype;	/* message type */
166 };
167 
168 /*
169  * LP64 view of the ILP32 msqid_ds structure
170  */
171 struct msqid_ds32 {
172 	struct ipc_perm32 msg_perm;	/* operation permission struct */
173 	caddr32_t	msg_first;	/* ptr to first message on q */
174 	caddr32_t	msg_last;	/* ptr to last message on q */
175 	uint32_t	msg_cbytes;	/* current # bytes on q */
176 	uint32_t	msg_qnum;	/* # of messages on q */
177 	uint32_t	msg_qbytes;	/* max # of bytes on q */
178 	pid32_t		msg_lspid;	/* pid of last msgsnd */
179 	pid32_t		msg_lrpid;	/* pid of last msgrcv */
180 	time32_t	msg_stime;	/* last msgsnd time */
181 	int32_t		msg_pad1;	/* reserved for time_t expansion */
182 	time32_t	msg_rtime;	/* last msgrcv time */
183 	int32_t		msg_pad2;	/* time_t expansion */
184 	time32_t	msg_ctime;	/* last change time */
185 	int32_t		msg_pad3;	/* time expansion */
186 	int16_t		msg_cv;
187 	int16_t		msg_qnum_cv;
188 	int32_t		msg_pad4[3];	/* reserve area */
189 };
190 #endif	/* _SYSCALL32 */
191 
192 #ifdef	__cplusplus
193 }
194 #endif
195 
196 #endif	/* _SYS_MSG_IMPL_H */
197