]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_entry.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_entry.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
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.
35 *
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.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: ipc/ipc_entry.h
54 * Author: Rich Draves
55 * Date: 1989
56 *
57 * Definitions for translation entries, which represent
58 * tasks' capabilities for ports and port sets.
59 */
60
61 #ifndef _IPC_IPC_ENTRY_H_
62 #define _IPC_IPC_ENTRY_H_
63
64 #include <mach/mach_types.h>
65 #include <mach/port.h>
66 #include <mach/kern_return.h>
67
68 #include <kern/kern_types.h>
69 #include <kern/zalloc.h>
70
71 #include <ipc/ipc_types.h>
72
73 /*
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.
80 *
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.
85 *
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.
89 *
90 * The first entry in the table (index 0) is always free.
91 * It is used as the head of the free list.
92 */
93
94 struct ipc_entry {
95 struct ipc_object *ie_object;
96 ipc_entry_bits_t ie_bits;
97 union {
98 mach_port_index_t next; /* next in freelist, or... */
99 ipc_table_index_t request; /* dead name request notify */
100 } index;
101 union {
102 mach_port_index_t table;
103 struct ipc_tree_entry *tree;
104 } hash;
105 };
106
107 #define ie_request index.request
108 #define ie_next index.next
109 #define ie_index hash.table
110
111 #define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
112 #define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
113
114 #define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
115 #define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
116
117 #define IE_BITS_COLLISION 0x00800000 /* 1 bit for collisions */
118
119
120 #ifndef NO_PORT_GEN
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)
125 #else
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 */
131
132
133 #define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
134
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;
141 };
142
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
147
148 extern zone_t ipc_tree_entry_zone;
149
150 #define ite_alloc() ((ipc_tree_entry_t) zalloc(ipc_tree_entry_zone))
151 #define ite_free(ite) zfree(ipc_tree_entry_zone, (ite))
152
153 /*
154 * Exported interfaces
155 */
156
157 /* Search for entry in a space by name */
158 extern ipc_entry_t ipc_entry_lookup(
159 ipc_space_t space,
160 mach_port_name_t name);
161
162 /* Allocate an entry in a space */
163 extern kern_return_t ipc_entry_get(
164 ipc_space_t space,
165 mach_port_name_t *namep,
166 ipc_entry_t *entryp);
167
168 /* Allocate an entry in a space, growing the space if necessary */
169 extern kern_return_t ipc_entry_alloc(
170 ipc_space_t space,
171 mach_port_name_t *namep,
172 ipc_entry_t *entryp);
173
174 /* Allocate/find an entry in a space with a specific name */
175 extern kern_return_t ipc_entry_alloc_name(
176 ipc_space_t space,
177 mach_port_name_t name,
178 ipc_entry_t *entryp);
179
180 /* Deallocate an entry from a space */
181 extern void ipc_entry_dealloc(
182 ipc_space_t space,
183 mach_port_name_t name,
184 ipc_entry_t entry);
185
186 /* Grow the table in a space */
187 extern kern_return_t ipc_entry_grow_table(
188 ipc_space_t space,
189 ipc_table_elems_t target_size);
190
191 #endif /* _IPC_IPC_ENTRY_H_ */