2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: ipc/ipc_entry.h
58 * Definitions for translation entries, which represent
59 * tasks' capabilities for ports and port sets.
62 #ifndef _IPC_IPC_ENTRY_H_
63 #define _IPC_IPC_ENTRY_H_
65 #include <mach/mach_types.h>
66 #include <mach/port.h>
67 #include <mach/kern_return.h>
69 #include <kern/kern_types.h>
70 #include <kern/zalloc.h>
72 #include <ipc/ipc_types.h>
75 * Spaces hold capabilities for ipc_object_t's.
76 * Each ipc_entry_t records a capability. Most capabilities have
77 * small names, and the entries are elements of a table.
78 * Capabilities can have large names, and a splay tree holds
79 * those entries. The cutoff point between the table and the tree
80 * is adjusted dynamically to minimize memory consumption.
82 * The ie_index field of entries in the table implements
83 * a ordered hash table with open addressing and linear probing.
84 * This hash table converts (space, object) -> name.
85 * It is used independently of the other fields.
87 * Free (unallocated) entries in the table have null ie_object
88 * fields. The ie_bits field is zero except for IE_BITS_GEN.
89 * The ie_next (ie_request) field links free entries into a free list.
91 * The first entry in the table (index 0) is always free.
92 * It is used as the head of the free list.
96 struct ipc_object
*ie_object
;
97 ipc_entry_bits_t ie_bits
;
99 mach_port_index_t next
; /* next in freelist, or... */
100 ipc_table_index_t request
; /* dead name request notify */
103 mach_port_index_t table
;
104 struct ipc_tree_entry
*tree
;
108 #define ie_request index.request
109 #define ie_next index.next
110 #define ie_index hash.table
112 #define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
113 #define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
115 #define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
116 #define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
118 #define IE_BITS_COLLISION 0x00800000 /* 1 bit for collisions */
122 #define IE_BITS_GEN_MASK 0xff000000 /* 8 bits for generation */
123 #define IE_BITS_GEN(bits) ((bits) & IE_BITS_GEN_MASK)
124 #define IE_BITS_GEN_ONE 0x04000000 /* low bit of generation */
125 #define IE_BITS_NEW_GEN(old) (((old) + IE_BITS_GEN_ONE) & IE_BITS_GEN_MASK)
127 #define IE_BITS_GEN_MASK 0
128 #define IE_BITS_GEN(bits) 0
129 #define IE_BITS_GEN_ONE 0
130 #define IE_BITS_NEW_GEN(old) (old)
131 #endif /* !USE_PORT_GEN */
134 #define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
136 struct ipc_tree_entry
{
137 struct ipc_entry ite_entry
;
138 mach_port_name_t ite_name
;
139 struct ipc_space
*ite_space
;
140 struct ipc_tree_entry
*ite_lchild
;
141 struct ipc_tree_entry
*ite_rchild
;
144 #define ite_bits ite_entry.ie_bits
145 #define ite_object ite_entry.ie_object
146 #define ite_request ite_entry.ie_request
147 #define ite_next ite_entry.hash.tree
149 extern zone_t ipc_tree_entry_zone
;
151 #define ite_alloc() ((ipc_tree_entry_t) zalloc(ipc_tree_entry_zone))
152 #define ite_free(ite) zfree(ipc_tree_entry_zone, (ite))
155 * Exported interfaces
158 /* Search for entry in a space by name */
159 extern ipc_entry_t
ipc_entry_lookup(
161 mach_port_name_t name
);
163 /* Allocate an entry in a space */
164 extern kern_return_t
ipc_entry_get(
166 mach_port_name_t
*namep
,
167 ipc_entry_t
*entryp
);
169 /* Allocate an entry in a space, growing the space if necessary */
170 extern kern_return_t
ipc_entry_alloc(
172 mach_port_name_t
*namep
,
173 ipc_entry_t
*entryp
);
175 /* Allocate/find an entry in a space with a specific name */
176 extern kern_return_t
ipc_entry_alloc_name(
178 mach_port_name_t name
,
179 ipc_entry_t
*entryp
);
181 /* Deallocate an entry from a space */
182 extern void ipc_entry_dealloc(
184 mach_port_name_t name
,
187 /* Grow the table in a space */
188 extern kern_return_t
ipc_entry_grow_table(
190 ipc_table_elems_t target_size
);
192 #endif /* _IPC_IPC_ENTRY_H_ */