2 * Copyright (c) 2013 Apple Computer, 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 #ifndef _KERN_COALITION_H_
30 #define _KERN_COALITION_H_
32 /* only kernel-private interfaces */
33 #ifdef XNU_KERNEL_PRIVATE
34 #include <mach/coalition.h>
35 #include <kern/thread_group.h>
39 void coalitions_init(void);
42 * KERN_ALREADY_IN_SET task is already in a coalition (maybe this one, maybe a different one)
43 * KERN_TERMINATED coalition is already terminated (so it may not adopt any more tasks)
45 kern_return_t
coalitions_adopt_task(coalition_t
*coaltions
, task_t task
);
46 kern_return_t
coalitions_adopt_init_task(task_t task
);
47 kern_return_t
coalitions_adopt_corpse_task(task_t task
);
49 /* Currently, no error conditions. If task is not already in a coalition,
50 * KERN_SUCCESS is returned because removing it did not fail.
52 kern_return_t
coalitions_remove_task(task_t task
);
53 void task_release_coalitions(task_t task
);
58 kern_return_t
coalitions_set_roles(coalition_t coalitions
[COALITION_NUM_TYPES
],
59 task_t task
, int roles
[COALITION_NUM_TYPES
]);
61 uint64_t coalition_id(coalition_t coal
);
62 void task_coalition_ids(task_t task
, uint64_t ids
[COALITION_NUM_TYPES
]);
63 void task_coalition_roles(task_t task
, int roles
[COALITION_NUM_TYPES
]);
64 int coalition_type(coalition_t coal
);
66 void task_coalition_update_gpu_stats(task_t task
, uint64_t gpu_ns_delta
);
67 boolean_t
task_coalition_adjust_focal_count(task_t task
, int count
, uint32_t *new_count
);
68 uint32_t task_coalition_focal_count(task_t task
);
69 boolean_t
task_coalition_adjust_nonfocal_count(task_t task
, int count
, uint32_t *new_count
);
70 uint32_t task_coalition_nonfocal_count(task_t task
);
71 struct thread_group
*task_coalition_get_thread_group(task_t task
);
72 void coalition_set_thread_group(coalition_t coal
, struct thread_group
*tg
);
73 struct thread_group
*kdp_coalition_get_thread_group(coalition_t coal
);
74 struct thread_group
*coalition_get_thread_group(coalition_t coal
);
75 void task_coalition_thread_group_focal_update(task_t task
);
77 void coalition_for_each_task(coalition_t coal
, void *ctx
,
78 void (*callback
)(coalition_t
, void *, task_t
));
80 void coalition_set_efficient(coalition_t coal
);
82 typedef void (*coalition_iterate_fn_t
)(void*, int, coalition_t
);
83 kern_return_t
coalition_iterate_stackshot(coalition_iterate_fn_t callout
, void *arg
, uint32_t coalition_type
);
85 /* Returns with a reference, or COALITION_NULL.
86 * There is no coalition with id 0.
88 coalition_t
coalition_find_by_id(uint64_t coal_id
);
90 /* Returns with a reference and an activation, or COALITION_NULL.
91 * There is no coalition with id 0.
93 coalition_t
coalition_find_and_activate_by_id(uint64_t coal_id
);
95 void coalition_remove_active(coalition_t coal
);
97 void coalition_release(coalition_t coal
);
100 * The following functions are to be used by the syscall wrapper
101 * in bsd/kern/kern_proc.c, after it has verified the caller's privilege.
105 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
107 * KERN_TERMINATED The coalition was already reaped.
108 * KERN_FAILURE The coalition was not empty or has never been terminated.
110 kern_return_t
coalition_reap_internal(coalition_t coal
);
113 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
115 * KERN_TERMINATED The coalition was already terminated (or even reaped)
116 * KERN_INVALID_NAME The coalition was already reaped.
118 kern_return_t
coalition_request_terminate_internal(coalition_t coal
);
121 * KERN_RESOURCE_SHORTAGE Unable to allocate kernel resources for a
124 kern_return_t
coalition_create_internal(int type
, int role
, boolean_t privileged
, coalition_t
*out
);
126 boolean_t
coalition_term_requested(coalition_t coal
);
127 boolean_t
coalition_is_terminated(coalition_t coal
);
128 boolean_t
coalition_is_reaped(coalition_t coal
);
129 boolean_t
coalition_is_privileged(coalition_t coal
);
130 boolean_t
task_is_in_privileged_coalition(task_t task
, int type
);
132 kern_return_t
coalition_resource_usage_internal(coalition_t coal
, struct coalition_resource_usage
*cru_out
);
134 task_t
kdp_coalition_get_leader(coalition_t coal
);
137 * development/debug interfaces
139 #if DEVELOPMENT || DEBUG
140 int coalition_should_notify(coalition_t coal
);
141 void coalition_set_notify(coalition_t coal
, int notify
);
144 #else /* !CONFIG_COALITIONS */
147 task_coalition_update_gpu_stats(__unused task_t task
,
148 __unused
uint64_t gpu_ns_delta
)
153 static inline boolean_t
154 task_coalition_adjust_focal_count(__unused task_t task
,
156 __unused
uint32_t *new_count
)
161 static inline boolean_t
162 task_coalition_adjust_nonfocal_count(__unused task_t task
,
164 __unused
uint32_t *new_count
)
169 static inline uint32_t
170 task_coalition_focal_count(__unused task_t task
)
176 coalition_for_each_task(__unused coalition_t coal
,
178 __unused
void (*callback
)(coalition_t
, void *, task_t
))
183 #endif /* CONFIG_COALITIONS */
184 #endif /* XNU_KERNEL_PRIVATE */
185 #endif /* _KERN_COALITION_H */