]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/thread.h
xnu-3789.51.2.tar.gz
[apple/xnu.git] / osfmk / kern / thread.h
CommitLineData
1c79356b 1/*
39037602 2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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>
55e303ae 91#include <mach/vm_param.h>
1c79356b
A
92#include <mach/thread_info.h>
93#include <mach/thread_status.h>
55e303ae 94#include <mach/exception_types.h>
9bccf70c 95
1c79356b
A
96#include <kern/kern_types.h>
97
91447636 98#include <sys/cdefs.h>
1c79356b 99
9bccf70c 100#ifdef MACH_KERNEL_PRIVATE
1c79356b 101
55e303ae 102#include <mach_assert.h>
1c79356b
A
103#include <mach_ldebug.h>
104
91447636
A
105#include <ipc/ipc_types.h>
106
1c79356b 107#include <mach/port.h>
1c79356b 108#include <kern/cpu_number.h>
3e170ce0 109#include <kern/smp.h>
1c79356b 110#include <kern/queue.h>
1c79356b 111#include <kern/timer.h>
fe8ab488 112#include <kern/simple_lock.h>
91447636 113#include <kern/locks.h>
1c79356b
A
114#include <kern/sched.h>
115#include <kern/sched_prim.h>
fe8ab488 116#include <mach/sfi_class.h>
1c79356b
A
117#include <kern/thread_call.h>
118#include <kern/timer_call.h>
119#include <kern/task.h>
55e303ae 120#include <kern/exception.h>
2d21ac55 121#include <kern/affinity.h>
813fb2f6
A
122#include <kern/debug.h>
123#include <kern/block_hint.h>
91447636 124
3e170ce0
A
125#include <kern/waitq.h>
126
1c79356b 127#include <ipc/ipc_kmsg.h>
55e303ae 128
91447636 129#include <machine/cpu_data.h>
1c79356b
A
130#include <machine/thread.h>
131
39037602 132
55e303ae 133struct thread {
39037602
A
134
135#if MACH_ASSERT
136#define THREAD_MAGIC 0x1234ABCDDCBA4321ULL
137 /* Ensure nothing uses &thread as a queue entry */
138 uint64_t thread_magic;
139#endif /* MACH_ASSERT */
140
1c79356b 141 /*
9bccf70c 142 * NOTE: The runq field in the thread structure has an unusual
2d21ac55 143 * locking protocol. If its value is PROCESSOR_NULL, then it is
9bccf70c 144 * locked by the thread_lock, but if its value is something else
fe8ab488
A
145 * then it is locked by the associated run queue lock. It is
146 * set to PROCESSOR_NULL without holding the thread lock, but the
147 * transition from PROCESSOR_NULL to non-null must be done
148 * under the thread lock and the run queue lock.
9bccf70c 149 *
3e170ce0
A
150 * New waitq APIs allow the 'links' and 'runq' fields to be
151 * anywhere in the thread structure.
1c79356b 152 */
39037602
A
153 union {
154 queue_chain_t runq_links; /* run queue links */
155 queue_chain_t wait_links; /* wait queue links */
156 };
157
158 processor_t runq; /* run queue assignment */
159
160 event64_t wait_event; /* wait queue event */
161 struct waitq *waitq; /* wait queue this thread is enqueued on */
162
9bccf70c 163 /* Data updated during assert_wait/thread_wakeup */
3e170ce0 164#if __SMP__
55e303ae 165 decl_simple_lock_data(,sched_lock) /* scheduling lock (thread_lock()) */
2d21ac55 166 decl_simple_lock_data(,wake_lock) /* for thread stop / wait (wake_lock()) */
3e170ce0 167#endif
39236c6e
A
168 integer_t options; /* options set by thread itself */
169#define TH_OPT_INTMASK 0x0003 /* interrupt / abort level */
170#define TH_OPT_VMPRIV 0x0004 /* may allocate reserved memory */
171#define TH_OPT_DTRACE 0x0008 /* executing under dtrace_probe */
172#define TH_OPT_SYSTEM_CRITICAL 0x0010 /* Thread must always be allowed to run - even under heavy load */
173#define TH_OPT_PROC_CPULIMIT 0x0020 /* Thread has a task-wide CPU limit applied to it */
174#define TH_OPT_PRVT_CPULIMIT 0x0040 /* Thread has a thread-private CPU limit applied to it */
3e170ce0
A
175#define TH_OPT_IDLE_THREAD 0x0080 /* Thread is a per-processor idle thread */
176#define TH_OPT_GLOBAL_FORCED_IDLE 0x0100 /* Thread performs forced idle for thermal control */
177#define TH_OPT_SCHED_VM_GROUP 0x0200 /* Thread belongs to special scheduler VM group */
178#define TH_OPT_HONOR_QLIMIT 0x0400 /* Thread will honor qlimit while sending mach_msg, regardless of MACH_SEND_ALWAYS */
490019cf 179#define TH_OPT_SEND_IMPORTANCE 0x0800 /* Thread will allow importance donation from kernel rpc */
39236c6e 180
2d21ac55 181 boolean_t wake_active; /* wake event on stop */
9bccf70c
A
182 int at_safe_point; /* thread_abort_safely allowed */
183 ast_t reason; /* why we blocked */
3e170ce0
A
184 uint32_t quantum_remaining;
185 wait_result_t wait_result; /* outcome of wait -
186 * may be examined by this thread
187 * WITHOUT locking */
39236c6e
A
188 thread_continue_t continuation; /* continue here next dispatch */
189 void *parameter; /* continuation parameter */
0b4e3aa0 190
9bccf70c 191 /* Data updated/used in thread_invoke */
9bccf70c 192 vm_offset_t kernel_stack; /* current kernel stack */
55e303ae 193 vm_offset_t reserved_stack; /* reserved kernel stack */
0b4e3aa0
A
194
195 /* Thread state: */
9bccf70c 196 int state;
1c79356b
A
197/*
198 * Thread states [bits or'ed]
199 */
55e303ae
A
200#define TH_WAIT 0x01 /* queued for waiting */
201#define TH_SUSP 0x02 /* stopped or requested to stop */
202#define TH_RUN 0x04 /* running or on runq */
203#define TH_UNINT 0x08 /* waiting uninteruptibly */
3e170ce0
A
204#define TH_TERMINATE 0x10 /* halted at termination */
205#define TH_TERMINATE2 0x20 /* added to termination queue */
1c79356b 206
2d21ac55 207#define TH_IDLE 0x80 /* idling processor */
1c79356b 208
9bccf70c 209 /* Scheduling information */
6d2010ae
A
210 sched_mode_t sched_mode; /* scheduling mode */
211 sched_mode_t saved_mode; /* saved mode during forced mode demotion */
fe8ab488 212
39037602
A
213 /* This thread's contribution to global sched counters */
214 sched_bucket_t th_sched_bucket;
215
fe8ab488
A
216 sfi_class_id_t sfi_class; /* SFI class (XXX Updated on CSW/QE/AST) */
217 sfi_class_id_t sfi_wait_class; /* Currently in SFI wait for this class, protected by sfi_lock */
39037602
A
218
219
fe8ab488 220 uint32_t sched_flags; /* current flag bits */
3e170ce0 221/* TH_SFLAG_FAIRSHARE_TRIPPED (unused) 0x0001 */
6d2010ae 222#define TH_SFLAG_FAILSAFE 0x0002 /* fail-safe has tripped */
39037602
A
223#define TH_SFLAG_THROTTLED 0x0004 /* throttled thread forced to timeshare mode (may be applied in addition to failsafe) */
224#define TH_SFLAG_DEMOTED_MASK (TH_SFLAG_THROTTLED | TH_SFLAG_FAILSAFE) /* saved_mode contains previous sched_mode */
6d2010ae
A
225
226#define TH_SFLAG_PROMOTED 0x0008 /* sched pri has been promoted */
227#define TH_SFLAG_ABORT 0x0010 /* abort interruptible waits */
228#define TH_SFLAG_ABORTSAFELY 0x0020 /* ... but only those at safe point */
229#define TH_SFLAG_ABORTED_MASK (TH_SFLAG_ABORT | TH_SFLAG_ABORTSAFELY)
230#define TH_SFLAG_DEPRESS 0x0040 /* normal depress yield */
231#define TH_SFLAG_POLLDEPRESS 0x0080 /* polled depress yield */
232#define TH_SFLAG_DEPRESSED_MASK (TH_SFLAG_DEPRESS | TH_SFLAG_POLLDEPRESS)
39037602 233/* unused TH_SFLAG_PRI_UPDATE 0x0100 */
6d2010ae 234#define TH_SFLAG_EAGERPREEMPT 0x0200 /* Any preemption of this thread should be treated as if AST_URGENT applied */
39236c6e 235#define TH_SFLAG_RW_PROMOTED 0x0400 /* sched pri has been promoted due to blocking with RW lock held */
39037602 236/* unused TH_SFLAG_THROTTLE_DEMOTED 0x0800 */
3e170ce0
A
237#define TH_SFLAG_WAITQ_PROMOTED 0x1000 /* sched pri promoted from waitq wakeup (generally for IPC receive) */
238#define TH_SFLAG_PROMOTED_MASK (TH_SFLAG_PROMOTED | TH_SFLAG_RW_PROMOTED | TH_SFLAG_WAITQ_PROMOTED)
39236c6e
A
239
240#define TH_SFLAG_RW_PROMOTED_BIT (10) /* 0x400 */
6d2010ae 241
3e170ce0
A
242 int16_t sched_pri; /* scheduled (current) priority */
243 int16_t base_pri; /* base priority */
244 int16_t max_priority; /* copy of max base priority */
245 int16_t task_priority; /* copy of task base priority */
246
6d2010ae
A
247#if defined(CONFIG_SCHED_GRRR)
248#if 0
249 uint16_t grrr_deficit; /* fixed point (1/1000th quantum) fractional deficit */
250#endif
251#endif
252
39236c6e
A
253 int16_t promotions; /* level of promotion */
254 int16_t pending_promoter_index;
255 uint32_t ref_count; /* number of references to me */
9bccf70c 256 void *pending_promoter[2];
1c79356b 257
39236c6e 258 uint32_t rwlock_count; /* Number of lck_rw_t locks held by thread */
1c79356b 259
39236c6e 260 integer_t importance; /* task-relative importance */
3e170ce0 261 uint32_t was_promoted_on_wakeup;
fe8ab488 262
39236c6e
A
263 /* Priority depression expiration */
264 integer_t depress_timer_active;
265 timer_call_data_t depress_timer;
266 /* real-time parameters */
9bccf70c 267 struct { /* see mach/thread_policy.h */
0b4e3aa0
A
268 uint32_t period;
269 uint32_t computation;
270 uint32_t constraint;
1c79356b 271 boolean_t preemptible;
55e303ae 272 uint64_t deadline;
1c79356b
A
273 } realtime;
274
6d2010ae 275 uint64_t last_run_time; /* time when thread was switched away from */
3e170ce0 276 uint64_t last_made_runnable_time; /* time when thread was unblocked or preempted */
fe8ab488
A
277
278#if defined(CONFIG_SCHED_MULTIQ)
279 sched_group_t sched_group;
280#endif /* defined(CONFIG_SCHED_MULTIQ) */
0b4e3aa0 281
9bccf70c
A
282 /* Data used during setrun/dispatch */
283 timer_data_t system_timer; /* system mode timer */
9bccf70c
A
284 processor_t bound_processor; /* bound to a processor? */
285 processor_t last_processor; /* processor last dispatched on */
6d2010ae 286 processor_t chosen_processor; /* Where we want to run this thread */
9bccf70c 287
0b4e3aa0 288 /* Fail-safe computation since last unblock or qualifying yield */
9bccf70c 289 uint64_t computation_metered;
0b4e3aa0 290 uint64_t computation_epoch;
6d2010ae 291 uint64_t safe_release; /* when to release fail-safe */
1c79356b 292
2d21ac55
A
293 /* Call out from scheduler */
294 void (*sched_call)(
295 int type,
296 thread_t thread);
6d2010ae
A
297#if defined(CONFIG_SCHED_PROTO)
298 uint32_t runqueue_generation; /* last time runqueue was drained */
299#endif
300
55e303ae 301 /* Statistics and timesharing calculations */
fe8ab488 302#if defined(CONFIG_SCHED_TIMESHARE_CORE)
91447636
A
303 natural_t sched_stamp; /* last scheduler tick */
304 natural_t sched_usage; /* timesharing cpu usage [sched] */
305 natural_t pri_shift; /* usage -> priority from pset */
306 natural_t cpu_usage; /* instrumented cpu usage [%cpu] */
307 natural_t cpu_delta; /* accumulated cpu_usage delta */
fe8ab488
A
308#endif /* CONFIG_SCHED_TIMESHARE_CORE */
309
2d21ac55
A
310 uint32_t c_switch; /* total context switches */
311 uint32_t p_switch; /* total processor switches */
312 uint32_t ps_switch; /* total pset switches */
1c79356b 313
3e170ce0 314 integer_t mutex_count; /* total count of locks held */
9bccf70c 315 /* Timing data structures */
316670eb 316 int precise_user_kernel_time; /* precise user/kernel enabled for this thread */
91447636 317 timer_data_t user_timer; /* user mode timer */
91447636 318 uint64_t user_timer_save; /* saved user timer value */
2d21ac55
A
319 uint64_t system_timer_save; /* saved system timer value */
320 uint64_t vtimer_user_save; /* saved values for vtimers */
321 uint64_t vtimer_prof_save;
322 uint64_t vtimer_rlim_save;
39037602 323 uint64_t vtimer_qos_save;
1c79356b 324
3e170ce0 325#if CONFIG_SCHED_SFI
fe8ab488
A
326 /* Timing for wait state */
327 uint64_t wait_sfi_begin_time; /* start time for thread waiting in SFI */
3e170ce0 328#endif
fe8ab488 329
9bccf70c 330 /* Timed wait expiration */
91447636
A
331 timer_call_data_t wait_timer;
332 integer_t wait_timer_active;
333 boolean_t wait_timer_is_set;
1c79356b 334
1c79356b 335
2d21ac55
A
336 /*
337 * Processor/cache affinity
338 * - affinity_threads links task threads with the same affinity set
339 */
340 affinity_set_t affinity_set;
341 queue_chain_t affinity_threads;
342
1c79356b
A
343 /* Various bits of stashed state */
344 union {
345 struct {
0b4e3aa0 346 mach_msg_return_t state; /* receive state */
39236c6e 347 mach_port_seqno_t seqno; /* seqno of recvd message */
0b4e3aa0 348 ipc_object_t object; /* object received on */
91447636 349 mach_vm_address_t msg_addr; /* receive buffer pointer */
39037602
A
350 mach_msg_size_t rsize; /* max size for recvd msg */
351 mach_msg_size_t msize; /* actual size for recvd msg */
0b4e3aa0 352 mach_msg_option_t option; /* options for receive */
b0d623f7 353 mach_port_name_t receiver_name; /* the receive port name */
39037602
A
354 union {
355 struct ipc_kmsg *kmsg; /* received message */
356 struct ipc_mqueue *peekq; /* mqueue to peek at */
357 struct {
358 mach_msg_priority_t qos; /* received message qos */
359 mach_msg_priority_t oqos; /* override qos for message */
360 } received_qos;
361 };
9bccf70c
A
362 mach_msg_continue_t continuation;
363 } receive;
1c79356b 364 struct {
0b4e3aa0
A
365 struct semaphore *waitsemaphore; /* semaphore ref */
366 struct semaphore *signalsemaphore; /* semaphore ref */
367 int options; /* semaphore options */
368 kern_return_t result; /* primary result */
9bccf70c
A
369 mach_msg_continue_t continuation;
370 } sema;
1c79356b 371 struct {
9bccf70c 372 int option; /* switch option */
39236c6e 373 boolean_t reenable_workq_callback; /* on entry, callbacks were suspended */
9bccf70c
A
374 } swtch;
375 int misc; /* catch-all for other state */
376 } saved;
1c79356b 377
39236c6e
A
378 /* Structure to save information about guard exception */
379 struct {
380 unsigned type; /* EXC_GUARD reason/type */
381 mach_exception_data_type_t code; /* Exception code */
382 mach_exception_data_type_t subcode; /* Exception sub-code */
383 } guard_exc_info;
384
3e170ce0
A
385 /* Kernel holds on this thread */
386 int16_t suspend_count;
387 /* User level suspensions */
388 int16_t user_stop_count;
39236c6e 389
9bccf70c 390 /* IPC data structures */
39236c6e
A
391#if IMPORTANCE_INHERITANCE
392 natural_t ith_assertions; /* assertions pending drop */
393#endif
394 struct ipc_kmsg_queue ith_messages; /* messages to reap */
9bccf70c 395 mach_port_t ith_rpc_reply; /* reply port for kernel RPCs */
1c79356b
A
396
397 /* Ast/Halt data structures */
b0d623f7 398 vm_offset_t recover; /* page fault recover(copyin/out) */
1c79356b 399
b0d623f7 400 queue_chain_t threads; /* global list of all threads */
1c79356b 401
55e303ae
A
402 /* Activation */
403 queue_chain_t task_threads;
404
55e303ae
A
405 /* Task membership */
406 struct task *task;
407 vm_map_t map;
408
b0d623f7 409 decl_lck_mtx_data(,mutex)
55e303ae 410
55e303ae
A
411
412 /* Pending thread ast(s) */
413 ast_t ast;
414
91447636 415 /* Miscellaneous bits guarded by mutex */
55e303ae 416 uint32_t
39037602
A
417 active:1, /* Thread is active and has not been terminated */
418 started:1, /* Thread has been started after creation */
419 static_param:1, /* Disallow policy parameter changes */
420 inspection:1, /* TRUE when task is being inspected by crash reporter */
421 policy_reset:1, /* Disallow policy parameter changes on terminating threads */
422 suspend_parked:1, /* thread parked in thread_suspended */
423 corpse_dup:1, /* TRUE when thread is an inactive duplicate in a corpse */
2d21ac55 424 :0;
39037602 425
55e303ae
A
426 /* Ports associated with this thread */
427 struct ipc_port *ith_self; /* not a right, doesn't hold ref */
428 struct ipc_port *ith_sself; /* a send right */
39236c6e 429 struct exception_action *exc_actions;
55e303ae 430
55e303ae
A
431#ifdef MACH_BSD
432 void *uthread;
433#endif
2d21ac55
A
434
435#if CONFIG_DTRACE
39236c6e
A
436 uint32_t t_dtrace_flags; /* DTrace thread states */
437#define TH_DTRACE_EXECSUCCESS 0x01
2d21ac55
A
438 uint32_t t_dtrace_predcache;/* DTrace per thread predicate value hint */
439 int64_t t_dtrace_tracing; /* Thread time under dtrace_probe() */
440 int64_t t_dtrace_vtime;
441#endif
b0d623f7 442
b0d623f7 443 clock_sec_t t_page_creation_time;
39236c6e 444 uint32_t t_page_creation_count;
3e170ce0 445 uint32_t t_page_creation_throttled;
04b8595b 446#if (DEVELOPMENT || DEBUG)
3e170ce0
A
447 uint64_t t_page_creation_throttled_hard;
448 uint64_t t_page_creation_throttled_soft;
04b8595b
A
449#endif /* DEVELOPMENT || DEBUG */
450
39037602
A
451#ifdef KPERF
452/* The high 7 bits are the number of frames to sample of a user callstack. */
453#define T_KPERF_CALLSTACK_DEPTH_OFFSET (25)
454#define T_KPERF_SET_CALLSTACK_DEPTH(DEPTH) (((uint32_t)(DEPTH)) << T_KPERF_CALLSTACK_DEPTH_OFFSET)
455#define T_KPERF_GET_CALLSTACK_DEPTH(FLAGS) ((FLAGS) >> T_KPERF_CALLSTACK_DEPTH_OFFSET)
456#endif
457
458#define T_KPERF_AST_CALLSTACK (1U << 0) /* dump a callstack on thread's next AST */
459#define T_KPERF_AST_DISPATCH (1U << 1) /* dump a name on thread's next AST */
460#define T_KPC_ALLOC (1U << 2) /* thread needs a kpc_buf allocated */
461/* only go up to T_KPERF_CALLSTACK_DEPTH_OFFSET - 1 */
462
463#ifdef KPERF
464 uint32_t kperf_flags;
465 uint32_t kperf_pet_gen; /* last generation of PET that sampled this thread*/
466 uint32_t kperf_c_switch; /* last dispatch detection */
467 uint32_t kperf_pet_cnt; /* how many times a thread has been sampled by PET */
468#endif
6d2010ae 469
39236c6e
A
470#ifdef KPC
471 /* accumulated performance counters for this thread */
472 uint64_t *kpc_buf;
473#endif
474
fe8ab488
A
475#if HYPERVISOR
476 /* hypervisor virtual CPU object associated with this thread */
477 void *hv_thread_target;
478#endif /* HYPERVISOR */
479
b0d623f7 480 uint64_t thread_id; /*system wide unique thread-id*/
6d2010ae
A
481
482 /* Statistics accumulated per-thread and aggregated per-task */
483 uint32_t syscalls_unix;
484 uint32_t syscalls_mach;
316670eb
A
485 ledger_t t_ledger;
486 ledger_t t_threadledger; /* per thread ledger */
fe8ab488
A
487#ifdef CONFIG_BANK
488 ledger_t t_bankledger; /* ledger to charge someone */
489 uint64_t t_deduct_bank_ledger_time; /* cpu time to be deducted from bank ledger */
490#endif
39236c6e 491
39037602
A
492 /* policy is protected by the thread mutex */
493 struct thread_requested_policy requested_policy;
494 struct thread_effective_policy effective_policy;
39236c6e 495
fe8ab488 496 /* usynch override is protected by the task lock, eventually will be thread mutex */
a1c7dba1
A
497 struct thread_qos_override {
498 struct thread_qos_override *override_next;
499 uint32_t override_contended_resource_count;
500 int16_t override_qos;
501 int16_t override_resource_type;
502 user_addr_t override_resource;
503 } *overrides;
fe8ab488 504
39037602
A
505 uint32_t ipc_overrides;
506 uint32_t user_promotions;
507 uint16_t user_promotion_basepri;
508
813fb2f6
A
509 block_hint_t pending_block_hint;
510 block_hint_t block_hint; /* What type of primitive last caused us to block. */
511
39236c6e 512 int iotier_override; /* atomic operations to set, cleared on ret to user */
fe8ab488 513 io_stat_info_t thread_io_stats; /* per-thread I/O statistics */
39236c6e
A
514
515
4b17d6b6
A
516 uint32_t thread_callout_interrupt_wakeups;
517 uint32_t thread_callout_platform_idle_wakeups;
518 uint32_t thread_timer_wakeups_bin_1;
519 uint32_t thread_timer_wakeups_bin_2;
520 uint16_t thread_tag;
521 uint16_t callout_woken_from_icontext:1,
522 callout_woken_from_platform_idle:1,
39236c6e
A
523 callout_woke_thread:1,
524 thread_bitfield_unused:13;
fe8ab488
A
525
526 mach_port_name_t ith_voucher_name;
527 ipc_voucher_t ith_voucher;
528#if CONFIG_IOSCHED
529 void *decmp_upl;
530#endif /* CONFIG_IOSCHED */
3e170ce0
A
531
532 /* work interval ID (if any) associated with the thread. Uses thread mutex */
533 uint64_t work_interval_id;
534
535 /*** Machine-dependent state ***/
536 struct machine_thread machine;
39037602
A
537
538#if SCHED_TRACE_THREAD_WAKEUPS
539 uintptr_t thread_wakeup_bt[64];
540#endif
0b4e3aa0 541};
1c79356b 542
39037602
A
543#define ith_state saved.receive.state
544#define ith_object saved.receive.object
545#define ith_msg_addr saved.receive.msg_addr
546#define ith_rsize saved.receive.rsize
547#define ith_msize saved.receive.msize
548#define ith_option saved.receive.option
549#define ith_receiver_name saved.receive.receiver_name
550#define ith_continuation saved.receive.continuation
551#define ith_kmsg saved.receive.kmsg
552#define ith_peekq saved.receive.peekq
553#define ith_qos saved.receive.received_qos.qos
554#define ith_qos_override saved.receive.received_qos.oqos
555#define ith_seqno saved.receive.seqno
556
557#define sth_waitsemaphore saved.sema.waitsemaphore
558#define sth_signalsemaphore saved.sema.signalsemaphore
559#define sth_options saved.sema.options
560#define sth_result saved.sema.result
561#define sth_continuation saved.sema.continuation
562
563#if MACH_ASSERT
564#define assert_thread_magic(thread) assertf((thread)->thread_magic == THREAD_MAGIC, \
565 "bad thread magic 0x%llx for thread %p, expected 0x%llx", \
566 (thread)->thread_magic, (thread), THREAD_MAGIC)
567#else
568#define assert_thread_magic(thread) do { (void)(thread); } while (0)
569#endif
1c79356b 570
39236c6e 571extern void thread_bootstrap(void);
1c79356b 572
39236c6e 573extern void thread_init(void);
9bccf70c 574
91447636 575extern void thread_daemon_init(void);
1c79356b 576
91447636 577#define thread_reference_internal(thread) \
2d21ac55 578 (void)hw_atomic_add(&(thread)->ref_count, 1)
91447636 579
91447636
A
580#define thread_reference(thread) \
581MACRO_BEGIN \
582 if ((thread) != THREAD_NULL) \
2d21ac55 583 thread_reference_internal(thread); \
91447636 584MACRO_END
1c79356b 585
55e303ae
A
586extern void thread_deallocate(
587 thread_t thread);
1c79356b 588
3e170ce0
A
589extern void thread_deallocate_safe(
590 thread_t thread);
591
813fb2f6
A
592extern void thread_inspect_deallocate(
593 thread_inspect_t thread);
594
55e303ae 595extern void thread_terminate_self(void);
1c79356b 596
91447636
A
597extern kern_return_t thread_terminate_internal(
598 thread_t thread);
599
39037602 600extern void thread_start(
2d21ac55
A
601 thread_t thread) __attribute__ ((noinline));
602
39037602
A
603extern void thread_start_in_assert_wait(
604 thread_t thread,
605 event_t event,
606 wait_interrupt_t interruptible) __attribute__ ((noinline));
607
91447636
A
608extern void thread_terminate_enqueue(
609 thread_t thread);
610
39037602
A
611extern void thread_exception_enqueue(
612 task_t task,
613 thread_t thread);
614
615extern void thread_copy_resource_info(
616 thread_t dst_thread,
617 thread_t src_thread);
618
3e170ce0
A
619extern void thread_terminate_crashed_threads(void);
620
91447636
A
621extern void thread_stack_enqueue(
622 thread_t thread);
623
55e303ae 624extern void thread_hold(
91447636 625 thread_t thread);
1c79356b 626
55e303ae 627extern void thread_release(
91447636 628 thread_t thread);
1c79356b 629
39037602
A
630extern void thread_corpse_continue(void);
631
743345f9
A
632extern boolean_t thread_is_active(thread_t thread);
633
3e170ce0
A
634/* Locking for scheduler state, always acquired with interrupts disabled (splsched()) */
635#if __SMP__
91447636 636#define thread_lock_init(th) simple_lock_init(&(th)->sched_lock, 0)
55e303ae
A
637#define thread_lock(th) simple_lock(&(th)->sched_lock)
638#define thread_unlock(th) simple_unlock(&(th)->sched_lock)
1c79356b 639
91447636
A
640#define wake_lock_init(th) simple_lock_init(&(th)->wake_lock, 0)
641#define wake_lock(th) simple_lock(&(th)->wake_lock)
642#define wake_unlock(th) simple_unlock(&(th)->wake_lock)
3e170ce0
A
643#else
644#define thread_lock_init(th) do { (void)th; } while(0)
645#define thread_lock(th) do { (void)th; } while(0)
646#define thread_unlock(th) do { (void)th; } while(0)
647
648#define wake_lock_init(th) do { (void)th; } while(0)
649#define wake_lock(th) do { (void)th; } while(0)
650#define wake_unlock(th) do { (void)th; } while(0)
651#endif
2d21ac55
A
652
653#define thread_should_halt_fast(thread) (!(thread)->active)
1c79356b 654
91447636
A
655extern void stack_alloc(
656 thread_t thread);
1c79356b 657
6d2010ae
A
658extern void stack_handoff(
659 thread_t from,
660 thread_t to);
661
55e303ae
A
662extern void stack_free(
663 thread_t thread);
1c79356b 664
6d2010ae
A
665extern void stack_free_reserved(
666 thread_t thread);
1c79356b 667
91447636
A
668extern boolean_t stack_alloc_try(
669 thread_t thread);
670
55e303ae 671extern void stack_collect(void);
1c79356b 672
39236c6e 673extern void stack_init(void);
91447636 674
6d2010ae 675
91447636
A
676extern kern_return_t thread_info_internal(
677 thread_t thread,
1c79356b
A
678 thread_flavor_t flavor,
679 thread_info_t thread_info_out,
680 mach_msg_type_number_t *thread_info_count);
681
1c79356b 682
1c79356b 683
91447636
A
684extern kern_return_t kernel_thread_create(
685 thread_continue_t continuation,
686 void *parameter,
687 integer_t priority,
688 thread_t *new_thread);
1c79356b 689
91447636
A
690extern kern_return_t kernel_thread_start_priority(
691 thread_continue_t continuation,
692 void *parameter,
693 integer_t priority,
694 thread_t *new_thread);
1c79356b 695
55e303ae
A
696extern void machine_stack_attach(
697 thread_t thread,
91447636 698 vm_offset_t stack);
1c79356b 699
55e303ae
A
700extern vm_offset_t machine_stack_detach(
701 thread_t thread);
702
703extern void machine_stack_handoff(
704 thread_t old,
705 thread_t new);
706
707extern thread_t machine_switch_context(
708 thread_t old_thread,
709 thread_continue_t continuation,
710 thread_t new_thread);
711
712extern void machine_load_context(
713 thread_t thread);
714
91447636
A
715extern kern_return_t machine_thread_state_initialize(
716 thread_t thread);
9bccf70c 717
55e303ae 718extern kern_return_t machine_thread_set_state(
91447636 719 thread_t thread,
55e303ae
A
720 thread_flavor_t flavor,
721 thread_state_t state,
722 mach_msg_type_number_t count);
723
724extern kern_return_t machine_thread_get_state(
91447636 725 thread_t thread,
55e303ae
A
726 thread_flavor_t flavor,
727 thread_state_t state,
728 mach_msg_type_number_t *count);
729
730extern kern_return_t machine_thread_dup(
91447636
A
731 thread_t self,
732 thread_t target);
55e303ae
A
733
734extern void machine_thread_init(void);
735
736extern kern_return_t machine_thread_create(
737 thread_t thread,
738 task_t task);
0c530ab8 739extern void machine_thread_switch_addrmode(
2d21ac55 740 thread_t thread);
55e303ae
A
741
742extern void machine_thread_destroy(
743 thread_t thread);
744
91447636
A
745extern void machine_set_current_thread(
746 thread_t thread);
55e303ae 747
91447636
A
748extern kern_return_t machine_thread_get_kern_state(
749 thread_t thread,
750 thread_flavor_t flavor,
751 thread_state_t tstate,
752 mach_msg_type_number_t *count);
753
b0d623f7
A
754extern kern_return_t machine_thread_inherit_taskwide(
755 thread_t thread,
756 task_t parent_task);
91447636 757
fe8ab488
A
758extern kern_return_t machine_thread_set_tsd_base(
759 thread_t thread,
760 mach_vm_offset_t tsd_base);
55e303ae 761
b0d623f7
A
762#define thread_mtx_lock(thread) lck_mtx_lock(&(thread)->mutex)
763#define thread_mtx_try(thread) lck_mtx_try_lock(&(thread)->mutex)
764#define thread_mtx_unlock(thread) lck_mtx_unlock(&(thread)->mutex)
55e303ae 765
39037602 766extern void thread_apc_ast(thread_t thread);
55e303ae 767
39037602 768extern void thread_update_qos_cpu_time(thread_t thread);
fe8ab488 769
2d21ac55
A
770void act_machine_sv_free(thread_t, int);
771
b0d623f7
A
772vm_offset_t min_valid_stack_address(void);
773vm_offset_t max_valid_stack_address(void);
774
39236c6e 775static inline uint16_t thread_set_tag_internal(thread_t thread, uint16_t tag) {
4b17d6b6
A
776 return __sync_fetch_and_or(&thread->thread_tag, tag);
777}
39236c6e
A
778
779static inline uint16_t thread_get_tag_internal(thread_t thread) {
4b17d6b6
A
780 return thread->thread_tag;
781}
782
fe8ab488 783
3e170ce0
A
784extern void thread_set_options(uint32_t thopt);
785
9bccf70c 786#else /* MACH_KERNEL_PRIVATE */
1c79356b 787
91447636 788__BEGIN_DECLS
1c79356b 789
91447636
A
790extern thread_t current_thread(void);
791
792extern void thread_reference(
793 thread_t thread);
55e303ae 794
91447636
A
795extern void thread_deallocate(
796 thread_t thread);
55e303ae 797
91447636 798__END_DECLS
1c79356b 799
9bccf70c 800#endif /* MACH_KERNEL_PRIVATE */
1c79356b 801
91447636 802#ifdef KERNEL_PRIVATE
1c79356b 803
91447636 804__BEGIN_DECLS
55e303ae 805
b0d623f7
A
806extern uint64_t thread_dispatchqaddr(
807 thread_t thread);
808
91447636 809__END_DECLS
55e303ae 810
91447636 811#endif /* KERNEL_PRIVATE */
55e303ae 812
fe8ab488
A
813#ifdef KERNEL
814__BEGIN_DECLS
815
816extern uint64_t thread_tid(thread_t thread);
817
818__END_DECLS
819
820#endif /* KERNEL */
821
91447636 822__BEGIN_DECLS
55e303ae 823
91447636 824#ifdef XNU_KERNEL_PRIVATE
9bccf70c 825
4b17d6b6
A
826/*
827 * Thread tags; for easy identification.
828 */
829#define THREAD_TAG_MAINTHREAD 0x1
830#define THREAD_TAG_CALLOUT 0x2
831#define THREAD_TAG_IOWORKLOOP 0x4
832
39037602
A
833#define THREAD_TAG_PTHREAD 0x10
834#define THREAD_TAG_WORKQUEUE 0x20
835
4b17d6b6
A
836uint16_t thread_set_tag(thread_t, uint16_t);
837uint16_t thread_get_tag(thread_t);
838
316670eb
A
839extern kern_return_t thread_state_initialize(
840 thread_t thread);
841
842extern kern_return_t thread_setstatus(
843 thread_t thread,
844 int flavor,
845 thread_state_t tstate,
846 mach_msg_type_number_t count);
847
848extern kern_return_t thread_getstatus(
849 thread_t thread,
850 int flavor,
851 thread_state_t tstate,
852 mach_msg_type_number_t *count);
853
3e170ce0
A
854extern kern_return_t thread_create_with_continuation(
855 task_t task,
856 thread_t *new_thread,
857 thread_continue_t continuation);
858
743345f9
A
859extern kern_return_t thread_create_waiting(task_t task,
860 thread_continue_t continuation,
861 event_t event,
862 thread_t *new_thread);
863
b0d623f7
A
864extern kern_return_t thread_create_workq(
865 task_t task,
b7266188 866 thread_continue_t thread_return,
b0d623f7
A
867 thread_t *new_thread);
868
39037602
A
869extern kern_return_t thread_create_workq_waiting(
870 task_t task,
871 thread_continue_t thread_return,
872 event_t event,
873 thread_t *new_thread);
874
2d21ac55
A
875extern void thread_yield_internal(
876 mach_msg_timeout_t interval);
877
39037602
A
878extern void thread_yield_to_preemption(void);
879
316670eb
A
880/*
881 * Thread-private CPU limits: apply a private CPU limit to this thread only. Available actions are:
882 *
883 * 1) Block. Prevent CPU consumption of the thread from exceeding the limit.
884 * 2) Exception. Generate a resource consumption exception when the limit is exceeded.
39236c6e 885 * 3) Disable. Remove any existing CPU limit.
316670eb
A
886 */
887#define THREAD_CPULIMIT_BLOCK 0x1
888#define THREAD_CPULIMIT_EXCEPTION 0x2
39236c6e 889#define THREAD_CPULIMIT_DISABLE 0x3
316670eb
A
890
891struct _thread_ledger_indices {
892 int cpu_time;
893};
894
895extern struct _thread_ledger_indices thread_ledgers;
896
39236c6e 897extern int thread_get_cpulimit(int *action, uint8_t *percentage, uint64_t *interval_ns);
316670eb
A
898extern int thread_set_cpulimit(int action, uint8_t percentage, uint64_t interval_ns);
899
91447636
A
900extern void thread_read_times(
901 thread_t thread,
902 time_value_t *user_time,
903 time_value_t *system_time);
1c79356b 904
fe8ab488
A
905extern uint64_t thread_get_runtime_self(void);
906
91447636
A
907extern void thread_setuserstack(
908 thread_t thread,
909 mach_vm_offset_t user_stack);
1c79356b 910
91447636
A
911extern uint64_t thread_adjuserstack(
912 thread_t thread,
913 int adjust);
55e303ae 914
91447636 915extern void thread_setentrypoint(
55e303ae 916 thread_t thread,
91447636
A
917 mach_vm_offset_t entry);
918
fe8ab488
A
919extern kern_return_t thread_set_tsd_base(
920 thread_t thread,
921 mach_vm_offset_t tsd_base);
922
2d21ac55 923extern kern_return_t thread_setsinglestep(
0c530ab8
A
924 thread_t thread,
925 int on);
926
6d2010ae
A
927extern kern_return_t thread_userstack(
928 thread_t,
929 int,
930 thread_state_t,
931 unsigned int,
932 mach_vm_offset_t *,
39037602
A
933 int *,
934 boolean_t);
6d2010ae 935
316670eb
A
936extern kern_return_t thread_entrypoint(
937 thread_t,
938 int,
939 thread_state_t,
940 unsigned int,
941 mach_vm_offset_t *);
6d2010ae 942
316670eb 943extern kern_return_t thread_userstackdefault(
39037602
A
944 mach_vm_offset_t *,
945 boolean_t);
6d2010ae 946
91447636
A
947extern kern_return_t thread_wire_internal(
948 host_priv_t host_priv,
949 thread_t thread,
950 boolean_t wired,
951 boolean_t *prev_state);
952
fe8ab488 953
91447636
A
954extern kern_return_t thread_dup(thread_t);
955
39037602
A
956extern kern_return_t thread_dup2(thread_t, thread_t);
957
2d21ac55
A
958typedef void (*sched_call_t)(
959 int type,
960 thread_t thread);
961
962#define SCHED_CALL_BLOCK 0x1
963#define SCHED_CALL_UNBLOCK 0x2
964
965extern void thread_sched_call(
966 thread_t thread,
967 sched_call_t call);
968
39037602
A
969extern sched_call_t thread_disable_sched_call(
970 thread_t thread,
971 sched_call_t call);
972
973extern void thread_reenable_sched_call(
974 thread_t thread,
975 sched_call_t call);
976
2d21ac55
A
977extern void thread_static_param(
978 thread_t thread,
979 boolean_t state);
980
fe8ab488
A
981extern boolean_t thread_is_static_param(
982 thread_t thread);
983
91447636 984extern task_t get_threadtask(thread_t);
0c530ab8
A
985#define thread_is_64bit(thd) \
986 task_has_64BitAddr(get_threadtask(thd))
987
91447636
A
988
989extern void *get_bsdthread_info(thread_t);
990extern void set_bsdthread_info(thread_t, void *);
b0d623f7 991extern void *uthread_alloc(task_t, thread_t, int);
3e170ce0 992extern void uthread_cleanup_name(void *uthread);
39037602 993extern void uthread_cleanup(task_t, void *, void *);
2d21ac55 994extern void uthread_zone_free(void *);
3e170ce0
A
995extern void uthread_cred_free(void *);
996
813fb2f6 997extern void uthread_reset_proc_refcount(void *);
3e170ce0
A
998#if PROC_REF_DEBUG
999extern int uthread_get_proc_refcount(void *);
3e170ce0
A
1000extern int proc_ref_tracking_disabled;
1001#endif
91447636
A
1002
1003extern boolean_t thread_should_halt(
1004 thread_t thread);
1005
316670eb
A
1006extern boolean_t thread_should_abort(
1007 thread_t);
1008
2d21ac55
A
1009extern int is_64signalregset(void);
1010
3e170ce0
A
1011extern void act_set_kperf(thread_t);
1012extern void set_astledger(thread_t thread);
39037602 1013extern void act_set_io_telemetry_ast(thread_t);
2d21ac55
A
1014
1015extern uint32_t dtrace_get_thread_predcache(thread_t);
1016extern int64_t dtrace_get_thread_vtime(thread_t);
1017extern int64_t dtrace_get_thread_tracing(thread_t);
1018extern boolean_t dtrace_get_thread_reentering(thread_t);
3e170ce0 1019extern int dtrace_get_thread_last_cpu_id(thread_t);
2d21ac55
A
1020extern vm_offset_t dtrace_get_kernel_stack(thread_t);
1021extern void dtrace_set_thread_predcache(thread_t, uint32_t);
1022extern void dtrace_set_thread_vtime(thread_t, int64_t);
1023extern void dtrace_set_thread_tracing(thread_t, int64_t);
1024extern void dtrace_set_thread_reentering(thread_t, boolean_t);
1025extern vm_offset_t dtrace_set_thread_recover(thread_t, vm_offset_t);
b0d623f7 1026extern void dtrace_thread_bootstrap(void);
39236c6e 1027extern void dtrace_thread_didexec(thread_t);
2d21ac55
A
1028
1029extern int64_t dtrace_calc_thread_recent_vtime(thread_t);
1030
1031
39236c6e 1032extern kern_return_t thread_set_wq_state32(
2d21ac55
A
1033 thread_t thread,
1034 thread_state_t tstate);
1035
39236c6e 1036extern kern_return_t thread_set_wq_state64(
2d21ac55
A
1037 thread_t thread,
1038 thread_state_t tstate);
1039
b0d623f7
A
1040extern vm_offset_t kernel_stack_mask;
1041extern vm_offset_t kernel_stack_size;
1042extern vm_offset_t kernel_stack_depth_max;
1043
39236c6e
A
1044void guard_ast(thread_t thread);
1045extern void fd_guard_ast(thread_t thread);
1046extern void mach_port_guard_ast(thread_t thread);
1047extern void thread_guard_violation(thread_t thread, unsigned type);
fe8ab488
A
1048extern void thread_update_io_stats(thread_t thread, int size, int io_flags);
1049
1050extern kern_return_t thread_set_voucher_name(mach_port_name_t name);
1051extern kern_return_t thread_get_current_voucher_origin_pid(int32_t *pid);
39236c6e 1052
ecc0ceb4
A
1053extern void set_thread_rwlock_boost(void);
1054extern void clear_thread_rwlock_boost(void);
1055
39037602
A
1056/*! @function thread_has_thread_name
1057 @abstract Checks if a thread has a name.
1058 @discussion This function takes one input, a thread, and returns a boolean value indicating if that thread already has a name associated with it.
1059 @param th The thread to inspect.
1060 @result TRUE if the thread has a name, FALSE otherwise.
1061*/
1062extern boolean_t thread_has_thread_name(thread_t th);
1063
1064/*! @function thread_set_thread_name
1065 @abstract Set a thread's name.
1066 @discussion This function takes two input parameters: a thread to name, and the name to apply to the thread. The name will be attached to the thread in order to better identify the thread.
1067 @param th The thread to be named.
1068 @param name The name to apply to the thread.
1069*/
1070extern void thread_set_thread_name(thread_t th, const char* name);
1071
490019cf
A
1072extern void thread_enable_send_importance(thread_t thread, boolean_t enable);
1073
39037602
A
1074/* Get a backtrace for a threads kernel or user stack (user_p), with pc and optionally
1075 * frame pointer (getfp). Returns bytes added to buffer, and kThreadTruncatedBT in
1076 * thread_trace_flags if a user page is not present after kdp_lightweight_fault() is
1077 * called.
1078 */
1079
1080extern int machine_trace_thread(
1081 thread_t thread,
1082 char *tracepos,
1083 char *tracebound,
1084 int nframes,
1085 boolean_t user_p,
1086 boolean_t getfp,
1087 uint32_t *thread_trace_flags);
1088
1089extern int machine_trace_thread64(thread_t thread,
1090 char *tracepos,
1091 char *tracebound,
1092 int nframes,
1093 boolean_t user_p,
1094 boolean_t getfp,
1095 uint32_t *thread_trace_flags);
1096
91447636
A
1097#endif /* XNU_KERNEL_PRIVATE */
1098
fe8ab488 1099
b0d623f7
A
1100/*! @function kernel_thread_start
1101 @abstract Create a kernel thread.
1102 @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).
1103 @param continuation A C-function pointer where the thread will begin execution.
1104 @param parameter Caller specified data to be passed to the new thread.
1105 @param new_thread Reference to the new thread is returned in this parameter.
1106 @result Returns KERN_SUCCESS on success or an appropriate kernel code type.
1107*/
1108
91447636
A
1109extern kern_return_t kernel_thread_start(
1110 thread_continue_t continuation,
1111 void *parameter,
1112 thread_t *new_thread);
6d2010ae
A
1113#ifdef KERNEL_PRIVATE
1114void thread_set_eager_preempt(thread_t thread);
1115void thread_clear_eager_preempt(thread_t thread);
316670eb 1116extern ipc_port_t convert_thread_to_port(thread_t);
813fb2f6 1117extern ipc_port_t convert_thread_inspect_to_port(thread_inspect_t);
39037602 1118extern boolean_t is_vm_privileged(void);
fe8ab488 1119extern boolean_t set_vm_privilege(boolean_t);
6d2010ae 1120#endif /* KERNEL_PRIVATE */
55e303ae 1121
91447636 1122__END_DECLS
55e303ae 1123
1c79356b 1124#endif /* _KERN_THREAD_H_ */