2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: ipc/ipc_entry.h
63 * Definitions for translation entries, which represent
64 * tasks' capabilities for ports and port sets.
67 #ifndef _IPC_IPC_ENTRY_H_
68 #define _IPC_IPC_ENTRY_H_
70 #include <mach/mach_types.h>
71 #include <mach/port.h>
72 #include <mach/kern_return.h>
74 #include <kern/kern_types.h>
75 #include <kern/zalloc.h>
77 #include <ipc/ipc_types.h>
80 * Spaces hold capabilities for ipc_object_t's.
81 * Each ipc_entry_t records a capability. Most capabilities have
82 * small names, and the entries are elements of a table.
84 * The ie_index field of entries in the table implements
85 * a ordered hash table with open addressing and linear probing.
87 * The ie_dist field holds the distance to the desired spot,
88 * which is used to implement robin-hood hashing.
90 * This hash table converts (space, object) -> name.
91 * It is used independently of the other fields.
93 * Free (unallocated) entries in the table have null ie_object
94 * fields. The ie_bits field is zero except for IE_BITS_GEN.
95 * The ie_next (ie_request) field links free entries into a free list.
97 * The first entry in the table (index 0) is always free.
98 * It is used as the head of the free list.
101 #define IPC_ENTRY_DIST_BITS 12
102 #define IPC_ENTRY_DIST_MAX ((1 << IPC_ENTRY_DIST_BITS) - 1)
103 #define IPC_ENTRY_INDEX_BITS 20
104 #define IPC_ENTRY_INDEX_MAX ((1 << IPC_ENTRY_INDEX_BITS) - 1)
107 struct ipc_object
*ie_object
;
108 ipc_entry_bits_t ie_bits
;
109 uint32_t ie_dist
: IPC_ENTRY_DIST_BITS
;
110 mach_port_index_t ie_index
: IPC_ENTRY_INDEX_BITS
;
112 mach_port_index_t next
; /* next in freelist, or... */
113 ipc_table_index_t request
; /* dead name request notify */
117 #define ie_request index.request
118 #define ie_next index.next
120 #define IE_REQ_NONE 0 /* no request */
122 #define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
123 #define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
125 #define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
126 #define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
128 #define IE_BITS_EXTYPE_MASK 0x00200000 /* 1 bit for extended capability */
131 #define IE_BITS_GEN_MASK 0xff000000 /* 8 bits for generation */
132 #define IE_BITS_GEN(bits) ((bits) & IE_BITS_GEN_MASK)
133 #define IE_BITS_GEN_ONE 0x04000000 /* low bit of generation */
134 #define IE_BITS_ROLL_POS 22 /* LSB pos of generation rollover */
135 #define IE_BITS_ROLL_BITS 2 /* number of generation rollover bits */
136 #define IE_BITS_ROLL_MASK (((1 << IE_BITS_ROLL_BITS) - 1) << IE_BITS_ROLL_POS)
137 #define IE_BITS_ROLL(bits) ((((bits) & IE_BITS_ROLL_MASK) << 8) ^ IE_BITS_GEN_MASK)
140 * Restart a generation counter with the specified bits for the rollover point.
141 * There are 4 different rollover points:
142 * bits rollover period
148 static inline ipc_entry_bits_t
149 ipc_entry_new_rollpoint(
150 ipc_entry_bits_t rollbits
)
152 rollbits
= (rollbits
<< IE_BITS_ROLL_POS
) & IE_BITS_ROLL_MASK
;
153 ipc_entry_bits_t newgen
= IE_BITS_GEN_MASK
+ IE_BITS_GEN_ONE
;
154 return newgen
| rollbits
;
158 * Get the next gencount, modulo the entry's rollover point. If the sum rolls over,
159 * the caller should re-start the generation counter with a different rollpoint.
161 static inline ipc_entry_bits_t
163 ipc_entry_bits_t oldgen
)
165 ipc_entry_bits_t sum
= (oldgen
+ IE_BITS_GEN_ONE
) & IE_BITS_GEN_MASK
;
166 ipc_entry_bits_t roll
= oldgen
& IE_BITS_ROLL_MASK
;
167 ipc_entry_bits_t newgen
= (sum
% IE_BITS_ROLL(oldgen
)) | roll
;
171 /* Determine if a gencount has rolled over or not. */
172 static inline boolean_t
173 ipc_entry_gen_rolled(
174 ipc_entry_bits_t oldgen
,
175 ipc_entry_bits_t newgen
)
177 return (oldgen
& IE_BITS_GEN_MASK
) > (newgen
& IE_BITS_GEN_MASK
);
181 #define IE_BITS_GEN_MASK 0
182 #define IE_BITS_GEN(bits) 0
183 #define IE_BITS_GEN_ONE 0
184 #define IE_BITS_ROLL_POS 0
185 #define IE_BITS_ROLL_MASK 0
186 #define IE_BITS_ROLL(bits) (bits)
188 static inline ipc_entry_bits_t
189 ipc_entry_new_rollpoint(
190 ipc_entry_bits_t rollbits
)
195 static inline ipc_entry_bits_t
197 ipc_entry_bits_t oldgen
)
202 static inline boolean_t
203 ipc_entry_gen_rolled(
204 ipc_entry_bits_t oldgen
,
205 ipc_entry_bits_t newgen
)
210 #endif /* !USE_PORT_GEN */
212 #define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
214 * Exported interfaces
217 /* Search for entry in a space by name */
218 extern ipc_entry_t
ipc_entry_lookup(
220 mach_port_name_t name
);
222 /* Hold a number of entries in a locked space */
223 extern kern_return_t
ipc_entries_hold(
227 /* claim and initialize a held entry in a locked space */
228 extern kern_return_t
ipc_entry_claim(
230 mach_port_name_t
*namep
,
231 ipc_entry_t
*entryp
);
233 /* Allocate an entry in a space */
234 extern kern_return_t
ipc_entry_get(
236 mach_port_name_t
*namep
,
237 ipc_entry_t
*entryp
);
239 /* Allocate an entry in a space, growing the space if necessary */
240 extern kern_return_t
ipc_entry_alloc(
242 mach_port_name_t
*namep
,
243 ipc_entry_t
*entryp
);
245 /* Allocate/find an entry in a space with a specific name */
246 extern kern_return_t
ipc_entry_alloc_name(
248 mach_port_name_t name
,
249 ipc_entry_t
*entryp
);
251 /* Deallocate an entry from a space */
252 extern void ipc_entry_dealloc(
254 mach_port_name_t name
,
257 /* Mark and entry modified in a space */
258 extern void ipc_entry_modified(
260 mach_port_name_t name
,
263 /* Grow the table in a space */
264 extern kern_return_t
ipc_entry_grow_table(
266 ipc_table_elems_t target_size
);
268 /* mask on/off default entry generation bits */
269 extern mach_port_name_t
ipc_entry_name_mask(
270 mach_port_name_t name
);
271 #endif /* _IPC_IPC_ENTRY_H_ */