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:37:52 mrt 27 * Correcting copyright 28 * 29 * Revision 2.4 91/03/16 14:49:01 rpd 30 * Added ipc_table_realloc. 31 * [91/03/04 rpd] 32 * 33 * Revision 2.3 91/02/05 17:24:19 mrt 34 * Changed to new Mach copyright 35 * [91/02/01 15:52:19 mrt] 36 * 37 * Revision 2.2 90/06/02 14:52:02 rpd 38 * Created for new IPC. 39 * [90/03/26 21:04:35 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_table.h 72 * Author: Rich Draves 73 * Date: 1989 74 * 75 * Definitions for tables, used for IPC capabilities (ipc_entry_t) 76 * and dead-name requests (ipc_port_request_t). 77 */ 78 79 #ifndef _IPC_IPC_TABLE_H_ 80 #define _IPC_IPC_TABLE_H_ 81 82 83 /* 84 * The is_table_next field of an ipc_space_t points to 85 * an ipc_table_size structure. These structures must 86 * be elements of an array, ipc_table_entries. 87 * 88 * The array must end with two elements with the same its_size value. 89 * Except for the terminating element, the its_size values must 90 * be strictly increasing. The largest (last) its_size value 91 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD). 92 * This ensures that 93 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index 94 * in the table, so ipc_entry_get won't allocate it. 95 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0) 96 * won't ever overflow. 97 * 98 * 99 * The ipr_size field of the first element in a table of 100 * dead-name requests (ipc_port_request_t) points to the 101 * ipc_table_size structure. The structures must be elements 102 * of ipc_table_dnrequests. ipc_table_dnrequests must end 103 * with an element with zero its_size, and except for this last 104 * element, the its_size values must be strictly increasing. 105 * 106 * The is_table_next field points to the ipc_table_size structure 107 * for the next larger size of table, not the one currently in use. 108 * The ipr_size field points to the currently used ipc_table_size. 109 */ 110 111 typedef natural_t ipc_table_index_t; /* index into tables */ 112 typedef natural_t ipc_table_elems_t; /* size of tables */ 113 114 typedef struct ipc_table_size { 115 ipc_table_elems_t its_size; /* number of elements in table */ 116 } *ipc_table_size_t; 117 118 #define ITS_NULL ((ipc_table_size_t) 0) 119 #define ITS_SIZE_NONE -1 120 121 extern ipc_table_size_t ipc_table_entries; 122 extern ipc_table_size_t ipc_table_dnrequests; 123 124 /* Initialize IPC capabilities table storage */ 125 extern void ipc_table_init(void); 126 127 /* 128 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free 129 * all potentially use the VM system. Hence simple locks can't 130 * be held across them. 131 * 132 * We can't use a copying realloc, because the realloc happens 133 * with the data unlocked. ipc_table_realloc remaps the data, 134 * so it is OK. 135 */ 136 137 /* Allocate a table */ 138 extern vm_offset_t ipc_table_alloc( 139 vm_size_t size); 140 141 /* Reallocate a big table */ 142 extern vm_offset_t ipc_table_realloc( 143 vm_size_t old_size, 144 vm_offset_t old_table, 145 vm_size_t new_size); 146 147 /* Free a table */ 148 extern void ipc_table_free( 149 vm_size_t size, 150 vm_offset_t table); 151 152 #define it_entries_alloc(its) \ 153 ((ipc_entry_t *) \ 154 ipc_table_alloc((its)->its_size * sizeof(struct ipc_entry *))) 155 156 #define it_entries_reallocable(its) \ 157 (((its)->its_size * sizeof(struct ipc_entry *)) >= PAGE_SIZE) 158 159 #define it_entries_realloc(its, table, nits) \ 160 ((ipc_entry_t *) \ 161 ipc_table_realloc((its)->its_size * sizeof(struct ipc_entry *), \ 162 (vm_offset_t)(table), \ 163 (nits)->its_size * sizeof(struct ipc_entry *))) 164 165 #define it_entries_free(its, table) \ 166 ipc_table_free((its)->its_size * sizeof(struct ipc_entry *), \ 167 (vm_offset_t)(table)) 168 169 #define it_dnrequests_alloc(its) \ 170 ((ipc_port_request_t) \ 171 ipc_table_alloc((its)->its_size * \ 172 sizeof(struct ipc_port_request))) 173 174 #define it_dnrequests_free(its, table) \ 175 ipc_table_free((its)->its_size * \ 176 sizeof(struct ipc_port_request), \ 177 (vm_offset_t)(table)) 178 179 #endif /* _IPC_IPC_TABLE_H_ */ 180