]>
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_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <kern/task.h>
32 #include <kern/thread.h>
33 #include <mach/mach_types.h>
34 #include <mach/vm_prot.h>
35 #include <vm/vm_kern.h>
36 #include <vm/vm_map.h>
37 #include <sys/systm.h>
39 #include <sys/proc_internal.h>
40 #include <sys/buf.h> /* for SET */
42 #include <sys/sysent.h>
43 #include <sys/sysproto.h>
45 /* Just to satisfy pstat command */
46 int dmmin
, dmmax
, dmtext
;
49 kmem_mb_alloc(vm_map_t mbmap
, int size
)
52 if (kernel_memory_allocate(mbmap
, &addr
, size
,
54 KMA_NOPAGEWAIT
|KMA_KOBJECT
|KMA_LOMEM
) == KERN_SUCCESS
)
62 * XXX this function only exists to be exported and do nothing.
72 /* Never returns a NULL */
75 thread_t thr_act
= current_thread();
77 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
78 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
80 if ((p
->p_flag
& P_INVFORK
) == 0)
81 panic("returning child proc not under vfork");
82 if (p
->p_vforkact
!= (void *)thr_act
)
83 panic("returning child proc which is not cur_act");
87 p
= (struct proc
*)get_bsdtask_info(current_task());
95 /* Device switch add delete routines */
97 extern int nblkdev
, nchrdev
;
99 struct bdevsw nobdev
= NO_BDEVICE
;
100 struct cdevsw nocdev
= NO_CDEVICE
;
102 * if index is -1, return a free slot if avaliable
103 * else see whether the index is free
104 * return the major number that is free else -1
108 bdevsw_isfree(int index
)
110 struct bdevsw
*devsw
;
113 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
114 if(memcmp((char *)devsw
,
116 sizeof(struct bdevsw
)) == 0)
120 /* NB: Not used below unless index is in range */
121 devsw
= &bdevsw
[index
];
124 if ((index
< 0) || (index
>= nblkdev
) ||
125 (memcmp((char *)devsw
,
127 sizeof(struct bdevsw
)) != 0)) {
134 * if index is -1, find a free slot to add
135 * else see whether the slot is free
136 * return the major number that is used else -1
139 bdevsw_add(int index
, struct bdevsw
* bsw
)
141 struct bdevsw
*devsw
;
144 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
145 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
146 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
147 if(memcmp((char *)devsw
,
149 sizeof(struct bdevsw
)) == 0)
153 devsw
= &bdevsw
[index
];
154 if ((index
< 0) || (index
>= nblkdev
) ||
155 (memcmp((char *)devsw
,
157 sizeof(struct bdevsw
)) != 0)) {
160 bdevsw
[index
] = *bsw
;
164 * if the slot has the same bsw, then remove
168 bdevsw_remove(int index
, struct bdevsw
* bsw
)
170 struct bdevsw
*devsw
;
172 devsw
= &bdevsw
[index
];
173 if ((index
< 0) || (index
>= nblkdev
) ||
174 (memcmp((char *)devsw
,
176 sizeof(struct bdevsw
)) != 0)) {
179 bdevsw
[index
] = nobdev
;
184 * if index is -1, return a free slot if avaliable
185 * else see whether the index is free
186 * return the major number that is free else -1
189 cdevsw_isfree(int index
)
191 struct cdevsw
*devsw
;
195 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
196 if(memcmp((char *)devsw
,
198 sizeof(struct cdevsw
)) == 0)
202 devsw
= &cdevsw
[index
];
203 if ((index
< 0) || (index
>= nchrdev
) ||
204 (memcmp((char *)devsw
,
206 sizeof(struct cdevsw
)) != 0)) {
213 * if index is -1, find a free slot to add
214 * else see whether the slot is free
215 * return the major number that is used else -1
218 cdevsw_add(int index
, struct cdevsw
* csw
)
220 struct cdevsw
*devsw
;
224 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
225 if(memcmp((char *)devsw
,
227 sizeof(struct cdevsw
)) == 0)
231 devsw
= &cdevsw
[index
];
232 if ((index
< 0) || (index
>= nchrdev
) ||
233 (memcmp((char *)devsw
,
235 sizeof(struct cdevsw
)) != 0)) {
238 cdevsw
[index
] = *csw
;
242 * if the index has the same bsw, then remove
246 cdevsw_remove(int index
, struct cdevsw
* csw
)
248 struct cdevsw
*devsw
;
250 devsw
= &cdevsw
[index
];
251 if ((index
< 0) || (index
>= nchrdev
) ||
252 (memcmp((char *)devsw
,
254 sizeof(struct cdevsw
)) != 0)) {
257 cdevsw
[index
] = nocdev
;
262 cdev_set_bdev(int cdev
, int bdev
)
264 extern int chrtoblk_add(int cdev
, int bdev
);
266 return (chrtoblk_set(cdev
, bdev
));
270 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
272 index
= cdevsw_add(index
, csw
);
276 if (cdev_set_bdev(index
, bdev
) < 0) {
277 cdevsw_remove(index
, csw
);
288 if (PE_parse_boot_arg("-s", namep
)) {
298 struct proc
*p
= procp
;
301 SET(p
->p_flag
, P_TBE
);
307 * WARNING - this is a temporary workaround for binary compatibility issues
308 * with anti-piracy software that relies on patching ptrace (3928003).
309 * This KPI will be removed in the system release after Tiger.
311 uintptr_t temp_patch_ptrace(uintptr_t new_ptrace
)
313 struct sysent
* callp
;
314 sy_call_t
* old_ptrace
;
316 boolean_t funnel_state
;
323 enter_funnel_section(kernel_flock
);
325 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
328 old_ptrace
= callp
->sy_call
;
330 /* only allow one patcher of ptrace */
331 if (old_ptrace
== (sy_call_t
*) ptrace
) {
332 callp
->sy_call
= (sy_call_t
*) new_ptrace
;
338 exit_funnel_section( );
340 (void)thread_funnel_set(kernel_flock
, funnel_state
);
343 return((uintptr_t)old_ptrace
);
346 void temp_unpatch_ptrace(void)
348 struct sysent
* callp
;
350 boolean_t funnel_state
;
354 enter_funnel_section(kernel_flock
);
356 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
359 callp
->sy_call
= (sy_call_t
*) ptrace
;
361 exit_funnel_section( );
363 (void)thread_funnel_set(kernel_flock
, funnel_state
);