xref: /xnu-8020.140.41/osfmk/ipc/ipc_table.h (revision 27b03b360a988dfd3dfdf34262bb0042026747cc) !
1 /*
2  * Copyright (c) 2000-2004 Apple Computer, 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  [email protected]
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_table.h
60  *	Author:	Rich Draves
61  *	Date:	1989
62  *
63  *	Definitions for tables, used for IPC capabilities (ipc_entry_t)
64  *	and dead-name requests (ipc_port_request_t).
65  */
66 
67 #ifndef _IPC_IPC_TABLE_H_
68 #define _IPC_IPC_TABLE_H_
69 
70 #include <mach/mach_types.h>
71 #include <mach/boolean.h>
72 #include <mach/vm_param.h>
73 #include <kern/kalloc.h>
74 
75 #include <ipc/ipc_types.h>
76 
77 /*
78  *	The is_table_next field of an ipc_space_t points to
79  *	an ipc_table_size structure.  These structures must
80  *	be elements of an array, ipc_table_entries.
81  *
82  *	The array must end with two elements with the same its_size value.
83  *	Except for the terminating element, the its_size values must
84  *	be strictly increasing.  The largest (last) its_size value
85  *	must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
86  *	This ensures that
87  *		1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
88  *		in the table, so ipc_entry_get won't allocate it.
89  *		2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
90  *		won't ever overflow.
91  *
92  *
93  *	The ipr_size field of the first element in a table of
94  *	dead-name requests (ipc_port_request_t) points to the
95  *	ipc_table_size structure.  The structures must be elements
96  *	of ipc_table_dnrequests.  ipc_table_dnrequests must end
97  *	with an element with zero its_size, and except for this last
98  *	element, the its_size values must be strictly increasing.
99  *
100  *	The is_table_next field points to the ipc_table_size structure
101  *	for the next larger size of table, not the one currently in use.
102  *	The ipr_size field points to the currently used ipc_table_size.
103  */
104 
105 struct ipc_table_size {
106 	ipc_table_elems_t its_size;     /* number of elements in table */
107 };
108 
109 extern struct ipc_table_size ipc_table_entries[];
110 extern struct ipc_table_size ipc_table_requests[];
111 KALLOC_TYPE_VAR_DECLARE(kt_var_it_entries);
112 
113 /*
114  *	Note that ipc_table_alloc and ipc_table_free
115  *	potentially use the VM system.  Hence simple locks can't
116  *	be held across them.
117  */
118 
119 #define it_entries_alloc(its)                                              \
120 	(struct ipc_entry *) kalloc_type_var_impl(kt_var_it_entries,           \
121 	    kt_size(0, sizeof(struct ipc_entry), (its)->its_size),             \
122 	    __zone_flags_mix_tag(Z_WAITOK | Z_ZERO, VM_ALLOC_SITE_TAG()), NULL)
123 
124 #define it_entries_free(count, table) ({                                   \
125 	__auto_type __count = (count);                                         \
126 	kfree_type_var_impl(kt_var_it_entries, os_ptr_load_and_erase(table),   \
127 	    kt_size(0, sizeof(struct ipc_entry), __count));                    \
128 })
129 
130 #define it_requests_alloc(its) \
131 	kalloc_type(struct ipc_port_request, (its)->its_size, Z_WAITOK | Z_ZERO)
132 
133 #define it_requests_free(its, table) \
134 	kfree_type(struct ipc_port_request, (its)->its_size, table)
135 
136 extern unsigned int ipc_table_max_entries(void);
137 extern unsigned int ipc_table_max_requests(void);
138 
139 #endif  /* _IPC_IPC_TABLE_H_ */
140