]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_stubs.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <kern/task.h>
30 #include <kern/thread.h>
31 #include <mach/mach_types.h>
32 #include <mach/vm_prot.h>
33 #include <vm/vm_kern.h>
34 #include <vm/vm_map.h>
35 #include <sys/systm.h>
37 #include <sys/proc_internal.h>
38 #include <sys/buf.h> /* for SET */
40 #include <sys/sysent.h>
41 #include <sys/sysproto.h>
43 /* XXX these should be in a common header somwhere, but aren't */
44 extern int chrtoblk_set(int, int);
45 extern vm_offset_t
kmem_mb_alloc(vm_map_t
, int);
47 /* XXX most of these just exist to export; there's no good header for them*/
49 int issingleuser(void);
53 /* Just to satisfy pstat command */
54 int dmmin
, dmmax
, dmtext
;
57 kmem_mb_alloc(vm_map_t mbmap
, int size
)
60 if (kernel_memory_allocate(mbmap
, &addr
, size
,
62 KMA_NOPAGEWAIT
|KMA_KOBJECT
|KMA_LOMEM
) == KERN_SUCCESS
)
70 * XXX this function only exists to be exported and do nothing.
80 /* Never returns a NULL */
83 thread_t thread
= current_thread();
85 ut
= (struct uthread
*)get_bsdthread_info(thread
);
86 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
88 if ((p
->p_lflag
& P_LINVFORK
) == 0)
89 panic("returning child proc not under vfork");
90 if (p
->p_vforkact
!= (void *)thread
)
91 panic("returning child proc which is not cur_act");
95 p
= (struct proc
*)get_bsdtask_info(current_task());
103 /* Device switch add delete routines */
105 struct bdevsw nobdev
= NO_BDEVICE
;
106 struct cdevsw nocdev
= NO_CDEVICE
;
108 * if index is -1, return a free slot if avaliable
109 * else see whether the index is free
110 * return the major number that is free else -1
114 bdevsw_isfree(int index
)
116 struct bdevsw
*devsw
;
119 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
120 if(memcmp((char *)devsw
,
122 sizeof(struct bdevsw
)) == 0)
126 /* NB: Not used below unless index is in range */
127 devsw
= &bdevsw
[index
];
130 if ((index
< 0) || (index
>= nblkdev
) ||
131 (memcmp((char *)devsw
,
133 sizeof(struct bdevsw
)) != 0)) {
140 * if index is -1, find a free slot to add
141 * else see whether the slot is free
142 * return the major number that is used else -1
145 bdevsw_add(int index
, struct bdevsw
* bsw
)
147 struct bdevsw
*devsw
;
150 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
151 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
152 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
153 if(memcmp((char *)devsw
,
155 sizeof(struct bdevsw
)) == 0)
159 devsw
= &bdevsw
[index
];
160 if ((index
< 0) || (index
>= nblkdev
) ||
161 (memcmp((char *)devsw
,
163 sizeof(struct bdevsw
)) != 0)) {
166 bdevsw
[index
] = *bsw
;
170 * if the slot has the same bsw, then remove
174 bdevsw_remove(int index
, struct bdevsw
* bsw
)
176 struct bdevsw
*devsw
;
178 devsw
= &bdevsw
[index
];
179 if ((index
< 0) || (index
>= nblkdev
) ||
180 (memcmp((char *)devsw
,
182 sizeof(struct bdevsw
)) != 0)) {
185 bdevsw
[index
] = nobdev
;
190 * if index is -1, return a free slot if avaliable
191 * else see whether the index is free
192 * return the major number that is free else -1
195 cdevsw_isfree(int index
)
197 struct cdevsw
*devsw
;
201 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
202 if(memcmp((char *)devsw
,
204 sizeof(struct cdevsw
)) == 0)
208 devsw
= &cdevsw
[index
];
209 if ((index
< 0) || (index
>= nchrdev
) ||
210 (memcmp((char *)devsw
,
212 sizeof(struct cdevsw
)) != 0)) {
219 * if index is -1, find a free slot to add
220 * else see whether the slot is free
221 * return the major number that is used else -1
223 * NOTE: In practice, -1 is unusable, since there are kernel internal
224 * devices that call this function with absolute index values,
225 * which will stomp on free-slot based assignments that happen
226 * before them. Therefore, if index is negative, we start
227 * looking for a free slot at the absolute value of index,
228 * instead of starting at 0 (lets out slot 1, but that's one
229 * of the problem slots down low - the vndevice). -12 is
230 * currently a safe starting point.
233 cdevsw_add(int index
, struct cdevsw
* csw
)
235 struct cdevsw
*devsw
;
239 index
= 0; /* historical behaviour; XXX broken */
241 index
= -index
; /* start at least this far up in the table */
242 devsw
= &cdevsw
[index
];
243 for(; index
< nchrdev
; index
++, devsw
++) {
244 if(memcmp((char *)devsw
,
246 sizeof(struct cdevsw
)) == 0)
250 devsw
= &cdevsw
[index
];
251 if ((index
< 0) || (index
>= nchrdev
) ||
252 (memcmp((char *)devsw
,
254 sizeof(struct cdevsw
)) != 0)) {
257 cdevsw
[index
] = *csw
;
261 * if the index has the same bsw, then remove
265 cdevsw_remove(int index
, struct cdevsw
* csw
)
267 struct cdevsw
*devsw
;
269 devsw
= &cdevsw
[index
];
270 if ((index
< 0) || (index
>= nchrdev
) ||
271 (memcmp((char *)devsw
,
273 sizeof(struct cdevsw
)) != 0)) {
276 cdevsw
[index
] = nocdev
;
281 cdev_set_bdev(int cdev
, int bdev
)
283 return (chrtoblk_set(cdev
, bdev
));
287 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
289 index
= cdevsw_add(index
, csw
);
293 if (cdev_set_bdev(index
, bdev
) < 0) {
294 cdevsw_remove(index
, csw
);
300 #include <pexpert/pexpert.h> /* for PE_parse_boot_arg */
303 * Notes: This function is used solely by UFS, apparently in an effort
304 * to work around an issue with single user mounts.
306 * It's not technically correct to reference PE_parse_boot_arg()
314 if (PE_parse_boot_argn("-s", namep
, sizeof(namep
))) {
324 struct proc
*p
= procp
;
327 OSBitOrAtomic(P_TBE
, (UInt32
*)&p
->p_flag
);