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