]>
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 * 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.
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
20 * @APPLE_LICENSE_HEADER_END@
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>
31 #include <sys/buf.h> /* for SET */
34 /* Just to satisfy pstat command */
35 int dmmin
, dmmax
, dmtext
;
37 kmem_mb_alloc(vm_map_t mbmap
, int size
)
40 if (kernel_memory_allocate(mbmap
, &addr
, size
,
42 KMA_NOPAGEWAIT
|KMA_KOBJECT
) == KERN_SUCCESS
)
54 /* Never returns a NULL */
57 thread_act_t thr_act
= current_act();
59 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
60 if (ut
&& (ut
->uu_flag
& P_VFORK
) && 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");
69 p
= (struct proc
*)get_bsdtask_info(current_task());
77 /* Device switch add delete routines */
79 extern int nblkdev
, nchrdev
;
81 struct bdevsw nobdev
= NO_BDEVICE
;
82 struct cdevsw nocdev
= NO_CDEVICE
;
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
90 bdevsw_isfree(int index
)
95 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
96 if(memcmp((char *)devsw
,
98 sizeof(struct bdevsw
)) == 0)
102 /* NB: Not used below unless index is in range */
103 devsw
= &bdevsw
[index
];
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
);