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_udata_info(int pid
, int flavor
, void *buffer
, int buffersize
)
188 return (__proc_info(PROC_INFO_CALL_UDATA_INFO
, pid
, flavor
, 0, buffer
, buffersize
));
192 proc_name(int pid
, void * buffer
, uint32_t buffersize
)
195 struct proc_bsdinfo pbsd
;
198 if (buffersize
< sizeof(pbsd
.pbi_name
)) {
203 retval
= proc_pidinfo(pid
, PROC_PIDTBSDINFO
, (uint64_t)0, &pbsd
, sizeof(struct proc_bsdinfo
));
205 if (pbsd
.pbi_name
[0]) {
206 bcopy(&pbsd
.pbi_name
, buffer
, sizeof(pbsd
.pbi_name
));
208 bcopy(&pbsd
.pbi_comm
, buffer
, sizeof(pbsd
.pbi_comm
));
210 len
= (int)strlen(buffer
);
217 proc_regionfilename(int pid
, uint64_t address
, void * buffer
, uint32_t buffersize
)
220 struct proc_regionwithpathinfo reginfo
;
222 if (buffersize
< MAXPATHLEN
) {
227 retval
= proc_pidinfo(pid
, PROC_PIDREGIONPATHINFO2
, (uint64_t)address
, ®info
, sizeof(struct proc_regionwithpathinfo
));
229 return ((int)(strlcpy(buffer
, reginfo
.prp_vip
.vip_path
, MAXPATHLEN
)));
235 proc_kmsgbuf(void * buffer
, uint32_t buffersize
)
239 if ((retval
= __proc_info(PROC_INFO_CALL_KERNMSGBUF
, 0, 0, (uint64_t)0, buffer
, buffersize
)) == -1)
245 proc_pidpath(int pid
, void * buffer
, uint32_t buffersize
)
249 if (buffersize
< PROC_PIDPATHINFO_SIZE
) {
253 if (buffersize
> PROC_PIDPATHINFO_MAXSIZE
) {
258 retval
= __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDPATHINFO
, (uint64_t)0, buffer
, buffersize
);
260 len
= (int)strlen(buffer
);
268 proc_libversion(int *major
, int * minor
)
279 proc_setpcontrol(const int control
)
283 if (control
< PROC_SETPC_NONE
|| control
> PROC_SETPC_TERMINATE
)
286 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_PCONTROL
, (uint64_t)control
, NULL
, 0)) == -1)
293 __private_extern__
int
294 proc_setthreadname(void * buffer
, int buffersize
)
298 retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_THREADNAME
, (uint64_t)0, buffer
, buffersize
);
307 proc_track_dirty(pid_t pid
, uint32_t flags
)
309 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_TRACK
, flags
, NULL
, 0) == -1) {
317 proc_set_dirty(pid_t pid
, bool dirty
)
319 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_SET
, dirty
, NULL
, 0) == -1) {
327 proc_get_dirty(pid_t pid
, uint32_t *flags
)
335 retval
= __proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_GET
, 0, NULL
, 0);
346 proc_clear_dirty(pid_t pid
, uint32_t flags
)
348 if (__proc_info(PROC_INFO_CALL_DIRTYCONTROL
, pid
, PROC_DIRTYCONTROL_CLEAR
, flags
, NULL
, 0) == -1) {
356 proc_terminate(pid_t pid
, int *sig
)
364 retval
= __proc_info(PROC_INFO_CALL_TERMINATE
, pid
, 0, 0, NULL
, 0);
375 * XXX the _fatal() variant both checks for an existing monitor
376 * (with important policy effects on first party background apps)
377 * and validates inputs.
380 proc_set_cpumon_params(pid_t pid
, int percentage
, int interval
)
382 proc_policy_cpuusage_attr_t attr
;
384 /* no argument validation ...
385 * task_set_cpuusage() ignores 0 values and squashes negative
386 * values into uint32_t.
389 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
390 attr
.ppattr_cpu_percentage
= percentage
;
391 attr
.ppattr_cpu_attr_interval
= (uint64_t)interval
;
392 attr
.ppattr_cpu_attr_deadline
= 0;
394 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
395 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
399 proc_get_cpumon_params(pid_t pid
, int *percentage
, int *interval
)
401 proc_policy_cpuusage_attr_t attr
;
404 ret
= __process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_GET
, PROC_POLICY_RESOURCE_USAGE
,
405 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0);
407 if ((ret
== 0) && (attr
.ppattr_cpu_attr
== PROC_POLICY_RSRCACT_NOTIFY_EXC
)) {
408 *percentage
= attr
.ppattr_cpu_percentage
;
409 *interval
= (int)attr
.ppattr_cpu_attr_interval
;
419 proc_set_cpumon_defaults(pid_t pid
)
421 proc_policy_cpuusage_attr_t attr
;
423 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
424 attr
.ppattr_cpu_percentage
= PROC_POLICY_CPUMON_DEFAULTS
;
425 attr
.ppattr_cpu_attr_interval
= 0;
426 attr
.ppattr_cpu_attr_deadline
= 0;
428 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
429 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
433 proc_resume_cpumon(pid_t pid
)
435 return __process_policy(PROC_POLICY_SCOPE_PROCESS
,
436 PROC_POLICY_ACTION_ENABLE
,
437 PROC_POLICY_RESOURCE_USAGE
,
438 PROC_POLICY_RUSAGE_CPU
,
443 proc_disable_cpumon(pid_t pid
)
445 proc_policy_cpuusage_attr_t attr
;
447 attr
.ppattr_cpu_attr
= PROC_POLICY_RSRCACT_NOTIFY_EXC
;
448 attr
.ppattr_cpu_percentage
= PROC_POLICY_CPUMON_DISABLE
;
449 attr
.ppattr_cpu_attr_interval
= 0;
450 attr
.ppattr_cpu_attr_deadline
= 0;
452 return(__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_SET
, PROC_POLICY_RESOURCE_USAGE
,
453 PROC_POLICY_RUSAGE_CPU
, (proc_policy_attribute_t
*)&attr
, pid
, 0));
458 * Turn on the CPU usage monitor using the supplied parameters, and make
459 * violations of the monitor fatal.
461 * Returns: 0 on success;
462 * -1 on failure and sets errno
465 proc_set_cpumon_params_fatal(pid_t pid
, int percentage
, int interval
)
467 int current_percentage
= 0;
468 int current_interval
= 0; /* intervals are in seconds */
471 if ((percentage
<= 0) || (interval
<= 0)) {
477 * Do a simple query to see if CPU monitoring is
478 * already active. If either the percentage or the
479 * interval is nonzero, then CPU monitoring is
480 * already in use for this process.
482 * XXX: need set...() and set..fatal() to behave similarly.
483 * Currently, this check prevents 1st party apps (which get a
484 * default non-fatal monitor) not to get a fatal monitor.
486 (void)proc_get_cpumon_params(pid
, ¤t_percentage
, ¤t_interval
);
487 if (current_percentage
|| current_interval
)
490 * The CPU monitor appears to be active.
491 * We choose not to disturb those settings.
497 if ((ret
= proc_set_cpumon_params(pid
, percentage
, interval
)) != 0) {
498 /* Failed to activate the CPU monitor */
502 if ((ret
= proc_rlimit_control(pid
, RLIMIT_CPU_USAGE_MONITOR
, CPUMON_MAKE_FATAL
)) != 0) {
503 /* Failed to set termination, back out the CPU monitor settings. */
504 (void)proc_disable_cpumon(pid
);
511 proc_set_wakemon_params(pid_t pid
, int rate_hz
, int flags __unused
)
513 struct proc_rlimit_control_wakeupmon params
;
515 params
.wm_flags
= WAKEMON_ENABLE
;
516 params
.wm_rate
= rate_hz
;
518 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
521 #ifndef WAKEMON_GET_PARAMS
522 #define WAKEMON_GET_PARAMS 0x4
523 #define WAKEMON_SET_DEFAULTS 0x8
527 proc_get_wakemon_params(pid_t pid
, int *rate_hz
, int *flags
)
529 struct proc_rlimit_control_wakeupmon params
;
532 params
.wm_flags
= WAKEMON_GET_PARAMS
;
534 if ((error
= proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
)) != 0) {
538 *rate_hz
= params
.wm_rate
;
539 *flags
= params
.wm_flags
;
545 proc_set_wakemon_defaults(pid_t pid
)
547 struct proc_rlimit_control_wakeupmon params
;
549 params
.wm_flags
= WAKEMON_ENABLE
| WAKEMON_SET_DEFAULTS
;
552 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
556 proc_disable_wakemon(pid_t pid
)
558 struct proc_rlimit_control_wakeupmon params
;
560 params
.wm_flags
= WAKEMON_DISABLE
;
563 return (proc_rlimit_control(pid
, RLIMIT_WAKEUPS_MONITOR
, ¶ms
));
567 proc_list_uptrs(int pid
, uint64_t *buf
, uint32_t bufsz
)
569 return __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDLISTUPTRS
, 0,
574 proc_list_dynkqueueids(int pid
, kqueue_id_t
*buf
, uint32_t bufsz
)
576 return __proc_info(PROC_INFO_CALL_PIDINFO
, pid
, PROC_PIDLISTDYNKQUEUES
, 0,
582 proc_setcpu_percentage(pid_t pid
, int action
, int percentage
)
584 proc_policy_cpuusage_attr_t attr
;
586 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
587 attr
.ppattr_cpu_attr
= action
;
588 attr
.ppattr_cpu_percentage
= percentage
;
589 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)
596 proc_clear_cpulimits(pid_t pid
)
598 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)
604 #if TARGET_OS_EMBEDDED
607 proc_setcpu_deadline(pid_t pid
, int action
, uint64_t deadline
)
609 proc_policy_cpuusage_attr_t attr
;
611 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
612 attr
.ppattr_cpu_attr
= action
;
613 attr
.ppattr_cpu_attr_deadline
= deadline
;
614 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)
622 proc_setcpu_percentage_withdeadline(pid_t pid
, int action
, int percentage
, uint64_t deadline
)
624 proc_policy_cpuusage_attr_t attr
;
626 bzero(&attr
, sizeof(proc_policy_cpuusage_attr_t
));
627 attr
.ppattr_cpu_attr
= action
;
628 attr
.ppattr_cpu_percentage
= percentage
;
629 attr
.ppattr_cpu_attr_deadline
= deadline
;
630 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)
637 proc_appstate(int pid
, int * appstatep
)
641 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) {
642 if (appstatep
!= NULL
)
651 proc_setappstate(int pid
, int appstate
)
653 int state
= appstate
;
656 case PROC_APPSTATE_NONE
:
657 case PROC_APPSTATE_ACTIVE
:
658 case PROC_APPSTATE_INACTIVE
:
659 case PROC_APPSTATE_BACKGROUND
:
660 case PROC_APPSTATE_NONUI
:
665 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)
672 proc_devstatusnotify(int devicestatus
)
674 int state
= devicestatus
;
676 switch (devicestatus
) {
677 case PROC_DEVSTATUS_SHORTTERM
:
678 case PROC_DEVSTATUS_LONGTERM
:
684 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) {
692 proc_pidbind(int pid
, uint64_t threadid
, int bind
)
698 case PROC_PIDBIND_CLEAR
:
699 passpid
= getpid(); /* ignore pid on clear */
701 case PROC_PIDBIND_SET
:
706 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)
713 proc_can_use_foreground_hw(int pid
, uint32_t *reason
)
715 return __proc_info(PROC_INFO_CALL_CANUSEFGHW
, pid
, 0, NULL
, reason
, sizeof(*reason
));
717 #endif /* TARGET_OS_EMBEDDED */
720 /* Donate importance to adaptive processes from this process */
722 proc_donate_importance_boost()
726 #if TARGET_OS_EMBEDDED
727 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
728 PROC_POLICY_ACTION_ENABLE
,
730 PROC_POLICY_IOS_DONATEIMP
,
731 NULL
, getpid(), (uint64_t)0);
732 #else /* TARGET_OS_EMBEDDED */
733 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
734 PROC_POLICY_ACTION_SET
,
736 PROC_POLICY_IMP_DONATION
,
738 #endif /* TARGET_OS_EMBEDDED */
746 static __attribute__((noinline
)) void
747 proc_importance_bad_assertion(char *reason
) {
752 * Use the address of these variables as the token. This way, they can be
753 * printed in the debugger as useful names.
755 uint64_t important_boost_assertion_token
= 0xfafafafafafafafa;
756 uint64_t normal_boost_assertion_token
= 0xfbfbfbfbfbfbfbfb;
757 uint64_t non_boost_assertion_token
= 0xfcfcfcfcfcfcfcfc;
758 uint64_t denap_boost_assertion_token
= 0xfdfdfdfdfdfdfdfd;
761 * Accept the boost on a message, or request another boost assertion
762 * if we have already accepted the implicit boost for this message.
764 * Returns EOVERFLOW if an attempt is made to take an extra assertion when not boosted.
766 * Returns EIO if the message was not a boosting message.
767 * TODO: Return a 'non-boost' token instead.
770 proc_importance_assertion_begin_with_msg(mach_msg_header_t
*msg
,
771 __unused mach_msg_trailer_t
*trailer
,
772 uint64_t *assertion_token
)
776 if (assertion_token
== NULL
)
779 #define LEGACYBOOSTMASK (MACH_MSGH_BITS_VOUCHER_MASK | MACH_MSGH_BITS_RAISEIMP)
780 #define LEGACYBOOSTED(m) (((m)->msgh_bits & LEGACYBOOSTMASK) == MACH_MSGH_BITS_RAISEIMP)
782 /* Is this a legacy boosted message? */
783 if (LEGACYBOOSTED(msg
)) {
786 * Have we accepted the implicit boost for this message yet?
787 * If we haven't accepted it yet, no need to call into kernel.
789 if ((msg
->msgh_bits
& MACH_MSGH_BITS_IMPHOLDASRT
) == 0) {
790 msg
->msgh_bits
|= MACH_MSGH_BITS_IMPHOLDASRT
;
791 *assertion_token
= (uint64_t) &important_boost_assertion_token
;
795 /* Request an additional boost count */
796 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
797 PROC_POLICY_ACTION_HOLD
,
799 PROC_POLICY_IMP_IMPORTANT
,
802 *assertion_token
= (uint64_t) &important_boost_assertion_token
;
804 } else if (errno
== EOVERFLOW
) {
805 proc_importance_bad_assertion("Attempted to take assertion while not boosted");
817 * Drop a boost assertion.
818 * Returns EOVERFLOW on boost assertion underflow.
821 proc_importance_assertion_complete(uint64_t assertion_token
)
825 if (assertion_token
== 0)
828 if (assertion_token
== (uint64_t) &important_boost_assertion_token
) {
829 rval
= __process_policy(PROC_POLICY_SCOPE_PROCESS
,
830 PROC_POLICY_ACTION_DROP
,
832 PROC_POLICY_IMP_IMPORTANT
,
836 } else if (errno
== EOVERFLOW
) {
837 proc_importance_bad_assertion("Attempted to drop too many assertions");
843 proc_importance_bad_assertion("Attempted to drop assertion with invalid token");
849 * Accept the De-Nap boost on a message, or request another boost assertion
850 * if we have already accepted the implicit boost for this message.
852 * Interface is deprecated before it really got started - just as synonym
853 * for proc_importance_assertion_begin_with_msg() now.
856 proc_denap_assertion_begin_with_msg(mach_msg_header_t
*msg
,
857 uint64_t *assertion_token
)
859 #pragma clang diagnostic push
860 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
861 return proc_importance_assertion_begin_with_msg(msg
, NULL
, assertion_token
);
862 #pragma clang diagnostic pop
867 * Drop a denap boost assertion.
869 * Interface is deprecated before it really got started - just a synonym
870 * for proc_importance_assertion_complete() now.
873 proc_denap_assertion_complete(uint64_t assertion_token
)
875 return proc_importance_assertion_complete(assertion_token
);
878 #if !TARGET_OS_EMBEDDED
881 proc_clear_vmpressure(pid_t pid
)
883 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)
889 /* set the current process as one who can resume suspended processes due to low virtual memory. Need to be root */
891 proc_set_owner_vmpressure(void)
895 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_VMRSRCOWNER
, (uint64_t)0, NULL
, 0)) == -1)
901 /* mark yourself to delay idle sleep on disk IO */
903 proc_set_delayidlesleep(void)
907 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_DELAYIDLESLEEP
, (uint64_t)1, NULL
, 0)) == -1)
913 /* Reset yourself to delay idle sleep on disk IO, if already set */
915 proc_clear_delayidlesleep(void)
919 if ((retval
= __proc_info(PROC_INFO_CALL_SETCONTROL
, getpid(), PROC_SELFSET_DELAYIDLESLEEP
, (uint64_t)0, NULL
, 0)) == -1)
925 /* disable the launch time backgroudn policy and restore the process to default group */
927 proc_disable_apptype(pid_t pid
, int apptype
)
930 case PROC_POLICY_OSX_APPTYPE_TAL
:
931 case PROC_POLICY_OSX_APPTYPE_DASHCLIENT
:
937 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_DISABLE
, PROC_POLICY_APPTYPE
, apptype
, NULL
, pid
, (uint64_t)0) != -1)
944 /* re-enable the launch time background policy if it had been disabled. */
946 proc_enable_apptype(pid_t pid
, int apptype
)
949 case PROC_POLICY_OSX_APPTYPE_TAL
:
950 case PROC_POLICY_OSX_APPTYPE_DASHCLIENT
:
957 if (__process_policy(PROC_POLICY_SCOPE_PROCESS
, PROC_POLICY_ACTION_ENABLE
, PROC_POLICY_APPTYPE
, apptype
, NULL
, pid
, (uint64_t)0) != -1)
964 #if !TARGET_IPHONE_SIMULATOR
967 proc_suppress(__unused pid_t pid
, __unused
uint64_t *generation
)
972 #endif /* !TARGET_IPHONE_SIMULATOR */
974 #endif /* !TARGET_OS_EMBEDDED */