]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/bsd_kern.c
13620cd60eb7600550c336ebe8a93a057d4eba3f
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <mach/mach_types.h>
25 #include <kern/kern_types.h>
26 #include <kern/processor.h>
27 #include <kern/thread.h>
28 #include <kern/task.h>
30 #include <kern/lock.h>
32 #include <ipc/ipc_port.h>
33 #include <ipc/ipc_object.h>
34 #include <vm/vm_map.h>
36 #include <vm/vm_protos.h> /* last */
38 #undef thread_should_halt
39 #undef ipc_port_release
41 /* BSD KERN COMPONENT INTERFACE */
43 task_t bsd_init_task
= TASK_NULL
;
44 char init_task_failure_data
[1024];
45 extern unsigned int not_in_kdp
; /* Skip acquiring locks if we're in kdp */
47 thread_t
get_firstthread(task_t
);
48 int get_task_userstop(task_t
);
49 int get_thread_userstop(thread_t
);
50 boolean_t
thread_should_abort(thread_t
);
51 boolean_t
current_thread_aborted(void);
52 void task_act_iterate_wth_args(task_t
, void(*)(thread_t
, void *), void *);
53 void ipc_port_release(ipc_port_t
);
54 boolean_t
is_thread_active(thread_t
);
55 kern_return_t
get_signalact(task_t
, thread_t
*, int);
56 int get_vmsubmap_entries(vm_map_t
, vm_object_offset_t
, vm_object_offset_t
);
61 void *get_bsdtask_info(task_t t
)
69 void set_bsdtask_info(task_t t
,void * v
)
77 void *get_bsdthread_info(thread_t th
)
83 * XXX: wait for BSD to fix signal code
84 * Until then, we cannot block here. We know the task
85 * can't go away, so we make sure it is still active after
86 * retrieving the first thread for extra safety.
88 thread_t
get_firstthread(task_t task
)
90 thread_t thread
= (thread_t
)queue_first(&task
->threads
);
92 if (queue_end(&task
->threads
, (queue_entry_t
)thread
))
104 thread_t
*result_out
,
107 kern_return_t result
= KERN_SUCCESS
;
108 thread_t inc
, thread
= THREAD_NULL
;
115 return (KERN_FAILURE
);
118 for (inc
= (thread_t
)queue_first(&task
->threads
);
119 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
120 thread_mtx_lock(inc
);
122 (inc
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) != TH_ABORT
) {
126 thread_mtx_unlock(inc
);
128 inc
= (thread_t
)queue_next(&inc
->task_threads
);
132 *result_out
= thread
;
136 act_set_astbsd(thread
);
138 thread_mtx_unlock(thread
);
141 result
= KERN_FAILURE
;
155 kern_return_t result
= KERN_FAILURE
;
163 return (KERN_FAILURE
);
166 for (inc
= (thread_t
)queue_first(&task
->threads
);
167 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
169 thread_mtx_lock(inc
);
172 (inc
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) != TH_ABORT
) {
173 result
= KERN_SUCCESS
;
177 thread_mtx_unlock(inc
);
181 inc
= (thread_t
)queue_next(&inc
->task_threads
);
184 if (result
== KERN_SUCCESS
) {
186 act_set_astbsd(thread
);
188 thread_mtx_unlock(thread
);
197 * This is only safe to call from a thread executing in
198 * in the task's context or if the task is locked Otherwise,
199 * the map could be switched for the task (and freed) before
200 * we to return it here.
202 vm_map_t
get_task_map(task_t t
)
207 vm_map_t
get_task_map_reference(task_t t
)
220 vm_map_reference_swap(m
);
228 ipc_space_t
get_task_ipcspace(task_t t
)
230 return(t
->itk_space
);
233 int get_task_numacts(task_t t
)
235 return(t
->thread_count
);
238 /* does this machine need 64bit register set for signal handler */
239 int is_64signalregset(void)
241 task_t t
= current_task();
242 if(t
->taskFeatures
[0] & tf64BitData
)
249 * The old map reference is returned.
252 swap_task_map(task_t task
,vm_map_t map
)
254 thread_t thread
= current_thread();
257 if (task
!= thread
->task
)
258 panic("swap_task_map");
262 thread
->map
= task
->map
= map
;
270 pmap_t
get_task_pmap(task_t t
)
272 return(t
->map
->pmap
);
278 pmap_t
get_map_pmap(vm_map_t map
)
285 task_t
get_threadtask(thread_t th
)
294 boolean_t
is_thread_idle(thread_t th
)
296 return((th
->state
& TH_IDLE
) == TH_IDLE
);
302 boolean_t
is_thread_running(thread_t th
)
304 return((th
->state
& TH_RUN
) == TH_RUN
);
334 return(vm_map_min(map
));
344 return(vm_map_max(map
));
354 get_vmsubmap_entries(
356 vm_object_offset_t start
,
357 vm_object_offset_t end
)
359 int total_entries
= 0;
360 vm_map_entry_t entry
;
364 entry
= vm_map_first_entry(map
);
365 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< start
)) {
366 entry
= entry
->vme_next
;
369 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< end
)) {
370 if(entry
->is_sub_map
) {
372 get_vmsubmap_entries(entry
->object
.sub_map
,
375 (entry
->vme_end
- entry
->vme_start
));
379 entry
= entry
->vme_next
;
383 return(total_entries
);
390 int total_entries
= 0;
391 vm_map_entry_t entry
;
395 entry
= vm_map_first_entry(map
);
397 while(entry
!= vm_map_to_entry(map
)) {
398 if(entry
->is_sub_map
) {
400 get_vmsubmap_entries(entry
->object
.sub_map
,
403 (entry
->vme_end
- entry
->vme_start
));
407 entry
= entry
->vme_next
;
411 return(total_entries
);
424 return(task
->user_stop_count
);
434 return(th
->user_stop_count
);
444 return ((th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) == TH_ABORT
);
448 * This routine is like thread_should_abort() above. It checks to
449 * see if the current thread is aborted. But unlike above, it also
450 * checks to see if thread is safely aborted. If so, it returns
451 * that fact, and clears the condition (safe aborts only should
452 * have a single effect, and a poll of the abort status
456 current_thread_aborted (
459 thread_t th
= current_thread();
462 if ((th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) == TH_ABORT
&&
463 (th
->options
& TH_OPT_INTMASK
) != THREAD_UNINT
)
465 if (th
->state
& TH_ABORT_SAFELY
) {
468 if (th
->state
& TH_ABORT_SAFELY
)
469 th
->state
&= ~(TH_ABORT
|TH_ABORT_SAFELY
);
480 task_act_iterate_wth_args(
482 void (*func_callback
)(thread_t
, void *),
489 for (inc
= (thread_t
)queue_first(&task
->threads
);
490 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
491 (void) (*func_callback
)(inc
, func_arg
);
492 inc
= (thread_t
)queue_next(&inc
->task_threads
);
502 ipc_object_release(&(port
)->ip_object
);
517 reenable
= ml_set_interrupts_enabled(FALSE
);
518 ast_on_fast(AST_BSD
);
519 (void)ml_set_interrupts_enabled(reenable
);