2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1982, 1986, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94
69 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
70 * support for mandatory and extensible security protections. This notice
71 * is included in support of clause 2.2 (b) of the Apple Public License,
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/sysctl.h>
78 #include <sys/kernel.h>
79 #include <sys/file_internal.h>
80 #include <sys/resourcevar.h>
81 #include <sys/malloc.h>
82 #include <sys/proc_internal.h>
83 #include <sys/kauth.h>
84 #include <sys/mount_internal.h>
85 #include <sys/sysproto.h>
87 #include <security/audit/audit.h>
89 #include <machine/vmparam.h>
91 #include <mach/mach_types.h>
92 #include <mach/time_value.h>
93 #include <mach/task.h>
94 #include <mach/task_info.h>
95 #include <mach/vm_map.h>
96 #include <mach/mach_vm.h>
97 #include <mach/thread_act.h> /* for thread_policy_set( ) */
98 #include <kern/thread.h>
99 #include <kern/policy_internal.h>
101 #include <kern/task.h>
102 #include <kern/clock.h> /* for absolutetime_to_microtime() */
103 #include <netinet/in.h> /* for TRAFFIC_MGT_SO_* */
104 #include <sys/socketvar.h> /* for struct socket */
106 #include <net/necp.h>
109 #include <vm/vm_map.h>
111 #include <kern/assert.h>
112 #include <sys/resource.h>
113 #include <sys/priv.h>
114 #include <IOKit/IOBSD.h>
117 #include <security/mac_framework.h>
120 int donice(struct proc
*curp
, struct proc
*chgp
, int n
);
121 int dosetrlimit(struct proc
*p
, u_int which
, struct rlimit
*limp
);
122 int uthread_get_background_state(uthread_t
);
123 static void do_background_socket(struct proc
*p
, thread_t thread
);
124 static int do_background_thread(thread_t thread
, int priority
);
125 static int do_background_proc(struct proc
*curp
, struct proc
*targetp
, int priority
);
126 static int set_gpudeny_proc(struct proc
*curp
, struct proc
*targetp
, int priority
);
127 static int proc_set_darwin_role(proc_t curp
, proc_t targetp
, int priority
);
128 static int proc_get_darwin_role(proc_t curp
, proc_t targetp
, int *priority
);
129 static int get_background_proc(struct proc
*curp
, struct proc
*targetp
, int *priority
);
130 int proc_pid_rusage(int pid
, int flavor
, user_addr_t buf
, int32_t *retval
);
131 void gather_rusage_info(proc_t p
, rusage_info_current
*ru
, int flavor
);
132 int fill_task_rusage(task_t task
, rusage_info_current
*ri
);
133 void fill_task_billed_usage(task_t task
, rusage_info_current
*ri
);
134 int fill_task_io_rusage(task_t task
, rusage_info_current
*ri
);
135 int fill_task_qos_rusage(task_t task
, rusage_info_current
*ri
);
136 uint64_t get_task_logical_writes(task_t task
, boolean_t external
);
137 void fill_task_monotonic_rusage(task_t task
, rusage_info_current
*ri
);
139 int proc_get_rusage(proc_t p
, int flavor
, user_addr_t buffer
, __unused
int is_zombie
);
141 rlim_t maxdmap
= MAXDSIZ
; /* XXX */
142 rlim_t maxsmap
= MAXSSIZ
- PAGE_MAX_SIZE
; /* XXX */
144 /* For plimit reference count */
145 os_refgrp_decl(, rlimit_refgrp
, "plimit_refcnt", NULL
);
147 ZONE_DECLARE(plimit_zone
, "plimit", sizeof(struct plimit
), ZC_NOENCRYPT
);
150 * Limits on the number of open files per process, and the number
151 * of child processes per process.
153 * Note: would be in kern/subr_param.c in FreeBSD.
155 __private_extern__
int maxfilesperproc
= OPEN_MAX
; /* per-proc open files limit */
157 SYSCTL_INT(_kern
, KERN_MAXPROCPERUID
, maxprocperuid
, CTLFLAG_RW
| CTLFLAG_LOCKED
,
158 &maxprocperuid
, 0, "Maximum processes allowed per userid" );
160 SYSCTL_INT(_kern
, KERN_MAXFILESPERPROC
, maxfilesperproc
, CTLFLAG_RW
| CTLFLAG_LOCKED
,
161 &maxfilesperproc
, 0, "Maximum files allowed open per process" );
163 /* Args and fn for proc_iteration callback used in setpriority */
164 struct puser_nice_args
{
171 static int puser_donice_callback(proc_t p
, void * arg
);
174 /* Args and fn for proc_iteration callback used in setpriority */
175 struct ppgrp_nice_args
{
181 static int ppgrp_donice_callback(proc_t p
, void * arg
);
184 * Resource controls and accounting.
187 getpriority(struct proc
*curp
, struct getpriority_args
*uap
, int32_t *retval
)
190 int low
= PRIO_MAX
+ 1;
191 kauth_cred_t my_cred
;
195 /* would also test (uap->who < 0), but id_t is unsigned */
196 if (uap
->who
> 0x7fffffff) {
200 switch (uap
->which
) {
206 p
= proc_find(uap
->who
);
216 struct pgrp
*pg
= PGRP_NULL
;
219 /* returns the pgrp to ref */
220 pg
= proc_pgrp(curp
);
221 } else if ((pg
= pgfind(uap
->who
)) == PGRP_NULL
) {
224 /* No need for iteration as it is a simple scan */
226 PGMEMBERS_FOREACH(pg
, p
) {
227 if (p
->p_nice
< low
) {
238 uap
->who
= kauth_cred_getuid(kauth_cred_get());
243 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
244 my_cred
= kauth_cred_proc_ref(p
);
245 if (kauth_cred_getuid(my_cred
) == uap
->who
&&
249 kauth_cred_unref(&my_cred
);
256 case PRIO_DARWIN_THREAD
:
257 /* we currently only support the current thread */
262 low
= proc_get_thread_policy(current_thread(), TASK_POLICY_INTERNAL
, TASK_POLICY_DARWIN_BG
);
266 case PRIO_DARWIN_PROCESS
:
270 p
= proc_find(uap
->who
);
271 if (p
== PROC_NULL
) {
277 error
= get_background_proc(curp
, p
, &low
);
287 case PRIO_DARWIN_ROLE
:
291 p
= proc_find(uap
->who
);
292 if (p
== PROC_NULL
) {
298 error
= proc_get_darwin_role(curp
, p
, &low
);
311 if (low
== PRIO_MAX
+ 1) {
318 /* call back function used for proc iteration in PRIO_USER */
320 puser_donice_callback(proc_t p
, void * arg
)
323 struct puser_nice_args
* pun
= (struct puser_nice_args
*)arg
;
324 kauth_cred_t my_cred
;
326 my_cred
= kauth_cred_proc_ref(p
);
327 if (kauth_cred_getuid(my_cred
) == pun
->who
) {
328 error
= donice(pun
->curp
, p
, pun
->prio
);
329 if (pun
->errorp
!= NULL
) {
330 *pun
->errorp
= error
;
332 if (pun
->foundp
!= NULL
) {
334 *pun
->foundp
= n
+ 1;
337 kauth_cred_unref(&my_cred
);
339 return PROC_RETURNED
;
342 /* call back function used for proc iteration in PRIO_PGRP */
344 ppgrp_donice_callback(proc_t p
, void * arg
)
347 struct ppgrp_nice_args
* pun
= (struct ppgrp_nice_args
*)arg
;
350 error
= donice(pun
->curp
, p
, pun
->prio
);
351 if (pun
->errorp
!= NULL
) {
352 *pun
->errorp
= error
;
354 if (pun
->foundp
!= NULL
) {
356 *pun
->foundp
= n
+ 1;
359 return PROC_RETURNED
;
371 setpriority(struct proc
*curp
, struct setpriority_args
*uap
, int32_t *retval
)
374 int found
= 0, error
= 0;
377 AUDIT_ARG(cmd
, uap
->which
);
378 AUDIT_ARG(owner
, uap
->who
, 0);
379 AUDIT_ARG(value32
, uap
->prio
);
381 /* would also test (uap->who < 0), but id_t is unsigned */
382 if (uap
->who
> 0x7fffffff) {
386 switch (uap
->which
) {
391 p
= proc_find(uap
->who
);
397 error
= donice(curp
, p
, uap
->prio
);
405 struct pgrp
*pg
= PGRP_NULL
;
406 struct ppgrp_nice_args ppgrp
;
409 pg
= proc_pgrp(curp
);
410 } else if ((pg
= pgfind(uap
->who
)) == PGRP_NULL
) {
415 ppgrp
.prio
= uap
->prio
;
416 ppgrp
.foundp
= &found
;
417 ppgrp
.errorp
= &error
;
419 /* PGRP_DROPREF drops the reference on process group */
420 pgrp_iterate(pg
, PGRP_DROPREF
, ppgrp_donice_callback
, (void *)&ppgrp
, NULL
, NULL
);
426 struct puser_nice_args punice
;
429 uap
->who
= kauth_cred_getuid(kauth_cred_get());
433 punice
.prio
= uap
->prio
;
434 punice
.who
= uap
->who
;
435 punice
.foundp
= &found
;
437 punice
.errorp
= &error
;
438 proc_iterate(PROC_ALLPROCLIST
, puser_donice_callback
, (void *)&punice
, NULL
, NULL
);
443 case PRIO_DARWIN_THREAD
: {
444 /* we currently only support the current thread */
449 error
= do_background_thread(current_thread(), uap
->prio
);
454 case PRIO_DARWIN_PROCESS
: {
458 p
= proc_find(uap
->who
);
465 error
= do_background_proc(curp
, p
, uap
->prio
);
474 case PRIO_DARWIN_GPU
: {
479 p
= proc_find(uap
->who
);
480 if (p
== PROC_NULL
) {
484 error
= set_gpudeny_proc(curp
, p
, uap
->prio
);
491 case PRIO_DARWIN_ROLE
: {
495 p
= proc_find(uap
->who
);
496 if (p
== PROC_NULL
) {
502 error
= proc_set_darwin_role(curp
, p
, uap
->prio
);
517 if (error
== EIDRM
) {
529 * mac_check_proc_sched:???
532 donice(struct proc
*curp
, struct proc
*chgp
, int n
)
536 kauth_cred_t my_cred
;
538 ucred
= kauth_cred_proc_ref(curp
);
539 my_cred
= kauth_cred_proc_ref(chgp
);
541 if (suser(ucred
, NULL
) && kauth_cred_getruid(ucred
) &&
542 kauth_cred_getuid(ucred
) != kauth_cred_getuid(my_cred
) &&
543 kauth_cred_getruid(ucred
) != kauth_cred_getuid(my_cred
)) {
553 if (n
< chgp
->p_nice
&& suser(ucred
, &curp
->p_acflag
)) {
558 error
= mac_proc_check_sched(curp
, chgp
);
564 chgp
->p_nice
= (char)n
;
566 (void)resetpriority(chgp
);
568 kauth_cred_unref(&ucred
);
569 kauth_cred_unref(&my_cred
);
574 set_gpudeny_proc(struct proc
*curp
, struct proc
*targetp
, int priority
)
578 kauth_cred_t target_cred
;
580 ucred
= kauth_cred_get();
581 target_cred
= kauth_cred_proc_ref(targetp
);
583 /* TODO: Entitlement instead of uid check */
585 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
586 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
587 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
592 if (curp
== targetp
) {
598 error
= mac_proc_check_sched(curp
, targetp
);
605 case PRIO_DARWIN_GPU_DENY
:
606 task_set_gpu_denied(proc_task(targetp
), TRUE
);
608 case PRIO_DARWIN_GPU_ALLOW
:
609 task_set_gpu_denied(proc_task(targetp
), FALSE
);
617 kauth_cred_unref(&target_cred
);
622 proc_set_darwin_role(proc_t curp
, proc_t targetp
, int priority
)
627 kauth_cred_t ucred
, target_cred
;
629 ucred
= kauth_cred_get();
630 target_cred
= kauth_cred_proc_ref(targetp
);
632 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
633 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
634 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
635 if (priv_check_cred(ucred
, PRIV_SETPRIORITY_DARWIN_ROLE
, 0) != 0) {
641 if (curp
!= targetp
) {
643 if ((error
= mac_proc_check_sched(curp
, targetp
))) {
649 proc_get_darwinbgstate(proc_task(targetp
), &flagsp
);
650 if ((flagsp
& PROC_FLAG_APPLICATION
) != PROC_FLAG_APPLICATION
) {
655 task_role_t role
= TASK_UNSPECIFIED
;
657 if ((error
= proc_darwin_role_to_task_role(priority
, &role
))) {
661 proc_set_task_policy(proc_task(targetp
), TASK_POLICY_ATTRIBUTE
,
662 TASK_POLICY_ROLE
, role
);
665 kauth_cred_unref(&target_cred
);
670 proc_get_darwin_role(proc_t curp
, proc_t targetp
, int *priority
)
675 kauth_cred_t ucred
, target_cred
;
677 ucred
= kauth_cred_get();
678 target_cred
= kauth_cred_proc_ref(targetp
);
680 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
681 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
682 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
687 if (curp
!= targetp
) {
689 if ((error
= mac_proc_check_sched(curp
, targetp
))) {
695 role
= proc_get_task_policy(proc_task(targetp
), TASK_POLICY_ATTRIBUTE
, TASK_POLICY_ROLE
);
697 *priority
= proc_task_role_to_darwin_role(role
);
700 kauth_cred_unref(&target_cred
);
706 get_background_proc(struct proc
*curp
, struct proc
*targetp
, int *priority
)
710 kauth_cred_t ucred
, target_cred
;
712 ucred
= kauth_cred_get();
713 target_cred
= kauth_cred_proc_ref(targetp
);
715 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
716 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
717 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
722 external
= (curp
== targetp
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
724 *priority
= proc_get_task_policy(current_task(), external
, TASK_POLICY_DARWIN_BG
);
727 kauth_cred_unref(&target_cred
);
732 do_background_proc(struct proc
*curp
, struct proc
*targetp
, int priority
)
739 kauth_cred_t target_cred
;
743 ucred
= kauth_cred_get();
744 target_cred
= kauth_cred_proc_ref(targetp
);
746 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
747 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
748 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
754 error
= mac_proc_check_sched(curp
, targetp
);
760 external
= (curp
== targetp
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
764 enable
= TASK_POLICY_ENABLE
;
766 case PRIO_DARWIN_NONUI
:
767 /* ignored for compatibility */
770 /* TODO: EINVAL if priority != 0 */
771 enable
= TASK_POLICY_DISABLE
;
775 proc_set_task_policy(proc_task(targetp
), external
, TASK_POLICY_DARWIN_BG
, enable
);
778 kauth_cred_unref(&target_cred
);
783 do_background_socket(struct proc
*p
, thread_t thread
)
787 int background
= false;
789 int update_necp
= false;
794 if (thread
!= THREAD_NULL
) {
795 background
= proc_get_effective_thread_policy(thread
, TASK_POLICY_ALL_SOCKETS_BG
);
797 background
= proc_get_effective_task_policy(proc_task(p
), TASK_POLICY_ALL_SOCKETS_BG
);
802 * For PRIO_DARWIN_PROCESS (thread is NULL), simply mark
803 * the sockets with the background flag. There's nothing
804 * to do here for the PRIO_DARWIN_THREAD case.
806 if (thread
== THREAD_NULL
) {
808 if (FILEGLOB_DTYPE(fp
->fp_glob
) == DTYPE_SOCKET
) {
809 struct socket
*sockp
= (struct socket
*)fp
->fp_glob
->fg_data
;
810 socket_set_traffic_mgt_flags(sockp
, TRAFFIC_MGT_SO_BACKGROUND
);
811 sockp
->so_background_thread
= NULL
;
814 else if (FILEGLOB_DTYPE(fp
->fp_glob
) == DTYPE_NETPOLICY
) {
815 if (necp_set_client_as_background(p
, fp
, background
)) {
823 /* disable networking IO throttle.
824 * NOTE - It is a known limitation of the current design that we
825 * could potentially clear TRAFFIC_MGT_SO_BACKGROUND bit for
826 * sockets created by other threads within this process.
829 struct socket
*sockp
;
831 if (FILEGLOB_DTYPE(fp
->fp_glob
) == DTYPE_SOCKET
) {
832 sockp
= (struct socket
*)fp
->fp_glob
->fg_data
;
833 /* skip if only clearing this thread's sockets */
834 if ((thread
) && (sockp
->so_background_thread
!= thread
)) {
837 socket_clear_traffic_mgt_flags(sockp
, TRAFFIC_MGT_SO_BACKGROUND
);
838 sockp
->so_background_thread
= NULL
;
841 else if (FILEGLOB_DTYPE(fp
->fp_glob
) == DTYPE_NETPOLICY
) {
842 if (necp_set_client_as_background(p
, fp
, background
)) {
854 necp_update_all_clients();
858 #pragma unused(p, thread)
864 * do_background_thread
866 * Requires: thread reference
869 * EPERM Tried to background while in vfork
870 * XXX - todo - does this need a MACF hook?
873 do_background_thread(thread_t thread
, int priority
)
876 int enable
, external
;
879 ut
= get_bsdthread_info(thread
);
881 /* Backgrounding is unsupported for threads in vfork */
882 if ((ut
->uu_flag
& UT_VFORK
) != 0) {
886 /* Backgrounding is unsupported for workq threads */
887 if (thread_is_static_param(thread
)) {
891 /* Not allowed to combine QoS and DARWIN_BG, doing so strips the QoS */
892 if (thread_has_qos_policy(thread
)) {
893 thread_remove_qos_policy(thread
);
897 /* TODO: Fail if someone passes something besides 0 or PRIO_DARWIN_BG */
898 enable
= (priority
== PRIO_DARWIN_BG
) ? TASK_POLICY_ENABLE
: TASK_POLICY_DISABLE
;
899 external
= (current_thread() == thread
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
901 proc_set_thread_policy(thread
, external
, TASK_POLICY_DARWIN_BG
, enable
);
914 setrlimit(struct proc
*p
, struct setrlimit_args
*uap
, __unused
int32_t *retval
)
919 if ((error
= copyin(uap
->rlp
, (caddr_t
)&alim
,
920 sizeof(struct rlimit
)))) {
924 return dosetrlimit(p
, uap
->which
, &alim
);
932 * Notes: EINVAL is returned both for invalid arguments, and in the
933 * case that the current usage (e.g. RLIMIT_STACK) is already
934 * in excess of the requested limit.
937 dosetrlimit(struct proc
*p
, u_int which
, struct rlimit
*newrlim
)
942 int posix
= (which
& _RLIMIT_POSIX_FLAG
) ? 1 : 0;
944 /* Mask out POSIX flag, saved above */
945 which
&= ~_RLIMIT_POSIX_FLAG
;
947 /* Unknown resource */
948 if (which
>= RLIM_NLIMITS
) {
953 * Take a snapshot of the current rlimit values and read this throughout
954 * this routine. This minimizes the critical sections and allow other
955 * processes in the system to access the plimit while we are in the
956 * middle of this setrlimit call.
959 rlim
= p
->p_limit
->pl_rlimit
[which
];
963 /* Sanity check: new soft limit cannot exceed new hard limit */
964 if (newrlim
->rlim_cur
> newrlim
->rlim_max
) {
968 * Sanity check: only super-user may raise the hard limit.
969 * newrlim->rlim_cur > rlim.rlim_max implies that the call is increasing the hard limit as well.
971 else if (newrlim
->rlim_cur
> rlim
.rlim_max
|| newrlim
->rlim_max
> rlim
.rlim_max
) {
972 /* suser() returns 0 if the calling thread is super user. */
973 error
= suser(kauth_cred_get(), &p
->p_acflag
);
977 /* Invalid setrlimit request: EINVAL or EPERM */
981 /* Only one thread is able to change the current process's rlimit values */
986 /* We have the reader lock of the process's plimit so it's safe to read the rlimit values */
989 if (newrlim
->rlim_cur
== RLIM_INFINITY
) {
990 task_vtimer_clear(p
->task
, TASK_VTIMER_RLIM
);
991 timerclear(&p
->p_rlim_cpu
);
993 task_absolutetime_info_data_t tinfo
;
994 mach_msg_type_number_t count
;
995 struct timeval ttv
, tv
;
997 clock_usec_t tv_usec
;
999 count
= TASK_ABSOLUTETIME_INFO_COUNT
;
1000 task_info(p
->task
, TASK_ABSOLUTETIME_INFO
, (task_info_t
)&tinfo
, &count
);
1001 absolutetime_to_microtime(tinfo
.total_user
+ tinfo
.total_system
, &tv_sec
, &tv_usec
);
1002 ttv
.tv_sec
= tv_sec
;
1003 ttv
.tv_usec
= tv_usec
;
1005 tv
.tv_sec
= (newrlim
->rlim_cur
> __INT_MAX__
? __INT_MAX__
: (__darwin_time_t
)newrlim
->rlim_cur
);
1007 timersub(&tv
, &ttv
, &p
->p_rlim_cpu
);
1010 if (timercmp(&p
->p_rlim_cpu
, &tv
, >)) {
1011 task_vtimer_set(p
->task
, TASK_VTIMER_RLIM
);
1013 task_vtimer_clear(p
->task
, TASK_VTIMER_RLIM
);
1015 timerclear(&p
->p_rlim_cpu
);
1017 psignal(p
, SIGXCPU
);
1023 if (newrlim
->rlim_cur
> maxdmap
) {
1024 newrlim
->rlim_cur
= maxdmap
;
1026 if (newrlim
->rlim_max
> maxdmap
) {
1027 newrlim
->rlim_max
= maxdmap
;
1032 if (p
->p_lflag
& P_LCUSTOM_STACK
) {
1033 /* Process has a custom stack set - rlimit cannot be used to change it */
1038 /* Disallow illegal stack size instead of clipping */
1039 if (newrlim
->rlim_cur
> maxsmap
||
1040 newrlim
->rlim_max
> maxsmap
) {
1046 * 4797860 - workaround poorly written installers by
1047 * doing previous implementation (< 10.5) when caller
1048 * is non-POSIX conforming.
1050 if (newrlim
->rlim_cur
> maxsmap
) {
1051 newrlim
->rlim_cur
= maxsmap
;
1053 if (newrlim
->rlim_max
> maxsmap
) {
1054 newrlim
->rlim_max
= maxsmap
;
1060 * Stack is allocated to the max at exec time with only
1061 * "rlim_cur" bytes accessible. If stack limit is going
1062 * up make more accessible, if going down make inaccessible.
1064 if (newrlim
->rlim_cur
> rlim
.rlim_cur
) {
1065 mach_vm_offset_t addr
;
1066 mach_vm_size_t size
;
1069 size
= round_page_64(newrlim
->rlim_cur
);
1070 size
-= round_page_64(rlim
.rlim_cur
);
1072 addr
= (mach_vm_offset_t
)(p
->user_stack
- round_page_64(newrlim
->rlim_cur
));
1073 kr
= mach_vm_protect(current_map(), addr
, size
, FALSE
, VM_PROT_DEFAULT
);
1074 if (kr
!= KERN_SUCCESS
) {
1078 } else if (newrlim
->rlim_cur
< rlim
.rlim_cur
) {
1079 mach_vm_offset_t addr
;
1080 mach_vm_size_t size
;
1086 * First check if new stack limit would agree
1087 * with current stack usage.
1088 * Get the current thread's stack pointer...
1090 cur_sp
= thread_adjuserstack(current_thread(), 0);
1091 if (cur_sp
<= p
->user_stack
&&
1092 cur_sp
> (p
->user_stack
- round_page_64(rlim
.rlim_cur
))) {
1093 /* stack pointer is in main stack */
1094 if (cur_sp
<= (p
->user_stack
- round_page_64(newrlim
->rlim_cur
))) {
1096 * New limit would cause current usage to be invalid:
1103 /* not on the main stack: reject */
1108 size
= round_page_64(rlim
.rlim_cur
);
1109 size
-= round_page_64(rlim
.rlim_cur
);
1111 addr
= (mach_vm_offset_t
)(p
->user_stack
- round_page_64(rlim
.rlim_cur
));
1113 kr
= mach_vm_protect(current_map(), addr
, size
, FALSE
, VM_PROT_NONE
);
1114 if (kr
!= KERN_SUCCESS
) {
1125 * Nothing to be done here as we already performed the sanity checks before entering the switch code block.
1126 * The real NOFILE limits enforced by the kernel is capped at MIN(RLIMIT_NOFILE, maxfilesperproc)
1132 * Only root can set to the maxproc limits, as it is
1133 * systemwide resource; all others are limited to
1134 * maxprocperuid (presumably less than maxproc).
1136 if (kauth_cred_issuser(kauth_cred_get())) {
1137 if (newrlim
->rlim_cur
> (rlim_t
)maxproc
) {
1138 newrlim
->rlim_cur
= maxproc
;
1140 if (newrlim
->rlim_max
> (rlim_t
)maxproc
) {
1141 newrlim
->rlim_max
= maxproc
;
1144 if (newrlim
->rlim_cur
> (rlim_t
)maxprocperuid
) {
1145 newrlim
->rlim_cur
= maxprocperuid
;
1147 if (newrlim
->rlim_max
> (rlim_t
)maxprocperuid
) {
1148 newrlim
->rlim_max
= maxprocperuid
;
1153 case RLIMIT_MEMLOCK
:
1155 * Tell the Mach VM layer about the new limit value.
1157 newrlim
->rlim_cur
= (vm_size_t
)newrlim
->rlim_cur
;
1158 vm_map_set_user_wire_limit(current_map(), (vm_size_t
)newrlim
->rlim_cur
);
1162 /* Everything checks out and we are now ready to update the rlimit */
1169 * COW the current plimit if it's shared, otherwise update it in place.
1170 * Finally unblock other threads wishing to change plimit.
1173 proc_limitupdate(p
, newrlim
, (uint8_t)which
);
1174 proc_limitunblock(p
);
1178 * This setrlimit has failed, just leave the plimit as is and unblock other
1179 * threads wishing to change plimit.
1182 proc_limitunblock(p
);
1191 getrlimit(struct proc
*p
, struct getrlimit_args
*uap
, __unused
int32_t *retval
)
1193 struct rlimit lim
= {};
1196 * Take out flag now in case we need to use it to trigger variant
1199 uap
->which
&= ~_RLIMIT_POSIX_FLAG
;
1201 if (uap
->which
>= RLIM_NLIMITS
) {
1204 proc_limitget(p
, uap
->which
, &lim
);
1205 return copyout((caddr_t
)&lim
,
1206 uap
->rlp
, sizeof(struct rlimit
));
1210 * Transform the running time and tick information in proc p into user,
1211 * system, and interrupt time usage.
1213 /* No lock on proc is held for this.. */
1215 calcru(struct proc
*p
, struct timeval
*up
, struct timeval
*sp
, struct timeval
*ip
)
1227 mach_task_basic_info_data_t tinfo
;
1228 task_thread_times_info_data_t ttimesinfo
;
1229 task_events_info_data_t teventsinfo
;
1230 mach_msg_type_number_t task_info_count
, task_ttimes_count
;
1231 mach_msg_type_number_t task_events_count
;
1232 struct timeval ut
, st
;
1234 task_info_count
= MACH_TASK_BASIC_INFO_COUNT
;
1235 task_info(task
, MACH_TASK_BASIC_INFO
,
1236 (task_info_t
)&tinfo
, &task_info_count
);
1237 ut
.tv_sec
= tinfo
.user_time
.seconds
;
1238 ut
.tv_usec
= tinfo
.user_time
.microseconds
;
1239 st
.tv_sec
= tinfo
.system_time
.seconds
;
1240 st
.tv_usec
= tinfo
.system_time
.microseconds
;
1241 timeradd(&ut
, up
, up
);
1242 timeradd(&st
, sp
, sp
);
1244 task_ttimes_count
= TASK_THREAD_TIMES_INFO_COUNT
;
1245 task_info(task
, TASK_THREAD_TIMES_INFO
,
1246 (task_info_t
)&ttimesinfo
, &task_ttimes_count
);
1248 ut
.tv_sec
= ttimesinfo
.user_time
.seconds
;
1249 ut
.tv_usec
= ttimesinfo
.user_time
.microseconds
;
1250 st
.tv_sec
= ttimesinfo
.system_time
.seconds
;
1251 st
.tv_usec
= ttimesinfo
.system_time
.microseconds
;
1252 timeradd(&ut
, up
, up
);
1253 timeradd(&st
, sp
, sp
);
1255 task_events_count
= TASK_EVENTS_INFO_COUNT
;
1256 task_info(task
, TASK_EVENTS_INFO
,
1257 (task_info_t
)&teventsinfo
, &task_events_count
);
1260 * No need to lock "p": this does not need to be
1261 * completely consistent, right ?
1263 p
->p_stats
->p_ru
.ru_minflt
= (teventsinfo
.faults
-
1264 teventsinfo
.pageins
);
1265 p
->p_stats
->p_ru
.ru_majflt
= teventsinfo
.pageins
;
1266 p
->p_stats
->p_ru
.ru_nivcsw
= (teventsinfo
.csw
-
1267 p
->p_stats
->p_ru
.ru_nvcsw
);
1268 if (p
->p_stats
->p_ru
.ru_nivcsw
< 0) {
1269 p
->p_stats
->p_ru
.ru_nivcsw
= 0;
1272 p
->p_stats
->p_ru
.ru_maxrss
= (long)tinfo
.resident_size_max
;
1276 __private_extern__
void munge_user64_rusage(struct rusage
*a_rusage_p
, struct user64_rusage
*a_user_rusage_p
);
1277 __private_extern__
void munge_user32_rusage(struct rusage
*a_rusage_p
, struct user32_rusage
*a_user_rusage_p
);
1281 getrusage(struct proc
*p
, struct getrusage_args
*uap
, __unused
int32_t *retval
)
1283 struct rusage
*rup
, rubuf
;
1284 struct user64_rusage rubuf64
= {};
1285 struct user32_rusage rubuf32
= {};
1286 size_t retsize
= sizeof(rubuf
); /* default: 32 bits */
1287 caddr_t retbuf
= (caddr_t
)&rubuf
; /* default: 32 bits */
1288 struct timeval utime
;
1289 struct timeval stime
;
1294 calcru(p
, &utime
, &stime
, NULL
);
1296 rup
= &p
->p_stats
->p_ru
;
1297 rup
->ru_utime
= utime
;
1298 rup
->ru_stime
= stime
;
1305 case RUSAGE_CHILDREN
:
1307 rup
= &p
->p_stats
->p_cru
;
1315 if (IS_64BIT_PROCESS(p
)) {
1316 retsize
= sizeof(rubuf64
);
1317 retbuf
= (caddr_t
)&rubuf64
;
1318 munge_user64_rusage(&rubuf
, &rubuf64
);
1320 retsize
= sizeof(rubuf32
);
1321 retbuf
= (caddr_t
)&rubuf32
;
1322 munge_user32_rusage(&rubuf
, &rubuf32
);
1325 return copyout(retbuf
, uap
->rusage
, retsize
);
1329 ruadd(struct rusage
*ru
, struct rusage
*ru2
)
1334 timeradd(&ru
->ru_utime
, &ru2
->ru_utime
, &ru
->ru_utime
);
1335 timeradd(&ru
->ru_stime
, &ru2
->ru_stime
, &ru
->ru_stime
);
1336 if (ru
->ru_maxrss
< ru2
->ru_maxrss
) {
1337 ru
->ru_maxrss
= ru2
->ru_maxrss
;
1339 ip
= &ru
->ru_first
; ip2
= &ru2
->ru_first
;
1340 for (i
= &ru
->ru_last
- &ru
->ru_first
; i
>= 0; i
--) {
1346 * Add the rusage stats of child in parent.
1348 * It adds rusage statistics of child process and statistics of all its
1349 * children to its parent.
1351 * Note: proc lock of parent should be held while calling this function.
1354 update_rusage_info_child(struct rusage_info_child
*ri
, rusage_info_current
*ri_current
)
1356 ri
->ri_child_user_time
+= (ri_current
->ri_user_time
+
1357 ri_current
->ri_child_user_time
);
1358 ri
->ri_child_system_time
+= (ri_current
->ri_system_time
+
1359 ri_current
->ri_child_system_time
);
1360 ri
->ri_child_pkg_idle_wkups
+= (ri_current
->ri_pkg_idle_wkups
+
1361 ri_current
->ri_child_pkg_idle_wkups
);
1362 ri
->ri_child_interrupt_wkups
+= (ri_current
->ri_interrupt_wkups
+
1363 ri_current
->ri_child_interrupt_wkups
);
1364 ri
->ri_child_pageins
+= (ri_current
->ri_pageins
+
1365 ri_current
->ri_child_pageins
);
1366 ri
->ri_child_elapsed_abstime
+= ((ri_current
->ri_proc_exit_abstime
-
1367 ri_current
->ri_proc_start_abstime
) + ri_current
->ri_child_elapsed_abstime
);
1371 * Reading soft limit from specified resource.
1374 proc_limitgetcur(proc_t p
, int which
, boolean_t to_lock_proc
)
1379 assert(which
< RLIM_NLIMITS
);
1382 * Serialize access to the process's plimit pointer for concurrent threads.
1385 lck_mtx_assert(&p
->p_mlock
, LCK_MTX_ASSERT_NOTOWNED
);
1389 rlim_cur
= p
->p_limit
->pl_rlimit
[which
].rlim_cur
;
1399 * Writing soft limit to specified resource. This is an internal function
1400 * used only by proc_exit and vfork_exit_internal to update RLIMIT_FSIZE in
1401 * place without invoking setrlimit.
1404 proc_limitsetcur_internal(proc_t p
, int which
, rlim_t value
)
1409 assertf(which
== RLIMIT_FSIZE
, "%s only supports RLIMIT_FSIZE\n", __FUNCTION__
);
1414 /* Only one thread is able to change rlimit values at a time */
1417 /* Prepare an rlimit for proc_limitupdate */
1418 rlim
= p
->p_limit
->pl_rlimit
[which
];
1419 rlim
.rlim_cur
= value
;
1422 * proc_limitupdate will COW the current plimit and update specified the soft limit
1423 * if the plimit is shared, otherwise it will update the soft limit in place.
1425 proc_limitupdate(p
, &rlim
, (uint8_t)which
);
1427 /* Unblock other threads wishing to change plimit */
1428 proc_limitunblock(p
);
1434 proc_limitget(proc_t p
, int which
, struct rlimit
* limp
)
1438 assert(which
< RLIM_NLIMITS
);
1440 /* Protect writes to the process's plimit pointer issued by concurrent threads */
1443 limp
->rlim_cur
= p
->p_limit
->pl_rlimit
[which
].rlim_cur
;
1444 limp
->rlim_max
= p
->p_limit
->pl_rlimit
[which
].rlim_max
;
1450 proc_limitfork(proc_t parent
, proc_t child
)
1452 assert(parent
&& child
);
1456 /* Child proc inherits parent's plimit */
1457 child
->p_limit
= parent
->p_limit
;
1459 /* Increment refcnt of the shared plimit */
1460 os_ref_retain(&parent
->p_limit
->pl_refcnt
);
1462 proc_unlock(parent
);
1466 proc_limitdrop(proc_t p
)
1468 struct plimit
*free_plim
= NULL
;
1469 os_ref_count_t refcnt
;
1473 /* Drop the plimit reference before exiting the system */
1474 refcnt
= os_ref_release(&p
->p_limit
->pl_refcnt
);
1476 free_plim
= p
->p_limit
;
1482 /* We are the last user of this plimit, free it now. */
1483 if (free_plim
!= NULL
) {
1484 zfree(plimit_zone
, free_plim
);
1489 * proc_limitblock/unblock are used to serialize access to plimit
1490 * from concurrent threads within the same process.
1491 * Callers must be holding the proc lock to enter, return with
1492 * the proc lock locked
1495 proc_limitblock(proc_t p
)
1497 lck_mtx_assert(&p
->p_mlock
, LCK_MTX_ASSERT_OWNED
);
1499 while (p
->p_lflag
& P_LLIMCHANGE
) {
1500 p
->p_lflag
|= P_LLIMWAIT
;
1501 msleep(&p
->p_limit
, &p
->p_mlock
, 0, "proc_limitblock", NULL
);
1503 p
->p_lflag
|= P_LLIMCHANGE
;
1507 * Callers must be holding the proc lock to enter, return with
1508 * the proc lock locked
1511 proc_limitunblock(proc_t p
)
1513 lck_mtx_assert(&p
->p_mlock
, LCK_MTX_ASSERT_OWNED
);
1515 p
->p_lflag
&= ~P_LLIMCHANGE
;
1516 if (p
->p_lflag
& P_LLIMWAIT
) {
1517 p
->p_lflag
&= ~P_LLIMWAIT
;
1518 wakeup(&p
->p_limit
);
1523 * Change the rlimit values of process "p" to "rlim" for resource "which".
1525 * If the current plimit is shared by multiple processes (refcnt > 1):
1526 * this routine replaces the process's original plimit with a new plimit,
1527 * update the requeted rlimit values, and free the original plimit if this
1528 * process is the last user.
1530 * If the current plimit is used only by the calling process (refcnt == 1):
1531 * this routine updates the new rlimit values in place.
1533 * Note: caller must be holding the proc lock before entering this routine.
1534 * This routine allocates and frees kernel memory without holding the proc lock
1535 * to minimize contention, and returns with the proc lock held.
1538 proc_limitupdate(proc_t p
, struct rlimit
*rlim
, uint8_t which
)
1540 struct plimit
*copy_plim
;
1541 struct plimit
*free_plim
;
1542 os_ref_count_t refcnt
;
1544 assert(p
&& p
->p_limit
);
1546 assert(which
< RLIM_NLIMITS
);
1547 lck_mtx_assert(&p
->p_mlock
, LCK_MTX_ASSERT_OWNED
);
1550 * If we are the only user of this plimit, don't bother allocating a plimit
1551 * before making changes. Just modify the rlimit values in place.
1553 refcnt
= os_ref_get_count(&p
->p_limit
->pl_refcnt
);
1555 p
->p_limit
->pl_rlimit
[which
] = *rlim
;
1560 * Allocating a new plimit for this process to apply the requested rlimit values.
1561 * Not holding the lock on the original plimit gives other processes in the system
1562 * a chance to access the plimit while we wait for memory below.
1564 * The default zalloc should always succeed when WAIT flag.
1567 copy_plim
= zalloc(plimit_zone
);
1569 /* Copy the current p_limit */
1571 bcopy(p
->p_limit
->pl_rlimit
, copy_plim
->pl_rlimit
, sizeof(struct rlimit
) * RLIM_NLIMITS
);
1574 * Drop our reference to the old plimit. Other processes sharing the old plimit could
1575 * have exited the system when we wait for memory for the new plimit above, thus, we
1576 * need to check the refcnt again and free the old plimit if this process is the last
1577 * user. Also since we are holding the proc lock here, it's impossible for another threads
1578 * to dereference the plimit, so it's safe to free the old plimit memory.
1581 refcnt
= os_ref_release(&p
->p_limit
->pl_refcnt
);
1583 free_plim
= p
->p_limit
;
1585 /* Initialize the newly allocated plimit */
1586 os_ref_init_count(©_plim
->pl_refcnt
, &rlimit_refgrp
, 1);
1588 /* Apply new rlimit values */
1589 copy_plim
->pl_rlimit
[which
] = *rlim
;
1591 /* All set, update the process's plimit pointer to the new plimit. */
1592 p
->p_limit
= copy_plim
;
1595 if (free_plim
!= NULL
) {
1596 zfree(plimit_zone
, free_plim
);
1599 /* Return with proc->p_mlock locked */
1604 iopolicysys_disk(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1606 iopolicysys_vfs_hfs_case_sensitivity(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1608 iopolicysys_vfs_atime_updates(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1610 iopolicysys_vfs_materialize_dataless_files(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1612 iopolicysys_vfs_statfs_no_data_volume(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1614 iopolicysys_vfs_trigger_resolve(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1616 iopolicysys_vfs_ignore_content_protection(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1621 * Description: System call MUX for use in manipulating I/O policy attributes of the current process or thread
1623 * Parameters: cmd Policy command
1624 * arg Pointer to policy arguments
1626 * Returns: 0 Success
1627 * EINVAL Invalid command or invalid policy arguments
1631 iopolicysys(struct proc
*p
, struct iopolicysys_args
*uap
, int32_t *retval
)
1634 struct _iopol_param_t iop_param
;
1636 if ((error
= copyin(uap
->arg
, &iop_param
, sizeof(iop_param
))) != 0) {
1640 switch (iop_param
.iop_iotype
) {
1641 case IOPOL_TYPE_DISK
:
1642 error
= iopolicysys_disk(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1643 if (error
== EIDRM
) {
1651 case IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY
:
1652 error
= iopolicysys_vfs_hfs_case_sensitivity(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1657 case IOPOL_TYPE_VFS_ATIME_UPDATES
:
1658 error
= iopolicysys_vfs_atime_updates(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1663 case IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES
:
1664 error
= iopolicysys_vfs_materialize_dataless_files(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1669 case IOPOL_TYPE_VFS_STATFS_NO_DATA_VOLUME
:
1670 error
= iopolicysys_vfs_statfs_no_data_volume(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1675 case IOPOL_TYPE_VFS_TRIGGER_RESOLVE
:
1676 error
= iopolicysys_vfs_trigger_resolve(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1681 case IOPOL_TYPE_VFS_IGNORE_CONTENT_PROTECTION
:
1682 error
= iopolicysys_vfs_ignore_content_protection(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1692 /* Individual iotype handlers are expected to update iop_param, if requested with a GET command */
1693 if (uap
->cmd
== IOPOL_CMD_GET
) {
1694 error
= copyout((caddr_t
)&iop_param
, uap
->arg
, sizeof(iop_param
));
1705 iopolicysys_disk(struct proc
*p __unused
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
1711 /* Validate scope */
1713 case IOPOL_SCOPE_PROCESS
:
1714 thread
= THREAD_NULL
;
1715 policy_flavor
= TASK_POLICY_IOPOL
;
1718 case IOPOL_SCOPE_THREAD
:
1719 thread
= current_thread();
1720 policy_flavor
= TASK_POLICY_IOPOL
;
1722 /* Not allowed to combine QoS and (non-PASSIVE) IO policy, doing so strips the QoS */
1723 if (cmd
== IOPOL_CMD_SET
&& thread_has_qos_policy(thread
)) {
1729 case IOPOL_THROTTLE
:
1730 case IOPOL_IMPORTANT
:
1731 case IOPOL_STANDARD
:
1732 if (!thread_is_static_param(thread
)) {
1733 thread_remove_qos_policy(thread
);
1735 * This is not an error case, this is to return a marker to user-space that
1736 * we stripped the thread of its QoS class.
1749 case IOPOL_SCOPE_DARWIN_BG
:
1750 #if !defined(XNU_TARGET_OS_OSX)
1751 /* We don't want this on platforms outside of macOS as BG is always IOPOL_THROTTLE */
1754 #else /* !defined(XNU_TARGET_OS_OSX) */
1755 thread
= THREAD_NULL
;
1756 policy_flavor
= TASK_POLICY_DARWIN_BG_IOPOL
;
1758 #endif /* !defined(XNU_TARGET_OS_OSX) */
1765 /* Validate policy */
1766 if (cmd
== IOPOL_CMD_SET
) {
1769 if (scope
== IOPOL_SCOPE_DARWIN_BG
) {
1770 /* the current default BG throttle level is UTILITY */
1771 policy
= IOPOL_UTILITY
;
1773 policy
= IOPOL_IMPORTANT
;
1778 case IOPOL_THROTTLE
:
1779 /* These levels are OK */
1781 case IOPOL_IMPORTANT
:
1783 case IOPOL_STANDARD
:
1786 if (scope
== IOPOL_SCOPE_DARWIN_BG
) {
1787 /* These levels are invalid for BG */
1791 /* OK for other scopes */
1800 /* Perform command */
1803 if (thread
!= THREAD_NULL
) {
1804 proc_set_thread_policy(thread
, TASK_POLICY_INTERNAL
, policy_flavor
, policy
);
1806 proc_set_task_policy(current_task(), TASK_POLICY_INTERNAL
, policy_flavor
, policy
);
1810 if (thread
!= THREAD_NULL
) {
1811 policy
= proc_get_thread_policy(thread
, TASK_POLICY_INTERNAL
, policy_flavor
);
1813 policy
= proc_get_task_policy(current_task(), TASK_POLICY_INTERNAL
, policy_flavor
);
1815 iop_param
->iop_policy
= policy
;
1818 error
= EINVAL
; /* unknown command */
1827 iopolicysys_vfs_hfs_case_sensitivity(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
1831 /* Validate scope */
1833 case IOPOL_SCOPE_PROCESS
:
1834 /* Only process OK */
1841 /* Validate policy */
1842 if (cmd
== IOPOL_CMD_SET
) {
1844 case IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
:
1846 case IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
:
1847 /* These policies are OK */
1855 /* Perform command */
1858 if (0 == kauth_cred_issuser(kauth_cred_get())) {
1859 /* If it's a non-root process, it needs to have the entitlement to set the policy */
1860 boolean_t entitled
= FALSE
;
1861 entitled
= IOTaskHasEntitlement(current_task(), "com.apple.private.iopol.case_sensitivity");
1869 case IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
:
1870 OSBitAndAtomic16(~((uint32_t)P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
), &p
->p_vfs_iopolicy
);
1872 case IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
:
1873 OSBitOrAtomic16((uint32_t)P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
, &p
->p_vfs_iopolicy
);
1882 iop_param
->iop_policy
= (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
)
1883 ? IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
1884 : IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
;
1887 error
= EINVAL
; /* unknown command */
1896 get_thread_atime_policy(struct uthread
*ut
)
1898 return (ut
->uu_flag
& UT_ATIME_UPDATE
) ? IOPOL_ATIME_UPDATES_OFF
: IOPOL_ATIME_UPDATES_DEFAULT
;
1902 set_thread_atime_policy(struct uthread
*ut
, int policy
)
1904 if (policy
== IOPOL_ATIME_UPDATES_OFF
) {
1905 ut
->uu_flag
|= UT_ATIME_UPDATE
;
1907 ut
->uu_flag
&= ~UT_ATIME_UPDATE
;
1912 set_task_atime_policy(struct proc
*p
, int policy
)
1914 if (policy
== IOPOL_ATIME_UPDATES_OFF
) {
1915 OSBitOrAtomic16((uint16_t)P_VFS_IOPOLICY_ATIME_UPDATES
, &p
->p_vfs_iopolicy
);
1917 OSBitAndAtomic16(~((uint16_t)P_VFS_IOPOLICY_ATIME_UPDATES
), &p
->p_vfs_iopolicy
);
1922 get_task_atime_policy(struct proc
*p
)
1924 return (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_ATIME_UPDATES
) ? IOPOL_ATIME_UPDATES_OFF
: IOPOL_ATIME_UPDATES_DEFAULT
;
1928 iopolicysys_vfs_atime_updates(struct proc
*p __unused
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
1933 /* Validate scope */
1935 case IOPOL_SCOPE_THREAD
:
1936 thread
= current_thread();
1938 case IOPOL_SCOPE_PROCESS
:
1939 thread
= THREAD_NULL
;
1946 /* Validate policy */
1947 if (cmd
== IOPOL_CMD_SET
) {
1949 case IOPOL_ATIME_UPDATES_DEFAULT
:
1950 case IOPOL_ATIME_UPDATES_OFF
:
1958 /* Perform command */
1961 if (thread
!= THREAD_NULL
) {
1962 set_thread_atime_policy(get_bsdthread_info(thread
), policy
);
1964 set_task_atime_policy(p
, policy
);
1968 if (thread
!= THREAD_NULL
) {
1969 policy
= get_thread_atime_policy(get_bsdthread_info(thread
));
1971 policy
= get_task_atime_policy(p
);
1973 iop_param
->iop_policy
= policy
;
1976 error
= EINVAL
; /* unknown command */
1985 get_thread_materialize_policy(struct uthread
*ut
)
1987 if (ut
->uu_flag
& UT_NSPACE_NODATALESSFAULTS
) {
1988 return IOPOL_MATERIALIZE_DATALESS_FILES_OFF
;
1989 } else if (ut
->uu_flag
& UT_NSPACE_FORCEDATALESSFAULTS
) {
1990 return IOPOL_MATERIALIZE_DATALESS_FILES_ON
;
1992 /* Default thread behavior is "inherit process behavior". */
1993 return IOPOL_MATERIALIZE_DATALESS_FILES_DEFAULT
;
1997 set_thread_materialize_policy(struct uthread
*ut
, int policy
)
1999 if (policy
== IOPOL_MATERIALIZE_DATALESS_FILES_OFF
) {
2000 ut
->uu_flag
&= ~UT_NSPACE_FORCEDATALESSFAULTS
;
2001 ut
->uu_flag
|= UT_NSPACE_NODATALESSFAULTS
;
2002 } else if (policy
== IOPOL_MATERIALIZE_DATALESS_FILES_ON
) {
2003 ut
->uu_flag
&= ~UT_NSPACE_NODATALESSFAULTS
;
2004 ut
->uu_flag
|= UT_NSPACE_FORCEDATALESSFAULTS
;
2006 ut
->uu_flag
&= ~(UT_NSPACE_NODATALESSFAULTS
| UT_NSPACE_FORCEDATALESSFAULTS
);
2011 set_proc_materialize_policy(struct proc
*p
, int policy
)
2013 if (policy
== IOPOL_MATERIALIZE_DATALESS_FILES_DEFAULT
) {
2015 * Caller has specified "use the default policy".
2016 * The default policy is to NOT materialize dataless
2019 policy
= IOPOL_MATERIALIZE_DATALESS_FILES_OFF
;
2021 if (policy
== IOPOL_MATERIALIZE_DATALESS_FILES_ON
) {
2022 OSBitOrAtomic16((uint16_t)P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES
, &p
->p_vfs_iopolicy
);
2024 OSBitAndAtomic16(~((uint16_t)P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES
), &p
->p_vfs_iopolicy
);
2029 get_proc_materialize_policy(struct proc
*p
)
2031 return (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES
) ? IOPOL_MATERIALIZE_DATALESS_FILES_ON
: IOPOL_MATERIALIZE_DATALESS_FILES_OFF
;
2035 iopolicysys_vfs_materialize_dataless_files(struct proc
*p __unused
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
2040 /* Validate scope */
2042 case IOPOL_SCOPE_THREAD
:
2043 thread
= current_thread();
2045 case IOPOL_SCOPE_PROCESS
:
2046 thread
= THREAD_NULL
;
2053 /* Validate policy */
2054 if (cmd
== IOPOL_CMD_SET
) {
2056 case IOPOL_MATERIALIZE_DATALESS_FILES_DEFAULT
:
2057 case IOPOL_MATERIALIZE_DATALESS_FILES_OFF
:
2058 case IOPOL_MATERIALIZE_DATALESS_FILES_ON
:
2066 /* Perform command */
2069 if (thread
!= THREAD_NULL
) {
2070 set_thread_materialize_policy(get_bsdthread_info(thread
), policy
);
2072 set_proc_materialize_policy(p
, policy
);
2076 if (thread
!= THREAD_NULL
) {
2077 policy
= get_thread_materialize_policy(get_bsdthread_info(thread
));
2079 policy
= get_proc_materialize_policy(p
);
2081 iop_param
->iop_policy
= policy
;
2084 error
= EINVAL
; /* unknown command */
2093 iopolicysys_vfs_statfs_no_data_volume(struct proc
*p __unused
, int cmd
,
2094 int scope
, int policy
, struct _iopol_param_t
*iop_param
)
2098 /* Validate scope */
2100 case IOPOL_SCOPE_PROCESS
:
2101 /* Only process OK */
2108 /* Validate policy */
2109 if (cmd
== IOPOL_CMD_SET
) {
2111 case IOPOL_VFS_STATFS_NO_DATA_VOLUME_DEFAULT
:
2113 case IOPOL_VFS_STATFS_FORCE_NO_DATA_VOLUME
:
2114 /* These policies are OK */
2122 /* Perform command */
2125 if (0 == kauth_cred_issuser(kauth_cred_get())) {
2126 /* If it's a non-root process, it needs to have the entitlement to set the policy */
2127 boolean_t entitled
= FALSE
;
2128 entitled
= IOTaskHasEntitlement(current_task(), "com.apple.private.iopol.case_sensitivity");
2136 case IOPOL_VFS_STATFS_NO_DATA_VOLUME_DEFAULT
:
2137 OSBitAndAtomic16(~((uint32_t)P_VFS_IOPOLICY_STATFS_NO_DATA_VOLUME
), &p
->p_vfs_iopolicy
);
2139 case IOPOL_VFS_STATFS_FORCE_NO_DATA_VOLUME
:
2140 OSBitOrAtomic16((uint32_t)P_VFS_IOPOLICY_STATFS_NO_DATA_VOLUME
, &p
->p_vfs_iopolicy
);
2149 iop_param
->iop_policy
= (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_STATFS_NO_DATA_VOLUME
)
2150 ? IOPOL_VFS_STATFS_FORCE_NO_DATA_VOLUME
2151 : IOPOL_VFS_STATFS_NO_DATA_VOLUME_DEFAULT
;
2154 error
= EINVAL
; /* unknown command */
2163 iopolicysys_vfs_trigger_resolve(struct proc
*p __unused
, int cmd
,
2164 int scope
, int policy
, struct _iopol_param_t
*iop_param
)
2168 /* Validate scope */
2170 case IOPOL_SCOPE_PROCESS
:
2171 /* Only process OK */
2178 /* Validate policy */
2179 if (cmd
== IOPOL_CMD_SET
) {
2181 case IOPOL_VFS_TRIGGER_RESOLVE_DEFAULT
:
2183 case IOPOL_VFS_TRIGGER_RESOLVE_OFF
:
2184 /* These policies are OK */
2192 /* Perform command */
2196 case IOPOL_VFS_TRIGGER_RESOLVE_DEFAULT
:
2197 OSBitAndAtomic16(~((uint32_t)P_VFS_IOPOLICY_TRIGGER_RESOLVE_DISABLE
), &p
->p_vfs_iopolicy
);
2199 case IOPOL_VFS_TRIGGER_RESOLVE_OFF
:
2200 OSBitOrAtomic16((uint32_t)P_VFS_IOPOLICY_TRIGGER_RESOLVE_DISABLE
, &p
->p_vfs_iopolicy
);
2209 iop_param
->iop_policy
= (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_TRIGGER_RESOLVE_DISABLE
)
2210 ? IOPOL_VFS_TRIGGER_RESOLVE_OFF
2211 : IOPOL_VFS_TRIGGER_RESOLVE_DEFAULT
;
2214 error
= EINVAL
; /* unknown command */
2223 iopolicysys_vfs_ignore_content_protection(struct proc
*p
, int cmd
, int scope
,
2224 int policy
, struct _iopol_param_t
*iop_param
)
2228 /* Validate scope */
2230 case IOPOL_SCOPE_PROCESS
:
2231 /* Only process OK */
2238 /* Validate policy */
2239 if (cmd
== IOPOL_CMD_SET
) {
2241 case IOPOL_VFS_CONTENT_PROTECTION_DEFAULT
:
2243 case IOPOL_VFS_CONTENT_PROTECTION_IGNORE
:
2244 /* These policies are OK */
2252 /* Perform command */
2255 if (0 == kauth_cred_issuser(kauth_cred_get())) {
2256 /* If it's a non-root process, it needs to have the entitlement to set the policy */
2257 boolean_t entitled
= FALSE
;
2258 entitled
= IOTaskHasEntitlement(current_task(), "com.apple.private.iopol.case_sensitivity");
2266 case IOPOL_VFS_CONTENT_PROTECTION_DEFAULT
:
2267 os_atomic_andnot(&p
->p_vfs_iopolicy
, P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION
, relaxed
);
2269 case IOPOL_VFS_CONTENT_PROTECTION_IGNORE
:
2270 os_atomic_or(&p
->p_vfs_iopolicy
, P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION
, relaxed
);
2279 iop_param
->iop_policy
= (os_atomic_load(&p
->p_vfs_iopolicy
, relaxed
) & P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION
)
2280 ? IOPOL_VFS_CONTENT_PROTECTION_IGNORE
2281 : IOPOL_VFS_CONTENT_PROTECTION_DEFAULT
;
2284 error
= EINVAL
; /* unknown command */
2292 /* BSD call back function for task_policy networking changes */
2294 proc_apply_task_networkbg(void * bsd_info
, thread_t thread
)
2296 assert(bsd_info
!= PROC_NULL
);
2298 pid_t pid
= proc_pid((proc_t
)bsd_info
);
2300 proc_t p
= proc_find(pid
);
2302 if (p
!= PROC_NULL
) {
2303 assert(p
== (proc_t
)bsd_info
);
2305 do_background_socket(p
, thread
);
2311 gather_rusage_info(proc_t p
, rusage_info_current
*ru
, int flavor
)
2313 struct rusage_info_child
*ri_child
;
2315 assert(p
->p_stats
!= NULL
);
2316 memset(ru
, 0, sizeof(*ru
));
2318 case RUSAGE_INFO_V5
:
2319 #if !XNU_TARGET_OS_OSX && __has_feature(ptrauth_calls)
2320 if (vm_shared_region_is_reslide(p
->task
)) {
2321 ru
->ri_flags
|= RU_PROC_RUNS_RESLIDE
;
2323 #endif /* !XNU_TARGET_OS_OSX && __has_feature(ptrauth_calls) */
2325 case RUSAGE_INFO_V4
:
2326 ru
->ri_logical_writes
= get_task_logical_writes(p
->task
, FALSE
);
2327 ru
->ri_lifetime_max_phys_footprint
= get_task_phys_footprint_lifetime_max(p
->task
);
2328 #if CONFIG_LEDGER_INTERVAL_MAX
2329 ru
->ri_interval_max_phys_footprint
= get_task_phys_footprint_interval_max(p
->task
, FALSE
);
2331 fill_task_monotonic_rusage(p
->task
, ru
);
2334 case RUSAGE_INFO_V3
:
2335 fill_task_qos_rusage(p
->task
, ru
);
2336 fill_task_billed_usage(p
->task
, ru
);
2339 case RUSAGE_INFO_V2
:
2340 fill_task_io_rusage(p
->task
, ru
);
2343 case RUSAGE_INFO_V1
:
2345 * p->p_stats->ri_child statistics are protected under proc lock.
2349 ri_child
= &(p
->p_stats
->ri_child
);
2350 ru
->ri_child_user_time
= ri_child
->ri_child_user_time
;
2351 ru
->ri_child_system_time
= ri_child
->ri_child_system_time
;
2352 ru
->ri_child_pkg_idle_wkups
= ri_child
->ri_child_pkg_idle_wkups
;
2353 ru
->ri_child_interrupt_wkups
= ri_child
->ri_child_interrupt_wkups
;
2354 ru
->ri_child_pageins
= ri_child
->ri_child_pageins
;
2355 ru
->ri_child_elapsed_abstime
= ri_child
->ri_child_elapsed_abstime
;
2360 case RUSAGE_INFO_V0
:
2361 proc_getexecutableuuid(p
, (unsigned char *)&ru
->ri_uuid
, sizeof(ru
->ri_uuid
));
2362 fill_task_rusage(p
->task
, ru
);
2363 ru
->ri_proc_start_abstime
= p
->p_stats
->ps_start
;
2368 proc_get_rusage(proc_t p
, int flavor
, user_addr_t buffer
, __unused
int is_zombie
)
2370 rusage_info_current ri_current
= {};
2376 case RUSAGE_INFO_V0
:
2377 size
= sizeof(struct rusage_info_v0
);
2380 case RUSAGE_INFO_V1
:
2381 size
= sizeof(struct rusage_info_v1
);
2384 case RUSAGE_INFO_V2
:
2385 size
= sizeof(struct rusage_info_v2
);
2388 case RUSAGE_INFO_V3
:
2389 size
= sizeof(struct rusage_info_v3
);
2392 case RUSAGE_INFO_V4
:
2393 size
= sizeof(struct rusage_info_v4
);
2396 case RUSAGE_INFO_V5
:
2397 size
= sizeof(struct rusage_info_v5
);
2408 * If task is still alive, collect info from the live task itself.
2409 * Otherwise, look to the cached info in the zombie proc.
2411 if (p
->p_ru
== NULL
) {
2412 gather_rusage_info(p
, &ri_current
, flavor
);
2413 ri_current
.ri_proc_exit_abstime
= 0;
2414 error
= copyout(&ri_current
, buffer
, size
);
2416 ri_current
= p
->p_ru
->ri
;
2417 error
= copyout(&p
->p_ru
->ri
, buffer
, size
);
2424 mach_to_bsd_rv(int mach_rv
)
2432 case KERN_INVALID_ARGUMENT
:
2436 panic("unknown error %#x", mach_rv
);
2443 * Resource limit controls
2445 * uap->flavor available flavors:
2447 * RLIMIT_WAKEUPS_MONITOR
2448 * RLIMIT_CPU_USAGE_MONITOR
2449 * RLIMIT_THREAD_CPULIMITS
2450 * RLIMIT_FOOTPRINT_INTERVAL
2453 proc_rlimit_control(__unused
struct proc
*p
, struct proc_rlimit_control_args
*uap
, __unused
int32_t *retval
)
2457 struct proc_rlimit_control_wakeupmon wakeupmon_args
;
2458 uint32_t cpumon_flags
;
2459 uint32_t cpulimits_flags
;
2460 kauth_cred_t my_cred
, target_cred
;
2461 #if CONFIG_LEDGER_INTERVAL_MAX
2462 uint32_t footprint_interval_flags
;
2463 uint64_t interval_max_footprint
;
2464 #endif /* CONFIG_LEDGER_INTERVAL_MAX */
2466 /* -1 implicitly means our own process (perhaps even the current thread for per-thread attributes) */
2467 if (uap
->pid
== -1) {
2468 targetp
= proc_self();
2470 targetp
= proc_find(uap
->pid
);
2473 /* proc_self() can return NULL for an exiting process */
2474 if (targetp
== PROC_NULL
) {
2478 my_cred
= kauth_cred_get();
2479 target_cred
= kauth_cred_proc_ref(targetp
);
2481 if (!kauth_cred_issuser(my_cred
) && kauth_cred_getruid(my_cred
) &&
2482 kauth_cred_getuid(my_cred
) != kauth_cred_getuid(target_cred
) &&
2483 kauth_cred_getruid(my_cred
) != kauth_cred_getuid(target_cred
)) {
2485 kauth_cred_unref(&target_cred
);
2489 switch (uap
->flavor
) {
2490 case RLIMIT_WAKEUPS_MONITOR
:
2491 if ((error
= copyin(uap
->arg
, &wakeupmon_args
, sizeof(wakeupmon_args
))) != 0) {
2494 if ((error
= mach_to_bsd_rv(task_wakeups_monitor_ctl(targetp
->task
, &wakeupmon_args
.wm_flags
,
2495 &wakeupmon_args
.wm_rate
))) != 0) {
2498 error
= copyout(&wakeupmon_args
, uap
->arg
, sizeof(wakeupmon_args
));
2500 case RLIMIT_CPU_USAGE_MONITOR
:
2501 cpumon_flags
= (uint32_t)uap
->arg
; // XXX temporarily stashing flags in argp (12592127)
2502 error
= mach_to_bsd_rv(task_cpu_usage_monitor_ctl(targetp
->task
, &cpumon_flags
));
2504 case RLIMIT_THREAD_CPULIMITS
:
2505 cpulimits_flags
= (uint32_t)uap
->arg
; // only need a limited set of bits, pass in void * argument
2507 if (uap
->pid
!= -1) {
2512 uint8_t percent
= 0;
2513 uint32_t ms_refill
= 0;
2516 percent
= (uint8_t)(cpulimits_flags
& 0xffU
); /* low 8 bits for percent */
2517 ms_refill
= (cpulimits_flags
>> 8) & 0xffffff; /* next 24 bits represent ms refill value */
2518 if (percent
>= 100) {
2523 ns_refill
= ((uint64_t)ms_refill
) * NSEC_PER_MSEC
;
2525 error
= mach_to_bsd_rv(thread_set_cpulimit(THREAD_CPULIMIT_BLOCK
, percent
, ns_refill
));
2528 #if CONFIG_LEDGER_INTERVAL_MAX
2529 case RLIMIT_FOOTPRINT_INTERVAL
:
2530 footprint_interval_flags
= (uint32_t)uap
->arg
; // XXX temporarily stashing flags in argp (12592127)
2532 * There is currently only one option for this flavor.
2534 if ((footprint_interval_flags
& FOOTPRINT_INTERVAL_RESET
) == 0) {
2538 interval_max_footprint
= get_task_phys_footprint_interval_max(targetp
->task
, TRUE
);
2540 #endif /* CONFIG_LEDGER_INTERVAL_MAX */
2547 kauth_cred_unref(&target_cred
);
2550 * Return value from this function becomes errno to userland caller.
2556 * Return the current amount of CPU consumed by this thread (in either user or kernel mode)
2559 thread_selfusage(struct proc
*p __unused
, struct thread_selfusage_args
*uap __unused
, uint64_t *retval
)
2563 runtime
= thread_get_runtime_self();
2571 thread_selfcounts(__unused
struct proc
*p
, __unused
struct thread_selfcounts_args
*uap
, __unused
int *ret_out
)
2575 #endif /* !MONOTONIC */