]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/bsd_kern.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <mach/mach_types.h>
26 #include <kern/queue.h>
28 #include <kern/thread.h>
29 #include <kern/thread_act.h>
30 #include <kern/task.h>
32 #include <kern/lock.h>
33 #include <vm/vm_map.h>
35 #include <ipc/ipc_port.h>
36 #include <ipc/ipc_object.h>
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_act_t
get_firstthread(task_t
);
48 vm_map_t
get_task_map(task_t
);
49 ipc_space_t
get_task_ipcspace(task_t
);
50 boolean_t
is_kerneltask(task_t
);
51 boolean_t
is_thread_idle(thread_t
);
52 vm_offset_t
get_map_min( vm_map_t
);
53 vm_offset_t
get_map_max( vm_map_t
);
54 int get_task_userstop(task_t
);
55 int get_thread_userstop(thread_act_t
);
56 boolean_t
thread_should_abort(thread_t
);
57 boolean_t
current_thread_aborted(void);
58 void task_act_iterate_wth_args(task_t
, void(*)(thread_act_t
, void *), void *);
59 void ipc_port_release(ipc_port_t
);
60 boolean_t
is_thread_active(thread_t
);
61 kern_return_t
get_thread_waitresult(thread_t
);
62 vm_size_t
get_vmmap_size(vm_map_t
);
63 int get_vmmap_entries(vm_map_t
);
64 int get_task_numacts(task_t
);
65 thread_act_t
get_firstthread(task_t task
);
66 kern_return_t
get_signalact(task_t
, thread_act_t
*, int);
72 void *get_bsdtask_info(task_t t
)
80 void set_bsdtask_info(task_t t
,void * v
)
88 void *get_bsdthread_info(thread_act_t th
)
94 * XXX: wait for BSD to fix signal code
95 * Until then, we cannot block here. We know the task
96 * can't go away, so we make sure it is still active after
97 * retrieving the first thread for extra safety.
99 thread_act_t
get_firstthread(task_t task
)
101 thread_act_t thr_act
;
103 thr_act
= (thread_act_t
)queue_first(&task
->threads
);
104 if (queue_end(&task
->threads
, (queue_entry_t
)thr_act
))
105 thr_act
= THR_ACT_NULL
;
107 return(THR_ACT_NULL
);
111 kern_return_t
get_signalact(task_t task
,thread_act_t
* thact
, int setast
)
116 thread_act_t thr_act
;
122 return(KERN_FAILURE
);
125 thr_act
= THR_ACT_NULL
;
126 for (inc
= (thread_act_t
)queue_first(&task
->threads
);
127 !queue_end(&task
->threads
, (queue_entry_t
)inc
);
129 th
= act_lock_thread(inc
);
131 ((th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) != TH_ABORT
)) {
135 act_unlock_thread(inc
);
136 ninc
= (thread_act_t
)queue_next(&inc
->task_threads
);
143 act_set_astbsd(thr_act
);
145 act_unlock_thread(thr_act
);
150 return(KERN_SUCCESS
);
152 return(KERN_FAILURE
);
156 kern_return_t
check_actforsig(task_t task
, thread_act_t thact
, int setast
)
161 thread_act_t thr_act
;
168 return(KERN_FAILURE
);
171 thr_act
= THR_ACT_NULL
;
172 for (inc
= (thread_act_t
)queue_first(&task
->threads
);
173 !queue_end(&task
->threads
, (queue_entry_t
)inc
);
177 ninc
= (thread_act_t
)queue_next(&inc
->task_threads
);
180 th
= act_lock_thread(inc
);
182 ((th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) != TH_ABORT
)) {
187 act_unlock_thread(inc
);
188 /* ninc = (thread_act_t)queue_next(&inc->thr_acts); */
194 act_set_astbsd(thr_act
);
196 act_unlock_thread(thr_act
);
201 return(KERN_SUCCESS
);
203 return(KERN_FAILURE
);
209 vm_map_t
get_task_map(task_t t
)
217 ipc_space_t
get_task_ipcspace(task_t t
)
219 return(t
->itk_space
);
222 int get_task_numacts(task_t t
)
224 return(t
->thread_count
);
227 /* does this machine need 64bit register set for signal handler */
228 int is_64signalregset(void)
230 task_t t
= current_task();
231 if(t
->taskFeatures
[0] & tf64BitData
)
238 * The old map reference is returned.
241 swap_task_map(task_t task
,vm_map_t map
)
243 thread_act_t act
= current_act();
246 if (task
!= act
->task
)
247 panic("swap_task_map");
251 act
->map
= task
->map
= map
;
257 swap_act_map(thread_act_t thr_act
,vm_map_t map
)
259 panic("swap_act_map");
265 pmap_t
get_task_pmap(task_t t
)
267 return(t
->map
->pmap
);
273 pmap_t
get_map_pmap(vm_map_t map
)
280 task_t
get_threadtask(thread_act_t th
)
289 boolean_t
is_thread_idle(thread_t th
)
291 return((th
->state
& TH_IDLE
) == TH_IDLE
);
297 boolean_t
is_thread_running(thread_t th
)
299 return((th
->state
& TH_RUN
) == TH_RUN
);
329 return(vm_map_min(map
));
339 return(vm_map_max(map
));
349 get_vmsubmap_entries(
351 vm_object_offset_t start
,
352 vm_object_offset_t end
)
354 int total_entries
= 0;
355 vm_map_entry_t entry
;
359 entry
= vm_map_first_entry(map
);
360 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< start
)) {
361 entry
= entry
->vme_next
;
364 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< end
)) {
365 if(entry
->is_sub_map
) {
367 get_vmsubmap_entries(entry
->object
.sub_map
,
370 (entry
->vme_end
- entry
->vme_start
));
374 entry
= entry
->vme_next
;
378 return(total_entries
);
385 int total_entries
= 0;
386 vm_map_entry_t entry
;
390 entry
= vm_map_first_entry(map
);
392 while(entry
!= vm_map_to_entry(map
)) {
393 if(entry
->is_sub_map
) {
395 get_vmsubmap_entries(entry
->object
.sub_map
,
398 (entry
->vme_end
- entry
->vme_start
));
402 entry
= entry
->vme_next
;
406 return(total_entries
);
419 return(task
->user_stop_count
);
429 return(th
->user_stop_count
);
439 return(!th
->top_act
||
440 (th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) == TH_ABORT
);
444 * This routine is like thread_should_abort() above. It checks to
445 * see if the current thread is aborted. But unlike above, it also
446 * checks to see if thread is safely aborted. If so, it returns
447 * that fact, and clears the condition (safe aborts only should
448 * have a single effect, and a poll of the abort status
452 current_thread_aborted (
455 thread_t th
= current_thread();
459 ((th
->state
& (TH_ABORT
|TH_ABORT_SAFELY
)) == TH_ABORT
&&
460 th
->interrupt_level
!= THREAD_UNINT
))
462 if (th
->state
& TH_ABORT_SAFELY
) {
465 if (th
->state
& TH_ABORT_SAFELY
)
466 th
->state
&= ~(TH_ABORT
|TH_ABORT_SAFELY
);
477 task_act_iterate_wth_args(
479 void (*func_callback
)(thread_act_t
, void *),
482 thread_act_t inc
, ninc
;
485 for (inc
= (thread_act_t
)queue_first(&task
->threads
);
486 !queue_end(&task
->threads
, (queue_entry_t
)inc
);
488 ninc
= (thread_act_t
)queue_next(&inc
->task_threads
);
489 (void) (*func_callback
)(inc
, func_arg
);
498 ipc_object_release(&(port
)->ip_object
);
509 get_thread_waitresult(
512 return(th
->wait_result
);
520 reenable
= ml_set_interrupts_enabled(FALSE
);
521 ast_on_fast(AST_BSD
);
522 (void)ml_set_interrupts_enabled(reenable
);