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*eb9fe4caSDavid Valin * Copyright 2009 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 #include <sys/ipc_impl.h> 307c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 317c478bd9Sstevel@tonic-gate #include <sys/msg.h> 327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 337c478bd9Sstevel@tonic-gate #include <sys/list.h> 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Argument vectors for the various flavors of msgsys(). 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define MSGGET 0 457c478bd9Sstevel@tonic-gate #define MSGCTL 1 467c478bd9Sstevel@tonic-gate #define MSGRCV 2 477c478bd9Sstevel@tonic-gate #define MSGSND 3 487c478bd9Sstevel@tonic-gate #define MSGIDS 4 497c478bd9Sstevel@tonic-gate #define MSGSNAP 5 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 527c478bd9Sstevel@tonic-gate 532c5b6df1Sdv142724 typedef struct msgq_wakeup { 542c5b6df1Sdv142724 list_node_t msgw_list; 552c5b6df1Sdv142724 long msgw_type; /* Message type request. */ 562c5b6df1Sdv142724 long msgw_snd_wake; /* Type of msg from msgsnd */ 57*eb9fe4caSDavid Valin size_t msgw_snd_size; /* Designates size of the msg sending */ 582c5b6df1Sdv142724 kthread_t *msgw_thrd; /* Thread waiting */ 592c5b6df1Sdv142724 kcondvar_t msgw_wake_cv; /* waiting on this */ 602c5b6df1Sdv142724 } msgq_wakeup_t; 612c5b6df1Sdv142724 622c5b6df1Sdv142724 632c5b6df1Sdv142724 typedef struct msg_select { 642c5b6df1Sdv142724 msgq_wakeup_t *(*selection)(); 652c5b6df1Sdv142724 struct msg_select *next_selection; 662c5b6df1Sdv142724 } msg_select_t; 672c5b6df1Sdv142724 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * There is one msg structure for each message in the system. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate struct msg { 727c478bd9Sstevel@tonic-gate list_node_t msg_node; /* message list node */ 737c478bd9Sstevel@tonic-gate long msg_type; /* message type */ 747c478bd9Sstevel@tonic-gate size_t msg_size; /* message text size */ 757c478bd9Sstevel@tonic-gate void *msg_addr; /* message text address */ 767c478bd9Sstevel@tonic-gate long msg_flags; /* message flags */ 777c478bd9Sstevel@tonic-gate long msg_copycnt; /* current # of copyouts on message */ 787c478bd9Sstevel@tonic-gate }; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Per message flags 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate #define MSG_RCVCOPY 00001 /* msgrcv is copying out this message */ 847c478bd9Sstevel@tonic-gate #define MSG_UNLINKED 00002 /* msg has been unlinked from queue */ 857c478bd9Sstevel@tonic-gate 86b2eb1770Sudpa /* 87b2eb1770Sudpa * msg_rcv_cv is now an array of kcondvar_t for performance reason. 88b2eb1770Sudpa * We use multiple condition variables (kcondvar_t) to avoid needing 89b2eb1770Sudpa * to wake all readers when sending a single message. 90b2eb1770Sudpa */ 912c5b6df1Sdv142724 922c5b6df1Sdv142724 #define MSG_NEG_INTERVAL 8 932c5b6df1Sdv142724 #define MSG_MAX_QNUM 64 942c5b6df1Sdv142724 #define MSG_MAX_QNUM_CV 65 95b2eb1770Sudpa 967c478bd9Sstevel@tonic-gate typedef struct kmsqid { 977c478bd9Sstevel@tonic-gate kipc_perm_t msg_perm; /* operation permission struct */ 987c478bd9Sstevel@tonic-gate list_t msg_list; /* list of messages on q */ 997c478bd9Sstevel@tonic-gate msglen_t msg_cbytes; /* current # bytes on q */ 1007c478bd9Sstevel@tonic-gate msgqnum_t msg_qnum; /* # of messages on q */ 1017c478bd9Sstevel@tonic-gate msgqnum_t msg_qmax; /* max # of messages on q */ 1027c478bd9Sstevel@tonic-gate msglen_t msg_qbytes; /* max # of bytes on q */ 1037c478bd9Sstevel@tonic-gate pid_t msg_lspid; /* pid of last msgsnd */ 1047c478bd9Sstevel@tonic-gate pid_t msg_lrpid; /* pid of last msgrcv */ 1057c478bd9Sstevel@tonic-gate time_t msg_stime; /* last msgsnd time */ 1067c478bd9Sstevel@tonic-gate time_t msg_rtime; /* last msgrcv time */ 1077c478bd9Sstevel@tonic-gate time_t msg_ctime; /* last change time */ 1082c5b6df1Sdv142724 uint_t msg_snd_cnt; /* # of waiting senders */ 1092c5b6df1Sdv142724 uint_t msg_rcv_cnt; /* # of waiting receivers */ 1102c5b6df1Sdv142724 uint64_t msg_lowest_type; /* Smallest type on queue */ 1112c5b6df1Sdv142724 /* 1122c5b6df1Sdv142724 * linked list of routines used to determine what to wake up next. 1132c5b6df1Sdv142724 * msg_fnd_sndr: Routines for waking up readers waiting 1142c5b6df1Sdv142724 * for a message from the sender. 1152c5b6df1Sdv142724 * msg_fnd_rdr: Routines for waking up readers waiting 1162c5b6df1Sdv142724 * for a copyout to finish. 1172c5b6df1Sdv142724 */ 1182c5b6df1Sdv142724 msg_select_t *msg_fnd_sndr; 1192c5b6df1Sdv142724 msg_select_t *msg_fnd_rdr; 1202c5b6df1Sdv142724 /* 1212c5b6df1Sdv142724 * Various counts and queues for controlling the sleeping 1222c5b6df1Sdv142724 * and waking up of processes that are waiting for various 1232c5b6df1Sdv142724 * message queue events. 1242c5b6df1Sdv142724 * 1252c5b6df1Sdv142724 * msg_cpy_block: List of receiving threads that are blocked because 1262c5b6df1Sdv142724 * the message of choice is being copied out. 1272c5b6df1Sdv142724 * msg_wait_snd: List of receiving threads whose type specifier 1282c5b6df1Sdv142724 * is positive or 0 but are blocked because there 1292c5b6df1Sdv142724 * are no matches. 1302c5b6df1Sdv142724 * msg_wait_snd_ngt: 1312c5b6df1Sdv142724 * List of receiving threads whose type specifier is 1322c5b6df1Sdv142724 * negative message type but are blocked because 1332c5b6df1Sdv142724 * there are no types that qualify. 134*eb9fe4caSDavid Valin * msg_wait_rcv: List of sending threads that are blocked because 135*eb9fe4caSDavid Valin * there is no room left on the message queue. 1362c5b6df1Sdv142724 */ 1377c478bd9Sstevel@tonic-gate kcondvar_t msg_snd_cv; 1382c5b6df1Sdv142724 list_t msg_cpy_block; 1392c5b6df1Sdv142724 list_t msg_wait_snd[MSG_MAX_QNUM_CV]; 1402c5b6df1Sdv142724 list_t msg_wait_snd_ngt[MSG_MAX_QNUM_CV]; 141*eb9fe4caSDavid Valin list_t msg_wait_rcv; 142*eb9fe4caSDavid Valin size_t msg_snd_smallest; /* Smallest msg on send wait list */ 1432c5b6df1Sdv142724 int msg_ngt_cnt; /* # of negative receivers blocked */ 1442c5b6df1Sdv142724 char msg_neg_copy; /* Neg type copy underway */ 1457c478bd9Sstevel@tonic-gate } kmsqid_t; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * LP64 view of the ILP32 msgbuf structure 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate struct ipcmsgbuf32 { 1547c478bd9Sstevel@tonic-gate int32_t mtype; /* message type */ 1557c478bd9Sstevel@tonic-gate char mtext[1]; /* message text */ 1567c478bd9Sstevel@tonic-gate }; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * LP64 view of the ILP32 msgsnap_head and msgsnap_mhead structures 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate struct msgsnap_head32 { 1627c478bd9Sstevel@tonic-gate size32_t msgsnap_size; /* bytes consumed/required in the buffer */ 1637c478bd9Sstevel@tonic-gate size32_t msgsnap_nmsg; /* number of messages in the buffer */ 1647c478bd9Sstevel@tonic-gate }; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate struct msgsnap_mhead32 { 1677c478bd9Sstevel@tonic-gate size32_t msgsnap_mlen; /* number of bytes in message that follows */ 1687c478bd9Sstevel@tonic-gate int32_t msgsnap_mtype; /* message type */ 1697c478bd9Sstevel@tonic-gate }; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* 1727c478bd9Sstevel@tonic-gate * LP64 view of the ILP32 msqid_ds structure 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate struct msqid_ds32 { 1757c478bd9Sstevel@tonic-gate struct ipc_perm32 msg_perm; /* operation permission struct */ 1767c478bd9Sstevel@tonic-gate caddr32_t msg_first; /* ptr to first message on q */ 1777c478bd9Sstevel@tonic-gate caddr32_t msg_last; /* ptr to last message on q */ 1787c478bd9Sstevel@tonic-gate uint32_t msg_cbytes; /* current # bytes on q */ 1797c478bd9Sstevel@tonic-gate uint32_t msg_qnum; /* # of messages on q */ 1807c478bd9Sstevel@tonic-gate uint32_t msg_qbytes; /* max # of bytes on q */ 1817c478bd9Sstevel@tonic-gate pid32_t msg_lspid; /* pid of last msgsnd */ 1827c478bd9Sstevel@tonic-gate pid32_t msg_lrpid; /* pid of last msgrcv */ 1837c478bd9Sstevel@tonic-gate time32_t msg_stime; /* last msgsnd time */ 1847c478bd9Sstevel@tonic-gate int32_t msg_pad1; /* reserved for time_t expansion */ 1857c478bd9Sstevel@tonic-gate time32_t msg_rtime; /* last msgrcv time */ 1867c478bd9Sstevel@tonic-gate int32_t msg_pad2; /* time_t expansion */ 1877c478bd9Sstevel@tonic-gate time32_t msg_ctime; /* last change time */ 1887c478bd9Sstevel@tonic-gate int32_t msg_pad3; /* time expansion */ 1897c478bd9Sstevel@tonic-gate int16_t msg_cv; 1907c478bd9Sstevel@tonic-gate int16_t msg_qnum_cv; 1917c478bd9Sstevel@tonic-gate int32_t msg_pad4[3]; /* reserve area */ 1927c478bd9Sstevel@tonic-gate }; 1937c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate #endif 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #endif /* _SYS_MSG_IMPL_H */ 200