]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/thread.h
xnu-1228.tar.gz
[apple/xnu.git] / osfmk / kern / thread.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 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
A
102#include <cputypes.h>
103
104#include <mach_assert.h>
1c79356b
A
105#include <mach_ldebug.h>
106
91447636
A
107#include <ipc/ipc_types.h>
108
1c79356b 109#include <mach/port.h>
1c79356b
A
110#include <kern/cpu_number.h>
111#include <kern/queue.h>
1c79356b
A
112#include <kern/timer.h>
113#include <kern/lock.h>
91447636 114#include <kern/locks.h>
1c79356b
A
115#include <kern/sched.h>
116#include <kern/sched_prim.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>
91447636 122
1c79356b 123#include <ipc/ipc_kmsg.h>
55e303ae 124
91447636 125#include <machine/cpu_data.h>
1c79356b
A
126#include <machine/thread.h>
127
55e303ae 128struct thread {
1c79356b 129 /*
9bccf70c 130 * NOTE: The runq field in the thread structure has an unusual
2d21ac55 131 * locking protocol. If its value is PROCESSOR_NULL, then it is
9bccf70c 132 * locked by the thread_lock, but if its value is something else
2d21ac55 133 * then it is locked by the associated run queue lock.
9bccf70c 134 *
91447636
A
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).
1c79356b 139 */
9bccf70c
A
140 /* Items examined often, modified infrequently */
141 queue_chain_t links; /* run/wait queue links */
2d21ac55 142 processor_t runq; /* run queue assignment */
9bccf70c
A
143 wait_queue_t wait_queue; /* wait queue we are currently on */
144 event64_t wait_event; /* wait queue event */
91447636
A
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 */
2d21ac55 148#define TH_OPT_DTRACE 0x08 /* executing under dtrace_probe */
1c79356b 149
9bccf70c 150 /* Data updated during assert_wait/thread_wakeup */
55e303ae 151 decl_simple_lock_data(,sched_lock) /* scheduling lock (thread_lock()) */
2d21ac55
A
152 decl_simple_lock_data(,wake_lock) /* for thread stop / wait (wake_lock()) */
153 boolean_t wake_active; /* wake event on stop */
9bccf70c
A
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 -
0b4e3aa0
A
157 * may be examined by this thread
158 * WITHOUT locking */
91447636
A
159 thread_continue_t continuation; /* continue here next dispatch */
160 void *parameter; /* continuation parameter */
0b4e3aa0 161
9bccf70c
A
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 */
0b4e3aa0 167
9bccf70c 168 vm_offset_t kernel_stack; /* current kernel stack */
55e303ae 169 vm_offset_t reserved_stack; /* reserved kernel stack */
0b4e3aa0
A
170
171 /* Thread state: */
9bccf70c 172 int state;
1c79356b
A
173/*
174 * Thread states [bits or'ed]
175 */
55e303ae
A
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 */
1c79356b 181
2d21ac55 182#define TH_IDLE 0x80 /* idling processor */
1c79356b 183
9bccf70c
A
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_PREEMPT 0x0004 /* can preempt kernel contexts */
189#define TH_MODE_FAILSAFE 0x0008 /* fail-safe has tripped */
190#define TH_MODE_PROMOTED 0x0010 /* sched pri has been promoted */
2d21ac55
A
191#define TH_MODE_ABORT 0x0020 /* abort interruptible waits */
192#define TH_MODE_ABORTSAFELY 0x0040 /* ... but only those at safe point */
193#define TH_MODE_ISABORTED (TH_MODE_ABORT | TH_MODE_ABORTSAFELY)
194#define TH_MODE_DEPRESS 0x0080 /* normal depress yield */
195#define TH_MODE_POLLDEPRESS 0x0100 /* polled depress yield */
9bccf70c
A
196#define TH_MODE_ISDEPRESSED (TH_MODE_DEPRESS | TH_MODE_POLLDEPRESS)
197
198 integer_t sched_pri; /* scheduled (current) priority */
199 integer_t priority; /* base priority */
200 integer_t max_priority; /* max base priority */
201 integer_t task_priority; /* copy of task base priority */
202
203 integer_t promotions; /* level of promotion */
204 integer_t pending_promoter_index;
205 void *pending_promoter[2];
1c79356b 206
9bccf70c 207 integer_t importance; /* task-relative importance */
1c79356b 208
55e303ae 209 /* real-time parameters */
9bccf70c 210 struct { /* see mach/thread_policy.h */
0b4e3aa0
A
211 uint32_t period;
212 uint32_t computation;
213 uint32_t constraint;
1c79356b 214 boolean_t preemptible;
55e303ae
A
215
216 uint64_t deadline;
1c79356b
A
217 } realtime;
218
0b4e3aa0
A
219 uint32_t current_quantum; /* duration of current quantum */
220
9bccf70c
A
221 /* Data used during setrun/dispatch */
222 timer_data_t system_timer; /* system mode timer */
9bccf70c
A
223 processor_t bound_processor; /* bound to a processor? */
224 processor_t last_processor; /* processor last dispatched on */
225 uint64_t last_switch; /* time of last context switch */
226
0b4e3aa0 227 /* Fail-safe computation since last unblock or qualifying yield */
9bccf70c 228 uint64_t computation_metered;
0b4e3aa0 229 uint64_t computation_epoch;
9bccf70c
A
230 integer_t safe_mode; /* saved mode during fail-safe */
231 natural_t safe_release; /* when to release fail-safe */
1c79356b 232
2d21ac55
A
233 /* Call out from scheduler */
234 void (*sched_call)(
235 int type,
236 thread_t thread);
237
55e303ae 238 /* Statistics and timesharing calculations */
91447636
A
239 natural_t sched_stamp; /* last scheduler tick */
240 natural_t sched_usage; /* timesharing cpu usage [sched] */
241 natural_t pri_shift; /* usage -> priority from pset */
242 natural_t cpu_usage; /* instrumented cpu usage [%cpu] */
243 natural_t cpu_delta; /* accumulated cpu_usage delta */
2d21ac55
A
244 uint32_t c_switch; /* total context switches */
245 uint32_t p_switch; /* total processor switches */
246 uint32_t ps_switch; /* total pset switches */
1c79356b 247
9bccf70c 248 /* Timing data structures */
91447636 249 timer_data_t user_timer; /* user mode timer */
91447636 250 uint64_t user_timer_save; /* saved user timer value */
2d21ac55
A
251 uint64_t system_timer_save; /* saved system timer value */
252 uint64_t vtimer_user_save; /* saved values for vtimers */
253 uint64_t vtimer_prof_save;
254 uint64_t vtimer_rlim_save;
1c79356b 255
9bccf70c 256 /* Timed wait expiration */
91447636
A
257 timer_call_data_t wait_timer;
258 integer_t wait_timer_active;
259 boolean_t wait_timer_is_set;
1c79356b 260
9bccf70c 261 /* Priority depression expiration */
91447636
A
262 timer_call_data_t depress_timer;
263 integer_t depress_timer_active;
1c79356b 264
2d21ac55
A
265 /*
266 * Processor/cache affinity
267 * - affinity_threads links task threads with the same affinity set
268 */
269 affinity_set_t affinity_set;
270 queue_chain_t affinity_threads;
271
1c79356b
A
272 /* Various bits of stashed state */
273 union {
274 struct {
0b4e3aa0
A
275 mach_msg_return_t state; /* receive state */
276 ipc_object_t object; /* object received on */
91447636 277 mach_vm_address_t msg_addr; /* receive buffer pointer */
0b4e3aa0
A
278 mach_msg_size_t msize; /* max size for recvd msg */
279 mach_msg_option_t option; /* options for receive */
280 mach_msg_size_t slist_size; /* scatter list size */
281 struct ipc_kmsg *kmsg; /* received message */
282 mach_port_seqno_t seqno; /* seqno of recvd message */
9bccf70c
A
283 mach_msg_continue_t continuation;
284 } receive;
1c79356b 285 struct {
0b4e3aa0
A
286 struct semaphore *waitsemaphore; /* semaphore ref */
287 struct semaphore *signalsemaphore; /* semaphore ref */
288 int options; /* semaphore options */
289 kern_return_t result; /* primary result */
9bccf70c
A
290 mach_msg_continue_t continuation;
291 } sema;
1c79356b 292 struct {
9bccf70c
A
293 int option; /* switch option */
294 } swtch;
295 int misc; /* catch-all for other state */
296 } saved;
1c79356b 297
9bccf70c
A
298 /* IPC data structures */
299 struct ipc_kmsg_queue ith_messages;
9bccf70c 300 mach_port_t ith_rpc_reply; /* reply port for kernel RPCs */
1c79356b
A
301
302 /* Ast/Halt data structures */
9bccf70c 303 vm_offset_t recover; /* page fault recover(copyin/out) */
2d21ac55 304 uint32_t ref_count; /* number of references to me */
1c79356b 305
2d21ac55 306 queue_chain_t threads; /* global list of all threads */
1c79356b 307
55e303ae
A
308 /* Activation */
309 queue_chain_t task_threads;
310
311 /*** Machine-dependent state ***/
91447636 312 struct machine_thread machine;
55e303ae
A
313
314 /* Task membership */
315 struct task *task;
316 vm_map_t map;
317
91447636 318 decl_mutex_data(,mutex)
55e303ae
A
319
320 /* Kernel holds on this thread */
321 int suspend_count;
322
323 /* User level suspensions */
324 int user_stop_count;
325
326 /* Pending thread ast(s) */
327 ast_t ast;
328
91447636 329 /* Miscellaneous bits guarded by mutex */
55e303ae 330 uint32_t
2d21ac55
A
331 active:1, /* Thread is active and has not been terminated */
332 started:1, /* Thread has been started after creation */
333 static_param:1, /* Disallow policy parameter changes */
334 :0;
55e303ae
A
335
336 /* Return Handers */
337 struct ReturnHandler {
338 struct ReturnHandler *next;
339 void (*handler)(
340 struct ReturnHandler *rh,
91447636 341 struct thread *thread);
55e303ae
A
342 } *handlers, special_handler;
343
344 /* Ports associated with this thread */
345 struct ipc_port *ith_self; /* not a right, doesn't hold ref */
346 struct ipc_port *ith_sself; /* a send right */
347 struct exception_action exc_actions[EXC_TYPES_COUNT];
348
349 /* Owned ulocks (a lock set element) */
350 queue_head_t held_ulocks;
351
55e303ae
A
352#ifdef MACH_BSD
353 void *uthread;
354#endif
2d21ac55
A
355
356#if CONFIG_DTRACE
357 uint32_t t_dtrace_predcache;/* DTrace per thread predicate value hint */
358 int64_t t_dtrace_tracing; /* Thread time under dtrace_probe() */
359 int64_t t_dtrace_vtime;
360#endif
361 uint32_t t_chud; /* CHUD flags, used for Shark */
0b4e3aa0 362};
1c79356b 363
1c79356b
A
364#define ith_state saved.receive.state
365#define ith_object saved.receive.object
91447636 366#define ith_msg_addr saved.receive.msg_addr
1c79356b
A
367#define ith_msize saved.receive.msize
368#define ith_option saved.receive.option
369#define ith_scatter_list_size saved.receive.slist_size
370#define ith_continuation saved.receive.continuation
371#define ith_kmsg saved.receive.kmsg
372#define ith_seqno saved.receive.seqno
373
374#define sth_waitsemaphore saved.sema.waitsemaphore
375#define sth_signalsemaphore saved.sema.signalsemaphore
376#define sth_options saved.sema.options
377#define sth_result saved.sema.result
378#define sth_continuation saved.sema.continuation
379
2d21ac55 380extern void thread_bootstrap(void) __attribute__((section("__TEXT, initcode")));
1c79356b 381
2d21ac55 382extern void thread_init(void) __attribute__((section("__TEXT, initcode")));
9bccf70c 383
91447636 384extern void thread_daemon_init(void);
1c79356b 385
91447636 386#define thread_reference_internal(thread) \
2d21ac55 387 (void)hw_atomic_add(&(thread)->ref_count, 1)
91447636
A
388
389#define thread_deallocate_internal(thread) \
390 hw_atomic_sub(&(thread)->ref_count, 1)
391
392#define thread_reference(thread) \
393MACRO_BEGIN \
394 if ((thread) != THREAD_NULL) \
2d21ac55 395 thread_reference_internal(thread); \
91447636 396MACRO_END
1c79356b 397
55e303ae
A
398extern void thread_deallocate(
399 thread_t thread);
1c79356b 400
55e303ae 401extern void thread_terminate_self(void);
1c79356b 402
91447636
A
403extern kern_return_t thread_terminate_internal(
404 thread_t thread);
405
2d21ac55
A
406extern void thread_start_internal(
407 thread_t thread) __attribute__ ((noinline));
408
91447636
A
409extern void thread_terminate_enqueue(
410 thread_t thread);
411
412extern void thread_stack_enqueue(
413 thread_t thread);
414
55e303ae 415extern void thread_hold(
91447636 416 thread_t thread);
1c79356b 417
55e303ae 418extern void thread_release(
91447636 419 thread_t thread);
1c79356b 420
91447636 421#define thread_lock_init(th) simple_lock_init(&(th)->sched_lock, 0)
55e303ae
A
422#define thread_lock(th) simple_lock(&(th)->sched_lock)
423#define thread_unlock(th) simple_unlock(&(th)->sched_lock)
1c79356b 424
91447636
A
425#define wake_lock_init(th) simple_lock_init(&(th)->wake_lock, 0)
426#define wake_lock(th) simple_lock(&(th)->wake_lock)
427#define wake_unlock(th) simple_unlock(&(th)->wake_lock)
2d21ac55
A
428
429#define thread_should_halt_fast(thread) (!(thread)->active)
1c79356b 430
91447636
A
431extern void stack_alloc(
432 thread_t thread);
1c79356b 433
55e303ae
A
434extern void stack_free(
435 thread_t thread);
1c79356b 436
55e303ae
A
437extern void stack_free_stack(
438 vm_offset_t stack);
1c79356b 439
91447636
A
440extern boolean_t stack_alloc_try(
441 thread_t thread);
442
55e303ae 443extern void stack_collect(void);
1c79356b 444
2d21ac55 445extern void stack_init(void) __attribute__((section("__TEXT, initcode")));
91447636
A
446
447extern kern_return_t thread_state_initialize(
448 thread_t thread);
449
1c79356b 450extern kern_return_t thread_setstatus(
91447636 451 thread_t thread,
1c79356b
A
452 int flavor,
453 thread_state_t tstate,
454 mach_msg_type_number_t count);
455
456extern kern_return_t thread_getstatus(
91447636 457 thread_t thread,
1c79356b
A
458 int flavor,
459 thread_state_t tstate,
460 mach_msg_type_number_t *count);
461
91447636
A
462extern kern_return_t thread_info_internal(
463 thread_t thread,
1c79356b
A
464 thread_flavor_t flavor,
465 thread_info_t thread_info_out,
466 mach_msg_type_number_t *thread_info_count);
467
55e303ae
A
468extern void thread_task_priority(
469 thread_t thread,
470 integer_t priority,
471 integer_t max_priority);
1c79356b 472
91447636
A
473extern void thread_policy_reset(
474 thread_t thread);
1c79356b 475
91447636
A
476extern kern_return_t kernel_thread_create(
477 thread_continue_t continuation,
478 void *parameter,
479 integer_t priority,
480 thread_t *new_thread);
1c79356b 481
91447636
A
482extern kern_return_t kernel_thread_start_priority(
483 thread_continue_t continuation,
484 void *parameter,
485 integer_t priority,
486 thread_t *new_thread);
1c79356b 487
55e303ae
A
488extern void machine_stack_attach(
489 thread_t thread,
91447636 490 vm_offset_t stack);
1c79356b 491
55e303ae
A
492extern vm_offset_t machine_stack_detach(
493 thread_t thread);
494
495extern void machine_stack_handoff(
496 thread_t old,
497 thread_t new);
498
499extern thread_t machine_switch_context(
500 thread_t old_thread,
501 thread_continue_t continuation,
502 thread_t new_thread);
503
504extern void machine_load_context(
505 thread_t thread);
506
91447636
A
507extern kern_return_t machine_thread_state_initialize(
508 thread_t thread);
9bccf70c 509
55e303ae 510extern kern_return_t machine_thread_set_state(
91447636 511 thread_t thread,
55e303ae
A
512 thread_flavor_t flavor,
513 thread_state_t state,
514 mach_msg_type_number_t count);
515
516extern kern_return_t machine_thread_get_state(
91447636 517 thread_t thread,
55e303ae
A
518 thread_flavor_t flavor,
519 thread_state_t state,
520 mach_msg_type_number_t *count);
521
522extern kern_return_t machine_thread_dup(
91447636
A
523 thread_t self,
524 thread_t target);
55e303ae
A
525
526extern void machine_thread_init(void);
527
528extern kern_return_t machine_thread_create(
529 thread_t thread,
530 task_t task);
0c530ab8 531extern void machine_thread_switch_addrmode(
2d21ac55 532 thread_t thread);
55e303ae
A
533
534extern void machine_thread_destroy(
535 thread_t thread);
536
91447636
A
537extern void machine_set_current_thread(
538 thread_t thread);
55e303ae
A
539
540extern void machine_thread_terminate_self(void);
541
91447636
A
542extern kern_return_t machine_thread_get_kern_state(
543 thread_t thread,
544 thread_flavor_t flavor,
545 thread_state_t tstate,
546 mach_msg_type_number_t *count);
547
548
55e303ae
A
549/*
550 * XXX Funnel locks XXX
551 */
552
553struct funnel_lock {
554 int fnl_type; /* funnel type */
91447636 555 lck_mtx_t *fnl_mutex; /* underlying mutex for the funnel */
55e303ae
A
556 void * fnl_mtxholder; /* thread (last)holdng mutex */
557 void * fnl_mtxrelease; /* thread (last)releasing mutex */
91447636 558 lck_mtx_t *fnl_oldmutex; /* Mutex before collapsing split funnel */
55e303ae
A
559};
560
55e303ae
A
561typedef struct ReturnHandler ReturnHandler;
562
91447636
A
563#define thread_mtx_lock(thread) mutex_lock(&(thread)->mutex)
564#define thread_mtx_try(thread) mutex_try(&(thread)->mutex)
565#define thread_mtx_unlock(thread) mutex_unlock(&(thread)->mutex)
55e303ae
A
566
567extern void act_execute_returnhandlers(void);
568
569extern void install_special_handler(
91447636 570 thread_t thread);
55e303ae
A
571
572extern void special_handler(
573 ReturnHandler *rh,
91447636 574 thread_t thread);
1c79356b 575
2d21ac55
A
576void act_machine_sv_free(thread_t, int);
577
9bccf70c 578#else /* MACH_KERNEL_PRIVATE */
1c79356b 579
91447636 580__BEGIN_DECLS
1c79356b 581
91447636
A
582extern thread_t current_thread(void);
583
584extern void thread_reference(
585 thread_t thread);
55e303ae 586
91447636
A
587extern void thread_deallocate(
588 thread_t thread);
55e303ae 589
91447636 590__END_DECLS
1c79356b 591
9bccf70c 592#endif /* MACH_KERNEL_PRIVATE */
1c79356b 593
91447636 594#ifdef KERNEL_PRIVATE
1c79356b 595
91447636 596typedef struct funnel_lock funnel_t;
9bccf70c 597
91447636 598#ifdef MACH_KERNEL_PRIVATE
9bccf70c 599
91447636
A
600extern void funnel_lock(
601 funnel_t *lock);
9bccf70c 602
91447636
A
603extern void funnel_unlock(
604 funnel_t *lock);
55e303ae 605
91447636
A
606vm_offset_t min_valid_stack_address(void);
607vm_offset_t max_valid_stack_address(void);
55e303ae 608
91447636 609#endif /* MACH_KERNEL_PRIVATE */
55e303ae 610
91447636 611__BEGIN_DECLS
55e303ae 612
91447636 613extern funnel_t *thread_funnel_get(void);
9bccf70c 614
91447636
A
615extern boolean_t thread_funnel_set(
616 funnel_t *lock,
617 boolean_t funneled);
55e303ae 618
91447636
A
619extern thread_t kernel_thread(
620 task_t task,
621 void (*start)(void));
55e303ae 622
91447636 623__END_DECLS
55e303ae 624
91447636 625#endif /* KERNEL_PRIVATE */
55e303ae 626
91447636 627__BEGIN_DECLS
55e303ae 628
91447636 629#ifdef XNU_KERNEL_PRIVATE
9bccf70c 630
2d21ac55
A
631extern void thread_yield_internal(
632 mach_msg_timeout_t interval);
633
55e303ae
A
634/*
635 * XXX Funnel locks XXX
636 */
637
9bccf70c 638#define THR_FUNNEL_NULL (funnel_t *)0
1c79356b 639
55e303ae
A
640extern funnel_t *funnel_alloc(
641 int type);
1c79356b 642
91447636
A
643extern void funnel_free(
644 funnel_t *lock);
1c79356b 645
91447636
A
646extern void thread_read_times(
647 thread_t thread,
648 time_value_t *user_time,
649 time_value_t *system_time);
1c79356b 650
91447636
A
651extern void thread_setuserstack(
652 thread_t thread,
653 mach_vm_offset_t user_stack);
1c79356b 654
91447636
A
655extern uint64_t thread_adjuserstack(
656 thread_t thread,
657 int adjust);
55e303ae 658
91447636 659extern void thread_setentrypoint(
55e303ae 660 thread_t thread,
91447636
A
661 mach_vm_offset_t entry);
662
2d21ac55 663extern kern_return_t thread_setsinglestep(
0c530ab8
A
664 thread_t thread,
665 int on);
666
91447636
A
667extern kern_return_t thread_wire_internal(
668 host_priv_t host_priv,
669 thread_t thread,
670 boolean_t wired,
671 boolean_t *prev_state);
672
91447636
A
673extern kern_return_t thread_dup(thread_t);
674
2d21ac55
A
675typedef void (*sched_call_t)(
676 int type,
677 thread_t thread);
678
679#define SCHED_CALL_BLOCK 0x1
680#define SCHED_CALL_UNBLOCK 0x2
681
682extern void thread_sched_call(
683 thread_t thread,
684 sched_call_t call);
685
686extern void thread_static_param(
687 thread_t thread,
688 boolean_t state);
689
91447636 690extern task_t get_threadtask(thread_t);
0c530ab8
A
691#define thread_is_64bit(thd) \
692 task_has_64BitAddr(get_threadtask(thd))
693
91447636
A
694
695extern void *get_bsdthread_info(thread_t);
696extern void set_bsdthread_info(thread_t, void *);
697extern void *uthread_alloc(task_t, thread_t);
2d21ac55
A
698extern void uthread_cleanup(task_t, void *, void *);
699extern void uthread_zone_free(void *);
700extern void uthread_cred_free(void *);
91447636
A
701
702extern boolean_t thread_should_halt(
703 thread_t thread);
704
2d21ac55
A
705extern int is_64signalregset(void);
706
707void act_set_apc(thread_t);
708
709extern uint32_t dtrace_get_thread_predcache(thread_t);
710extern int64_t dtrace_get_thread_vtime(thread_t);
711extern int64_t dtrace_get_thread_tracing(thread_t);
712extern boolean_t dtrace_get_thread_reentering(thread_t);
713extern vm_offset_t dtrace_get_kernel_stack(thread_t);
714extern void dtrace_set_thread_predcache(thread_t, uint32_t);
715extern void dtrace_set_thread_vtime(thread_t, int64_t);
716extern void dtrace_set_thread_tracing(thread_t, int64_t);
717extern void dtrace_set_thread_reentering(thread_t, boolean_t);
718extern vm_offset_t dtrace_set_thread_recover(thread_t, vm_offset_t);
719
720extern int64_t dtrace_calc_thread_recent_vtime(thread_t);
721
722
723extern void thread_set_wq_state32(
724 thread_t thread,
725 thread_state_t tstate);
726
727extern void thread_set_wq_state64(
728 thread_t thread,
729 thread_state_t tstate);
730
91447636
A
731#endif /* XNU_KERNEL_PRIVATE */
732
733extern kern_return_t kernel_thread_start(
734 thread_continue_t continuation,
735 void *parameter,
736 thread_t *new_thread);
55e303ae 737
91447636 738__END_DECLS
55e303ae 739
1c79356b 740#endif /* _KERN_THREAD_H_ */