]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task.h
3449f26c7bd9d8691c26db47dff4a7511b356b21
[apple/xnu.git] / osfmk / kern / task.h
1 /*
2 * Copyright (c) 2000-2010, 2015 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 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: task.h
60 * Author: Avadis Tevanian, Jr.
61 *
62 * This file contains the structure definitions for tasks.
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 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
85 * support for mandatory and extensible security protections. This notice
86 * is included in support of clause 2.2 (b) of the Apple Public License,
87 * Version 2.0.
88 * Copyright (c) 2005 SPARTA, Inc.
89 */
90
91 #ifndef _KERN_TASK_H_
92 #define _KERN_TASK_H_
93
94 #include <kern/kern_types.h>
95 #include <mach/mach_types.h>
96 #include <sys/cdefs.h>
97
98 #ifdef XNU_KERNEL_PRIVATE
99 #include <kern/kern_cdata.h>
100 #include <mach/sfi_class.h>
101 #include <kern/queue.h>
102 #endif /* XNU_KERNEL_PRIVATE */
103
104 #ifdef MACH_KERNEL_PRIVATE
105
106 #include <mach/boolean.h>
107 #include <mach/port.h>
108 #include <mach/time_value.h>
109 #include <mach/message.h>
110 #include <mach/mach_param.h>
111 #include <mach/task_info.h>
112 #include <mach/exception_types.h>
113 #include <mach/vm_statistics.h>
114 #include <machine/task.h>
115
116 #include <kern/cpu_data.h>
117 #include <kern/queue.h>
118 #include <kern/exception.h>
119 #include <kern/locks.h>
120 #include <security/_label.h>
121 #include <ipc/ipc_port.h>
122
123 #include <kern/thread.h>
124 #include <mach/coalition.h>
125
126 #ifdef CONFIG_ATM
127 #include <atm/atm_internal.h>
128 #endif
129
130 struct _cpu_time_qos_stats {
131 uint64_t cpu_time_qos_default;
132 uint64_t cpu_time_qos_maintenance;
133 uint64_t cpu_time_qos_background;
134 uint64_t cpu_time_qos_utility;
135 uint64_t cpu_time_qos_legacy;
136 uint64_t cpu_time_qos_user_initiated;
137 uint64_t cpu_time_qos_user_interactive;
138 };
139
140 #ifdef CONFIG_BANK
141 #include <bank/bank_internal.h>
142 #endif
143
144 struct task {
145 /* Synchronization/destruction information */
146 decl_lck_mtx_data(,lock) /* Task's lock */
147 uint32_t ref_count; /* Number of references to me */
148 boolean_t active; /* Task has not been terminated */
149 boolean_t halting; /* Task is being halted */
150
151 /* Miscellaneous */
152 vm_map_t map; /* Address space description */
153 queue_chain_t tasks; /* global list of tasks */
154 void *user_data; /* Arbitrary data settable via IPC */
155
156 #if defined(CONFIG_SCHED_MULTIQ)
157 sched_group_t sched_group;
158 #endif /* defined(CONFIG_SCHED_MULTIQ) */
159
160 /* Threads in this task */
161 queue_head_t threads;
162
163 processor_set_t pset_hint;
164 struct affinity_space *affinity_space;
165
166 int thread_count;
167 uint32_t active_thread_count;
168 int suspend_count; /* Internal scheduling only */
169
170 /* User-visible scheduling information */
171 integer_t user_stop_count; /* outstanding stops */
172 integer_t legacy_stop_count; /* outstanding legacy stops */
173
174 integer_t priority; /* base priority for threads */
175 integer_t max_priority; /* maximum priority for threads */
176
177 integer_t importance; /* priority offset (BSD 'nice' value) */
178
179 /* Task security and audit tokens */
180 security_token_t sec_token;
181 audit_token_t audit_token;
182
183 /* Statistics */
184 uint64_t total_user_time; /* terminated threads only */
185 uint64_t total_system_time;
186
187 /* Virtual timers */
188 uint32_t vtimers;
189
190 /* IPC structures */
191 decl_lck_mtx_data(,itk_lock_data)
192 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
193 struct ipc_port *itk_nself; /* not a right, doesn't hold ref */
194 struct ipc_port *itk_sself; /* a send right */
195 struct exception_action exc_actions[EXC_TYPES_COUNT];
196 /* a send right each valid element */
197 struct ipc_port *itk_host; /* a send right */
198 struct ipc_port *itk_bootstrap; /* a send right */
199 struct ipc_port *itk_seatbelt; /* a send right */
200 struct ipc_port *itk_gssd; /* yet another send right */
201 struct ipc_port *itk_debug_control; /* send right for debugmode communications */
202 struct ipc_port *itk_task_access; /* and another send right */
203 struct ipc_port *itk_resume; /* a receive right to resume this task */
204 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
205 /* all send rights */
206
207 struct ipc_space *itk_space;
208
209 /* Synchronizer ownership information */
210 queue_head_t semaphore_list; /* list of owned semaphores */
211 int semaphores_owned; /* number of semaphores owned */
212
213 ledger_t ledger;
214
215 unsigned int priv_flags; /* privilege resource flags */
216 #define VM_BACKING_STORE_PRIV 0x1
217
218 MACHINE_TASK
219
220 integer_t faults; /* faults counter */
221 integer_t pageins; /* pageins counter */
222 integer_t cow_faults; /* copy on write fault counter */
223 integer_t messages_sent; /* messages sent counter */
224 integer_t messages_received; /* messages received counter */
225 integer_t syscalls_mach; /* mach system call counter */
226 integer_t syscalls_unix; /* unix system call counter */
227 uint32_t c_switch; /* total context switches */
228 uint32_t p_switch; /* total processor switches */
229 uint32_t ps_switch; /* total pset switches */
230
231 #ifdef MACH_BSD
232 void *bsd_info;
233 #endif
234 kcdata_descriptor_t corpse_info;
235 void * corpse_info_kernel;
236 queue_chain_t corpse_tasks;
237 #ifdef CONFIG_MACF
238 struct label * crash_label;
239 #endif
240 struct vm_shared_region *shared_region;
241 volatile uint32_t t_flags; /* general-purpose task flags protected by task_lock (TL) */
242 #define TF_NONE 0
243 #define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */
244 #define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */
245 #define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */
246 #define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */
247 #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */
248 #define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */
249 #define TF_CORPSE 0x00000020 /* task is a corpse */
250 #define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */
251 #define TF_CORPSE_FORK 0x00000080 /* task is a forked corpse */
252
253 #define task_has_64BitAddr(task) \
254 (((task)->t_flags & TF_64B_ADDR) != 0)
255 #define task_set_64BitAddr(task) \
256 ((task)->t_flags |= TF_64B_ADDR)
257 #define task_clear_64BitAddr(task) \
258 ((task)->t_flags &= ~TF_64B_ADDR)
259 #define task_has_64BitData(task) \
260 (((task)->t_flags & TF_64B_DATA) != 0)
261
262 #define task_is_a_corpse(task) \
263 (((task)->t_flags & TF_CORPSE) != 0)
264
265 #define task_set_corpse(task) \
266 ((task)->t_flags |= TF_CORPSE)
267
268 #define task_corpse_pending_report(task) \
269 (((task)->t_flags & TF_PENDING_CORPSE) != 0)
270
271 #define task_set_corpse_pending_report(task) \
272 ((task)->t_flags |= TF_PENDING_CORPSE)
273
274 #define task_clear_corpse_pending_report(task) \
275 ((task)->t_flags &= ~TF_PENDING_CORPSE)
276
277 #define task_is_a_corpse_fork(task) \
278 (((task)->t_flags & TF_CORPSE_FORK) != 0)
279
280 mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */
281 mach_vm_size_t all_image_info_size; /* section location and size */
282
283 #if KPERF
284 #define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */
285 #define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_chud" signifying KPC forced all counters */
286
287 uint32_t t_chud; /* CHUD flags, used for Shark */
288 #endif
289
290 boolean_t pidsuspended; /* pid_suspend called; no threads can execute */
291 boolean_t frozen; /* frozen; private resident pages committed to swap */
292 boolean_t changing_freeze_state; /* in the process of freezing or thawing */
293 uint16_t policy_ru_cpu :4,
294 policy_ru_cpu_ext :4,
295 applied_ru_cpu :4,
296 applied_ru_cpu_ext :4;
297 uint8_t rusage_cpu_flags;
298 uint8_t rusage_cpu_percentage; /* Task-wide CPU limit percentage */
299 uint64_t rusage_cpu_interval; /* Task-wide CPU limit interval */
300 uint8_t rusage_cpu_perthr_percentage; /* Per-thread CPU limit percentage */
301 uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */
302 uint64_t rusage_cpu_deadline;
303 thread_call_t rusage_cpu_callt;
304
305 #if CONFIG_ATM
306 struct atm_task_descriptor *atm_context; /* pointer to per task atm descriptor */
307 #endif
308 #if CONFIG_BANK
309 struct bank_task *bank_context; /* pointer to per task bank structure */
310 #endif
311
312 #if IMPORTANCE_INHERITANCE
313 struct ipc_importance_task *task_imp_base; /* Base of IPC importance chain */
314 #endif /* IMPORTANCE_INHERITANCE */
315
316 vm_extmod_statistics_data_t extmod_statistics;
317
318 #if MACH_ASSERT
319 int8_t suspends_outstanding; /* suspends this task performed in excess of resumes */
320 #endif
321
322 struct task_requested_policy requested_policy;
323 struct task_effective_policy effective_policy;
324
325 /*
326 * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away.
327 */
328 uint32_t low_mem_notified_warn :1, /* warning low memory notification is sent to the task */
329 low_mem_notified_critical :1, /* critical low memory notification is sent to the task */
330 purged_memory_warn :1, /* purgeable memory of the task is purged for warning level pressure */
331 purged_memory_critical :1, /* purgeable memory of the task is purged for critical level pressure */
332 low_mem_privileged_listener :1, /* if set, task would like to know about pressure changes before other tasks on the system */
333 mem_notify_reserved :27; /* reserved for future use */
334
335 io_stat_info_t task_io_stats;
336 uint64_t task_immediate_writes __attribute__((aligned(8)));
337 uint64_t task_deferred_writes __attribute__((aligned(8)));
338 uint64_t task_invalidated_writes __attribute__((aligned(8)));
339 uint64_t task_metadata_writes __attribute__((aligned(8)));
340
341 /*
342 * The cpu_time_qos_stats fields are protected by the task lock
343 */
344 struct _cpu_time_qos_stats cpu_time_qos_stats;
345
346 /* Statistics accumulated for terminated threads from this task */
347 uint32_t task_timer_wakeups_bin_1;
348 uint32_t task_timer_wakeups_bin_2;
349 uint64_t task_gpu_ns;
350 uint64_t task_energy;
351
352 /* # of purgeable volatile VM objects owned by this task: */
353 int task_volatile_objects;
354 /* # of purgeable but not volatile VM objects owned by this task: */
355 int task_nonvolatile_objects;
356 boolean_t task_purgeable_disowning;
357 boolean_t task_purgeable_disowned;
358
359 /*
360 * A task's coalition set is "adopted" in task_create_internal
361 * and unset in task_deallocate_internal, so each array member
362 * can be referenced without the task lock.
363 * Note: these fields are protected by coalition->lock,
364 * not the task lock.
365 */
366 coalition_t coalition[COALITION_NUM_TYPES];
367 queue_chain_t task_coalition[COALITION_NUM_TYPES];
368 uint64_t dispatchqueue_offset;
369
370 #if DEVELOPMENT || DEBUG
371 boolean_t task_unnested;
372 int task_disconnected_count;
373 #endif
374
375 #if HYPERVISOR
376 void *hv_task_target; /* hypervisor virtual machine object associated with this task */
377 #endif /* HYPERVISOR */
378
379 #if CONFIG_SECLUDED_MEMORY
380 boolean_t task_can_use_secluded_mem;
381 boolean_t task_could_use_secluded_mem;
382 boolean_t task_could_also_use_secluded_mem;
383 #endif /* CONFIG_SECLUDED_MEMORY */
384
385 queue_head_t io_user_clients;
386 uint32_t exec_token;
387 };
388
389 #define task_lock(task) lck_mtx_lock(&(task)->lock)
390 #define task_lock_assert_owned(task) lck_mtx_assert(&(task)->lock, LCK_MTX_ASSERT_OWNED)
391 #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
392 #define task_unlock(task) lck_mtx_unlock(&(task)->lock)
393
394 #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
395 #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
396 #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
397 #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
398
399 #define TASK_REFERENCE_LEAK_DEBUG 0
400
401 #if TASK_REFERENCE_LEAK_DEBUG
402 extern void task_reference_internal(task_t task);
403 extern uint32_t task_deallocate_internal(task_t task);
404 #else
405 #define task_reference_internal(task) \
406 (void)hw_atomic_add(&(task)->ref_count, 1)
407
408 #define task_deallocate_internal(task) \
409 hw_atomic_sub(&(task)->ref_count, 1)
410 #endif
411
412 #define task_reference(task) \
413 MACRO_BEGIN \
414 if ((task) != TASK_NULL) \
415 task_reference_internal(task); \
416 MACRO_END
417
418 extern kern_return_t kernel_task_create(
419 task_t task,
420 vm_offset_t map_base,
421 vm_size_t map_size,
422 task_t *child);
423
424 /* Initialize task module */
425 extern void task_init(void);
426
427 /* coalition_init() calls this to initialize ledgers before task_init() */
428 extern void init_task_ledgers(void);
429
430 #define current_task_fast() (current_thread()->task)
431 #define current_task() current_task_fast()
432
433 extern lck_attr_t task_lck_attr;
434 extern lck_grp_t task_lck_grp;
435
436
437 #else /* MACH_KERNEL_PRIVATE */
438
439 __BEGIN_DECLS
440
441 extern task_t current_task(void);
442
443 extern void task_reference(task_t task);
444
445 #define TF_NONE 0
446
447 __END_DECLS
448
449 #endif /* MACH_KERNEL_PRIVATE */
450
451 __BEGIN_DECLS
452
453 #ifdef XNU_KERNEL_PRIVATE
454
455 /* Hold all threads in a task */
456 extern kern_return_t task_hold(
457 task_t task);
458
459 /* Wait for task to stop running, either just to get off CPU or to cease being runnable */
460 extern kern_return_t task_wait(
461 task_t task,
462 boolean_t until_not_runnable);
463
464 /* Release hold on all threads in a task */
465 extern kern_return_t task_release(
466 task_t task);
467
468 /* Suspend/resume a task where the kernel owns the suspend count */
469 extern kern_return_t task_suspend_internal( task_t task);
470 extern kern_return_t task_resume_internal( task_t task);
471
472 /* Suspends a task by placing a hold on its threads */
473 extern kern_return_t task_pidsuspend(
474 task_t task);
475 extern kern_return_t task_pidsuspend_locked(
476 task_t task);
477
478 /* Resumes a previously paused task */
479 extern kern_return_t task_pidresume(
480 task_t task);
481
482 extern kern_return_t task_send_trace_memory(
483 task_t task,
484 uint32_t pid,
485 uint64_t uniqueid);
486
487 #if DEVELOPMENT || DEBUG
488
489 extern kern_return_t task_disconnect_page_mappings(
490 task_t task);
491 #endif
492
493 extern void tasks_system_suspend(boolean_t suspend);
494
495 #if CONFIG_FREEZE
496
497 /* Freeze a task's resident pages */
498 extern kern_return_t task_freeze(
499 task_t task,
500 uint32_t *purgeable_count,
501 uint32_t *wired_count,
502 uint32_t *clean_count,
503 uint32_t *dirty_count,
504 uint32_t dirty_budget,
505 boolean_t *shared,
506 boolean_t walk_only);
507
508 /* Thaw a currently frozen task */
509 extern kern_return_t task_thaw(
510 task_t task);
511
512 #endif /* CONFIG_FREEZE */
513
514 /* Halt all other threads in the current task */
515 extern kern_return_t task_start_halt(
516 task_t task);
517
518 /* Wait for other threads to halt and free halting task resources */
519 extern void task_complete_halt(
520 task_t task);
521
522 extern kern_return_t task_terminate_internal(
523 task_t task);
524
525 extern kern_return_t task_create_internal(
526 task_t parent_task,
527 coalition_t *parent_coalitions,
528 boolean_t inherit_memory,
529 boolean_t is_64bit,
530 uint32_t flags,
531 task_t *child_task); /* OUT */
532
533
534 extern void task_power_info_locked(
535 task_t task,
536 task_power_info_t info,
537 gpu_energy_data_t gpu_energy,
538 uint64_t *task_power);
539
540 extern uint64_t task_gpu_utilisation(
541 task_t task);
542
543 extern uint64_t task_energy(
544 task_t task);
545
546 extern void task_vtimer_set(
547 task_t task,
548 integer_t which);
549
550 extern void task_vtimer_clear(
551 task_t task,
552 integer_t which);
553
554 extern void task_vtimer_update(
555 task_t task,
556 integer_t which,
557 uint32_t *microsecs);
558
559 #define TASK_VTIMER_USER 0x01
560 #define TASK_VTIMER_PROF 0x02
561 #define TASK_VTIMER_RLIM 0x04
562
563 extern void task_set_64bit(
564 task_t task,
565 boolean_t is64bit);
566
567 extern void task_backing_store_privileged(
568 task_t task);
569
570 extern void task_set_dyld_info(
571 task_t task,
572 mach_vm_address_t addr,
573 mach_vm_size_t size);
574
575 /* Get number of activations in a task */
576 extern int get_task_numacts(
577 task_t task);
578
579 extern int get_task_numactivethreads(task_t task);
580 extern kern_return_t task_collect_crash_info(task_t task, struct proc *p, int is_corpse_fork);
581 void task_port_notify(mach_msg_header_t *msg);
582 void task_wait_till_threads_terminate_locked(task_t task);
583
584 /* JMM - should just be temporary (implementation in bsd_kern still) */
585 extern void set_bsdtask_info(task_t,void *);
586 extern vm_map_t get_task_map_reference(task_t);
587 extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t, boolean_t);
588 extern pmap_t get_task_pmap(task_t);
589 extern uint64_t get_task_resident_size(task_t);
590 extern uint64_t get_task_compressed(task_t);
591 extern uint64_t get_task_resident_max(task_t);
592 extern uint64_t get_task_phys_footprint(task_t);
593 extern uint64_t get_task_phys_footprint_max(task_t);
594 extern uint64_t get_task_phys_footprint_limit(task_t);
595 extern uint64_t get_task_purgeable_size(task_t);
596 extern uint64_t get_task_cpu_time(task_t);
597 extern uint64_t get_task_dispatchqueue_offset(task_t);
598 extern uint64_t get_task_dispatchqueue_serialno_offset(task_t);
599 extern uint64_t get_task_uniqueid(task_t);
600
601 extern uint64_t get_task_internal(task_t);
602 extern uint64_t get_task_internal_compressed(task_t);
603 extern uint64_t get_task_purgeable_nonvolatile(task_t);
604 extern uint64_t get_task_purgeable_nonvolatile_compressed(task_t);
605 extern uint64_t get_task_iokit_mapped(task_t);
606 extern uint64_t get_task_alternate_accounting(task_t);
607 extern uint64_t get_task_alternate_accounting_compressed(task_t);
608 extern uint64_t get_task_memory_region_count(task_t);
609 extern uint64_t get_task_page_table(task_t);
610
611 extern kern_return_t task_convert_phys_footprint_limit(int, int *);
612 extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t);
613 extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb);
614
615 extern boolean_t is_kerneltask(task_t task);
616 extern boolean_t is_corpsetask(task_t task);
617
618 extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast);
619
620 extern kern_return_t machine_task_get_state(
621 task_t task,
622 int flavor,
623 thread_state_t state,
624 mach_msg_type_number_t *state_count);
625
626 extern kern_return_t machine_task_set_state(
627 task_t task,
628 int flavor,
629 thread_state_t state,
630 mach_msg_type_number_t state_count);
631
632 extern void machine_task_terminate(task_t task);
633
634 struct _task_ledger_indices {
635 int cpu_time;
636 int tkm_private;
637 int tkm_shared;
638 int phys_mem;
639 int wired_mem;
640 int internal;
641 int iokit_mapped;
642 int alternate_accounting;
643 int alternate_accounting_compressed;
644 int page_table;
645 int phys_footprint;
646 int internal_compressed;
647 int purgeable_volatile;
648 int purgeable_nonvolatile;
649 int purgeable_volatile_compressed;
650 int purgeable_nonvolatile_compressed;
651 int platform_idle_wakeups;
652 int interrupt_wakeups;
653 #if CONFIG_SCHED_SFI
654 int sfi_wait_times[MAX_SFI_CLASS_ID];
655 #endif /* CONFIG_SCHED_SFI */
656 #ifdef CONFIG_BANK
657 int cpu_time_billed_to_me;
658 int cpu_time_billed_to_others;
659 #endif
660 int physical_writes;
661 int logical_writes;
662 };
663 extern struct _task_ledger_indices task_ledgers;
664
665 /* requires task to be unlocked, returns a referenced thread */
666 thread_t task_findtid(task_t task, uint64_t tid);
667
668 extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags);
669 extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags);
670 extern kern_return_t task_io_monitor_ctl(task_t task, uint32_t *flags);
671
672 extern void task_atm_reset(task_t task);
673 extern void task_bank_reset(task_t task);
674 extern void task_bank_init(task_t task);
675
676 extern int task_pid(task_t task);
677 extern boolean_t task_has_assertions(task_t task);
678 /* End task_policy */
679
680 extern void task_set_gpu_denied(task_t task, boolean_t denied);
681 extern boolean_t task_is_gpu_denied(task_t task);
682
683 extern queue_head_t * task_io_user_clients(task_t task);
684
685 #endif /* XNU_KERNEL_PRIVATE */
686
687 #ifdef KERNEL_PRIVATE
688
689 extern void *get_bsdtask_info(task_t);
690 extern void *get_bsdthreadtask_info(thread_t);
691 extern void task_bsdtask_kill(task_t);
692 extern vm_map_t get_task_map(task_t);
693 extern ledger_t get_task_ledger(task_t);
694
695 extern boolean_t get_task_pidsuspended(task_t);
696 extern boolean_t get_task_frozen(task_t);
697
698 /* Convert from a task to a port */
699 extern ipc_port_t convert_task_to_port(task_t);
700 extern ipc_port_t convert_task_name_to_port(task_name_t);
701 extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task);
702
703 /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */
704 extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port);
705
706 extern boolean_t task_suspension_notify(mach_msg_header_t *);
707
708 #define TASK_WRITE_IMMEDIATE 0x1
709 #define TASK_WRITE_DEFERRED 0x2
710 #define TASK_WRITE_INVALIDATED 0x4
711 #define TASK_WRITE_METADATA 0x8
712 extern void task_update_logical_writes(task_t task, uint32_t io_size, int flags, void *vp);
713
714 #if CONFIG_SECLUDED_MEMORY
715 extern void task_set_can_use_secluded_mem(
716 task_t task,
717 boolean_t can_use_secluded_mem);
718 extern void task_set_could_use_secluded_mem(
719 task_t task,
720 boolean_t could_use_secluded_mem);
721 extern void task_set_could_also_use_secluded_mem(
722 task_t task,
723 boolean_t could_also_use_secluded_mem);
724 extern boolean_t task_can_use_secluded_mem(task_t task);
725 extern boolean_t task_could_use_secluded_mem(task_t task);
726 #endif /* CONFIG_SECLUDED_MEMORY */
727
728 #if CONFIG_MACF
729 extern struct label *get_task_crash_label(task_t task);
730 extern void set_task_crash_label(task_t task, struct label *label);
731 #endif /* CONFIG_MACF */
732
733 #endif /* KERNEL_PRIVATE */
734
735 extern task_t kernel_task;
736
737 extern void task_deallocate(
738 task_t task);
739
740 extern void task_name_deallocate(
741 task_name_t task_name);
742
743 extern void task_suspension_token_deallocate(
744 task_suspension_token_t token);
745 __END_DECLS
746
747 #endif /* _KERN_TASK_H_ */