Lines Matching defs:task
33 #include <kern/task.h>
53 static int task_get_cpuusage(task_t task, uint32_t * percentagep, uint64_t * intervalp, uint64_t * deadlinep);
54 int task_set_cpuusage(task_t task, uint64_t percentage, uint64_t interval, uint64_t deadline, int scope);
55 static int task_clear_cpuusage_locked(task_t task);
56 static int task_apply_resource_actions(task_t task, int type);
57 static void task_priority(task_t task, integer_t priority, integer_t max_priority);
58 static kern_return_t task_role_default_handler(task_t task, task_role_t role);
62 static int proc_get_task_selfdiskacc_internal(task_t task, thread_t thread);
68 static void add_taskwatch_locked(task_t task, task_watch_t * twp);
69 static void remove_taskwatch_locked(task_t task, task_watch_t * twp);
72 static void apply_appstate_watchers(task_t task, int setbg);
122 * This routine should always be called with the task lock held.
124 * and TASK_BACKGROUND_APPLICATION of task with no special app type.
127 task_role_default_handler(task_t task, task_role_t role)
131 switch (task->role) {
136 if ((task->ext_appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) &&
137 (task->appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE)) {
138 task_priority(task,
141 task->max_priority);
143 task->role = role;
161 task_t task,
170 if (task == TASK_NULL || task == kernel_task)
183 if ((current_task() == task) && (info != NULL) &&
188 task_lock(task);
191 if (task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_NONE) {
192 result = task_role_default_handler(task, info->role);
194 switch (task->ext_appliedstate.apptype) {
198 proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_FOREGROUND);
199 bsdinfo = task->bsd_info;
205 task->ext_appliedstate.apptype = PROC_POLICY_OSX_APPTYPE_NONE;
207 proc_restore_bgtaskpolicy_internal(task, 1, 0, BASEPRI_FOREGROUND);
208 bsdinfo = task->bsd_info;
215 task_priority(task, BASEPRI_FOREGROUND, task->max_priority);
218 } /* switch (task->ext_appliedstate.apptype) */
219 task->role = TASK_FOREGROUND_APPLICATION;
225 if (task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_NONE) {
226 result = task_role_default_handler(task, info->role);
228 switch (task->ext_appliedstate.apptype) {
232 if (task->ext_appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) {
233 proc_apply_bgtaskpolicy_internal(task, 1, 1);
234 bsdinfo = task->bsd_info;
240 task_priority(task, BASEPRI_BACKGROUND, task->max_priority);
242 } /* switch (task->ext_appliedstate.apptype) */
243 task->role = TASK_BACKGROUND_APPLICATION;
249 if (task != current_task()||
250 task->sec_token.val[0] != 0)
253 task_priority(task, BASEPRI_CONTROL, task->max_priority);
254 task->role = info->role;
259 if (task != current_task() ||
260 task->sec_token.val[0] != 0)
263 task_priority(task, MAXPRI_RESERVED - 3, MAXPRI_RESERVED);
264 task->role = info->role;
268 task_priority(task, BASEPRI_DEFAULT, MAXPRI_USER);
269 task->role = info->role;
277 task_unlock(task);
296 task_t task,
302 task->max_priority = max_priority;
304 if (priority > task->max_priority)
305 priority = task->max_priority;
310 task->priority = priority;
312 queue_iterate(&task->threads, thread, thread_t, task_threads) {
324 task_t task,
327 if (task == TASK_NULL || task == kernel_task)
330 task_lock(task);
332 if (!task->active) {
333 task_unlock(task);
338 if (task->role >= TASK_CONTROL_APPLICATION) {
339 task_unlock(task);
344 task_priority(task, importance + BASEPRI_DEFAULT, task->max_priority);
345 task->role = TASK_RENICED;
347 task_unlock(task);
354 task_t task,
360 if (task == TASK_NULL || task == kernel_task)
375 task_lock(task);
376 info->role = task->role;
377 task_unlock(task);
389 /* task Darwin BG enforcement/settings related routines */
391 proc_get_task_bg_policy(task_t task)
397 if (current_task() == task)
401 val = task->ext_policystate.hw_bg;
403 val = task->policystate.hw_bg;
411 proc_get_thread_bg_policy(task_t task, uint64_t tid)
422 task_lock(task);
423 thread = task_findtid(task, tid);
426 task_unlock(task);
437 task_t task = current_task();;
440 if ((task->ext_appliedstate.hw_bg != TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) ||
441 (task->appliedstate.hw_bg != TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) ||
463 proc_set_bgtaskpolicy(task_t task, int intval)
468 if (current_task() == task)
471 task_lock(task);
475 if (task->ext_policystate.hw_bg != intval)
476 task->ext_policystate.hw_bg = intval;
478 if (task->policystate.hw_bg != intval)
479 task->policystate.hw_bg = intval;
482 task_unlock(task);
486 /* set and apply as well , handles reset of NONUI due to setprio() task app state implmn side effect */
488 proc_set_and_apply_bgtaskpolicy(task_t task, int prio)
493 error = proc_set_bgtaskpolicy(task, TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL);
495 error = proc_apply_bgtaskpolicy(task);
498 apply_appstate_watchers(task, 1);
502 error = proc_restore_bgtaskpolicy(task);
505 error = proc_apply_task_gpuacc(task, TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT);
508 apply_appstate_watchers(task, 0);
519 proc_set_bgthreadpolicy(task_t task, uint64_t tid, int prio)
531 task_lock(task);
533 thread = task_findtid(task, tid);
540 task_unlock(task);
546 proc_set_and_apply_bgthreadpolicy(task_t task, uint64_t tid, int prio)
551 error = proc_set_bgthreadpolicy(task, tid, TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL);
553 error = proc_apply_bgthreadpolicy(task, tid);
555 error = proc_restore_bgthreadpolicy(task, tid);
562 proc_add_bgtaskpolicy(task_t task, int val)
566 if (current_task() == task)
569 task_lock(task);
572 task->policystate.hw_bg |= val;
574 task->ext_policystate.hw_bg |= val;
577 task_unlock(task);
582 proc_add_bgthreadpolicy(task_t task, uint64_t tid, int val)
594 task_lock(task);
596 thread = task_findtid(task, tid);
603 task_unlock(task);
609 proc_remove_bgtaskpolicy(task_t task, int intval)
613 if (current_task() == task)
616 task_lock(task);
619 task->policystate.hw_bg &= ~intval;
621 task->ext_policystate.hw_bg &= ~intval;
624 task_unlock(task);
629 proc_remove_bgthreadpolicy(task_t task, uint64_t tid, int val)
641 task_lock(task);
643 thread = task_findtid(task, tid);
650 task_unlock(task);
662 proc_apply_bgtaskpolicy(task_t task)
666 if (task == current_task())
668 return(proc_apply_bgtaskpolicy_internal(task, 0, external));
672 proc_apply_bgtaskpolicy_external(task_t task)
674 return(proc_apply_bgtaskpolicy_internal(task, 0, 1));
678 proc_apply_bgtaskpolicy_internal(task_t task, int locked, int external)
682 task_lock(task);
685 if (task->proc_terminate != 0)
690 if (task->ext_appliedstate.hw_bg != task->ext_policystate.hw_bg) {
691 task->ext_appliedstate.hw_bg = task->ext_policystate.hw_bg;
692 task_priority(task, MAXPRI_THROTTLE, MAXPRI_THROTTLE);
696 if (task->appliedstate.hw_bg != task->policystate.hw_bg) {
697 task->appliedstate.hw_bg = task->policystate.hw_bg;
698 task_priority(task, MAXPRI_THROTTLE, MAXPRI_THROTTLE);
703 task_unlock(task);
715 wqtask = thread->task;
727 proc_apply_bgthreadpolicy(task_t task, uint64_t tid)
738 localtask = task;
763 if (thread->task->proc_terminate != 0)
785 if (thread->task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) {
813 if (thread->task->proc_terminate != 0)
844 proc_restore_bgtaskpolicy(task_t task)
848 if (current_task() == task)
850 return(proc_restore_bgtaskpolicy_internal(task, 0, external, BASEPRI_DEFAULT));
854 proc_restore_bgtaskpolicy_internal(task_t task, int locked, int external, int pri)
857 task_lock(task);
860 if (task->proc_terminate != 0)
864 task->ext_appliedstate.hw_bg = TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE;
866 if (task->appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) {
867 task_priority(task, pri, MAXPRI_USER);
869 task->role = TASK_DEFAULT_APPLICATION;
873 task->appliedstate.hw_bg = TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE;
875 if (task->ext_appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_NONE) {
876 task_priority(task, pri, MAXPRI_USER);
878 task->role = TASK_DEFAULT_APPLICATION;
884 task_unlock(task);
898 wqtask = thread->task;
902 if (thread->task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) {
923 proc_restore_bgthreadpolicy(task_t task, uint64_t tid)
934 task_lock(task);
936 thread = task_findtid(task, tid);
943 if (thread->task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) {
951 task_unlock(task);
967 if (thread->task->proc_terminate != 0)
995 proc_set_task_apptype(task_t task, int type, thread_t thread)
997 proc_set_task_apptype(task_t task, int type, __unused thread_t thread)
1007 task->ext_policystate.apptype = type;
1008 task->policystate.apptype = type;
1009 proc_apply_bgtaskpolicy_external(task);
1011 task->ext_appliedstate.apptype = type;
1015 task->ext_policystate.apptype = type;
1016 task->policystate.apptype = type;
1017 task->ext_appliedstate.apptype = type;
1025 task_lock(th->task);
1027 task_unlock(th->task);
1032 task->ext_policystate.apptype = type;
1033 task->policystate.apptype = type;
1036 task->ext_policystate.apptype = type;
1037 task->policystate.apptype = type;
1039 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1040 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1044 task->ext_policystate.apptype = type;
1045 task->policystate.apptype = type;
1046 proc_apply_bgtaskpolicy_external(task);
1048 task->ext_appliedstate.apptype = type;
1052 task->ext_policystate.apptype = type;
1053 task->policystate.apptype = type;
1054 proc_apply_bgtaskpolicy_internal(task, 0, 0);
1070 proc_get_darwinbgstate(task_t task, uint32_t * flagsp)
1072 if (task->ext_appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL){
1075 if (task->appliedstate.hw_bg == TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL){
1079 if (task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) {
1093 proc_get_task_disacc(task_t task)
1096 if ((task->ext_appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0)
1099 if ((task->ext_appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0) {
1101 if ((task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_TAL) || (task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_DBCLIENT)) {
1103 if ((task->ext_appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_THROTTLE) &&
1104 ((task->appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE)!= 0) &&
1105 (task->appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_THROTTLE)) {
1113 if (task->ext_appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS)
1114 return(task->ext_appliedstate.hw_disk);
1115 if ((task->appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0)
1117 if (task->appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS)
1118 return(task->appliedstate.hw_disk);
1123 proc_get_task_selfdiskacc_internal(task_t task, thread_t thread)
1125 /* if the task is marked for proc_terminate, no throttling for it */
1126 if (task->proc_terminate != 0)
1129 * As per defined iopolicysys behavior, thread trumps task.
1144 if ((task->ext_appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0)
1147 if ((task->ext_appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0) {
1149 if ((task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_TAL) || (task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_DBCLIENT)) {
1151 if ((task->ext_appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_THROTTLE) &&
1152 ((task->appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE)!= 0) &&
1153 (task->appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_THROTTLE)) {
1161 if (task->ext_appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS)
1162 return(task->ext_appliedstate.hw_disk);
1163 if ((task->appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_DISKTHROTTLE) != 0)
1165 if (task->appliedstate.hw_disk != TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS)
1166 return(task->appliedstate.hw_disk);
1182 return(proc_get_task_selfdiskacc_internal(thread->task, thread));
1203 proc_apply_task_diskacc(task_t task, int policy)
1207 task_lock(task);
1208 if (task == self) {
1209 task->appliedstate.hw_disk = policy;
1210 task->policystate.hw_disk = policy;
1212 task->ext_appliedstate.hw_disk = policy;
1213 task->ext_policystate.hw_disk = policy;
1215 task_unlock(task);
1220 proc_apply_thread_diskacc(task_t task, uint64_t tid, int policy)
1228 task_lock(task);
1229 thread = task_findtid(task, tid);
1234 task_unlock(task);
1243 proc_task_remove_throttle(task_t task)
1248 task_lock(task);
1252 proc_restore_bgtaskpolicy_internal(task, 1, 0, BASEPRI_DEFAULT);
1254 proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_DEFAULT);
1256 for (thread = (thread_t)queue_first(&task->threads);
1257 !queue_end(&task->threads, (queue_entry_t)thread); ) {
1259 if (thread->task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) {
1276 /* reset task iopolicy */
1277 task->ext_appliedstate.hw_disk = TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS;
1278 task->appliedstate.hw_disk = TASK_POLICY_HWACCESS_DISK_ATTRIBUTE_FULLACCESS;
1279 task->proc_terminate = 1;
1281 task_unlock(task);
1289 task_t task = current_task();
1292 task_lock(task);
1295 task_unlock(task);
1300 proc_denyinherit_policy(__unused task_t task)
1306 proc_denyselfset_policy(__unused task_t task)
1315 task_t task = current_task();
1320 if (((task->ext_appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_NOGPU) != 0) || (task->ext_appliedstate.hw_gpu == TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS))
1322 if (((task->appliedstate.hw_bg & TASK_POLICY_BACKGROUND_ATTRIBUTE_NOGPU) != 0) || (task->appliedstate.hw_gpu == TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS))
1341 proc_apply_task_gpuacc(task_t task, int policy)
1346 task_lock(task);
1347 if (task == self) {
1348 task->appliedstate.hw_gpu = policy;
1349 task->policystate.hw_gpu = policy;
1351 task->ext_appliedstate.hw_gpu = policy;
1352 task->ext_policystate.hw_gpu = policy;
1354 task_unlock(task);
1361 proc_get_task_ruse_cpu(task_t task, uint32_t * policyp, uint32_t * percentagep, uint64_t * intervalp, uint64_t * deadlinep)
1366 task_lock(task);
1367 if (task != current_task()) {
1368 *policyp = task->ext_policystate.ru_cpu;
1370 *policyp = task->policystate.ru_cpu;
1373 error = task_get_cpuusage(task, percentagep, intervalp, deadlinep);
1392 * has been consumed -- regardless of how much wallclock time has elapsed -- by either the task as an
1394 * in the task are added together), or by any one thread in the task (so-called "per-thread" scope).
1402 * CPU limit. All other types of notifications force task-wide scope for the limit.
1405 proc_set_task_ruse_cpu(task_t task, uint32_t policy, uint32_t percentage, uint64_t interval, uint64_t deadline)
1437 task_lock(task);
1438 if (task != current_task()) {
1439 task->ext_policystate.ru_cpu = policy;
1441 task->policystate.ru_cpu = policy;
1443 error = task_set_cpuusage(task, percentage, interval, deadline, scope);
1444 task_unlock(task);
1449 proc_clear_task_ruse_cpu(task_t task)
1455 task_lock(task);
1456 if (task != current_task()) {
1457 task->ext_policystate.ru_cpu = TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT;
1459 task->policystate.ru_cpu = TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT;
1462 error = task_clear_cpuusage_locked(task);
1466 action = task->ext_appliedstate.ru_cpu;
1467 if (task->ext_appliedstate.ru_cpu != TASK_POLICY_RESOURCE_ATTRIBUTE_NONE) {
1469 task->ext_appliedstate.ru_cpu = TASK_POLICY_RESOURCE_ATTRIBUTE_NONE;
1472 bsdinfo = task->bsd_info;
1473 task_unlock(task);
1479 task_unlock(task);
1487 task_apply_resource_actions(task_t task, int type)
1507 task_lock(task);
1509 if (task->ext_appliedstate.ru_cpu == TASK_POLICY_RESOURCE_ATTRIBUTE_NONE) {
1511 task->ext_appliedstate.ru_cpu = task->ext_policystate.ru_cpu;
1512 action = task->ext_appliedstate.ru_cpu;
1514 action = task->ext_appliedstate.ru_cpu;
1518 bsdinfo = task->bsd_info;
1519 task_unlock(task);
1522 task_unlock(task);
1529 task_get_cpuusage(task_t task, uint32_t * percentagep, uint64_t * intervalp, uint64_t * deadlinep)
1531 *percentagep = task->rusage_cpu_percentage;
1532 *intervalp = task->rusage_cpu_interval;
1533 *deadlinep = task->rusage_cpu_deadline;
1539 task_set_cpuusage(task_t task, uint64_t percentage, uint64_t interval, uint64_t deadline, int scope)
1546 lck_mtx_assert(&task->lock, LCK_MTX_ASSERT_OWNED);
1559 * A per-thread CPU limit on a task generates an exception
1560 * (LEDGER_ACTION_EXCEPTION) if any one thread in the task
1563 task->rusage_cpu_flags |= TASK_RUSECPU_FLAGS_PERTHR_LIMIT;
1564 task->rusage_cpu_perthr_percentage = percentage;
1565 task->rusage_cpu_perthr_interval = interval;
1566 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1574 task->rusage_cpu_flags |= TASK_RUSECPU_FLAGS_PROC_LIMIT;
1575 task->rusage_cpu_percentage = percentage;
1576 task->rusage_cpu_interval = interval;
1578 ledger_set_limit(task->ledger, task_ledgers.cpu_time, abstime);
1579 ledger_set_period(task->ledger, task_ledgers.cpu_time, interval);
1580 ledger_set_action(task->ledger, task_ledgers.cpu_time, LEDGER_ACTION_BLOCK);
1588 if (task->rusage_cpu_callt != NULL) {
1589 task_unlock(task);
1590 thread_call_cancel_wait(task->rusage_cpu_callt);
1591 task_lock(task);
1593 if (task->rusage_cpu_callt == NULL) {
1594 task->rusage_cpu_callt = thread_call_allocate_with_priority(task_action_cpuusage, (thread_call_param_t)task, THREAD_CALL_PRIORITY_KERNEL);
1597 if (task->rusage_cpu_callt != 0) {
1598 task->rusage_cpu_flags |= TASK_RUSECPU_FLAGS_DEADLINE;
1599 task->rusage_cpu_deadline = deadline;
1604 thread_call_enter_delayed(task->rusage_cpu_callt, abstime);
1612 task_clear_cpuusage(task_t task)
1616 task_lock(task);
1617 retval = task_clear_cpuusage_locked(task);
1618 task_unlock(task);
1624 task_clear_cpuusage_locked(task_t task)
1630 if (task->rusage_cpu_flags & TASK_RUSECPU_FLAGS_PROC_LIMIT) {
1631 task->rusage_cpu_flags &= ~TASK_RUSECPU_FLAGS_PROC_LIMIT;
1632 ledger_set_limit(task->ledger, task_ledgers.cpu_time, LEDGER_LIMIT_INFINITY);
1633 task->rusage_cpu_percentage = 0;
1634 task->rusage_cpu_interval = 0;
1637 if (task->rusage_cpu_flags & TASK_RUSECPU_FLAGS_PERTHR_LIMIT) {
1638 task->rusage_cpu_flags &= ~TASK_RUSECPU_FLAGS_PERTHR_LIMIT;
1639 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1642 task->rusage_cpu_perthr_percentage = 0;
1643 task->rusage_cpu_perthr_interval = 0;
1648 if (task->rusage_cpu_flags & TASK_RUSECPU_FLAGS_DEADLINE) {
1649 task->rusage_cpu_flags &= ~TASK_RUSECPU_FLAGS_DEADLINE;
1650 if (task->rusage_cpu_callt != 0) {
1651 savecallt = task->rusage_cpu_callt;
1652 task->rusage_cpu_callt = NULL;
1653 task->rusage_cpu_deadline = 0;
1654 task_unlock(task);
1657 task_lock(task);
1667 task_t task = (task_t)param0;
1668 (void)task_apply_resource_actions(task, TASK_POLICY_CPU_RESOURCE_USAGE);
1673 /* return the appstate of a task */
1675 proc_lf_getappstate(task_t task)
1677 return(task->appstate);
1682 /* set appstate of a task and apply approp actions */
1684 proc_lf_setappstate(task_t task, int state)
1707 task_lock(task);
1708 oldstate = task->appstate;
1719 task->ext_policystate.hw_bg = TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL;
1720 proc_apply_bgtaskpolicy_internal(task, 1, 1);
1730 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1731 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1736 kret = task_pidsuspend_locked(task);
1755 ret = proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_DEFAULT);
1761 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1762 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1763 ret = proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_DEFAULT);
1768 kret = task_pidsuspend_locked(task);
1772 ret = proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_DEFAULT);
1785 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1786 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT;
1791 task->ext_policystate.hw_bg = TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL;
1793 ret = proc_apply_bgtaskpolicy_internal(task, 1, 1);
1795 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT;
1796 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT;
1807 kret = task_pidsuspend_locked(task);
1811 ret = proc_restore_bgtaskpolicy_internal(task, 1, 1, BASEPRI_DEFAULT);
1812 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT;
1813 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_DEFAULT;
1828 task->ext_policystate.hw_bg = TASK_POLICY_BACKGROUND_ATTRIBUTE_ALL;
1829 ret = proc_apply_bgtaskpolicy_internal(task, 1, 1);
1840 task->ext_policystate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1841 task->ext_appliedstate.hw_gpu = TASK_POLICY_HWACCESS_GPU_ATTRIBUTE_NOACCESS;
1844 /* pidresume does drop task lock,so no need to have locked version */
1845 task_unlock(task);
1846 kret = task_pidresume(task);
1847 task_lock(task);
1851 /* set the new app state on the task */
1852 task->appstate = state;
1854 task_unlock(task);
1858 proc_apply_task_networkbg_internal(task->bsd_info, NULL);
1860 proc_restore_task_networkbg_internal(task->bsd_info, NULL);
1864 memorystatus_on_suspend(proc_pid(task->bsd_info));
1866 memorystatus_on_resume(proc_pid(task->bsd_info));
1870 apply_appstate_watchers(task, setbg);
1889 add_taskwatch_locked(task_t task, task_watch_t * twp)
1891 queue_enter(&task->task_watchers, twp, task_watch_t *, tw_links);
1892 task->num_taskwatchers++;
1897 remove_taskwatch_locked(task_t task, task_watch_t * twp)
1899 queue_remove(&task->task_watchers, twp, task_watch_t *, tw_links);
1900 task->num_taskwatchers--;
1911 task_t task = TASK_NULL;
1932 /* task is still active ? */
1953 /* already bound to another task */
1963 twp->tw_task = target_task; /* holds the task reference */
1987 task = twp->tw_task;
1989 remove_taskwatch_locked(task, twp);
1993 task_deallocate(task); /* drop task ref in twp */
2015 proc_restore_task_networkbg_internal(thread->task->bsd_info, thread);
2018 proc_apply_task_networkbg_internal(thread->task->bsd_info, thread);
2023 apply_appstate_watchers(task_t task, int setbg)
2031 if ((numwatchers = task->num_taskwatchers) == 0)
2042 if (task->watchapplying != 0) {
2043 lck_mtx_sleep(&task_watch_mtx, LCK_SLEEP_DEFAULT, &task->watchapplying, THREAD_UNINT);
2049 if (numwatchers != task->num_taskwatchers) {
2055 task->watchapplying = 1;
2057 queue_iterate(&task->task_watchers, twp, task_watch_t *, tw_links) {
2080 task->watchapplying = 0;
2081 thread_wakeup_one(&task->watchapplying);
2108 task_removewatchers(task_t task)
2115 if ((numwatchers = task->num_taskwatchers) == 0)
2125 if (task->num_taskwatchers == 0) {
2130 if (numwatchers != task->num_taskwatchers) {
2138 while((twp = (task_watch_t *)dequeue_head(&task->task_watchers)) != NULL)
2141 task->num_taskwatchers--;
2149 if ((task->num_taskwatchers == 0) || (i > numwatchers))
2173 proc_disable_task_apptype(task_t task, int policy_subtype)
2182 task_lock(task);
2184 if (task->ext_policystate.apptype != policy_subtype) {
2190 switch (task->role) {
2205 if (task->ext_appliedstate.apptype != PROC_POLICY_OSX_APPTYPE_NONE) {
2206 switch (task->ext_appliedstate.apptype) {
2210 task->ext_appliedstate.apptype = PROC_POLICY_OSX_APPTYPE_NONE;
2212 proc_restore_bgtaskpolicy_internal(task, 1, 1, maxpri);
2213 bsdinfo = task->bsd_info;
2219 task->ext_appliedstate.apptype = PROC_POLICY_OSX_APPTYPE_NONE;
2221 proc_restore_bgtaskpolicy_internal(task, 1, 0, maxpri);
2222 bsdinfo = task->bsd_info;
2237 task_unlock(task);
2246 proc_enable_task_apptype(task_t task, int policy_subtype)
2252 task_lock(task);
2254 if (task->ext_policystate.apptype != policy_subtype) {
2259 if (task->ext_appliedstate.apptype == PROC_POLICY_OSX_APPTYPE_NONE) {
2260 switch (task->ext_policystate.apptype) {
2264 task->ext_appliedstate.apptype = task->ext_policystate.apptype;
2265 if (task->role == TASK_BACKGROUND_APPLICATION) {
2266 if (task->role == TASK_BACKGROUND_APPLICATION) {
2267 proc_apply_bgtaskpolicy_internal(task, 1, 1);
2268 bsdinfo = task->bsd_info;
2282 task_unlock(task);
2294 if ((thread->task->ext_appliedstate.apptype == PROC_POLICY_IOS_APPLE_DAEMON) &&