]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_stubs.c
cc8e42431c09565efe290d42180f5e567a357053
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 */
40 #include <sys/sysent.h>
41 #include <sys/sysproto.h>
43 /* Just to satisfy pstat command */
44 int dmmin
, dmmax
, dmtext
;
47 kmem_mb_alloc(vm_map_t mbmap
, int size
)
50 if (kernel_memory_allocate(mbmap
, &addr
, size
,
52 KMA_NOPAGEWAIT
|KMA_KOBJECT
|KMA_LOMEM
) == KERN_SUCCESS
)
60 * XXX this function only exists to be exported and do nothing.
70 /* Never returns a NULL */
73 thread_t thr_act
= current_thread();
75 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
76 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
78 if ((p
->p_flag
& P_INVFORK
) == 0)
79 panic("returning child proc not under vfork");
80 if (p
->p_vforkact
!= (void *)thr_act
)
81 panic("returning child proc which is not cur_act");
85 p
= (struct proc
*)get_bsdtask_info(current_task());
93 /* Device switch add delete routines */
95 extern int nblkdev
, nchrdev
;
97 struct bdevsw nobdev
= NO_BDEVICE
;
98 struct cdevsw nocdev
= NO_CDEVICE
;
100 * if index is -1, return a free slot if avaliable
101 * else see whether the index is free
102 * return the major number that is free else -1
106 bdevsw_isfree(int index
)
108 struct bdevsw
*devsw
;
111 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
112 if(memcmp((char *)devsw
,
114 sizeof(struct bdevsw
)) == 0)
118 /* NB: Not used below unless index is in range */
119 devsw
= &bdevsw
[index
];
122 if ((index
< 0) || (index
>= nblkdev
) ||
123 (memcmp((char *)devsw
,
125 sizeof(struct bdevsw
)) != 0)) {
132 * if index is -1, find a free slot to add
133 * else see whether the slot is free
134 * return the major number that is used else -1
137 bdevsw_add(int index
, struct bdevsw
* bsw
)
139 struct bdevsw
*devsw
;
142 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
143 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
144 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
145 if(memcmp((char *)devsw
,
147 sizeof(struct bdevsw
)) == 0)
151 devsw
= &bdevsw
[index
];
152 if ((index
< 0) || (index
>= nblkdev
) ||
153 (memcmp((char *)devsw
,
155 sizeof(struct bdevsw
)) != 0)) {
158 bdevsw
[index
] = *bsw
;
162 * if the slot has the same bsw, then remove
166 bdevsw_remove(int index
, struct bdevsw
* bsw
)
168 struct bdevsw
*devsw
;
170 devsw
= &bdevsw
[index
];
171 if ((index
< 0) || (index
>= nblkdev
) ||
172 (memcmp((char *)devsw
,
174 sizeof(struct bdevsw
)) != 0)) {
177 bdevsw
[index
] = nobdev
;
182 * if index is -1, return a free slot if avaliable
183 * else see whether the index is free
184 * return the major number that is free else -1
187 cdevsw_isfree(int index
)
189 struct cdevsw
*devsw
;
193 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
194 if(memcmp((char *)devsw
,
196 sizeof(struct cdevsw
)) == 0)
200 devsw
= &cdevsw
[index
];
201 if ((index
< 0) || (index
>= nchrdev
) ||
202 (memcmp((char *)devsw
,
204 sizeof(struct cdevsw
)) != 0)) {
211 * if index is -1, find a free slot to add
212 * else see whether the slot is free
213 * return the major number that is used else -1
216 cdevsw_add(int index
, struct cdevsw
* csw
)
218 struct cdevsw
*devsw
;
222 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
223 if(memcmp((char *)devsw
,
225 sizeof(struct cdevsw
)) == 0)
229 devsw
= &cdevsw
[index
];
230 if ((index
< 0) || (index
>= nchrdev
) ||
231 (memcmp((char *)devsw
,
233 sizeof(struct cdevsw
)) != 0)) {
236 cdevsw
[index
] = *csw
;
240 * if the index has the same bsw, then remove
244 cdevsw_remove(int index
, struct cdevsw
* csw
)
246 struct cdevsw
*devsw
;
248 devsw
= &cdevsw
[index
];
249 if ((index
< 0) || (index
>= nchrdev
) ||
250 (memcmp((char *)devsw
,
252 sizeof(struct cdevsw
)) != 0)) {
255 cdevsw
[index
] = nocdev
;
260 cdev_set_bdev(int cdev
, int bdev
)
262 extern int chrtoblk_add(int cdev
, int bdev
);
264 return (chrtoblk_set(cdev
, bdev
));
268 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
270 index
= cdevsw_add(index
, csw
);
274 if (cdev_set_bdev(index
, bdev
) < 0) {
275 cdevsw_remove(index
, csw
);
286 if (PE_parse_boot_arg("-s", namep
)) {
296 struct proc
*p
= procp
;
299 SET(p
->p_flag
, P_TBE
);
305 * WARNING - this is a temporary workaround for binary compatibility issues
306 * with anti-piracy software that relies on patching ptrace (3928003).
307 * This KPI will be removed in the system release after Tiger.
309 uintptr_t temp_patch_ptrace(uintptr_t new_ptrace
)
311 struct sysent
* callp
;
312 sy_call_t
* old_ptrace
;
314 boolean_t funnel_state
;
321 enter_funnel_section(kernel_flock
);
323 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
326 old_ptrace
= callp
->sy_call
;
328 /* only allow one patcher of ptrace */
329 if (old_ptrace
== (sy_call_t
*) ptrace
) {
330 callp
->sy_call
= (sy_call_t
*) new_ptrace
;
336 exit_funnel_section( );
338 (void)thread_funnel_set(kernel_flock
, funnel_state
);
341 return((uintptr_t)old_ptrace
);
344 void temp_unpatch_ptrace(void)
346 struct sysent
* callp
;
348 boolean_t funnel_state
;
352 enter_funnel_section(kernel_flock
);
354 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
357 callp
->sy_call
= (sy_call_t
*) ptrace
;
359 exit_funnel_section( );
361 (void)thread_funnel_set(kernel_flock
, funnel_state
);