xref: /illumos-gate/usr/src/uts/common/sys/msg_impl.h (revision 2c5b6df1)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b2eb1770Sudpa  * Common Development and Distribution License (the "License").
6b2eb1770Sudpa  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*2c5b6df1Sdv142724  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_MSG_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MSG_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h>
327c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
337c478bd9Sstevel@tonic-gate #include <sys/msg.h>
347c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
357c478bd9Sstevel@tonic-gate #include <sys/list.h>
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Argument vectors for the various flavors of msgsys().
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	MSGGET	0
477c478bd9Sstevel@tonic-gate #define	MSGCTL	1
487c478bd9Sstevel@tonic-gate #define	MSGRCV	2
497c478bd9Sstevel@tonic-gate #define	MSGSND	3
507c478bd9Sstevel@tonic-gate #define	MSGIDS	4
517c478bd9Sstevel@tonic-gate #define	MSGSNAP	5
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
547c478bd9Sstevel@tonic-gate 
55*2c5b6df1Sdv142724 typedef struct  msgq_wakeup {
56*2c5b6df1Sdv142724 	list_node_t	msgw_list;
57*2c5b6df1Sdv142724 	long		msgw_type;	/* Message type request. */
58*2c5b6df1Sdv142724 	long		msgw_snd_wake;	/* Type of msg from msgsnd */
59*2c5b6df1Sdv142724 	kthread_t	*msgw_thrd;	/* Thread waiting */
60*2c5b6df1Sdv142724 	kcondvar_t	msgw_wake_cv;	/* waiting on this */
61*2c5b6df1Sdv142724 } msgq_wakeup_t;
62*2c5b6df1Sdv142724 
63*2c5b6df1Sdv142724 
64*2c5b6df1Sdv142724 typedef struct msg_select {
65*2c5b6df1Sdv142724 	msgq_wakeup_t *(*selection)();
66*2c5b6df1Sdv142724 	struct msg_select *next_selection;
67*2c5b6df1Sdv142724 } msg_select_t;
68*2c5b6df1Sdv142724 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * There is one msg structure for each message in the system.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate struct msg {
737c478bd9Sstevel@tonic-gate 	list_node_t	msg_node;	/* message list node */
747c478bd9Sstevel@tonic-gate 	long		msg_type;	/* message type */
757c478bd9Sstevel@tonic-gate 	size_t		msg_size;	/* message text size */
767c478bd9Sstevel@tonic-gate 	void		*msg_addr;	/* message text address */
777c478bd9Sstevel@tonic-gate 	long		msg_flags;	/* message flags */
787c478bd9Sstevel@tonic-gate 	long		msg_copycnt;	/* current # of copyouts on message */
797c478bd9Sstevel@tonic-gate };
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Per message flags
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	MSG_RCVCOPY	00001	/* msgrcv is copying out this message */
857c478bd9Sstevel@tonic-gate #define	MSG_UNLINKED	00002	/* msg has been unlinked from queue */
867c478bd9Sstevel@tonic-gate 
87b2eb1770Sudpa /*
88b2eb1770Sudpa  * msg_rcv_cv is now an array of kcondvar_t for performance reason.
89b2eb1770Sudpa  * We use multiple condition variables (kcondvar_t) to avoid needing
90b2eb1770Sudpa  * to wake all readers when sending a single message.
91b2eb1770Sudpa  */
92*2c5b6df1Sdv142724 
93*2c5b6df1Sdv142724 #define	MSG_NEG_INTERVAL 8
94*2c5b6df1Sdv142724 #define	MSG_MAX_QNUM	64
95*2c5b6df1Sdv142724 #define	MSG_MAX_QNUM_CV	65
96b2eb1770Sudpa 
977c478bd9Sstevel@tonic-gate typedef struct kmsqid {
987c478bd9Sstevel@tonic-gate 	kipc_perm_t	msg_perm;	/* operation permission struct */
997c478bd9Sstevel@tonic-gate 	list_t		msg_list;	/* list of messages on q */
1007c478bd9Sstevel@tonic-gate 	msglen_t	msg_cbytes;	/* current # bytes on q */
1017c478bd9Sstevel@tonic-gate 	msgqnum_t	msg_qnum;	/* # of messages on q */
1027c478bd9Sstevel@tonic-gate 	msgqnum_t	msg_qmax;	/* max # of messages on q */
1037c478bd9Sstevel@tonic-gate 	msglen_t	msg_qbytes;	/* max # of bytes on q */
1047c478bd9Sstevel@tonic-gate 	pid_t		msg_lspid;	/* pid of last msgsnd */
1057c478bd9Sstevel@tonic-gate 	pid_t		msg_lrpid;	/* pid of last msgrcv */
1067c478bd9Sstevel@tonic-gate 	time_t		msg_stime;	/* last msgsnd time */
1077c478bd9Sstevel@tonic-gate 	time_t		msg_rtime;	/* last msgrcv time */
1087c478bd9Sstevel@tonic-gate 	time_t		msg_ctime;	/* last change time */
109*2c5b6df1Sdv142724 	uint_t		msg_snd_cnt;	/* # of waiting senders */
110*2c5b6df1Sdv142724 	uint_t		msg_rcv_cnt;	/* # of waiting receivers */
111*2c5b6df1Sdv142724 	uint64_t	msg_lowest_type; /* Smallest type on queue */
112*2c5b6df1Sdv142724 	/*
113*2c5b6df1Sdv142724 	 * linked list of routines used to determine what to wake up next.
114*2c5b6df1Sdv142724 	 * 	msg_fnd_sndr:	Routines for waking up readers waiting
115*2c5b6df1Sdv142724 	 *			for a message from the sender.
116*2c5b6df1Sdv142724 	 *	msg_fnd_rdr:	Routines for waking up readers waiting
117*2c5b6df1Sdv142724 	 *			for a copyout to finish.
118*2c5b6df1Sdv142724 	 */
119*2c5b6df1Sdv142724 	msg_select_t	*msg_fnd_sndr;
120*2c5b6df1Sdv142724 	msg_select_t	*msg_fnd_rdr;
121*2c5b6df1Sdv142724 	/*
122*2c5b6df1Sdv142724 	 * Various counts and queues for controlling the sleeping
123*2c5b6df1Sdv142724 	 * and waking up of processes that are waiting for various
124*2c5b6df1Sdv142724 	 * message queue events.
125*2c5b6df1Sdv142724 	 *
126*2c5b6df1Sdv142724 	 * msg_cpy_block:   List of receiving threads that are blocked because
127*2c5b6df1Sdv142724 	 *		    the message of choice is being copied out.
128*2c5b6df1Sdv142724 	 * msg_wait_snd:    List of receiving threads whose type specifier
129*2c5b6df1Sdv142724 	 *		    is positive or 0 but are blocked because there
130*2c5b6df1Sdv142724 	 *		    are no matches.
131*2c5b6df1Sdv142724 	 * msg_wait_snd_ngt:
132*2c5b6df1Sdv142724 	 *		    List of receiving threads whose type specifier is
133*2c5b6df1Sdv142724 	 *		    negative message type but are blocked because
134*2c5b6df1Sdv142724 	 *		    there are no types that qualify.
135*2c5b6df1Sdv142724 	 */
1367c478bd9Sstevel@tonic-gate 	kcondvar_t	msg_snd_cv;
137*2c5b6df1Sdv142724 	list_t		msg_cpy_block;
138*2c5b6df1Sdv142724 	list_t		msg_wait_snd[MSG_MAX_QNUM_CV];
139*2c5b6df1Sdv142724 	list_t		msg_wait_snd_ngt[MSG_MAX_QNUM_CV];
140*2c5b6df1Sdv142724 	int		msg_ngt_cnt;	/* # of negative receivers blocked */
141*2c5b6df1Sdv142724 	char		msg_neg_copy;	/* Neg type copy underway */
1427c478bd9Sstevel@tonic-gate } kmsqid_t;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * LP64 view of the ILP32 msgbuf structure
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate struct ipcmsgbuf32 {
1517c478bd9Sstevel@tonic-gate 	int32_t	mtype;		/* message type */
1527c478bd9Sstevel@tonic-gate 	char	mtext[1];	/* message text */
1537c478bd9Sstevel@tonic-gate };
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * LP64 view of the ILP32 msgsnap_head and msgsnap_mhead structures
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate struct msgsnap_head32 {
1597c478bd9Sstevel@tonic-gate 	size32_t msgsnap_size;	/* bytes consumed/required in the buffer */
1607c478bd9Sstevel@tonic-gate 	size32_t msgsnap_nmsg;	/* number of messages in the buffer */
1617c478bd9Sstevel@tonic-gate };
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate struct msgsnap_mhead32 {
1647c478bd9Sstevel@tonic-gate 	size32_t msgsnap_mlen;	/* number of bytes in message that follows */
1657c478bd9Sstevel@tonic-gate 	int32_t	msgsnap_mtype;	/* message type */
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * LP64 view of the ILP32 msqid_ds structure
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate struct msqid_ds32 {
1727c478bd9Sstevel@tonic-gate 	struct ipc_perm32 msg_perm;	/* operation permission struct */
1737c478bd9Sstevel@tonic-gate 	caddr32_t	msg_first;	/* ptr to first message on q */
1747c478bd9Sstevel@tonic-gate 	caddr32_t	msg_last;	/* ptr to last message on q */
1757c478bd9Sstevel@tonic-gate 	uint32_t	msg_cbytes;	/* current # bytes on q */
1767c478bd9Sstevel@tonic-gate 	uint32_t	msg_qnum;	/* # of messages on q */
1777c478bd9Sstevel@tonic-gate 	uint32_t	msg_qbytes;	/* max # of bytes on q */
1787c478bd9Sstevel@tonic-gate 	pid32_t		msg_lspid;	/* pid of last msgsnd */
1797c478bd9Sstevel@tonic-gate 	pid32_t		msg_lrpid;	/* pid of last msgrcv */
1807c478bd9Sstevel@tonic-gate 	time32_t	msg_stime;	/* last msgsnd time */
1817c478bd9Sstevel@tonic-gate 	int32_t		msg_pad1;	/* reserved for time_t expansion */
1827c478bd9Sstevel@tonic-gate 	time32_t	msg_rtime;	/* last msgrcv time */
1837c478bd9Sstevel@tonic-gate 	int32_t		msg_pad2;	/* time_t expansion */
1847c478bd9Sstevel@tonic-gate 	time32_t	msg_ctime;	/* last change time */
1857c478bd9Sstevel@tonic-gate 	int32_t		msg_pad3;	/* time expansion */
1867c478bd9Sstevel@tonic-gate 	int16_t		msg_cv;
1877c478bd9Sstevel@tonic-gate 	int16_t		msg_qnum_cv;
1887c478bd9Sstevel@tonic-gate 	int32_t		msg_pad4[3];	/* reserve area */
1897c478bd9Sstevel@tonic-gate };
1907c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate #endif
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #endif	/* _SYS_MSG_IMPL_H */
197