]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_mqueue.h
xnu-3248.60.10.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_mqueue.h
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 Software.Distribution@CS.CMU.EDU
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 #include <kern/spl.h>
77 #include <kern/waitq.h>
78
79 #include <ipc/ipc_kmsg.h>
80 #include <ipc/ipc_object.h>
81 #include <ipc/ipc_types.h>
82
83 #include <sys/event.h>
84
85 typedef struct ipc_mqueue {
86 union {
87 struct {
88 struct waitq waitq;
89 struct ipc_kmsg_queue messages;
90 mach_port_seqno_t seqno;
91 mach_port_name_t receiver_name;
92 uint16_t msgcount;
93 uint16_t qlimit;
94 } __attribute__((__packed__)) port;
95 struct {
96 struct waitq_set setq;
97 mach_port_name_t local_name;
98 } __attribute__((__packed__)) pset;
99 } data;
100 } *ipc_mqueue_t;
101
102 #define IMQ_NULL ((ipc_mqueue_t) 0)
103
104 #define imq_wait_queue data.port.waitq
105 #define imq_messages data.port.messages
106 #define imq_msgcount data.port.msgcount
107 #define imq_qlimit data.port.qlimit
108 #define imq_seqno data.port.seqno
109 #define imq_receiver_name data.port.receiver_name
110
111 /*
112 * we can use the 'eventmask' bits of the waitq b/c
113 * they are only used by global queues
114 */
115 #define imq_fullwaiters data.port.waitq.waitq_eventmask
116 #define imq_in_pset data.port.waitq.waitq_set_id
117
118 #define imq_set_queue data.pset.setq
119 #define imq_local_name data.pset.local_name
120 #define imq_is_set(mq) waitqs_is_set(&(mq)->imq_set_queue)
121
122 #define imq_lock(mq) waitq_lock(&(mq)->imq_wait_queue)
123 #define imq_lock_try(mq) waitq_lock_try(&(mq)->imq_wait_queue)
124 #define imq_unlock(mq) waitq_unlock(&(mq)->imq_wait_queue)
125 #define imq_held(mq) waitq_held(&(mq)->imq_wait_queue)
126
127 extern void imq_reserve_and_lock(ipc_mqueue_t mq,
128 uint64_t *reserved_prepost, spl_t *spl);
129
130 extern void imq_release_and_unlock(ipc_mqueue_t mq,
131 uint64_t reserved_prepost, spl_t spl);
132
133 #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit)
134 #define imq_full_kernel(mq) ((mq)->imq_msgcount >= MACH_PORT_QLIMIT_KERNEL)
135
136 extern int ipc_mqueue_full;
137 // extern int ipc_mqueue_rcv;
138
139 #define IPC_MQUEUE_FULL CAST_EVENT64_T(&ipc_mqueue_full)
140 #define IPC_MQUEUE_RECEIVE NO_EVENT64
141
142 /*
143 * Exported interfaces
144 */
145
146 /* Initialize a newly-allocated message queue */
147 extern void ipc_mqueue_init(
148 ipc_mqueue_t mqueue,
149 boolean_t is_set,
150 uint64_t *reserved_link);
151
152 /* de-initialize / cleanup an mqueue (specifically waitq resources) */
153 extern void ipc_mqueue_deinit(
154 ipc_mqueue_t mqueue);
155
156 /* destroy an mqueue */
157 extern void ipc_mqueue_destroy(
158 ipc_mqueue_t mqueue);
159
160 /* Wake up receivers waiting in a message queue */
161 extern void ipc_mqueue_changed(
162 ipc_mqueue_t mqueue);
163
164 /* Add the specific mqueue as a member of the set */
165 extern kern_return_t ipc_mqueue_add(
166 ipc_mqueue_t mqueue,
167 ipc_mqueue_t set_mqueue,
168 uint64_t *reserved_link,
169 uint64_t *reserved_prepost);
170
171 /* Check to see if mqueue is member of set_mqueue */
172 extern boolean_t ipc_mqueue_member(
173 ipc_mqueue_t mqueue,
174 ipc_mqueue_t set_mqueue);
175
176 /* Remove an mqueue from a specific set */
177 extern kern_return_t ipc_mqueue_remove(
178 ipc_mqueue_t mqueue,
179 ipc_mqueue_t set_mqueue);
180
181 /* Remove an mqueue from all sets */
182 extern void ipc_mqueue_remove_from_all(
183 ipc_mqueue_t mqueue);
184
185 /* Remove all the members of the specifiied set */
186 extern void ipc_mqueue_remove_all(
187 ipc_mqueue_t mqueue);
188
189 /* Send a message to a port */
190 extern mach_msg_return_t ipc_mqueue_send(
191 ipc_mqueue_t mqueue,
192 ipc_kmsg_t kmsg,
193 mach_msg_option_t option,
194 mach_msg_timeout_t timeout_val,
195 spl_t s);
196
197 /* check for queue send queue full of a port */
198 extern mach_msg_return_t ipc_mqueue_preflight_send(
199 ipc_mqueue_t mqueue,
200 ipc_kmsg_t kmsg,
201 mach_msg_option_t option,
202 mach_msg_timeout_t timeout_val);
203
204 /* Deliver message to message queue or waiting receiver */
205 extern void ipc_mqueue_post(
206 ipc_mqueue_t mqueue,
207 ipc_kmsg_t kmsg);
208
209 /* Receive a message from a message queue */
210 extern void ipc_mqueue_receive(
211 ipc_mqueue_t mqueue,
212 mach_msg_option_t option,
213 mach_msg_size_t max_size,
214 mach_msg_timeout_t timeout_val,
215 int interruptible);
216
217 /* Receive a message from a message queue using a specified thread */
218 extern wait_result_t ipc_mqueue_receive_on_thread(
219 ipc_mqueue_t mqueue,
220 mach_msg_option_t option,
221 mach_msg_size_t max_size,
222 mach_msg_timeout_t rcv_timeout,
223 int interruptible,
224 thread_t thread);
225
226 /* Continuation routine for message receive */
227 extern void ipc_mqueue_receive_continue(
228 void *param,
229 wait_result_t wresult);
230
231 /* Select a message from a queue and try to post it to ourself */
232 extern void ipc_mqueue_select_on_thread(
233 ipc_mqueue_t port_mq,
234 ipc_mqueue_t set_mq,
235 mach_msg_option_t option,
236 mach_msg_size_t max_size,
237 thread_t thread);
238
239 /* Peek into a messaqe queue to see if there are messages */
240 extern unsigned ipc_mqueue_peek(
241 ipc_mqueue_t mqueue,
242 mach_port_seqno_t *msg_seqnop,
243 mach_msg_size_t *msg_sizep,
244 mach_msg_id_t *msg_idp,
245 mach_msg_max_trailer_t *msg_trailerp);
246
247 /* Peek into a messaqe queue set to see if there are queues with messages */
248 extern unsigned ipc_mqueue_set_peek(
249 ipc_mqueue_t mqueue);
250
251 /* Gather the names of member port for a given set */
252 extern void ipc_mqueue_set_gather_member_names(
253 ipc_space_t space,
254 ipc_mqueue_t set_mq,
255 ipc_entry_num_t maxnames,
256 mach_port_name_t *names,
257 ipc_entry_num_t *actualp);
258
259 /* Clear a message count reservation */
260 extern void ipc_mqueue_release_msgcount(
261 ipc_mqueue_t port_mq,
262 ipc_mqueue_t set_mq);
263
264 /* Change a queue limit */
265 extern void ipc_mqueue_set_qlimit(
266 ipc_mqueue_t mqueue,
267 mach_port_msgcount_t qlimit);
268
269 /* Change a queue's sequence number */
270 extern void ipc_mqueue_set_seqno(
271 ipc_mqueue_t mqueue,
272 mach_port_seqno_t seqno);
273
274 /* Convert a name in a space to a message queue */
275 extern mach_msg_return_t ipc_mqueue_copyin(
276 ipc_space_t space,
277 mach_port_name_t name,
278 ipc_mqueue_t *mqueuep,
279 ipc_object_t *objectp);
280
281 #endif /* _IPC_IPC_MQUEUE_H_ */