|
|
1.1 root 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 [email protected]
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: */
28: /*
29: * File: ipc/ipc_table.c
30: * Author: Rich Draves
31: * Date: 1989
32: *
33: * Functions to manipulate tables of IPC capabilities.
34: */
35:
36: #include <mach/kern_return.h>
37: #include <mach/vm_param.h>
38: #include <ipc/ipc_table.h>
39: #include <ipc/ipc_port.h>
40: #include <ipc/ipc_entry.h>
41: #include <kern/kalloc.h>
1.1.1.2 root 42: #include <kern/slab.h>
1.1 root 43: #include <vm/vm_kern.h>
44:
45: ipc_table_size_t ipc_table_dnrequests;
1.1.1.3 root 46: const unsigned int ipc_table_dnrequests_size = 64;
1.1 root 47:
48: void
49: ipc_table_fill(
50: ipc_table_size_t its, /* array to fill */
51: unsigned int num, /* size of array */
52: unsigned int min, /* at least this many elements */
53: vm_size_t elemsize) /* size of elements */
54: {
55: unsigned int index;
56: vm_size_t minsize = min * elemsize;
57: vm_size_t size;
58: vm_size_t incrsize;
59:
60: /* first use powers of two, up to the page size */
61:
62: for (index = 0, size = 1;
63: (index < num) && (size < PAGE_SIZE);
64: size <<= 1) {
65: if (size >= minsize) {
66: its[index].its_size = size / elemsize;
67: index++;
68: }
69: }
70:
71: /* then increments of a page, then two pages, etc. */
72:
73: for (incrsize = PAGE_SIZE; index < num;) {
74: unsigned int period;
75:
76: for (period = 0;
77: (period < 15) && (index < num);
78: period++, size += incrsize) {
79: if (size >= minsize) {
80: its[index].its_size = size / elemsize;
81: index++;
82: }
83: }
84: if (incrsize < (PAGE_SIZE << 3))
85: incrsize <<= 1;
86: }
87: }
88:
89: void
90: ipc_table_init(void)
91: {
92: ipc_table_dnrequests = (ipc_table_size_t)
93: kalloc(sizeof(struct ipc_table_size) *
94: ipc_table_dnrequests_size);
95: assert(ipc_table_dnrequests != ITS_NULL);
96:
97: ipc_table_fill(ipc_table_dnrequests, ipc_table_dnrequests_size - 1,
98: 2, sizeof(struct ipc_port_request));
99:
100: /* the last element should have zero size */
101:
102: ipc_table_dnrequests[ipc_table_dnrequests_size - 1].its_size = 0;
103: }
104:
105: /*
106: * Routine: ipc_table_alloc
107: * Purpose:
108: * Allocate a table.
109: * Conditions:
110: * May block.
111: */
112:
113: vm_offset_t
114: ipc_table_alloc(
115: vm_size_t size)
116: {
1.1.1.4 ! root 117: return kalloc(size);
1.1 root 118: }
119:
120: /*
121: * Routine: ipc_table_free
122: * Purpose:
123: * Free a table allocated with ipc_table_alloc or
124: * ipc_table_realloc.
125: * Conditions:
126: * May block.
127: */
128:
129: void
130: ipc_table_free(
131: vm_size_t size,
132: vm_offset_t table)
133: {
1.1.1.4 ! root 134: kfree(table, size);
1.1 root 135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.