]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_stubs.c
xnu-124.7.tar.gz
[apple/xnu.git] / bsd / kern / bsd_stubs.c
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 #include <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 #include <sys/buf.h> /* for SET */
32
33 /* Just to satisfy pstat command */
34 int dmmin, dmmax, dmtext;
35
36 kmem_mb_alloc(vm_map_t mbmap, int size)
37 {
38 vm_offset_t addr;
39 if (kernel_memory_allocate(mbmap, &addr, size,
40 0,
41 KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS)
42 return((void *)addr);
43 else
44 return(0);
45
46 }
47
48 pcb_synch() {}
49 unix_master() {}
50 unix_release() {}
51
52 struct proc *
53 current_proc(void)
54 {
55 /* Never returns a NULL */
56 struct proc *p = (struct proc *)get_bsdtask_info(current_task());
57 if (p == NULL)
58 p = kernproc;
59 return (p);
60 }
61
62 /* Device switch add delete routines */
63
64 extern int nblkdev, nchrdev;
65
66 struct bdevsw nobdev = NO_BDEVICE;
67 struct cdevsw nocdev = NO_CDEVICE;
68 /*
69 * if index is -1, return a free slot if avaliable
70 * else see whether the index is free
71 * return the major number that is free else -1
72 *
73 */
74 int
75 bdevsw_isfree(int index)
76 {
77 struct bdevsw *devsw;
78 if (index == -1) {
79 devsw = bdevsw;
80 for(index=0; index < nblkdev; index++, devsw++) {
81 if(memcmp((char *)devsw,
82 (char *)&nobdev,
83 sizeof(struct bdevsw)) == 0)
84 break;
85 }
86 }
87
88 if ((index < 0) || (index >= nblkdev) ||
89 (memcmp((char *)devsw,
90 (char *)&nobdev,
91 sizeof(struct bdevsw)) != 0)) {
92 return(-1);
93 }
94 return(index);
95 }
96
97 /*
98 * if index is -1, find a free slot to add
99 * else see whether the slot is free
100 * return the major number that is used else -1
101 */
102 int
103 bdevsw_add(int index, struct bdevsw * bsw)
104 {
105 struct bdevsw *devsw;
106
107 if (index == -1) {
108 devsw = bdevsw;
109 for(index=0; index < nblkdev; index++, devsw++) {
110 if(memcmp((char *)devsw,
111 (char *)&nobdev,
112 sizeof(struct bdevsw)) == 0)
113 break;
114 }
115 }
116 devsw = &bdevsw[index];
117 if ((index < 0) || (index >= nblkdev) ||
118 (memcmp((char *)devsw,
119 (char *)&nobdev,
120 sizeof(struct bdevsw)) != 0)) {
121 return(-1);
122 }
123 bdevsw[index] = *bsw;
124 return(index);
125 }
126 /*
127 * if the slot has the same bsw, then remove
128 * else -1
129 */
130 int
131 bdevsw_remove(int index, struct bdevsw * bsw)
132 {
133 struct bdevsw *devsw;
134
135 devsw = &bdevsw[index];
136 if ((index < 0) || (index >= nblkdev) ||
137 (memcmp((char *)devsw,
138 (char *)bsw,
139 sizeof(struct bdevsw)) != 0)) {
140 return(-1);
141 }
142 bdevsw[index] = nobdev;
143 return(index);
144 }
145
146 /*
147 * if index is -1, return a free slot if avaliable
148 * else see whether the index is free
149 * return the major number that is free else -1
150 */
151 int
152 cdevsw_isfree(int index)
153 {
154 struct cdevsw *devsw;
155
156 if (index == -1) {
157 devsw = cdevsw;
158 for(index=0; index < nchrdev; index++, devsw++) {
159 if(memcmp((char *)devsw,
160 (char *)&nocdev,
161 sizeof(struct cdevsw)) == 0)
162 break;
163 }
164 }
165 devsw = &cdevsw[index];
166 if ((index < 0) || (index >= nchrdev) ||
167 (memcmp((char *)devsw,
168 (char *)&nocdev,
169 sizeof(struct cdevsw)) != 0)) {
170 return(-1);
171 }
172 return(index);
173 }
174
175 /*
176 * if index is -1, find a free slot to add
177 * else see whether the slot is free
178 * return the major number that is used else -1
179 */
180 int
181 cdevsw_add(int index, struct cdevsw * csw)
182 {
183 struct cdevsw *devsw;
184
185 if (index == -1) {
186 devsw = cdevsw;
187 for(index=0; index < nchrdev; index++, devsw++) {
188 if(memcmp((char *)devsw,
189 (char *)&nocdev,
190 sizeof(struct cdevsw)) == 0)
191 break;
192 }
193 }
194 devsw = &cdevsw[index];
195 if ((index < 0) || (index >= nchrdev) ||
196 (memcmp((char *)devsw,
197 (char *)&nocdev,
198 sizeof(struct cdevsw)) != 0)) {
199 return(-1);
200 }
201 cdevsw[index] = *csw;
202 return(index);
203 }
204 /*
205 * if the index has the same bsw, then remove
206 * else -1
207 */
208 int
209 cdevsw_remove(int index, struct cdevsw * csw)
210 {
211 struct cdevsw *devsw;
212
213 devsw = &cdevsw[index];
214 if ((index < 0) || (index >= nchrdev) ||
215 (memcmp((char *)devsw,
216 (char *)csw,
217 sizeof(struct cdevsw)) != 0)) {
218 return(-1);
219 }
220 cdevsw[index] = nocdev;
221 return(index);
222 }
223
224 int
225 memcmp(s1, s2, n)
226 register char *s1, *s2;
227 register n;
228 {
229 while (--n >= 0)
230 if (*s1++ != *s2++)
231 return (*--s1 - *--s2);
232 return (0);
233 }
234 int
235 issingleuser(void)
236 {
237 char namep[16];
238
239
240 if (PE_parse_boot_arg("-s", namep)) {
241 return(1);
242 } else {
243 return(0);
244 }
245 }
246
247 void *
248 tbeproc(void *procp)
249 {
250 struct proc *p = procp;
251
252 if (p)
253 SET(p->p_flag, P_TBE);
254 return;
255 }
256