1/*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
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.
41 *
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.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
49 *  School of Computer Science
50 *  Carnegie Mellon University
51 *  Pittsburgh PA 15213-3890
52 *
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_table.h
60 *	Author:	Rich Draves
61 *	Date:	1989
62 *
63 *	Definitions for tables, used for IPC capabilities (ipc_entry_t)
64 *	and dead-name requests (ipc_port_request_t).
65 */
66
67#ifndef	_IPC_IPC_TABLE_H_
68#define	_IPC_IPC_TABLE_H_
69
70#include <mach/mach_types.h>
71#include <mach/boolean.h>
72#include <mach/vm_param.h>
73
74#include <ipc/ipc_types.h>
75
76/*
77 *	The is_table_next field of an ipc_space_t points to
78 *	an ipc_table_size structure.  These structures must
79 *	be elements of an array, ipc_table_entries.
80 *
81 *	The array must end with two elements with the same its_size value.
82 *	Except for the terminating element, the its_size values must
83 *	be strictly increasing.  The largest (last) its_size value
84 *	must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
85 *	This ensures that
86 *		1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
87 *		in the table, so ipc_entry_get won't allocate it.
88 *		2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
89 *		won't ever overflow.
90 *
91 *
92 *	The ipr_size field of the first element in a table of
93 *	dead-name requests (ipc_port_request_t) points to the
94 *	ipc_table_size structure.  The structures must be elements
95 *	of ipc_table_dnrequests.  ipc_table_dnrequests must end
96 *	with an element with zero its_size, and except for this last
97 *	element, the its_size values must be strictly increasing.
98 *
99 *	The is_table_next field points to the ipc_table_size structure
100 *	for the next larger size of table, not the one currently in use.
101 *	The ipr_size field points to the currently used ipc_table_size.
102 */
103
104struct ipc_table_size {
105	ipc_table_elems_t its_size;	/* number of elements in table */
106};
107
108extern ipc_table_size_t ipc_table_entries;
109extern ipc_table_size_t ipc_table_requests;
110
111/* Initialize IPC capabilities table storage */
112extern void ipc_table_init(void);
113
114/*
115 *	Note that ipc_table_alloc and ipc_table_free
116 *	potentially use the VM system.  Hence simple locks can't
117 *	be held across them.
118 */
119
120/* Allocate a table */
121extern void * ipc_table_alloc(
122	vm_size_t	size);
123
124/* Free a table */
125extern void ipc_table_free(
126	vm_size_t	size,
127	void *		table);
128
129#define	it_entries_alloc(its)						\
130	((ipc_entry_t)							\
131	 ipc_table_alloc((its)->its_size * sizeof(struct ipc_entry)))
132
133#define	it_entries_free(its, table)					\
134	ipc_table_free((its)->its_size * sizeof(struct ipc_entry),	\
135		       (void *)(table))
136
137
138#define	it_requests_alloc(its)						\
139	((ipc_port_request_t)						\
140	 ipc_table_alloc((its)->its_size *				\
141			 sizeof(struct ipc_port_request)))
142
143#define	it_requests_free(its, table)					\
144	ipc_table_free((its)->its_size *				\
145		       sizeof(struct ipc_port_request),			\
146		       (void *)(table))
147
148#endif	/* _IPC_IPC_TABLE_H_ */
149