xref: /onnv-gate/usr/src/uts/common/sys/msg_impl.h (revision 8834:00075a1c20bb)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52565Sudpa  * Common Development and Distribution License (the "License").
62565Sudpa  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*8834SDavid.Valin@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_MSG_IMPL_H
270Sstevel@tonic-gate #define	_SYS_MSG_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/ipc_impl.h>
300Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
310Sstevel@tonic-gate #include <sys/msg.h>
320Sstevel@tonic-gate #include <sys/t_lock.h>
330Sstevel@tonic-gate #include <sys/list.h>
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * Argument vectors for the various flavors of msgsys().
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	MSGGET	0
450Sstevel@tonic-gate #define	MSGCTL	1
460Sstevel@tonic-gate #define	MSGRCV	2
470Sstevel@tonic-gate #define	MSGSND	3
480Sstevel@tonic-gate #define	MSGIDS	4
490Sstevel@tonic-gate #define	MSGSNAP	5
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
520Sstevel@tonic-gate 
534153Sdv142724 typedef struct  msgq_wakeup {
544153Sdv142724 	list_node_t	msgw_list;
554153Sdv142724 	long		msgw_type;	/* Message type request. */
564153Sdv142724 	long		msgw_snd_wake;	/* Type of msg from msgsnd */
57*8834SDavid.Valin@Sun.COM 	size_t		msgw_snd_size;	/* Designates size of the msg sending */
584153Sdv142724 	kthread_t	*msgw_thrd;	/* Thread waiting */
594153Sdv142724 	kcondvar_t	msgw_wake_cv;	/* waiting on this */
604153Sdv142724 } msgq_wakeup_t;
614153Sdv142724 
624153Sdv142724 
634153Sdv142724 typedef struct msg_select {
644153Sdv142724 	msgq_wakeup_t *(*selection)();
654153Sdv142724 	struct msg_select *next_selection;
664153Sdv142724 } msg_select_t;
674153Sdv142724 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * There is one msg structure for each message in the system.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate struct msg {
720Sstevel@tonic-gate 	list_node_t	msg_node;	/* message list node */
730Sstevel@tonic-gate 	long		msg_type;	/* message type */
740Sstevel@tonic-gate 	size_t		msg_size;	/* message text size */
750Sstevel@tonic-gate 	void		*msg_addr;	/* message text address */
760Sstevel@tonic-gate 	long		msg_flags;	/* message flags */
770Sstevel@tonic-gate 	long		msg_copycnt;	/* current # of copyouts on message */
780Sstevel@tonic-gate };
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * Per message flags
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate #define	MSG_RCVCOPY	00001	/* msgrcv is copying out this message */
840Sstevel@tonic-gate #define	MSG_UNLINKED	00002	/* msg has been unlinked from queue */
850Sstevel@tonic-gate 
862565Sudpa /*
872565Sudpa  * msg_rcv_cv is now an array of kcondvar_t for performance reason.
882565Sudpa  * We use multiple condition variables (kcondvar_t) to avoid needing
892565Sudpa  * to wake all readers when sending a single message.
902565Sudpa  */
914153Sdv142724 
924153Sdv142724 #define	MSG_NEG_INTERVAL 8
934153Sdv142724 #define	MSG_MAX_QNUM	64
944153Sdv142724 #define	MSG_MAX_QNUM_CV	65
952565Sudpa 
960Sstevel@tonic-gate typedef struct kmsqid {
970Sstevel@tonic-gate 	kipc_perm_t	msg_perm;	/* operation permission struct */
980Sstevel@tonic-gate 	list_t		msg_list;	/* list of messages on q */
990Sstevel@tonic-gate 	msglen_t	msg_cbytes;	/* current # bytes on q */
1000Sstevel@tonic-gate 	msgqnum_t	msg_qnum;	/* # of messages on q */
1010Sstevel@tonic-gate 	msgqnum_t	msg_qmax;	/* max # of messages on q */
1020Sstevel@tonic-gate 	msglen_t	msg_qbytes;	/* max # of bytes on q */
1030Sstevel@tonic-gate 	pid_t		msg_lspid;	/* pid of last msgsnd */
1040Sstevel@tonic-gate 	pid_t		msg_lrpid;	/* pid of last msgrcv */
1050Sstevel@tonic-gate 	time_t		msg_stime;	/* last msgsnd time */
1060Sstevel@tonic-gate 	time_t		msg_rtime;	/* last msgrcv time */
1070Sstevel@tonic-gate 	time_t		msg_ctime;	/* last change time */
1084153Sdv142724 	uint_t		msg_snd_cnt;	/* # of waiting senders */
1094153Sdv142724 	uint_t		msg_rcv_cnt;	/* # of waiting receivers */
1104153Sdv142724 	uint64_t	msg_lowest_type; /* Smallest type on queue */
1114153Sdv142724 	/*
1124153Sdv142724 	 * linked list of routines used to determine what to wake up next.
1134153Sdv142724 	 * 	msg_fnd_sndr:	Routines for waking up readers waiting
1144153Sdv142724 	 *			for a message from the sender.
1154153Sdv142724 	 *	msg_fnd_rdr:	Routines for waking up readers waiting
1164153Sdv142724 	 *			for a copyout to finish.
1174153Sdv142724 	 */
1184153Sdv142724 	msg_select_t	*msg_fnd_sndr;
1194153Sdv142724 	msg_select_t	*msg_fnd_rdr;
1204153Sdv142724 	/*
1214153Sdv142724 	 * Various counts and queues for controlling the sleeping
1224153Sdv142724 	 * and waking up of processes that are waiting for various
1234153Sdv142724 	 * message queue events.
1244153Sdv142724 	 *
1254153Sdv142724 	 * msg_cpy_block:   List of receiving threads that are blocked because
1264153Sdv142724 	 *		    the message of choice is being copied out.
1274153Sdv142724 	 * msg_wait_snd:    List of receiving threads whose type specifier
1284153Sdv142724 	 *		    is positive or 0 but are blocked because there
1294153Sdv142724 	 *		    are no matches.
1304153Sdv142724 	 * msg_wait_snd_ngt:
1314153Sdv142724 	 *		    List of receiving threads whose type specifier is
1324153Sdv142724 	 *		    negative message type but are blocked because
1334153Sdv142724 	 *		    there are no types that qualify.
134*8834SDavid.Valin@Sun.COM 	 * msg_wait_rcv:    List of sending threads that are blocked because
135*8834SDavid.Valin@Sun.COM 	 *		    there is no room left on the message queue.
1364153Sdv142724 	 */
1370Sstevel@tonic-gate 	kcondvar_t	msg_snd_cv;
1384153Sdv142724 	list_t		msg_cpy_block;
1394153Sdv142724 	list_t		msg_wait_snd[MSG_MAX_QNUM_CV];
1404153Sdv142724 	list_t		msg_wait_snd_ngt[MSG_MAX_QNUM_CV];
141*8834SDavid.Valin@Sun.COM 	list_t		msg_wait_rcv;
142*8834SDavid.Valin@Sun.COM 	size_t		msg_snd_smallest; /* Smallest msg on send wait list */
1434153Sdv142724 	int		msg_ngt_cnt;	/* # of negative receivers blocked */
1444153Sdv142724 	char		msg_neg_copy;	/* Neg type copy underway */
1450Sstevel@tonic-gate } kmsqid_t;
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #endif	/* _KERNEL */
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate #if defined(_SYSCALL32)
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * LP64 view of the ILP32 msgbuf structure
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate struct ipcmsgbuf32 {
1540Sstevel@tonic-gate 	int32_t	mtype;		/* message type */
1550Sstevel@tonic-gate 	char	mtext[1];	/* message text */
1560Sstevel@tonic-gate };
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate  * LP64 view of the ILP32 msgsnap_head and msgsnap_mhead structures
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate struct msgsnap_head32 {
1620Sstevel@tonic-gate 	size32_t msgsnap_size;	/* bytes consumed/required in the buffer */
1630Sstevel@tonic-gate 	size32_t msgsnap_nmsg;	/* number of messages in the buffer */
1640Sstevel@tonic-gate };
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate struct msgsnap_mhead32 {
1670Sstevel@tonic-gate 	size32_t msgsnap_mlen;	/* number of bytes in message that follows */
1680Sstevel@tonic-gate 	int32_t	msgsnap_mtype;	/* message type */
1690Sstevel@tonic-gate };
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * LP64 view of the ILP32 msqid_ds structure
1730Sstevel@tonic-gate  */
1740Sstevel@tonic-gate struct msqid_ds32 {
1750Sstevel@tonic-gate 	struct ipc_perm32 msg_perm;	/* operation permission struct */
1760Sstevel@tonic-gate 	caddr32_t	msg_first;	/* ptr to first message on q */
1770Sstevel@tonic-gate 	caddr32_t	msg_last;	/* ptr to last message on q */
1780Sstevel@tonic-gate 	uint32_t	msg_cbytes;	/* current # bytes on q */
1790Sstevel@tonic-gate 	uint32_t	msg_qnum;	/* # of messages on q */
1800Sstevel@tonic-gate 	uint32_t	msg_qbytes;	/* max # of bytes on q */
1810Sstevel@tonic-gate 	pid32_t		msg_lspid;	/* pid of last msgsnd */
1820Sstevel@tonic-gate 	pid32_t		msg_lrpid;	/* pid of last msgrcv */
1830Sstevel@tonic-gate 	time32_t	msg_stime;	/* last msgsnd time */
1840Sstevel@tonic-gate 	int32_t		msg_pad1;	/* reserved for time_t expansion */
1850Sstevel@tonic-gate 	time32_t	msg_rtime;	/* last msgrcv time */
1860Sstevel@tonic-gate 	int32_t		msg_pad2;	/* time_t expansion */
1870Sstevel@tonic-gate 	time32_t	msg_ctime;	/* last change time */
1880Sstevel@tonic-gate 	int32_t		msg_pad3;	/* time expansion */
1890Sstevel@tonic-gate 	int16_t		msg_cv;
1900Sstevel@tonic-gate 	int16_t		msg_qnum_cv;
1910Sstevel@tonic-gate 	int32_t		msg_pad4[3];	/* reserve area */
1920Sstevel@tonic-gate };
1930Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #ifdef	__cplusplus
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #endif	/* _SYS_MSG_IMPL_H */
200