FreeBSD/Linux Kernel Cross Reference
sys/ipc/ipc_object.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992,1991,1990,1989 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: ipc_object.h,v $
29 * Revision 2.8 93/11/17 16:59:54 dbg
30 * Added ANSI function prototypes.
31 * [93/09/23 dbg]
32 *
33 * Revision 2.7 92/05/21 17:11:06 jfriedl
34 * Appended 'U' to long constants that would otherwise be signed.
35 * [92/05/16 jfriedl]
36 *
37 * Revision 2.6 91/10/09 16:09:27 af
38 * Added (unconditional) ipc_object_print declaration.
39 * [91/09/02 rpd]
40 *
41 * Revision 2.5 91/05/14 16:35:04 mrt
42 * Correcting copyright
43 *
44 * Revision 2.4 91/02/05 17:22:53 mrt
45 * Changed to new Mach copyright
46 * [91/02/01 15:49:25 mrt]
47 *
48 * Revision 2.3 90/11/05 14:29:21 rpd
49 * Removed ipc_object_reference_macro, ipc_object_release_macro.
50 * Created new io_reference, io_release macros.
51 * [90/10/29 rpd]
52 *
53 * Revision 2.2 90/06/02 14:51:04 rpd
54 * Created for new IPC.
55 * [90/03/26 21:00:05 rpd]
56 *
57 */
58 /*
59 * File: ipc/ipc_object.h
60 * Author: Rich Draves
61 * Date: 1989
62 *
63 * Definitions for IPC objects, for which tasks have capabilities.
64 */
65
66 #ifndef _IPC_IPC_OBJECT_H_
67 #define _IPC_IPC_OBJECT_H_
68
69 #include <mach_ipc_compat.h>
70
71 #include <mach/kern_return.h>
72 #include <mach/message.h>
73 #include <kern/lock.h>
74 #include <kern/macro_help.h>
75 #include <kern/zalloc.h>
76 #include <ipc/ipc_types.h> /* ipc_space_t */
77
78 typedef unsigned int ipc_object_refs_t;
79 typedef unsigned int ipc_object_bits_t;
80 typedef unsigned int ipc_object_type_t;
81
82 typedef struct ipc_object {
83 decl_simple_lock_data(,io_lock_data)
84 ipc_object_refs_t io_references;
85 ipc_object_bits_t io_bits;
86 } *ipc_object_t;
87
88 #define IO_NULL ((ipc_object_t) 0)
89 #define IO_DEAD ((ipc_object_t) -1)
90
91 #define IO_VALID(io) (((io) != IO_NULL) && ((io) != IO_DEAD))
92
93 #define IO_BITS_KOTYPE 0x0000ffff /* used by the object */
94 #define IO_BITS_OTYPE 0x7fff0000 /* determines a zone */
95 #define IO_BITS_ACTIVE 0x80000000U /* is object alive? */
96
97 #define io_active(io) ((int)(io)->io_bits < 0) /* hack */
98
99 #define io_otype(io) (((io)->io_bits & IO_BITS_OTYPE) >> 16)
100 #define io_kotype(io) ((io)->io_bits & IO_BITS_KOTYPE)
101
102 #define io_makebits(active, otype, kotype) \
103 (((active) ? IO_BITS_ACTIVE : 0) | ((otype) << 16) | (kotype))
104
105 #define IOT_PORT 0
106 #define IOT_PORT_SET 1
107 #define IOT_NUMBER 2 /* number of types used */
108
109 extern zone_t ipc_object_zones[IOT_NUMBER];
110
111 #define io_alloc(otype) \
112 ((ipc_object_t) zalloc(ipc_object_zones[(otype)]))
113
114 #define io_free(otype, io) \
115 zfree(ipc_object_zones[(otype)], (vm_offset_t) (io))
116
117 #define io_lock_init(io) simple_lock_init(&(io)->io_lock_data)
118 #define io_lock(io) simple_lock(&(io)->io_lock_data)
119 #define io_lock_try(io) simple_lock_try(&(io)->io_lock_data)
120 #define io_unlock(io) simple_unlock(&(io)->io_lock_data)
121
122 #define io_check_unlock(io) \
123 MACRO_BEGIN \
124 ipc_object_refs_t _refs = (io)->io_references; \
125 \
126 io_unlock(io); \
127 if (_refs == 0) \
128 io_free(io_otype(io), io); \
129 MACRO_END
130
131 #define io_reference(io) \
132 MACRO_BEGIN \
133 (io)->io_references++; \
134 MACRO_END
135
136 #define io_release(io) \
137 MACRO_BEGIN \
138 (io)->io_references--; \
139 MACRO_END
140
141 extern void
142 ipc_object_reference(ipc_object_t);
143
144 extern void
145 ipc_object_release(ipc_object_t);
146
147 extern kern_return_t
148 ipc_object_translate(
149 ipc_space_t space,
150 mach_port_t name,
151 mach_port_right_t right,
152 ipc_object_t *objectp);
153
154 extern kern_return_t
155 ipc_object_alloc_dead(
156 ipc_space_t space,
157 mach_port_t *namep);
158
159 extern kern_return_t
160 ipc_object_alloc_dead_name(
161 ipc_space_t space,
162 mach_port_t name);
163
164 extern kern_return_t
165 ipc_object_alloc(
166 ipc_space_t space,
167 ipc_object_type_t otype,
168 mach_port_type_t type,
169 mach_port_urefs_t urefs,
170 mach_port_t *namep,
171 ipc_object_t *objectp);
172
173 extern kern_return_t
174 ipc_object_alloc_name(
175 ipc_space_t space,
176 ipc_object_type_t otype,
177 mach_port_type_t type,
178 mach_port_urefs_t urefs,
179 mach_port_t name,
180 ipc_object_t *objectp);
181
182 extern mach_msg_type_name_t
183 ipc_object_copyin_type(mach_msg_type_name_t);
184
185 extern kern_return_t
186 ipc_object_copyin(
187 ipc_space_t space,
188 mach_port_t name,
189 mach_msg_type_name_t msgt_name,
190 ipc_object_t *objectp);
191
192 extern void
193 ipc_object_copyin_from_kernel(
194 ipc_object_t object,
195 mach_msg_type_name_t msgt_name);
196
197 extern void
198 ipc_object_destroy(
199 ipc_object_t object,
200 mach_msg_type_name_t msgt_name);
201
202 extern kern_return_t
203 ipc_object_copyout(
204 ipc_space_t space,
205 ipc_object_t object,
206 mach_msg_type_name_t msgt_name,
207 boolean_t overflow,
208 mach_port_t *namep);
209
210 extern kern_return_t
211 ipc_object_copyout_name(
212 ipc_space_t space,
213 ipc_object_t object,
214 mach_msg_type_name_t msgt_name,
215 boolean_t overflow,
216 mach_port_t name);
217
218 extern void
219 ipc_object_copyout_dest(
220 ipc_space_t space,
221 ipc_object_t object,
222 mach_msg_type_name_t msgt_name,
223 mach_port_t *namep);
224
225 extern kern_return_t
226 ipc_object_rename(
227 ipc_space_t space,
228 mach_port_t oname,
229 mach_port_t nname);
230
231 #if MACH_IPC_COMPAT
232
233 extern mach_msg_type_name_t
234 ipc_object_copyout_type_compat(mach_msg_type_name_t);
235
236 extern kern_return_t
237 ipc_object_copyin_compat(ipc_space_t, mach_port_t,
238 mach_msg_type_name_t, boolean_t,
239 ipc_object_t *);
240
241 extern kern_return_t
242 ipc_object_copyin_header(ipc_space_t, mach_port_t,
243 ipc_object_t *, mach_msg_type_name_t *);
244
245 extern kern_return_t
246 ipc_object_copyout_compat(ipc_space_t, ipc_object_t,
247 mach_msg_type_name_t, mach_port_t *);
248
249 extern kern_return_t
250 ipc_object_copyout_name_compat(ipc_space_t, ipc_object_t,
251 mach_msg_type_name_t, mach_port_t);
252
253 #endif /* MACH_IPC_COMPAT */
254
255 extern void
256 ipc_object_print(ipc_object_t);
257
258 #endif /* _IPC_IPC_OBJECT_H_ */
Cache object: 53194932996fd1dd665183e565e339d4
|