|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* ! 23: * @OSF_COPYRIGHT@ ! 24: */ ! 25: /* ! 26: * HISTORY ! 27: * ! 28: * Revision 1.1.1.1 1998/09/22 21:05:28 wsanchez ! 29: * Import of Mac OS X kernel (~semeria) ! 30: * ! 31: * Revision 1.2 1998/06/01 17:29:25 youngwor ! 32: * Added infrastructure for shared port space support ! 33: * ! 34: * Revision 1.1.1.1 1998/03/07 02:26:16 wsanchez ! 35: * Import of OSF Mach kernel (~mburg) ! 36: * ! 37: * Revision 1.2.10.1 1994/09/23 02:12:16 ezf ! 38: * change marker to not FREE ! 39: * [1994/09/22 21:30:49 ezf] ! 40: * ! 41: * Revision 1.2.2.3 1993/07/22 16:17:30 rod ! 42: * Add ANSI prototypes. CR #9523. ! 43: * [1993/07/22 13:33:29 rod] ! 44: * ! 45: * Revision 1.2.2.2 1993/06/02 23:33:55 jeffc ! 46: * Added to OSF/1 R1.3 from NMK15.0. ! 47: * [1993/06/02 21:11:14 jeffc] ! 48: * ! 49: * Revision 1.2 1992/11/25 01:09:56 robert ! 50: * integrate changes below for norma_14 ! 51: * ! 52: * Philippe Bernadat (bernadat) at gr.osf.org ! 53: * Limit ipc table allocation chunks to 8 pages, otherwise ! 54: * the kernel might dead lock because of VM_PAGE_FREE_RESERVED ! 55: * limited to 15. [[email protected] & [email protected]] ! 56: * [1992/11/13 19:31:46 robert] ! 57: * ! 58: * Revision 1.1 1992/09/30 02:08:13 robert ! 59: * Initial revision ! 60: * ! 61: * $EndLog$ ! 62: */ ! 63: /* CMU_HIST */ ! 64: /* ! 65: * Revision 2.6 91/10/09 16:11:08 af ! 66: * Revision 2.5.2.1 91/09/16 10:16:06 rpd ! 67: * Removed unused variables. ! 68: * [91/09/02 rpd] ! 69: * ! 70: * Revision 2.5.2.1 91/09/16 10:16:06 rpd ! 71: * Removed unused variables. ! 72: * [91/09/02 rpd] ! 73: * ! 74: * Revision 2.5 91/05/14 16:37:35 mrt ! 75: * Correcting copyright ! 76: * ! 77: * Revision 2.4 91/03/16 14:48:52 rpd ! 78: * Added ipc_table_realloc and ipc_table_reallocable. ! 79: * [91/03/04 rpd] ! 80: * ! 81: * Revision 2.3 91/02/05 17:24:15 mrt ! 82: * Changed to new Mach copyright ! 83: * [91/02/01 15:52:05 mrt] ! 84: * ! 85: * Revision 2.2 90/06/02 14:51:58 rpd ! 86: * Created for new IPC. ! 87: * [90/03/26 21:04:20 rpd] ! 88: * ! 89: */ ! 90: /* CMU_ENDHIST */ ! 91: /* ! 92: * Mach Operating System ! 93: * Copyright (c) 1991,1990,1989 Carnegie Mellon University ! 94: * All Rights Reserved. ! 95: * ! 96: * Permission to use, copy, modify and distribute this software and its ! 97: * documentation is hereby granted, provided that both the copyright ! 98: * notice and this permission notice appear in all copies of the ! 99: * software, derivative works or modified versions, and any portions ! 100: * thereof, and that both notices appear in supporting documentation. ! 101: * ! 102: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 103: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 104: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 105: * ! 106: * Carnegie Mellon requests users of this software to return to ! 107: * ! 108: * Software Distribution Coordinator or [email protected] ! 109: * School of Computer Science ! 110: * Carnegie Mellon University ! 111: * Pittsburgh PA 15213-3890 ! 112: * ! 113: * any improvements or extensions that they make and grant Carnegie Mellon ! 114: * the rights to redistribute these changes. ! 115: */ ! 116: /* ! 117: */ ! 118: /* ! 119: * File: ipc/ipc_table.c ! 120: * Author: Rich Draves ! 121: * Date: 1989 ! 122: * ! 123: * Functions to manipulate tables of IPC capabilities. ! 124: */ ! 125: ! 126: #include <mach/kern_return.h> ! 127: #include <mach/vm_param.h> ! 128: #include <ipc/ipc_table.h> ! 129: #include <ipc/ipc_port.h> ! 130: #include <ipc/ipc_entry.h> ! 131: #include <kern/kalloc.h> ! 132: #include <vm/vm_kern.h> ! 133: ! 134: /* ! 135: * Forward declarations ! 136: */ ! 137: void ipc_table_fill( ! 138: ipc_table_size_t its, ! 139: unsigned int num, ! 140: unsigned int min, ! 141: vm_size_t elemsize); ! 142: ! 143: /* ! 144: * We borrow the kalloc map, rather than creating ! 145: * yet another submap of the kernel map. ! 146: */ ! 147: ! 148: extern vm_map_t kalloc_map; ! 149: ! 150: ipc_table_size_t ipc_table_entries; ! 151: unsigned int ipc_table_entries_size = 512; ! 152: ! 153: ipc_table_size_t ipc_table_dnrequests; ! 154: unsigned int ipc_table_dnrequests_size = 64; ! 155: ! 156: void ! 157: ipc_table_fill( ! 158: ipc_table_size_t its, /* array to fill */ ! 159: unsigned int num, /* size of array */ ! 160: unsigned int min, /* at least this many elements */ ! 161: vm_size_t elemsize) /* size of elements */ ! 162: { ! 163: unsigned int index; ! 164: vm_size_t minsize = min * elemsize; ! 165: vm_size_t size; ! 166: vm_size_t incrsize; ! 167: ! 168: /* first use powers of two, up to the page size */ ! 169: ! 170: for (index = 0, size = 1; ! 171: (index < num) && (size < PAGE_SIZE); ! 172: size <<= 1) { ! 173: if (size >= minsize) { ! 174: its[index].its_size = size / elemsize; ! 175: index++; ! 176: } ! 177: } ! 178: ! 179: /* then increments of a page, then two pages, etc. */ ! 180: ! 181: for (incrsize = PAGE_SIZE; index < num;) { ! 182: unsigned int period; ! 183: ! 184: for (period = 0; ! 185: (period < 15) && (index < num); ! 186: period++, size += incrsize) { ! 187: if (size >= minsize) { ! 188: its[index].its_size = size / elemsize; ! 189: index++; ! 190: } ! 191: } ! 192: if (incrsize < (PAGE_SIZE << 3)) ! 193: incrsize <<= 1; ! 194: } ! 195: } ! 196: ! 197: void ! 198: ipc_table_init(void) ! 199: { ! 200: ipc_table_entries = (ipc_table_size_t) ! 201: kalloc(sizeof(struct ipc_table_size) * ! 202: ipc_table_entries_size); ! 203: assert(ipc_table_entries != ITS_NULL); ! 204: ! 205: ipc_table_fill(ipc_table_entries, ipc_table_entries_size - 1, ! 206: 4, sizeof(struct ipc_entry) + ! 207: sizeof(ipc_entry_bits_t) + ! 208: sizeof(ipc_table_index_t)); ! 209: ! 210: /* the last two elements should have the same size */ ! 211: ! 212: ipc_table_entries[ipc_table_entries_size - 1].its_size = ! 213: ipc_table_entries[ipc_table_entries_size - 2].its_size; ! 214: ! 215: ! 216: ipc_table_dnrequests = (ipc_table_size_t) ! 217: kalloc(sizeof(struct ipc_table_size) * ! 218: ipc_table_dnrequests_size); ! 219: assert(ipc_table_dnrequests != ITS_NULL); ! 220: ! 221: ipc_table_fill(ipc_table_dnrequests, ipc_table_dnrequests_size - 1, ! 222: 2, sizeof(struct ipc_port_request)); ! 223: ! 224: /* the last element should have zero size */ ! 225: ! 226: ipc_table_dnrequests[ipc_table_dnrequests_size - 1].its_size = 0; ! 227: } ! 228: ! 229: /* ! 230: * Routine: ipc_table_alloc ! 231: * Purpose: ! 232: * Allocate a table. ! 233: * Conditions: ! 234: * May block. ! 235: */ ! 236: ! 237: vm_offset_t ! 238: ipc_table_alloc( ! 239: vm_size_t size) ! 240: { ! 241: vm_offset_t table; ! 242: ! 243: if (size < PAGE_SIZE) ! 244: table = kalloc(size); ! 245: else ! 246: if (kmem_alloc(kalloc_map, &table, size) != KERN_SUCCESS) ! 247: table = 0; ! 248: ! 249: return table; ! 250: } ! 251: ! 252: /* ! 253: * Routine: ipc_table_realloc ! 254: * Purpose: ! 255: * Reallocate a big table. ! 256: * ! 257: * The new table remaps the old table, ! 258: * so copying is not necessary. ! 259: * Conditions: ! 260: * Only works for page-size or bigger tables. ! 261: * May block. ! 262: */ ! 263: ! 264: vm_offset_t ! 265: ipc_table_realloc( ! 266: vm_size_t old_size, ! 267: vm_offset_t old_table, ! 268: vm_size_t new_size) ! 269: { ! 270: vm_offset_t new_table; ! 271: ! 272: if (kmem_realloc(kalloc_map, old_table, old_size, ! 273: &new_table, new_size) != KERN_SUCCESS) ! 274: new_table = 0; ! 275: ! 276: return new_table; ! 277: } ! 278: ! 279: /* ! 280: * Routine: ipc_table_free ! 281: * Purpose: ! 282: * Free a table allocated with ipc_table_alloc or ! 283: * ipc_table_realloc. ! 284: * Conditions: ! 285: * May block. ! 286: */ ! 287: ! 288: void ! 289: ipc_table_free( ! 290: vm_size_t size, ! 291: vm_offset_t table) ! 292: { ! 293: if (size < PAGE_SIZE) ! 294: kfree(table, size); ! 295: else ! 296: kmem_free(kalloc_map, table, size); ! 297: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.