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