2 * Copyright (c) 2000-2009 Apple 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 * @OSF_FREE_COPYRIGHT@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr.
62 * This file contains the structure definitions for threads.
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
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.
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.
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.
84 #ifndef _KERN_THREAD_H_
85 #define _KERN_THREAD_H_
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>
96 #include <kern/kern_types.h>
98 #include <sys/cdefs.h>
100 #ifdef MACH_KERNEL_PRIVATE
102 #include <cputypes.h>
104 #include <mach_assert.h>
105 #include <mach_ldebug.h>
107 #include <ipc/ipc_types.h>
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>
123 #include <ipc/ipc_kmsg.h>
125 #include <machine/cpu_data.h>
126 #include <machine/thread.h>
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.
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).
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 #define TH_OPT_SYSTEM_CRITICAL 0x10 /* Thread must always be allowed to run - even under heavy load */
150 #define TH_OPT_PROC_CPULIMIT 0x20 /* Thread has a task-wide CPU limit applied to it */
151 #define TH_OPT_PRVT_CPULIMIT 0x40 /* Thread has a thread-private CPU limit applied to it */
153 /* Data updated during assert_wait/thread_wakeup */
154 decl_simple_lock_data(,sched_lock
) /* scheduling lock (thread_lock()) */
155 decl_simple_lock_data(,wake_lock
) /* for thread stop / wait (wake_lock()) */
156 boolean_t wake_active
; /* wake event on stop */
157 int at_safe_point
; /* thread_abort_safely allowed */
158 ast_t reason
; /* why we blocked */
159 wait_result_t wait_result
; /* outcome of wait -
160 * may be examined by this thread
162 thread_continue_t continuation
; /* continue here next dispatch */
163 void *parameter
; /* continuation parameter */
165 /* Data updated/used in thread_invoke */
166 struct funnel_lock
*funnel_lock
; /* Non-reentrancy funnel */
168 #define TH_FN_OWNED 0x1 /* we own the funnel */
169 #define TH_FN_REFUNNEL 0x2 /* re-acquire funnel on dispatch */
171 vm_offset_t kernel_stack
; /* current kernel stack */
172 vm_offset_t reserved_stack
; /* reserved kernel stack */
177 * Thread states [bits or'ed]
179 #define TH_WAIT 0x01 /* queued for waiting */
180 #define TH_SUSP 0x02 /* stopped or requested to stop */
181 #define TH_RUN 0x04 /* running or on runq */
182 #define TH_UNINT 0x08 /* waiting uninteruptibly */
183 #define TH_TERMINATE 0x10 /* halted at termination */
184 #define TH_TERMINATE2 0x20 /* added to termination queue */
186 #define TH_IDLE 0x80 /* idling processor */
188 /* Scheduling information */
189 sched_mode_t sched_mode
; /* scheduling mode */
190 sched_mode_t saved_mode
; /* saved mode during forced mode demotion */
192 unsigned int sched_flags
; /* current flag bits */
193 #define TH_SFLAG_FAIRSHARE_TRIPPED 0x0001 /* fairshare scheduling activated */
194 #define TH_SFLAG_FAILSAFE 0x0002 /* fail-safe has tripped */
195 #define TH_SFLAG_THROTTLED 0x0004 /* owner task in throttled state */
196 #define TH_SFLAG_DEMOTED_MASK (TH_SFLAG_THROTTLED | TH_SFLAG_FAILSAFE | TH_SFLAG_FAIRSHARE_TRIPPED)
198 #define TH_SFLAG_PROMOTED 0x0008 /* sched pri has been promoted */
199 #define TH_SFLAG_ABORT 0x0010 /* abort interruptible waits */
200 #define TH_SFLAG_ABORTSAFELY 0x0020 /* ... but only those at safe point */
201 #define TH_SFLAG_ABORTED_MASK (TH_SFLAG_ABORT | TH_SFLAG_ABORTSAFELY)
202 #define TH_SFLAG_DEPRESS 0x0040 /* normal depress yield */
203 #define TH_SFLAG_POLLDEPRESS 0x0080 /* polled depress yield */
204 #define TH_SFLAG_DEPRESSED_MASK (TH_SFLAG_DEPRESS | TH_SFLAG_POLLDEPRESS)
205 #define TH_SFLAG_PRI_UPDATE 0x0100 /* Updating priority */
206 #define TH_SFLAG_EAGERPREEMPT 0x0200 /* Any preemption of this thread should be treated as if AST_URGENT applied */
209 * A thread can either be completely unthrottled, about to be throttled,
210 * throttled (TH_SFLAG_THROTTLED), or about to be unthrottled
212 #define TH_SFLAG_PENDING_THROTTLE_DEMOTION 0x1000 /* Pending sched_mode demotion */
213 #define TH_SFLAG_PENDING_THROTTLE_PROMOTION 0x2000 /* Pending sched_mode promition */
214 #define TH_SFLAG_PENDING_THROTTLE_MASK (TH_SFLAG_PENDING_THROTTLE_DEMOTION | TH_SFLAG_PENDING_THROTTLE_PROMOTION)
216 integer_t sched_pri
; /* scheduled (current) priority */
217 integer_t priority
; /* base priority */
218 integer_t max_priority
; /* max base priority */
219 integer_t task_priority
; /* copy of task base priority */
221 #if defined(CONFIG_SCHED_GRRR)
223 uint16_t grrr_deficit
; /* fixed point (1/1000th quantum) fractional deficit */
227 integer_t promotions
; /* level of promotion */
228 integer_t pending_promoter_index
;
229 void *pending_promoter
[2];
231 integer_t importance
; /* task-relative importance */
233 /* real-time parameters */
234 struct { /* see mach/thread_policy.h */
236 uint32_t computation
;
238 boolean_t preemptible
;
243 uint32_t was_promoted_on_wakeup
;
244 uint32_t current_quantum
; /* duration of current quantum */
245 uint64_t last_run_time
; /* time when thread was switched away from */
246 uint64_t last_quantum_refill_time
; /* time when current_quantum was refilled after expiration */
248 /* Data used during setrun/dispatch */
249 timer_data_t system_timer
; /* system mode timer */
250 processor_t bound_processor
; /* bound to a processor? */
251 processor_t last_processor
; /* processor last dispatched on */
252 processor_t chosen_processor
; /* Where we want to run this thread */
254 /* Fail-safe computation since last unblock or qualifying yield */
255 uint64_t computation_metered
;
256 uint64_t computation_epoch
;
257 uint64_t safe_release
; /* when to release fail-safe */
259 /* Call out from scheduler */
263 #if defined(CONFIG_SCHED_PROTO)
264 uint32_t runqueue_generation
; /* last time runqueue was drained */
267 /* Statistics and timesharing calculations */
268 #if defined(CONFIG_SCHED_TRADITIONAL)
269 natural_t sched_stamp
; /* last scheduler tick */
270 natural_t sched_usage
; /* timesharing cpu usage [sched] */
271 natural_t pri_shift
; /* usage -> priority from pset */
272 natural_t cpu_usage
; /* instrumented cpu usage [%cpu] */
273 natural_t cpu_delta
; /* accumulated cpu_usage delta */
275 uint32_t c_switch
; /* total context switches */
276 uint32_t p_switch
; /* total processor switches */
277 uint32_t ps_switch
; /* total pset switches */
279 /* Timing data structures */
280 int precise_user_kernel_time
; /* precise user/kernel enabled for this thread */
281 timer_data_t user_timer
; /* user mode timer */
282 uint64_t user_timer_save
; /* saved user timer value */
283 uint64_t system_timer_save
; /* saved system timer value */
284 uint64_t vtimer_user_save
; /* saved values for vtimers */
285 uint64_t vtimer_prof_save
;
286 uint64_t vtimer_rlim_save
;
288 /* Timed wait expiration */
289 timer_call_data_t wait_timer
;
290 integer_t wait_timer_active
;
291 boolean_t wait_timer_is_set
;
293 /* Priority depression expiration */
294 timer_call_data_t depress_timer
;
295 integer_t depress_timer_active
;
298 * Processor/cache affinity
299 * - affinity_threads links task threads with the same affinity set
301 affinity_set_t affinity_set
;
302 queue_chain_t affinity_threads
;
304 /* Various bits of stashed state */
307 mach_msg_return_t state
; /* receive state */
308 ipc_object_t object
; /* object received on */
309 mach_vm_address_t msg_addr
; /* receive buffer pointer */
310 mach_msg_size_t msize
; /* max size for recvd msg */
311 mach_msg_option_t option
; /* options for receive */
312 mach_msg_size_t slist_size
; /* scatter list size */
313 mach_port_name_t receiver_name
; /* the receive port name */
314 struct ipc_kmsg
*kmsg
; /* received message */
315 mach_port_seqno_t seqno
; /* seqno of recvd message */
316 mach_msg_continue_t continuation
;
319 struct semaphore
*waitsemaphore
; /* semaphore ref */
320 struct semaphore
*signalsemaphore
; /* semaphore ref */
321 int options
; /* semaphore options */
322 kern_return_t result
; /* primary result */
323 mach_msg_continue_t continuation
;
326 int option
; /* switch option */
328 int misc
; /* catch-all for other state */
331 /* IPC data structures */
332 struct ipc_kmsg_queue ith_messages
;
333 mach_port_t ith_rpc_reply
; /* reply port for kernel RPCs */
335 /* Ast/Halt data structures */
336 vm_offset_t recover
; /* page fault recover(copyin/out) */
337 uint32_t ref_count
; /* number of references to me */
339 queue_chain_t threads
; /* global list of all threads */
342 queue_chain_t task_threads
;
344 /*** Machine-dependent state ***/
345 struct machine_thread machine
;
347 /* Task membership */
351 decl_lck_mtx_data(,mutex
)
353 /* Kernel holds on this thread */
356 /* User level suspensions */
359 /* Pending thread ast(s) */
362 /* Miscellaneous bits guarded by mutex */
364 active
:1, /* Thread is active and has not been terminated */
365 started
:1, /* Thread has been started after creation */
366 static_param
:1, /* Disallow policy parameter changes */
370 struct ReturnHandler
{
371 struct ReturnHandler
*next
;
373 struct ReturnHandler
*rh
,
374 struct thread
*thread
);
375 } *handlers
, special_handler
;
377 /* Ports associated with this thread */
378 struct ipc_port
*ith_self
; /* not a right, doesn't hold ref */
379 struct ipc_port
*ith_sself
; /* a send right */
380 struct exception_action exc_actions
[EXC_TYPES_COUNT
];
382 /* Owned ulocks (a lock set element) */
383 queue_head_t held_ulocks
;
390 uint32_t t_dtrace_predcache
;/* DTrace per thread predicate value hint */
391 int64_t t_dtrace_tracing
; /* Thread time under dtrace_probe() */
392 int64_t t_dtrace_vtime
;
395 uint32_t t_page_creation_count
;
396 clock_sec_t t_page_creation_time
;
398 #define T_CHUD_MARKED 0x01 /* this thread is marked by CHUD */
399 #define T_IN_CHUD 0x02 /* this thread is already in a CHUD handler */
400 #define THREAD_PMC_FLAG 0x04 /* Bit in "t_chud" signifying PMC interest */
401 #define T_AST_CALLSTACK 0x08 /* Thread scheduled to dump a
402 * callstack on its next
404 #define T_AST_NAME 0x10 /* Thread scheduled to dump
405 * its name on its next
407 #define T_NAME_DONE 0x20 /* Thread has previously
408 * recorded its name */
410 uint32_t t_chud
; /* CHUD flags, used for Shark */
411 uint32_t chud_c_switch
; /* last dispatch detection */
413 integer_t mutex_count
; /* total count of locks held */
415 uint64_t thread_id
; /*system wide unique thread-id*/
417 /* Statistics accumulated per-thread and aggregated per-task */
418 uint32_t syscalls_unix
;
419 uint32_t syscalls_mach
;
421 ledger_t t_threadledger
; /* per thread ledger */
422 struct process_policy ext_appliedstate
; /* externally applied actions */
423 struct process_policy ext_policystate
; /* externally defined process policy states*/
424 struct process_policy appliedstate
; /* self applied acions */
425 struct process_policy policystate
; /* process wide policy states */
427 task_watch_t
* taskwatch
; /* task watch */
428 integer_t saved_importance
; /* saved task-relative importance */
429 #endif /* CONFIG_EMBEDDED */
432 #define ith_state saved.receive.state
433 #define ith_object saved.receive.object
434 #define ith_msg_addr saved.receive.msg_addr
435 #define ith_msize saved.receive.msize
436 #define ith_option saved.receive.option
437 #define ith_scatter_list_size saved.receive.slist_size
438 #define ith_receiver_name saved.receive.receiver_name
439 #define ith_continuation saved.receive.continuation
440 #define ith_kmsg saved.receive.kmsg
441 #define ith_seqno saved.receive.seqno
443 #define sth_waitsemaphore saved.sema.waitsemaphore
444 #define sth_signalsemaphore saved.sema.signalsemaphore
445 #define sth_options saved.sema.options
446 #define sth_result saved.sema.result
447 #define sth_continuation saved.sema.continuation
449 extern void thread_bootstrap(void) __attribute__((section("__TEXT, initcode")));
451 extern void thread_init(void) __attribute__((section("__TEXT, initcode")));
453 extern void thread_daemon_init(void);
455 #define thread_reference_internal(thread) \
456 (void)hw_atomic_add(&(thread)->ref_count, 1)
458 #define thread_deallocate_internal(thread) \
459 hw_atomic_sub(&(thread)->ref_count, 1)
461 #define thread_reference(thread) \
463 if ((thread) != THREAD_NULL) \
464 thread_reference_internal(thread); \
467 extern void thread_deallocate(
470 extern void thread_terminate_self(void);
472 extern kern_return_t
thread_terminate_internal(
475 extern void thread_start_internal(
476 thread_t thread
) __attribute__ ((noinline
));
478 extern void thread_terminate_enqueue(
481 extern void thread_stack_enqueue(
484 extern void thread_hold(
487 extern void thread_release(
491 #define thread_lock_init(th) simple_lock_init(&(th)->sched_lock, 0)
492 #define thread_lock(th) simple_lock(&(th)->sched_lock)
493 #define thread_unlock(th) simple_unlock(&(th)->sched_lock)
495 #define wake_lock_init(th) simple_lock_init(&(th)->wake_lock, 0)
496 #define wake_lock(th) simple_lock(&(th)->wake_lock)
497 #define wake_unlock(th) simple_unlock(&(th)->wake_lock)
499 #define thread_should_halt_fast(thread) (!(thread)->active)
501 extern void stack_alloc(
504 extern void stack_handoff(
508 extern void stack_free(
511 extern void stack_free_reserved(
514 extern boolean_t
stack_alloc_try(
517 extern void stack_collect(void);
519 extern void stack_init(void) __attribute__((section("__TEXT, initcode")));
522 extern kern_return_t
thread_info_internal(
524 thread_flavor_t flavor
,
525 thread_info_t thread_info_out
,
526 mach_msg_type_number_t
*thread_info_count
);
528 extern void thread_task_priority(
531 integer_t max_priority
);
533 extern void thread_policy_reset(
536 extern kern_return_t
kernel_thread_create(
537 thread_continue_t continuation
,
540 thread_t
*new_thread
);
542 extern kern_return_t
kernel_thread_start_priority(
543 thread_continue_t continuation
,
546 thread_t
*new_thread
);
548 extern void machine_stack_attach(
552 extern vm_offset_t
machine_stack_detach(
555 extern void machine_stack_handoff(
559 extern thread_t
machine_switch_context(
561 thread_continue_t continuation
,
562 thread_t new_thread
);
564 extern void machine_load_context(
567 extern kern_return_t
machine_thread_state_initialize(
570 extern kern_return_t
machine_thread_set_state(
572 thread_flavor_t flavor
,
573 thread_state_t state
,
574 mach_msg_type_number_t count
);
576 extern kern_return_t
machine_thread_get_state(
578 thread_flavor_t flavor
,
579 thread_state_t state
,
580 mach_msg_type_number_t
*count
);
582 extern kern_return_t
machine_thread_dup(
586 extern void machine_thread_init(void);
588 extern kern_return_t
machine_thread_create(
591 extern void machine_thread_switch_addrmode(
594 extern void machine_thread_destroy(
597 extern void machine_set_current_thread(
600 extern kern_return_t
machine_thread_get_kern_state(
602 thread_flavor_t flavor
,
603 thread_state_t tstate
,
604 mach_msg_type_number_t
*count
);
606 extern kern_return_t
machine_thread_inherit_taskwide(
611 * XXX Funnel locks XXX
615 int fnl_type
; /* funnel type */
616 lck_mtx_t
*fnl_mutex
; /* underlying mutex for the funnel */
617 void * fnl_mtxholder
; /* thread (last)holdng mutex */
618 void * fnl_mtxrelease
; /* thread (last)releasing mutex */
619 lck_mtx_t
*fnl_oldmutex
; /* Mutex before collapsing split funnel */
622 typedef struct ReturnHandler ReturnHandler
;
624 #define thread_mtx_lock(thread) lck_mtx_lock(&(thread)->mutex)
625 #define thread_mtx_try(thread) lck_mtx_try_lock(&(thread)->mutex)
626 #define thread_mtx_unlock(thread) lck_mtx_unlock(&(thread)->mutex)
628 extern void act_execute_returnhandlers(void);
630 extern void install_special_handler(
633 extern void special_handler(
637 void act_machine_sv_free(thread_t
, int);
639 vm_offset_t
min_valid_stack_address(void);
640 vm_offset_t
max_valid_stack_address(void);
642 extern void funnel_lock(
643 struct funnel_lock
*lock
);
645 extern void funnel_unlock(
646 struct funnel_lock
*lock
);
648 #else /* MACH_KERNEL_PRIVATE */
652 extern thread_t
current_thread(void);
654 extern void thread_reference(
657 extern void thread_deallocate(
662 #endif /* MACH_KERNEL_PRIVATE */
664 #ifdef KERNEL_PRIVATE
668 #if defined(__i386__)
670 extern thread_t
kernel_thread(
672 void (*start
)(void));
674 #endif /* defined(__i386__) */
676 extern uint64_t thread_tid(
679 extern uint64_t thread_dispatchqaddr(
684 #endif /* KERNEL_PRIVATE */
688 #ifdef XNU_KERNEL_PRIVATE
690 extern kern_return_t
thread_state_initialize(
693 extern kern_return_t
thread_setstatus(
696 thread_state_t tstate
,
697 mach_msg_type_number_t count
);
699 extern kern_return_t
thread_getstatus(
702 thread_state_t tstate
,
703 mach_msg_type_number_t
*count
);
705 extern kern_return_t
thread_create_workq(
707 thread_continue_t thread_return
,
708 thread_t
*new_thread
);
710 extern void thread_yield_internal(
711 mach_msg_timeout_t interval
);
714 * Thread-private CPU limits: apply a private CPU limit to this thread only. Available actions are:
716 * 1) Block. Prevent CPU consumption of the thread from exceeding the limit.
717 * 2) Exception. Generate a resource consumption exception when the limit is exceeded.
719 #define THREAD_CPULIMIT_BLOCK 0x1
720 #define THREAD_CPULIMIT_EXCEPTION 0x2
722 struct _thread_ledger_indices
{
726 extern struct _thread_ledger_indices thread_ledgers
;
728 extern int thread_set_cpulimit(int action
, uint8_t percentage
, uint64_t interval_ns
);
730 typedef struct funnel_lock funnel_t
;
732 #define THR_FUNNEL_NULL (funnel_t *)0
734 extern funnel_t
*funnel_alloc(
737 extern void funnel_free(
740 extern funnel_t
*thread_funnel_get(void);
742 extern boolean_t
thread_funnel_set(
746 extern void thread_read_times(
748 time_value_t
*user_time
,
749 time_value_t
*system_time
);
751 extern void thread_setuserstack(
753 mach_vm_offset_t user_stack
);
755 extern uint64_t thread_adjuserstack(
759 extern void thread_setentrypoint(
761 mach_vm_offset_t entry
);
763 extern kern_return_t
thread_setsinglestep(
767 extern kern_return_t
thread_userstack(
775 extern kern_return_t
thread_entrypoint(
782 extern kern_return_t
thread_userstackdefault(
786 extern kern_return_t
thread_wire_internal(
787 host_priv_t host_priv
,
790 boolean_t
*prev_state
);
792 extern kern_return_t
thread_dup(thread_t
);
794 typedef void (*sched_call_t
)(
798 #define SCHED_CALL_BLOCK 0x1
799 #define SCHED_CALL_UNBLOCK 0x2
801 extern void thread_sched_call(
805 extern void thread_static_param(
809 extern kern_return_t
thread_policy_set_internal(
811 thread_policy_flavor_t flavor
,
812 thread_policy_t policy_info
,
813 mach_msg_type_number_t count
);
816 extern task_t
get_threadtask(thread_t
);
817 #define thread_is_64bit(thd) \
818 task_has_64BitAddr(get_threadtask(thd))
821 extern void *get_bsdthread_info(thread_t
);
822 extern void set_bsdthread_info(thread_t
, void *);
823 extern void *uthread_alloc(task_t
, thread_t
, int);
824 extern void uthread_cleanup(task_t
, void *, void *);
825 extern void uthread_zone_free(void *);
826 extern void uthread_cred_free(void *);
828 extern boolean_t
thread_should_halt(
831 extern boolean_t
thread_should_abort(
834 extern int is_64signalregset(void);
836 void act_set_apc(thread_t
);
837 void act_set_kperf(thread_t
);
839 extern uint32_t dtrace_get_thread_predcache(thread_t
);
840 extern int64_t dtrace_get_thread_vtime(thread_t
);
841 extern int64_t dtrace_get_thread_tracing(thread_t
);
842 extern boolean_t
dtrace_get_thread_reentering(thread_t
);
843 extern vm_offset_t
dtrace_get_kernel_stack(thread_t
);
844 extern void dtrace_set_thread_predcache(thread_t
, uint32_t);
845 extern void dtrace_set_thread_vtime(thread_t
, int64_t);
846 extern void dtrace_set_thread_tracing(thread_t
, int64_t);
847 extern void dtrace_set_thread_reentering(thread_t
, boolean_t
);
848 extern vm_offset_t
dtrace_set_thread_recover(thread_t
, vm_offset_t
);
849 extern void dtrace_thread_bootstrap(void);
851 extern int64_t dtrace_calc_thread_recent_vtime(thread_t
);
854 extern void thread_set_wq_state32(
856 thread_state_t tstate
);
858 extern void thread_set_wq_state64(
860 thread_state_t tstate
);
862 extern vm_offset_t kernel_stack_mask
;
863 extern vm_offset_t kernel_stack_size
;
864 extern vm_offset_t kernel_stack_depth_max
;
866 #endif /* XNU_KERNEL_PRIVATE */
868 /*! @function kernel_thread_start
869 @abstract Create a kernel thread.
870 @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).
871 @param continuation A C-function pointer where the thread will begin execution.
872 @param parameter Caller specified data to be passed to the new thread.
873 @param new_thread Reference to the new thread is returned in this parameter.
874 @result Returns KERN_SUCCESS on success or an appropriate kernel code type.
877 extern kern_return_t
kernel_thread_start(
878 thread_continue_t continuation
,
880 thread_t
*new_thread
);
881 #ifdef KERNEL_PRIVATE
882 void thread_set_eager_preempt(thread_t thread
);
883 void thread_clear_eager_preempt(thread_t thread
);
884 extern ipc_port_t
convert_thread_to_port(thread_t
);
885 #endif /* KERNEL_PRIVATE */
889 #endif /* _KERN_THREAD_H_ */