]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/coalition.h
38bdefd58f449c225a969eeec55c5147dea8c4e3
[apple/xnu.git] / osfmk / kern / coalition.h
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
32 #ifdef XNU_KERNEL_PRIVATE
33
34 void coalition_init(void);
35
36 /* These may return:
37 * KERN_ALREADY_IN_SET task is already in a coalition (maybe this one, maybe a different one)
38 * KERN_TERMINATED coalition is already terminated (so it may not adopt any more tasks)
39 */
40 kern_return_t coalition_adopt_task(coalition_t coal, task_t task);
41 kern_return_t coalition_default_adopt_task(task_t task);
42
43 /* Currently, no error conditions. If task is not already in a coalition,
44 * KERN_SUCCESS is returned because removing it did not fail.
45 */
46 kern_return_t coalition_remove_task(task_t task);
47
48 uint64_t coalition_id(coalition_t coal);
49 uint64_t task_coalition_id(task_t task);
50
51 /* Returns with a reference, or COALITION_NULL.
52 * There is no coalition with id 0.
53 */
54 coalition_t coalition_find_by_id(uint64_t coal_id);
55
56 /* Returns with a reference and an activation, or COALITION_NULL.
57 * There is no coalition with id 0.
58 */
59 coalition_t coalition_find_and_activate_by_id(uint64_t coal_id);
60
61 /* This may return:
62 * KERN_TERMINATED coalition is terminated
63 * This will panic if the coalition is already reaped, which implies
64 * that it wasn't active.
65 */
66 kern_return_t coalition_extend_active(coalition_t coal);
67
68 void coalition_remove_active(coalition_t coal);
69
70 void coalition_release(coalition_t coal);
71
72 /*
73 * The following functions are to be used by the syscall wrapper
74 * in bsd/kern/kern_proc.c, after it has verified the caller's privilege.
75 */
76
77 /* This may return:
78 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
79 * not be terminated.
80 * KERN_TERMINATED The coalition was already reaped.
81 * KERN_FAILURE The coalition was not empty or has never been terminated.
82 */
83 kern_return_t coalition_reap_internal(coalition_t coal);
84
85 /* This may return:
86 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
87 * not be terminated.
88 * KERN_TERMINATED The coalition was already terminated (or even reaped)
89 * KERN_INVALID_NAME The coalition was already reaped.
90 */
91 kern_return_t coalition_request_terminate_internal(coalition_t coal);
92
93 /* This may return:
94 * KERN_RESOURCE_SHORTAGE Unable to allocate kernel resources for a
95 * new coalition.
96 */
97 kern_return_t coalition_create_internal(coalition_t *out, boolean_t privileged);
98
99 boolean_t coalition_is_privileged(coalition_t coal);
100 boolean_t task_is_in_privileged_coalition(task_t task);
101
102 /* This struct is also defined in bsd/sys/coalition.h. Keep in sync. */
103 struct coalition_resource_usage {
104 uint64_t tasks_started;
105 uint64_t tasks_exited;
106 uint64_t time_nonempty;
107 uint64_t cpu_time;
108 uint64_t interrupt_wakeups;
109 uint64_t platform_idle_wakeups;
110 uint64_t bytesread;
111 uint64_t byteswritten;
112 uint64_t gpu_time;
113 };
114
115 kern_return_t coalition_resource_usage_internal(coalition_t coal, struct coalition_resource_usage *cru_out);
116
117 ledger_t coalition_get_ledger(coalition_t coal);
118
119 #endif /* XNU_KERNEL_PRIVATE */
120
121 #endif /* _KERN_COALITION_H */