]>
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/proc_internal.h>
32 #include <sys/buf.h> /* for SET */
34 #include <sys/sysent.h>
35 #include <sys/sysproto.h>
37 /* Just to satisfy pstat command */
38 int dmmin
, dmmax
, dmtext
;
41 kmem_mb_alloc(vm_map_t mbmap
, int size
)
44 if (kernel_memory_allocate(mbmap
, &addr
, size
,
46 KMA_NOPAGEWAIT
|KMA_KOBJECT
|KMA_LOMEM
) == KERN_SUCCESS
)
54 * XXX this function only exists to be exported and do nothing.
64 /* Never returns a NULL */
67 thread_t thr_act
= current_thread();
69 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
70 if (ut
&& (ut
->uu_flag
& UT_VFORK
) && ut
->uu_proc
) {
72 if ((p
->p_flag
& P_INVFORK
) == 0)
73 panic("returning child proc not under vfork");
74 if (p
->p_vforkact
!= (void *)thr_act
)
75 panic("returning child proc which is not cur_act");
79 p
= (struct proc
*)get_bsdtask_info(current_task());
87 /* Device switch add delete routines */
89 extern int nblkdev
, nchrdev
;
91 struct bdevsw nobdev
= NO_BDEVICE
;
92 struct cdevsw nocdev
= NO_CDEVICE
;
94 * if index is -1, return a free slot if avaliable
95 * else see whether the index is free
96 * return the major number that is free else -1
100 bdevsw_isfree(int index
)
102 struct bdevsw
*devsw
;
105 for(index
=0; index
< nblkdev
; index
++, devsw
++) {
106 if(memcmp((char *)devsw
,
108 sizeof(struct bdevsw
)) == 0)
112 /* NB: Not used below unless index is in range */
113 devsw
= &bdevsw
[index
];
116 if ((index
< 0) || (index
>= nblkdev
) ||
117 (memcmp((char *)devsw
,
119 sizeof(struct bdevsw
)) != 0)) {
126 * if index is -1, find a free slot to add
127 * else see whether the slot is free
128 * return the major number that is used else -1
131 bdevsw_add(int index
, struct bdevsw
* bsw
)
133 struct bdevsw
*devsw
;
136 devsw
= &bdevsw
[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */
137 /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */
138 for(index
=1; index
< nblkdev
; index
++, devsw
++) {
139 if(memcmp((char *)devsw
,
141 sizeof(struct bdevsw
)) == 0)
145 devsw
= &bdevsw
[index
];
146 if ((index
< 0) || (index
>= nblkdev
) ||
147 (memcmp((char *)devsw
,
149 sizeof(struct bdevsw
)) != 0)) {
152 bdevsw
[index
] = *bsw
;
156 * if the slot has the same bsw, then remove
160 bdevsw_remove(int index
, struct bdevsw
* bsw
)
162 struct bdevsw
*devsw
;
164 devsw
= &bdevsw
[index
];
165 if ((index
< 0) || (index
>= nblkdev
) ||
166 (memcmp((char *)devsw
,
168 sizeof(struct bdevsw
)) != 0)) {
171 bdevsw
[index
] = nobdev
;
176 * if index is -1, return a free slot if avaliable
177 * else see whether the index is free
178 * return the major number that is free else -1
181 cdevsw_isfree(int index
)
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)) {
205 * if index is -1, find a free slot to add
206 * else see whether the slot is free
207 * return the major number that is used else -1
210 cdevsw_add(int index
, struct cdevsw
* csw
)
212 struct cdevsw
*devsw
;
216 for(index
=0; index
< nchrdev
; index
++, devsw
++) {
217 if(memcmp((char *)devsw
,
219 sizeof(struct cdevsw
)) == 0)
223 devsw
= &cdevsw
[index
];
224 if ((index
< 0) || (index
>= nchrdev
) ||
225 (memcmp((char *)devsw
,
227 sizeof(struct cdevsw
)) != 0)) {
230 cdevsw
[index
] = *csw
;
234 * if the index has the same bsw, then remove
238 cdevsw_remove(int index
, struct cdevsw
* csw
)
240 struct cdevsw
*devsw
;
242 devsw
= &cdevsw
[index
];
243 if ((index
< 0) || (index
>= nchrdev
) ||
244 (memcmp((char *)devsw
,
246 sizeof(struct cdevsw
)) != 0)) {
249 cdevsw
[index
] = nocdev
;
254 cdev_set_bdev(int cdev
, int bdev
)
256 extern int chrtoblk_add(int cdev
, int bdev
);
258 return (chrtoblk_set(cdev
, bdev
));
262 cdevsw_add_with_bdev(int index
, struct cdevsw
* csw
, int bdev
)
264 index
= cdevsw_add(index
, csw
);
268 if (cdev_set_bdev(index
, bdev
) < 0) {
269 cdevsw_remove(index
, csw
);
280 if (PE_parse_boot_arg("-s", namep
)) {
290 struct proc
*p
= procp
;
293 SET(p
->p_flag
, P_TBE
);
299 * WARNING - this is a temporary workaround for binary compatibility issues
300 * with anti-piracy software that relies on patching ptrace (3928003).
301 * This KPI will be removed in the system release after Tiger.
303 uintptr_t temp_patch_ptrace(uintptr_t new_ptrace
)
305 struct sysent
* callp
;
306 sy_call_t
* old_ptrace
;
308 boolean_t funnel_state
;
315 enter_funnel_section(kernel_flock
);
317 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
320 old_ptrace
= callp
->sy_call
;
322 /* only allow one patcher of ptrace */
323 if (old_ptrace
== (sy_call_t
*) ptrace
) {
324 callp
->sy_call
= (sy_call_t
*) new_ptrace
;
330 exit_funnel_section( );
332 (void)thread_funnel_set(kernel_flock
, funnel_state
);
335 return((uintptr_t)old_ptrace
);
338 void temp_unpatch_ptrace(void)
340 struct sysent
* callp
;
342 boolean_t funnel_state
;
346 enter_funnel_section(kernel_flock
);
348 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
351 callp
->sy_call
= (sy_call_t
*) ptrace
;
353 exit_funnel_section( );
355 (void)thread_funnel_set(kernel_flock
, funnel_state
);