]>
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_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <kern/task.h>
25 #include <kern/thread.h>
26 #include <mach/mach_types.h>
27 #include <mach/vm_prot.h>
28 #include <vm/vm_kern.h>
29 #include <vm/vm_map.h>
30 #include <sys/systm.h>
32 #include <sys/proc_internal.h>
33 #include <sys/buf.h> /* for SET */
36 /* Just to satisfy pstat command */
37 int dmmin
, dmmax
, dmtext
;
40 kmem_mb_alloc(vm_map_t mbmap
, int size
)
43 if (kernel_memory_allocate(mbmap
, &addr
, size
,
45 KMA_NOPAGEWAIT
|KMA_KOBJECT
) == KERN_SUCCESS
)
53 * XXX this function only exists to be exported and do nothing.
63 /* Never returns a NULL */
66 thread_t thr_act
= current_thread();
68 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
69 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
71 if ((p
->p_flag
& P_INVFORK
) == 0)
72 panic("returning child proc not under vfork");
73 if (p
->p_vforkact
!= (void *)thr_act
)
74 panic("returning child proc which is not cur_act");
78 p
= (struct proc
*)get_bsdtask_info(current_task());
86 /* Device switch add delete routines */
88 extern int nblkdev
, nchrdev
;
90 struct bdevsw nobdev
= NO_BDEVICE
;
91 struct cdevsw nocdev
= NO_CDEVICE
;
93 * if index is -1, return a free slot if avaliable
94 * else see whether the index is free
95 * return the major number that is free else -1
99 bdevsw_isfree(int index
)
101 struct bdevsw
*devsw
;
104 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
105 if(memcmp((char *)devsw
,
107 sizeof(struct bdevsw
)) == 0)
111 /* NB: Not used below unless index is in range */
112 devsw
= &bdevsw
[index
];
115 if ((index
< 0) || (index
>= nblkdev
) ||
116 (memcmp((char *)devsw
,
118 sizeof(struct bdevsw
)) != 0)) {
125 * if index is -1, find a free slot to add
126 * else see whether the slot is free
127 * return the major number that is used else -1
130 bdevsw_add(int index
, struct bdevsw
* bsw
)
132 struct bdevsw
*devsw
;
135 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
136 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
137 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
138 if(memcmp((char *)devsw
,
140 sizeof(struct bdevsw
)) == 0)
144 devsw
= &bdevsw
[index
];
145 if ((index
< 0) || (index
>= nblkdev
) ||
146 (memcmp((char *)devsw
,
148 sizeof(struct bdevsw
)) != 0)) {
151 bdevsw
[index
] = *bsw
;
155 * if the slot has the same bsw, then remove
159 bdevsw_remove(int index
, struct bdevsw
* bsw
)
161 struct bdevsw
*devsw
;
163 devsw
= &bdevsw
[index
];
164 if ((index
< 0) || (index
>= nblkdev
) ||
165 (memcmp((char *)devsw
,
167 sizeof(struct bdevsw
)) != 0)) {
170 bdevsw
[index
] = nobdev
;
175 * if index is -1, return a free slot if avaliable
176 * else see whether the index is free
177 * return the major number that is free else -1
180 cdevsw_isfree(int index
)
182 struct cdevsw
*devsw
;
186 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
187 if(memcmp((char *)devsw
,
189 sizeof(struct cdevsw
)) == 0)
193 devsw
= &cdevsw
[index
];
194 if ((index
< 0) || (index
>= nchrdev
) ||
195 (memcmp((char *)devsw
,
197 sizeof(struct cdevsw
)) != 0)) {
204 * if index is -1, find a free slot to add
205 * else see whether the slot is free
206 * return the major number that is used else -1
209 cdevsw_add(int index
, struct cdevsw
* csw
)
211 struct cdevsw
*devsw
;
215 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
216 if(memcmp((char *)devsw
,
218 sizeof(struct cdevsw
)) == 0)
222 devsw
= &cdevsw
[index
];
223 if ((index
< 0) || (index
>= nchrdev
) ||
224 (memcmp((char *)devsw
,
226 sizeof(struct cdevsw
)) != 0)) {
229 cdevsw
[index
] = *csw
;
233 * if the index has the same bsw, then remove
237 cdevsw_remove(int index
, struct cdevsw
* csw
)
239 struct cdevsw
*devsw
;
241 devsw
= &cdevsw
[index
];
242 if ((index
< 0) || (index
>= nchrdev
) ||
243 (memcmp((char *)devsw
,
245 sizeof(struct cdevsw
)) != 0)) {
248 cdevsw
[index
] = nocdev
;
253 cdev_set_bdev(int cdev
, int bdev
)
255 extern int chrtoblk_add(int cdev
, int bdev
);
257 return (chrtoblk_set(cdev
, bdev
));
261 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
263 index
= cdevsw_add(index
, csw
);
267 if (cdev_set_bdev(index
, bdev
) < 0) {
268 cdevsw_remove(index
, csw
);
279 if (PE_parse_boot_arg("-s", namep
)) {
289 struct proc
*p
= procp
;
292 SET(p
->p_flag
, P_TBE
);