* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
* @(#)kern_resource.c 8.2 (Berkeley) %G%
#include <sys/resourcevar.h>
* Resource controls and accounting.
struct getpriority_args
{
getpriority(curp
, uap
, retval
)
register struct getpriority_args
*uap
;
register int low
= PRIO_MAX
+ 1;
register struct pgrp
*pg
;
else if ((pg
= pgfind(uap
->who
)) == NULL
)
for (p
= pg
->pg_mem
; p
!= NULL
; p
= p
->p_pgrpnxt
) {
uap
->who
= curp
->p_ucred
->cr_uid
;
for (p
= (struct proc
*)allproc
; p
!= NULL
; p
= p
->p_nxt
) {
if (p
->p_ucred
->cr_uid
== uap
->who
&&
struct setpriority_args
{
setpriority(curp
, uap
, retval
)
register struct setpriority_args
*uap
;
int found
= 0, error
= 0;
error
= donice(curp
, p
, uap
->prio
);
register struct pgrp
*pg
;
else if ((pg
= pgfind(uap
->who
)) == NULL
)
for (p
= pg
->pg_mem
; p
!= NULL
; p
= p
->p_pgrpnxt
) {
error
= donice(curp
, p
, uap
->prio
);
uap
->who
= curp
->p_ucred
->cr_uid
;
for (p
= (struct proc
*)allproc
; p
!= NULL
; p
= p
->p_nxt
)
if (p
->p_ucred
->cr_uid
== uap
->who
) {
error
= donice(curp
, p
, uap
->prio
);
register struct proc
*curp
, *chgp
;
register struct pcred
*pcred
= curp
->p_cred
;
if (pcred
->pc_ucred
->cr_uid
&& pcred
->p_ruid
&&
pcred
->pc_ucred
->cr_uid
!= chgp
->p_ucred
->cr_uid
&&
pcred
->p_ruid
!= chgp
->p_ucred
->cr_uid
)
if (n
< chgp
->p_nice
&& suser(pcred
->pc_ucred
, &curp
->p_acflag
))
(void)resetpriority(chgp
);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
osetrlimit(p
, uap
, retval
)
register struct setrlimit_args
*uap
;
copyin((caddr_t
)uap
->lim
, (caddr_t
)&olim
, sizeof (struct orlimit
)))
lim
.rlim_cur
= olim
.rlim_cur
;
lim
.rlim_max
= olim
.rlim_max
;
return (dosetrlimit(p
, uap
->which
, &lim
));
ogetrlimit(p
, uap
, retval
)
register struct getrlimit_args
*uap
;
if (uap
->which
>= RLIM_NLIMITS
)
olim
.rlim_cur
= p
->p_rlimit
[uap
->which
].rlim_cur
;
olim
.rlim_cur
= 0x7fffffff;
olim
.rlim_max
= p
->p_rlimit
[uap
->which
].rlim_max
;
olim
.rlim_max
= 0x7fffffff;
return (copyout((caddr_t
)&olim
, (caddr_t
)uap
->rlp
, sizeof(olim
)));
#endif /* COMPAT_43 || COMPAT_SUNOS */
struct __setrlimit_args
{
setrlimit(p
, uap
, retval
)
register struct __setrlimit_args
*uap
;
copyin((caddr_t
)uap
->lim
, (caddr_t
)&alim
, sizeof (struct rlimit
)))
return (dosetrlimit(p
, uap
->which
, &alim
));
dosetrlimit(p
, which
, limp
)
register struct rlimit
*alimp
;
if (which
>= RLIM_NLIMITS
)
alimp
= &p
->p_rlimit
[which
];
if (limp
->rlim_cur
> alimp
->rlim_max
||
limp
->rlim_max
> alimp
->rlim_max
)
if (error
= suser(p
->p_ucred
, &p
->p_acflag
))
if (limp
->rlim_cur
> limp
->rlim_max
)
limp
->rlim_cur
= limp
->rlim_max
;
if (p
->p_limit
->p_refcnt
> 1 &&
(p
->p_limit
->p_lflags
& PL_SHAREMOD
) == 0) {
p
->p_limit
= limcopy(p
->p_limit
);
alimp
= &p
->p_rlimit
[which
];
if (limp
->rlim_cur
> maxdmap
)
limp
->rlim_cur
= maxdmap
;
if (limp
->rlim_max
> maxdmap
)
limp
->rlim_max
= maxdmap
;
if (limp
->rlim_cur
> maxdmap
)
limp
->rlim_cur
= maxdmap
;
if (limp
->rlim_max
> maxdmap
)
limp
->rlim_max
= maxdmap
;
* Stack is allocated to the max at exec time with only
* "rlim_cur" bytes accessible. If stack limit is going
* up make more accessible, if going down make inaccessible.
if (limp
->rlim_cur
!= alimp
->rlim_cur
) {
if (limp
->rlim_cur
> alimp
->rlim_cur
) {
size
= limp
->rlim_cur
- alimp
->rlim_cur
;
addr
= USRSTACK
- limp
->rlim_cur
;
size
= alimp
->rlim_cur
- limp
->rlim_cur
;
addr
= USRSTACK
- alimp
->rlim_cur
;
(void) vm_map_protect(&p
->p_vmspace
->vm_map
,
addr
, addr
+size
, prot
, FALSE
);
if (limp
->rlim_cur
> maxfiles
)
limp
->rlim_cur
= maxfiles
;
if (limp
->rlim_max
> maxfiles
)
limp
->rlim_max
= maxfiles
;
if (limp
->rlim_cur
> maxproc
)
limp
->rlim_cur
= maxproc
;
if (limp
->rlim_max
> maxproc
)
limp
->rlim_max
= maxproc
;
struct __getrlimit_args
{
getrlimit(p
, uap
, retval
)
register struct __getrlimit_args
*uap
;
if (uap
->which
>= RLIM_NLIMITS
)
return (copyout((caddr_t
)&p
->p_rlimit
[uap
->which
], (caddr_t
)uap
->rlp
,
sizeof (struct rlimit
)));
* Transform the running time and tick information in proc p into user,
* system, and interrupt time usage.
register struct timeval
*up
;
register struct timeval
*sp
;
register struct timeval
*ip
;
register u_quad_t u
, st
, ut
, it
, tot
;
register u_long sec
, usec
;
up
->tv_sec
= up
->tv_usec
= 0;
sp
->tv_sec
= sp
->tv_usec
= 0;
ip
->tv_sec
= ip
->tv_usec
= 0;
usec
= p
->p_rtime
.tv_usec
;
* Adjust for the current time slice. This is actually fairly
* important since the error here is on the order of a time
* quantum, which is much greater than the sampling error.
sec
+= tv
.tv_sec
- runtime
.tv_sec
;
usec
+= tv
.tv_usec
- runtime
.tv_usec
;
u
= sec
* 1000000 + usec
;
sp
->tv_sec
= st
/ 1000000;
sp
->tv_usec
= st
% 1000000;
up
->tv_sec
= ut
/ 1000000;
up
->tv_usec
= ut
% 1000000;
ip
->tv_sec
= it
/ 1000000;
ip
->tv_usec
= it
% 1000000;
getrusage(p
, uap
, retval
)
register struct getrusage_args
*uap
;
register struct rusage
*rup
;
calcru(p
, &rup
->ru_utime
, &rup
->ru_stime
, NULL
);
rup
= &p
->p_stats
->p_cru
;
return (copyout((caddr_t
)rup
, (caddr_t
)uap
->rusage
,
sizeof (struct rusage
)));
register struct rusage
*ru
, *ru2
;
timevaladd(&ru
->ru_utime
, &ru2
->ru_utime
);
timevaladd(&ru
->ru_stime
, &ru2
->ru_stime
);
if (ru
->ru_maxrss
< ru2
->ru_maxrss
)
ru
->ru_maxrss
= ru2
->ru_maxrss
;
ip
= &ru
->ru_first
; ip2
= &ru2
->ru_first
;
for (i
= &ru
->ru_last
- &ru
->ru_first
; i
>= 0; i
--)
* Make a copy of the plimit structure.
* We share these structures copy-on-write after fork,
* and copy when a limit is changed.
register struct plimit
*copy
;
MALLOC(copy
, struct plimit
*, sizeof(struct plimit
),
bcopy(lim
->pl_rlimit
, copy
->pl_rlimit
,
sizeof(struct rlimit
) * RLIM_NLIMITS
);