1/*
2 * Copyright (c) 2000-2010 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	MACH_KERNEL_PRIVATE
99
100#include <mach/boolean.h>
101#include <mach/port.h>
102#include <mach/time_value.h>
103#include <mach/message.h>
104#include <mach/mach_param.h>
105#include <mach/task_info.h>
106#include <mach/exception_types.h>
107#include <mach/vm_statistics.h>
108#include <machine/task.h>
109
110#include <kern/cpu_data.h>
111#include <kern/queue.h>
112#include <kern/exception.h>
113#include <kern/lock.h>
114#include <security/_label.h>
115#include <ipc/ipc_labelh.h>
116#endif /* MACH_KERNEL_PRIVATE */
117
118#ifdef XNU_KERNEL_PRIVATE
119
120/* defns for task->rsu_controldata */
121#define TASK_POLICY_CPU_RESOURCE_USAGE		0
122#define TASK_POLICY_WIREDMEM_RESOURCE_USAGE	1
123#define TASK_POLICY_VIRTUALMEM_RESOURCE_USAGE	2
124#define TASK_POLICY_DISK_RESOURCE_USAGE		3
125#define TASK_POLICY_NETWORK_RESOURCE_USAGE	4
126#define TASK_POLICY_POWER_RESOURCE_USAGE	5
127
128#define TASK_POLICY_RESOURCE_USAGE_COUNT 6
129
130/*
131 * Process Action and Policy bit definitions
132
133The bit defns of the policy states
13464   60    56   52   48   44   40   36   32   28   24   20   16   12   8        0
135|----|-----|----|----|----|----|----|----|----|----|----|----|----|----|--------|
136|RFU | RFU | PWR| NET| DSK| CPU| VM | WM | LVM| RFU| CPU| NET| GPU| DSK| BGRND  |
137|----|-----|----|----|----|----|----|----|----|----|----|----|----|----|--------|
138|<-----------   RESOURCE USAGE  -------->|< LOWSRC>|<-HARDWARE ACCESS->|BackGrnd|
139|----|-----|----|----|----|----|----|----|----|----|----|----|----|----|--------|
140
141*
142*/
143
144#define TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE		0x00
145#define TASK_POLICY_BACKGROUND_ATTRIBUTE_LOWPRI		0x01
146#define TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE	0x02
147#define TASK_POLICY_BACKGROUND_ATTRIBUTE_NETTHROTTLE	0x04
148#define TASK_POLICY_BACKGROUND_ATTRIBUTE_NOGPU		0x08
149#if CONFIG_EMBEDDED
150#define TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL		0x0F
151#else /* CONFIG_EMBEDDED */
152#define TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL		0x07
153#endif /* CONFIG_EMBEDDED */
154#define TASK_POLICY_BACKGROUND_ATTRIBUTE_DEFAULT	TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL
155
156/* Hardware disk access attributes, bit different as it should reflect IOPOL_XXX */
157#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_NONE	0x00
158#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS	0x01
159#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_NORMAL	0x01
160#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_PASSIVE	0x02
161#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_THROTTLE	0x03
162#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_UTILITY	0x04
163#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_DEFAULT	TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS
164
165/* Hardware GPU access attributes */
166#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NONE		0x00
167#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_FULLACCESS	0x00
168#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS	0x01
169#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT	TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_FULLACCESS
170
171/* Hardware Network access attributes */
172#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_NONE		0x00
173#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_FULLACCESS	0x00
174#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_THROTTLE	0x01
175#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_DEFAULT	TASK_POLICY_HWACCESS_NET_ATTRIBUTE_FULLACCESS
176
177/* Hardware CPU access attributes */
178#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_NONE		0x00
179#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_FULLACCESS	0x00
180#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_ONE		0x01
181#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_LLCACHE	0x02
182#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_DEFAULT	TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_FULLACCESS
183
184/* Resource usage/low resource attributes */
185#define TASK_POLICY_RESOURCE_ATTRIBUTE_NONE		0x00
186#define TASK_POLICY_RESOURCE_ATTRIBUTE_THROTTLE		0x01
187#define TASK_POLICY_RESOURCE_ATTRIBUTE_SUSPEND 		0x02
188#define TASK_POLICY_RESOURCE_ATTRIBUTE_TERMINATE	0x03
189#define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_KQ	0x04
190#define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_EXC	0x05
191#define TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT		TASK_POLICY_RESOURCE_ATTRIBUTE_NONE
192
193#endif /* XNU_KERNEL_PRIVATE */
194
195#ifdef MACH_KERNEL_PRIVATE
196
197typedef struct process_policy {
198	uint64_t  apptype:4,
199		  rfu1:4,
200		  ru_power:4,	/* Resource Usage Power */
201		  ru_net:4,	/* Resource Usage Network */
202		  ru_disk:4,	/* Resource Usage Disk */
203		  ru_cpu:4,	/* Resource Usage CPU */
204		  ru_virtmem:4,	/* Resource Usage VM */
205		  ru_wiredmem:4,/* Resource Usage Wired Memory */
206		  low_vm:4,	/* Low Virtual Memory */
207		  rfu2:4,
208		  hw_cpu:4,	/* HW Access to CPU */
209		  hw_net:4,	/* HW Access to Network */
210		  hw_gpu:4,	/* HW Access to GPU */
211		  hw_disk:4,	/* HW Access to Disk */
212		  hw_bg:8;	/* Darwin Background Policy */
213} process_policy_t;
214
215#if CONFIG_EMBEDDED
216
217typedef struct task_watcher {
218	queue_chain_t	tw_links;		/* queueing of threads */
219	task_t		tw_task;	/* task that is being watched */
220	thread_t	tw_thread;	/* thread that is watching the watch_task */
221	int		tw_state;	/* the current app state of the thread */
222	int		tw_importance;	/* importance prior to backgrounding */
223} task_watch_t;
224
225extern lck_mtx_t task_watch_mtx;
226
227#endif /* CONFIG_EMBEDDED */
228
229#include <kern/thread.h>
230
231extern process_policy_t default_task_proc_policy;	/* init value for the process policy attributes */
232extern process_policy_t default_task_null_policy;	/* none as the value for the process policy attributes */
233
234struct task {
235	/* Synchronization/destruction information */
236	decl_lck_mtx_data(,lock)		/* Task's lock */
237	uint32_t	ref_count;	/* Number of references to me */
238	boolean_t	active;		/* Task has not been terminated */
239	boolean_t	halting;	/* Task is being halted */
240
241	/* Miscellaneous */
242	vm_map_t	map;		/* Address space description */
243	queue_chain_t	tasks;	/* global list of tasks */
244	void		*user_data;	/* Arbitrary data settable via IPC */
245
246	/* Threads in this task */
247	queue_head_t		threads;
248
249	processor_set_t		pset_hint;
250	struct affinity_space	*affinity_space;
251
252	int			thread_count;
253	uint32_t		active_thread_count;
254	int			suspend_count;	/* Internal scheduling only */
255
256	/* User-visible scheduling information */
257	integer_t		user_stop_count;	/* outstanding stops */
258
259	task_role_t		role;
260
261	integer_t		priority;			/* base priority for threads */
262	integer_t		max_priority;		/* maximum priority for threads */
263
264	/* Task security and audit tokens */
265	security_token_t sec_token;
266	audit_token_t	audit_token;
267
268	/* Statistics */
269	uint64_t		total_user_time;	/* terminated threads only */
270	uint64_t		total_system_time;
271
272	/* Virtual timers */
273	uint32_t		vtimers;
274
275	/* IPC structures */
276	decl_lck_mtx_data(,itk_lock_data)
277	struct ipc_port *itk_self;	/* not a right, doesn't hold ref */
278	struct ipc_port *itk_nself;	/* not a right, doesn't hold ref */
279	struct ipc_port *itk_sself;	/* a send right */
280	struct exception_action exc_actions[EXC_TYPES_COUNT];
281		 			/* a send right each valid element  */
282	struct ipc_port *itk_host;	/* a send right */
283	struct ipc_port *itk_bootstrap;	/* a send right */
284	struct ipc_port *itk_seatbelt;	/* a send right */
285	struct ipc_port *itk_gssd;	/* yet another send right */
286	struct ipc_port *itk_task_access; /* and another send right */
287	struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
288					/* all send rights */
289
290	struct ipc_space *itk_space;
291
292	/* Synchronizer ownership information */
293	queue_head_t	semaphore_list;		/* list of owned semaphores   */
294	queue_head_t	lock_set_list;		/* list of owned lock sets    */
295	int		semaphores_owned;	/* number of semaphores owned */
296	int 		lock_sets_owned;	/* number of lock sets owned  */
297
298	ledger_t	ledger;
299
300	unsigned int	priv_flags;			/* privilege resource flags */
301#define VM_BACKING_STORE_PRIV	0x1
302
303	MACHINE_TASK
304
305	integer_t faults;              /* faults counter */
306        integer_t pageins;             /* pageins counter */
307        integer_t cow_faults;          /* copy on write fault counter */
308        integer_t messages_sent;       /* messages sent counter */
309        integer_t messages_received;   /* messages received counter */
310        integer_t syscalls_mach;       /* mach system call counter */
311        integer_t syscalls_unix;       /* unix system call counter */
312		uint32_t  c_switch;			   /* total context switches */
313		uint32_t  p_switch;			   /* total processor switches */
314		uint32_t  ps_switch;		   /* total pset switches */
315
316	zinfo_usage_t tkm_zinfo;	/* per-task, per-zone usage statistics */
317
318#ifdef  MACH_BSD
319	void *bsd_info;
320#endif
321	struct vm_shared_region		*shared_region;
322	uint32_t taskFeatures[2];		/* Special feature for this task */
323#define tf64BitAddr	0x80000000		/* Task has 64-bit addressing */
324#define tf64BitData	0x40000000		/* Task has 64-bit data registers */
325#define task_has_64BitAddr(task)	\
326	 (((task)->taskFeatures[0] & tf64BitAddr) != 0)
327#define task_set_64BitAddr(task)	\
328	 ((task)->taskFeatures[0] |= tf64BitAddr)
329#define task_clear_64BitAddr(task)	\
330	 ((task)->taskFeatures[0] &= ~tf64BitAddr)
331
332	mach_vm_address_t	all_image_info_addr; /* dyld __all_image_info     */
333	mach_vm_size_t		all_image_info_size; /* section location and size */
334#if CONFIG_MACF_MACH
335	ipc_labelh_t label;
336#endif
337
338#if CONFIG_COUNTERS
339#define TASK_PMC_FLAG 0x1	/* Bit in "t_chud" signifying PMC interest */
340	uint32_t t_chud;		/* CHUD flags, used for Shark */
341#endif
342
343	boolean_t pidsuspended; /* pid_suspend called; no threads can execute */
344	boolean_t frozen;       /* frozen; private resident pages committed to swap */
345	process_policy_t ext_appliedstate;	/* externally applied actions */
346	process_policy_t ext_policystate;	/* externally defined process policy states*/
347	process_policy_t appliedstate;		/* self applied acions */
348	process_policy_t policystate;		/* process wide policy states */
349	uint8_t  rusage_cpu_flags;
350	uint8_t  rusage_cpu_percentage;		/* Task-wide CPU limit percentage */
351	uint64_t rusage_cpu_interval;		/* Task-wide CPU limit interval */
352	uint8_t  rusage_cpu_perthr_percentage;  /* Per-thread CPU limit percentage */
353	uint64_t rusage_cpu_perthr_interval;    /* Per-thread CPU limit interval */
354	uint64_t rusage_cpu_deadline;
355	thread_call_t rusage_cpu_callt;
356#if CONFIG_EMBEDDED
357	uint32_t	appstate;		/* the current appstate */
358	queue_head_t	task_watchers;		/* app state watcher threads */
359	int	num_taskwatchers;
360	int		watchapplying;
361#endif /* CONFIG_EMBEDDED */
362
363	vm_extmod_statistics_data_t	extmod_statistics;
364	natural_t	proc_terminate;	/* the process is marked for proc_terminate */
365
366	/* Statistics accumulated for terminated threads from this task */
367	uint32_t	task_timer_wakeups_bin_1;
368	uint32_t	task_timer_wakeups_bin_2;
369};
370
371#define task_lock(task)		lck_mtx_lock(&(task)->lock)
372#define task_lock_try(task)	lck_mtx_try_lock(&(task)->lock)
373#define task_unlock(task)	lck_mtx_unlock(&(task)->lock)
374
375#if CONFIG_MACF_MACH
376#define maclabel label->lh_label
377
378#define tasklabel_lock(task)	lh_lock((task)->label)
379#define tasklabel_unlock(task)	lh_unlock((task)->label)
380
381extern void tasklabel_lock2(task_t a, task_t b);
382extern void tasklabel_unlock2(task_t a, task_t b);
383#endif /* MAC_MACH */
384
385#define	itk_lock_init(task)	lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
386#define	itk_lock_destroy(task)	lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
387#define	itk_lock(task)		lck_mtx_lock(&(task)->itk_lock_data)
388#define	itk_unlock(task)	lck_mtx_unlock(&(task)->itk_lock_data)
389
390#define task_reference_internal(task)		\
391			(void)hw_atomic_add(&(task)->ref_count, 1)
392
393#define task_deallocate_internal(task)		\
394			hw_atomic_sub(&(task)->ref_count, 1)
395
396#define task_reference(task)					\
397MACRO_BEGIN										\
398	if ((task) != TASK_NULL)					\
399		task_reference_internal(task);			\
400MACRO_END
401
402extern kern_return_t	kernel_task_create(
403							task_t			task,
404							vm_offset_t		map_base,
405							vm_size_t		map_size,
406							task_t 			*child);
407
408/* Initialize task module */
409extern void		task_init(void) __attribute__((section("__TEXT, initcode")));
410
411#define	current_task_fast()	(current_thread()->task)
412#define current_task()		current_task_fast()
413
414extern lck_attr_t      task_lck_attr;
415extern lck_grp_t       task_lck_grp;
416
417#else	/* MACH_KERNEL_PRIVATE */
418
419__BEGIN_DECLS
420
421extern task_t	current_task(void);
422
423extern void		task_reference(task_t	task);
424
425__END_DECLS
426
427#endif	/* MACH_KERNEL_PRIVATE */
428
429__BEGIN_DECLS
430
431#ifdef	XNU_KERNEL_PRIVATE
432
433/* Hold all threads in a task */
434extern kern_return_t	task_hold(
435							task_t		task);
436
437/* Wait for task to stop running, either just to get off CPU or to cease being runnable */
438extern kern_return_t	task_wait(
439							task_t		task,
440							boolean_t 	until_not_runnable);
441
442/* Release hold on all threads in a task */
443extern kern_return_t	task_release(
444							task_t		task);
445
446/* Suspends a task by placing a hold on its threads */
447extern kern_return_t    task_pidsuspend(
448							task_t		task);
449extern kern_return_t    task_pidsuspend_locked(
450							task_t		task);
451
452/* Resumes a previously paused task */
453extern kern_return_t    task_pidresume(
454							task_t		task);
455
456#if CONFIG_FREEZE
457
458/* Freeze a task's resident pages */
459extern kern_return_t	task_freeze(
460							task_t		task,
461							uint32_t	*purgeable_count,
462							uint32_t	*wired_count,
463							uint32_t	*clean_count,
464							uint32_t	*dirty_count,
465							uint32_t	dirty_budget,
466							boolean_t	*shared,
467							boolean_t	walk_only);
468
469/* Thaw a currently frozen task */
470extern kern_return_t	task_thaw(
471							task_t		task);
472
473#endif /* CONFIG_FREEZE */
474
475/* Halt all other threads in the current task */
476extern kern_return_t	task_start_halt(
477							task_t		task);
478
479/* Wait for other threads to halt and free halting task resources */
480extern void		task_complete_halt(
481							task_t		task);
482
483extern kern_return_t	task_terminate_internal(
484							task_t			task);
485
486extern kern_return_t	task_create_internal(
487							task_t		parent_task,
488							boolean_t	inherit_memory,
489							boolean_t	is_64bit,
490							task_t		*child_task);	/* OUT */
491
492extern kern_return_t	task_importance(
493							task_t			task,
494							integer_t		importance);
495
496extern void		task_vtimer_set(
497					task_t		task,
498					integer_t	which);
499
500extern void		task_vtimer_clear(
501					task_t		task,
502					integer_t	which);
503
504extern void		task_vtimer_update(
505					task_t		task,
506					integer_t	which,
507					uint32_t	*microsecs);
508
509#define	TASK_VTIMER_USER		0x01
510#define	TASK_VTIMER_PROF		0x02
511#define	TASK_VTIMER_RLIM		0x04
512
513extern void		task_set_64bit(
514					task_t		task,
515					boolean_t	is64bit);
516
517extern void		task_backing_store_privileged(
518					task_t		task);
519
520extern void		task_set_dyld_info(
521    					task_t		task,
522					mach_vm_address_t addr,
523					mach_vm_size_t size);
524
525/* Get number of activations in a task */
526extern int		get_task_numacts(
527					task_t		task);
528
529extern int get_task_numactivethreads(task_t task);
530
531/* JMM - should just be temporary (implementation in bsd_kern still) */
532extern void	set_bsdtask_info(task_t,void *);
533extern vm_map_t get_task_map_reference(task_t);
534extern vm_map_t	swap_task_map(task_t, thread_t, vm_map_t, boolean_t);
535extern pmap_t	get_task_pmap(task_t);
536extern uint64_t	get_task_resident_size(task_t);
537
538extern boolean_t	is_kerneltask(task_t task);
539
540extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast);
541
542extern kern_return_t machine_task_get_state(
543					task_t task,
544					int flavor,
545					thread_state_t state,
546					mach_msg_type_number_t *state_count);
547
548extern kern_return_t machine_task_set_state(
549					task_t task,
550					int flavor,
551					thread_state_t state,
552					mach_msg_type_number_t state_count);
553
554extern void machine_task_terminate(task_t task);
555
556struct _task_ledger_indices {
557	int cpu_time;
558	int tkm_private;
559	int tkm_shared;
560	int phys_mem;
561	int wired_mem;
562	int platform_idle_wakeups;
563	int interrupt_wakeups;
564};
565extern struct _task_ledger_indices task_ledgers;
566
567int proc_get_task_bg_policy(task_t task);
568int proc_get_thread_bg_policy(task_t task, uint64_t tid);
569int proc_get_self_isbackground(void);
570int proc_get_selfthread_isbackground(void);
571
572int proc_get_darwinbgstate(task_t, uint32_t *);
573int proc_set_bgtaskpolicy(task_t task, int intval);
574int proc_set_and_apply_bgtaskpolicy(task_t task, int intval);
575int proc_set_bgthreadpolicy(task_t task, uint64_t tid, int val);
576int proc_set_and_apply_bgthreadpolicy(task_t task, uint64_t tid, int val);
577
578int proc_add_bgtaskpolicy(task_t task, int val);
579int proc_add_bgthreadpolicy(task_t task, uint64_t tid, int val);
580int proc_remove_bgtaskpolicy(task_t task, int policy);
581int proc_remove_bgthreadpolicy(task_t task, uint64_t tid, int val);
582
583int proc_apply_bgtaskpolicy(task_t task);
584int proc_apply_bgtaskpolicy_external(task_t task);
585int proc_apply_bgthreadpolicy(task_t task, uint64_t tid);
586int proc_apply_bgtask_selfpolicy(void);
587int proc_apply_bgthread_selfpolicy(void);
588int proc_apply_workq_bgthreadpolicy(thread_t);
589
590int proc_restore_bgtaskpolicy(task_t task);
591int proc_restore_bgthreadpolicy(task_t task, uint64_t tid);
592int proc_restore_bgthread_selfpolicy(void);
593int proc_restore_workq_bgthreadpolicy(thread_t);
594void proc_task_remove_throttle(task_t task);
595
596/* hw access routines */
597int proc_apply_task_diskacc(task_t task, int policy);
598int proc_apply_thread_diskacc(task_t task, uint64_t tid, int policy);
599int proc_apply_thread_selfdiskacc(int policy);
600int proc_get_task_disacc(task_t task);
601int proc_get_task_selfdiskacc(void);
602int proc_get_diskacc(thread_t thread);
603int proc_get_thread_selfdiskacc(void);
604int proc_denyinherit_policy(task_t task);
605int proc_denyselfset_policy(task_t task);
606
607int proc_get_task_selfgpuacc_deny(void);
608int proc_apply_task_gpuacc(task_t task, int prio);
609
610int proc_get_task_ruse_cpu(task_t task, uint32_t * policyp, uint32_t * percentagep, uint64_t * intervalp, uint64_t * deadlinep);
611int proc_set_task_ruse_cpu(task_t task, uint32_t policy, uint32_t percentage, uint64_t interval, uint64_t deadline);
612int proc_clear_task_ruse_cpu(task_t task);
613thread_t task_findtid(task_t, uint64_t);
614
615#define TASK_RUSECPU_FLAGS_PROC_LIMIT	0x1
616#define TASK_RUSECPU_FLAGS_PERTHR_LIMIT	0x2
617#define TASK_RUSECPU_FLAGS_DEADLINE		0x4
618
619#define PROC_POLICY_OSX_APPTYPE_NONE		0
620#if CONFIG_EMBEDDED
621#define PROC_POLICY_IOS_RESV1_APPTYPE		1
622#define PROC_POLICY_IOS_APPLE_DAEMON		2
623#define PROC_POLICY_IOS_APPTYPE			3
624#define PROC_POLICY_IOS_NONUITYPE		4
625#else
626#define PROC_POLICY_OSX_APPTYPE_TAL		1
627#define PROC_POLICY_OSX_APPTYPE_WIDGET		2
628#define PROC_POLICY_OSX_APPTYPE_DBCLIENT	2	/* Not a bug, just rename of widget */
629#endif
630
631void proc_set_task_apptype(task_t task, int type, thread_t thread);
632int proc_disable_task_apptype(task_t task, int policy_subtype);
633int proc_enable_task_apptype(task_t task, int policy_subtype);
634
635#if CONFIG_EMBEDDED
636extern int proc_setthread_saved_importance(thread_t thread, int importance);
637#endif
638
639/* BSD call back functions */
640extern int proc_apply_resource_actions(void * p, int type, int action);
641extern int proc_restore_resource_actions(void * p, int type, int action);
642extern int task_restore_resource_actions(task_t task, int type);
643
644extern void proc_apply_task_networkbg(void * bsd_info);
645extern void proc_restore_task_networkbg(void * bsd_info);
646extern void proc_set_task_networkbg(void * bsd_info, int setbg);
647extern int task_clear_cpuusage(task_t task);
648
649#if CONFIG_EMBEDDED
650#define TASK_APPSTATE_NONE              0
651#define TASK_APPSTATE_ACTIVE            1
652#define TASK_APPSTATE_BACKGROUND        2
653#define TASK_APPSTATE_NONUI             3
654#define TASK_APPSTATE_INACTIVE          4
655
656extern int proc_lf_getappstate(task_t task);
657extern int proc_lf_setappstate(task_t task, int state);
658extern int proc_lf_pidbind(task_t curtask, uint64_t tid, task_t target_task, int bind);
659extern void thead_remove_taskwatch(thread_t thread);
660extern void task_removewatchers(task_t task);
661#endif /* CONFIG_EMBEDDED */
662
663#endif	/* XNU_KERNEL_PRIVATE */
664
665#ifdef	KERNEL_PRIVATE
666
667extern void 	*get_bsdtask_info(task_t);
668extern void	*get_bsdthreadtask_info(thread_t);
669extern vm_map_t get_task_map(task_t);
670extern ledger_t	get_task_ledger(task_t);
671
672extern boolean_t get_task_pidsuspended(task_t);
673extern boolean_t get_task_frozen(task_t);
674
675/* Convert from a task to a port */
676extern ipc_port_t convert_task_to_port(task_t);
677
678/* Convert from a task name to a port */
679extern ipc_port_t convert_task_name_to_port(task_name_t);
680
681#endif	/* KERNEL_PRIVATE */
682
683extern task_t	kernel_task;
684
685extern void		task_deallocate(
686					task_t		task);
687
688extern void		task_name_deallocate(
689					task_name_t		task_name);
690__END_DECLS
691
692#endif	/* _KERN_TASK_H_ */
693