]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_table.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_table.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * @OSF_COPYRIGHT@
32 */
1c79356b
A
33/*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58/*
59 */
60/*
61 * File: ipc/ipc_table.h
62 * Author: Rich Draves
63 * Date: 1989
64 *
65 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
66 * and dead-name requests (ipc_port_request_t).
67 */
68
69#ifndef _IPC_IPC_TABLE_H_
70#define _IPC_IPC_TABLE_H_
71
91447636 72#include <mach/mach_types.h>
1c79356b
A
73#include <mach/boolean.h>
74#include <mach/vm_param.h>
75
91447636
A
76#include <ipc/ipc_types.h>
77
1c79356b
A
78/*
79 * The is_table_next field of an ipc_space_t points to
80 * an ipc_table_size structure. These structures must
81 * be elements of an array, ipc_table_entries.
82 *
83 * The array must end with two elements with the same its_size value.
84 * Except for the terminating element, the its_size values must
85 * be strictly increasing. The largest (last) its_size value
86 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
87 * This ensures that
88 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
89 * in the table, so ipc_entry_get won't allocate it.
90 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
91 * won't ever overflow.
92 *
93 *
94 * The ipr_size field of the first element in a table of
95 * dead-name requests (ipc_port_request_t) points to the
96 * ipc_table_size structure. The structures must be elements
97 * of ipc_table_dnrequests. ipc_table_dnrequests must end
98 * with an element with zero its_size, and except for this last
99 * element, the its_size values must be strictly increasing.
100 *
101 * The is_table_next field points to the ipc_table_size structure
102 * for the next larger size of table, not the one currently in use.
103 * The ipr_size field points to the currently used ipc_table_size.
104 */
105
91447636 106struct ipc_table_size {
1c79356b 107 ipc_table_elems_t its_size; /* number of elements in table */
91447636 108};
1c79356b
A
109
110extern ipc_table_size_t ipc_table_entries;
111extern ipc_table_size_t ipc_table_dnrequests;
112
113/* Initialize IPC capabilities table storage */
114extern void ipc_table_init(void);
115
116/*
117 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
118 * all potentially use the VM system. Hence simple locks can't
119 * be held across them.
120 *
121 * We can't use a copying realloc, because the realloc happens
122 * with the data unlocked. ipc_table_realloc remaps the data,
123 * so it is OK.
124 */
125
126/* Allocate a table */
91447636 127extern void * ipc_table_alloc(
1c79356b
A
128 vm_size_t size);
129
130/* Reallocate a big table */
91447636 131extern void * ipc_table_realloc(
1c79356b 132 vm_size_t old_size,
91447636 133 void * old_table,
1c79356b
A
134 vm_size_t new_size);
135
136/* Free a table */
137extern void ipc_table_free(
138 vm_size_t size,
91447636 139 void * table);
1c79356b 140
765c9de3
A
141#define it_entries_reallocable(its) \
142 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
143
1c79356b
A
144#define it_entries_alloc(its) \
145 ((ipc_entry_t) \
765c9de3 146 ipc_table_alloc(it_entries_reallocable(its) ? \
91447636 147 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
765c9de3
A
148 (its)->its_size * sizeof(struct ipc_entry) \
149 ))
1c79356b
A
150
151#define it_entries_realloc(its, table, nits) \
152 ((ipc_entry_t) \
153 ipc_table_realloc( \
91447636
A
154 round_page((its)->its_size * sizeof(struct ipc_entry)), \
155 (void *)(table), \
156 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
1c79356b
A
157 ))
158
159#define it_entries_free(its, table) \
765c9de3 160 ipc_table_free(it_entries_reallocable(its) ? \
91447636 161 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
765c9de3 162 (its)->its_size * sizeof(struct ipc_entry), \
91447636 163 (void *)(table) \
1c79356b
A
164 )
165
166#define it_dnrequests_alloc(its) \
167 ((ipc_port_request_t) \
168 ipc_table_alloc((its)->its_size * \
169 sizeof(struct ipc_port_request)))
170
171#define it_dnrequests_free(its, table) \
172 ipc_table_free((its)->its_size * \
173 sizeof(struct ipc_port_request), \
91447636 174 (void *)(table))
1c79356b
A
175
176#endif /* _IPC_IPC_TABLE_H_ */