2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: ipc/ipc_entry.h
57 * Definitions for translation entries, which represent
58 * tasks' capabilities for ports and port sets.
61 #ifndef _IPC_IPC_ENTRY_H_
62 #define _IPC_IPC_ENTRY_H_
64 #include <mach/mach_types.h>
65 #include <mach/port.h>
66 #include <mach/kern_return.h>
68 #include <kern/kern_types.h>
69 #include <kern/zalloc.h>
71 #include <ipc/ipc_types.h>
74 * Spaces hold capabilities for ipc_object_t's.
75 * Each ipc_entry_t records a capability. Most capabilities have
76 * small names, and the entries are elements of a table.
77 * Capabilities can have large names, and a splay tree holds
78 * those entries. The cutoff point between the table and the tree
79 * is adjusted dynamically to minimize memory consumption.
81 * The ie_index field of entries in the table implements
82 * a ordered hash table with open addressing and linear probing.
83 * This hash table converts (space, object) -> name.
84 * It is used independently of the other fields.
86 * Free (unallocated) entries in the table have null ie_object
87 * fields. The ie_bits field is zero except for IE_BITS_GEN.
88 * The ie_next (ie_request) field links free entries into a free list.
90 * The first entry in the table (index 0) is always free.
91 * It is used as the head of the free list.
95 struct ipc_object
*ie_object
;
96 ipc_entry_bits_t ie_bits
;
98 mach_port_index_t next
; /* next in freelist, or... */
99 ipc_table_index_t request
; /* dead name request notify */
102 mach_port_index_t table
;
103 struct ipc_tree_entry
*tree
;
107 #define ie_request index.request
108 #define ie_next index.next
109 #define ie_index hash.table
111 #define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
112 #define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
114 #define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
115 #define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
117 #define IE_BITS_COLLISION 0x00800000 /* 1 bit for collisions */
121 #define IE_BITS_GEN_MASK 0xff000000 /* 8 bits for generation */
122 #define IE_BITS_GEN(bits) ((bits) & IE_BITS_GEN_MASK)
123 #define IE_BITS_GEN_ONE 0x04000000 /* low bit of generation */
124 #define IE_BITS_NEW_GEN(old) (((old) + IE_BITS_GEN_ONE) & IE_BITS_GEN_MASK)
126 #define IE_BITS_GEN_MASK 0
127 #define IE_BITS_GEN(bits) 0
128 #define IE_BITS_GEN_ONE 0
129 #define IE_BITS_NEW_GEN(old) (old)
130 #endif /* !USE_PORT_GEN */
133 #define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
135 struct ipc_tree_entry
{
136 struct ipc_entry ite_entry
;
137 mach_port_name_t ite_name
;
138 struct ipc_space
*ite_space
;
139 struct ipc_tree_entry
*ite_lchild
;
140 struct ipc_tree_entry
*ite_rchild
;
143 #define ite_bits ite_entry.ie_bits
144 #define ite_object ite_entry.ie_object
145 #define ite_request ite_entry.ie_request
146 #define ite_next ite_entry.hash.tree
148 extern zone_t ipc_tree_entry_zone
;
150 #define ite_alloc() ((ipc_tree_entry_t) zalloc(ipc_tree_entry_zone))
151 #define ite_free(ite) zfree(ipc_tree_entry_zone, (ite))
154 * Exported interfaces
157 /* Search for entry in a space by name */
158 extern ipc_entry_t
ipc_entry_lookup(
160 mach_port_name_t name
);
162 /* Allocate an entry in a space */
163 extern kern_return_t
ipc_entry_get(
165 mach_port_name_t
*namep
,
166 ipc_entry_t
*entryp
);
168 /* Allocate an entry in a space, growing the space if necessary */
169 extern kern_return_t
ipc_entry_alloc(
171 mach_port_name_t
*namep
,
172 ipc_entry_t
*entryp
);
174 /* Allocate/find an entry in a space with a specific name */
175 extern kern_return_t
ipc_entry_alloc_name(
177 mach_port_name_t name
,
178 ipc_entry_t
*entryp
);
180 /* Deallocate an entry from a space */
181 extern void ipc_entry_dealloc(
183 mach_port_name_t name
,
186 /* Grow the table in a space */
187 extern kern_return_t
ipc_entry_grow_table(
189 ipc_table_elems_t target_size
);
191 #endif /* _IPC_IPC_ENTRY_H_ */