|
|
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: #include <sys/time.h>
23: #include <kern/task.h>
24: #include <kern/thread.h>
25: #import <mach/mach_types.h>
26: #include <mach/vm_prot.h>
27: #include <vm/vm_kern.h>
28: #include <vm/vm_map.h>
29: #include <sys/systm.h>
30: #include <sys/conf.h>
31:
32: kmem_mb_alloc(vm_map_t mbmap, int size)
33: {
34: vm_offset_t addr;
35: if (kernel_memory_allocate(mbmap, &addr, size,
36: 0,
37: KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS)
38: return((void *)addr);
39: else
40: return(0);
41:
42: }
43:
44: vm_offset_t kalloc_noblock(size)
45: vm_size_t size;
46: {
47: return(kalloc(size));
48: }
49: vm_offset_t zalloc_noblock(zone)
50: register void * zone;
51: {
52: return(zalloc(zone));
53: }
54:
55: pcb_synch() {}
56: task_dowait() {}
57: task_hold(task_t t)
58: {
59: return(task_hold_locked(t));
60: }
61: task_suspend_nowait(task_t task)
62: {
63: return(task_suspend(task));
64: }
65: task_tllock() {}
66: task_tlunlock() {}
67:
68:
69: unix_master() {}
70: unix_release() {}
71: vm_map_check_protection() {}
72: vm_map_find() {}
73: vm_object_cache_clear() {}
74:
75: #undef current_proc
76: struct proc *
77: current_proc(void)
78: {
79: return((struct proc *)get_bsdtask_info(current_task()));
80: }
81: /* Device switch add delete routines */
82:
83: extern int nblkdev, nchrdev;
84:
85: struct bdevsw nobdev = NO_BDEVICE;
86: struct cdevsw nocdev = NO_CDEVICE;
87: /*
88: * if index is -1, return a free slot if avaliable
89: * else see whether the index is free
90: * return the major number that is free else -1
91: *
92: */
93: int
94: bdevsw_isfree(int index)
95: {
96: struct bdevsw *devsw;
97: if (index == -1) {
98: devsw = bdevsw;
99: for(index=0; index < nblkdev; index++, devsw++) {
100: if(memcmp((char *)devsw,
101: (char *)&nobdev,
102: sizeof(struct bdevsw)) == 0)
103: break;
104: }
105: }
106:
107: if ((index < 0) || (index >= nblkdev) ||
108: (memcmp((char *)devsw,
109: (char *)&nobdev,
110: sizeof(struct bdevsw)) != 0)) {
111: return(-1);
112: }
113: return(index);
114: }
115:
116: /*
117: * if index is -1, find a free slot to add
118: * else see whether the slot is free
119: * return the major number that is used else -1
120: */
121: int
122: bdevsw_add(int index, struct bdevsw * bsw)
123: {
124: struct bdevsw *devsw;
125:
126: if (index == -1) {
127: devsw = bdevsw;
128: for(index=0; index < nblkdev; index++, devsw++) {
129: if(memcmp((char *)devsw,
130: (char *)&nobdev,
131: sizeof(struct bdevsw)) == 0)
132: break;
133: }
134: }
135: devsw = &bdevsw[index];
136: if ((index < 0) || (index >= nblkdev) ||
137: (memcmp((char *)devsw,
138: (char *)&nobdev,
139: sizeof(struct bdevsw)) != 0)) {
140: return(-1);
141: }
142: bdevsw[index] = *bsw;
143: return(index);
144: }
145: /*
146: * if the slot has the same bsw, then remove
147: * else -1
148: */
149: int
150: bdevsw_remove(int index, struct bdevsw * bsw)
151: {
152: struct bdevsw *devsw;
153:
154: devsw = &bdevsw[index];
155: if ((index < 0) || (index >= nblkdev) ||
156: (memcmp((char *)devsw,
157: (char *)bsw,
158: sizeof(struct bdevsw)) != 0)) {
159: return(-1);
160: }
161: bdevsw[index] = nobdev;
162: return(index);
163: }
164:
165: /*
166: * if index is -1, return a free slot if avaliable
167: * else see whether the index is free
168: * return the major number that is free else -1
169: */
170: int
171: cdevsw_isfree(int index)
172: {
173: struct cdevsw *devsw;
174:
175: if (index == -1) {
176: devsw = cdevsw;
177: for(index=0; index < nchrdev; index++, devsw++) {
178: if(memcmp((char *)devsw,
179: (char *)&nocdev,
180: sizeof(struct cdevsw)) == 0)
181: break;
182: }
183: }
184: devsw = &cdevsw[index];
185: if ((index < 0) || (index >= nchrdev) ||
186: (memcmp((char *)devsw,
187: (char *)&nocdev,
188: sizeof(struct cdevsw)) != 0)) {
189: return(-1);
190: }
191: return(index);
192: }
193:
194: /*
195: * if index is -1, find a free slot to add
196: * else see whether the slot is free
197: * return the major number that is used else -1
198: */
199: int
200: cdevsw_add(int index, struct cdevsw * csw)
201: {
202: struct cdevsw *devsw;
203:
204: if (index == -1) {
205: devsw = cdevsw;
206: for(index=0; index < nchrdev; index++, devsw++) {
207: if(memcmp((char *)devsw,
208: (char *)&nocdev,
209: sizeof(struct cdevsw)) == 0)
210: break;
211: }
212: }
213: devsw = &cdevsw[index];
214: if ((index < 0) || (index >= nchrdev) ||
215: (memcmp((char *)devsw,
216: (char *)&nocdev,
217: sizeof(struct cdevsw)) != 0)) {
218: return(-1);
219: }
220: cdevsw[index] = *csw;
221: return(index);
222: }
223: /*
224: * if the index has the same bsw, then remove
225: * else -1
226: */
227: int
228: cdevsw_remove(int index, struct cdevsw * csw)
229: {
230: struct cdevsw *devsw;
231:
232: devsw = &cdevsw[index];
233: if ((index < 0) || (index >= nchrdev) ||
234: (memcmp((char *)devsw,
235: (char *)csw,
236: sizeof(struct cdevsw)) != 0)) {
237: return(-1);
238: }
239: cdevsw[index] = nocdev;
240: return(index);
241: }
242:
243: int
244: memcmp(s1, s2, n)
245: register char *s1, *s2;
246: register n;
247: {
248: while (--n >= 0)
249: if (*s1++ != *s2++)
250: return (*--s1 - *--s2);
251: return (0);
252: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.