]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
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. | |
0a7de745 | 41 | * |
1c79356b A |
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. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
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 | ||
0a7de745 | 73 | #ifndef _IPC_IPC_KMSG_H_ |
1c79356b A |
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 | 84 | |
f427ee49 | 85 | #if (DEVELOPMENT || DEBUG) |
2a1bd2d3 A |
86 | /* Turn on to keep partial message signatures for better debug */ |
87 | #define IKM_PARTIAL_SIG 0 | |
f427ee49 A |
88 | #endif |
89 | ||
1c79356b A |
90 | /* |
91 | * This structure is only the header for a kmsg buffer; | |
92 | * the actual buffer is normally larger. The rest of the buffer | |
93 | * holds the body of the message. | |
94 | * | |
95 | * In a kmsg, the port fields hold pointers to ports instead | |
96 | * of port names. These pointers hold references. | |
97 | * | |
98 | * The ikm_header.msgh_remote_port field is the destination | |
99 | * of the message. | |
5ba3f43e A |
100 | * |
101 | * sync_qos and special_port_qos stores the qos for prealloced | |
102 | * port, this fields could be deleted once we remove ip_prealloc. | |
1c79356b A |
103 | */ |
104 | ||
91447636 | 105 | struct ipc_kmsg { |
39037602 A |
106 | struct ipc_kmsg *ikm_next; /* next message on port/discard queue */ |
107 | struct ipc_kmsg *ikm_prev; /* prev message on port/discard queue */ | |
f427ee49 A |
108 | union { |
109 | ipc_port_t XNU_PTRAUTH_SIGNED_PTR("kmsg.ikm_prealloc") ikmu_prealloc; /* port we were preallocated from */ | |
110 | void *XNU_PTRAUTH_SIGNED_PTR("kmsg.ikm_data") ikmu_data; | |
111 | } ikm_u; | |
112 | mach_msg_header_t *XNU_PTRAUTH_SIGNED_PTR("kmsg.ikm_header") ikm_header; | |
113 | ipc_port_t XNU_PTRAUTH_SIGNED_PTR("kmsg.ikm_voucher") ikm_voucher; /* voucher port carried */ | |
39037602 A |
114 | struct ipc_importance_elem *ikm_importance; /* inherited from */ |
115 | queue_chain_t ikm_inheritance; /* inherited from link */ | |
d9a64523 | 116 | struct turnstile *ikm_turnstile; /* send turnstile for ikm_prealloc port */ |
39037602 A |
117 | #if MACH_FLIPC |
118 | struct mach_node *ikm_node; /* Originating node - needed for ack */ | |
119 | #endif | |
c3c9b80d A |
120 | mach_msg_size_t ikm_size; |
121 | uint32_t ikm_ppriority; /* pthread priority of this kmsg */ | |
f427ee49 A |
122 | #if IKM_PARTIAL_SIG |
123 | uintptr_t ikm_header_sig; /* sig for just the header */ | |
124 | uintptr_t ikm_headtrail_sig;/* sif for header and trailer */ | |
125 | #endif | |
126 | uintptr_t ikm_signature; /* sig for all kernel-processed data */ | |
c3c9b80d | 127 | ipc_object_copyin_flags_t ikm_flags; |
f427ee49 A |
128 | mach_msg_qos_t ikm_qos_override; /* qos override on this kmsg */ |
129 | mach_msg_filter_id ikm_filter_policy_id; /* Sandbox-specific policy id used for message filtering */ | |
91447636 | 130 | }; |
f427ee49 A |
131 | #define ikm_prealloc ikm_u.ikmu_prealloc |
132 | #define ikm_data ikm_u.ikmu_data | |
1c79356b | 133 | |
b0d623f7 | 134 | #if defined(__i386__) || defined(__arm__) |
0a7de745 | 135 | #define IKM_SUPPORT_LEGACY 1 |
b0d623f7 | 136 | #else |
0a7de745 | 137 | #define IKM_SUPPORT_LEGACY 0 |
b0d623f7 | 138 | #endif |
1c79356b | 139 | |
0a7de745 | 140 | #define IKM_OVERHEAD (sizeof(struct ipc_kmsg)) |
1c79356b | 141 | |
0a7de745 A |
142 | #define ikm_plus_overhead(size) ((mach_msg_size_t)((size) + IKM_OVERHEAD)) |
143 | #define ikm_less_overhead(size) ((mach_msg_size_t)((size) - IKM_OVERHEAD)) | |
1c79356b A |
144 | |
145 | /* | |
146 | * XXX For debugging. | |
147 | */ | |
0a7de745 | 148 | #define IKM_BOGUS ((ipc_kmsg_t) 0xffffff10) |
1c79356b A |
149 | |
150 | /* | |
151 | * The size of the kernel message buffers that will be cached. | |
152 | * IKM_SAVED_KMSG_SIZE includes overhead; IKM_SAVED_MSG_SIZE doesn't. | |
153 | */ | |
91447636 | 154 | extern zone_t ipc_kmsg_zone; |
0a7de745 A |
155 | #define IKM_SAVED_KMSG_SIZE 256 |
156 | #define IKM_SAVED_MSG_SIZE ikm_less_overhead(IKM_SAVED_KMSG_SIZE) | |
1c79356b | 157 | |
0a7de745 | 158 | #define ikm_prealloc_inuse_port(kmsg) \ |
1c79356b A |
159 | ((kmsg)->ikm_prealloc) |
160 | ||
0a7de745 | 161 | #define ikm_prealloc_inuse(kmsg) \ |
1c79356b A |
162 | ((kmsg)->ikm_prealloc != IP_NULL) |
163 | ||
0a7de745 A |
164 | #define ikm_prealloc_set_inuse(kmsg, port) \ |
165 | MACRO_BEGIN \ | |
166 | assert((port) != IP_NULL); \ | |
167 | (kmsg)->ikm_prealloc = (port); \ | |
168 | ip_reference(port); \ | |
1c79356b A |
169 | MACRO_END |
170 | ||
0a7de745 A |
171 | #define ikm_prealloc_clear_inuse(kmsg, port) \ |
172 | MACRO_BEGIN \ | |
173 | (kmsg)->ikm_prealloc = IP_NULL; \ | |
1c79356b A |
174 | MACRO_END |
175 | ||
f427ee49 | 176 | #define ikm_qos_init(kmsg) \ |
0a7de745 | 177 | MACRO_BEGIN \ |
f427ee49 A |
178 | (kmsg)->ikm_ppriority = MACH_MSG_PRIORITY_UNSPECIFIED; \ |
179 | (kmsg)->ikm_qos_override = THREAD_QOS_UNSPECIFIED; \ | |
b7266188 A |
180 | MACRO_END |
181 | ||
1c79356b A |
182 | struct ipc_kmsg_queue { |
183 | struct ipc_kmsg *ikmq_base; | |
184 | }; | |
185 | ||
186 | typedef struct ipc_kmsg_queue *ipc_kmsg_queue_t; | |
187 | ||
0a7de745 | 188 | #define IKMQ_NULL ((ipc_kmsg_queue_t) 0) |
1c79356b A |
189 | |
190 | ||
191 | /* | |
192 | * Exported interfaces | |
193 | */ | |
194 | ||
0a7de745 A |
195 | #define ipc_kmsg_queue_init(queue) \ |
196 | MACRO_BEGIN \ | |
197 | (queue)->ikmq_base = IKM_NULL; \ | |
1c79356b A |
198 | MACRO_END |
199 | ||
0a7de745 | 200 | #define ipc_kmsg_queue_empty(queue) ((queue)->ikmq_base == IKM_NULL) |
1c79356b A |
201 | |
202 | /* Enqueue a kmsg */ | |
203 | extern void ipc_kmsg_enqueue( | |
0a7de745 A |
204 | ipc_kmsg_queue_t queue, |
205 | ipc_kmsg_t kmsg); | |
1c79356b | 206 | |
39037602 | 207 | extern boolean_t ipc_kmsg_enqueue_qos( |
0a7de745 A |
208 | ipc_kmsg_queue_t queue, |
209 | ipc_kmsg_t kmsg); | |
39037602 A |
210 | |
211 | extern boolean_t ipc_kmsg_override_qos( | |
212 | ipc_kmsg_queue_t queue, | |
213 | ipc_kmsg_t kmsg, | |
f427ee49 | 214 | mach_msg_qos_t qos_ovr); |
39037602 | 215 | |
1c79356b A |
216 | /* Dequeue and return a kmsg */ |
217 | extern ipc_kmsg_t ipc_kmsg_dequeue( | |
218 | ipc_kmsg_queue_t queue); | |
219 | ||
220 | /* Pull a kmsg out of a queue */ | |
221 | extern void ipc_kmsg_rmqueue( | |
0a7de745 A |
222 | ipc_kmsg_queue_t queue, |
223 | ipc_kmsg_t kmsg); | |
1c79356b | 224 | |
39037602 A |
225 | /* Pull the (given) first kmsg out of a queue */ |
226 | extern void ipc_kmsg_rmqueue_first( | |
0a7de745 | 227 | ipc_kmsg_queue_t queue, |
39037602 A |
228 | ipc_kmsg_t kmsg); |
229 | ||
0a7de745 | 230 | #define ipc_kmsg_queue_first(queue) ((queue)->ikmq_base) |
1c79356b A |
231 | |
232 | /* Return the kmsg following the given kmsg */ | |
233 | extern ipc_kmsg_t ipc_kmsg_queue_next( | |
0a7de745 A |
234 | ipc_kmsg_queue_t queue, |
235 | ipc_kmsg_t kmsg); | |
1c79356b | 236 | |
1c79356b A |
237 | /* Allocate a kernel message */ |
238 | extern ipc_kmsg_t ipc_kmsg_alloc( | |
0a7de745 | 239 | mach_msg_size_t size); |
1c79356b A |
240 | |
241 | /* Free a kernel message buffer */ | |
242 | extern void ipc_kmsg_free( | |
0a7de745 | 243 | ipc_kmsg_t kmsg); |
1c79356b A |
244 | |
245 | /* Destroy kernel message */ | |
246 | extern void ipc_kmsg_destroy( | |
0a7de745 | 247 | ipc_kmsg_t kmsg); |
1c79356b | 248 | |
6d2010ae A |
249 | /* Enqueue kernel message for deferred destruction */ |
250 | extern boolean_t ipc_kmsg_delayed_destroy( | |
251 | ipc_kmsg_t kmsg); | |
252 | ||
253 | /* Process all the delayed message destroys */ | |
254 | extern void ipc_kmsg_reap_delayed(void); | |
91447636 | 255 | |
1c79356b | 256 | /* Preallocate a kernel message buffer */ |
b7266188 | 257 | extern ipc_kmsg_t ipc_kmsg_prealloc( |
0a7de745 | 258 | mach_msg_size_t size); |
b7266188 A |
259 | |
260 | /* bind a preallocated message buffer to a port */ | |
1c79356b | 261 | extern void ipc_kmsg_set_prealloc( |
0a7de745 A |
262 | ipc_kmsg_t kmsg, |
263 | ipc_port_t port); | |
1c79356b | 264 | |
b7266188 | 265 | /* Clear preallocated message buffer binding */ |
1c79356b | 266 | extern void ipc_kmsg_clear_prealloc( |
0a7de745 A |
267 | ipc_kmsg_t kmsg, |
268 | ipc_port_t port); | |
1c79356b A |
269 | |
270 | /* Allocate a kernel message buffer and copy a user message to the buffer */ | |
271 | extern mach_msg_return_t ipc_kmsg_get( | |
0a7de745 A |
272 | mach_vm_address_t msg_addr, |
273 | mach_msg_size_t size, | |
274 | ipc_kmsg_t *kmsgp); | |
1c79356b A |
275 | |
276 | /* Allocate a kernel message buffer and copy a kernel message to the buffer */ | |
277 | extern mach_msg_return_t ipc_kmsg_get_from_kernel( | |
0a7de745 A |
278 | mach_msg_header_t *msg, |
279 | mach_msg_size_t size, | |
280 | ipc_kmsg_t *kmsgp); | |
1c79356b A |
281 | |
282 | /* Send a message to a port */ | |
283 | extern mach_msg_return_t ipc_kmsg_send( | |
0a7de745 A |
284 | ipc_kmsg_t kmsg, |
285 | mach_msg_option_t option, | |
286 | mach_msg_timeout_t timeout_val); | |
1c79356b A |
287 | |
288 | /* Copy a kernel message buffer to a user message */ | |
289 | extern mach_msg_return_t ipc_kmsg_put( | |
0a7de745 A |
290 | ipc_kmsg_t kmsg, |
291 | mach_msg_option_t option, | |
292 | mach_vm_address_t rcv_addr, | |
293 | mach_msg_size_t rcv_size, | |
294 | mach_msg_size_t trailer_size, | |
295 | mach_msg_size_t *size); | |
1c79356b A |
296 | |
297 | /* Copy a kernel message buffer to a kernel message */ | |
298 | extern void ipc_kmsg_put_to_kernel( | |
0a7de745 A |
299 | mach_msg_header_t *msg, |
300 | ipc_kmsg_t kmsg, | |
301 | mach_msg_size_t size); | |
1c79356b A |
302 | |
303 | /* Copyin port rights in the header of a message */ | |
304 | extern mach_msg_return_t ipc_kmsg_copyin_header( | |
fe8ab488 | 305 | ipc_kmsg_t kmsg, |
0a7de745 | 306 | ipc_space_t space, |
f427ee49 | 307 | mach_msg_priority_t priority, |
0a7de745 | 308 | mach_msg_option_t *optionp); |
1c79356b A |
309 | |
310 | /* Copyin port rights and out-of-line memory from a user message */ | |
311 | extern mach_msg_return_t ipc_kmsg_copyin( | |
0a7de745 A |
312 | ipc_kmsg_t kmsg, |
313 | ipc_space_t space, | |
314 | vm_map_t map, | |
f427ee49 | 315 | mach_msg_priority_t priority, |
0a7de745 | 316 | mach_msg_option_t *optionp); |
1c79356b A |
317 | |
318 | /* Copyin port rights and out-of-line memory from a kernel message */ | |
6d2010ae | 319 | extern mach_msg_return_t ipc_kmsg_copyin_from_kernel( |
0a7de745 | 320 | ipc_kmsg_t kmsg); |
1c79356b | 321 | |
b0d623f7 | 322 | #if IKM_SUPPORT_LEGACY |
6d2010ae | 323 | extern mach_msg_return_t ipc_kmsg_copyin_from_kernel_legacy( |
0a7de745 | 324 | ipc_kmsg_t kmsg); |
b0d623f7 A |
325 | #endif |
326 | ||
1c79356b A |
327 | /* Copyout port rights in the header of a message */ |
328 | extern mach_msg_return_t ipc_kmsg_copyout_header( | |
fe8ab488 | 329 | ipc_kmsg_t kmsg, |
0a7de745 A |
330 | ipc_space_t space, |
331 | mach_msg_option_t option); | |
1c79356b | 332 | |
1c79356b A |
333 | /* Copyout the header and body to a user message */ |
334 | extern mach_msg_return_t ipc_kmsg_copyout( | |
0a7de745 A |
335 | ipc_kmsg_t kmsg, |
336 | ipc_space_t space, | |
337 | vm_map_t map, | |
338 | mach_msg_body_t *slist, | |
339 | mach_msg_option_t option); | |
1c79356b A |
340 | |
341 | /* Copyout port rights and out-of-line memory from the body of a message */ | |
342 | extern mach_msg_return_t ipc_kmsg_copyout_body( | |
0a7de745 A |
343 | ipc_kmsg_t kmsg, |
344 | ipc_space_t space, | |
345 | vm_map_t map, | |
cb323159 | 346 | mach_msg_option_t option, |
0a7de745 | 347 | mach_msg_body_t *slist); |
1c79356b A |
348 | |
349 | /* Copyout port rights and out-of-line memory to a user message, | |
0a7de745 | 350 | * not reversing the ports in the header */ |
1c79356b | 351 | extern mach_msg_return_t ipc_kmsg_copyout_pseudo( |
0a7de745 A |
352 | ipc_kmsg_t kmsg, |
353 | ipc_space_t space, | |
354 | vm_map_t map, | |
355 | mach_msg_body_t *slist); | |
1c79356b | 356 | |
91447636 A |
357 | /* Compute size of message as copied out to the specified space/map */ |
358 | extern mach_msg_size_t ipc_kmsg_copyout_size( | |
0a7de745 A |
359 | ipc_kmsg_t kmsg, |
360 | vm_map_t map); | |
91447636 | 361 | |
1c79356b | 362 | /* Copyout the destination port in the message */ |
0a7de745 A |
363 | extern void ipc_kmsg_copyout_dest( |
364 | ipc_kmsg_t kmsg, | |
365 | ipc_space_t space); | |
1c79356b A |
366 | |
367 | /* kernel's version of ipc_kmsg_copyout_dest */ | |
368 | extern void ipc_kmsg_copyout_to_kernel( | |
0a7de745 A |
369 | ipc_kmsg_t kmsg, |
370 | ipc_space_t space); | |
1c79356b | 371 | |
b0d623f7 A |
372 | #if IKM_SUPPORT_LEGACY |
373 | extern void ipc_kmsg_copyout_to_kernel_legacy( | |
0a7de745 A |
374 | ipc_kmsg_t kmsg, |
375 | ipc_space_t space); | |
b0d623f7 A |
376 | #endif |
377 | ||
316670eb | 378 | extern mach_msg_trailer_size_t |
f427ee49 A |
379 | ipc_kmsg_trailer_size(mach_msg_option_t option, thread_t thread); |
380 | extern void | |
0a7de745 A |
381 | ipc_kmsg_add_trailer(ipc_kmsg_t kmsg, ipc_space_t space, |
382 | mach_msg_option_t option, thread_t thread, | |
383 | mach_port_seqno_t seqno, boolean_t minimal_trailer, | |
384 | mach_vm_offset_t context); | |
316670eb | 385 | |
39037602 A |
386 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) |
387 | extern void ipc_kmsg_trace_send(ipc_kmsg_t kmsg, | |
0a7de745 | 388 | mach_msg_option_t option); |
39037602 | 389 | #else |
0a7de745 | 390 | #define ipc_kmsg_trace_send(a, b) do { } while (0) |
39037602 A |
391 | #endif |
392 | ||
cb323159 A |
393 | extern mach_msg_header_t * |
394 | ipc_kmsg_msg_header(ipc_kmsg_t); | |
395 | ||
0a7de745 | 396 | #endif /* _IPC_IPC_KMSG_H_ */ |