]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/task.h
xnu-2050.7.9.tar.gz
[apple/xnu.git] / osfmk / kern / task.h
CommitLineData
1c79356b 1/*
316670eb 2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_FREE_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 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 */
2d21ac55
A
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 */
1c79356b
A
90
91#ifndef _KERN_TASK_H_
92#define _KERN_TASK_H_
93
94#include <kern/kern_types.h>
95#include <mach/mach_types.h>
91447636 96#include <sys/cdefs.h>
9bccf70c
A
97
98#ifdef MACH_KERNEL_PRIVATE
99
1c79356b
A
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>
6d2010ae 107#include <mach/vm_statistics.h>
0c530ab8 108#include <machine/task.h>
91447636
A
109
110#include <kern/cpu_data.h>
1c79356b
A
111#include <kern/queue.h>
112#include <kern/exception.h>
113#include <kern/lock.h>
2d21ac55
A
114#include <security/_label.h>
115#include <ipc/ipc_labelh.h>
6d2010ae
A
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
316670eb 158#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS 0x01
6d2010ae
A
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
316670eb
A
162#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_UTILITY 0x04
163#define TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_DEFAULT TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS
6d2010ae 164
316670eb 165/* Hardware GPU access attributes */
6d2010ae 166#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NONE 0x00
6d2010ae
A
167#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_FULLACCESS 0x00
168#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS 0x01
316670eb 169#define TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_FULLACCESS
6d2010ae
A
170
171/* Hardware Network access attributes */
172#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_NONE 0x00
316670eb 173#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_FULLACCESS 0x00
6d2010ae 174#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_THROTTLE 0x01
316670eb 175#define TASK_POLICY_HWACCESS_NET_ATTRIBUTE_DEFAULT TASK_POLICY_HWACCESS_NET_ATTRIBUTE_FULLACCESS
6d2010ae
A
176
177/* Hardware CPU access attributes */
178#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_NONE 0x00
316670eb 179#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_FULLACCESS 0x00
6d2010ae
A
180#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_ONE 0x01
181#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_LLCACHE 0x02
316670eb 182#define TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_DEFAULT TASK_POLICY_HWACCESS_CPU_ATTRIBUTE_FULLACCESS
6d2010ae
A
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
316670eb
A
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
6d2010ae
A
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
316670eb
A
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
6d2010ae
A
229#include <kern/thread.h>
230
231extern process_policy_t default_task_proc_policy; /* init value for the process policy attributes */
316670eb 232extern process_policy_t default_task_null_policy; /* none as the value for the process policy attributes */
1c79356b 233
91447636 234struct task {
1c79356b 235 /* Synchronization/destruction information */
b0d623f7 236 decl_lck_mtx_data(,lock) /* Task's lock */
2d21ac55 237 uint32_t ref_count; /* Number of references to me */
1c79356b 238 boolean_t active; /* Task has not been terminated */
b0d623f7 239 boolean_t halting; /* Task is being halted */
1c79356b
A
240
241 /* Miscellaneous */
242 vm_map_t map; /* Address space description */
2d21ac55 243 queue_chain_t tasks; /* global list of tasks */
1c79356b 244 void *user_data; /* Arbitrary data settable via IPC */
1c79356b 245
55e303ae 246 /* Threads in this task */
2d21ac55 247 queue_head_t threads;
b0d623f7
A
248
249 processor_set_t pset_hint;
250 struct affinity_space *affinity_space;
251
2d21ac55
A
252 int thread_count;
253 uint32_t active_thread_count;
b0d623f7 254 int suspend_count; /* Internal scheduling only */
1c79356b
A
255
256 /* User-visible scheduling information */
257 integer_t user_stop_count; /* outstanding stops */
258
0b4e3aa0 259 task_role_t role;
1c79356b 260
0b4e3aa0
A
261 integer_t priority; /* base priority for threads */
262 integer_t max_priority; /* maximum priority for threads */
1c79356b 263
55e303ae 264 /* Task security and audit tokens */
1c79356b 265 security_token_t sec_token;
55e303ae 266 audit_token_t audit_token;
1c79356b
A
267
268 /* Statistics */
91447636
A
269 uint64_t total_user_time; /* terminated threads only */
270 uint64_t total_system_time;
1c79356b 271
2d21ac55
A
272 /* Virtual timers */
273 uint32_t vtimers;
1c79356b
A
274
275 /* IPC structures */
b0d623f7 276 decl_lck_mtx_data(,itk_lock_data)
1c79356b 277 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
0c530ab8 278 struct ipc_port *itk_nself; /* not a right, doesn't hold ref */
1c79356b
A
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 */
2d21ac55
A
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 */
1c79356b
A
287 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
288 /* all send rights */
289
290 struct ipc_space *itk_space;
291
1c79356b
A
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
316670eb
A
298 ledger_t ledger;
299
91447636
A
300 unsigned int priv_flags; /* privilege resource flags */
301#define VM_BACKING_STORE_PRIV 0x1
0c530ab8
A
302
303 MACHINE_TASK
1c79356b 304
1c79356b
A
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 */
316670eb
A
312 uint32_t c_switch; /* total context switches */
313 uint32_t p_switch; /* total processor switches */
314 uint32_t ps_switch; /* total pset switches */
6d2010ae 315
6d2010ae
A
316 zinfo_usage_t tkm_zinfo; /* per-task, per-zone usage statistics */
317
1c79356b
A
318#ifdef MACH_BSD
319 void *bsd_info;
320#endif
2d21ac55 321 struct vm_shared_region *shared_region;
55e303ae
A
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 */
91447636
A
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
b0d623f7
A
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 */
2d21ac55
A
334#if CONFIG_MACF_MACH
335 ipc_labelh_t label;
336#endif
337
b0d623f7
A
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
316670eb
A
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 */
6d2010ae 346 process_policy_t ext_policystate; /* externally defined process policy states*/
316670eb 347 process_policy_t appliedstate; /* self applied acions */
6d2010ae 348 process_policy_t policystate; /* process wide policy states */
316670eb
A
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 */
6d2010ae
A
362
363 vm_extmod_statistics_data_t extmod_statistics;
316670eb 364 natural_t proc_terminate; /* the process is marked for proc_terminate */
91447636 365};
1c79356b 366
b0d623f7
A
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)
1c79356b 370
2d21ac55
A
371#if CONFIG_MACF_MACH
372#define maclabel label->lh_label
373
374#define tasklabel_lock(task) lh_lock((task)->label)
375#define tasklabel_unlock(task) lh_unlock((task)->label)
376
377extern void tasklabel_lock2(task_t a, task_t b);
378extern void tasklabel_unlock2(task_t a, task_t b);
379#endif /* MAC_MACH */
380
b0d623f7
A
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)
1c79356b 385
91447636 386#define task_reference_internal(task) \
2d21ac55 387 (void)hw_atomic_add(&(task)->ref_count, 1)
9bccf70c 388
91447636
A
389#define task_deallocate_internal(task) \
390 hw_atomic_sub(&(task)->ref_count, 1)
55e303ae 391
91447636
A
392#define task_reference(task) \
393MACRO_BEGIN \
394 if ((task) != TASK_NULL) \
395 task_reference_internal(task); \
396MACRO_END
1c79356b 397
91447636
A
398extern kern_return_t kernel_task_create(
399 task_t task,
400 vm_offset_t map_base,
401 vm_size_t map_size,
402 task_t *child);
55e303ae 403
1c79356b 404/* Initialize task module */
2d21ac55 405extern void task_init(void) __attribute__((section("__TEXT, initcode")));
1c79356b 406
91447636
A
407#define current_task_fast() (current_thread()->task)
408#define current_task() current_task_fast()
1c79356b 409
b0d623f7
A
410extern lck_attr_t task_lck_attr;
411extern lck_grp_t task_lck_grp;
412
91447636 413#else /* MACH_KERNEL_PRIVATE */
1c79356b 414
91447636
A
415__BEGIN_DECLS
416
417extern task_t current_task(void);
418
419extern void task_reference(task_t task);
420
421__END_DECLS
1c79356b 422
9bccf70c 423#endif /* MACH_KERNEL_PRIVATE */
1c79356b 424
91447636 425__BEGIN_DECLS
1c79356b 426
91447636
A
427#ifdef XNU_KERNEL_PRIVATE
428
429/* Hold all threads in a task */
1c79356b 430extern kern_return_t task_hold(
91447636 431 task_t task);
1c79356b 432
316670eb
A
433/* Wait for task to stop running, either just to get off CPU or to cease being runnable */
434extern kern_return_t task_wait(
435 task_t task,
436 boolean_t until_not_runnable);
437
91447636 438/* Release hold on all threads in a task */
1c79356b 439extern kern_return_t task_release(
91447636 440 task_t task);
1c79356b 441
316670eb
A
442/* Suspends a task by placing a hold on its threads */
443extern kern_return_t task_pidsuspend(
444 task_t task);
445extern kern_return_t task_pidsuspend_locked(
446 task_t task);
447
448/* Resumes a previously paused task */
449extern kern_return_t task_pidresume(
450 task_t task);
451
6d2010ae
A
452#if CONFIG_FREEZE
453
454/* Freeze a task's resident pages */
455extern kern_return_t task_freeze(
456 task_t task,
457 uint32_t *purgeable_count,
458 uint32_t *wired_count,
459 uint32_t *clean_count,
460 uint32_t *dirty_count,
316670eb 461 uint32_t dirty_budget,
6d2010ae
A
462 boolean_t *shared,
463 boolean_t walk_only);
464
465/* Thaw a currently frozen task */
466extern kern_return_t task_thaw(
467 task_t task);
468
469#endif /* CONFIG_FREEZE */
470
91447636 471/* Halt all other threads in the current task */
b0d623f7
A
472extern kern_return_t task_start_halt(
473 task_t task);
474
475/* Wait for other threads to halt and free halting task resources */
476extern void task_complete_halt(
91447636
A
477 task_t task);
478
479extern kern_return_t task_terminate_internal(
480 task_t task);
481
482extern kern_return_t task_create_internal(
483 task_t parent_task,
484 boolean_t inherit_memory,
0c530ab8 485 boolean_t is_64bit,
91447636 486 task_t *child_task); /* OUT */
1c79356b 487
0b4e3aa0
A
488extern kern_return_t task_importance(
489 task_t task,
490 integer_t importance);
91447636 491
2d21ac55
A
492extern void task_vtimer_set(
493 task_t task,
494 integer_t which);
495
496extern void task_vtimer_clear(
497 task_t task,
498 integer_t which);
499
500extern void task_vtimer_update(
501 task_t task,
502 integer_t which,
503 uint32_t *microsecs);
504
505#define TASK_VTIMER_USER 0x01
506#define TASK_VTIMER_PROF 0x02
507#define TASK_VTIMER_RLIM 0x04
508
91447636
A
509extern void task_set_64bit(
510 task_t task,
511 boolean_t is64bit);
512
513extern void task_backing_store_privileged(
514 task_t task);
515
b0d623f7
A
516extern void task_set_dyld_info(
517 task_t task,
518 mach_vm_address_t addr,
519 mach_vm_size_t size);
520
91447636
A
521/* Get number of activations in a task */
522extern int get_task_numacts(
523 task_t task);
524
b0d623f7 525extern int get_task_numactivethreads(task_t task);
0b4e3aa0 526
1c79356b 527/* JMM - should just be temporary (implementation in bsd_kern still) */
1c79356b 528extern void set_bsdtask_info(task_t,void *);
91447636 529extern vm_map_t get_task_map_reference(task_t);
6d2010ae 530extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t, boolean_t);
1c79356b 531extern pmap_t get_task_pmap(task_t);
b0d623f7 532extern uint64_t get_task_resident_size(task_t);
9bccf70c 533
91447636 534extern boolean_t is_kerneltask(task_t task);
9bccf70c 535
2d21ac55
A
536extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast);
537
b0d623f7
A
538extern kern_return_t machine_task_get_state(
539 task_t task,
540 int flavor,
541 thread_state_t state,
542 mach_msg_type_number_t *state_count);
543
544extern kern_return_t machine_task_set_state(
545 task_t task,
546 int flavor,
547 thread_state_t state,
548 mach_msg_type_number_t state_count);
549
316670eb
A
550extern void machine_task_terminate(task_t task);
551
552struct _task_ledger_indices {
553 int cpu_time;
554 int tkm_private;
555 int tkm_shared;
556 int phys_mem;
557 int wired_mem;
558};
559extern struct _task_ledger_indices task_ledgers;
b0d623f7 560
6d2010ae
A
561int proc_get_task_bg_policy(task_t task);
562int proc_get_thread_bg_policy(task_t task, uint64_t tid);
563int proc_get_self_isbackground(void);
564int proc_get_selfthread_isbackground(void);
565
566int proc_get_darwinbgstate(task_t, uint32_t *);
567int proc_set_bgtaskpolicy(task_t task, int intval);
316670eb 568int proc_set_and_apply_bgtaskpolicy(task_t task, int intval);
6d2010ae 569int proc_set_bgthreadpolicy(task_t task, uint64_t tid, int val);
316670eb 570int proc_set_and_apply_bgthreadpolicy(task_t task, uint64_t tid, int val);
6d2010ae
A
571
572int proc_add_bgtaskpolicy(task_t task, int val);
573int proc_add_bgthreadpolicy(task_t task, uint64_t tid, int val);
574int proc_remove_bgtaskpolicy(task_t task, int policy);
575int proc_remove_bgthreadpolicy(task_t task, uint64_t tid, int val);
576
577int proc_apply_bgtaskpolicy(task_t task);
578int proc_apply_bgtaskpolicy_external(task_t task);
6d2010ae
A
579int proc_apply_bgthreadpolicy(task_t task, uint64_t tid);
580int proc_apply_bgtask_selfpolicy(void);
581int proc_apply_bgthread_selfpolicy(void);
582int proc_apply_workq_bgthreadpolicy(thread_t);
583
584int proc_restore_bgtaskpolicy(task_t task);
585int proc_restore_bgthreadpolicy(task_t task, uint64_t tid);
586int proc_restore_bgthread_selfpolicy(void);
587int proc_restore_workq_bgthreadpolicy(thread_t);
316670eb 588void proc_task_remove_throttle(task_t task);
6d2010ae
A
589
590/* hw access routines */
591int proc_apply_task_diskacc(task_t task, int policy);
592int proc_apply_thread_diskacc(task_t task, uint64_t tid, int policy);
593int proc_apply_thread_selfdiskacc(int policy);
594int proc_get_task_disacc(task_t task);
595int proc_get_task_selfdiskacc(void);
316670eb 596int proc_get_diskacc(thread_t thread);
6d2010ae
A
597int proc_get_thread_selfdiskacc(void);
598int proc_denyinherit_policy(task_t task);
599int proc_denyselfset_policy(task_t task);
600
601int proc_get_task_selfgpuacc_deny(void);
602int proc_apply_task_gpuacc(task_t task, int prio);
603
604int proc_get_task_ruse_cpu(task_t task, uint32_t * policyp, uint32_t * percentagep, uint64_t * intervalp, uint64_t * deadlinep);
605int proc_set_task_ruse_cpu(task_t task, uint32_t policy, uint32_t percentage, uint64_t interval, uint64_t deadline);
316670eb 606int proc_clear_task_ruse_cpu(task_t task);
6d2010ae
A
607thread_t task_findtid(task_t, uint64_t);
608
316670eb
A
609#define TASK_RUSECPU_FLAGS_PROC_LIMIT 0x1
610#define TASK_RUSECPU_FLAGS_PERTHR_LIMIT 0x2
611#define TASK_RUSECPU_FLAGS_DEADLINE 0x4
612
6d2010ae 613#define PROC_POLICY_OSX_APPTYPE_NONE 0
316670eb
A
614#if CONFIG_EMBEDDED
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
619#else
6d2010ae
A
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 */
316670eb 623#endif
6d2010ae 624
316670eb 625void proc_set_task_apptype(task_t task, int type, thread_t thread);
6d2010ae
A
626int proc_disable_task_apptype(task_t task, int policy_subtype);
627int proc_enable_task_apptype(task_t task, int policy_subtype);
628
316670eb
A
629#if CONFIG_EMBEDDED
630extern int proc_setthread_saved_importance(thread_t thread, int importance);
631#endif
6d2010ae
A
632
633/* BSD call back functions */
634extern int proc_apply_resource_actions(void * p, int type, int action);
635extern int proc_restore_resource_actions(void * p, int type, int action);
636extern int task_restore_resource_actions(task_t task, int type);
637
638extern void proc_apply_task_networkbg(void * bsd_info);
639extern void proc_restore_task_networkbg(void * bsd_info);
640extern void proc_set_task_networkbg(void * bsd_info, int setbg);
316670eb
A
641extern int task_clear_cpuusage(task_t task);
642
643#if CONFIG_EMBEDDED
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
649
650extern int proc_lf_getappstate(task_t task);
651extern int proc_lf_setappstate(task_t task, int state);
652extern int proc_lf_pidbind(task_t curtask, uint64_t tid, task_t target_task, int bind);
653extern void thead_remove_taskwatch(thread_t thread);
654extern void task_removewatchers(task_t task);
655#endif /* CONFIG_EMBEDDED */
656
91447636 657#endif /* XNU_KERNEL_PRIVATE */
9bccf70c 658
91447636 659#ifdef KERNEL_PRIVATE
9bccf70c 660
91447636 661extern void *get_bsdtask_info(task_t);
2d21ac55 662extern void *get_bsdthreadtask_info(thread_t);
91447636 663extern vm_map_t get_task_map(task_t);
316670eb
A
664extern ledger_t get_task_ledger(task_t);
665
666extern boolean_t get_task_pidsuspended(task_t);
667extern boolean_t get_task_frozen(task_t);
668
669/* Convert from a task to a port */
670extern ipc_port_t convert_task_to_port(task_t);
671
672/* Convert from a task name to a port */
673extern ipc_port_t convert_task_name_to_port(task_name_t);
9bccf70c 674
91447636 675#endif /* KERNEL_PRIVATE */
9bccf70c 676
91447636
A
677extern task_t kernel_task;
678
679extern void task_deallocate(
680 task_t task);
9bccf70c 681
0c530ab8
A
682extern void task_name_deallocate(
683 task_name_t task_name);
91447636 684__END_DECLS
9bccf70c 685
1c79356b 686#endif /* _KERN_TASK_H_ */