2 * Copyright (c) 2006, 2010 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/cdefs.h>
30 #include <sys/errno.h>
31 #include <sys/msgbuf.h>
32 #include <sys/resource.h>
33 #include <sys/process_policy.h>
34 #include <sys/event.h>
35 #include <mach/message.h>
37 #include "libproc_internal.h"
39 int __proc_info(int callnum
, int pid
, int flavor
, uint64_t arg
, void * buffer
, int buffersize
);
40 __private_extern__
int proc_setthreadname(void * buffer
, int buffersize
);
41 int __process_policy(int scope
, int action
, int policy
, int policy_subtype
, proc_policy_attribute_t
* attrp
, pid_t target_pid
, uint64_t target_threadid
);
42 int proc_rlimit_control(pid_t pid
, int flavor
, void *arg
);
45 proc_listpids(uint32_t type
, uint32_t typeinfo
, void *buffer
, int buffersize
)
49 if ((type
>= PROC_ALL_PIDS
) || (type
<= PROC_PPID_ONLY
)) {
50 if ((retval
= __proc_info(PROC_INFO_CALL_LISTPIDS
, type
, typeinfo
,(uint64_t)0, buffer
, buffersize
)) == -1)
61 proc_listallpids(void * buffer
, int buffersize
)
64 numpids
= proc_listpids(PROC_ALL_PIDS
, (uint32_t)0, buffer
, buffersize
);
69 return(numpids
/sizeof(int));
73 proc_listpgrppids(pid_t pgrpid
, void * buffer
, int buffersize
)
76 numpids
= proc_listpids(PROC_PGRP_ONLY
, (uint32_t)pgrpid
, buffer
, buffersize
);
80 return(numpids
/sizeof(int));
84 proc_listchildpids(pid_t ppid
, void * buffer
, int buffersize
)
87 numpids
= proc_listpids(PROC_PPID_ONLY
, (uint32_t)ppid
, buffer
, buffersize
);
91 return(numpids
/sizeof(int));
96 proc_pidinfo(int pid
, int flavor
, uint64_t arg
, void *buffer
, int buffersize
)
100 if ((retval
= __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, flavor
, arg
, buffer
, buffersize
)) == -1)
108 proc_pidoriginatorinfo(int flavor
, void *buffer
, int buffersize
)
112 if ((retval
= __proc_info(PROC_INFO_CALL_PIDORIGINATORINFO
, getpid(), flavor
, 0, buffer
, buffersize
)) == -1)
119 proc_listcoalitions(int flavor
, int coaltype
, void *buffer
, int buffersize
)
123 if ((retval
= __proc_info(PROC_INFO_CALL_LISTCOALITIONS
, flavor
, coaltype
, 0, buffer
, buffersize
)) == -1)
130 proc_pid_rusage(int pid
, int flavor
, rusage_info_t
*buffer
)
132 return (__proc_info(PROC_INFO_CALL_PIDRUSAGE
, pid
, flavor
, 0, buffer
, 0));
136 proc_setthread_cpupercent(uint8_t percentage
, uint32_t ms_refill
)
140 /* Pack percentage and refill into a 32-bit number to match existing kernel implementation */
141 if ((percentage
>= 100) || (ms_refill
& ~0xffffffU
)) {
146 arg
= ((ms_refill
<< 8) | percentage
);
148 return (proc_rlimit_control(-1, RLIMIT_THREAD_CPULIMITS
, (void *)(uintptr_t)arg
));
152 proc_pidfdinfo(int pid
, int fd
, int flavor
, void * buffer
, int buffersize
)
156 if ((retval
= __proc_info(PROC_INFO_CALL_PIDFDINFO
, pid
, flavor
, (uint64_t)fd
, buffer
, buffersize
)) == -1)
164 proc_pidfileportinfo(int pid
, uint32_t fileport
, int flavor
, void *buffer
, int buffersize
)
168 if ((retval
= __proc_info(PROC_INFO_CALL_PIDFILEPORTINFO
, pid
, flavor
, (uint64_t)fileport
, buffer
, buffersize
)) == -1)
174 proc_piddynkqueueinfo(int pid
, int flavor
, kqueue_id_t kq_id
, void *buffer
, int buffersize
)
178 if ((ret
= __proc_info(PROC_INFO_CALL_PIDDYNKQUEUEINFO
, pid
, flavor
, (uint64_t)kq_id
, buffer
, buffersize
)) == -1) {
186 proc_name(int pid
, void * buffer
, uint32_t buffersize
)
189 struct proc_bsdinfo pbsd
;
192 if (buffersize
< sizeof(pbsd
.pbi_name
)) {
197 retval
= proc_pidinfo(pid
, PROC_PIDTBSDINFO
, (uint64_t)0, &pbsd
, sizeof(struct proc_bsdinfo
));
199 if (pbsd
.pbi_name
[0]) {
200 bcopy(&pbsd
.pbi_name
, buffer
, sizeof(pbsd
.pbi_name
));
202 bcopy(&pbsd
.pbi_comm
, buffer
, sizeof(pbsd
.pbi_comm
));
204 len
= (int)strlen(buffer
);
211 proc_regionfilename(int pid
, uint64_t address
, void * buffer
, uint32_t buffersize
)
214 struct proc_regionwithpathinfo reginfo
;
216 if (buffersize
< MAXPATHLEN
) {
221 retval
= proc_pidinfo(pid
, PROC_PIDREGIONPATHINFO
, (uint64_t)address
, ®info
, sizeof(struct proc_regionwithpathinfo
));
223 return ((int)(strlcpy(buffer
, reginfo
.prp_vip
.vip_path
, MAXPATHLEN
)));
229 proc_kmsgbuf(void * buffer
, uint32_t buffersize
)
233 if ((retval
= __proc_info(PROC_INFO_CALL_KERNMSGBUF
, 0, 0, (uint64_t)0, buffer
, buffersize
)) == -1)
239 proc_pidpath(int pid
, void * buffer
, uint32_t buffersize
)
243 if (buffersize
< PROC_PIDPATHINFO_SIZE
) {
247 if (buffersize
> PROC_PIDPATHINFO_MAXSIZE
) {
252 retval
= __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDPATHINFO
, (uint64_t)0, buffer
, buffersize
);
254 len
= (int)strlen(buffer
);
262 proc_libversion(int *major
, int * minor
)
273 proc_setpcontrol(const int control
)
277 if (control
< PROC_SETPC_NONE
|| control
> PROC_SETPC_TERMINATE
)
280 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_PCONTROL
, (uint64_t)control
, NULL
, 0)) == -1)
287 __private_extern__
int
288 proc_setthreadname(void * buffer
, int buffersize
)
292 retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_THREADNAME
, (uint64_t)0, buffer
, buffersize
);
301 proc_track_dirty(pid_t pid
, uint32_t flags
)
303 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_TRACK
, flags
, NULL
, 0) == -1) {
311 proc_set_dirty(pid_t pid
, bool dirty
)
313 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_SET
, dirty
, NULL
, 0) == -1) {
321 proc_get_dirty(pid_t pid
, uint32_t *flags
)
329 retval
= __proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_GET
, 0, NULL
, 0);
340 proc_clear_dirty(pid_t pid
, uint32_t flags
)
342 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_CLEAR
, flags
, NULL
, 0) == -1) {
350 proc_terminate(pid_t pid
, int *sig
)
358 retval
= __proc_info(PROC_INFO_CALL_TERMINATE
, pid
, 0, 0, NULL
, 0);
369 * XXX the _fatal() variant both checks for an existing monitor
370 * (with important policy effects on first party background apps)
371 * and validates inputs.
374 proc_set_cpumon_params(pid_t pid
, int percentage
, int interval
)
376 proc_policy_cpuusage_attr_t attr
;
378 /* no argument validation ...
379 * task_set_cpuusage() ignores 0 values and squashes negative
380 * values into uint32_t.
383 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
384 attr
.ppattr_cpu_percentage
= percentage
;
385 attr
.ppattr_cpu_attr_interval
= (uint64_t)interval
;
386 attr
.ppattr_cpu_attr_deadline
= 0;
388 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
389 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
393 proc_get_cpumon_params(pid_t pid
, int *percentage
, int *interval
)
395 proc_policy_cpuusage_attr_t attr
;
398 ret
= __process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_GET
, PROC_POLICY_RESOURCE_USAGE
,
399 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0);
401 if ((ret
== 0) && (attr
.ppattr_cpu_attr
== PROC_POLICY_RSRCACT_NOTIFY_EXC
)) {
402 *percentage
= attr
.ppattr_cpu_percentage
;
403 *interval
= (int)attr
.ppattr_cpu_attr_interval
;
413 proc_set_cpumon_defaults(pid_t pid
)
415 proc_policy_cpuusage_attr_t attr
;
417 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
418 attr
.ppattr_cpu_percentage
= PROC_POLICY_CPUMON_DEFAULTS
;
419 attr
.ppattr_cpu_attr_interval
= 0;
420 attr
.ppattr_cpu_attr_deadline
= 0;
422 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
423 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
427 proc_resume_cpumon(pid_t pid
)
429 return __process_policy(PROC_POLICY_SCOPE_PROCESS
,
430 PROC_POLICY_ACTION_ENABLE
,
431 PROC_POLICY_RESOURCE_USAGE
,
432 PROC_POLICY_RUSAGE_CPU
,
437 proc_disable_cpumon(pid_t pid
)
439 proc_policy_cpuusage_attr_t attr
;
441 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
442 attr
.ppattr_cpu_percentage
= PROC_POLICY_CPUMON_DISABLE
;
443 attr
.ppattr_cpu_attr_interval
= 0;
444 attr
.ppattr_cpu_attr_deadline
= 0;
446 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
447 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
452 * Turn on the CPU usage monitor using the supplied parameters, and make
453 * violations of the monitor fatal.
455 * Returns: 0 on success;
456 * -1 on failure and sets errno
459 proc_set_cpumon_params_fatal(pid_t pid
, int percentage
, int interval
)
461 int current_percentage
= 0;
462 int current_interval
= 0; /* intervals are in seconds */
465 if ((percentage
<= 0) || (interval
<= 0)) {
471 * Do a simple query to see if CPU monitoring is
472 * already active. If either the percentage or the
473 * interval is nonzero, then CPU monitoring is
474 * already in use for this process.
476 * XXX: need set...() and set..fatal() to behave similarly.
477 * Currently, this check prevents 1st party apps (which get a
478 * default non-fatal monitor) not to get a fatal monitor.
480 (void)proc_get_cpumon_params(pid
, ¤t_percentage
, ¤t_interval
);
481 if (current_percentage
|| current_interval
)
484 * The CPU monitor appears to be active.
485 * We choose not to disturb those settings.
491 if ((ret
= proc_set_cpumon_params(pid
, percentage
, interval
)) != 0) {
492 /* Failed to activate the CPU monitor */
496 if ((ret
= proc_rlimit_control(pid
, RLIMIT_CPU_USAGE_MONITOR
, CPUMON_MAKE_FATAL
)) != 0) {
497 /* Failed to set termination, back out the CPU monitor settings. */
498 (void)proc_disable_cpumon(pid
);
505 proc_set_wakemon_params(pid_t pid
, int rate_hz
, int flags __unused
)
507 struct proc_rlimit_control_wakeupmon params
;
509 params
.wm_flags
= WAKEMON_ENABLE
;
510 params
.wm_rate
= rate_hz
;
512 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
515 #ifndef WAKEMON_GET_PARAMS
516 #define WAKEMON_GET_PARAMS 0x4
517 #define WAKEMON_SET_DEFAULTS 0x8
521 proc_get_wakemon_params(pid_t pid
, int *rate_hz
, int *flags
)
523 struct proc_rlimit_control_wakeupmon params
;
526 params
.wm_flags
= WAKEMON_GET_PARAMS
;
528 if ((error
= proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
)) != 0) {
532 *rate_hz
= params
.wm_rate
;
533 *flags
= params
.wm_flags
;
539 proc_set_wakemon_defaults(pid_t pid
)
541 struct proc_rlimit_control_wakeupmon params
;
543 params
.wm_flags
= WAKEMON_ENABLE
| WAKEMON_SET_DEFAULTS
;
546 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
550 proc_disable_wakemon(pid_t pid
)
552 struct proc_rlimit_control_wakeupmon params
;
554 params
.wm_flags
= WAKEMON_DISABLE
;
557 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
561 proc_list_uptrs(int pid
, uint64_t *buf
, uint32_t bufsz
)
563 return __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDLISTUPTRS
, 0,
568 proc_list_dynkqueueids(int pid
, kqueue_id_t
*buf
, uint32_t bufsz
)
570 return __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDLISTDYNKQUEUES
, 0,
576 proc_setcpu_percentage(pid_t pid
, int action
, int percentage
)
578 proc_policy_cpuusage_attr_t attr
;
580 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
581 attr
.ppattr_cpu_attr
= action
;
582 attr
.ppattr_cpu_percentage
= percentage
;
583 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_RESOURCE_USAGE
, PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, (uint64_t)0) != -1)
590 proc_clear_cpulimits(pid_t pid
)
592 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_RESTORE
, PROC_POLICY_RESOURCE_USAGE
, PROC_POLICY_RUSAGE_CPU
, NULL
, pid
, (uint64_t)0) != -1)
598 #if TARGET_OS_EMBEDDED
601 proc_setcpu_deadline(pid_t pid
, int action
, uint64_t deadline
)
603 proc_policy_cpuusage_attr_t attr
;
605 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
606 attr
.ppattr_cpu_attr
= action
;
607 attr
.ppattr_cpu_attr_deadline
= deadline
;
608 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_RESOURCE_USAGE
, PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, (uint64_t)0) != -1)
616 proc_setcpu_percentage_withdeadline(pid_t pid
, int action
, int percentage
, uint64_t deadline
)
618 proc_policy_cpuusage_attr_t attr
;
620 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
621 attr
.ppattr_cpu_attr
= action
;
622 attr
.ppattr_cpu_percentage
= percentage
;
623 attr
.ppattr_cpu_attr_deadline
= deadline
;
624 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_RESOURCE_USAGE
, PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, (uint64_t)0) != -1)
631 proc_appstate(int pid
, int * appstatep
)
635 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_GET
, PROC_POLICY_APP_LIFECYCLE
, PROC_POLICY_APPLIFE_STATE
, (proc_policy_attribute_t
*)&state
, pid
, (uint64_t)0) != -1) {
636 if (appstatep
!= NULL
)
645 proc_setappstate(int pid
, int appstate
)
647 int state
= appstate
;
650 case PROC_APPSTATE_NONE
:
651 case PROC_APPSTATE_ACTIVE
:
652 case PROC_APPSTATE_INACTIVE
:
653 case PROC_APPSTATE_BACKGROUND
:
654 case PROC_APPSTATE_NONUI
:
659 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_APP_LIFECYCLE
, PROC_POLICY_APPLIFE_STATE
, (proc_policy_attribute_t
*)&state
, pid
, (uint64_t)0) != -1)
666 proc_devstatusnotify(int devicestatus
)
668 int state
= devicestatus
;
670 switch (devicestatus
) {
671 case PROC_DEVSTATUS_SHORTTERM
:
672 case PROC_DEVSTATUS_LONGTERM
:
678 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_APP_LIFECYCLE
, PROC_POLICY_APPLIFE_DEVSTATUS
, (proc_policy_attribute_t
*)&state
, getpid(), (uint64_t)0) != -1) {
686 proc_pidbind(int pid
, uint64_t threadid
, int bind
)
692 case PROC_PIDBIND_CLEAR
:
693 passpid
= getpid(); /* ignore pid on clear */
695 case PROC_PIDBIND_SET
:
700 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_APPLY
, PROC_POLICY_APP_LIFECYCLE
, PROC_POLICY_APPLIFE_PIDBIND
, (proc_policy_attribute_t
*)&state
, passpid
, threadid
) != -1)
707 proc_can_use_foreground_hw(int pid
, uint32_t *reason
)
709 return __proc_info(PROC_INFO_CALL_CANUSEFGHW
, pid
, 0, NULL
, reason
, sizeof(*reason
));
711 #endif /* TARGET_OS_EMBEDDED */
714 /* Donate importance to adaptive processes from this process */
716 proc_donate_importance_boost()
720 #if TARGET_OS_EMBEDDED
721 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
722 PROC_POLICY_ACTION_ENABLE
,
724 PROC_POLICY_IOS_DONATEIMP
,
725 NULL
, getpid(), (uint64_t)0);
726 #else /* TARGET_OS_EMBEDDED */
727 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
728 PROC_POLICY_ACTION_SET
,
730 PROC_POLICY_IMP_DONATION
,
732 #endif /* TARGET_OS_EMBEDDED */
740 static __attribute__((noinline
)) void
741 proc_importance_bad_assertion(char *reason
) {
746 * Use the address of these variables as the token. This way, they can be
747 * printed in the debugger as useful names.
749 uint64_t important_boost_assertion_token
= 0xfafafafafafafafa;
750 uint64_t normal_boost_assertion_token
= 0xfbfbfbfbfbfbfbfb;
751 uint64_t non_boost_assertion_token
= 0xfcfcfcfcfcfcfcfc;
752 uint64_t denap_boost_assertion_token
= 0xfdfdfdfdfdfdfdfd;
755 * Accept the boost on a message, or request another boost assertion
756 * if we have already accepted the implicit boost for this message.
758 * Returns EOVERFLOW if an attempt is made to take an extra assertion when not boosted.
760 * Returns EIO if the message was not a boosting message.
761 * TODO: Return a 'non-boost' token instead.
764 proc_importance_assertion_begin_with_msg(mach_msg_header_t
*msg
,
765 __unused mach_msg_trailer_t
*trailer
,
766 uint64_t *assertion_token
)
770 if (assertion_token
== NULL
)
773 #define LEGACYBOOSTMASK (MACH_MSGH_BITS_VOUCHER_MASK | MACH_MSGH_BITS_RAISEIMP)
774 #define LEGACYBOOSTED(m) (((m)->msgh_bits & LEGACYBOOSTMASK) == MACH_MSGH_BITS_RAISEIMP)
776 /* Is this a legacy boosted message? */
777 if (LEGACYBOOSTED(msg
)) {
780 * Have we accepted the implicit boost for this message yet?
781 * If we haven't accepted it yet, no need to call into kernel.
783 if ((msg
->msgh_bits
& MACH_MSGH_BITS_IMPHOLDASRT
) == 0) {
784 msg
->msgh_bits
|= MACH_MSGH_BITS_IMPHOLDASRT
;
785 *assertion_token
= (uint64_t) &important_boost_assertion_token
;
789 /* Request an additional boost count */
790 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
791 PROC_POLICY_ACTION_HOLD
,
793 PROC_POLICY_IMP_IMPORTANT
,
796 *assertion_token
= (uint64_t) &important_boost_assertion_token
;
798 } else if (errno
== EOVERFLOW
) {
799 proc_importance_bad_assertion("Attempted to take assertion while not boosted");
811 * Drop a boost assertion.
812 * Returns EOVERFLOW on boost assertion underflow.
815 proc_importance_assertion_complete(uint64_t assertion_token
)
819 if (assertion_token
== 0)
822 if (assertion_token
== (uint64_t) &important_boost_assertion_token
) {
823 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
824 PROC_POLICY_ACTION_DROP
,
826 PROC_POLICY_IMP_IMPORTANT
,
830 } else if (errno
== EOVERFLOW
) {
831 proc_importance_bad_assertion("Attempted to drop too many assertions");
837 proc_importance_bad_assertion("Attempted to drop assertion with invalid token");
843 * Accept the De-Nap boost on a message, or request another boost assertion
844 * if we have already accepted the implicit boost for this message.
846 * Interface is deprecated before it really got started - just as synonym
847 * for proc_importance_assertion_begin_with_msg() now.
850 proc_denap_assertion_begin_with_msg(mach_msg_header_t
*msg
,
851 uint64_t *assertion_token
)
853 #pragma clang diagnostic push
854 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
855 return proc_importance_assertion_begin_with_msg(msg
, NULL
, assertion_token
);
856 #pragma clang diagnostic pop
861 * Drop a denap boost assertion.
863 * Interface is deprecated before it really got started - just a synonym
864 * for proc_importance_assertion_complete() now.
867 proc_denap_assertion_complete(uint64_t assertion_token
)
869 return proc_importance_assertion_complete(assertion_token
);
872 #if !TARGET_OS_EMBEDDED
875 proc_clear_vmpressure(pid_t pid
)
877 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_RESTORE
, PROC_POLICY_RESOURCE_STARVATION
, PROC_POLICY_RS_VIRTUALMEM
, NULL
, pid
, (uint64_t)0) != -1)
883 /* set the current process as one who can resume suspended processes due to low virtual memory. Need to be root */
885 proc_set_owner_vmpressure(void)
889 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_VMRSRCOWNER
, (uint64_t)0, NULL
, 0)) == -1)
895 /* mark yourself to delay idle sleep on disk IO */
897 proc_set_delayidlesleep(void)
901 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_DELAYIDLESLEEP
, (uint64_t)1, NULL
, 0)) == -1)
907 /* Reset yourself to delay idle sleep on disk IO, if already set */
909 proc_clear_delayidlesleep(void)
913 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_DELAYIDLESLEEP
, (uint64_t)0, NULL
, 0)) == -1)
919 /* disable the launch time backgroudn policy and restore the process to default group */
921 proc_disable_apptype(pid_t pid
, int apptype
)
924 case PROC_POLICY_OSX_APPTYPE_TAL
:
925 case PROC_POLICY_OSX_APPTYPE_DASHCLIENT
:
931 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_DISABLE
, PROC_POLICY_APPTYPE
, apptype
, NULL
, pid
, (uint64_t)0) != -1)
938 /* re-enable the launch time background policy if it had been disabled. */
940 proc_enable_apptype(pid_t pid
, int apptype
)
943 case PROC_POLICY_OSX_APPTYPE_TAL
:
944 case PROC_POLICY_OSX_APPTYPE_DASHCLIENT
:
951 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_ENABLE
, PROC_POLICY_APPTYPE
, apptype
, NULL
, pid
, (uint64_t)0) != -1)
958 #if !TARGET_IPHONE_SIMULATOR
961 proc_suppress(__unused pid_t pid
, __unused
uint64_t *generation
)
966 #endif /* !TARGET_IPHONE_SIMULATOR */
968 #endif /* !TARGET_OS_EMBEDDED */