]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/wrappers/libproc/libproc_internal.h
xnu-4903.221.2.tar.gz
[apple/xnu.git] / libsyscall / wrappers / libproc / libproc_internal.h
1 /*
2 * Copyright (c) 2010-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #ifndef _LIBPROC_INTERNALH_
24 #define _LIBPROC_INTERNALH_
25
26 #include <TargetConditionals.h>
27
28 #include <sys/cdefs.h>
29 #include <libproc.h>
30 #include <mach/message.h>
31
32 __BEGIN_DECLS
33
34 /* CPU monitor action */
35 #define PROC_SETCPU_ACTION_NONE 0
36 #define PROC_SETCPU_ACTION_THROTTLE 1
37
38 int proc_setcpu_percentage(pid_t pid, int action, int percentage) __OSX_AVAILABLE_STARTING(__MAC_10_12_2, __IPHONE_5_0);
39 int proc_clear_cpulimits(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_12_2, __IPHONE_5_0);
40
41 /* CPU limits, applies to current thread only. 0% unsets limit */
42 int proc_setthread_cpupercent(uint8_t percentage, uint32_t ms_refill) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_5_0);
43
44 #if TARGET_OS_EMBEDDED
45
46 /* CPU monitor action, continued */
47 #define PROC_SETCPU_ACTION_SUSPEND 2
48 #define PROC_SETCPU_ACTION_TERMINATE 3
49 #define PROC_SETCPU_ACTION_NOTIFY 4
50
51 int proc_setcpu_deadline(pid_t pid, int action, uint64_t deadline) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
52 int proc_setcpu_percentage_withdeadline(pid_t pid, int action, int percentage, uint64_t deadline) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
53
54 #define PROC_APPSTATE_NONE 0
55 #define PROC_APPSTATE_ACTIVE 1
56 #define PROC_APPSTATE_BACKGROUND 2
57 #define PROC_APPSTATE_NONUI 3
58 #define PROC_APPSTATE_INACTIVE 4
59
60 int proc_setappstate(int pid, int appstate);
61 int proc_appstate(int pid, int * appstatep);
62
63 #define PROC_DEVSTATUS_SHORTTERM 1
64 #define PROC_DEVSTATUS_LONGTERM 2
65
66 int proc_devstatusnotify(int devicestatus);
67
68 #define PROC_PIDBIND_CLEAR 0
69 #define PROC_PIDBIND_SET 1
70 int proc_pidbind(int pid, uint64_t threadid, int bind);
71
72 /*
73 * High level check to see if a process is allowed to use HW
74 * resources reserved for foreground applications.
75 * Returns:
76 * 1 if the PID is allowed
77 * 0 if the PID is NOT allowed
78 * <0 on error
79 *
80 * When 0 is returned, 'reason' is set to indicate why
81 * the pid is not allowed to use foreground-only hardware.
82 * Reasons returned by the kernel are found in <sys/proc_info.h>
83 *
84 * When <0 is returned, errno indicates the reason
85 * for the failure.
86 */
87 int proc_can_use_foreground_hw(int pid, uint32_t *reason);
88
89 #else /* TARGET_OS_EMBEDDED */
90
91 /* resume the process suspend due to low VM resource */
92 int proc_clear_vmpressure(pid_t pid);
93 /* set self as the one who is going to resume suspended processes due to low VM. Need to be root */
94 int proc_set_owner_vmpressure(void);
95
96 /* mark yourself to delay idle sleep on disk IO */
97 int proc_set_delayidlesleep(void);
98 /* Reset yourself to delay idle sleep on disk IO, if already set */
99 int proc_clear_delayidlesleep(void);
100
101
102 /* sub policies for PROC_POLICY_APPTYPE */
103 #define PROC_POLICY_OSX_APPTYPE_NONE 0
104 #define PROC_POLICY_OSX_APPTYPE_TAL 1 /* TAL based launched */
105 #define PROC_POLICY_OSX_APPTYPE_WIDGET 2 /* for dashboard client */
106 #define PROC_POLICY_OSX_APPTYPE_DASHCLIENT 2 /* rename to move away from widget */
107
108 /*
109 * Resumes the backgrounded TAL or dashboard client. Only priv users can disable TAL apps.
110 * Valid apptype are PROC_POLICY_OSX_APPTYPE_DASHCLIENT and PROC_POLICY_OSX_APPTYPE_TAL.
111 * Returns 0 on success otherwise appropriate error code.
112 */
113 int proc_disable_apptype(pid_t pid, int apptype);
114 int proc_enable_apptype(pid_t pid, int apptype);
115
116 #endif /* TARGET_OS_EMBEDDED */
117
118 /* mark process as importance donating */
119 int proc_donate_importance_boost(void);
120
121 /* DEPRECATED: supported for backward compatibility only */
122 /* check the message for an importance boost and take an assertion on it */
123 int proc_importance_assertion_begin_with_msg(mach_msg_header_t *msg,
124 mach_msg_trailer_t *trailer,
125 uint64_t *assertion_token) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_8, __MAC_10_10, __IPHONE_6_0, __IPHONE_8_0);
126
127 /* DEPRECATED: supported for backward compatibility only */
128 /* drop an assertion */
129 int proc_importance_assertion_complete(uint64_t assertion_handle);
130
131 /* check the message for a App De-Nap boost and take an assertion on it */
132 int proc_denap_assertion_begin_with_msg(mach_msg_header_t *msg,
133 uint64_t *assertion_token);
134
135 /* drop a de-nap assertion */
136 int proc_denap_assertion_complete(uint64_t assertion_handle);
137
138 /* ongoing percent-over-time CPU monitor */
139 int proc_set_cpumon_defaults(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
140 int proc_set_cpumon_params(pid_t pid, int percentage, int interval) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
141 int proc_set_cpumon_params_fatal(pid_t pid, int percentage, int interval) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
142
143 int proc_get_cpumon_params(pid_t pid, int *percentage, int *interval) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
144 int proc_resume_cpumon(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);
145 int proc_disable_cpumon(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
146
147 /* ongoing wakes/second monitor */
148 int proc_set_wakemon_defaults(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
149 int proc_set_wakemon_params(pid_t pid, int rate_hz, int flags) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
150 int proc_get_wakemon_params(pid_t pid, int *rate_hz, int *flags) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
151 int proc_disable_wakemon(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
152
153 int proc_reset_footprint_interval(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_14, __IPHONE_12_0);
154
155 /* request trace buffer collection */
156 int proc_trace_log(pid_t pid, uint64_t uniqueid) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
157
158 /* proc_info call to get the originator information */
159 int proc_pidoriginatorinfo(int flavor, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
160
161 int proc_listcoalitions(int flavor, int coaltype, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_8_3);
162
163 #if !TARGET_IPHONE_SIMULATOR
164
165 #define PROC_SUPPRESS_SUCCESS (0)
166 #define PROC_SUPPRESS_BAD_ARGUMENTS (-1)
167 #define PROC_SUPPRESS_OLD_GENERATION (-2)
168 #define PROC_SUPPRESS_ALREADY_SUPPRESSED (-3)
169
170 int proc_suppress(pid_t pid, uint64_t *generation);
171 #endif /* !TARGET_IPHONE_SIMULATOR */
172
173 __END_DECLS
174
175 #endif /* _LIBPROC_INTERNALH_ */
176