]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_entry.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_entry.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
0a7de745 31/*
1c79356b
A
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
0a7de745 35 *
1c79356b
A
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.
0a7de745 41 *
1c79356b
A
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.
0a7de745 45 *
1c79356b 46 * Carnegie Mellon requests users of this software to return to
0a7de745 47 *
1c79356b
A
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
0a7de745 52 *
1c79356b
A
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_entry.h
60 * Author: Rich Draves
61 * Date: 1989
62 *
63 * Definitions for translation entries, which represent
64 * tasks' capabilities for ports and port sets.
65 */
66
0a7de745 67#ifndef _IPC_IPC_ENTRY_H_
1c79356b
A
68#define _IPC_IPC_ENTRY_H_
69
91447636 70#include <mach/mach_types.h>
1c79356b
A
71#include <mach/port.h>
72#include <mach/kern_return.h>
91447636
A
73
74#include <kern/kern_types.h>
1c79356b 75#include <kern/zalloc.h>
91447636 76
1c79356b
A
77#include <ipc/ipc_types.h>
78
79/*
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.
1c79356b
A
83 *
84 * The ie_index field of entries in the table implements
85 * a ordered hash table with open addressing and linear probing.
0a7de745
A
86 *
87 * The ie_dist field holds the distance to the desired spot,
88 * which is used to implement robin-hood hashing.
89 *
1c79356b
A
90 * This hash table converts (space, object) -> name.
91 * It is used independently of the other fields.
92 *
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.
96 *
97 * The first entry in the table (index 0) is always free.
98 * It is used as the head of the free list.
99 */
100
0a7de745
A
101#define IPC_ENTRY_DIST_BITS 12
102#define IPC_ENTRY_DIST_MAX ((1 << IPC_ENTRY_DIST_BITS) - 1)
f427ee49
A
103#ifdef __LP64__
104#define IPC_ENTRY_INDEX_BITS 32
105#define IPC_ENTRY_INDEX_MAX (UINT32_MAX)
106#else
0a7de745
A
107#define IPC_ENTRY_INDEX_BITS 20
108#define IPC_ENTRY_INDEX_MAX ((1 << IPC_ENTRY_INDEX_BITS) - 1)
f427ee49 109#endif
0a7de745 110
91447636 111struct ipc_entry {
f427ee49 112 struct ipc_object *XNU_PTRAUTH_SIGNED_PTR("ipc_entry.ie_object") ie_object;
0a7de745
A
113 ipc_entry_bits_t ie_bits;
114 uint32_t ie_dist : IPC_ENTRY_DIST_BITS;
115 mach_port_index_t ie_index : IPC_ENTRY_INDEX_BITS;
1c79356b 116 union {
0a7de745
A
117 mach_port_index_t next; /* next in freelist, or... */
118 ipc_table_index_t request; /* dead name request notify */
1c79356b 119 } index;
91447636 120};
1c79356b 121
0a7de745
A
122#define ie_request index.request
123#define ie_next index.next
1c79356b 124
0a7de745 125#define IE_REQ_NONE 0 /* no request */
6d2010ae 126
0a7de745
A
127#define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
128#define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
1c79356b 129
0a7de745
A
130#define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
131#define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
1c79356b 132
cb323159
A
133#define IE_BITS_EXTYPE_MASK 0x00200000 /* 1 bit for extended capability */
134
1c79356b 135#ifndef NO_PORT_GEN
0a7de745
A
136#define IE_BITS_GEN_MASK 0xff000000 /* 8 bits for generation */
137#define IE_BITS_GEN(bits) ((bits) & IE_BITS_GEN_MASK)
138#define IE_BITS_GEN_ONE 0x04000000 /* low bit of generation */
139#define IE_BITS_ROLL_POS 22 /* LSB pos of generation rollover */
140#define IE_BITS_ROLL_BITS 2 /* number of generation rollover bits */
141#define IE_BITS_ROLL_MASK (((1 << IE_BITS_ROLL_BITS) - 1) << IE_BITS_ROLL_POS)
142#define IE_BITS_ROLL(bits) ((((bits) & IE_BITS_ROLL_MASK) << 8) ^ IE_BITS_GEN_MASK)
5c9f4661
A
143
144/*
145 * Restart a generation counter with the specified bits for the rollover point.
146 * There are 4 different rollover points:
147 * bits rollover period
148 * 0 0 64
149 * 0 1 48
150 * 1 0 32
151 * 1 1 16
152 */
0a7de745
A
153static inline ipc_entry_bits_t
154ipc_entry_new_rollpoint(
5c9f4661
A
155 ipc_entry_bits_t rollbits)
156{
157 rollbits = (rollbits << IE_BITS_ROLL_POS) & IE_BITS_ROLL_MASK;
158 ipc_entry_bits_t newgen = IE_BITS_GEN_MASK + IE_BITS_GEN_ONE;
0a7de745 159 return newgen | rollbits;
5c9f4661
A
160}
161
162/*
163 * Get the next gencount, modulo the entry's rollover point. If the sum rolls over,
164 * the caller should re-start the generation counter with a different rollpoint.
165 */
0a7de745
A
166static inline ipc_entry_bits_t
167ipc_entry_new_gen(
5c9f4661
A
168 ipc_entry_bits_t oldgen)
169{
170 ipc_entry_bits_t sum = (oldgen + IE_BITS_GEN_ONE) & IE_BITS_GEN_MASK;
171 ipc_entry_bits_t roll = oldgen & IE_BITS_ROLL_MASK;
172 ipc_entry_bits_t newgen = (sum % IE_BITS_ROLL(oldgen)) | roll;
173 return newgen;
174}
175
176/* Determine if a gencount has rolled over or not. */
0a7de745
A
177static inline boolean_t
178ipc_entry_gen_rolled(
5c9f4661
A
179 ipc_entry_bits_t oldgen,
180 ipc_entry_bits_t newgen)
181{
182 return (oldgen & IE_BITS_GEN_MASK) > (newgen & IE_BITS_GEN_MASK);
183}
184
1c79356b 185#else
0a7de745
A
186#define IE_BITS_GEN_MASK 0
187#define IE_BITS_GEN(bits) 0
188#define IE_BITS_GEN_ONE 0
189#define IE_BITS_ROLL_POS 0
190#define IE_BITS_ROLL_MASK 0
191#define IE_BITS_ROLL(bits) (bits)
192
193static inline ipc_entry_bits_t
194ipc_entry_new_rollpoint(
5c9f4661
A
195 ipc_entry_bits_t rollbits)
196{
197 return 0;
198}
199
0a7de745
A
200static inline ipc_entry_bits_t
201ipc_entry_new_gen(
5c9f4661
A
202 ipc_entry_bits_t oldgen)
203{
204 return 0;
205}
206
0a7de745
A
207static inline boolean_t
208ipc_entry_gen_rolled(
5c9f4661
A
209 ipc_entry_bits_t oldgen,
210 ipc_entry_bits_t newgen)
211{
212 return FALSE;
213}
1c79356b 214
0a7de745 215#endif /* !USE_PORT_GEN */
1c79356b 216
0a7de745 217#define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
1c79356b
A
218/*
219 * Exported interfaces
220 */
221
222/* Search for entry in a space by name */
223extern ipc_entry_t ipc_entry_lookup(
0a7de745
A
224 ipc_space_t space,
225 mach_port_name_t name);
1c79356b 226
fe8ab488
A
227/* Hold a number of entries in a locked space */
228extern kern_return_t ipc_entries_hold(
0a7de745
A
229 ipc_space_t space,
230 natural_t count);
fe8ab488
A
231
232/* claim and initialize a held entry in a locked space */
233extern kern_return_t ipc_entry_claim(
0a7de745
A
234 ipc_space_t space,
235 mach_port_name_t *namep,
236 ipc_entry_t *entryp);
fe8ab488 237
1c79356b
A
238/* Allocate an entry in a space, growing the space if necessary */
239extern kern_return_t ipc_entry_alloc(
0a7de745
A
240 ipc_space_t space,
241 mach_port_name_t *namep,
242 ipc_entry_t *entryp);
1c79356b
A
243
244/* Allocate/find an entry in a space with a specific name */
245extern kern_return_t ipc_entry_alloc_name(
0a7de745
A
246 ipc_space_t space,
247 mach_port_name_t name,
248 ipc_entry_t *entryp);
1c79356b
A
249
250/* Deallocate an entry from a space */
251extern void ipc_entry_dealloc(
0a7de745
A
252 ipc_space_t space,
253 mach_port_name_t name,
254 ipc_entry_t entry);
1c79356b 255
316670eb
A
256/* Mark and entry modified in a space */
257extern void ipc_entry_modified(
0a7de745
A
258 ipc_space_t space,
259 mach_port_name_t name,
260 ipc_entry_t entry);
316670eb 261
1c79356b
A
262/* Grow the table in a space */
263extern kern_return_t ipc_entry_grow_table(
0a7de745
A
264 ipc_space_t space,
265 ipc_table_elems_t target_size);
1c79356b 266
39037602
A
267/* mask on/off default entry generation bits */
268extern mach_port_name_t ipc_entry_name_mask(
269 mach_port_name_t name);
0a7de745 270#endif /* _IPC_IPC_ENTRY_H_ */