]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_kmsg.h
xnu-3789.70.16.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_kmsg.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, 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 */
2d21ac55
A
56/*
57 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
58 * support for mandatory and extensible security protections. This notice
59 * is included in support of clause 2.2 (b) of the Apple Public License,
60 * Version 2.0.
61 * Copyright (c) 2005 SPARTA, Inc.
62 */
1c79356b
A
63/*
64 */
65/*
66 * File: ipc/ipc_kmsg.h
67 * Author: Rich Draves
68 * Date: 1989
69 *
70 * Definitions for kernel messages.
71 */
72
73#ifndef _IPC_IPC_KMSG_H_
74#define _IPC_IPC_KMSG_H_
75
1c79356b
A
76#include <mach/vm_types.h>
77#include <mach/message.h>
91447636 78#include <kern/kern_types.h>
1c79356b 79#include <kern/assert.h>
1c79356b 80#include <kern/macro_help.h>
91447636 81#include <ipc/ipc_types.h>
1c79356b 82#include <ipc/ipc_object.h>
39037602 83#include <sys/kdebug.h>
1c79356b
A
84
85/*
86 * This structure is only the header for a kmsg buffer;
87 * the actual buffer is normally larger. The rest of the buffer
88 * holds the body of the message.
89 *
90 * In a kmsg, the port fields hold pointers to ports instead
91 * of port names. These pointers hold references.
92 *
93 * The ikm_header.msgh_remote_port field is the destination
94 * of the message.
95 */
96
91447636 97struct ipc_kmsg {
39037602
A
98 mach_msg_size_t ikm_size;
99 struct ipc_kmsg *ikm_next; /* next message on port/discard queue */
100 struct ipc_kmsg *ikm_prev; /* prev message on port/discard queue */
101 mach_msg_header_t *ikm_header;
102 ipc_port_t ikm_prealloc; /* port we were preallocated from */
103 ipc_port_t ikm_voucher; /* voucher port carried */
104 mach_msg_priority_t ikm_qos; /* qos of this kmsg */
105 mach_msg_priority_t ikm_qos_override; /* qos override on this kmsg */
106 struct ipc_importance_elem *ikm_importance; /* inherited from */
107 queue_chain_t ikm_inheritance; /* inherited from link */
108#if MACH_FLIPC
109 struct mach_node *ikm_node; /* Originating node - needed for ack */
110#endif
91447636 111};
1c79356b 112
b0d623f7
A
113#if defined(__i386__) || defined(__arm__)
114#define IKM_SUPPORT_LEGACY 1
115#else
116#define IKM_SUPPORT_LEGACY 0
117#endif
1c79356b 118
91447636 119#define IKM_OVERHEAD (sizeof(struct ipc_kmsg))
1c79356b
A
120
121#define ikm_plus_overhead(size) ((mach_msg_size_t)((size) + IKM_OVERHEAD))
122#define ikm_less_overhead(size) ((mach_msg_size_t)((size) - IKM_OVERHEAD))
123
124/*
125 * XXX For debugging.
126 */
127#define IKM_BOGUS ((ipc_kmsg_t) 0xffffff10)
128
129/*
130 * The size of the kernel message buffers that will be cached.
131 * IKM_SAVED_KMSG_SIZE includes overhead; IKM_SAVED_MSG_SIZE doesn't.
132 */
91447636
A
133extern zone_t ipc_kmsg_zone;
134#define IKM_SAVED_KMSG_SIZE 256
135#define IKM_SAVED_MSG_SIZE ikm_less_overhead(IKM_SAVED_KMSG_SIZE)
1c79356b
A
136
137#define ikm_prealloc_inuse_port(kmsg) \
138 ((kmsg)->ikm_prealloc)
139
140#define ikm_prealloc_inuse(kmsg) \
141 ((kmsg)->ikm_prealloc != IP_NULL)
142
143#define ikm_prealloc_set_inuse(kmsg, port) \
144MACRO_BEGIN \
9bccf70c
A
145 assert((port) != IP_NULL); \
146 (kmsg)->ikm_prealloc = (port); \
147 ip_reference(port); \
1c79356b
A
148MACRO_END
149
150#define ikm_prealloc_clear_inuse(kmsg, port) \
151MACRO_BEGIN \
152 (kmsg)->ikm_prealloc = IP_NULL; \
153MACRO_END
154
39037602
A
155#if MACH_FLIPC
156#define ikm_flipc_init(kmsg) (kmsg)->ikm_node = MACH_NODE_NULL
157#else
158#define ikm_flipc_init(kmsg)
159#endif
160
161#define ikm_init(kmsg, size) \
162MACRO_BEGIN \
163 (kmsg)->ikm_size = (size); \
164 (kmsg)->ikm_prealloc = IP_NULL; \
165 (kmsg)->ikm_voucher = IP_NULL; \
166 (kmsg)->ikm_importance = IIE_NULL; \
167 (kmsg)->ikm_qos = MACH_MSG_PRIORITY_UNSPECIFIED; \
168 (kmsg)->ikm_qos_override = MACH_MSG_PRIORITY_UNSPECIFIED; \
169 ikm_flipc_init(kmsg); \
170 assert((kmsg)->ikm_prev = (kmsg)->ikm_next = IKM_BOGUS); \
1c79356b
A
171MACRO_END
172
173#define ikm_check_init(kmsg, size) \
174MACRO_BEGIN \
175 assert((kmsg)->ikm_size == (size)); \
176 assert((kmsg)->ikm_prev == IKM_BOGUS); \
177 assert((kmsg)->ikm_next == IKM_BOGUS); \
178MACRO_END
179
b7266188
A
180#define ikm_set_header(kmsg, mtsize) \
181MACRO_BEGIN \
182 (kmsg)->ikm_header = (mach_msg_header_t *) \
183 ((vm_offset_t)((kmsg) + 1) + (kmsg)->ikm_size - (mtsize)); \
184MACRO_END
185
1c79356b
A
186struct ipc_kmsg_queue {
187 struct ipc_kmsg *ikmq_base;
188};
189
190typedef struct ipc_kmsg_queue *ipc_kmsg_queue_t;
191
192#define IKMQ_NULL ((ipc_kmsg_queue_t) 0)
193
194
195/*
196 * Exported interfaces
197 */
198
199#define ipc_kmsg_queue_init(queue) \
200MACRO_BEGIN \
201 (queue)->ikmq_base = IKM_NULL; \
202MACRO_END
203
204#define ipc_kmsg_queue_empty(queue) ((queue)->ikmq_base == IKM_NULL)
205
206/* Enqueue a kmsg */
207extern void ipc_kmsg_enqueue(
208 ipc_kmsg_queue_t queue,
209 ipc_kmsg_t kmsg);
210
39037602
A
211extern boolean_t ipc_kmsg_enqueue_qos(
212 ipc_kmsg_queue_t queue,
213 ipc_kmsg_t kmsg);
214
215extern boolean_t ipc_kmsg_override_qos(
216 ipc_kmsg_queue_t queue,
217 ipc_kmsg_t kmsg,
218 mach_msg_priority_t override);
219
1c79356b
A
220/* Dequeue and return a kmsg */
221extern ipc_kmsg_t ipc_kmsg_dequeue(
222 ipc_kmsg_queue_t queue);
223
224/* Pull a kmsg out of a queue */
225extern void ipc_kmsg_rmqueue(
226 ipc_kmsg_queue_t queue,
227 ipc_kmsg_t kmsg);
228
39037602
A
229/* Pull the (given) first kmsg out of a queue */
230extern void ipc_kmsg_rmqueue_first(
231 ipc_kmsg_queue_t queue,
232 ipc_kmsg_t kmsg);
233
1c79356b
A
234#define ipc_kmsg_queue_first(queue) ((queue)->ikmq_base)
235
236/* Return the kmsg following the given kmsg */
237extern ipc_kmsg_t ipc_kmsg_queue_next(
238 ipc_kmsg_queue_t queue,
239 ipc_kmsg_t kmsg);
240
1c79356b
A
241/* Allocate a kernel message */
242extern ipc_kmsg_t ipc_kmsg_alloc(
243 mach_msg_size_t size);
244
245/* Free a kernel message buffer */
246extern void ipc_kmsg_free(
247 ipc_kmsg_t kmsg);
248
249/* Destroy kernel message */
250extern void ipc_kmsg_destroy(
251 ipc_kmsg_t kmsg);
252
6d2010ae
A
253/* Enqueue kernel message for deferred destruction */
254extern boolean_t ipc_kmsg_delayed_destroy(
255 ipc_kmsg_t kmsg);
256
257/* Process all the delayed message destroys */
258extern void ipc_kmsg_reap_delayed(void);
91447636 259
1c79356b 260/* Preallocate a kernel message buffer */
b7266188
A
261extern ipc_kmsg_t ipc_kmsg_prealloc(
262 mach_msg_size_t size);
263
264/* bind a preallocated message buffer to a port */
1c79356b
A
265extern void ipc_kmsg_set_prealloc(
266 ipc_kmsg_t kmsg,
267 ipc_port_t port);
268
b7266188 269/* Clear preallocated message buffer binding */
1c79356b
A
270extern void ipc_kmsg_clear_prealloc(
271 ipc_kmsg_t kmsg,
272 ipc_port_t port);
273
274/* Allocate a kernel message buffer and copy a user message to the buffer */
275extern mach_msg_return_t ipc_kmsg_get(
91447636 276 mach_vm_address_t msg_addr,
1c79356b
A
277 mach_msg_size_t size,
278 ipc_kmsg_t *kmsgp);
279
280/* Allocate a kernel message buffer and copy a kernel message to the buffer */
281extern mach_msg_return_t ipc_kmsg_get_from_kernel(
282 mach_msg_header_t *msg,
283 mach_msg_size_t size,
284 ipc_kmsg_t *kmsgp);
285
286/* Send a message to a port */
287extern mach_msg_return_t ipc_kmsg_send(
288 ipc_kmsg_t kmsg,
289 mach_msg_option_t option,
91447636 290 mach_msg_timeout_t timeout_val);
1c79356b
A
291
292/* Copy a kernel message buffer to a user message */
293extern mach_msg_return_t ipc_kmsg_put(
1c79356b 294 ipc_kmsg_t kmsg,
39037602
A
295 mach_msg_option_t option,
296 mach_vm_address_t rcv_addr,
297 mach_msg_size_t rcv_size,
298 mach_msg_size_t trailer_size,
299 mach_msg_size_t *size);
1c79356b
A
300
301/* Copy a kernel message buffer to a kernel message */
302extern void ipc_kmsg_put_to_kernel(
303 mach_msg_header_t *msg,
304 ipc_kmsg_t kmsg,
305 mach_msg_size_t size);
306
307/* Copyin port rights in the header of a message */
308extern mach_msg_return_t ipc_kmsg_copyin_header(
fe8ab488 309 ipc_kmsg_t kmsg,
1c79356b 310 ipc_space_t space,
39037602 311 mach_msg_priority_t override,
39236c6e 312 mach_msg_option_t *optionp);
1c79356b
A
313
314/* Copyin port rights and out-of-line memory from a user message */
315extern mach_msg_return_t ipc_kmsg_copyin(
316 ipc_kmsg_t kmsg,
317 ipc_space_t space,
318 vm_map_t map,
39037602 319 mach_msg_priority_t override,
39236c6e 320 mach_msg_option_t *optionp);
1c79356b
A
321
322/* Copyin port rights and out-of-line memory from a kernel message */
6d2010ae 323extern mach_msg_return_t ipc_kmsg_copyin_from_kernel(
1c79356b
A
324 ipc_kmsg_t kmsg);
325
b0d623f7 326#if IKM_SUPPORT_LEGACY
6d2010ae 327extern mach_msg_return_t ipc_kmsg_copyin_from_kernel_legacy(
b0d623f7
A
328 ipc_kmsg_t kmsg);
329#endif
330
1c79356b
A
331/* Copyout port rights in the header of a message */
332extern mach_msg_return_t ipc_kmsg_copyout_header(
fe8ab488
A
333 ipc_kmsg_t kmsg,
334 ipc_space_t space,
335 mach_msg_option_t option);
1c79356b
A
336
337/* Copyout a port right returning a name */
338extern mach_msg_return_t ipc_kmsg_copyout_object(
339 ipc_space_t space,
340 ipc_object_t object,
341 mach_msg_type_name_t msgt_name,
342 mach_port_name_t *namep);
343
344/* Copyout the header and body to a user message */
345extern mach_msg_return_t ipc_kmsg_copyout(
346 ipc_kmsg_t kmsg,
347 ipc_space_t space,
348 vm_map_t map,
fe8ab488
A
349 mach_msg_body_t *slist,
350 mach_msg_option_t option);
1c79356b
A
351
352/* Copyout port rights and out-of-line memory from the body of a message */
353extern mach_msg_return_t ipc_kmsg_copyout_body(
354 ipc_kmsg_t kmsg,
355 ipc_space_t space,
356 vm_map_t map,
357 mach_msg_body_t *slist);
358
359/* Copyout port rights and out-of-line memory to a user message,
360 not reversing the ports in the header */
361extern mach_msg_return_t ipc_kmsg_copyout_pseudo(
362 ipc_kmsg_t kmsg,
363 ipc_space_t space,
364 vm_map_t map,
365 mach_msg_body_t *slist);
366
91447636
A
367/* Compute size of message as copied out to the specified space/map */
368extern mach_msg_size_t ipc_kmsg_copyout_size(
369 ipc_kmsg_t kmsg,
370 vm_map_t map);
371
1c79356b
A
372/* Copyout the destination port in the message */
373extern void ipc_kmsg_copyout_dest(
374 ipc_kmsg_t kmsg,
375 ipc_space_t space);
376
377/* kernel's version of ipc_kmsg_copyout_dest */
378extern void ipc_kmsg_copyout_to_kernel(
379 ipc_kmsg_t kmsg,
380 ipc_space_t space);
381
b0d623f7
A
382#if IKM_SUPPORT_LEGACY
383extern void ipc_kmsg_copyout_to_kernel_legacy(
384 ipc_kmsg_t kmsg,
385 ipc_space_t space);
386#endif
387
316670eb
A
388extern mach_msg_trailer_size_t
389ipc_kmsg_add_trailer(ipc_kmsg_t kmsg, ipc_space_t space,
390 mach_msg_option_t option, thread_t thread,
391 mach_port_seqno_t seqno, boolean_t minimal_trailer,
392 mach_vm_offset_t context);
393
39037602
A
394#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
395extern void ipc_kmsg_trace_send(ipc_kmsg_t kmsg,
396 mach_msg_option_t option);
397#else
398#define ipc_kmsg_trace_send(a,b) do { } while (0)
399#endif
400
1c79356b 401#endif /* _IPC_IPC_KMSG_H_ */
2d21ac55 402