FreeBSD/Linux Kernel Cross Reference
sys/ipc/ipc_object.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 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.7 92/05/21 17:11:06 jfriedl
30 * Appended 'U' to long constants that would otherwise be signed.
31 * [92/05/16 jfriedl]
32 *
33 * Revision 2.6 91/10/09 16:09:27 af
34 * Revision 2.5.2.1 91/09/16 10:15:46 rpd
35 * Added (unconditional) ipc_object_print declaration.
36 * [91/09/02 rpd]
37 *
38 * Revision 2.5.2.1 91/09/16 10:15:46 rpd
39 * Added (unconditional) ipc_object_print declaration.
40 * [91/09/02 rpd]
41 *
42 * Revision 2.5 91/05/14 16:35:04 mrt
43 * Correcting copyright
44 *
45 * Revision 2.4 91/02/05 17:22:53 mrt
46 * Changed to new Mach copyright
47 * [91/02/01 15:49:25 mrt]
48 *
49 * Revision 2.3 90/11/05 14:29:21 rpd
50 * Removed ipc_object_reference_macro, ipc_object_release_macro.
51 * Created new io_reference, io_release macros.
52 * [90/10/29 rpd]
53 *
54 * Revision 2.2 90/06/02 14:51:04 rpd
55 * Created for new IPC.
56 * [90/03/26 21:00:05 rpd]
57 *
58 */
59 /*
60 * File: ipc/ipc_object.h
61 * Author: Rich Draves
62 * Date: 1989
63 *
64 * Definitions for IPC objects, for which tasks have capabilities.
65 */
66
67 #ifndef _IPC_IPC_OBJECT_H_
68 #define _IPC_IPC_OBJECT_H_
69
70 #include <mach_ipc_compat.h>
71
72 #include <mach/kern_return.h>
73 #include <mach/message.h>
74 #include <kern/lock.h>
75 #include <kern/macro_help.h>
76 #include <kern/zalloc.h>
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(/* ipc_space_t, mach_port_t,
149 mach_port_right_t, ipc_object_t * */);
150
151 extern kern_return_t
152 ipc_object_alloc_dead(/* ipc_space_t, mach_port_t * */);
153
154 extern kern_return_t
155 ipc_object_alloc_dead_name(/* ipc_space_t, mach_port_t */);
156
157 extern kern_return_t
158 ipc_object_alloc(/* ipc_space_t, ipc_object_type_t,
159 mach_port_type_t, mach_port_urefs_t,
160 mach_port_t *, ipc_object_t * */);
161
162 extern kern_return_t
163 ipc_object_alloc_name(/* ipc_space_t, ipc_object_type_t,
164 mach_port_type_t, mach_port_urefs_t,
165 mach_port_t, ipc_object_t * */);
166
167 extern mach_msg_type_name_t
168 ipc_object_copyin_type(/* mach_msg_type_name_t */);
169
170 extern kern_return_t
171 ipc_object_copyin(/* ipc_space_t, mach_port_t,
172 mach_msg_type_name_t, ipc_object_t * */);
173
174 extern void
175 ipc_object_copyin_from_kernel(/* ipc_object_t, mach_msg_type_name_t */);
176
177 extern void
178 ipc_object_destroy(/* ipc_object_t, mach_msg_type_name_t */);
179
180 extern kern_return_t
181 ipc_object_copyout(/* ipc_space_t, ipc_object_t,
182 mach_msg_type_name_t, boolean_t, mach_port_t * */);
183
184 extern kern_return_t
185 ipc_object_copyout_name(/* ipc_space_t, ipc_object_t,
186 mach_msg_type_name_t, boolean_t, mach_port_t */);
187
188 extern void
189 ipc_object_copyout_dest(/* ipc_space_t, ipc_object_t,
190 mach_msg_type_name_t, mach_port_t * */);
191
192 extern kern_return_t
193 ipc_object_rename(/* ipc_space_t, mach_port_t, mach_port_t */);
194
195 #if MACH_IPC_COMPAT
196
197 extern mach_msg_type_name_t
198 ipc_object_copyout_type_compat(/* mach_msg_type_name_t */);
199
200 extern kern_return_t
201 ipc_object_copyin_compat(/* ipc_space_t, mach_port_t,
202 mach_msg_type_name_t, boolean_t,
203 ipc_object_t * */);
204
205 extern kern_return_t
206 ipc_object_copyin_header(/* ipc_space_t, mach_port_t,
207 ipc_object_t *, mach_msg_type_name_t * */);
208
209 extern kern_return_t
210 ipc_object_copyout_compat(/* ipc_space_t, ipc_object_t,
211 mach_msg_type_name_t, mach_port_t * */);
212
213 extern kern_return_t
214 ipc_object_copyout_name_compat(/* ipc_space_t, ipc_object_t,
215 mach_msg_type_name_t, mach_port_t */);
216
217 #endif MACH_IPC_COMPAT
218
219 extern void
220 ipc_object_print(/* ipc_object_t */);
221
222 #endif _IPC_IPC_OBJECT_H_
Cache object: 28f5ae6e8dcbf4a224f8e78c8f6469e3
|