X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/743345f9a4b36f7e2f9ba37691e70c50baecb56e..cc8bc92ae4a8e9f1a1ab61bf83d34ad8150b3405:/osfmk/kern/task.h diff --git a/osfmk/kern/task.h b/osfmk/kern/task.h index a3c5edb6b..847120f95 100644 --- a/osfmk/kern/task.h +++ b/osfmk/kern/task.h @@ -113,6 +113,10 @@ #include #include +#if MONOTONIC +#include +#endif /* MONOTONIC */ + #include #include #include @@ -122,6 +126,7 @@ #include #include +#include #ifdef CONFIG_ATM #include @@ -137,14 +142,12 @@ struct _cpu_time_qos_stats { uint64_t cpu_time_qos_user_interactive; }; -#ifdef CONFIG_BANK #include -#endif struct task { /* Synchronization/destruction information */ decl_lck_mtx_data(,lock) /* Task's lock */ - uint32_t ref_count; /* Number of references to me */ + _Atomic uint32_t ref_count; /* Number of references to me */ boolean_t active; /* Task has not been terminated */ boolean_t halting; /* Task is being halted */ @@ -183,6 +186,7 @@ struct task { /* Statistics */ uint64_t total_user_time; /* terminated threads only */ uint64_t total_system_time; + uint64_t total_ptime; /* Virtual timers */ uint32_t vtimers; @@ -232,7 +236,7 @@ struct task { void *bsd_info; #endif kcdata_descriptor_t corpse_info; - void * corpse_info_kernel; + uint64_t crashed_thread_id; queue_chain_t corpse_tasks; #ifdef CONFIG_MACF struct label * crash_label; @@ -251,7 +255,7 @@ struct task { #define TF_CORPSE_FORK 0x00000080 /* task is a forked corpse */ #define TF_LRETURNWAIT 0x00000100 /* task is waiting for fork/posix_spawn/exec to complete */ #define TF_LRETURNWAITER 0x00000200 /* task is waiting for TF_LRETURNWAIT to get cleared */ - +#define TF_PLATFORM 0x00000400 /* task is a platform binary */ #define task_has_64BitAddr(task) \ (((task)->t_flags & TF_64B_ADDR) != 0) @@ -315,13 +319,16 @@ struct task { uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */ uint64_t rusage_cpu_deadline; thread_call_t rusage_cpu_callt; +#if CONFIG_EMBEDDED + queue_head_t task_watchers; /* app state watcher threads */ + int num_taskwatchers; + int watchapplying; +#endif /* CONFIG_EMBEDDED */ #if CONFIG_ATM struct atm_task_descriptor *atm_context; /* pointer to per task atm descriptor */ #endif -#if CONFIG_BANK struct bank_task *bank_context; /* pointer to per task bank structure */ -#endif #if IMPORTANCE_INHERITANCE struct ipc_importance_task *task_imp_base; /* Base of IPC importance chain */ @@ -346,6 +353,12 @@ struct task { low_mem_privileged_listener :1, /* if set, task would like to know about pressure changes before other tasks on the system */ mem_notify_reserved :27; /* reserved for future use */ + uint32_t memlimit_is_active :1, /* if set, use active attributes, otherwise use inactive attributes */ + memlimit_is_fatal :1, /* if set, exceeding current memlimit will prove fatal to the task */ + memlimit_active_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds active memory limit */ + memlimit_inactive_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds inactive memory limit */ + memlimit_attrs_reserved :28; /* reserved for future use */ + io_stat_info_t task_io_stats; uint64_t task_immediate_writes __attribute__((aligned(8))); uint64_t task_deferred_writes __attribute__((aligned(8))); @@ -363,6 +376,11 @@ struct task { uint64_t task_gpu_ns; uint64_t task_energy; +#if MONOTONIC + /* Read and written under task_lock */ + struct mt_task task_monotonic; +#endif /* MONOTONIC */ + /* # of purgeable volatile VM objects owned by this task: */ int task_volatile_objects; /* # of purgeable but not volatile VM objects owned by this task: */ @@ -401,7 +419,7 @@ struct task { }; #define task_lock(task) lck_mtx_lock(&(task)->lock) -#define task_lock_assert_owned(task) lck_mtx_assert(&(task)->lock, LCK_MTX_ASSERT_OWNED) +#define task_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->lock, LCK_MTX_ASSERT_OWNED) #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock) #define task_unlock(task) lck_mtx_unlock(&(task)->lock) @@ -417,10 +435,10 @@ extern void task_reference_internal(task_t task); extern uint32_t task_deallocate_internal(task_t task); #else #define task_reference_internal(task) \ - (void)hw_atomic_add(&(task)->ref_count, 1) + (void)atomic_fetch_add_explicit(&(task)->ref_count, 1, memory_order_relaxed) #define task_deallocate_internal(task) \ - hw_atomic_sub(&(task)->ref_count, 1) + (atomic_fetch_sub_explicit(&task->ref_count, 1, memory_order_release) - 1) #endif #define task_reference(task) \ @@ -551,12 +569,17 @@ extern kern_return_t task_create_internal( uint32_t procflags, task_t *child_task); /* OUT */ +extern kern_return_t task_info( + task_t task, + task_flavor_t flavor, + task_info_t task_info_out, + mach_msg_type_number_t *task_info_count); extern void task_power_info_locked( task_t task, task_power_info_t info, - gpu_energy_data_t gpu_energy, - uint64_t *task_power); + gpu_energy_data_t gpu_energy, + task_power_info_v2_t infov2); extern uint64_t task_gpu_utilisation( task_t task); @@ -564,6 +587,9 @@ extern uint64_t task_gpu_utilisation( extern uint64_t task_energy( task_t task); +extern uint64_t task_cpu_ptime( + task_t task); + extern void task_vtimer_set( task_t task, integer_t which); @@ -585,6 +611,10 @@ extern void task_set_64bit( task_t task, boolean_t is64bit); +extern void task_set_platform_binary( + task_t task, + boolean_t is_platform); + extern void task_backing_store_privileged( task_t task); @@ -598,26 +628,35 @@ extern int get_task_numacts( task_t task); extern int get_task_numactivethreads(task_t task); -extern kern_return_t task_collect_crash_info(task_t task, struct proc *p, int is_corpse_fork); + +struct label; +extern kern_return_t task_collect_crash_info( + task_t task, +#if CONFIG_MACF + struct label *crash_label, +#endif + int is_corpse_fork); void task_port_notify(mach_msg_header_t *msg); void task_wait_till_threads_terminate_locked(task_t task); /* JMM - should just be temporary (implementation in bsd_kern still) */ extern void set_bsdtask_info(task_t,void *); extern vm_map_t get_task_map_reference(task_t); -extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t, boolean_t); +extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t); extern pmap_t get_task_pmap(task_t); extern uint64_t get_task_resident_size(task_t); extern uint64_t get_task_compressed(task_t); extern uint64_t get_task_resident_max(task_t); extern uint64_t get_task_phys_footprint(task_t); -extern uint64_t get_task_phys_footprint_max(task_t); +extern uint64_t get_task_phys_footprint_recent_max(task_t); +extern uint64_t get_task_phys_footprint_lifetime_max(task_t); extern uint64_t get_task_phys_footprint_limit(task_t); extern uint64_t get_task_purgeable_size(task_t); extern uint64_t get_task_cpu_time(task_t); extern uint64_t get_task_dispatchqueue_offset(task_t); extern uint64_t get_task_dispatchqueue_serialno_offset(task_t); -extern uint64_t get_task_uniqueid(task_t); +extern uint64_t get_task_uniqueid(task_t task); +extern int get_task_version(task_t task); extern uint64_t get_task_internal(task_t); extern uint64_t get_task_internal_compressed(task_t); @@ -630,9 +669,17 @@ extern uint64_t get_task_memory_region_count(task_t); extern uint64_t get_task_page_table(task_t); extern kern_return_t task_convert_phys_footprint_limit(int, int *); -extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t); +extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t, boolean_t); extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb); +/* Jetsam memlimit attributes */ +extern boolean_t task_get_memlimit_is_active(task_t task); +extern boolean_t task_get_memlimit_is_fatal(task_t task); +extern void task_set_memlimit_is_active(task_t task, boolean_t memlimit_is_active); +extern void task_set_memlimit_is_fatal(task_t task, boolean_t memlimit_is_fatal); +extern boolean_t task_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); +extern void task_mark_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); + extern boolean_t is_kerneltask(task_t task); extern boolean_t is_corpsetask(task_t task); @@ -674,17 +721,18 @@ struct _task_ledger_indices { #if CONFIG_SCHED_SFI int sfi_wait_times[MAX_SFI_CLASS_ID]; #endif /* CONFIG_SCHED_SFI */ -#ifdef CONFIG_BANK int cpu_time_billed_to_me; int cpu_time_billed_to_others; -#endif int physical_writes; int logical_writes; + int energy_billed_to_me; + int energy_billed_to_others; }; extern struct _task_ledger_indices task_ledgers; /* requires task to be unlocked, returns a referenced thread */ thread_t task_findtid(task_t task, uint64_t tid); +int pid_from_task(task_t task); extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags); extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags); @@ -695,6 +743,7 @@ extern void task_clear_exec_copy_flag(task_t task); extern boolean_t task_is_exec_copy(task_t); extern boolean_t task_did_exec(task_t task); extern boolean_t task_is_active(task_t task); +extern boolean_t task_is_halting(task_t task); extern void task_clear_return_wait(task_t task); extern void task_wait_to_return(void); extern event_t task_get_return_wait_event(task_t task); @@ -712,6 +761,8 @@ extern boolean_t task_is_gpu_denied(task_t task); extern queue_head_t * task_io_user_clients(task_t task); +extern void task_copy_fields_for_exec(task_t dst_task, task_t src_task); + #endif /* XNU_KERNEL_PRIVATE */ #ifdef KERNEL_PRIVATE @@ -728,6 +779,7 @@ extern boolean_t get_task_frozen(task_t); /* Convert from a task to a port */ extern ipc_port_t convert_task_to_port(task_t); extern ipc_port_t convert_task_name_to_port(task_name_t); +extern ipc_port_t convert_task_inspect_to_port(task_inspect_t); extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task); /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */ @@ -757,7 +809,6 @@ extern boolean_t task_could_use_secluded_mem(task_t task); #if CONFIG_MACF extern struct label *get_task_crash_label(task_t task); -extern void set_task_crash_label(task_t task, struct label *label); #endif /* CONFIG_MACF */ #endif /* KERNEL_PRIVATE */ @@ -770,6 +821,9 @@ extern void task_deallocate( extern void task_name_deallocate( task_name_t task_name); +extern void task_inspect_deallocate( + task_inspect_t task_inspect); + extern void task_suspension_token_deallocate( task_suspension_token_t token); __END_DECLS