2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * @OSF_FREE_COPYRIGHT@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr.
62 * This file contains the structure definitions for tasks.
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
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.
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.
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.
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,
88 * Copyright (c) 2005 SPARTA, Inc.
94 #include <kern/kern_types.h>
95 #include <mach/mach_types.h>
96 #include <sys/cdefs.h>
98 #ifdef MACH_KERNEL_PRIVATE
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>
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 */
118 #ifdef XNU_KERNEL_PRIVATE
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
128 #define TASK_POLICY_RESOURCE_USAGE_COUNT 6
131 * Process Action and Policy bit definitions
133 The bit defns of the policy states
134 64 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 |----|-----|----|----|----|----|----|----|----|----|----|----|----|----|--------|
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
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
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
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
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
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
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
193 #endif /* XNU_KERNEL_PRIVATE */
195 #ifdef MACH_KERNEL_PRIVATE
197 typedef struct process_policy
{
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 */
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 */
217 typedef 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 */
225 extern lck_mtx_t task_watch_mtx
;
227 #endif /* CONFIG_EMBEDDED */
229 #include <kern/thread.h>
231 extern process_policy_t default_task_proc_policy
; /* init value for the process policy attributes */
232 extern process_policy_t default_task_null_policy
; /* none as the value for the process policy attributes */
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 */
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 */
246 /* Threads in this task */
247 queue_head_t threads
;
249 processor_set_t pset_hint
;
250 struct affinity_space
*affinity_space
;
253 uint32_t active_thread_count
;
254 int suspend_count
; /* Internal scheduling only */
256 /* User-visible scheduling information */
257 integer_t user_stop_count
; /* outstanding stops */
261 integer_t priority
; /* base priority for threads */
262 integer_t max_priority
; /* maximum priority for threads */
264 /* Task security and audit tokens */
265 security_token_t sec_token
;
266 audit_token_t audit_token
;
269 uint64_t total_user_time
; /* terminated threads only */
270 uint64_t total_system_time
;
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 */
290 struct ipc_space
*itk_space
;
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 */
300 unsigned int priv_flags
; /* privilege resource flags */
301 #define VM_BACKING_STORE_PRIV 0x1
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 */
316 zinfo_usage_t tkm_zinfo
; /* per-task, per-zone usage statistics */
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)
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 */
339 #define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */
340 uint32_t t_chud
; /* CHUD flags, used for Shark */
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
;
357 uint32_t appstate
; /* the current appstate */
358 queue_head_t task_watchers
; /* app state watcher threads */
359 int num_taskwatchers
;
361 #endif /* CONFIG_EMBEDDED */
363 vm_extmod_statistics_data_t extmod_statistics
;
364 natural_t proc_terminate
; /* the process is marked for proc_terminate */
367 #define task_lock(task) lck_mtx_lock(&(task)->lock)
368 #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
369 #define task_unlock(task) lck_mtx_unlock(&(task)->lock)
372 #define maclabel label->lh_label
374 #define tasklabel_lock(task) lh_lock((task)->label)
375 #define tasklabel_unlock(task) lh_unlock((task)->label)
377 extern void tasklabel_lock2(task_t a
, task_t b
);
378 extern void tasklabel_unlock2(task_t a
, task_t b
);
379 #endif /* MAC_MACH */
381 #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
382 #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
383 #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
384 #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
386 #define task_reference_internal(task) \
387 (void)hw_atomic_add(&(task)->ref_count, 1)
389 #define task_deallocate_internal(task) \
390 hw_atomic_sub(&(task)->ref_count, 1)
392 #define task_reference(task) \
394 if ((task) != TASK_NULL) \
395 task_reference_internal(task); \
398 extern kern_return_t
kernel_task_create(
400 vm_offset_t map_base
,
404 /* Initialize task module */
405 extern void task_init(void) __attribute__((section("__TEXT, initcode")));
407 #define current_task_fast() (current_thread()->task)
408 #define current_task() current_task_fast()
410 extern lck_attr_t task_lck_attr
;
411 extern lck_grp_t task_lck_grp
;
413 #else /* MACH_KERNEL_PRIVATE */
417 extern task_t
current_task(void);
419 extern void task_reference(task_t task
);
423 #endif /* MACH_KERNEL_PRIVATE */
427 #ifdef XNU_KERNEL_PRIVATE
429 /* Hold all threads in a task */
430 extern kern_return_t
task_hold(
433 /* Wait for task to stop running, either just to get off CPU or to cease being runnable */
434 extern kern_return_t
task_wait(
436 boolean_t until_not_runnable
);
438 /* Release hold on all threads in a task */
439 extern kern_return_t
task_release(
442 /* Suspends a task by placing a hold on its threads */
443 extern kern_return_t
task_pidsuspend(
445 extern kern_return_t
task_pidsuspend_locked(
448 /* Resumes a previously paused task */
449 extern kern_return_t
task_pidresume(
454 /* Freeze a task's resident pages */
455 extern kern_return_t
task_freeze(
457 uint32_t *purgeable_count
,
458 uint32_t *wired_count
,
459 uint32_t *clean_count
,
460 uint32_t *dirty_count
,
461 uint32_t dirty_budget
,
463 boolean_t walk_only
);
465 /* Thaw a currently frozen task */
466 extern kern_return_t
task_thaw(
469 #endif /* CONFIG_FREEZE */
471 /* Halt all other threads in the current task */
472 extern kern_return_t
task_start_halt(
475 /* Wait for other threads to halt and free halting task resources */
476 extern void task_complete_halt(
479 extern kern_return_t
task_terminate_internal(
482 extern kern_return_t
task_create_internal(
484 boolean_t inherit_memory
,
486 task_t
*child_task
); /* OUT */
488 extern kern_return_t
task_importance(
490 integer_t importance
);
492 extern void task_vtimer_set(
496 extern void task_vtimer_clear(
500 extern void task_vtimer_update(
503 uint32_t *microsecs
);
505 #define TASK_VTIMER_USER 0x01
506 #define TASK_VTIMER_PROF 0x02
507 #define TASK_VTIMER_RLIM 0x04
509 extern void task_set_64bit(
513 extern void task_backing_store_privileged(
516 extern void task_set_dyld_info(
518 mach_vm_address_t addr
,
519 mach_vm_size_t size
);
521 /* Get number of activations in a task */
522 extern int get_task_numacts(
525 extern int get_task_numactivethreads(task_t task
);
527 /* JMM - should just be temporary (implementation in bsd_kern still) */
528 extern void set_bsdtask_info(task_t
,void *);
529 extern vm_map_t
get_task_map_reference(task_t
);
530 extern vm_map_t
swap_task_map(task_t
, thread_t
, vm_map_t
, boolean_t
);
531 extern pmap_t
get_task_pmap(task_t
);
532 extern uint64_t get_task_resident_size(task_t
);
534 extern boolean_t
is_kerneltask(task_t task
);
536 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
538 extern kern_return_t
machine_task_get_state(
541 thread_state_t state
,
542 mach_msg_type_number_t
*state_count
);
544 extern kern_return_t
machine_task_set_state(
547 thread_state_t state
,
548 mach_msg_type_number_t state_count
);
550 extern void machine_task_terminate(task_t task
);
552 struct _task_ledger_indices
{
559 extern struct _task_ledger_indices task_ledgers
;
561 int proc_get_task_bg_policy(task_t task
);
562 int proc_get_thread_bg_policy(task_t task
, uint64_t tid
);
563 int proc_get_self_isbackground(void);
564 int proc_get_selfthread_isbackground(void);
566 int proc_get_darwinbgstate(task_t
, uint32_t *);
567 int proc_set_bgtaskpolicy(task_t task
, int intval
);
568 int proc_set_and_apply_bgtaskpolicy(task_t task
, int intval
);
569 int proc_set_bgthreadpolicy(task_t task
, uint64_t tid
, int val
);
570 int proc_set_and_apply_bgthreadpolicy(task_t task
, uint64_t tid
, int val
);
572 int proc_add_bgtaskpolicy(task_t task
, int val
);
573 int proc_add_bgthreadpolicy(task_t task
, uint64_t tid
, int val
);
574 int proc_remove_bgtaskpolicy(task_t task
, int policy
);
575 int proc_remove_bgthreadpolicy(task_t task
, uint64_t tid
, int val
);
577 int proc_apply_bgtaskpolicy(task_t task
);
578 int proc_apply_bgtaskpolicy_external(task_t task
);
579 int proc_apply_bgthreadpolicy(task_t task
, uint64_t tid
);
580 int proc_apply_bgtask_selfpolicy(void);
581 int proc_apply_bgthread_selfpolicy(void);
582 int proc_apply_workq_bgthreadpolicy(thread_t
);
584 int proc_restore_bgtaskpolicy(task_t task
);
585 int proc_restore_bgthreadpolicy(task_t task
, uint64_t tid
);
586 int proc_restore_bgthread_selfpolicy(void);
587 int proc_restore_workq_bgthreadpolicy(thread_t
);
588 void proc_task_remove_throttle(task_t task
);
590 /* hw access routines */
591 int proc_apply_task_diskacc(task_t task
, int policy
);
592 int proc_apply_thread_diskacc(task_t task
, uint64_t tid
, int policy
);
593 int proc_apply_thread_selfdiskacc(int policy
);
594 int proc_get_task_disacc(task_t task
);
595 int proc_get_task_selfdiskacc(void);
596 int proc_get_diskacc(thread_t thread
);
597 int proc_get_thread_selfdiskacc(void);
598 int proc_denyinherit_policy(task_t task
);
599 int proc_denyselfset_policy(task_t task
);
601 int proc_get_task_selfgpuacc_deny(void);
602 int proc_apply_task_gpuacc(task_t task
, int prio
);
604 int proc_get_task_ruse_cpu(task_t task
, uint32_t * policyp
, uint32_t * percentagep
, uint64_t * intervalp
, uint64_t * deadlinep
);
605 int proc_set_task_ruse_cpu(task_t task
, uint32_t policy
, uint32_t percentage
, uint64_t interval
, uint64_t deadline
);
606 int proc_clear_task_ruse_cpu(task_t task
);
607 thread_t
task_findtid(task_t
, uint64_t);
609 #define TASK_RUSECPU_FLAGS_PROC_LIMIT 0x1
610 #define TASK_RUSECPU_FLAGS_PERTHR_LIMIT 0x2
611 #define TASK_RUSECPU_FLAGS_DEADLINE 0x4
613 #define PROC_POLICY_OSX_APPTYPE_NONE 0
615 #define PROC_POLICY_IOS_RESV1_APPTYPE 1
616 #define PROC_POLICY_IOS_APPLE_DAEMON 2
617 #define PROC_POLICY_IOS_APPTYPE 3
618 #define PROC_POLICY_IOS_NONUITYPE 4
620 #define PROC_POLICY_OSX_APPTYPE_TAL 1
621 #define PROC_POLICY_OSX_APPTYPE_WIDGET 2
622 #define PROC_POLICY_OSX_APPTYPE_DBCLIENT 2 /* Not a bug, just rename of widget */
625 void proc_set_task_apptype(task_t task
, int type
, thread_t thread
);
626 int proc_disable_task_apptype(task_t task
, int policy_subtype
);
627 int proc_enable_task_apptype(task_t task
, int policy_subtype
);
630 extern int proc_setthread_saved_importance(thread_t thread
, int importance
);
633 /* BSD call back functions */
634 extern int proc_apply_resource_actions(void * p
, int type
, int action
);
635 extern int proc_restore_resource_actions(void * p
, int type
, int action
);
636 extern int task_restore_resource_actions(task_t task
, int type
);
638 extern void proc_apply_task_networkbg(void * bsd_info
);
639 extern void proc_restore_task_networkbg(void * bsd_info
);
640 extern void proc_set_task_networkbg(void * bsd_info
, int setbg
);
641 extern int task_clear_cpuusage(task_t task
);
644 #define TASK_APPSTATE_NONE 0
645 #define TASK_APPSTATE_ACTIVE 1
646 #define TASK_APPSTATE_BACKGROUND 2
647 #define TASK_APPSTATE_NONUI 3
648 #define TASK_APPSTATE_INACTIVE 4
650 extern int proc_lf_getappstate(task_t task
);
651 extern int proc_lf_setappstate(task_t task
, int state
);
652 extern int proc_lf_pidbind(task_t curtask
, uint64_t tid
, task_t target_task
, int bind
);
653 extern void thead_remove_taskwatch(thread_t thread
);
654 extern void task_removewatchers(task_t task
);
655 #endif /* CONFIG_EMBEDDED */
657 #endif /* XNU_KERNEL_PRIVATE */
659 #ifdef KERNEL_PRIVATE
661 extern void *get_bsdtask_info(task_t
);
662 extern void *get_bsdthreadtask_info(thread_t
);
663 extern vm_map_t
get_task_map(task_t
);
664 extern ledger_t
get_task_ledger(task_t
);
666 extern boolean_t
get_task_pidsuspended(task_t
);
667 extern boolean_t
get_task_frozen(task_t
);
669 /* Convert from a task to a port */
670 extern ipc_port_t
convert_task_to_port(task_t
);
672 /* Convert from a task name to a port */
673 extern ipc_port_t
convert_task_name_to_port(task_name_t
);
675 #endif /* KERNEL_PRIVATE */
677 extern task_t kernel_task
;
679 extern void task_deallocate(
682 extern void task_name_deallocate(
683 task_name_t task_name
);
686 #endif /* _KERN_TASK_H_ */