]>
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_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <kern/task.h>
30 #include <kern/thread.h>
31 #include <mach/mach_types.h>
32 #include <mach/vm_prot.h>
33 #include <vm/vm_kern.h>
34 #include <vm/vm_map.h>
35 #include <sys/systm.h>
37 #include <sys/proc_internal.h>
38 #include <sys/buf.h> /* for SET */
39 #include <sys/kernel.h>
41 #include <sys/sysent.h>
42 #include <sys/sysproto.h>
44 /* XXX these should be in a common header somwhere, but aren't */
45 extern int chrtoblk_set(int, int);
46 extern vm_offset_t
kmem_mb_alloc(vm_map_t
, int, int);
48 /* XXX most of these just exist to export; there's no good header for them*/
53 /* Just to satisfy pstat command */
54 int dmmin
, dmmax
, dmtext
;
57 kmem_mb_alloc(vm_map_t mbmap
, int size
, int physContig
)
60 kern_return_t kr
= KERN_SUCCESS
;
63 kr
= kernel_memory_allocate(mbmap
, &addr
, size
,
64 0, KMA_NOPAGEWAIT
|KMA_KOBJECT
|KMA_LOMEM
);
66 kr
= kmem_alloc_contig(mbmap
, &addr
, size
, PAGE_MASK
,
67 0xfffff, 0, KMA_NOPAGEWAIT
| KMA_KOBJECT
| KMA_LOMEM
);
69 if( kr
!= KERN_SUCCESS
)
76 * XXX this function only exists to be exported and do nothing.
86 /* Never returns a NULL */
89 thread_t thread
= current_thread();
91 ut
= (struct uthread
*)get_bsdthread_info(thread
);
92 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
94 if ((p
->p_lflag
& P_LINVFORK
) == 0)
95 panic("returning child proc not under vfork");
96 if (p
->p_vforkact
!= (void *)thread
)
97 panic("returning child proc which is not cur_act");
101 p
= (struct proc
*)get_bsdtask_info(current_task());
109 /* Device switch add delete routines */
111 struct bdevsw nobdev
= NO_BDEVICE
;
112 struct cdevsw nocdev
= NO_CDEVICE
;
114 * if index is -1, return a free slot if avaliable
115 * else see whether the index is free
116 * return the major number that is free else -1
120 bdevsw_isfree(int index
)
122 struct bdevsw
*devsw
;
125 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
126 if(memcmp((char *)devsw
,
128 sizeof(struct bdevsw
)) == 0)
132 /* NB: Not used below unless index is in range */
133 devsw
= &bdevsw
[index
];
136 if ((index
< 0) || (index
>= nblkdev
) ||
137 (memcmp((char *)devsw
,
139 sizeof(struct bdevsw
)) != 0)) {
146 * if index is -1, find a free slot to add
147 * else see whether the slot is free
148 * return the major number that is used else -1
151 bdevsw_add(int index
, struct bdevsw
* bsw
)
153 struct bdevsw
*devsw
;
156 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
157 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
158 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
159 if(memcmp((char *)devsw
,
161 sizeof(struct bdevsw
)) == 0)
165 devsw
= &bdevsw
[index
];
166 if ((index
< 0) || (index
>= nblkdev
) ||
167 (memcmp((char *)devsw
,
169 sizeof(struct bdevsw
)) != 0)) {
172 bdevsw
[index
] = *bsw
;
176 * if the slot has the same bsw, then remove
180 bdevsw_remove(int index
, struct bdevsw
* bsw
)
182 struct bdevsw
*devsw
;
184 devsw
= &bdevsw
[index
];
185 if ((index
< 0) || (index
>= nblkdev
) ||
186 (memcmp((char *)devsw
,
188 sizeof(struct bdevsw
)) != 0)) {
191 bdevsw
[index
] = nobdev
;
196 * if index is -1, return a free slot if avaliable
197 * else see whether the index is free
198 * return the major number that is free else -1
201 cdevsw_isfree(int index
)
203 struct cdevsw
*devsw
;
207 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
208 if(memcmp((char *)devsw
,
210 sizeof(struct cdevsw
)) == 0)
214 devsw
= &cdevsw
[index
];
215 if ((index
< 0) || (index
>= nchrdev
) ||
216 (memcmp((char *)devsw
,
218 sizeof(struct cdevsw
)) != 0)) {
225 * if index is -1, find a free slot to add
226 * else see whether the slot is free
227 * return the major number that is used else -1
229 * NOTE: In practice, -1 is unusable, since there are kernel internal
230 * devices that call this function with absolute index values,
231 * which will stomp on free-slot based assignments that happen
232 * before them. Therefore, if index is negative, we start
233 * looking for a free slot at the absolute value of index,
234 * instead of starting at 0 (lets out slot 1, but that's one
235 * of the problem slots down low - the vndevice). -12 is
236 * currently a safe starting point.
239 cdevsw_add(int index
, struct cdevsw
* csw
)
241 struct cdevsw
*devsw
;
245 index
= 0; /* historical behaviour; XXX broken */
247 index
= -index
; /* start at least this far up in the table */
248 devsw
= &cdevsw
[index
];
249 for(; index
< nchrdev
; index
++, devsw
++) {
250 if(memcmp((char *)devsw
,
252 sizeof(struct cdevsw
)) == 0)
256 devsw
= &cdevsw
[index
];
257 if ((index
< 0) || (index
>= nchrdev
) ||
258 (memcmp((char *)devsw
,
260 sizeof(struct cdevsw
)) != 0)) {
263 cdevsw
[index
] = *csw
;
267 * if the index has the same bsw, then remove
271 cdevsw_remove(int index
, struct cdevsw
* csw
)
273 struct cdevsw
*devsw
;
275 devsw
= &cdevsw
[index
];
276 if ((index
< 0) || (index
>= nchrdev
) ||
277 (memcmp((char *)devsw
,
279 sizeof(struct cdevsw
)) != 0)) {
282 cdevsw
[index
] = nocdev
;
287 cdev_set_bdev(int cdev
, int bdev
)
289 return (chrtoblk_set(cdev
, bdev
));
293 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
295 index
= cdevsw_add(index
, csw
);
299 if (cdev_set_bdev(index
, bdev
) < 0) {
300 cdevsw_remove(index
, csw
);
306 #include <pexpert/pexpert.h> /* for PE_parse_boot_arg */
311 struct proc
*p
= procp
;
314 OSBitOrAtomic(P_TBE
, &p
->p_flag
);
319 * Copy the "hostname" variable into a caller-provided buffer
320 * Returns: 0 for success, ENAMETOOLONG for insufficient buffer space.
321 * On success, "len" will be set to the number of characters preceding
322 * the NULL character in the hostname.
325 bsd_hostname(char *buf
, int bufsize
, int *len
)
328 * "hostname" is null-terminated, and "hostnamelen" is equivalent to strlen(hostname).
330 if (hostnamelen
< bufsize
) {
331 strlcpy(buf
, hostname
, bufsize
);