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