]>
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 */
33 /* Just to satisfy pstat command */
34 int dmmin
, dmmax
, dmtext
;
36 kmem_mb_alloc(vm_map_t mbmap
, int size
)
39 if (kernel_memory_allocate(mbmap
, &addr
, size
,
41 KMA_NOPAGEWAIT
|KMA_KOBJECT
) == KERN_SUCCESS
)
55 /* Never returns a NULL */
56 struct proc
*p
= (struct proc
*)get_bsdtask_info(current_task());
62 /* Device switch add delete routines */
64 extern int nblkdev
, nchrdev
;
66 struct bdevsw nobdev
= NO_BDEVICE
;
67 struct cdevsw nocdev
= NO_CDEVICE
;
69 * if index is -1, return a free slot if avaliable
70 * else see whether the index is free
71 * return the major number that is free else -1
75 bdevsw_isfree(int index
)
80 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
81 if(memcmp((char *)devsw
,
83 sizeof(struct bdevsw
)) == 0)
88 if ((index
< 0) || (index
>= nblkdev
) ||
89 (memcmp((char *)devsw
,
91 sizeof(struct bdevsw
)) != 0)) {
98 * if index is -1, find a free slot to add
99 * else see whether the slot is free
100 * return the major number that is used else -1
103 bdevsw_add(int index
, struct bdevsw
* bsw
)
105 struct bdevsw
*devsw
;
109 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
110 if(memcmp((char *)devsw
,
112 sizeof(struct bdevsw
)) == 0)
116 devsw
= &bdevsw
[index
];
117 if ((index
< 0) || (index
>= nblkdev
) ||
118 (memcmp((char *)devsw
,
120 sizeof(struct bdevsw
)) != 0)) {
123 bdevsw
[index
] = *bsw
;
127 * if the slot has the same bsw, then remove
131 bdevsw_remove(int index
, struct bdevsw
* bsw
)
133 struct bdevsw
*devsw
;
135 devsw
= &bdevsw
[index
];
136 if ((index
< 0) || (index
>= nblkdev
) ||
137 (memcmp((char *)devsw
,
139 sizeof(struct bdevsw
)) != 0)) {
142 bdevsw
[index
] = nobdev
;
147 * if index is -1, return a free slot if avaliable
148 * else see whether the index is free
149 * return the major number that is free else -1
152 cdevsw_isfree(int index
)
154 struct cdevsw
*devsw
;
158 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
159 if(memcmp((char *)devsw
,
161 sizeof(struct cdevsw
)) == 0)
165 devsw
= &cdevsw
[index
];
166 if ((index
< 0) || (index
>= nchrdev
) ||
167 (memcmp((char *)devsw
,
169 sizeof(struct cdevsw
)) != 0)) {
176 * if index is -1, find a free slot to add
177 * else see whether the slot is free
178 * return the major number that is used else -1
181 cdevsw_add(int index
, struct cdevsw
* csw
)
183 struct cdevsw
*devsw
;
187 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
188 if(memcmp((char *)devsw
,
190 sizeof(struct cdevsw
)) == 0)
194 devsw
= &cdevsw
[index
];
195 if ((index
< 0) || (index
>= nchrdev
) ||
196 (memcmp((char *)devsw
,
198 sizeof(struct cdevsw
)) != 0)) {
201 cdevsw
[index
] = *csw
;
205 * if the index has the same bsw, then remove
209 cdevsw_remove(int index
, struct cdevsw
* csw
)
211 struct cdevsw
*devsw
;
213 devsw
= &cdevsw
[index
];
214 if ((index
< 0) || (index
>= nchrdev
) ||
215 (memcmp((char *)devsw
,
217 sizeof(struct cdevsw
)) != 0)) {
220 cdevsw
[index
] = nocdev
;
226 register char *s1
, *s2
;
231 return (*--s1
- *--s2
);
240 if (PE_parse_boot_arg("-s", namep
)) {
250 struct proc
*p
= procp
;
253 SET(p
->p_flag
, P_TBE
);