]>
Commit | Line | Data |
---|---|---|
fe8ab488 A |
1 | /* |
2 | * Copyright (c) 2013 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
14 | * | |
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 | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _KERN_COALITION_H_ | |
30 | #define _KERN_COALITION_H_ | |
31 | ||
3e170ce0 | 32 | /* only kernel-private interfaces */ |
fe8ab488 | 33 | #ifdef XNU_KERNEL_PRIVATE |
3e170ce0 | 34 | #include <mach/coalition.h> |
fe8ab488 | 35 | |
3e170ce0 A |
36 | #if CONFIG_COALITIONS |
37 | ||
38 | void coalitions_init(void); | |
fe8ab488 A |
39 | |
40 | /* These may return: | |
41 | * KERN_ALREADY_IN_SET task is already in a coalition (maybe this one, maybe a different one) | |
42 | * KERN_TERMINATED coalition is already terminated (so it may not adopt any more tasks) | |
43 | */ | |
3e170ce0 A |
44 | kern_return_t coalitions_adopt_task(coalition_t *coaltions, task_t task); |
45 | kern_return_t coalitions_adopt_init_task(task_t task); | |
fe8ab488 A |
46 | |
47 | /* Currently, no error conditions. If task is not already in a coalition, | |
48 | * KERN_SUCCESS is returned because removing it did not fail. | |
49 | */ | |
3e170ce0 A |
50 | kern_return_t coalitions_remove_task(task_t task); |
51 | void task_release_coalitions(task_t task); | |
52 | ||
53 | /* | |
54 | * | |
55 | */ | |
56 | kern_return_t coalitions_set_roles(coalition_t coalitions[COALITION_NUM_TYPES], | |
57 | task_t task, int roles[COALITION_NUM_TYPES]); | |
fe8ab488 A |
58 | |
59 | uint64_t coalition_id(coalition_t coal); | |
3e170ce0 A |
60 | void task_coalition_ids(task_t task, uint64_t ids[COALITION_NUM_TYPES]); |
61 | void task_coalition_roles(task_t task, int roles[COALITION_NUM_TYPES]); | |
62 | int coalition_type(coalition_t coal); | |
63 | ||
64 | void task_coalition_update_gpu_stats(task_t task, uint64_t gpu_ns_delta); | |
65 | uint32_t task_coalition_adjust_focal_count(task_t task, int count); | |
66 | uint32_t task_coalition_focal_count(task_t task); | |
67 | uint32_t task_coalition_adjust_nonfocal_count(task_t task, int count); | |
68 | uint32_t task_coalition_nonfocal_count(task_t task); | |
69 | ||
70 | void coalition_for_each_task(coalition_t coal, void *ctx, | |
71 | void (*callback)(coalition_t, void *, task_t)); | |
fe8ab488 A |
72 | |
73 | /* Returns with a reference, or COALITION_NULL. | |
74 | * There is no coalition with id 0. | |
75 | */ | |
76 | coalition_t coalition_find_by_id(uint64_t coal_id); | |
77 | ||
78 | /* Returns with a reference and an activation, or COALITION_NULL. | |
79 | * There is no coalition with id 0. | |
80 | */ | |
81 | coalition_t coalition_find_and_activate_by_id(uint64_t coal_id); | |
82 | ||
fe8ab488 A |
83 | void coalition_remove_active(coalition_t coal); |
84 | ||
85 | void coalition_release(coalition_t coal); | |
86 | ||
87 | /* | |
88 | * The following functions are to be used by the syscall wrapper | |
89 | * in bsd/kern/kern_proc.c, after it has verified the caller's privilege. | |
90 | */ | |
91 | ||
92 | /* This may return: | |
93 | * KERN_DEFAULT_SET The default coalition, which contains the kernel, may | |
94 | * not be terminated. | |
95 | * KERN_TERMINATED The coalition was already reaped. | |
96 | * KERN_FAILURE The coalition was not empty or has never been terminated. | |
97 | */ | |
98 | kern_return_t coalition_reap_internal(coalition_t coal); | |
99 | ||
100 | /* This may return: | |
101 | * KERN_DEFAULT_SET The default coalition, which contains the kernel, may | |
102 | * not be terminated. | |
103 | * KERN_TERMINATED The coalition was already terminated (or even reaped) | |
104 | * KERN_INVALID_NAME The coalition was already reaped. | |
105 | */ | |
106 | kern_return_t coalition_request_terminate_internal(coalition_t coal); | |
107 | ||
108 | /* This may return: | |
109 | * KERN_RESOURCE_SHORTAGE Unable to allocate kernel resources for a | |
110 | * new coalition. | |
111 | */ | |
3e170ce0 | 112 | kern_return_t coalition_create_internal(int type, boolean_t privileged, coalition_t *out); |
fe8ab488 A |
113 | |
114 | boolean_t coalition_is_privileged(coalition_t coal); | |
3e170ce0 | 115 | boolean_t task_is_in_privileged_coalition(task_t task, int type); |
fe8ab488 A |
116 | |
117 | kern_return_t coalition_resource_usage_internal(coalition_t coal, struct coalition_resource_usage *cru_out); | |
118 | ||
3e170ce0 A |
119 | /* |
120 | * development/debug interfaces | |
121 | */ | |
122 | #if defined(DEVELOPMENT) || defined(DEBUG) | |
123 | int coalition_should_notify(coalition_t coal); | |
124 | void coalition_set_notify(coalition_t coal, int notify); | |
125 | #endif | |
126 | ||
127 | #else /* !CONFIG_COALITIONS */ | |
128 | ||
129 | static inline void task_coalition_update_gpu_stats(__unused task_t task, | |
130 | __unused uint64_t gpu_ns_delta) | |
131 | { | |
132 | return; | |
133 | } | |
134 | ||
135 | static inline uint32_t task_coalition_adjust_focal_count(__unused task_t task, | |
136 | __unused int count) | |
137 | { | |
138 | return 0; | |
139 | } | |
140 | ||
141 | static inline uint32_t task_coalition_adjust_nonfocal_count(__unused task_t task, | |
142 | __unused int count) | |
143 | { | |
144 | return 0; | |
145 | } | |
146 | ||
147 | static inline uint32_t task_coalition_focal_count(__unused task_t task) | |
148 | { | |
149 | return 0; | |
150 | } | |
151 | ||
152 | static inline void coalition_for_each_task(__unused coalition_t coal, | |
153 | __unused void *ctx, | |
154 | __unused void (*callback)(coalition_t, void *, task_t)) | |
155 | { | |
156 | return; | |
157 | } | |
158 | ||
159 | #endif /* CONFIG_COALITIONS */ | |
fe8ab488 | 160 | #endif /* XNU_KERNEL_PRIVATE */ |
fe8ab488 | 161 | #endif /* _KERN_COALITION_H */ |