]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_stubs.c
8a41d1d8df5347784afa76179b5c5bb1584df0a5
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
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>
34 #include <sys/buf.h> /* for SET */
37 /* Just to satisfy pstat command */
38 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
)
57 /* Never returns a NULL */
60 thread_act_t thr_act
= current_act();
62 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
63 if (ut
&& (ut
->uu_flag
& P_VFORK
) && 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");
72 p
= (struct proc
*)get_bsdtask_info(current_task());
80 /* Device switch add delete routines */
82 extern int nblkdev
, nchrdev
;
84 struct bdevsw nobdev
= NO_BDEVICE
;
85 struct cdevsw nocdev
= NO_CDEVICE
;
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
93 bdevsw_isfree(int index
)
98 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
99 if(memcmp((char *)devsw
,
101 sizeof(struct bdevsw
)) == 0)
106 if ((index
< 0) || (index
>= nblkdev
) ||
107 (memcmp((char *)devsw
,
109 sizeof(struct bdevsw
)) != 0)) {
116 * if index is -1, find a free slot to add
117 * else see whether the slot is free
118 * return the major number that is used else -1
121 bdevsw_add(int index
, struct bdevsw
* bsw
)
123 struct bdevsw
*devsw
;
126 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
127 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
128 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
129 if(memcmp((char *)devsw
,
131 sizeof(struct bdevsw
)) == 0)
135 devsw
= &bdevsw
[index
];
136 if ((index
< 0) || (index
>= nblkdev
) ||
137 (memcmp((char *)devsw
,
139 sizeof(struct bdevsw
)) != 0)) {
142 bdevsw
[index
] = *bsw
;
146 * if the slot has the same bsw, then remove
150 bdevsw_remove(int index
, struct bdevsw
* bsw
)
152 struct bdevsw
*devsw
;
154 devsw
= &bdevsw
[index
];
155 if ((index
< 0) || (index
>= nblkdev
) ||
156 (memcmp((char *)devsw
,
158 sizeof(struct bdevsw
)) != 0)) {
161 bdevsw
[index
] = nobdev
;
166 * if index is -1, return a free slot if avaliable
167 * else see whether the index is free
168 * return the major number that is free else -1
171 cdevsw_isfree(int index
)
173 struct cdevsw
*devsw
;
177 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
178 if(memcmp((char *)devsw
,
180 sizeof(struct cdevsw
)) == 0)
184 devsw
= &cdevsw
[index
];
185 if ((index
< 0) || (index
>= nchrdev
) ||
186 (memcmp((char *)devsw
,
188 sizeof(struct cdevsw
)) != 0)) {
195 * if index is -1, find a free slot to add
196 * else see whether the slot is free
197 * return the major number that is used else -1
200 cdevsw_add(int index
, struct cdevsw
* csw
)
202 struct cdevsw
*devsw
;
206 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
207 if(memcmp((char *)devsw
,
209 sizeof(struct cdevsw
)) == 0)
213 devsw
= &cdevsw
[index
];
214 if ((index
< 0) || (index
>= nchrdev
) ||
215 (memcmp((char *)devsw
,
217 sizeof(struct cdevsw
)) != 0)) {
220 cdevsw
[index
] = *csw
;
224 * if the index has the same bsw, then remove
228 cdevsw_remove(int index
, struct cdevsw
* csw
)
230 struct cdevsw
*devsw
;
232 devsw
= &cdevsw
[index
];
233 if ((index
< 0) || (index
>= nchrdev
) ||
234 (memcmp((char *)devsw
,
236 sizeof(struct cdevsw
)) != 0)) {
239 cdevsw
[index
] = nocdev
;
244 cdev_set_bdev(int cdev
, int bdev
)
246 extern int chrtoblk_add(int cdev
, int bdev
);
248 return (chrtoblk_set(cdev
, bdev
));
252 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
254 index
= cdevsw_add(index
, csw
);
258 if (cdev_set_bdev(index
, bdev
) < 0) {
259 cdevsw_remove(index
, csw
);
270 if (PE_parse_boot_arg("-s", namep
)) {
280 struct proc
*p
= procp
;
283 SET(p
->p_flag
, P_TBE
);