xref: /titanic_50/usr/src/uts/common/sys/msg_impl.h (revision 9512fe850e98fdd448c638ca63fdd92a8a510255)
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 2006 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 /*
56  * There is one msg structure for each message in the system.
57  */
58 struct msg {
59 	list_node_t	msg_node;	/* message list node */
60 	long		msg_type;	/* message type */
61 	size_t		msg_size;	/* message text size */
62 	void		*msg_addr;	/* message text address */
63 	long		msg_flags;	/* message flags */
64 	long		msg_copycnt;	/* current # of copyouts on message */
65 };
66 
67 /*
68  * Per message flags
69  */
70 #define	MSG_RCVCOPY	00001	/* msgrcv is copying out this message */
71 #define	MSG_UNLINKED	00002	/* msg has been unlinked from queue */
72 
73 /*
74  * msg_rcv_cv is now an array of kcondvar_t for performance reason.
75  * We use multiple condition variables (kcondvar_t) to avoid needing
76  * to wake all readers when sending a single message.
77  */
78 #define	MAX_QNUM	63
79 #define	MAX_QNUM_CV	64
80 #define	MSG_QNUM(x)	((x < 1) ? 0 : (x % MAX_QNUM) + 1)
81 
82 typedef struct kmsqid {
83 	kipc_perm_t	msg_perm;	/* operation permission struct */
84 	list_t		msg_list;	/* list of messages on q */
85 	msglen_t	msg_cbytes;	/* current # bytes on q */
86 	msgqnum_t	msg_qnum;	/* # of messages on q */
87 	msgqnum_t	msg_qmax;	/* max # of messages on q */
88 	msglen_t	msg_qbytes;	/* max # of bytes on q */
89 	pid_t		msg_lspid;	/* pid of last msgsnd */
90 	pid_t		msg_lrpid;	/* pid of last msgrcv */
91 	time_t		msg_stime;	/* last msgsnd time */
92 	time_t		msg_rtime;	/* last msgrcv time */
93 	time_t		msg_ctime;	/* last change time */
94 	uint64_t	msg_snd_cnt;	/* # of waiting senders */
95 	uint64_t	msg_rcv_cnt[MAX_QNUM_CV]; /* # of waiting receivers */
96 	kcondvar_t	msg_snd_cv;
97 	kcondvar_t	msg_rcv_cv[MAX_QNUM_CV];
98 } kmsqid_t;
99 
100 #endif	/* _KERNEL */
101 
102 #if defined(_SYSCALL32)
103 /*
104  * LP64 view of the ILP32 msgbuf structure
105  */
106 struct ipcmsgbuf32 {
107 	int32_t	mtype;		/* message type */
108 	char	mtext[1];	/* message text */
109 };
110 
111 /*
112  * LP64 view of the ILP32 msgsnap_head and msgsnap_mhead structures
113  */
114 struct msgsnap_head32 {
115 	size32_t msgsnap_size;	/* bytes consumed/required in the buffer */
116 	size32_t msgsnap_nmsg;	/* number of messages in the buffer */
117 };
118 
119 struct msgsnap_mhead32 {
120 	size32_t msgsnap_mlen;	/* number of bytes in message that follows */
121 	int32_t	msgsnap_mtype;	/* message type */
122 };
123 
124 /*
125  * LP64 view of the ILP32 msqid_ds structure
126  */
127 struct msqid_ds32 {
128 	struct ipc_perm32 msg_perm;	/* operation permission struct */
129 	caddr32_t	msg_first;	/* ptr to first message on q */
130 	caddr32_t	msg_last;	/* ptr to last message on q */
131 	uint32_t	msg_cbytes;	/* current # bytes on q */
132 	uint32_t	msg_qnum;	/* # of messages on q */
133 	uint32_t	msg_qbytes;	/* max # of bytes on q */
134 	pid32_t		msg_lspid;	/* pid of last msgsnd */
135 	pid32_t		msg_lrpid;	/* pid of last msgrcv */
136 	time32_t	msg_stime;	/* last msgsnd time */
137 	int32_t		msg_pad1;	/* reserved for time_t expansion */
138 	time32_t	msg_rtime;	/* last msgrcv time */
139 	int32_t		msg_pad2;	/* time_t expansion */
140 	time32_t	msg_ctime;	/* last change time */
141 	int32_t		msg_pad3;	/* time expansion */
142 	int16_t		msg_cv;
143 	int16_t		msg_qnum_cv;
144 	int32_t		msg_pad4[3];	/* reserve area */
145 };
146 #endif	/* _SYSCALL32 */
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _SYS_MSG_IMPL_H */
153