FreeBSD kernel kern code
kern_resource.c File Reference
#include <sys/cdefs.h>
#include "opt_compat.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/file.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/refcount.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/time.h>
#include <sys/umtx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
Include dependency graph for kern_resource.c:

Go to the source code of this file.

Data Structures

struct  setpriority_args
 
struct  rtprio_thread_args
 
struct  rtprio_args
 
struct  __setrlimit_args
 
struct  __getrlimit_args
 
struct  getrusage_args
 

Macros

#define UIHASH(uid)   (&uihashtbl[(uid) & uihash])
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_PLIMIT,"plimit","plimit structures")
 
static MALLOC_DEFINE (M_UIDINFO,"uidinfo","uidinfo structures")
 
static LIST_HEAD (uihashhead, uidinfo)
 
int sys_getpriority (struct thread *td, struct getpriority_args *uap)
 
int sys_setpriority (struct thread *td, struct setpriority_args *uap)
 
static int donice (struct thread *td, struct proc *p, int n)
 
 SYSCTL_INT (_security_bsd, OID_AUTO, unprivileged_idprio, CTLFLAG_RW,&unprivileged_idprio, 0,"Allow non-root users to set an idle priority")
 
int sys_rtprio_thread (struct thread *td, struct rtprio_thread_args *uap)
 
int sys_rtprio (struct thread *td, struct rtprio_args *uap)
 
int rtp_to_pri (struct rtprio *rtp, struct thread *td)
 
void pri_to_rtp (struct thread *td, struct rtprio *rtp)
 
int sys_setrlimit (struct thread *td, struct __setrlimit_args *uap)
 
static void lim_cb (void *arg)
 
int kern_setrlimit (struct thread *td, u_int which, struct rlimit *limp)
 
int kern_proc_setrlimit (struct thread *td, struct proc *p, u_int which, struct rlimit *limp)
 
int sys_getrlimit (struct thread *td, struct __getrlimit_args *uap)
 
void calccru (struct proc *p, struct timeval *up, struct timeval *sp)
 
void calcru (struct proc *p, struct timeval *up, struct timeval *sp)
 
void rufetchtd (struct thread *td, struct rusage *ru)
 
static void calcru1 (struct proc *p, struct rusage_ext *ruxp, struct timeval *up, struct timeval *sp)
 
int sys_getrusage (struct thread *td, struct getrusage_args *uap)
 
int kern_getrusage (struct thread *td, int who, struct rusage *rup)
 
void rucollect (struct rusage *ru, struct rusage *ru2)
 
void ruadd (struct rusage *ru, struct rusage_ext *rux, struct rusage *ru2, struct rusage_ext *rux2)
 
static void ruxagg_locked (struct rusage_ext *rux, struct thread *td)
 
void ruxagg (struct proc *p, struct thread *td)
 
void rufetch (struct proc *p, struct rusage *ru)
 
void rufetchcalc (struct proc *p, struct rusage *ru, struct timeval *up, struct timeval *sp)
 
struct plimit * lim_alloc ()
 
struct plimit * lim_hold (struct plimit *limp)
 
void lim_fork (struct proc *p1, struct proc *p2)
 
void lim_free (struct plimit *limp)
 
void lim_copy (struct plimit *dst, struct plimit *src)
 
rlim_t lim_max (struct proc *p, int which)
 
rlim_t lim_cur (struct proc *p, int which)
 
void lim_rlimit (struct proc *p, int which, struct rlimit *rlp)
 
void uihashinit ()
 
static struct uidinfo * uilookup (uid_t uid)
 
struct uidinfo * uifind (uid_t uid)
 
void uihold (struct uidinfo *uip)
 
void uifree (struct uidinfo *uip)
 
void ui_racct_foreach (void(*callback)(struct racct *racct, void *arg2, void *arg3), void *arg2, void *arg3)
 
int chgproccnt (struct uidinfo *uip, int diff, rlim_t max)
 
int chgsbsize (struct uidinfo *uip, u_int *hiwat, u_int to, rlim_t max)
 
int chgptscnt (struct uidinfo *uip, int diff, rlim_t max)
 

Variables

static struct rwlock uihashtbl_lock
 
static int unprivileged_idprio
 

Macro Definition Documentation

#define UIHASH (   uid)    (&uihashtbl[(uid) & uihash])

Definition at line 72 of file kern_resource.c.

Referenced by uifind(), and uilookup().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void calccru ( struct proc *  p,
struct timeval *  up,
struct timeval *  sp 
)

Definition at line 809 of file kern_resource.c.

References calcru1().

Referenced by fill_kinfo_proc_only(), kern_getrusage(), and proc_to_reap().

Here is the call graph for this function:

Here is the caller graph for this function:

void calcru ( struct proc *  p,
struct timeval *  up,
struct timeval *  sp 
)

Definition at line 825 of file kern_resource.c.

References calcru1(), cpu_ticks, and ruxagg().

Referenced by fill_kinfo_proc_only(), kern_clock_gettime(), proc_to_reap(), and rufetchcalc().

Here is the call graph for this function:

Here is the caller graph for this function:

static void calcru1 ( struct proc *  p,
struct rusage_ext *  ruxp,
struct timeval *  up,
struct timeval *  sp 
)
static

Definition at line 884 of file kern_resource.c.

References cputick2usec(), and printf().

Referenced by calccru(), calcru(), and rufetchtd().

Here is the call graph for this function:

Here is the caller graph for this function:

int chgproccnt ( struct uidinfo *  uip,
int  diff,
rlim_t  max 
)

Definition at line 1357 of file kern_resource.c.

References printf().

Referenced by change_ruid(), fork1(), proc0_init(), and proc_reap().

Here is the call graph for this function:

Here is the caller graph for this function:

int chgptscnt ( struct uidinfo *  uip,
int  diff,
rlim_t  max 
)

Definition at line 1409 of file kern_resource.c.

References printf().

Referenced by pts_alloc(), pts_alloc_external(), and ptsdrv_free().

Here is the call graph for this function:

Here is the caller graph for this function:

int chgsbsize ( struct uidinfo *  uip,
u_int *  hiwat,
u_int  to,
rlim_t  max 
)

Definition at line 1381 of file kern_resource.c.

References printf().

Referenced by sbrelease_internal(), sbreserve_locked(), sodealloc(), uipc_rcvd(), and uipc_send().

Here is the call graph for this function:

Here is the caller graph for this function:

static int donice ( struct thread *  td,
struct proc *  p,
int  n 
)
static

Definition at line 260 of file kern_resource.c.

References p_cansched(), priv_check(), and sched_nice().

Referenced by sys_setpriority().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_getrusage ( struct thread *  td,
int  who,
struct rusage *  rup 
)

Definition at line 979 of file kern_resource.c.

References calccru(), rufetchcalc(), and rufetchtd().

Referenced by sys_getrusage().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_proc_setrlimit ( struct thread *  td,
struct proc *  p,
u_int  which,
struct rlimit *  limp 
)

Definition at line 659 of file kern_resource.c.

References hz, lim_alloc(), lim_cb(), lim_copy(), lim_free(), maxdsiz, maxfilesperproc, maxprocperuid, maxssiz, and priv_check().

Referenced by kern_setrlimit(), and sysctl_kern_proc_rlimit().

Here is the call graph for this function:

Here is the caller graph for this function:

int kern_setrlimit ( struct thread *  td,
u_int  which,
struct rlimit *  limp 
)

Definition at line 652 of file kern_resource.c.

References kern_proc_setrlimit().

Referenced by sys_setrlimit().

Here is the call graph for this function:

Here is the caller graph for this function:

struct plimit* lim_alloc ( )

Definition at line 1112 of file kern_resource.c.

References malloc().

Referenced by kern_proc_setrlimit(), proc0_init(), and sys_acct().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lim_cb ( void *  arg)
static

Definition at line 618 of file kern_resource.c.

References cpu_tickrate(), hz, kern_psignal(), killproc(), lim_rlimit(), and ruxagg().

Referenced by kern_proc_setrlimit(), and lim_fork().

Here is the call graph for this function:

Here is the caller graph for this function:

void lim_copy ( struct plimit *  dst,
struct plimit *  src 
)

Definition at line 1154 of file kern_resource.c.

Referenced by kern_proc_setrlimit().

Here is the caller graph for this function:

rlim_t lim_cur ( struct proc *  p,
int  which 
)

Definition at line 1180 of file kern_resource.c.

References lim_rlimit().

Referenced by coredump(), do_aout_hdr(), exec_aout_imgact(), fork1(), getmaxfd(), pts_alloc(), pts_alloc_external(), sbreserve_locked(), sys_getdtablesize(), and vn_rlimit_fsize().

Here is the call graph for this function:

Here is the caller graph for this function:

void lim_fork ( struct proc *  p1,
struct proc *  p2 
)

Definition at line 1131 of file kern_resource.c.

References hz, lim_cb(), and lim_hold().

Referenced by do_fork().

Here is the call graph for this function:

Here is the caller graph for this function:

void lim_free ( struct plimit *  limp)

Definition at line 1140 of file kern_resource.c.

References free().

Referenced by acct_disable(), acct_process(), exit1(), and kern_proc_setrlimit().

Here is the call graph for this function:

Here is the caller graph for this function:

struct plimit* lim_hold ( struct plimit *  limp)

Definition at line 1122 of file kern_resource.c.

Referenced by acct_process(), and lim_fork().

Here is the caller graph for this function:

rlim_t lim_max ( struct proc *  p,
int  which 
)

Definition at line 1167 of file kern_resource.c.

References lim_rlimit().

Referenced by copyout_map(), and kern_shmat().

Here is the call graph for this function:

Here is the caller graph for this function:

void lim_rlimit ( struct proc *  p,
int  which,
struct rlimit *  rlp 
)

Definition at line 1193 of file kern_resource.c.

Referenced by lim_cb(), lim_cur(), lim_max(), note_procstat_rlimit(), sys_getrlimit(), and sysctl_kern_proc_rlimit().

Here is the caller graph for this function:

static LIST_HEAD ( uihashhead  ,
uidinfo   
)
static

Definition at line 74 of file kern_resource.c.

static MALLOC_DEFINE ( M_PLIMIT  ,
"plimit"  ,
"plimit structures"   
)
static
static MALLOC_DEFINE ( M_UIDINFO  ,
"uidinfo"  ,
"uidinfo structures"   
)
static
void pri_to_rtp ( struct thread *  td,
struct rtprio *  rtp 
)

Definition at line 513 of file kern_resource.c.

Referenced by getscheduler(), ksched_getparam(), sys_rtprio(), and sys_rtprio_thread().

Here is the caller graph for this function:

int rtp_to_pri ( struct rtprio *  rtp,
struct thread *  td 
)

Definition at line 470 of file kern_resource.c.

References critical_enter(), critical_exit(), sched_class(), sched_prio(), sched_user_prio(), and umtx_pi_adjust().

Referenced by create_thread(), ksched_setscheduler(), poll_idle(), sys_rtprio(), and sys_rtprio_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

void ruadd ( struct rusage *  ru,
struct rusage_ext *  rux,
struct rusage *  ru2,
struct rusage_ext *  rux2 
)

Definition at line 1028 of file kern_resource.c.

References rucollect().

Referenced by exit1(), and proc_reap().

Here is the call graph for this function:

Here is the caller graph for this function:

void rucollect ( struct rusage *  ru,
struct rusage *  ru2 
)

Definition at line 1014 of file kern_resource.c.

Referenced by ruadd(), rufetch(), and thread_exit().

Here is the caller graph for this function:

void rufetch ( struct proc *  p,
struct rusage *  ru 
)

Definition at line 1076 of file kern_resource.c.

References rucollect(), and ruxagg().

Referenced by fill_kinfo_proc_only(), get_process_cputime(), proc0_post(), and rufetchcalc().

Here is the call graph for this function:

Here is the caller graph for this function:

void rufetchcalc ( struct proc *  p,
struct rusage *  ru,
struct timeval *  up,
struct timeval *  sp 
)

Definition at line 1097 of file kern_resource.c.

References calcru(), and rufetch().

Referenced by acct_process(), kern_getrusage(), and tty_info().

Here is the call graph for this function:

Here is the caller graph for this function:

void rufetchtd ( struct thread *  td,
struct rusage *  ru 
)

Definition at line 857 of file kern_resource.c.

References calcru1(), cpu_ticks, and ruxagg().

Referenced by fill_kinfo_thread(), and kern_getrusage().

Here is the call graph for this function:

Here is the caller graph for this function:

void ruxagg ( struct proc *  p,
struct thread *  td 
)

Definition at line 1058 of file kern_resource.c.

References ruxagg_locked().

Referenced by calcru(), lim_cb(), rufetch(), rufetchtd(), and thread_exit().

Here is the call graph for this function:

Here is the caller graph for this function:

static void ruxagg_locked ( struct rusage_ext *  rux,
struct thread *  td 
)
static

Definition at line 1046 of file kern_resource.c.

Referenced by ruxagg().

Here is the caller graph for this function:

int sys_getpriority ( struct thread *  td,
struct getpriority_args *  uap 
)

Definition at line 93 of file kern_resource.c.

References allproc_lock, p_cansee(), pfind(), pgfind(), and proctree_lock.

Here is the call graph for this function:

int sys_getrlimit ( struct thread *  td,
struct __getrlimit_args uap 
)

Definition at line 786 of file kern_resource.c.

References lim_rlimit().

Here is the call graph for this function:

int sys_getrusage ( struct thread *  td,
struct getrusage_args uap 
)

Definition at line 965 of file kern_resource.c.

References kern_getrusage().

Here is the call graph for this function:

int sys_rtprio ( struct thread *  td,
struct rtprio_args uap 
)

Definition at line 374 of file kern_resource.c.

References p_cansched(), p_cansee(), pfind(), pri_to_rtp(), priv_check(), rtp_to_pri(), and unprivileged_idprio.

Here is the call graph for this function:

int sys_rtprio_thread ( struct thread *  td,
struct rtprio_thread_args uap 
)
int sys_setpriority ( struct thread *  td,
struct setpriority_args uap 
)

Definition at line 178 of file kern_resource.c.

References allproc_lock, donice(), p_cansee(), pfind(), pgfind(), setpriority_args::prio, proctree_lock, setpriority_args::which, and setpriority_args::who.

Here is the call graph for this function:

int sys_setrlimit ( struct thread *  td,
struct __setrlimit_args uap 
)

Definition at line 604 of file kern_resource.c.

References kern_setrlimit().

Here is the call graph for this function:

SYSCTL_INT ( _security_bsd  ,
OID_AUTO  ,
unprivileged_idprio  ,
CTLFLAG_RW  ,
unprivileged_idprio,
,
"Allow non-root users to set an idle priority  
)
void ui_racct_foreach ( void(*)(struct racct *racct, void *arg2, void *arg3)  callback,
void *  arg2,
void *  arg3 
)

Definition at line 1337 of file kern_resource.c.

References callback, and uihashtbl_lock.

struct uidinfo* uifind ( uid_t  uid)

Definition at line 1238 of file kern_resource.c.

References free(), malloc(), mtx_init(), racct_create(), racct_destroy(), UIHASH, uihashtbl_lock, uihold(), and uilookup().

Referenced by do_execve(), proc0_init(), sys_seteuid(), sys_setresuid(), sys_setreuid(), and sys_setuid().

Here is the call graph for this function:

Here is the caller graph for this function:

void uifree ( struct uidinfo *  uip)

Definition at line 1300 of file kern_resource.c.

References free(), mtx_destroy(), printf(), racct_destroy(), and uihashtbl_lock.

Referenced by change_euid(), change_ruid(), crfree(), do_execve(), sys_seteuid(), sys_setresuid(), sys_setreuid(), and sys_setuid().

Here is the call graph for this function:

Here is the caller graph for this function:

void uihashinit ( )

Definition at line 1205 of file kern_resource.c.

References hashinit(), maxproc, and uihashtbl_lock.

Referenced by procinit().

Here is the call graph for this function:

Here is the caller graph for this function:

void uihold ( struct uidinfo *  uip)

Definition at line 1277 of file kern_resource.c.

Referenced by change_euid(), change_ruid(), crcopy(), and uifind().

Here is the caller graph for this function:

static struct uidinfo* uilookup ( uid_t  uid)
static

Definition at line 1217 of file kern_resource.c.

References UIHASH, and uihashtbl_lock.

Referenced by uifind().

Here is the caller graph for this function:

Variable Documentation

struct rwlock uihashtbl_lock
static

Definition at line 73 of file kern_resource.c.

Referenced by ui_racct_foreach(), uifind(), uifree(), uihashinit(), and uilookup().

int unprivileged_idprio
static

Definition at line 277 of file kern_resource.c.

Referenced by sys_rtprio(), and sys_rtprio_thread().