]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_stubs.c
70f1088aa137d848ad65e87f87db452eb17f9376
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 */
41 /* Just to satisfy pstat command */
42 int dmmin
, dmmax
, dmtext
;
45 kmem_mb_alloc(vm_map_t mbmap
, int size
)
48 if (kernel_memory_allocate(mbmap
, &addr
, size
,
50 KMA_NOPAGEWAIT
|KMA_KOBJECT
) == KERN_SUCCESS
)
58 * XXX this function only exists to be exported and do nothing.
68 /* Never returns a NULL */
71 thread_t thr_act
= current_thread();
73 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
74 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
76 if ((p
->p_flag
& P_INVFORK
) == 0)
77 panic("returning child proc not under vfork");
78 if (p
->p_vforkact
!= (void *)thr_act
)
79 panic("returning child proc which is not cur_act");
83 p
= (struct proc
*)get_bsdtask_info(current_task());
91 /* Device switch add delete routines */
93 extern int nblkdev
, nchrdev
;
95 struct bdevsw nobdev
= NO_BDEVICE
;
96 struct cdevsw nocdev
= NO_CDEVICE
;
98 * if index is -1, return a free slot if avaliable
99 * else see whether the index is free
100 * return the major number that is free else -1
104 bdevsw_isfree(int index
)
106 struct bdevsw
*devsw
;
109 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
110 if(memcmp((char *)devsw
,
112 sizeof(struct bdevsw
)) == 0)
116 /* NB: Not used below unless index is in range */
117 devsw
= &bdevsw
[index
];
120 if ((index
< 0) || (index
>= nblkdev
) ||
121 (memcmp((char *)devsw
,
123 sizeof(struct bdevsw
)) != 0)) {
130 * if index is -1, find a free slot to add
131 * else see whether the slot is free
132 * return the major number that is used else -1
135 bdevsw_add(int index
, struct bdevsw
* bsw
)
137 struct bdevsw
*devsw
;
140 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
141 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
142 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
143 if(memcmp((char *)devsw
,
145 sizeof(struct bdevsw
)) == 0)
149 devsw
= &bdevsw
[index
];
150 if ((index
< 0) || (index
>= nblkdev
) ||
151 (memcmp((char *)devsw
,
153 sizeof(struct bdevsw
)) != 0)) {
156 bdevsw
[index
] = *bsw
;
160 * if the slot has the same bsw, then remove
164 bdevsw_remove(int index
, struct bdevsw
* bsw
)
166 struct bdevsw
*devsw
;
168 devsw
= &bdevsw
[index
];
169 if ((index
< 0) || (index
>= nblkdev
) ||
170 (memcmp((char *)devsw
,
172 sizeof(struct bdevsw
)) != 0)) {
175 bdevsw
[index
] = nobdev
;
180 * if index is -1, return a free slot if avaliable
181 * else see whether the index is free
182 * return the major number that is free else -1
185 cdevsw_isfree(int index
)
187 struct cdevsw
*devsw
;
191 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
192 if(memcmp((char *)devsw
,
194 sizeof(struct cdevsw
)) == 0)
198 devsw
= &cdevsw
[index
];
199 if ((index
< 0) || (index
>= nchrdev
) ||
200 (memcmp((char *)devsw
,
202 sizeof(struct cdevsw
)) != 0)) {
209 * if index is -1, find a free slot to add
210 * else see whether the slot is free
211 * return the major number that is used else -1
214 cdevsw_add(int index
, struct cdevsw
* csw
)
216 struct cdevsw
*devsw
;
220 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
221 if(memcmp((char *)devsw
,
223 sizeof(struct cdevsw
)) == 0)
227 devsw
= &cdevsw
[index
];
228 if ((index
< 0) || (index
>= nchrdev
) ||
229 (memcmp((char *)devsw
,
231 sizeof(struct cdevsw
)) != 0)) {
234 cdevsw
[index
] = *csw
;
238 * if the index has the same bsw, then remove
242 cdevsw_remove(int index
, struct cdevsw
* csw
)
244 struct cdevsw
*devsw
;
246 devsw
= &cdevsw
[index
];
247 if ((index
< 0) || (index
>= nchrdev
) ||
248 (memcmp((char *)devsw
,
250 sizeof(struct cdevsw
)) != 0)) {
253 cdevsw
[index
] = nocdev
;
258 cdev_set_bdev(int cdev
, int bdev
)
260 extern int chrtoblk_add(int cdev
, int bdev
);
262 return (chrtoblk_set(cdev
, bdev
));
266 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
268 index
= cdevsw_add(index
, csw
);
272 if (cdev_set_bdev(index
, bdev
) < 0) {
273 cdevsw_remove(index
, csw
);
284 if (PE_parse_boot_arg("-s", namep
)) {
294 struct proc
*p
= procp
;
297 SET(p
->p_flag
, P_TBE
);