]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/thread.h
xnu-1456.1.26.tar.gz
[apple/xnu.git] / osfmk / kern / thread.h
1 /*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_FREE_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58 /*
59 * File: thread.h
60 * Author: Avadis Tevanian, Jr.
61 *
62 * This file contains the structure definitions for threads.
63 *
64 */
65 /*
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
68 *
69 * Permission to use, copy, modify and distribute this software and its
70 * documentation is hereby granted, provided that both the copyright
71 * notice and this permission notice appear in all copies of the
72 * software, derivative works or modified versions, and any portions
73 * thereof, and that both notices appear in supporting documentation.
74 *
75 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
76 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
77 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
78 *
79 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
80 * improvements that they make and grant CSL redistribution rights.
81 *
82 */
83
84 #ifndef _KERN_THREAD_H_
85 #define _KERN_THREAD_H_
86
87 #include <mach/kern_return.h>
88 #include <mach/mach_types.h>
89 #include <mach/message.h>
90 #include <mach/boolean.h>
91 #include <mach/vm_param.h>
92 #include <mach/thread_info.h>
93 #include <mach/thread_status.h>
94 #include <mach/exception_types.h>
95
96 #include <kern/kern_types.h>
97
98 #include <sys/cdefs.h>
99
100 #ifdef MACH_KERNEL_PRIVATE
101
102 #include <cputypes.h>
103
104 #include <mach_assert.h>
105 #include <mach_ldebug.h>
106
107 #include <ipc/ipc_types.h>
108
109 #include <mach/port.h>
110 #include <kern/cpu_number.h>
111 #include <kern/queue.h>
112 #include <kern/timer.h>
113 #include <kern/lock.h>
114 #include <kern/locks.h>
115 #include <kern/sched.h>
116 #include <kern/sched_prim.h>
117 #include <kern/thread_call.h>
118 #include <kern/timer_call.h>
119 #include <kern/task.h>
120 #include <kern/exception.h>
121 #include <kern/affinity.h>
122
123 #include <ipc/ipc_kmsg.h>
124
125 #include <machine/cpu_data.h>
126 #include <machine/thread.h>
127
128 struct thread {
129 /*
130 * NOTE: The runq field in the thread structure has an unusual
131 * locking protocol. If its value is PROCESSOR_NULL, then it is
132 * locked by the thread_lock, but if its value is something else
133 * then it is locked by the associated run queue lock.
134 *
135 * When the thread is on a wait queue, these first three fields
136 * are treated as an unofficial union with a wait_queue_element.
137 * If you change these, you must change that definition as well
138 * (kern/wait_queue.h).
139 */
140 /* Items examined often, modified infrequently */
141 queue_chain_t links; /* run/wait queue links */
142 processor_t runq; /* run queue assignment */
143 wait_queue_t wait_queue; /* wait queue we are currently on */
144 event64_t wait_event; /* wait queue event */
145 integer_t options; /* options set by thread itself */
146 #define TH_OPT_INTMASK 0x03 /* interrupt / abort level */
147 #define TH_OPT_VMPRIV 0x04 /* may allocate reserved memory */
148 #define TH_OPT_DTRACE 0x08 /* executing under dtrace_probe */
149
150 /* Data updated during assert_wait/thread_wakeup */
151 decl_simple_lock_data(,sched_lock) /* scheduling lock (thread_lock()) */
152 decl_simple_lock_data(,wake_lock) /* for thread stop / wait (wake_lock()) */
153 boolean_t wake_active; /* wake event on stop */
154 int at_safe_point; /* thread_abort_safely allowed */
155 ast_t reason; /* why we blocked */
156 wait_result_t wait_result; /* outcome of wait -
157 * may be examined by this thread
158 * WITHOUT locking */
159 thread_continue_t continuation; /* continue here next dispatch */
160 void *parameter; /* continuation parameter */
161
162 /* Data updated/used in thread_invoke */
163 struct funnel_lock *funnel_lock; /* Non-reentrancy funnel */
164 int funnel_state;
165 #define TH_FN_OWNED 0x1 /* we own the funnel */
166 #define TH_FN_REFUNNEL 0x2 /* re-acquire funnel on dispatch */
167
168 vm_offset_t kernel_stack; /* current kernel stack */
169 vm_offset_t reserved_stack; /* reserved kernel stack */
170
171 /* Thread state: */
172 int state;
173 /*
174 * Thread states [bits or'ed]
175 */
176 #define TH_WAIT 0x01 /* queued for waiting */
177 #define TH_SUSP 0x02 /* stopped or requested to stop */
178 #define TH_RUN 0x04 /* running or on runq */
179 #define TH_UNINT 0x08 /* waiting uninteruptibly */
180 #define TH_TERMINATE 0x10 /* halted at termination */
181
182 #define TH_IDLE 0x80 /* idling processor */
183
184 /* Scheduling information */
185 integer_t sched_mode; /* scheduling mode bits */
186 #define TH_MODE_REALTIME 0x0001 /* time constraints supplied */
187 #define TH_MODE_TIMESHARE 0x0002 /* use timesharing algorithm */
188 #define TH_MODE_FAILSAFE 0x0004 /* fail-safe has tripped */
189 #define TH_MODE_PROMOTED 0x0008 /* sched pri has been promoted */
190 #define TH_MODE_ABORT 0x0010 /* abort interruptible waits */
191 #define TH_MODE_ABORTSAFELY 0x0020 /* ... but only those at safe point */
192 #define TH_MODE_ISABORTED (TH_MODE_ABORT | TH_MODE_ABORTSAFELY)
193 #define TH_MODE_DEPRESS 0x0040 /* normal depress yield */
194 #define TH_MODE_POLLDEPRESS 0x0080 /* polled depress yield */
195 #define TH_MODE_ISDEPRESSED (TH_MODE_DEPRESS | TH_MODE_POLLDEPRESS)
196
197 integer_t sched_pri; /* scheduled (current) priority */
198 integer_t priority; /* base priority */
199 integer_t max_priority; /* max base priority */
200 integer_t task_priority; /* copy of task base priority */
201
202 integer_t promotions; /* level of promotion */
203 integer_t pending_promoter_index;
204 void *pending_promoter[2];
205
206 integer_t importance; /* task-relative importance */
207
208 /* real-time parameters */
209 struct { /* see mach/thread_policy.h */
210 uint32_t period;
211 uint32_t computation;
212 uint32_t constraint;
213 boolean_t preemptible;
214
215 uint64_t deadline;
216 } realtime;
217
218 uint32_t current_quantum; /* duration of current quantum */
219
220 /* Data used during setrun/dispatch */
221 timer_data_t system_timer; /* system mode timer */
222 processor_t bound_processor; /* bound to a processor? */
223 processor_t last_processor; /* processor last dispatched on */
224
225 /* Fail-safe computation since last unblock or qualifying yield */
226 uint64_t computation_metered;
227 uint64_t computation_epoch;
228 integer_t safe_mode; /* saved mode during fail-safe */
229 natural_t safe_release; /* when to release fail-safe */
230
231 /* Call out from scheduler */
232 void (*sched_call)(
233 int type,
234 thread_t thread);
235
236 /* Statistics and timesharing calculations */
237 natural_t sched_stamp; /* last scheduler tick */
238 natural_t sched_usage; /* timesharing cpu usage [sched] */
239 natural_t pri_shift; /* usage -> priority from pset */
240 natural_t cpu_usage; /* instrumented cpu usage [%cpu] */
241 natural_t cpu_delta; /* accumulated cpu_usage delta */
242 uint32_t c_switch; /* total context switches */
243 uint32_t p_switch; /* total processor switches */
244 uint32_t ps_switch; /* total pset switches */
245
246 /* Timing data structures */
247 timer_data_t user_timer; /* user mode timer */
248 uint64_t user_timer_save; /* saved user timer value */
249 uint64_t system_timer_save; /* saved system timer value */
250 uint64_t vtimer_user_save; /* saved values for vtimers */
251 uint64_t vtimer_prof_save;
252 uint64_t vtimer_rlim_save;
253
254 /* Timed wait expiration */
255 timer_call_data_t wait_timer;
256 integer_t wait_timer_active;
257 boolean_t wait_timer_is_set;
258
259 /* Priority depression expiration */
260 timer_call_data_t depress_timer;
261 integer_t depress_timer_active;
262
263 /*
264 * Processor/cache affinity
265 * - affinity_threads links task threads with the same affinity set
266 */
267 affinity_set_t affinity_set;
268 queue_chain_t affinity_threads;
269
270 /* Various bits of stashed state */
271 union {
272 struct {
273 mach_msg_return_t state; /* receive state */
274 ipc_object_t object; /* object received on */
275 mach_vm_address_t msg_addr; /* receive buffer pointer */
276 mach_msg_size_t msize; /* max size for recvd msg */
277 mach_msg_option_t option; /* options for receive */
278 mach_msg_size_t slist_size; /* scatter list size */
279 mach_port_name_t receiver_name; /* the receive port name */
280 struct ipc_kmsg *kmsg; /* received message */
281 mach_port_seqno_t seqno; /* seqno of recvd message */
282 mach_msg_continue_t continuation;
283 } receive;
284 struct {
285 struct semaphore *waitsemaphore; /* semaphore ref */
286 struct semaphore *signalsemaphore; /* semaphore ref */
287 int options; /* semaphore options */
288 kern_return_t result; /* primary result */
289 mach_msg_continue_t continuation;
290 } sema;
291 struct {
292 int option; /* switch option */
293 } swtch;
294 int misc; /* catch-all for other state */
295 } saved;
296
297 /* IPC data structures */
298 struct ipc_kmsg_queue ith_messages;
299 mach_port_t ith_rpc_reply; /* reply port for kernel RPCs */
300
301 /* Ast/Halt data structures */
302 vm_offset_t recover; /* page fault recover(copyin/out) */
303 uint32_t ref_count; /* number of references to me */
304
305 queue_chain_t threads; /* global list of all threads */
306
307 /* Activation */
308 queue_chain_t task_threads;
309
310 /*** Machine-dependent state ***/
311 struct machine_thread machine;
312
313 /* Task membership */
314 struct task *task;
315 vm_map_t map;
316
317 decl_lck_mtx_data(,mutex)
318
319 /* Kernel holds on this thread */
320 int suspend_count;
321
322 /* User level suspensions */
323 int user_stop_count;
324
325 /* Pending thread ast(s) */
326 ast_t ast;
327
328 /* Miscellaneous bits guarded by mutex */
329 uint32_t
330 active:1, /* Thread is active and has not been terminated */
331 started:1, /* Thread has been started after creation */
332 static_param:1, /* Disallow policy parameter changes */
333 :0;
334
335 /* Return Handers */
336 struct ReturnHandler {
337 struct ReturnHandler *next;
338 void (*handler)(
339 struct ReturnHandler *rh,
340 struct thread *thread);
341 } *handlers, special_handler;
342
343 /* Ports associated with this thread */
344 struct ipc_port *ith_self; /* not a right, doesn't hold ref */
345 struct ipc_port *ith_sself; /* a send right */
346 struct exception_action exc_actions[EXC_TYPES_COUNT];
347
348 /* Owned ulocks (a lock set element) */
349 queue_head_t held_ulocks;
350
351 #ifdef MACH_BSD
352 void *uthread;
353 #endif
354
355 #if CONFIG_DTRACE
356 uint32_t t_dtrace_predcache;/* DTrace per thread predicate value hint */
357 int64_t t_dtrace_tracing; /* Thread time under dtrace_probe() */
358 int64_t t_dtrace_vtime;
359 #endif
360
361 #define T_CHUD_MARKED 0x1 /* this thread is marked by CHUD */
362 #define T_IN_CHUD 0x2 /* this thread is already in a CHUD handler */
363 #define THREAD_PMC_FLAG 0x4 /* Bit in "t_chud" signifying PMC interest */
364 uint32_t t_page_creation_count;
365 clock_sec_t t_page_creation_time;
366
367 uint32_t t_chud; /* CHUD flags, used for Shark */
368 uint64_t thread_id; /*system wide unique thread-id*/
369 };
370
371 #define ith_state saved.receive.state
372 #define ith_object saved.receive.object
373 #define ith_msg_addr saved.receive.msg_addr
374 #define ith_msize saved.receive.msize
375 #define ith_option saved.receive.option
376 #define ith_scatter_list_size saved.receive.slist_size
377 #define ith_receiver_name saved.receive.receiver_name
378 #define ith_continuation saved.receive.continuation
379 #define ith_kmsg saved.receive.kmsg
380 #define ith_seqno saved.receive.seqno
381
382 #define sth_waitsemaphore saved.sema.waitsemaphore
383 #define sth_signalsemaphore saved.sema.signalsemaphore
384 #define sth_options saved.sema.options
385 #define sth_result saved.sema.result
386 #define sth_continuation saved.sema.continuation
387
388 extern void thread_bootstrap(void) __attribute__((section("__TEXT, initcode")));
389
390 extern void thread_init(void) __attribute__((section("__TEXT, initcode")));
391
392 extern void thread_daemon_init(void);
393
394 #define thread_reference_internal(thread) \
395 (void)hw_atomic_add(&(thread)->ref_count, 1)
396
397 #define thread_deallocate_internal(thread) \
398 hw_atomic_sub(&(thread)->ref_count, 1)
399
400 #define thread_reference(thread) \
401 MACRO_BEGIN \
402 if ((thread) != THREAD_NULL) \
403 thread_reference_internal(thread); \
404 MACRO_END
405
406 extern void thread_deallocate(
407 thread_t thread);
408
409 extern void thread_terminate_self(void);
410
411 extern kern_return_t thread_terminate_internal(
412 thread_t thread);
413
414 extern void thread_start_internal(
415 thread_t thread) __attribute__ ((noinline));
416
417 extern void thread_terminate_enqueue(
418 thread_t thread);
419
420 extern void thread_stack_enqueue(
421 thread_t thread);
422
423 extern void thread_hold(
424 thread_t thread);
425
426 extern void thread_release(
427 thread_t thread);
428
429
430 #define thread_lock_init(th) simple_lock_init(&(th)->sched_lock, 0)
431 #define thread_lock(th) simple_lock(&(th)->sched_lock)
432 #define thread_unlock(th) simple_unlock(&(th)->sched_lock)
433
434 #define wake_lock_init(th) simple_lock_init(&(th)->wake_lock, 0)
435 #define wake_lock(th) simple_lock(&(th)->wake_lock)
436 #define wake_unlock(th) simple_unlock(&(th)->wake_lock)
437
438 #define thread_should_halt_fast(thread) (!(thread)->active)
439
440 extern void stack_alloc(
441 thread_t thread);
442
443 extern void stack_free(
444 thread_t thread);
445
446 extern void stack_free_stack(
447 vm_offset_t stack);
448
449 extern boolean_t stack_alloc_try(
450 thread_t thread);
451
452 extern void stack_collect(void);
453
454 extern void stack_init(void) __attribute__((section("__TEXT, initcode")));
455
456 extern kern_return_t thread_state_initialize(
457 thread_t thread);
458
459 extern kern_return_t thread_setstatus(
460 thread_t thread,
461 int flavor,
462 thread_state_t tstate,
463 mach_msg_type_number_t count);
464
465 extern kern_return_t thread_getstatus(
466 thread_t thread,
467 int flavor,
468 thread_state_t tstate,
469 mach_msg_type_number_t *count);
470
471 extern kern_return_t thread_info_internal(
472 thread_t thread,
473 thread_flavor_t flavor,
474 thread_info_t thread_info_out,
475 mach_msg_type_number_t *thread_info_count);
476
477 extern void thread_task_priority(
478 thread_t thread,
479 integer_t priority,
480 integer_t max_priority);
481
482 extern void thread_policy_reset(
483 thread_t thread);
484
485 extern kern_return_t kernel_thread_create(
486 thread_continue_t continuation,
487 void *parameter,
488 integer_t priority,
489 thread_t *new_thread);
490
491 extern kern_return_t kernel_thread_start_priority(
492 thread_continue_t continuation,
493 void *parameter,
494 integer_t priority,
495 thread_t *new_thread);
496
497 extern void machine_stack_attach(
498 thread_t thread,
499 vm_offset_t stack);
500
501 extern vm_offset_t machine_stack_detach(
502 thread_t thread);
503
504 extern void machine_stack_handoff(
505 thread_t old,
506 thread_t new);
507
508 extern thread_t machine_switch_context(
509 thread_t old_thread,
510 thread_continue_t continuation,
511 thread_t new_thread);
512
513 extern void machine_load_context(
514 thread_t thread);
515
516 extern kern_return_t machine_thread_state_initialize(
517 thread_t thread);
518
519 extern kern_return_t machine_thread_set_state(
520 thread_t thread,
521 thread_flavor_t flavor,
522 thread_state_t state,
523 mach_msg_type_number_t count);
524
525 extern kern_return_t machine_thread_get_state(
526 thread_t thread,
527 thread_flavor_t flavor,
528 thread_state_t state,
529 mach_msg_type_number_t *count);
530
531 extern kern_return_t machine_thread_dup(
532 thread_t self,
533 thread_t target);
534
535 extern void machine_thread_init(void);
536
537 extern kern_return_t machine_thread_create(
538 thread_t thread,
539 task_t task);
540 extern void machine_thread_switch_addrmode(
541 thread_t thread);
542
543 extern void machine_thread_destroy(
544 thread_t thread);
545
546 extern void machine_set_current_thread(
547 thread_t thread);
548
549 extern void machine_thread_terminate_self(void);
550
551 extern kern_return_t machine_thread_get_kern_state(
552 thread_t thread,
553 thread_flavor_t flavor,
554 thread_state_t tstate,
555 mach_msg_type_number_t *count);
556
557 extern kern_return_t machine_thread_inherit_taskwide(
558 thread_t thread,
559 task_t parent_task);
560
561 /*
562 * XXX Funnel locks XXX
563 */
564
565 struct funnel_lock {
566 int fnl_type; /* funnel type */
567 lck_mtx_t *fnl_mutex; /* underlying mutex for the funnel */
568 void * fnl_mtxholder; /* thread (last)holdng mutex */
569 void * fnl_mtxrelease; /* thread (last)releasing mutex */
570 lck_mtx_t *fnl_oldmutex; /* Mutex before collapsing split funnel */
571 };
572
573 typedef struct ReturnHandler ReturnHandler;
574
575 #define thread_mtx_lock(thread) lck_mtx_lock(&(thread)->mutex)
576 #define thread_mtx_try(thread) lck_mtx_try_lock(&(thread)->mutex)
577 #define thread_mtx_unlock(thread) lck_mtx_unlock(&(thread)->mutex)
578
579 extern void act_execute_returnhandlers(void);
580
581 extern void install_special_handler(
582 thread_t thread);
583
584 extern void special_handler(
585 ReturnHandler *rh,
586 thread_t thread);
587
588 void act_machine_sv_free(thread_t, int);
589
590 vm_offset_t min_valid_stack_address(void);
591 vm_offset_t max_valid_stack_address(void);
592
593 extern void funnel_lock(
594 struct funnel_lock *lock);
595
596 extern void funnel_unlock(
597 struct funnel_lock *lock);
598
599 #else /* MACH_KERNEL_PRIVATE */
600
601 __BEGIN_DECLS
602
603 extern thread_t current_thread(void);
604
605 extern void thread_reference(
606 thread_t thread);
607
608 extern void thread_deallocate(
609 thread_t thread);
610
611 __END_DECLS
612
613 #endif /* MACH_KERNEL_PRIVATE */
614
615 #ifdef KERNEL_PRIVATE
616
617 __BEGIN_DECLS
618
619 #ifndef __LP64__
620
621 extern thread_t kernel_thread(
622 task_t task,
623 void (*start)(void));
624
625 #endif /* __LP64__ */
626
627 extern uint64_t thread_tid(
628 thread_t thread);
629
630 extern uint64_t thread_dispatchqaddr(
631 thread_t thread);
632
633 __END_DECLS
634
635 #endif /* KERNEL_PRIVATE */
636
637 __BEGIN_DECLS
638
639 #ifdef XNU_KERNEL_PRIVATE
640
641 extern kern_return_t thread_create_workq(
642 task_t task,
643 thread_t *new_thread);
644
645 extern void thread_yield_internal(
646 mach_msg_timeout_t interval);
647
648 typedef struct funnel_lock funnel_t;
649
650 #define THR_FUNNEL_NULL (funnel_t *)0
651
652 extern funnel_t *funnel_alloc(
653 int type);
654
655 extern void funnel_free(
656 funnel_t *lock);
657
658 extern funnel_t *thread_funnel_get(void);
659
660 extern boolean_t thread_funnel_set(
661 funnel_t *lock,
662 boolean_t funneled);
663
664 extern void thread_read_times(
665 thread_t thread,
666 time_value_t *user_time,
667 time_value_t *system_time);
668
669 extern void thread_setuserstack(
670 thread_t thread,
671 mach_vm_offset_t user_stack);
672
673 extern uint64_t thread_adjuserstack(
674 thread_t thread,
675 int adjust);
676
677 extern void thread_setentrypoint(
678 thread_t thread,
679 mach_vm_offset_t entry);
680
681 extern kern_return_t thread_setsinglestep(
682 thread_t thread,
683 int on);
684
685 extern kern_return_t thread_wire_internal(
686 host_priv_t host_priv,
687 thread_t thread,
688 boolean_t wired,
689 boolean_t *prev_state);
690
691 extern kern_return_t thread_dup(thread_t);
692
693 typedef void (*sched_call_t)(
694 int type,
695 thread_t thread);
696
697 #define SCHED_CALL_BLOCK 0x1
698 #define SCHED_CALL_UNBLOCK 0x2
699
700 extern void thread_sched_call(
701 thread_t thread,
702 sched_call_t call);
703
704 extern void thread_static_param(
705 thread_t thread,
706 boolean_t state);
707
708 extern kern_return_t thread_policy_set_internal(
709 thread_t thread,
710 thread_policy_flavor_t flavor,
711 thread_policy_t policy_info,
712 mach_msg_type_number_t count);
713
714
715 extern task_t get_threadtask(thread_t);
716 #define thread_is_64bit(thd) \
717 task_has_64BitAddr(get_threadtask(thd))
718
719
720 extern void *get_bsdthread_info(thread_t);
721 extern void set_bsdthread_info(thread_t, void *);
722 extern void *uthread_alloc(task_t, thread_t, int);
723 extern void uthread_cleanup(task_t, void *, void *);
724 extern void uthread_zone_free(void *);
725 extern void uthread_cred_free(void *);
726
727 extern boolean_t thread_should_halt(
728 thread_t thread);
729
730 extern int is_64signalregset(void);
731
732 void act_set_apc(thread_t);
733
734 extern uint32_t dtrace_get_thread_predcache(thread_t);
735 extern int64_t dtrace_get_thread_vtime(thread_t);
736 extern int64_t dtrace_get_thread_tracing(thread_t);
737 extern boolean_t dtrace_get_thread_reentering(thread_t);
738 extern vm_offset_t dtrace_get_kernel_stack(thread_t);
739 extern void dtrace_set_thread_predcache(thread_t, uint32_t);
740 extern void dtrace_set_thread_vtime(thread_t, int64_t);
741 extern void dtrace_set_thread_tracing(thread_t, int64_t);
742 extern void dtrace_set_thread_reentering(thread_t, boolean_t);
743 extern vm_offset_t dtrace_set_thread_recover(thread_t, vm_offset_t);
744 extern void dtrace_thread_bootstrap(void);
745
746 extern int64_t dtrace_calc_thread_recent_vtime(thread_t);
747
748
749 extern void thread_set_wq_state32(
750 thread_t thread,
751 thread_state_t tstate);
752
753 extern void thread_set_wq_state64(
754 thread_t thread,
755 thread_state_t tstate);
756
757 extern vm_offset_t kernel_stack_mask;
758 extern vm_offset_t kernel_stack_size;
759 extern vm_offset_t kernel_stack_depth_max;
760
761 #endif /* XNU_KERNEL_PRIVATE */
762
763 /*! @function kernel_thread_start
764 @abstract Create a kernel thread.
765 @discussion This function takes three input parameters, namely reference to the function that the thread should execute, caller specified data and a reference which is used to return the newly created kernel thread. The function returns KERN_SUCCESS on success or an appropriate kernel code type indicating the error. It may be noted that the caller is responsible for explicitly releasing the reference to the created thread when no longer needed. This should be done by calling thread_deallocate(new_thread).
766 @param continuation A C-function pointer where the thread will begin execution.
767 @param parameter Caller specified data to be passed to the new thread.
768 @param new_thread Reference to the new thread is returned in this parameter.
769 @result Returns KERN_SUCCESS on success or an appropriate kernel code type.
770 */
771
772 extern kern_return_t kernel_thread_start(
773 thread_continue_t continuation,
774 void *parameter,
775 thread_t *new_thread);
776
777 __END_DECLS
778
779 #endif /* _KERN_THREAD_H_ */