]>
Commit | Line | Data |
---|---|---|
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/waitq.h> | |
77 | ||
78 | #include <ipc/ipc_kmsg.h> | |
79 | #include <ipc/ipc_object.h> | |
80 | #include <ipc/ipc_types.h> | |
81 | ||
82 | #include <sys/event.h> | |
83 | ||
84 | typedef struct ipc_mqueue { | |
85 | union { | |
86 | struct { | |
87 | struct waitq waitq; | |
88 | struct ipc_kmsg_queue messages; | |
89 | mach_port_seqno_t seqno; | |
90 | mach_port_name_t receiver_name; | |
91 | uint16_t msgcount; | |
92 | uint16_t qlimit; | |
93 | #if MACH_FLIPC | |
94 | struct flipc_port *fport; // Null for local port, or ptr to flipc port | |
95 | #endif | |
96 | } __attribute__((__packed__)) port; | |
97 | struct { | |
98 | struct waitq_set setq; | |
99 | } __attribute__((__packed__)) pset; | |
100 | } data; | |
101 | struct klist imq_klist; | |
102 | } *ipc_mqueue_t; | |
103 | ||
104 | #define IMQ_NULL ((ipc_mqueue_t) 0) | |
105 | ||
106 | #define imq_wait_queue data.port.waitq | |
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 | |
111 | #define imq_receiver_name data.port.receiver_name | |
112 | #if MACH_FLIPC | |
113 | #define imq_fport data.port.fport | |
114 | #endif | |
115 | ||
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 | |
122 | #define imq_preposts data.port.waitq.waitq_prepost_id | |
123 | ||
124 | #define imq_set_queue data.pset.setq | |
125 | #define imq_is_set(mq) waitqs_is_set(&(mq)->imq_set_queue) | |
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) | |
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) | |
133 | #define imq_valid(mq) waitq_valid(&(mq)->imq_wait_queue) | |
134 | ||
135 | extern void imq_reserve_and_lock(ipc_mqueue_t mq, | |
136 | uint64_t *reserved_prepost); | |
137 | ||
138 | extern void imq_release_and_unlock(ipc_mqueue_t mq, | |
139 | uint64_t reserved_prepost); | |
140 | ||
141 | #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit) | |
142 | #define imq_full_kernel(mq) ((mq)->imq_msgcount >= MACH_PORT_QLIMIT_KERNEL) | |
143 | ||
144 | extern int ipc_mqueue_full; | |
145 | // extern int ipc_mqueue_rcv; | |
146 | ||
147 | #define IPC_MQUEUE_FULL CAST_EVENT64_T(&ipc_mqueue_full) | |
148 | #define IPC_MQUEUE_RECEIVE NO_EVENT64 | |
149 | ||
150 | /* | |
151 | * Exported interfaces | |
152 | */ | |
153 | ||
154 | /* Initialize a newly-allocated message queue */ | |
155 | extern void ipc_mqueue_init( | |
156 | ipc_mqueue_t mqueue, | |
157 | boolean_t is_set, | |
158 | uint64_t *reserved_link); | |
159 | ||
160 | /* de-initialize / cleanup an mqueue (specifically waitq resources) */ | |
161 | extern void ipc_mqueue_deinit( | |
162 | ipc_mqueue_t mqueue); | |
163 | ||
164 | /* destroy an mqueue */ | |
165 | extern boolean_t ipc_mqueue_destroy_locked( | |
166 | ipc_mqueue_t mqueue); | |
167 | ||
168 | /* Wake up receivers waiting in a message queue */ | |
169 | extern void ipc_mqueue_changed( | |
170 | ipc_mqueue_t mqueue); | |
171 | ||
172 | /* Add the specific mqueue as a member of the set */ | |
173 | extern kern_return_t ipc_mqueue_add( | |
174 | ipc_mqueue_t mqueue, | |
175 | ipc_mqueue_t set_mqueue, | |
176 | uint64_t *reserved_link, | |
177 | uint64_t *reserved_prepost); | |
178 | ||
179 | /* Check to see if mqueue is member of set_mqueue */ | |
180 | extern boolean_t ipc_mqueue_member( | |
181 | ipc_mqueue_t mqueue, | |
182 | ipc_mqueue_t set_mqueue); | |
183 | ||
184 | /* Remove an mqueue from a specific set */ | |
185 | extern kern_return_t ipc_mqueue_remove( | |
186 | ipc_mqueue_t mqueue, | |
187 | ipc_mqueue_t set_mqueue); | |
188 | ||
189 | /* Remove an mqueue from all sets */ | |
190 | extern void ipc_mqueue_remove_from_all( | |
191 | ipc_mqueue_t mqueue); | |
192 | ||
193 | /* Remove all the members of the specifiied set */ | |
194 | extern void ipc_mqueue_remove_all( | |
195 | ipc_mqueue_t mqueue); | |
196 | ||
197 | /* Send a message to a port */ | |
198 | extern mach_msg_return_t ipc_mqueue_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 | /* check for queue send queue full of a port */ | |
205 | extern mach_msg_return_t ipc_mqueue_preflight_send( | |
206 | ipc_mqueue_t mqueue, | |
207 | ipc_kmsg_t kmsg, | |
208 | mach_msg_option_t option, | |
209 | mach_msg_timeout_t timeout_val); | |
210 | ||
211 | /* Set a [send-possible] override on the mqueue */ | |
212 | extern void ipc_mqueue_override_send( | |
213 | ipc_mqueue_t mqueue, | |
214 | mach_msg_priority_t override); | |
215 | ||
216 | /* Deliver message to message queue or waiting receiver */ | |
217 | extern void ipc_mqueue_post( | |
218 | ipc_mqueue_t mqueue, | |
219 | ipc_kmsg_t kmsg, | |
220 | mach_msg_option_t option); | |
221 | ||
222 | /* Receive a message from a message queue */ | |
223 | extern void ipc_mqueue_receive( | |
224 | ipc_mqueue_t mqueue, | |
225 | mach_msg_option_t option, | |
226 | mach_msg_size_t max_size, | |
227 | mach_msg_timeout_t timeout_val, | |
228 | int interruptible); | |
229 | ||
230 | /* Receive a message from a message queue using a specified thread */ | |
231 | extern wait_result_t ipc_mqueue_receive_on_thread( | |
232 | ipc_mqueue_t mqueue, | |
233 | mach_msg_option_t option, | |
234 | mach_msg_size_t max_size, | |
235 | mach_msg_timeout_t rcv_timeout, | |
236 | int interruptible, | |
237 | thread_t thread); | |
238 | ||
239 | /* Continuation routine for message receive */ | |
240 | extern void ipc_mqueue_receive_continue( | |
241 | void *param, | |
242 | wait_result_t wresult); | |
243 | ||
244 | /* Select a message from a queue and try to post it to ourself */ | |
245 | extern void ipc_mqueue_select_on_thread( | |
246 | ipc_mqueue_t port_mq, | |
247 | ipc_mqueue_t set_mq, | |
248 | mach_msg_option_t option, | |
249 | mach_msg_size_t max_size, | |
250 | thread_t thread); | |
251 | ||
252 | /* Peek into a messaqe queue to see if there are messages */ | |
253 | extern unsigned ipc_mqueue_peek( | |
254 | ipc_mqueue_t mqueue, | |
255 | mach_port_seqno_t *msg_seqnop, | |
256 | mach_msg_size_t *msg_sizep, | |
257 | mach_msg_id_t *msg_idp, | |
258 | mach_msg_max_trailer_t *msg_trailerp, | |
259 | ipc_kmsg_t *kmsgp); | |
260 | ||
261 | /* Peek into a locked messaqe queue to see if there are messages */ | |
262 | extern unsigned ipc_mqueue_peek_locked( | |
263 | ipc_mqueue_t mqueue, | |
264 | mach_port_seqno_t *msg_seqnop, | |
265 | mach_msg_size_t *msg_sizep, | |
266 | mach_msg_id_t *msg_idp, | |
267 | mach_msg_max_trailer_t *msg_trailerp, | |
268 | ipc_kmsg_t *kmsgp); | |
269 | ||
270 | /* Peek into a messaqe queue set to see if there are queues with messages */ | |
271 | extern unsigned ipc_mqueue_set_peek( | |
272 | ipc_mqueue_t mqueue); | |
273 | ||
274 | /* Release an mqueue/port reference that was granted by MACH_PEEK_MSG */ | |
275 | extern void ipc_mqueue_release_peek_ref( | |
276 | ipc_mqueue_t mqueue); | |
277 | ||
278 | /* Gather the names of member port for a given set */ | |
279 | extern void ipc_mqueue_set_gather_member_names( | |
280 | ipc_space_t space, | |
281 | ipc_mqueue_t set_mq, | |
282 | ipc_entry_num_t maxnames, | |
283 | mach_port_name_t *names, | |
284 | ipc_entry_num_t *actualp); | |
285 | ||
286 | /* Clear a message count reservation */ | |
287 | extern void ipc_mqueue_release_msgcount( | |
288 | ipc_mqueue_t port_mq, | |
289 | ipc_mqueue_t set_mq); | |
290 | ||
291 | /* Change a queue limit */ | |
292 | extern void ipc_mqueue_set_qlimit( | |
293 | ipc_mqueue_t mqueue, | |
294 | mach_port_msgcount_t qlimit); | |
295 | ||
296 | /* Change a queue's sequence number */ | |
297 | extern void ipc_mqueue_set_seqno( | |
298 | ipc_mqueue_t mqueue, | |
299 | mach_port_seqno_t seqno); | |
300 | ||
301 | /* Convert a name in a space to a message queue */ | |
302 | extern mach_msg_return_t ipc_mqueue_copyin( | |
303 | ipc_space_t space, | |
304 | mach_port_name_t name, | |
305 | ipc_mqueue_t *mqueuep, | |
306 | ipc_object_t *objectp); | |
307 | ||
308 | #endif /* _IPC_IPC_MQUEUE_H_ */ |