|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
4: * Copyright (c) 1993,1994 The University of Utah and
5: * the Computer Systems Laboratory (CSL).
6: * All rights reserved.
7: *
8: * Permission to use, copy, modify and distribute this software and its
9: * documentation is hereby granted, provided that both the copyright
10: * notice and this permission notice appear in all copies of the
11: * software, derivative works or modified versions, and any portions
12: * thereof, and that both notices appear in supporting documentation.
13: *
14: * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
15: * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
16: * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
17: * THIS SOFTWARE.
18: *
19: * Carnegie Mellon requests users of this software to return to
20: *
21: * Software Distribution Coordinator or [email protected]
22: * School of Computer Science
23: * Carnegie Mellon University
24: * Pittsburgh PA 15213-3890
25: *
26: * any improvements or extensions that they make and grant Carnegie Mellon
27: * the rights to redistribute these changes.
28: */
29: /*
30: */
31: /*
32: * File: ipc/ipc_space.c
33: * Author: Rich Draves
34: * Date: 1989
35: *
36: * Functions to manipulate IPC capability spaces.
37: */
38:
1.1.1.3 root 39: #include <string.h>
1.1 root 40:
41: #include <mach/boolean.h>
42: #include <mach/kern_return.h>
43: #include <mach/port.h>
44: #include <kern/assert.h>
45: #include <kern/sched_prim.h>
1.1.1.3 root 46: #include <kern/slab.h>
1.1 root 47: #include <ipc/port.h>
48: #include <ipc/ipc_entry.h>
49: #include <ipc/ipc_table.h>
50: #include <ipc/ipc_port.h>
51: #include <ipc/ipc_space.h>
52: #include <ipc/ipc_right.h>
53:
54:
55:
1.1.1.3 root 56: struct kmem_cache ipc_space_cache;
1.1 root 57: ipc_space_t ipc_space_kernel;
58: ipc_space_t ipc_space_reply;
59:
60: /*
61: * Routine: ipc_space_reference
62: * Routine: ipc_space_release
63: * Purpose:
64: * Function versions of the IPC space macros.
65: * The "is_" cover macros can be defined to use the
66: * macros or the functions, as desired.
67: */
68:
69: void
70: ipc_space_reference(
71: ipc_space_t space)
72: {
73: ipc_space_reference_macro(space);
74: }
75:
76: void
77: ipc_space_release(
78: ipc_space_t space)
79: {
80: ipc_space_release_macro(space);
81: }
82:
1.1.1.4 ! root 83: /* A place-holder object for the zeroth entry. */
! 84: struct ipc_entry zero_entry;
! 85:
1.1 root 86: /*
87: * Routine: ipc_space_create
88: * Purpose:
89: * Creates a new IPC space.
90: *
91: * The new space has two references, one for the caller
92: * and one because it is active.
93: * Conditions:
94: * Nothing locked. Allocates memory.
95: * Returns:
96: * KERN_SUCCESS Created a space.
97: * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
98: */
99:
100: kern_return_t
101: ipc_space_create(
102: ipc_space_t *spacep)
103: {
104: ipc_space_t space;
105:
106: space = is_alloc();
107: if (space == IS_NULL)
108: return KERN_RESOURCE_SHORTAGE;
109:
110: is_ref_lock_init(space);
111: space->is_references = 2;
112:
113: is_lock_init(space);
114: space->is_active = TRUE;
1.1.1.4 ! root 115:
! 116: rdxtree_init(&space->is_map);
! 117: rdxtree_init(&space->is_reverse_map);
! 118: /* The zeroth entry is reserved. */
! 119: rdxtree_insert(&space->is_map, 0, &zero_entry);
! 120: space->is_size = 1;
! 121: space->is_free_list = NULL;
! 122: space->is_free_list_size = 0;
1.1 root 123:
124: *spacep = space;
125: return KERN_SUCCESS;
126: }
127:
128: /*
129: * Routine: ipc_space_create_special
130: * Purpose:
131: * Create a special space. A special space
132: * doesn't hold rights in the normal way.
133: * Instead it is place-holder for holding
134: * disembodied (naked) receive rights.
135: * See ipc_port_alloc_special/ipc_port_dealloc_special.
136: * Conditions:
137: * Nothing locked.
138: * Returns:
139: * KERN_SUCCESS Created a space.
140: * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
141: */
142:
143: kern_return_t
144: ipc_space_create_special(
145: ipc_space_t *spacep)
146: {
147: ipc_space_t space;
148:
149: space = is_alloc();
150: if (space == IS_NULL)
151: return KERN_RESOURCE_SHORTAGE;
152:
153: is_ref_lock_init(space);
154: space->is_references = 1;
155:
156: is_lock_init(space);
157: space->is_active = FALSE;
158:
159: *spacep = space;
160: return KERN_SUCCESS;
161: }
162:
163: /*
164: * Routine: ipc_space_destroy
165: * Purpose:
166: * Marks the space as dead and cleans up the entries.
167: * Does nothing if the space is already dead.
168: * Conditions:
169: * Nothing locked.
170: */
171:
172: void
173: ipc_space_destroy(
174: ipc_space_t space)
175: {
176: boolean_t active;
177:
178: assert(space != IS_NULL);
179:
180: is_write_lock(space);
181: active = space->is_active;
182: space->is_active = FALSE;
183: is_write_unlock(space);
184:
185: if (!active)
186: return;
187:
1.1.1.4 ! root 188: ipc_entry_t entry;
! 189: struct rdxtree_iter iter;
! 190: rdxtree_for_each(&space->is_map, &iter, entry) {
! 191: if (entry->ie_name == MACH_PORT_NULL)
! 192: continue;
1.1 root 193:
194: mach_port_type_t type = IE_BITS_TYPE(entry->ie_bits);
195:
196: if (type != MACH_PORT_TYPE_NONE) {
197: mach_port_t name =
1.1.1.4 ! root 198: MACH_PORT_MAKEB(entry->ie_name, entry->ie_bits);
1.1 root 199:
200: ipc_right_clean(space, name, entry);
201: }
202:
1.1.1.4 ! root 203: ie_free(entry);
1.1 root 204: }
1.1.1.4 ! root 205: rdxtree_remove_all(&space->is_map);
! 206: rdxtree_remove_all(&space->is_reverse_map);
1.1 root 207:
208: /*
209: * Because the space is now dead,
210: * we must release the "active" reference for it.
211: * Our caller still has his reference.
212: */
213:
214: is_release(space);
215: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.