]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/bsd_stubs.c
xnu-517.3.7.tar.gz
[apple/xnu.git] / bsd / kern / bsd_stubs.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25#include <sys/time.h>
26#include <kern/task.h>
27#include <kern/thread.h>
28#include <mach/mach_types.h>
29#include <mach/vm_prot.h>
30#include <vm/vm_kern.h>
31#include <vm/vm_map.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/buf.h> /* for SET */
0b4e3aa0 35#include <sys/user.h>
1c79356b
A
36
37/* Just to satisfy pstat command */
38int dmmin, dmmax, dmtext;
39
40kmem_mb_alloc(vm_map_t mbmap, int size)
41{
42 vm_offset_t addr;
43 if (kernel_memory_allocate(mbmap, &addr, size,
44 0,
45 KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS)
55e303ae 46 return(addr);
1c79356b
A
47 else
48 return(0);
49
50}
51
52pcb_synch() {}
1c79356b
A
53
54struct proc *
55current_proc(void)
56{
57 /* Never returns a NULL */
0b4e3aa0
A
58 struct uthread * ut;
59 struct proc *p;
60 thread_act_t thr_act = current_act();
61
62 ut = (struct uthread *)get_bsdthread_info(thr_act);
63 if (ut && (ut->uu_flag & P_VFORK) && ut->uu_proc) {
64 p = ut->uu_proc;
65 if ((p->p_flag & P_INVFORK) == 0)
66 panic("returning child proc not under vfork");
67 if (p->p_vforkact != (void *)thr_act)
68 panic("returning child proc which is not cur_act");
69 return(p);
70 }
71
72 p = (struct proc *)get_bsdtask_info(current_task());
73
1c79356b 74 if (p == NULL)
0b4e3aa0
A
75 return (kernproc);
76
1c79356b
A
77 return (p);
78}
79
80/* Device switch add delete routines */
81
82extern int nblkdev, nchrdev;
83
84struct bdevsw nobdev = NO_BDEVICE;
85struct cdevsw nocdev = NO_CDEVICE;
86/*
87 * if index is -1, return a free slot if avaliable
88 * else see whether the index is free
89 * return the major number that is free else -1
90 *
91 */
92int
93bdevsw_isfree(int index)
94{
95 struct bdevsw *devsw;
96 if (index == -1) {
97 devsw = bdevsw;
98 for(index=0; index < nblkdev; index++, devsw++) {
99 if(memcmp((char *)devsw,
100 (char *)&nobdev,
101 sizeof(struct bdevsw)) == 0)
102 break;
103 }
55e303ae
A
104 } else {
105 /* NB: Not used below unless index is in range */
106 devsw = &bdevsw[index];
1c79356b
A
107 }
108
109 if ((index < 0) || (index >= nblkdev) ||
110 (memcmp((char *)devsw,
111 (char *)&nobdev,
112 sizeof(struct bdevsw)) != 0)) {
113 return(-1);
114 }
115 return(index);
116}
117
118/*
119 * if index is -1, find a free slot to add
120 * else see whether the slot is free
121 * return the major number that is used else -1
122 */
123int
124bdevsw_add(int index, struct bdevsw * bsw)
125{
126 struct bdevsw *devsw;
127
128 if (index == -1) {
55e303ae 129 devsw = &bdevsw[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
9bccf70c
A
130 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
131 for(index=1; index < nblkdev; index++, devsw++) {
1c79356b
A
132 if(memcmp((char *)devsw,
133 (char *)&nobdev,
134 sizeof(struct bdevsw)) == 0)
135 break;
136 }
137 }
138 devsw = &bdevsw[index];
139 if ((index < 0) || (index >= nblkdev) ||
140 (memcmp((char *)devsw,
141 (char *)&nobdev,
142 sizeof(struct bdevsw)) != 0)) {
143 return(-1);
144 }
145 bdevsw[index] = *bsw;
146 return(index);
147}
148/*
149 * if the slot has the same bsw, then remove
150 * else -1
151 */
152int
153bdevsw_remove(int index, struct bdevsw * bsw)
154{
155 struct bdevsw *devsw;
156
157 devsw = &bdevsw[index];
158 if ((index < 0) || (index >= nblkdev) ||
159 (memcmp((char *)devsw,
160 (char *)bsw,
161 sizeof(struct bdevsw)) != 0)) {
162 return(-1);
163 }
164 bdevsw[index] = nobdev;
165 return(index);
166}
167
168/*
169 * if index is -1, return a free slot if avaliable
170 * else see whether the index is free
171 * return the major number that is free else -1
172 */
173int
174cdevsw_isfree(int index)
175{
176 struct cdevsw *devsw;
177
178 if (index == -1) {
179 devsw = cdevsw;
180 for(index=0; index < nchrdev; index++, devsw++) {
181 if(memcmp((char *)devsw,
182 (char *)&nocdev,
183 sizeof(struct cdevsw)) == 0)
184 break;
185 }
186 }
187 devsw = &cdevsw[index];
188 if ((index < 0) || (index >= nchrdev) ||
189 (memcmp((char *)devsw,
190 (char *)&nocdev,
191 sizeof(struct cdevsw)) != 0)) {
192 return(-1);
193 }
194 return(index);
195}
196
197/*
198 * if index is -1, find a free slot to add
199 * else see whether the slot is free
200 * return the major number that is used else -1
201 */
202int
203cdevsw_add(int index, struct cdevsw * csw)
204{
205 struct cdevsw *devsw;
206
207 if (index == -1) {
208 devsw = cdevsw;
209 for(index=0; index < nchrdev; index++, devsw++) {
210 if(memcmp((char *)devsw,
211 (char *)&nocdev,
212 sizeof(struct cdevsw)) == 0)
213 break;
214 }
215 }
216 devsw = &cdevsw[index];
217 if ((index < 0) || (index >= nchrdev) ||
218 (memcmp((char *)devsw,
219 (char *)&nocdev,
220 sizeof(struct cdevsw)) != 0)) {
221 return(-1);
222 }
223 cdevsw[index] = *csw;
224 return(index);
225}
226/*
227 * if the index has the same bsw, then remove
228 * else -1
229 */
230int
231cdevsw_remove(int index, struct cdevsw * csw)
232{
233 struct cdevsw *devsw;
234
235 devsw = &cdevsw[index];
236 if ((index < 0) || (index >= nchrdev) ||
237 (memcmp((char *)devsw,
238 (char *)csw,
239 sizeof(struct cdevsw)) != 0)) {
240 return(-1);
241 }
242 cdevsw[index] = nocdev;
243 return(index);
244}
245
9bccf70c
A
246static int
247cdev_set_bdev(int cdev, int bdev)
248{
249 extern int chrtoblk_add(int cdev, int bdev);
250
251 return (chrtoblk_set(cdev, bdev));
252}
253
254int
255cdevsw_add_with_bdev(int index, struct cdevsw * csw, int bdev)
256{
257 index = cdevsw_add(index, csw);
258 if (index < 0) {
259 return (index);
260 }
261 if (cdev_set_bdev(index, bdev) < 0) {
262 cdevsw_remove(index, csw);
263 return (-1);
264 }
265 return (index);
266}
267
1c79356b
A
268issingleuser(void)
269{
270 char namep[16];
271
272
273 if (PE_parse_boot_arg("-s", namep)) {
274 return(1);
275 } else {
276 return(0);
277 }
278}
279
280void *
281tbeproc(void *procp)
282{
283 struct proc *p = procp;
284
285 if (p)
286 SET(p->p_flag, P_TBE);
287 return;
288}
289