2 * Copyright (c) 2000-2008 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 <machine/spl.h>
86 #include <sys/mount_internal.h>
87 #include <sys/sysproto.h>
89 #include <security/audit/audit.h>
91 #include <machine/vmparam.h>
93 #include <mach/mach_types.h>
94 #include <mach/time_value.h>
95 #include <mach/task.h>
96 #include <mach/task_info.h>
97 #include <mach/vm_map.h>
98 #include <mach/mach_vm.h>
99 #include <mach/thread_act.h> /* for thread_policy_set( ) */
100 #include <kern/lock.h>
101 #include <kern/thread.h>
103 #include <kern/task.h>
104 #include <kern/clock.h> /* for absolutetime_to_microtime() */
105 #include <netinet/in.h> /* for TRAFFIC_MGT_SO_* */
106 #include <sys/socketvar.h> /* for struct socket */
108 #include <vm/vm_map.h>
110 #include <kern/assert.h>
111 #include <sys/resource.h>
113 int donice(struct proc
*curp
, struct proc
*chgp
, int n
);
114 int dosetrlimit(struct proc
*p
, u_int which
, struct rlimit
*limp
);
115 int uthread_get_background_state(uthread_t
);
116 static void do_background_socket(struct proc
*p
, thread_t thread
, int priority
);
117 static int do_background_thread(struct proc
*curp
, thread_t thread
, int priority
);
118 static int do_background_proc(struct proc
*curp
, struct proc
*targetp
, int priority
);
119 static int get_background_proc(struct proc
*curp
, struct proc
*targetp
, int *priority
);
120 void proc_apply_task_networkbg_internal(proc_t
, thread_t
);
121 void proc_restore_task_networkbg_internal(proc_t
, thread_t
);
122 int proc_pid_rusage(int pid
, int flavor
, user_addr_t buf
, int32_t *retval
);
123 void gather_rusage_info_v2(proc_t p
, struct rusage_info_v2
*ru
, int flavor
);
124 int fill_task_rusage_v2(task_t task
, struct rusage_info_v2
*ri
);
125 static void rusage_info_v2_to_v0(struct rusage_info_v0
*ri_v0
, struct rusage_info_v2
*ri_v2
);
126 static void rusage_info_v2_to_v1(struct rusage_info_v1
*ri_v1
, struct rusage_info_v2
*ri_v2
);
128 int proc_get_rusage(proc_t p
, int flavor
, user_addr_t buffer
, __unused
int is_zombie
);
130 rlim_t maxdmap
= MAXDSIZ
; /* XXX */
131 rlim_t maxsmap
= MAXSSIZ
- PAGE_SIZE
; /* XXX */
134 * Limits on the number of open files per process, and the number
135 * of child processes per process.
137 * Note: would be in kern/subr_param.c in FreeBSD.
139 __private_extern__
int maxfilesperproc
= OPEN_MAX
; /* per-proc open files limit */
141 SYSCTL_INT(_kern
, KERN_MAXPROCPERUID
, maxprocperuid
, CTLFLAG_RW
| CTLFLAG_LOCKED
,
142 &maxprocperuid
, 0, "Maximum processes allowed per userid" );
144 SYSCTL_INT(_kern
, KERN_MAXFILESPERPROC
, maxfilesperproc
, CTLFLAG_RW
| CTLFLAG_LOCKED
,
145 &maxfilesperproc
, 0, "Maximum files allowed open per process" );
147 /* Args and fn for proc_iteration callback used in setpriority */
148 struct puser_nice_args
{
155 static int puser_donice_callback(proc_t p
, void * arg
);
158 /* Args and fn for proc_iteration callback used in setpriority */
159 struct ppgrp_nice_args
{
165 static int ppgrp_donice_callback(proc_t p
, void * arg
);
168 * Resource controls and accounting.
171 getpriority(struct proc
*curp
, struct getpriority_args
*uap
, int32_t *retval
)
174 int low
= PRIO_MAX
+ 1;
175 kauth_cred_t my_cred
;
179 /* would also test (uap->who < 0), but id_t is unsigned */
180 if (uap
->who
> 0x7fffffff)
183 switch (uap
->which
) {
190 p
= proc_find(uap
->who
);
200 struct pgrp
*pg
= PGRP_NULL
;
203 /* returns the pgrp to ref */
204 pg
= proc_pgrp(curp
);
205 } else if ((pg
= pgfind(uap
->who
)) == PGRP_NULL
) {
208 /* No need for iteration as it is a simple scan */
210 for (p
= pg
->pg_members
.lh_first
; p
!= 0; p
= p
->p_pglist
.le_next
) {
221 uap
->who
= kauth_cred_getuid(kauth_cred_get());
225 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
226 my_cred
= kauth_cred_proc_ref(p
);
227 if (kauth_cred_getuid(my_cred
) == uap
->who
&&
230 kauth_cred_unref(&my_cred
);
237 case PRIO_DARWIN_THREAD
:
238 /* we currently only support the current thread */
242 low
= proc_get_task_policy(current_task(), current_thread(), TASK_POLICY_INTERNAL
, TASK_POLICY_DARWIN_BG
);
246 case PRIO_DARWIN_PROCESS
:
250 p
= proc_find(uap
->who
);
256 error
= get_background_proc(curp
, p
, &low
);
267 if (low
== PRIO_MAX
+ 1)
273 /* call back function used for proc iteration in PRIO_USER */
275 puser_donice_callback(proc_t p
, void * arg
)
278 struct puser_nice_args
* pun
= (struct puser_nice_args
*)arg
;
279 kauth_cred_t my_cred
;
281 my_cred
= kauth_cred_proc_ref(p
);
282 if (kauth_cred_getuid(my_cred
) == pun
->who
) {
283 error
= donice(pun
->curp
, p
, pun
->prio
);
284 if (pun
->errorp
!= NULL
)
285 *pun
->errorp
= error
;
286 if (pun
->foundp
!= NULL
) {
291 kauth_cred_unref(&my_cred
);
293 return(PROC_RETURNED
);
296 /* call back function used for proc iteration in PRIO_PGRP */
298 ppgrp_donice_callback(proc_t p
, void * arg
)
301 struct ppgrp_nice_args
* pun
= (struct ppgrp_nice_args
*)arg
;
304 error
= donice(pun
->curp
, p
, pun
->prio
);
305 if (pun
->errorp
!= NULL
)
306 *pun
->errorp
= error
;
307 if (pun
->foundp
!= NULL
) {
312 return(PROC_RETURNED
);
324 setpriority(struct proc
*curp
, struct setpriority_args
*uap
, __unused
int32_t *retval
)
327 int found
= 0, error
= 0;
330 AUDIT_ARG(cmd
, uap
->which
);
331 AUDIT_ARG(owner
, uap
->who
, 0);
332 AUDIT_ARG(value32
, uap
->prio
);
334 /* would also test (uap->who < 0), but id_t is unsigned */
335 if (uap
->who
> 0x7fffffff)
338 switch (uap
->which
) {
344 p
= proc_find(uap
->who
);
349 error
= donice(curp
, p
, uap
->prio
);
356 struct pgrp
*pg
= PGRP_NULL
;
357 struct ppgrp_nice_args ppgrp
;
360 pg
= proc_pgrp(curp
);
361 } else if ((pg
= pgfind(uap
->who
)) == PGRP_NULL
)
365 ppgrp
.prio
= uap
->prio
;
366 ppgrp
.foundp
= &found
;
367 ppgrp
.errorp
= &error
;
369 /* PGRP_DROPREF drops the reference on process group */
370 pgrp_iterate(pg
, PGRP_DROPREF
, ppgrp_donice_callback
, (void *)&ppgrp
, NULL
, NULL
);
376 struct puser_nice_args punice
;
379 uap
->who
= kauth_cred_getuid(kauth_cred_get());
382 punice
.prio
= uap
->prio
;
383 punice
.who
= uap
->who
;
384 punice
.foundp
= &found
;
386 punice
.errorp
= &error
;
387 proc_iterate(PROC_ALLPROCLIST
, puser_donice_callback
, (void *)&punice
, NULL
, NULL
);
392 case PRIO_DARWIN_THREAD
: {
393 /* we currently only support the current thread */
397 error
= do_background_thread(curp
, current_thread(), uap
->prio
);
402 case PRIO_DARWIN_PROCESS
: {
406 p
= proc_find(uap
->who
);
412 error
= do_background_proc(curp
, p
, uap
->prio
);
433 * mac_check_proc_sched:???
436 donice(struct proc
*curp
, struct proc
*chgp
, int n
)
440 kauth_cred_t my_cred
;
442 ucred
= kauth_cred_proc_ref(curp
);
443 my_cred
= kauth_cred_proc_ref(chgp
);
445 if (suser(ucred
, NULL
) && kauth_cred_getruid(ucred
) &&
446 kauth_cred_getuid(ucred
) != kauth_cred_getuid(my_cred
) &&
447 kauth_cred_getruid(ucred
) != kauth_cred_getuid(my_cred
)) {
455 if (n
< chgp
->p_nice
&& suser(ucred
, &curp
->p_acflag
)) {
460 error
= mac_proc_check_sched(curp
, chgp
);
467 (void)resetpriority(chgp
);
469 kauth_cred_unref(&ucred
);
470 kauth_cred_unref(&my_cred
);
475 get_background_proc(struct proc
*curp
, struct proc
*targetp
, int *priority
)
479 kauth_cred_t ucred
, target_cred
;
481 ucred
= kauth_cred_get();
482 target_cred
= kauth_cred_proc_ref(targetp
);
484 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
485 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
486 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
)) {
491 external
= (curp
== targetp
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
493 *priority
= proc_get_task_policy(current_task(), THREAD_NULL
, external
, TASK_POLICY_DARWIN_BG
);
496 kauth_cred_unref(&target_cred
);
501 do_background_proc(struct proc
*curp
, struct proc
*targetp
, int priority
)
508 kauth_cred_t target_cred
;
513 ucred
= kauth_cred_get();
514 target_cred
= kauth_cred_proc_ref(targetp
);
516 if (!kauth_cred_issuser(ucred
) && kauth_cred_getruid(ucred
) &&
517 kauth_cred_getuid(ucred
) != kauth_cred_getuid(target_cred
) &&
518 kauth_cred_getruid(ucred
) != kauth_cred_getuid(target_cred
))
525 error
= mac_proc_check_sched(curp
, targetp
);
530 external
= (curp
== targetp
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
533 case PRIO_DARWIN_NONUI
:
534 flavor
= TASK_POLICY_GPU_DENY
;
535 enable
= TASK_POLICY_ENABLE
;
538 flavor
= TASK_POLICY_DARWIN_BG
;
539 enable
= TASK_POLICY_ENABLE
;
543 * DARWIN_BG and GPU_DENY disable are overloaded,
544 * so we need to turn them both off at the same time
546 * TODO: It would be nice to fail if priority != 0
548 flavor
= TASK_POLICY_DARWIN_BG_AND_GPU
;
549 enable
= TASK_POLICY_DISABLE
;
553 proc_set_task_policy(proc_task(targetp
), THREAD_NULL
, external
, flavor
, enable
);
556 kauth_cred_unref(&target_cred
);
561 do_background_socket(struct proc
*p
, thread_t thread
, int priority
)
564 struct filedesc
*fdp
;
568 if (priority
== PRIO_DARWIN_BG
) {
570 * For PRIO_DARWIN_PROCESS (thread is NULL), simply mark
571 * the sockets with the background flag. There's nothing
572 * to do here for the PRIO_DARWIN_THREAD case.
574 if (thread
== THREAD_NULL
) {
578 for (i
= 0; i
< fdp
->fd_nfiles
; i
++) {
579 struct socket
*sockp
;
581 fp
= fdp
->fd_ofiles
[i
];
582 if (fp
== NULL
|| (fdp
->fd_ofileflags
[i
] & UF_RESERVED
) != 0 ||
583 FILEGLOB_DTYPE(fp
->f_fglob
) != DTYPE_SOCKET
) {
586 sockp
= (struct socket
*)fp
->f_fglob
->fg_data
;
587 socket_set_traffic_mgt_flags(sockp
, TRAFFIC_MGT_SO_BACKGROUND
);
588 sockp
->so_background_thread
= NULL
;
595 /* disable networking IO throttle.
596 * NOTE - It is a known limitation of the current design that we
597 * could potentially clear TRAFFIC_MGT_SO_BACKGROUND bit for
598 * sockets created by other threads within this process.
602 for ( i
= 0; i
< fdp
->fd_nfiles
; i
++ ) {
603 struct socket
*sockp
;
605 fp
= fdp
->fd_ofiles
[ i
];
606 if ( fp
== NULL
|| (fdp
->fd_ofileflags
[ i
] & UF_RESERVED
) != 0 ||
607 FILEGLOB_DTYPE(fp
->f_fglob
) != DTYPE_SOCKET
) {
610 sockp
= (struct socket
*)fp
->f_fglob
->fg_data
;
611 /* skip if only clearing this thread's sockets */
612 if ((thread
) && (sockp
->so_background_thread
!= thread
)) {
615 socket_clear_traffic_mgt_flags(sockp
, TRAFFIC_MGT_SO_BACKGROUND
);
616 sockp
->so_background_thread
= NULL
;
621 #pragma unused(p, thread, priority)
627 * do_background_thread
629 * EPERM Tried to background while in vfork
630 * XXX - todo - does this need a MACF hook?
633 do_background_thread(struct proc
*curp
, thread_t thread
, int priority
)
636 int enable
, external
;
638 ut
= get_bsdthread_info(thread
);
640 /* Backgrounding is unsupported for threads in vfork */
641 if ((ut
->uu_flag
& UT_VFORK
) != 0)
644 /* TODO: Fail if someone passes something besides 0 or PRIO_DARWIN_BG */
645 enable
= (priority
== PRIO_DARWIN_BG
) ? TASK_POLICY_ENABLE
: TASK_POLICY_DISABLE
;
646 external
= (current_thread() == thread
) ? TASK_POLICY_INTERNAL
: TASK_POLICY_EXTERNAL
;
648 proc_set_task_policy_thread(curp
->task
, thread_tid(thread
), external
,
649 TASK_POLICY_DARWIN_BG
, enable
);
662 setrlimit(struct proc
*p
, struct setrlimit_args
*uap
, __unused
int32_t *retval
)
667 if ((error
= copyin(uap
->rlp
, (caddr_t
)&alim
,
668 sizeof (struct rlimit
))))
671 return (dosetrlimit(p
, uap
->which
, &alim
));
677 * ENOMEM Cannot copy limit structure
680 * Notes: EINVAL is returned both for invalid arguments, and in the
681 * case that the current usage (e.g. RLIMIT_STACK) is already
682 * in excess of the requested limit.
685 dosetrlimit(struct proc
*p
, u_int which
, struct rlimit
*limp
)
687 struct rlimit
*alimp
;
690 int posix
= (which
& _RLIMIT_POSIX_FLAG
) ? 1 : 0;
692 /* Mask out POSIX flag, saved above */
693 which
&= ~_RLIMIT_POSIX_FLAG
;
695 if (which
>= RLIM_NLIMITS
)
698 alimp
= &p
->p_rlimit
[which
];
699 if (limp
->rlim_cur
> limp
->rlim_max
)
702 if (limp
->rlim_cur
> alimp
->rlim_max
||
703 limp
->rlim_max
> alimp
->rlim_max
)
704 if ((error
= suser(kauth_cred_get(), &p
->p_acflag
))) {
710 if ((error
= proc_limitreplace(p
)) != 0) {
711 proc_limitunblock(p
);
715 alimp
= &p
->p_rlimit
[which
];
720 if (limp
->rlim_cur
== RLIM_INFINITY
) {
721 task_vtimer_clear(p
->task
, TASK_VTIMER_RLIM
);
722 timerclear(&p
->p_rlim_cpu
);
725 task_absolutetime_info_data_t tinfo
;
726 mach_msg_type_number_t count
;
727 struct timeval ttv
, tv
;
729 clock_usec_t tv_usec
;
731 count
= TASK_ABSOLUTETIME_INFO_COUNT
;
732 task_info(p
->task
, TASK_ABSOLUTETIME_INFO
,
733 (task_info_t
)&tinfo
, &count
);
734 absolutetime_to_microtime(tinfo
.total_user
+ tinfo
.total_system
,
737 ttv
.tv_usec
= tv_usec
;
739 tv
.tv_sec
= (limp
->rlim_cur
> __INT_MAX__
? __INT_MAX__
: limp
->rlim_cur
);
741 timersub(&tv
, &ttv
, &p
->p_rlim_cpu
);
744 if (timercmp(&p
->p_rlim_cpu
, &tv
, >))
745 task_vtimer_set(p
->task
, TASK_VTIMER_RLIM
);
747 task_vtimer_clear(p
->task
, TASK_VTIMER_RLIM
);
749 timerclear(&p
->p_rlim_cpu
);
757 if (limp
->rlim_cur
> maxdmap
)
758 limp
->rlim_cur
= maxdmap
;
759 if (limp
->rlim_max
> maxdmap
)
760 limp
->rlim_max
= maxdmap
;
764 /* Disallow illegal stack size instead of clipping */
765 if (limp
->rlim_cur
> maxsmap
||
766 limp
->rlim_max
> maxsmap
) {
773 * 4797860 - workaround poorly written installers by
774 * doing previous implementation (< 10.5) when caller
775 * is non-POSIX conforming.
777 if (limp
->rlim_cur
> maxsmap
)
778 limp
->rlim_cur
= maxsmap
;
779 if (limp
->rlim_max
> maxsmap
)
780 limp
->rlim_max
= maxsmap
;
785 * Stack is allocated to the max at exec time with only
786 * "rlim_cur" bytes accessible. If stack limit is going
787 * up make more accessible, if going down make inaccessible.
789 if (limp
->rlim_cur
> alimp
->rlim_cur
) {
794 size
= round_page_64(limp
->rlim_cur
);
795 size
-= round_page_64(alimp
->rlim_cur
);
797 addr
= p
->user_stack
- round_page_64(limp
->rlim_cur
);
798 kr
= mach_vm_protect(current_map(),
800 FALSE
, VM_PROT_DEFAULT
);
801 if (kr
!= KERN_SUCCESS
) {
805 } else if (limp
->rlim_cur
< alimp
->rlim_cur
) {
813 * First check if new stack limit would agree
814 * with current stack usage.
815 * Get the current thread's stack pointer...
817 cur_sp
= thread_adjuserstack(current_thread(),
819 if (cur_sp
<= p
->user_stack
&&
820 cur_sp
> (p
->user_stack
-
821 round_page_64(alimp
->rlim_cur
))) {
822 /* stack pointer is in main stack */
823 if (cur_sp
<= (p
->user_stack
-
824 round_page_64(limp
->rlim_cur
))) {
826 * New limit would cause
827 * current usage to be invalid:
834 /* not on the main stack: reject */
839 size
= round_page_64(alimp
->rlim_cur
);
840 size
-= round_page_64(limp
->rlim_cur
);
842 addr
= p
->user_stack
- round_page_64(alimp
->rlim_cur
);
844 kr
= mach_vm_protect(current_map(),
846 FALSE
, VM_PROT_NONE
);
847 if (kr
!= KERN_SUCCESS
) {
858 * Only root can set the maxfiles limits, as it is
859 * systemwide resource. If we are expecting POSIX behavior,
860 * instead of clamping the value, return EINVAL. We do this
861 * because historically, people have been able to attempt to
862 * set RLIM_INFINITY to get "whatever the maximum is".
864 if ( kauth_cred_issuser(kauth_cred_get()) ) {
865 if (limp
->rlim_cur
!= alimp
->rlim_cur
&&
866 limp
->rlim_cur
> (rlim_t
)maxfiles
) {
871 limp
->rlim_cur
= maxfiles
;
873 if (limp
->rlim_max
!= alimp
->rlim_max
&&
874 limp
->rlim_max
> (rlim_t
)maxfiles
)
875 limp
->rlim_max
= maxfiles
;
878 if (limp
->rlim_cur
!= alimp
->rlim_cur
&&
879 limp
->rlim_cur
> (rlim_t
)maxfilesperproc
) {
884 limp
->rlim_cur
= maxfilesperproc
;
886 if (limp
->rlim_max
!= alimp
->rlim_max
&&
887 limp
->rlim_max
> (rlim_t
)maxfilesperproc
)
888 limp
->rlim_max
= maxfilesperproc
;
894 * Only root can set to the maxproc limits, as it is
895 * systemwide resource; all others are limited to
896 * maxprocperuid (presumably less than maxproc).
898 if ( kauth_cred_issuser(kauth_cred_get()) ) {
899 if (limp
->rlim_cur
> (rlim_t
)maxproc
)
900 limp
->rlim_cur
= maxproc
;
901 if (limp
->rlim_max
> (rlim_t
)maxproc
)
902 limp
->rlim_max
= maxproc
;
905 if (limp
->rlim_cur
> (rlim_t
)maxprocperuid
)
906 limp
->rlim_cur
= maxprocperuid
;
907 if (limp
->rlim_max
> (rlim_t
)maxprocperuid
)
908 limp
->rlim_max
= maxprocperuid
;
914 * Tell the Mach VM layer about the new limit value.
917 vm_map_set_user_wire_limit(current_map(), limp
->rlim_cur
);
926 proc_limitunblock(p
);
932 getrlimit(struct proc
*p
, struct getrlimit_args
*uap
, __unused
int32_t *retval
)
937 * Take out flag now in case we need to use it to trigger variant
940 uap
->which
&= ~_RLIMIT_POSIX_FLAG
;
942 if (uap
->which
>= RLIM_NLIMITS
)
944 proc_limitget(p
, uap
->which
, &lim
);
945 return (copyout((caddr_t
)&lim
,
946 uap
->rlp
, sizeof (struct rlimit
)));
950 * Transform the running time and tick information in proc p into user,
951 * system, and interrupt time usage.
953 /* No lock on proc is held for this.. */
955 calcru(struct proc
*p
, struct timeval
*up
, struct timeval
*sp
, struct timeval
*ip
)
966 mach_task_basic_info_data_t tinfo
;
967 task_thread_times_info_data_t ttimesinfo
;
968 task_events_info_data_t teventsinfo
;
969 mach_msg_type_number_t task_info_count
, task_ttimes_count
;
970 mach_msg_type_number_t task_events_count
;
971 struct timeval ut
,st
;
973 task_info_count
= MACH_TASK_BASIC_INFO_COUNT
;
974 task_info(task
, MACH_TASK_BASIC_INFO
,
975 (task_info_t
)&tinfo
, &task_info_count
);
976 ut
.tv_sec
= tinfo
.user_time
.seconds
;
977 ut
.tv_usec
= tinfo
.user_time
.microseconds
;
978 st
.tv_sec
= tinfo
.system_time
.seconds
;
979 st
.tv_usec
= tinfo
.system_time
.microseconds
;
980 timeradd(&ut
, up
, up
);
981 timeradd(&st
, sp
, sp
);
983 task_ttimes_count
= TASK_THREAD_TIMES_INFO_COUNT
;
984 task_info(task
, TASK_THREAD_TIMES_INFO
,
985 (task_info_t
)&ttimesinfo
, &task_ttimes_count
);
987 ut
.tv_sec
= ttimesinfo
.user_time
.seconds
;
988 ut
.tv_usec
= ttimesinfo
.user_time
.microseconds
;
989 st
.tv_sec
= ttimesinfo
.system_time
.seconds
;
990 st
.tv_usec
= ttimesinfo
.system_time
.microseconds
;
991 timeradd(&ut
, up
, up
);
992 timeradd(&st
, sp
, sp
);
994 task_events_count
= TASK_EVENTS_INFO_COUNT
;
995 task_info(task
, TASK_EVENTS_INFO
,
996 (task_info_t
)&teventsinfo
, &task_events_count
);
999 * No need to lock "p": this does not need to be
1000 * completely consistent, right ?
1002 p
->p_stats
->p_ru
.ru_minflt
= (teventsinfo
.faults
-
1003 teventsinfo
.pageins
);
1004 p
->p_stats
->p_ru
.ru_majflt
= teventsinfo
.pageins
;
1005 p
->p_stats
->p_ru
.ru_nivcsw
= (teventsinfo
.csw
-
1006 p
->p_stats
->p_ru
.ru_nvcsw
);
1007 if (p
->p_stats
->p_ru
.ru_nivcsw
< 0)
1008 p
->p_stats
->p_ru
.ru_nivcsw
= 0;
1010 p
->p_stats
->p_ru
.ru_maxrss
= tinfo
.resident_size_max
;
1014 __private_extern__
void munge_user64_rusage(struct rusage
*a_rusage_p
, struct user64_rusage
*a_user_rusage_p
);
1015 __private_extern__
void munge_user32_rusage(struct rusage
*a_rusage_p
, struct user32_rusage
*a_user_rusage_p
);
1019 getrusage(struct proc
*p
, struct getrusage_args
*uap
, __unused
int32_t *retval
)
1021 struct rusage
*rup
, rubuf
;
1022 struct user64_rusage rubuf64
;
1023 struct user32_rusage rubuf32
;
1024 size_t retsize
= sizeof(rubuf
); /* default: 32 bits */
1025 caddr_t retbuf
= (caddr_t
)&rubuf
; /* default: 32 bits */
1026 struct timeval utime
;
1027 struct timeval stime
;
1032 calcru(p
, &utime
, &stime
, NULL
);
1034 rup
= &p
->p_stats
->p_ru
;
1035 rup
->ru_utime
= utime
;
1036 rup
->ru_stime
= stime
;
1043 case RUSAGE_CHILDREN
:
1045 rup
= &p
->p_stats
->p_cru
;
1053 if (IS_64BIT_PROCESS(p
)) {
1054 retsize
= sizeof(rubuf64
);
1055 retbuf
= (caddr_t
)&rubuf64
;
1056 munge_user64_rusage(&rubuf
, &rubuf64
);
1058 retsize
= sizeof(rubuf32
);
1059 retbuf
= (caddr_t
)&rubuf32
;
1060 munge_user32_rusage(&rubuf
, &rubuf32
);
1063 return (copyout(retbuf
, uap
->rusage
, retsize
));
1067 ruadd(struct rusage
*ru
, struct rusage
*ru2
)
1072 timeradd(&ru
->ru_utime
, &ru2
->ru_utime
, &ru
->ru_utime
);
1073 timeradd(&ru
->ru_stime
, &ru2
->ru_stime
, &ru
->ru_stime
);
1074 if (ru
->ru_maxrss
< ru2
->ru_maxrss
)
1075 ru
->ru_maxrss
= ru2
->ru_maxrss
;
1076 ip
= &ru
->ru_first
; ip2
= &ru2
->ru_first
;
1077 for (i
= &ru
->ru_last
- &ru
->ru_first
; i
>= 0; i
--)
1082 * Add the rusage stats of child in parent.
1084 * It adds rusage statistics of child process and statistics of all its
1085 * children to its parent.
1087 * Note: proc lock of parent should be held while calling this function.
1090 update_rusage_info_child(struct rusage_info_child
*ri
, struct rusage_info_v2
*ri2
)
1092 ri
->ri_child_user_time
+= (ri2
->ri_user_time
+
1093 ri2
->ri_child_user_time
);
1094 ri
->ri_child_system_time
+= (ri2
->ri_system_time
+
1095 ri2
->ri_child_system_time
);
1096 ri
->ri_child_pkg_idle_wkups
+= (ri2
->ri_pkg_idle_wkups
+
1097 ri2
->ri_child_pkg_idle_wkups
);
1098 ri
->ri_child_interrupt_wkups
+= (ri2
->ri_interrupt_wkups
+
1099 ri2
->ri_child_interrupt_wkups
);
1100 ri
->ri_child_pageins
+= (ri2
->ri_pageins
+
1101 ri2
->ri_child_pageins
);
1102 ri
->ri_child_elapsed_abstime
+= ((ri2
->ri_proc_exit_abstime
-
1103 ri2
->ri_proc_start_abstime
) + ri2
->ri_child_elapsed_abstime
);
1107 proc_limitget(proc_t p
, int which
, struct rlimit
* limp
)
1110 limp
->rlim_cur
= p
->p_rlimit
[which
].rlim_cur
;
1111 limp
->rlim_max
= p
->p_rlimit
[which
].rlim_max
;
1117 proc_limitdrop(proc_t p
, int exiting
)
1119 struct plimit
* freelim
= NULL
;
1120 struct plimit
* freeoldlim
= NULL
;
1124 if (--p
->p_limit
->pl_refcnt
== 0) {
1125 freelim
= p
->p_limit
;
1128 if ((exiting
!= 0) && (p
->p_olimit
!= NULL
) && (--p
->p_olimit
->pl_refcnt
== 0)) {
1129 freeoldlim
= p
->p_olimit
;
1134 if (freelim
!= NULL
)
1135 FREE_ZONE(freelim
, sizeof *p
->p_limit
, M_PLIMIT
);
1136 if (freeoldlim
!= NULL
)
1137 FREE_ZONE(freeoldlim
, sizeof *p
->p_olimit
, M_PLIMIT
);
1142 proc_limitfork(proc_t parent
, proc_t child
)
1145 child
->p_limit
= parent
->p_limit
;
1146 child
->p_limit
->pl_refcnt
++;
1147 child
->p_olimit
= NULL
;
1152 proc_limitblock(proc_t p
)
1155 while (p
->p_lflag
& P_LLIMCHANGE
) {
1156 p
->p_lflag
|= P_LLIMWAIT
;
1157 msleep(&p
->p_olimit
, &p
->p_mlock
, 0, "proc_limitblock", NULL
);
1159 p
->p_lflag
|= P_LLIMCHANGE
;
1166 proc_limitunblock(proc_t p
)
1169 p
->p_lflag
&= ~P_LLIMCHANGE
;
1170 if (p
->p_lflag
& P_LLIMWAIT
) {
1171 p
->p_lflag
&= ~P_LLIMWAIT
;
1172 wakeup(&p
->p_olimit
);
1177 /* This is called behind serialization provided by proc_limitblock/unlbock */
1179 proc_limitreplace(proc_t p
)
1181 struct plimit
*copy
;
1186 if (p
->p_limit
->pl_refcnt
== 1) {
1193 MALLOC_ZONE(copy
, struct plimit
*,
1194 sizeof(struct plimit
), M_PLIMIT
, M_WAITOK
);
1200 bcopy(p
->p_limit
->pl_rlimit
, copy
->pl_rlimit
,
1201 sizeof(struct rlimit
) * RLIM_NLIMITS
);
1202 copy
->pl_refcnt
= 1;
1203 /* hang on to reference to old till process exits */
1204 p
->p_olimit
= p
->p_limit
;
1214 * Description: System call MUX for use in manipulating I/O policy attributes of the current process or thread
1216 * Parameters: cmd Policy command
1217 * arg Pointer to policy arguments
1219 * Returns: 0 Success
1220 * EINVAL Invalid command or invalid policy arguments
1225 iopolicysys_disk(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1227 iopolicysys_vfs(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
);
1230 iopolicysys(struct proc
*p
, struct iopolicysys_args
*uap
, __unused
int32_t *retval
)
1233 struct _iopol_param_t iop_param
;
1235 if ((error
= copyin(uap
->arg
, &iop_param
, sizeof(iop_param
))) != 0)
1238 switch (iop_param
.iop_iotype
) {
1239 case IOPOL_TYPE_DISK
:
1240 error
= iopolicysys_disk(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1244 case IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY
:
1245 error
= iopolicysys_vfs(p
, uap
->cmd
, iop_param
.iop_scope
, iop_param
.iop_policy
, &iop_param
);
1254 /* Individual iotype handlers are expected to update iop_param, if requested with a GET command */
1255 if (uap
->cmd
== IOPOL_CMD_GET
) {
1256 error
= copyout((caddr_t
)&iop_param
, uap
->arg
, sizeof(iop_param
));
1266 iopolicysys_disk(struct proc
*p __unused
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
1272 /* Validate scope */
1274 case IOPOL_SCOPE_PROCESS
:
1275 thread
= THREAD_NULL
;
1276 policy_flavor
= TASK_POLICY_IOPOL
;
1279 case IOPOL_SCOPE_THREAD
:
1280 thread
= current_thread();
1281 policy_flavor
= TASK_POLICY_IOPOL
;
1284 case IOPOL_SCOPE_DARWIN_BG
:
1285 thread
= THREAD_NULL
;
1286 policy_flavor
= TASK_POLICY_DARWIN_BG_IOPOL
;
1294 /* Validate policy */
1295 if (cmd
== IOPOL_CMD_SET
) {
1298 if (scope
== IOPOL_SCOPE_DARWIN_BG
) {
1299 /* the current default BG throttle level is UTILITY */
1300 policy
= IOPOL_UTILITY
;
1302 policy
= IOPOL_IMPORTANT
;
1307 case IOPOL_THROTTLE
:
1308 /* These levels are OK */
1310 case IOPOL_IMPORTANT
:
1312 case IOPOL_STANDARD
:
1315 if (scope
== IOPOL_SCOPE_DARWIN_BG
) {
1316 /* These levels are invalid for BG */
1320 /* OK for other scopes */
1329 /* Perform command */
1332 proc_set_task_policy(current_task(), thread
,
1333 TASK_POLICY_INTERNAL
, policy_flavor
,
1337 policy
= proc_get_task_policy(current_task(), thread
,
1338 TASK_POLICY_INTERNAL
, policy_flavor
);
1340 iop_param
->iop_policy
= policy
;
1343 error
= EINVAL
; /* unknown command */
1352 iopolicysys_vfs(struct proc
*p
, int cmd
, int scope
, int policy
, struct _iopol_param_t
*iop_param
)
1356 /* Validate scope */
1358 case IOPOL_SCOPE_PROCESS
:
1359 /* Only process OK */
1366 /* Validate policy */
1367 if (cmd
== IOPOL_CMD_SET
) {
1369 case IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
:
1371 case IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
:
1372 /* These policies are OK */
1380 /* Perform command */
1383 if (0 == kauth_cred_issuser(kauth_cred_get())) {
1389 case IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
:
1390 OSBitAndAtomic16(~((uint32_t)P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
), &p
->p_vfs_iopolicy
);
1392 case IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
:
1393 OSBitOrAtomic16((uint32_t)P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
, &p
->p_vfs_iopolicy
);
1402 iop_param
->iop_policy
= (p
->p_vfs_iopolicy
& P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY
)
1403 ? IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE
1404 : IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT
;
1407 error
= EINVAL
; /* unknown command */
1415 /* BSD call back function for task_policy */
1416 void proc_apply_task_networkbg(void * bsd_info
, thread_t thread
, int bg
);
1419 proc_apply_task_networkbg(void * bsd_info
, thread_t thread
, int bg
)
1421 proc_t p
= PROC_NULL
;
1422 proc_t curp
= (proc_t
)bsd_info
;
1424 int prio
= (bg
? PRIO_DARWIN_BG
: 0);
1428 if (p
!= PROC_NULL
) {
1429 do_background_socket(p
, thread
, prio
);
1435 gather_rusage_info_v2(proc_t p
, struct rusage_info_v2
*ru
, int flavor
)
1437 struct rusage_info_child
*ri_child
;
1439 assert(p
->p_stats
!= NULL
);
1441 case RUSAGE_INFO_V2
:
1442 ru
->ri_diskio_bytesread
= p
->p_stats
->ri_diskiobytes
.ri_bytesread
;
1443 ru
->ri_diskio_byteswritten
= p
->p_stats
->ri_diskiobytes
.ri_byteswritten
;
1446 case RUSAGE_INFO_V1
:
1448 * p->p_stats->ri_child statistics are protected under proc lock.
1452 ri_child
= &(p
->p_stats
->ri_child
);
1453 ru
->ri_child_user_time
= ri_child
->ri_child_user_time
;
1454 ru
->ri_child_system_time
= ri_child
->ri_child_system_time
;
1455 ru
->ri_child_pkg_idle_wkups
= ri_child
->ri_child_pkg_idle_wkups
;
1456 ru
->ri_child_interrupt_wkups
= ri_child
->ri_child_interrupt_wkups
;
1457 ru
->ri_child_pageins
= ri_child
->ri_child_pageins
;
1458 ru
->ri_child_elapsed_abstime
= ri_child
->ri_child_elapsed_abstime
;
1463 case RUSAGE_INFO_V0
:
1464 proc_getexecutableuuid(p
, (unsigned char *)&ru
->ri_uuid
, sizeof (ru
->ri_uuid
));
1465 fill_task_rusage_v2(p
->task
, ru
);
1466 ru
->ri_proc_start_abstime
= p
->p_stats
->ps_start
;
1471 * Temporary function to copy value from rusage_info_v2 to rusage_info_v0.
1474 rusage_info_v2_to_v0(struct rusage_info_v0
*ri_v0
, struct rusage_info_v2
*ri_v2
)
1476 memcpy(&ri_v0
->ri_uuid
[0], &ri_v2
->ri_uuid
[0], sizeof(ri_v0
->ri_uuid
));
1477 ri_v0
->ri_user_time
= ri_v2
->ri_user_time
;
1478 ri_v0
->ri_system_time
= ri_v2
->ri_system_time
;
1479 ri_v0
->ri_pkg_idle_wkups
= ri_v2
->ri_pkg_idle_wkups
;
1480 ri_v0
->ri_interrupt_wkups
= ri_v2
->ri_interrupt_wkups
;
1481 ri_v0
->ri_pageins
= ri_v2
->ri_pageins
;
1482 ri_v0
->ri_wired_size
= ri_v2
->ri_wired_size
;
1483 ri_v0
->ri_resident_size
= ri_v2
->ri_resident_size
;
1484 ri_v0
->ri_phys_footprint
= ri_v2
->ri_phys_footprint
;
1485 ri_v0
->ri_proc_start_abstime
= ri_v2
->ri_proc_start_abstime
;
1486 ri_v0
->ri_proc_exit_abstime
= ri_v2
->ri_proc_exit_abstime
;
1490 rusage_info_v2_to_v1(struct rusage_info_v1
*ri_v1
, struct rusage_info_v2
*ri_v2
)
1492 memcpy(&ri_v1
->ri_uuid
[0], &ri_v2
->ri_uuid
[0], sizeof(ri_v1
->ri_uuid
));
1493 ri_v1
->ri_user_time
= ri_v2
->ri_user_time
;
1494 ri_v1
->ri_system_time
= ri_v2
->ri_system_time
;
1495 ri_v1
->ri_pkg_idle_wkups
= ri_v2
->ri_pkg_idle_wkups
;
1496 ri_v1
->ri_interrupt_wkups
= ri_v2
->ri_interrupt_wkups
;
1497 ri_v1
->ri_pageins
= ri_v2
->ri_pageins
;
1498 ri_v1
->ri_wired_size
= ri_v2
->ri_wired_size
;
1499 ri_v1
->ri_resident_size
= ri_v2
->ri_resident_size
;
1500 ri_v1
->ri_phys_footprint
= ri_v2
->ri_phys_footprint
;
1501 ri_v1
->ri_proc_start_abstime
= ri_v2
->ri_proc_start_abstime
;
1502 ri_v1
->ri_proc_exit_abstime
= ri_v2
->ri_proc_exit_abstime
;
1503 ri_v1
->ri_child_user_time
= ri_v2
->ri_child_user_time
;
1504 ri_v1
->ri_child_system_time
= ri_v2
->ri_child_system_time
;
1505 ri_v1
->ri_child_pkg_idle_wkups
= ri_v2
->ri_child_pkg_idle_wkups
;
1506 ri_v1
->ri_child_interrupt_wkups
= ri_v2
->ri_child_interrupt_wkups
;
1507 ri_v1
->ri_child_pageins
= ri_v2
->ri_child_pageins
;
1508 ri_v1
->ri_child_elapsed_abstime
= ri_v2
->ri_child_elapsed_abstime
;
1512 proc_get_rusage(proc_t p
, int flavor
, user_addr_t buffer
, __unused
int is_zombie
)
1514 struct rusage_info_v0 ri_v0
;
1515 struct rusage_info_v1 ri_v1
;
1516 struct rusage_info_v2 ri_v2
;
1521 case RUSAGE_INFO_V0
:
1523 * If task is still alive, collect info from the live task itself.
1524 * Otherwise, look to the cached info in the zombie proc.
1526 if (p
->p_ru
== NULL
) {
1527 gather_rusage_info_v2(p
, &ri_v2
, flavor
);
1528 ri_v2
.ri_proc_exit_abstime
= 0;
1529 rusage_info_v2_to_v0(&ri_v0
, &ri_v2
);
1531 rusage_info_v2_to_v0(&ri_v0
, &p
->p_ru
->ri
);
1533 error
= copyout(&ri_v0
, buffer
, sizeof (ri_v0
));
1536 case RUSAGE_INFO_V1
:
1538 * If task is still alive, collect info from the live task itself.
1539 * Otherwise, look to the cached info in the zombie proc.
1541 if (p
->p_ru
== NULL
) {
1542 gather_rusage_info_v2(p
, &ri_v2
, flavor
);
1543 ri_v2
.ri_proc_exit_abstime
= 0;
1544 rusage_info_v2_to_v1(&ri_v1
, &ri_v2
);
1546 rusage_info_v2_to_v1(&ri_v1
, &p
->p_ru
->ri
);
1548 error
= copyout(&ri_v1
, buffer
, sizeof (ri_v1
));
1551 case RUSAGE_INFO_V2
:
1553 * If task is still alive, collect info from the live task itself.
1554 * Otherwise, look to the cached info in the zombie proc.
1556 if (p
->p_ru
== NULL
) {
1557 gather_rusage_info_v2(p
, &ri_v2
, flavor
);
1558 ri_v2
.ri_proc_exit_abstime
= 0;
1560 ri_v2
= p
->p_ru
->ri
;
1562 error
= copyout(&ri_v2
, buffer
, sizeof (ri_v2
));
1574 mach_to_bsd_rv(int mach_rv
)
1582 case KERN_INVALID_ARGUMENT
:
1586 panic("unknown error %#x", mach_rv
);
1593 * Resource limit controls
1595 * uap->flavor available flavors:
1597 * RLIMIT_WAKEUPS_MONITOR
1600 proc_rlimit_control(__unused
struct proc
*p
, struct proc_rlimit_control_args
*uap
, int32_t *retval
)
1604 struct proc_rlimit_control_wakeupmon wakeupmon_args
;
1605 uint32_t cpumon_flags
;
1606 kauth_cred_t my_cred
, target_cred
;
1610 if ((targetp
= proc_find(uap
->pid
)) == PROC_NULL
) {
1615 my_cred
= kauth_cred_get();
1616 target_cred
= kauth_cred_proc_ref(targetp
);
1618 if (!kauth_cred_issuser(my_cred
) && kauth_cred_getruid(my_cred
) &&
1619 kauth_cred_getuid(my_cred
) != kauth_cred_getuid(target_cred
) &&
1620 kauth_cred_getruid(my_cred
) != kauth_cred_getuid(target_cred
)) {
1622 kauth_cred_unref(&target_cred
);
1628 switch (uap
->flavor
) {
1629 case RLIMIT_WAKEUPS_MONITOR
:
1630 if ((error
= copyin(uap
->arg
, &wakeupmon_args
, sizeof (wakeupmon_args
))) != 0) {
1633 if ((error
= mach_to_bsd_rv(task_wakeups_monitor_ctl(targetp
->task
, &wakeupmon_args
.wm_flags
,
1634 &wakeupmon_args
.wm_rate
))) != 0) {
1637 error
= copyout(&wakeupmon_args
, uap
->arg
, sizeof (wakeupmon_args
));
1639 case RLIMIT_CPU_USAGE_MONITOR
:
1640 cpumon_flags
= uap
->arg
; // XXX temporarily stashing flags in argp (12592127)
1641 error
= mach_to_bsd_rv(task_cpu_usage_monitor_ctl(targetp
->task
, &cpumon_flags
));
1649 kauth_cred_unref(&target_cred
);
1656 * Return value from this function becomes errno to userland caller.
1657 * *retval is what the system call invocation returns.