1 /* 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 /* 29 * @OSF_COPYRIGHT@ 30 */ 31 /* 32 * Mach Operating System 33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 * All Rights Reserved. 35 * 36 * Permission to use, copy, modify and distribute this software and its 37 * documentation is hereby granted, provided that both the copyright 38 * notice and this permission notice appear in all copies of the 39 * software, derivative works or modified versions, and any portions 40 * thereof, and that both notices appear in supporting documentation. 41 * 42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 * 46 * Carnegie Mellon requests users of this software to return to 47 * 48 * Software Distribution Coordinator or [email protected] 49 * School of Computer Science 50 * Carnegie Mellon University 51 * Pittsburgh PA 15213-3890 52 * 53 * any improvements or extensions that they make and grant Carnegie Mellon 54 * the rights to redistribute these changes. 55 */ 56 /* 57 */ 58 /* 59 * File: ipc/ipc_mqueue.h 60 * Author: Rich Draves 61 * Date: 1989 62 * 63 * Definitions for message queues. 64 */ 65 66 #ifndef _IPC_IPC_MQUEUE_H_ 67 #define _IPC_IPC_MQUEUE_H_ 68 69 #include <mach_assert.h> 70 71 #include <mach/message.h> 72 73 #include <kern/assert.h> 74 #include <kern/macro_help.h> 75 #include <kern/kern_types.h> 76 77 #include <ipc/ipc_kmsg.h> 78 #include <ipc/ipc_object.h> 79 #include <ipc/ipc_types.h> 80 81 #include <sys/event.h> 82 83 typedef struct ipc_mqueue { 84 circle_queue_head_t imq_messages; 85 mach_port_seqno_t imq_seqno; 86 mach_port_name_t imq_receiver_name; 87 uint16_t imq_msgcount; 88 uint16_t imq_qlimit; 89 /* 90 * The imq_context structure member fills in a 32-bit padding gap 91 * in ipc_mqueue. 92 */ 93 uint32_t imq_context; 94 95 union { 96 /* 97 * Special Reply Ports (ip_type() == IOT_SPECIAL_REPLY_PORT): 98 * only use imq_srp_owner_thread 99 * 100 * Ports, based on ip_sync_link_state, use: 101 * - PORT_SYNC_LINK_ANY: imq_klist 102 * - PORT_SYNC_LINK_WORKLOOP_KNOTE: imq_inheritor_knote 103 * - PORT_SYNC_LINK_WORKLOOP_STASH: imq_inheritor_turnstile (has a +1) 104 * - PORT_SYNC_LINK_RCV_THREAD: imq_inheritor_thread_ref 105 */ 106 struct klist imq_klist; 107 struct knote *XNU_PTRAUTH_SIGNED_PTR("ipc_mqueue.knote") imq_inheritor_knote; 108 struct turnstile *XNU_PTRAUTH_SIGNED_PTR("ipc_mqueue.turnstile") imq_inheritor_turnstile; 109 thread_t XNU_PTRAUTH_SIGNED_PTR("ipc_mqueue.thread_ref") imq_inheritor_thread_ref; 110 thread_t XNU_PTRAUTH_SIGNED_PTR("ipc_mqueue.srp_owner_thread") imq_srp_owner_thread; 111 }; 112 } *ipc_mqueue_t; 113 114 #define IMQ_NULL ((ipc_mqueue_t) 0) 115 116 #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit) 117 #define imq_full_kernel(mq) ((mq)->imq_msgcount >= MACH_PORT_QLIMIT_KERNEL) 118 119 extern const bool ipc_mqueue_full; 120 121 #define IPC_MQUEUE_FULL CAST_EVENT64_T(&ipc_mqueue_full) 122 #define IPC_MQUEUE_RECEIVE NO_EVENT64 123 124 /* 125 * Exported interfaces 126 */ 127 128 /* Initialize a newly-allocated message queue */ 129 extern void ipc_mqueue_init( 130 ipc_mqueue_t mqueue); 131 132 /* destroy an mqueue */ 133 extern boolean_t ipc_mqueue_destroy_locked( 134 ipc_mqueue_t mqueue, 135 waitq_link_list_t *free_l); 136 137 /* Wake up receivers waiting in a message queue */ 138 extern void ipc_mqueue_changed( 139 ipc_space_t space, 140 waitq_t waitq); 141 142 /* Add the specific mqueue as a member of the set */ 143 extern kern_return_t ipc_mqueue_add_locked( 144 ipc_mqueue_t mqueue, 145 ipc_pset_t pset, 146 waitq_link_t *linkp); 147 148 /* Send a message to a port */ 149 extern mach_msg_return_t ipc_mqueue_send_locked( 150 ipc_mqueue_t mqueue, 151 ipc_kmsg_t kmsg, 152 mach_msg_option64_t option, 153 mach_msg_timeout_t timeout_val); 154 155 /* Set a [send-possible] override on the mqueue */ 156 extern void ipc_mqueue_override_send_locked( 157 ipc_mqueue_t mqueue, 158 mach_msg_qos_t qos_ovr); 159 160 /* Receive a message from a message queue */ 161 extern void ipc_mqueue_receive( 162 waitq_t waitq, 163 mach_msg_timeout_t timeout_val, 164 int interruptible, 165 thread_t thread, 166 bool has_continuation); 167 168 /* Receive a message from a message queue using a specified thread */ 169 extern wait_result_t ipc_mqueue_receive_on_thread_and_unlock( 170 waitq_t waitq, 171 mach_msg_timeout_t rcv_timeout, 172 int interruptible, 173 thread_t thread); 174 175 /* Peek into a messaqe queue to see if there are messages */ 176 extern unsigned ipc_mqueue_peek( 177 ipc_mqueue_t mqueue, 178 mach_port_seqno_t *msg_seqnop, 179 mach_msg_size_t *msg_sizep, 180 mach_msg_id_t *msg_idp, 181 mach_msg_max_trailer_t *msg_trailerp, 182 ipc_kmsg_t *kmsgp); 183 184 /* Peek into a locked messaqe queue to see if there are messages */ 185 extern unsigned ipc_mqueue_peek_locked( 186 ipc_mqueue_t mqueue, 187 mach_port_seqno_t *msg_seqnop, 188 mach_msg_size_t *msg_sizep, 189 mach_msg_id_t *msg_idp, 190 mach_msg_max_trailer_t *msg_trailerp, 191 ipc_kmsg_t *kmsgp); 192 193 /* Change a queue limit */ 194 extern void ipc_mqueue_set_qlimit_locked( 195 ipc_mqueue_t mqueue, 196 mach_port_msgcount_t qlimit); 197 198 /* Change a queue's sequence number */ 199 extern void ipc_mqueue_set_seqno_locked( 200 ipc_mqueue_t mqueue, 201 mach_port_seqno_t seqno); 202 203 /* Convert a name in a space to a message queue */ 204 extern mach_msg_return_t ipc_mqueue_copyin( 205 ipc_space_t space, 206 mach_port_name_t name, 207 ipc_object_t *objectp); 208 209 /* Safe to use the klist ptr */ 210 extern bool ipc_port_has_klist( 211 ipc_port_t port); 212 213 #endif /* _IPC_IPC_MQUEUE_H_ */ 214