Lines Matching defs:task

57  *	File:	kern/task.c
108 #include <kern/task.h>
177 task_t task);
179 task_t task,
182 task_t task);
184 task_t task );
186 task_t task);
189 task_t task);
193 task_t task)
195 task_lock(task);
196 task->priv_flags |= VM_BACKING_STORE_PRIV;
197 task_unlock(task);
204 task_t task,
213 if (task_has_64BitAddr(task))
216 task_set_64BitAddr(task);
218 if ( !task_has_64BitAddr(task))
227 (void) vm_map_remove(task->map,
232 (void) vm_map_remove(task->map,
236 task_clear_64BitAddr(task);
239 * task's 64-bit feature flag due to the 32-bit/64-bit register save
242 * state with respect to its task's 64-bitness.
245 task_lock(task);
246 queue_iterate(&task->threads, thread, thread_t, task_threads) {
251 task_unlock(task);
257 task_set_dyld_info(task_t task, mach_vm_address_t addr, mach_vm_size_t size)
259 task_lock(task);
260 task->all_image_info_addr = addr;
261 task->all_image_info_size = size;
262 task_unlock(task);
270 lck_grp_init(&task_lck_grp, "task", &task_lck_grp_attr);
278 sizeof(struct task),
279 task_max * sizeof(struct task),
280 TASK_CHUNK * sizeof(struct task),
288 * Create the kernel task as the first task.
303 * Create a task running in the kernel address space. It may
328 * No longer supported: too many calls assume that a task has a valid
366 if ((t = ledger_template_create("Per-task ledger")) == NULL)
367 panic("couldn't create task ledger template");
387 panic("couldn't create entries for task ledger template");
452 new_task->taskFeatures[0] = 0; /* Init task features */
453 new_task->taskFeatures[1] = 0; /* Init task features */
587 * Drop a reference on a task.
591 task_t task)
595 if (task == TASK_NULL)
598 if (task_deallocate_internal(task) > 0)
602 queue_remove(&terminated_tasks, task, task_t, tasks);
608 * the task.
610 machine_task_terminate(task);
612 ipc_task_terminate(task);
614 if (task->affinity_space)
615 task_affinity_deallocate(task);
617 vm_map_deallocate(task->map);
618 is_release(task->itk_space);
620 ledger_get_entries(task->ledger, task_ledgers.interrupt_wakeups,
622 ledger_get_entries(task->ledger, task_ledgers.platform_idle_wakeups,
627 dead_task_statistics.total_user_time += task->total_user_time;
628 dead_task_statistics.total_system_time += task->total_system_time;
633 dead_task_statistics.task_timer_wakeups_bin_1 += task->task_timer_wakeups_bin_1;
634 dead_task_statistics.task_timer_wakeups_bin_2 += task->task_timer_wakeups_bin_2;
637 lck_mtx_destroy(&task->lock, &task_lck_grp);
640 labelh_release(task->label);
643 if (!ledger_get_entries(task->ledger, task_ledgers.tkm_private, &credit,
648 if (!ledger_get_entries(task->ledger, task_ledgers.tkm_shared, &credit,
653 ledger_dereference(task->ledger);
654 zinfo_task_free(task);
655 zfree(task_zone, task);
661 * Drop a reference on a task name.
674 * Terminate the specified task. See comments on thread_terminate
675 * (kern/thread.c) about problems with terminating the "current task."
680 task_t task)
682 if (task == TASK_NULL)
685 if (task->bsd_info)
688 return (task_terminate_internal(task));
693 task_t task)
699 assert(task != kernel_task);
702 self_task = self->task;
705 * Get the task locked and make sure that we are not racing
708 if (task == self_task)
709 task_lock(task);
711 if (task < self_task) {
712 task_lock(task);
717 task_lock(task);
720 if (!task->active) {
727 task_unlock(task);
728 if (self_task != task)
734 if (self_task != task)
745 * at user space by holding the task (we would have held
748 * held there). Mark the task inactive, and prevent
749 * further task operations via the task port.
751 task_hold_locked(task);
752 task->active = FALSE;
753 ipc_task_disable(task);
756 * Terminate each thread in the task.
758 queue_iterate(&task->threads, thread, thread_t, task_threads) {
762 task_unlock(task);
766 * remove all task watchers
768 task_removewatchers(task);
772 * Destroy all synchronizers owned by the task.
774 task_synchronizer_destroy_all(task);
779 ipc_space_terminate(task->itk_space);
781 if (vm_map_has_4GB_pagezero(task->map))
782 vm_map_clear_4GB_pagezero(task->map);
785 * If the current thread is a member of the task
787 * the task will not be dropped until the thread
792 vm_map_remove(task->map,
793 task->map->min_offset,
794 task->map->max_offset,
798 vm_shared_region_set(task, NULL);
801 queue_remove(&tasks, task, task_t, tasks);
802 queue_enter(&terminated_tasks, task, task_t, tasks);
813 * Get rid of the task active reference on itself.
815 task_deallocate(task);
823 * Shut the current task down (except for the current thread) in
824 * preparation for dramatic changes to the task (probably exec).
825 * We hold the task and mark all other threads in the task for
830 task_t task)
834 assert(task != kernel_task);
838 if (task != self->task)
841 task_lock(task);
843 if (task->halting || !task->active || !self->active) {
850 task_unlock(task);
855 task->halting = TRUE;
857 if (task->thread_count > 1) {
865 task_hold_locked(task);
868 * Terminate all the other threads in the task.
870 queue_iterate(&task->threads, thread, thread_t, task_threads) {
875 task_release_locked(task);
877 task_unlock(task);
885 * Complete task halt by waiting for threads to terminate, then clean
886 * up task resources (VM, port namespace, etc...) and then let the
887 * current thread go in the (practically empty) task context.
890 task_complete_halt(task_t task)
892 task_lock(task);
893 assert(task->halting);
894 assert(task == current_task());
901 if (task->thread_count > 1) {
902 assert_wait((event_t)&task->halting, THREAD_UNINT);
903 task_unlock(task);
906 task_unlock(task);
911 * to perform cleanup of task-level resources
913 * ripping apart the task.
915 machine_task_terminate(task);
918 * Destroy all synchronizers owned by the task.
920 task_synchronizer_destroy_all(task);
926 ipc_space_clean(task->itk_space);
932 vm_map_remove(task->map, task->map->min_offset,
933 task->map->max_offset, VM_MAP_NO_FLAGS);
935 task->halting = FALSE;
941 * Suspend execution of the specified task.
942 * This is a recursive-style suspension of the task, a count of
945 * CONDITIONS: the task is locked and active.
949 register task_t task)
953 assert(task->active);
955 if (task->suspend_count++ > 0)
961 queue_iterate(&task->threads, thread, thread_t, task_threads) {
972 * and verify that the task is active. This differs from task_suspend
973 * in that it places a kernel hold on the task rather than just a
977 * CONDITIONS: the caller holds a reference on the task
981 register task_t task)
983 if (task == TASK_NULL)
986 task_lock(task);
988 if (!task->active) {
989 task_unlock(task);
994 task_hold_locked(task);
995 task_unlock(task);
1002 task_t task,
1005 if (task == TASK_NULL)
1008 task_lock(task);
1010 if (!task->active) {
1011 task_unlock(task);
1016 task_wait_locked(task, until_not_runnable);
1017 task_unlock(task);
1025 * Wait for all threads in task to stop.
1028 * Called with task locked, active, and held.
1032 register task_t task,
1037 assert(task->active);
1038 assert(task->suspend_count > 0);
1045 * the task.
1047 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1056 * Release a kernel hold on a task.
1058 * CONDITIONS: the task is locked and active
1062 register task_t task)
1066 assert(task->active);
1067 assert(task->suspend_count > 0);
1069 if (--task->suspend_count > 0)
1072 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1083 * and verify that the task is active.
1085 * CONDITIONS: The caller holds a reference to the task
1089 task_t task)
1091 if (task == TASK_NULL)
1094 task_lock(task);
1096 if (!task->active) {
1097 task_unlock(task);
1102 task_release_locked(task);
1103 task_unlock(task);
1110 task_t task,
1121 if (task == TASK_NULL)
1127 task_lock(task);
1128 if (!task->active) {
1129 task_unlock(task);
1137 actual = task->thread_count;
1144 /* unlock the task and allocate more memory */
1145 task_unlock(task);
1158 /* OK, have memory and the task is locked & active */
1163 for (thread = (thread_t)queue_first(&task->threads); i < actual;
1169 assert(queue_end(&task->threads, (queue_entry_t)thread));
1174 /* can unlock task now that we've got the thread refs */
1175 task_unlock(task);
1219 register task_t task)
1221 if (!task->active) {
1225 if (task->user_stop_count++ > 0) {
1227 * If the stop count was positive, the task is
1234 * Put a kernel-level hold on the threads in the task (all
1235 * user-level task suspensions added together represent a
1239 task_hold_locked(task);
1240 task_wait_locked(task, TRUE);
1247 register task_t task,
1252 if (!task->active) {
1257 if (task->pidsuspended == FALSE) {
1260 task->pidsuspended = FALSE;
1263 if (task->user_stop_count > (task->pidsuspended ? 1 : 0)) {
1264 if (--task->user_stop_count == 0) {
1273 * Release the task if necessary.
1276 task_release_locked(task);
1284 * Implement a user-level suspension on a task.
1287 * The caller holds a reference to the task
1291 register task_t task)
1295 if (task == TASK_NULL || task == kernel_task)
1298 task_lock(task);
1300 kr = place_task_hold(task);
1302 task_unlock(task);
1309 * Release a kernel hold on a task.
1312 * The caller holds a reference to the task
1316 register task_t task)
1320 if (task == TASK_NULL || task == kernel_task)
1323 task_lock(task);
1325 kr = release_task_hold(task, FALSE);
1327 task_unlock(task);
1333 task_pidsuspend_locked(task_t task)
1337 if (task->pidsuspended) {
1342 task->pidsuspended = TRUE;
1344 kr = place_task_hold(task);
1346 task->pidsuspended = FALSE;
1356 * Suspends a task by placing a hold on its threads.
1359 * The caller holds a reference to the task
1363 register task_t task)
1367 if (task == TASK_NULL || task == kernel_task)
1370 task_lock(task);
1372 kr = task_pidsuspend_locked(task);
1374 task_unlock(task);
1384 * Resumes a previously suspended task.
1387 * The caller holds a reference to the task
1391 register task_t task)
1398 if (task == TASK_NULL || task == kernel_task)
1401 task_lock(task);
1404 frozen = task->frozen;
1405 task->frozen = FALSE;
1408 kr = release_task_hold(task, TRUE);
1410 task_unlock(task);
1414 kr = vm_map_thaw(task->map);
1426 * Freeze a task.
1429 * The caller holds a reference to the task
1433 register task_t task,
1444 if (task == TASK_NULL || task == kernel_task)
1447 task_lock(task);
1449 if (task->frozen) {
1450 task_unlock(task);
1455 task->frozen = TRUE;
1458 task_unlock(task);
1461 kr = vm_map_freeze_walk(task->map, purgeable_count, wired_count, clean_count, dirty_count, dirty_budget, shared);
1463 kr = vm_map_freeze(task->map, purgeable_count, wired_count, clean_count, dirty_count, dirty_budget, shared);
1472 * Thaw a currently frozen task.
1475 * The caller holds a reference to the task
1479 register task_t task)
1483 if (task == TASK_NULL || task == kernel_task)
1486 task_lock(task);
1488 if (!task->frozen) {
1489 task_unlock(task);
1493 task->frozen = FALSE;
1495 task_unlock(task);
1497 kr = vm_map_thaw(task->map);
1507 task_t task,
1515 if (task == TASK_NULL)
1521 task_lock(task);
1522 task->sec_token = sec_token;
1523 task->audit_token = audit_token;
1524 task_unlock(task);
1532 kr = task_set_special_port(task, TASK_HOST_PORT, host_port);
1542 * task names, etc...), so I left it in the formal task interface.
1546 task_t task,
1551 if (task == TASK_NULL)
1563 task_t task,
1570 if (task == TASK_NULL)
1573 task_lock(task);
1575 if ((task != current_task()) && (!task->active)) {
1576 task_unlock(task);
1597 map = (task == kernel_task)? kernel_map: task->map;
1610 basic_info->policy = ((task != kernel_task)?
1612 basic_info->suspend_count = task->user_stop_count;
1614 absolutetime_to_microtime(task->total_user_time, &secs, &usecs);
1619 absolutetime_to_microtime(task->total_system_time, &secs, &usecs);
1642 map = (task == kernel_task)? kernel_map: task->map;
1648 basic_info->policy = ((task != kernel_task)?
1650 basic_info->suspend_count = task->user_stop_count;
1652 absolutetime_to_microtime(task->total_user_time, &secs, &usecs);
1657 absolutetime_to_microtime(task->total_system_time, &secs, &usecs);
1680 map = (task == kernel_task) ? kernel_map : task->map;
1692 basic_info->policy = ((task != kernel_task) ?
1695 basic_info->suspend_count = task->user_stop_count;
1697 absolutetime_to_microtime(task->total_user_time, &secs, &usecs);
1702 absolutetime_to_microtime(task->total_system_time, &secs, &usecs);
1728 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1756 info->total_user = task->total_user_time;
1757 info->total_system = task->total_system_time;
1759 queue_iterate(&task->threads, thread, thread_t, task_threads) {
1808 info->all_image_info_addr = task->all_image_info_addr;
1809 info->all_image_info_size = task->all_image_info_size;
1813 info->all_image_info_format = task_has_64BitAddr(task) ?
1835 p = get_bsdtask_info(task);
1841 info->extmod_statistics = task->extmod_statistics;
1863 if (task == kernel_task) {
1867 * info for the kernel task, gather from everywhere.
1869 task_unlock(task);
1875 /* count all other task/thread shared alloc/free against the kernel */
1878 /* XXX this really shouldn't be using the function parameter 'task' as a local var! */
1879 queue_iterate(&tasks, task, task_t, tasks) {
1880 if (task == kernel_task) {
1881 if (ledger_get_entries(task->ledger,
1888 if (!ledger_get_entries(task->ledger,
1896 if (!ledger_get_entries(task->ledger,
1901 if (!ledger_get_entries(task->ledger,
1906 task_unlock(task);
1940 if (task != kernel_task) {
1945 rr_base->base_priority = task->priority;
1968 if (task == kernel_task) {
1973 ts_base->base_priority = task->priority;
1990 *sec_token_p = task->sec_token;
2007 *audit_token_p = task->audit_token;
2030 events_info->faults = task->faults;
2031 events_info->pageins = task->pageins;
2032 events_info->cow_faults = task->cow_faults;
2033 events_info->messages_sent = task->messages_sent;
2034 events_info->messages_received = task->messages_received;
2035 events_info->syscalls_mach = task->syscalls_mach;
2036 events_info->syscalls_unix = task->syscalls_unix;
2038 events_info->csw = task->c_switch;
2040 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2057 error = task_affinity_info(task, task_info_out, task_info_count);
2074 ledger_get_entries(task->ledger, task_ledgers.interrupt_wakeups,
2076 ledger_get_entries(task->ledger, task_ledgers.platform_idle_wakeups,
2079 info->task_timer_wakeups_bin_1 = task->task_timer_wakeups_bin_1;
2080 info->task_timer_wakeups_bin_2 = task->task_timer_wakeups_bin_2;
2082 info->total_user = task->total_user_time;
2083 info->total_system = task->total_system_time;
2085 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2089 if ((task == kernel_task) && (thread->priority == IDLEPRI) && (thread->sched_pri == IDLEPRI))
2118 task_unlock(task);
2124 task_t task,
2130 /* assert(task == current_task()); */ /* bogus assert 4803227 4807483 */
2132 task_lock(task);
2134 task->vtimers |= which;
2139 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2152 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2163 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2174 task_unlock(task);
2179 task_t task,
2182 assert(task == current_task());
2184 task_lock(task);
2186 task->vtimers &= ~which;
2188 task_unlock(task);
2194 task_t task,
2203 assert(task == current_task());
2205 assert(task->vtimers & which);
2246 * Change the assigned processor set for the task
2250 __unused task_t task,
2264 task_t task,
2267 return (task_assign(task, &pset0, assign_threads));
2273 * Return name of processor set that task is assigned to.
2277 task_t task,
2280 if (!task->active)
2293 * the given task. Policy must be a policy which is enabled for the
2298 __unused task_t task,
2312 * the given task. Policy can be any policy implemented by the
2318 __unused task_t task,
2333 task_t task,
2340 printf("task 0x%x: setting fast_tas to [0x%x, 0x%x]\n",
2341 task, pc, endpc);
2343 task_lock(task);
2344 task->fast_tas_base = pc;
2345 task->fast_tas_end = endpc;
2346 task_unlock(task);
2352 __unused task_t task,
2361 task_synchronizer_destroy_all(task_t task)
2370 while (!queue_empty(&task->semaphore_list)) {
2371 semaphore = (semaphore_t) queue_first(&task->semaphore_list);
2372 (void) semaphore_destroy(task, semaphore);
2379 while (!queue_empty(&task->lock_set_list)) {
2380 lock_set = (lock_set_t) queue_first(&task->lock_set_list);
2381 (void) lock_set_destroy(task, lock_set);
2387 * on the task. Subsequent thread creation will have this initial
2393 task_t task,
2400 if (task == TASK_NULL) {
2404 task_lock(task);
2406 if (!task->active) {
2407 task_unlock(task);
2411 ret = machine_task_set_state(task, flavor, state, state_count);
2413 task_unlock(task);
2419 * on the task, as set by task_set_state(). Flavors and structures
2424 task_t task,
2431 if (task == TASK_NULL) {
2435 task_lock(task);
2437 if (!task->active) {
2438 task_unlock(task);
2442 ret = machine_task_get_state(task, flavor, state, state_count);
2444 task_unlock(task);
2463 check_for_tasksuspend(task_t task)
2466 if (task == TASK_NULL)
2469 return (task->suspend_count > 0);
2480 void task_reference(task_t task);
2483 task_t task)
2485 if (task != TASK_NULL)
2486 task_reference_internal(task);
2490 * This routine is called always with task lock held.
2492 * operates on it under the task lock held.
2495 task_findtid(task_t task, uint64_t tid)
2499 queue_iterate(&task->threads, thread, thread_t, task_threads) {
2509 * Protect 2 task labels against modification by adding a reference on
2536 struct task *task)
2539 tasklabel_lock(task);
2540 task->label = labelh_modify(task->label);
2541 mac_task_label_update(pl, &task->maclabel);
2542 tasklabel_unlock(task);
2543 ip_lock(task->itk_self);
2544 mac_port_label_update_cred(pl, &task->itk_self->ip_label);
2545 ip_unlock(task->itk_self);
2550 struct task *task,
2555 tasklabel_lock(task);
2556 task->label = labelh_modify(task->label);
2557 (*f)(&task->maclabel, arg);
2558 tasklabel_unlock(task);
2562 mac_task_get_label(struct task *task)
2564 return (&task->maclabel);