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