1/*
2 * Copyright (c) 2010 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
31__BEGIN_DECLS
32
33#if TARGET_OS_EMBEDDED
34
35#define PROC_SETCPU_ACTION_NONE		0
36#define PROC_SETCPU_ACTION_THROTTLE	1
37#define PROC_SETCPU_ACTION_SUSPEND	2
38#define PROC_SETCPU_ACTION_TERMINATE	3
39#define PROC_SETCPU_ACTION_NOTIFY	4
40
41int proc_setcpu_percentage(pid_t pid, int action, int percentage) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
42int proc_setcpu_deadline(pid_t pid, int action, uint64_t deadline) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
43int proc_setcpu_percentage_withdeadline(pid_t pid, int action, int percentage, uint64_t deadline) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
44int proc_clear_cpulimits(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);
45
46#define PROC_APPSTATE_NONE		0
47#define PROC_APPSTATE_ACTIVE		1
48#define PROC_APPSTATE_BACKGROUND	2
49#define PROC_APPSTATE_NONUI		3
50#define PROC_APPSTATE_INACTIVE		4
51
52int proc_setappstate(int pid, int appstate);
53int proc_appstate(int pid, int * appstatep);
54
55#define PROC_DEVSTATUS_SHORTTERM	1
56#define PROC_DEVSTATUS_LONGTERM		2
57
58int proc_devstatusnotify(int devicestatus);
59
60#define PROC_PIDBIND_CLEAR	0
61#define PROC_PIDBIND_SET	1
62int proc_pidbind(int pid, uint64_t threadid, int bind);
63
64#else /* TARGET_OS_EMBEDDED */
65
66/* resume the process suspend due to low VM resource */
67int proc_clear_vmpressure(pid_t pid);
68/* set self as the one who is going to resume suspended processes due to low VM. Need to be root */
69int proc_set_owner_vmpressure(void);
70
71/* mark yourself to delay idle sleep on disk IO */
72int proc_set_delayidlesleep(void);
73/* Reset yourself to delay idle sleep on disk IO, if already set */
74int proc_clear_delayidlesleep(void);
75
76
77/* sub policies for PROC_POLICY_APPTYPE */
78#define PROC_POLICY_OSX_APPTYPE_NONE            0
79#define PROC_POLICY_OSX_APPTYPE_TAL             1       /* TAL based launched */
80#define PROC_POLICY_OSX_APPTYPE_WIDGET          2       /* for dashboard client */
81#define PROC_POLICY_OSX_APPTYPE_DASHCLIENT      2       /* rename to move away from widget */
82
83/*
84 * Resumes the backgrounded TAL or dashboard client. Only priv users can disable TAL apps.
85 * Valid apptype are PROC_POLICY_OSX_APPTYPE_DASHCLIENT and PROC_POLICY_OSX_APPTYPE_TAL.
86 * Returns 0 on success otherwise appropriate error code.
87 */
88int proc_disable_apptype(pid_t pid, int apptype);
89int proc_enable_apptype(pid_t pid, int apptype);
90
91#endif /* TARGET_OS_EMBEDDED */
92
93/* mark process as importance donating */
94int proc_donate_importance_boost(void);
95
96/* check the message for an importance boost and take an assertion on it */
97int proc_importance_assertion_begin_with_msg(mach_msg_header_t  *msg,
98											 mach_msg_trailer_t *trailer,
99											 uint64_t *assertion_token);
100
101/* drop an assertion */
102int proc_importance_assertion_complete(uint64_t assertion_handle);
103
104int proc_set_cpumon_params(pid_t pid, int percentage, int interval) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
105int proc_get_cpumon_params(pid_t pid, int *percentage, int *interval) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
106int proc_set_cpumon_defaults(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
107int proc_disable_cpumon(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0);
108
109int proc_set_wakemon_params(pid_t pid, int rate_hz, int flags) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
110int proc_get_wakemon_params(pid_t pid, int *rate_hz, int *flags) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
111int proc_set_wakemon_defaults(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
112int proc_disable_wakemon(pid_t pid) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
113
114#if !TARGET_IPHONE_SIMULATOR
115
116#define PROC_SUPPRESS_SUCCESS                (0)
117#define PROC_SUPPRESS_BAD_ARGUMENTS         (-1)
118#define PROC_SUPPRESS_OLD_GENERATION        (-2)
119#define PROC_SUPPRESS_ALREADY_SUPPRESSED    (-3)
120
121int proc_suppress(pid_t pid, uint64_t *generation);
122#endif /* !TARGET_IPHONE_SIMULATOR */
123
124__END_DECLS
125
126#endif /* _LIBPROC_INTERNALH_ */
127
128