]>
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/proc_internal.h>
32 #include <sys/buf.h> /* for SET */
35 /* Just to satisfy pstat command */
36 int dmmin
, dmmax
, dmtext
;
39 kmem_mb_alloc(vm_map_t mbmap
, int size
)
42 if (kernel_memory_allocate(mbmap
, &addr
, size
,
44 KMA_NOPAGEWAIT
|KMA_KOBJECT
) == KERN_SUCCESS
)
52 * XXX this function only exists to be exported and do nothing.
62 /* Never returns a NULL */
65 thread_t thr_act
= current_thread();
67 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
68 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
70 if ((p
->p_flag
& P_INVFORK
) == 0)
71 panic("returning child proc not under vfork");
72 if (p
->p_vforkact
!= (void *)thr_act
)
73 panic("returning child proc which is not cur_act");
77 p
= (struct proc
*)get_bsdtask_info(current_task());
85 /* Device switch add delete routines */
87 extern int nblkdev
, nchrdev
;
89 struct bdevsw nobdev
= NO_BDEVICE
;
90 struct cdevsw nocdev
= NO_CDEVICE
;
92 * if index is -1, return a free slot if avaliable
93 * else see whether the index is free
94 * return the major number that is free else -1
98 bdevsw_isfree(int index
)
100 struct bdevsw
*devsw
;
103 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
104 if(memcmp((char *)devsw
,
106 sizeof(struct bdevsw
)) == 0)
110 /* NB: Not used below unless index is in range */
111 devsw
= &bdevsw
[index
];
114 if ((index
< 0) || (index
>= nblkdev
) ||
115 (memcmp((char *)devsw
,
117 sizeof(struct bdevsw
)) != 0)) {
124 * if index is -1, find a free slot to add
125 * else see whether the slot is free
126 * return the major number that is used else -1
129 bdevsw_add(int index
, struct bdevsw
* bsw
)
131 struct bdevsw
*devsw
;
134 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
135 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
136 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
137 if(memcmp((char *)devsw
,
139 sizeof(struct bdevsw
)) == 0)
143 devsw
= &bdevsw
[index
];
144 if ((index
< 0) || (index
>= nblkdev
) ||
145 (memcmp((char *)devsw
,
147 sizeof(struct bdevsw
)) != 0)) {
150 bdevsw
[index
] = *bsw
;
154 * if the slot has the same bsw, then remove
158 bdevsw_remove(int index
, struct bdevsw
* bsw
)
160 struct bdevsw
*devsw
;
162 devsw
= &bdevsw
[index
];
163 if ((index
< 0) || (index
>= nblkdev
) ||
164 (memcmp((char *)devsw
,
166 sizeof(struct bdevsw
)) != 0)) {
169 bdevsw
[index
] = nobdev
;
174 * if index is -1, return a free slot if avaliable
175 * else see whether the index is free
176 * return the major number that is free else -1
179 cdevsw_isfree(int index
)
181 struct cdevsw
*devsw
;
185 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
186 if(memcmp((char *)devsw
,
188 sizeof(struct cdevsw
)) == 0)
192 devsw
= &cdevsw
[index
];
193 if ((index
< 0) || (index
>= nchrdev
) ||
194 (memcmp((char *)devsw
,
196 sizeof(struct cdevsw
)) != 0)) {
203 * if index is -1, find a free slot to add
204 * else see whether the slot is free
205 * return the major number that is used else -1
208 cdevsw_add(int index
, struct cdevsw
* csw
)
210 struct cdevsw
*devsw
;
214 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
215 if(memcmp((char *)devsw
,
217 sizeof(struct cdevsw
)) == 0)
221 devsw
= &cdevsw
[index
];
222 if ((index
< 0) || (index
>= nchrdev
) ||
223 (memcmp((char *)devsw
,
225 sizeof(struct cdevsw
)) != 0)) {
228 cdevsw
[index
] = *csw
;
232 * if the index has the same bsw, then remove
236 cdevsw_remove(int index
, struct cdevsw
* csw
)
238 struct cdevsw
*devsw
;
240 devsw
= &cdevsw
[index
];
241 if ((index
< 0) || (index
>= nchrdev
) ||
242 (memcmp((char *)devsw
,
244 sizeof(struct cdevsw
)) != 0)) {
247 cdevsw
[index
] = nocdev
;
252 cdev_set_bdev(int cdev
, int bdev
)
254 extern int chrtoblk_add(int cdev
, int bdev
);
256 return (chrtoblk_set(cdev
, bdev
));
260 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
262 index
= cdevsw_add(index
, csw
);
266 if (cdev_set_bdev(index
, bdev
) < 0) {
267 cdevsw_remove(index
, csw
);
278 if (PE_parse_boot_arg("-s", namep
)) {
288 struct proc
*p
= procp
;
291 SET(p
->p_flag
, P_TBE
);