FreeBSD/Linux Kernel Cross Reference
sys/ipc/ipc_space.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993-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_space.h,v $
29 * Revision 2.8 93/11/17 17:02:07 dbg
30 * Moved declaration of ipc_space_t to ipc/ipc_types.h. Added ANSI
31 * function prototypes.
32 * [93/03/30 dbg]
33 *
34 * Revision 2.7 91/06/17 15:46:29 jsb
35 * Renamed NORMA conditionals.
36 * [91/06/17 10:45:36 jsb]
37 *
38 * Revision 2.6 91/05/14 16:36:57 mrt
39 * Correcting copyright
40 *
41 * Revision 2.5 91/03/16 14:48:45 rpd
42 * Added is_growing.
43 * [91/03/04 rpd]
44 *
45 * Revision 2.4 91/02/05 17:23:48 mrt
46 * Changed to new Mach copyright
47 * [91/02/01 15:51:32 mrt]
48 *
49 * Revision 2.3 90/09/28 16:55:23 jsb
50 * Added NORMA_IPC support.
51 * [90/09/28 14:04:12 jsb]
52 *
53 * Revision 2.2 90/06/02 14:51:43 rpd
54 * Created for new IPC.
55 * [90/03/26 21:03:27 rpd]
56 *
57 */
58 /*
59 * File: ipc/ipc_space.h
60 * Author: Rich Draves
61 * Date: 1989
62 *
63 * Definitions for IPC spaces of capabilities.
64 */
65
66 #ifndef _IPC_IPC_SPACE_H_
67 #define _IPC_IPC_SPACE_H_
68
69 #include <mach_ipc_compat.h>
70 #include <norma_ipc.h>
71
72 #include <mach/boolean.h>
73 #include <mach/kern_return.h>
74 #include <kern/macro_help.h>
75 #include <kern/lock.h>
76 #include <kern/zalloc.h>
77 #include <ipc/ipc_types.h>
78 #include <ipc/ipc_entry.h>
79 #include <ipc/ipc_splay.h>
80
81 /*
82 * Every task has a space of IPC capabilities.
83 * IPC operations like send and receive use this space.
84 * IPC kernel calls manipulate the space of the target task.
85 *
86 * Every space has a non-NULL is_table with is_table_size entries.
87 * A space may have a NULL is_tree. is_tree_small records the
88 * number of entries in the tree that, if the table were to grow
89 * to the next larger size, would move from the tree to the table.
90 *
91 * is_growing marks when the table is in the process of growing.
92 * When the table is growing, it can't be freed or grown by another
93 * thread, because of krealloc/kmem_realloc's requirements.
94 */
95
96 typedef unsigned int ipc_space_refs_t;
97
98 struct ipc_space {
99 decl_simple_lock_data(,is_ref_lock_data)
100 ipc_space_refs_t is_references;
101
102 decl_simple_lock_data(,is_lock_data)
103 boolean_t is_active; /* is the space alive? */
104 boolean_t is_growing; /* is the space growing? */
105 ipc_entry_t is_table; /* an array of entries */
106 ipc_entry_num_t is_table_size; /* current size of table */
107 struct ipc_table_size *is_table_next; /* info for larger table */
108 struct ipc_splay_tree is_tree; /* a splay tree of entries */
109 ipc_entry_num_t is_tree_total; /* number of entries in the tree */
110 ipc_entry_num_t is_tree_small; /* # of small entries in the tree */
111 ipc_entry_num_t is_tree_hash; /* # of hashed entries in the tree */
112
113 #if MACH_IPC_COMPAT
114 struct ipc_port *is_notify; /* notification port */
115 #endif /* MACH_IPC_COMPAT */
116 };
117
118 extern zone_t ipc_space_zone;
119
120 #define is_alloc() ((ipc_space_t) zalloc(ipc_space_zone))
121 #define is_free(is) zfree(ipc_space_zone, (vm_offset_t) (is))
122
123 extern ipc_space_t ipc_space_kernel;
124 extern ipc_space_t ipc_space_reply;
125 #if NORMA_IPC
126 extern ipc_space_t ipc_space_remote;
127 #endif /* NORMA_IPC */
128
129 #define is_ref_lock_init(is) simple_lock_init(&(is)->is_ref_lock_data)
130
131 #define ipc_space_reference_macro(is) \
132 MACRO_BEGIN \
133 simple_lock(&(is)->is_ref_lock_data); \
134 assert((is)->is_references > 0); \
135 (is)->is_references++; \
136 simple_unlock(&(is)->is_ref_lock_data); \
137 MACRO_END
138
139 #define ipc_space_release_macro(is) \
140 MACRO_BEGIN \
141 ipc_space_refs_t _refs; \
142 \
143 simple_lock(&(is)->is_ref_lock_data); \
144 assert((is)->is_references > 0); \
145 _refs = --(is)->is_references; \
146 simple_unlock(&(is)->is_ref_lock_data); \
147 \
148 if (_refs == 0) \
149 is_free(is); \
150 MACRO_END
151
152 #define is_lock_init(is) simple_lock_init(&(is)->is_lock_data)
153
154 #define is_read_lock(is) simple_lock(&(is)->is_lock_data)
155 #define is_read_unlock(is) simple_unlock(&(is)->is_lock_data)
156
157 #define is_write_lock(is) simple_lock(&(is)->is_lock_data)
158 #define is_write_lock_try(is) simple_lock_try(&(is)->is_lock_data)
159 #define is_write_unlock(is) simple_unlock(&(is)->is_lock_data)
160
161 #define is_write_to_read_lock(is)
162
163 extern void ipc_space_reference(ipc_space_t space);
164 extern void ipc_space_release(ipc_space_t space);
165
166 #define is_reference(is) ipc_space_reference(is)
167 #define is_release(is) ipc_space_release(is)
168
169 extern kern_return_t
170 ipc_space_create(ipc_table_size_t, ipc_space_t *);
171
172 extern kern_return_t
173 ipc_space_create_special(ipc_space_t *);
174
175 extern void
176 ipc_space_destroy(ipc_space_t);
177
178 #if MACH_IPC_COMPAT
179
180 /*
181 * Routine: ipc_space_make_notify
182 * Purpose:
183 * Given a space, return a send right for a notification.
184 * May return IP_NULL/IP_DEAD.
185 * Conditions:
186 * The space is locked (read or write) and active.
187 *
188 * ipc_port_t
189 * ipc_space_make_notify(space)
190 * ipc_space_t space;
191 */
192
193 #define ipc_space_make_notify(space) \
194 ipc_port_copy_send(space->is_notify)
195
196 #endif /* MACH_IPC_COMPAT */
197
198 #endif /* _IPC_IPC_SPACE_H_ */
Cache object: a9636c23e46abf0b2cf25056a8e8e4fd
|