]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_mqueue.h
xnu-3789.70.16.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_mqueue.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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>
91447636 75#include <kern/kern_types.h>
3e170ce0 76#include <kern/waitq.h>
1c79356b
A
77
78#include <ipc/ipc_kmsg.h>
79#include <ipc/ipc_object.h>
80#include <ipc/ipc_types.h>
81
b0d623f7
A
82#include <sys/event.h>
83
1c79356b
A
84typedef struct ipc_mqueue {
85 union {
86 struct {
3e170ce0 87 struct waitq waitq;
1c79356b 88 struct ipc_kmsg_queue messages;
b0d623f7
A
89 mach_port_seqno_t seqno;
90 mach_port_name_t receiver_name;
3e170ce0
A
91 uint16_t msgcount;
92 uint16_t qlimit;
39037602
A
93#if MACH_FLIPC
94 struct flipc_port *fport; // Null for local port, or ptr to flipc port
95#endif
813fb2f6 96 } port;
b0d623f7 97 struct {
3e170ce0 98 struct waitq_set setq;
813fb2f6 99 } pset;
1c79356b 100 } data;
39037602 101 struct klist imq_klist;
1c79356b
A
102} *ipc_mqueue_t;
103
104#define IMQ_NULL ((ipc_mqueue_t) 0)
105
3e170ce0 106#define imq_wait_queue data.port.waitq
1c79356b
A
107#define imq_messages data.port.messages
108#define imq_msgcount data.port.msgcount
109#define imq_qlimit data.port.qlimit
110#define imq_seqno data.port.seqno
b0d623f7 111#define imq_receiver_name data.port.receiver_name
39037602
A
112#if MACH_FLIPC
113#define imq_fport data.port.fport
114#endif
1c79356b 115
3e170ce0
A
116/*
117 * we can use the 'eventmask' bits of the waitq b/c
118 * they are only used by global queues
119 */
120#define imq_fullwaiters data.port.waitq.waitq_eventmask
121#define imq_in_pset data.port.waitq.waitq_set_id
39037602 122#define imq_preposts data.port.waitq.waitq_prepost_id
3e170ce0
A
123
124#define imq_set_queue data.pset.setq
3e170ce0 125#define imq_is_set(mq) waitqs_is_set(&(mq)->imq_set_queue)
39037602
A
126#define imq_is_queue(mq) waitq_is_queue(&(mq)->imq_wait_queue)
127#define imq_is_valid(mq) waitq_is_valid(&(mq)->imq_wait_queue)
3e170ce0
A
128
129#define imq_lock(mq) waitq_lock(&(mq)->imq_wait_queue)
130#define imq_lock_try(mq) waitq_lock_try(&(mq)->imq_wait_queue)
131#define imq_unlock(mq) waitq_unlock(&(mq)->imq_wait_queue)
132#define imq_held(mq) waitq_held(&(mq)->imq_wait_queue)
39037602 133#define imq_valid(mq) waitq_valid(&(mq)->imq_wait_queue)
1c79356b 134
813fb2f6
A
135/*
136 * Get an ipc_mqueue pointer from a waitq pointer. These are traditionally the
137 * same pointer, but this conversion makes no assumptions on union structure
138 * member positions - it should allow the waitq to move around in either the
139 * port-set mqueue or the port mqueue independently.
140 */
141#define imq_from_waitq(waitq) (waitq_is_set(waitq) ? \
142 ((struct ipc_mqueue *)((void *)( \
143 (uintptr_t)(waitq) - \
144 __offsetof(struct ipc_mqueue, imq_wait_queue)) \
145 )) : \
146 ((struct ipc_mqueue *)((void *)( \
147 (uintptr_t)(waitq) - \
148 __offsetof(struct ipc_mqueue, imq_set_queue)) \
149 )) \
150 )
151
3e170ce0 152extern void imq_reserve_and_lock(ipc_mqueue_t mq,
39037602 153 uint64_t *reserved_prepost);
3e170ce0
A
154
155extern void imq_release_and_unlock(ipc_mqueue_t mq,
39037602 156 uint64_t reserved_prepost);
1c79356b
A
157
158#define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit)
c910b4d9 159#define imq_full_kernel(mq) ((mq)->imq_msgcount >= MACH_PORT_QLIMIT_KERNEL)
1c79356b
A
160
161extern int ipc_mqueue_full;
b0d623f7 162// extern int ipc_mqueue_rcv;
1c79356b 163
cf7d32b8 164#define IPC_MQUEUE_FULL CAST_EVENT64_T(&ipc_mqueue_full)
b0d623f7 165#define IPC_MQUEUE_RECEIVE NO_EVENT64
1c79356b
A
166
167/*
168 * Exported interfaces
169 */
170
171/* Initialize a newly-allocated message queue */
172extern void ipc_mqueue_init(
91447636 173 ipc_mqueue_t mqueue,
3e170ce0
A
174 boolean_t is_set,
175 uint64_t *reserved_link);
176
177/* de-initialize / cleanup an mqueue (specifically waitq resources) */
178extern void ipc_mqueue_deinit(
179 ipc_mqueue_t mqueue);
91447636
A
180
181/* destroy an mqueue */
39037602 182extern boolean_t ipc_mqueue_destroy_locked(
91447636 183 ipc_mqueue_t mqueue);
1c79356b 184
1c79356b
A
185/* Wake up receivers waiting in a message queue */
186extern void ipc_mqueue_changed(
187 ipc_mqueue_t mqueue);
188
91447636
A
189/* Add the specific mqueue as a member of the set */
190extern kern_return_t ipc_mqueue_add(
191 ipc_mqueue_t mqueue,
316670eb 192 ipc_mqueue_t set_mqueue,
3e170ce0
A
193 uint64_t *reserved_link,
194 uint64_t *reserved_prepost);
91447636
A
195
196/* Check to see if mqueue is member of set_mqueue */
197extern boolean_t ipc_mqueue_member(
198 ipc_mqueue_t mqueue,
199 ipc_mqueue_t set_mqueue);
200
201/* Remove an mqueue from a specific set */
202extern kern_return_t ipc_mqueue_remove(
203 ipc_mqueue_t mqueue,
3e170ce0 204 ipc_mqueue_t set_mqueue);
91447636
A
205
206/* Remove an mqueue from all sets */
207extern void ipc_mqueue_remove_from_all(
3e170ce0 208 ipc_mqueue_t mqueue);
91447636
A
209
210/* Remove all the members of the specifiied set */
211extern void ipc_mqueue_remove_all(
3e170ce0 212 ipc_mqueue_t mqueue);
91447636 213
1c79356b
A
214/* Send a message to a port */
215extern mach_msg_return_t ipc_mqueue_send(
216 ipc_mqueue_t mqueue,
217 ipc_kmsg_t kmsg,
218 mach_msg_option_t option,
39037602 219 mach_msg_timeout_t timeout_val);
1c79356b 220
39236c6e
A
221/* check for queue send queue full of a port */
222extern mach_msg_return_t ipc_mqueue_preflight_send(
223 ipc_mqueue_t mqueue,
224 ipc_kmsg_t kmsg,
225 mach_msg_option_t option,
226 mach_msg_timeout_t timeout_val);
227
39037602
A
228/* Set a [send-possible] override on the mqueue */
229extern void ipc_mqueue_override_send(
230 ipc_mqueue_t mqueue,
231 mach_msg_priority_t override);
232
1c79356b
A
233/* Deliver message to message queue or waiting receiver */
234extern void ipc_mqueue_post(
235 ipc_mqueue_t mqueue,
39037602
A
236 ipc_kmsg_t kmsg,
237 mach_msg_option_t option);
1c79356b
A
238
239/* Receive a message from a message queue */
240extern void ipc_mqueue_receive(
241 ipc_mqueue_t mqueue,
242 mach_msg_option_t option,
243 mach_msg_size_t max_size,
91447636 244 mach_msg_timeout_t timeout_val,
1c79356b
A
245 int interruptible);
246
b0d623f7
A
247/* Receive a message from a message queue using a specified thread */
248extern wait_result_t ipc_mqueue_receive_on_thread(
249 ipc_mqueue_t mqueue,
250 mach_msg_option_t option,
251 mach_msg_size_t max_size,
252 mach_msg_timeout_t rcv_timeout,
253 int interruptible,
254 thread_t thread);
255
1c79356b 256/* Continuation routine for message receive */
91447636
A
257extern void ipc_mqueue_receive_continue(
258 void *param,
259 wait_result_t wresult);
1c79356b
A
260
261/* Select a message from a queue and try to post it to ourself */
b0d623f7 262extern void ipc_mqueue_select_on_thread(
3e170ce0
A
263 ipc_mqueue_t port_mq,
264 ipc_mqueue_t set_mq,
1c79356b 265 mach_msg_option_t option,
b0d623f7
A
266 mach_msg_size_t max_size,
267 thread_t thread);
268
269/* Peek into a messaqe queue to see if there are messages */
6d2010ae 270extern unsigned ipc_mqueue_peek(
39236c6e
A
271 ipc_mqueue_t mqueue,
272 mach_port_seqno_t *msg_seqnop,
273 mach_msg_size_t *msg_sizep,
274 mach_msg_id_t *msg_idp,
39037602
A
275 mach_msg_max_trailer_t *msg_trailerp,
276 ipc_kmsg_t *kmsgp);
277
278/* Peek into a locked messaqe queue to see if there are messages */
279extern unsigned ipc_mqueue_peek_locked(
280 ipc_mqueue_t mqueue,
281 mach_port_seqno_t *msg_seqnop,
282 mach_msg_size_t *msg_sizep,
283 mach_msg_id_t *msg_idp,
284 mach_msg_max_trailer_t *msg_trailerp,
285 ipc_kmsg_t *kmsgp);
39236c6e
A
286
287/* Peek into a messaqe queue set to see if there are queues with messages */
288extern unsigned ipc_mqueue_set_peek(
b0d623f7 289 ipc_mqueue_t mqueue);
1c79356b 290
39037602
A
291/* Release an mqueue/port reference that was granted by MACH_PEEK_MSG */
292extern void ipc_mqueue_release_peek_ref(
293 ipc_mqueue_t mqueue);
294
39236c6e
A
295/* Gather the names of member port for a given set */
296extern void ipc_mqueue_set_gather_member_names(
3e170ce0
A
297 ipc_space_t space,
298 ipc_mqueue_t set_mq,
39236c6e
A
299 ipc_entry_num_t maxnames,
300 mach_port_name_t *names,
301 ipc_entry_num_t *actualp);
302
1c79356b
A
303/* Clear a message count reservation */
304extern void ipc_mqueue_release_msgcount(
3e170ce0
A
305 ipc_mqueue_t port_mq,
306 ipc_mqueue_t set_mq);
1c79356b
A
307
308/* Change a queue limit */
309extern void ipc_mqueue_set_qlimit(
310 ipc_mqueue_t mqueue,
311 mach_port_msgcount_t qlimit);
312
313/* Change a queue's sequence number */
314extern void ipc_mqueue_set_seqno(
315 ipc_mqueue_t mqueue,
316 mach_port_seqno_t seqno);
317
318/* Convert a name in a space to a message queue */
319extern mach_msg_return_t ipc_mqueue_copyin(
320 ipc_space_t space,
321 mach_port_name_t name,
322 ipc_mqueue_t *mqueuep,
323 ipc_object_t *objectp);
324
325#endif /* _IPC_IPC_MQUEUE_H_ */