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