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