xref: /trueos/sys/sys/mach/ipc/ipc_entry.h (revision 16d1bdc48d4af6c24d88395d77ebe359f763877c)
1 /*
2  * Copyright 1991-1998 by Open Software Foundation, Inc.
3  *              All Rights Reserved
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both the copyright notice and this permission notice appear in
9  * supporting documentation.
10  *
11  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 /*
22  * MkLinux
23  */
24 /* CMU_HIST */
25 /*
26  * Revision 2.5  91/05/14  16:31:54  mrt
27  * 	Correcting copyright
28  *
29  * Revision 2.4  91/02/05  17:21:24  mrt
30  * 	Changed to new Mach copyright
31  * 	[91/02/01  15:44:29  mrt]
32  *
33  * Revision 2.3  91/01/08  15:13:06  rpd
34  * 	Removed MACH_IPC_GENNOS, IE_BITS_UNUSEDC, IE_BITS_UNUSEDG.
35  * 	[90/11/08            rpd]
36  *
37  * Revision 2.2  90/06/02  14:49:41  rpd
38  * 	Created for new IPC.
39  * 	[90/03/26  20:54:40  rpd]
40  *
41  */
42 /* CMU_ENDHIST */
43 /*
44  * Mach Operating System
45  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
46  * All Rights Reserved.
47  *
48  * Permission to use, copy, modify and distribute this software and its
49  * documentation is hereby granted, provided that both the copyright
50  * notice and this permission notice appear in all copies of the
51  * software, derivative works or modified versions, and any portions
52  * thereof, and that both notices appear in supporting documentation.
53  *
54  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
55  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
56  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
57  *
58  * Carnegie Mellon requests users of this software to return to
59  *
60  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
61  *  School of Computer Science
62  *  Carnegie Mellon University
63  *  Pittsburgh PA 15213-3890
64  *
65  * any improvements or extensions that they make and grant Carnegie Mellon
66  * the rights to redistribute these changes.
67  */
68 /*
69  */
70 /*
71  *	File:	ipc/ipc_entry.h
72  *	Author:	Rich Draves
73  *	Date:	1989
74  *
75  *	Definitions for translation entries, which represent
76  *	tasks' capabilities for ports and port sets.
77  */
78 
79 #ifndef	_IPC_IPC_ENTRY_H_
80 #define _IPC_IPC_ENTRY_H_
81 
82 #include <sys/mach/mach_types.h>
83 #include <sys/mach/port.h>
84 #include <sys/mach/kern_return.h>
85 #include <vm/uma.h>
86 #include <sys/mach/port.h>
87 #include <sys/mach/ipc/ipc_table.h>
88 #include <sys/mach/ipc/ipc_types.h>
89 #include <sys/mach/ipc/ipc_object.h>
90 
91 /*
92  *	Spaces hold capabilities for ipc_object_t's (ports and port sets).
93  *	Each ipc_entry_t records a capability.  Most capabilities have
94  *	small names, and the entries are elements of a table.
95  *	Capabilities can have large names, and a splay tree holds
96  *	those entries.  The cutoff point between the table and the tree
97  *	is adjusted dynamically to minimize memory consumption.
98  *
99  *	The ie_index field of entries in the table implements
100  *	a ordered hash table with open addressing and linear probing.
101  *	This hash table converts (space, object) -> name.
102  *	It is used independently of the other fields.
103  *
104  *	Free (unallocated) entries in the table have null ie_object
105  *	fields.  The ie_bits field is zero except for IE_BITS_GEN.
106  *	The ie_next (ie_request) field links free entries into a free list.
107  *
108  *	The first entry in the table (index 0) is always free.
109  *	It is used as the head of the free list.
110  */
111 
112 typedef natural_t ipc_entry_bits_t;
113 typedef ipc_table_elems_t ipc_entry_num_t;	/* number of entries */
114 
115 typedef struct ipc_entry {
116 	ipc_entry_bits_t ie_bits;
117 	mach_port_name_t ie_name;
118 	struct ipc_space *ie_space;
119 	struct file		*ie_fp;
120 	struct ipc_object *ie_object;
121 	struct ipc_entry *ie_link;
122 	LIST_ENTRY(ipc_entry) ie_space_link;
123 	union {
124 		mach_port_index_t next;
125 		ipc_table_index_t /* XXX ipc_port_request_index_t */ request;
126 	} index;
127 	union {
128 		mach_port_index_t table;
129 		struct ipc_tree_entry *tree;
130 	} hash;
131 } *ipc_entry_t;
132 
133 #define	IE_NULL		((ipc_entry_t) 0)
134 
135 #define	ie_request	index.request
136 #define	ie_next		index.next
137 #define	ie_index	hash.table
138 
139 #define	IE_BITS_UREFS_MASK	0x0000ffff	/* 16 bits of user-reference */
140 #define	IE_BITS_UREFS(bits)	((bits) & IE_BITS_UREFS_MASK)
141 
142 #define	IE_BITS_TYPE_MASK	0x001f0000	/* 5 bits of capability type */
143 #define	IE_BITS_TYPE(bits)	((bits) & IE_BITS_TYPE_MASK)
144 
145 #define	IE_BITS_COLLISION	0x00800000	/* 1 bit for collisions */
146 
147 
148 #ifndef NO_PORT_GEN
149 #define	IE_BITS_GEN_MASK	0xff000000	/* 8 bits for generation */
150 #define	IE_BITS_GEN(bits)	((bits) & IE_BITS_GEN_MASK)
151 #define	IE_BITS_GEN_ONE		0x04000000	/* low bit of generation */
152 #define IE_BITS_NEW_GEN(old)	(((old) + IE_BITS_GEN_ONE) & IE_BITS_GEN_MASK)
153 #else
154 #define	IE_BITS_GEN_MASK	0
155 #define	IE_BITS_GEN(bits)	0
156 #define	IE_BITS_GEN_ONE		0
157 #define IE_BITS_NEW_GEN(old)	(old)
158 #endif	/* !USE_PORT_GEN */
159 
160 
161 #define	IE_BITS_RIGHT_MASK	0x007fffff	/* relevant to the right */
162 
163 
164 typedef struct ipc_tree_entry {
165 	struct ipc_entry ite_entry;
166 	mach_port_name_t ite_name;
167 	struct ipc_space *ite_space;
168 	struct ipc_tree_entry *ite_lchild;
169 	struct ipc_tree_entry *ite_rchild;
170 } *ipc_tree_entry_t;
171 
172 #define	ITE_NULL	((ipc_tree_entry_t) 0)
173 
174 #define	ite_bits	ite_entry.ie_bits
175 #define	ite_object	ite_entry.ie_object
176 #define	ite_request	ite_entry.ie_request
177 #define	ite_next	ite_entry.hash.tree
178 
179 extern uma_zone_t ipc_tree_entry_zone;
180 
181 #define ite_alloc()	((ipc_tree_entry_t) uma_zalloc(ipc_tree_entry_zone, M_WAITOK))
182 #define	ite_free(ite)	uma_zfree(ipc_tree_entry_zone, (ite))
183 
184 /*
185  * Exported interfaces
186  */
187 
188 /* Search for entry in a space by name */
189 extern ipc_entry_t ipc_entry_lookup(
190 	ipc_space_t	space,
191 	mach_port_name_t	name);
192 
193 /* release a reference to an entry */
194 void ipc_entry_release(
195 	ipc_entry_t entry);
196 
197 /* Allocate an entry in a space */
198 extern kern_return_t ipc_entry_get(
199 	ipc_space_t	space,
200 	boolean_t	is_send_once,
201 	mach_port_name_t	*namep,
202 	ipc_entry_t	*entryp);
203 
204 /* Allocate an entry in a space, growing the space if necessary */
205 extern kern_return_t ipc_entry_alloc(
206 	ipc_space_t	space,
207 	boolean_t	is_send_once,
208 	mach_port_name_t	*namep,
209 	ipc_entry_t	*entryp);
210 
211 /* Allocate/find an entry in a space with a specific name */
212 extern kern_return_t ipc_entry_alloc_name(
213 	ipc_space_t	space,
214 	mach_port_name_t	name,
215 	ipc_entry_t	*entryp);
216 
217 /* Deallocate an entry from a space */
218 extern void ipc_entry_dealloc(
219 	ipc_space_t	space,
220 	mach_port_name_t	name,
221 	ipc_entry_t	entry);
222 
223 extern int ipc_entry_refs(
224 	ipc_entry_t entry);
225 
226 extern void ipc_entry_add_refs(
227 	ipc_entry_t entry, int delta);
228 
229 extern void ipc_entry_hold(
230 	ipc_entry_t entry);
231 
232 extern void ipc_entry_release(
233 	ipc_entry_t entry);
234 
235 kern_return_t ipc_entry_file_to_port(
236 	ipc_space_t space,
237 	mach_port_name_t name,
238 	ipc_object_t *objectp);
239 
240 kern_return_t ipc_entry_port_to_file(
241 	ipc_space_t space,
242 	mach_port_name_t *namep,
243 	ipc_object_t object);
244 
245 void ipc_entry_close(
246 	ipc_space_t space __unused,
247 	mach_port_name_t name);
248 
249 
250 #endif	/* _IPC_IPC_ENTRY_H_ */
251