]>
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
)
56 /* Never returns a NULL */
59 thread_act_t thr_act
= current_act();
61 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
62 if (ut
&& (ut
->uu_flag
& P_VFORK
) && ut
->uu_proc
) {
64 if ((p
->p_flag
& P_INVFORK
) == 0)
65 panic("returning child proc not under vfork");
66 if (p
->p_vforkact
!= (void *)thr_act
)
67 panic("returning child proc which is not cur_act");
71 p
= (struct proc
*)get_bsdtask_info(current_task());
79 /* Device switch add delete routines */
81 extern int nblkdev
, nchrdev
;
83 struct bdevsw nobdev
= NO_BDEVICE
;
84 struct cdevsw nocdev
= NO_CDEVICE
;
86 * if index is -1, return a free slot if avaliable
87 * else see whether the index is free
88 * return the major number that is free else -1
92 bdevsw_isfree(int index
)
97 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
98 if(memcmp((char *)devsw
,
100 sizeof(struct bdevsw
)) == 0)
105 if ((index
< 0) || (index
>= nblkdev
) ||
106 (memcmp((char *)devsw
,
108 sizeof(struct bdevsw
)) != 0)) {
115 * if index is -1, find a free slot to add
116 * else see whether the slot is free
117 * return the major number that is used else -1
120 bdevsw_add(int index
, struct bdevsw
* bsw
)
122 struct bdevsw
*devsw
;
126 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
127 if(memcmp((char *)devsw
,
129 sizeof(struct bdevsw
)) == 0)
133 devsw
= &bdevsw
[index
];
134 if ((index
< 0) || (index
>= nblkdev
) ||
135 (memcmp((char *)devsw
,
137 sizeof(struct bdevsw
)) != 0)) {
140 bdevsw
[index
] = *bsw
;
144 * if the slot has the same bsw, then remove
148 bdevsw_remove(int index
, struct bdevsw
* bsw
)
150 struct bdevsw
*devsw
;
152 devsw
= &bdevsw
[index
];
153 if ((index
< 0) || (index
>= nblkdev
) ||
154 (memcmp((char *)devsw
,
156 sizeof(struct bdevsw
)) != 0)) {
159 bdevsw
[index
] = nobdev
;
164 * if index is -1, return a free slot if avaliable
165 * else see whether the index is free
166 * return the major number that is free else -1
169 cdevsw_isfree(int index
)
171 struct cdevsw
*devsw
;
175 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
176 if(memcmp((char *)devsw
,
178 sizeof(struct cdevsw
)) == 0)
182 devsw
= &cdevsw
[index
];
183 if ((index
< 0) || (index
>= nchrdev
) ||
184 (memcmp((char *)devsw
,
186 sizeof(struct cdevsw
)) != 0)) {
193 * if index is -1, find a free slot to add
194 * else see whether the slot is free
195 * return the major number that is used else -1
198 cdevsw_add(int index
, struct cdevsw
* csw
)
200 struct cdevsw
*devsw
;
204 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
205 if(memcmp((char *)devsw
,
207 sizeof(struct cdevsw
)) == 0)
211 devsw
= &cdevsw
[index
];
212 if ((index
< 0) || (index
>= nchrdev
) ||
213 (memcmp((char *)devsw
,
215 sizeof(struct cdevsw
)) != 0)) {
218 cdevsw
[index
] = *csw
;
222 * if the index has the same bsw, then remove
226 cdevsw_remove(int index
, struct cdevsw
* csw
)
228 struct cdevsw
*devsw
;
230 devsw
= &cdevsw
[index
];
231 if ((index
< 0) || (index
>= nchrdev
) ||
232 (memcmp((char *)devsw
,
234 sizeof(struct cdevsw
)) != 0)) {
237 cdevsw
[index
] = nocdev
;
247 if (PE_parse_boot_arg("-s", namep
)) {
257 struct proc
*p
= procp
;
260 SET(p
->p_flag
, P_TBE
);