131921Sbrian/* $NetBSD: resourcevar.h,v 1.52 2011/05/14 17:57:05 rmind Exp $ */ 231921Sbrian 331921Sbrian/* 431921Sbrian * Copyright (c) 1991, 1993 531921Sbrian * The Regents of the University of California. All rights reserved. 631921Sbrian * 731921Sbrian * Redistribution and use in source and binary forms, with or without 831921Sbrian * modification, are permitted provided that the following conditions 931921Sbrian * are met: 1031921Sbrian * 1. Redistributions of source code must retain the above copyright 1131921Sbrian * notice, this list of conditions and the following disclaimer. 1231921Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1331921Sbrian * notice, this list of conditions and the following disclaimer in the 1431921Sbrian * documentation and/or other materials provided with the distribution. 1531921Sbrian * 3. Neither the name of the University nor the names of its contributors 1631921Sbrian * may be used to endorse or promote products derived from this software 1731921Sbrian * without specific prior written permission. 1831921Sbrian * 1931921Sbrian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2031921Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2131921Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2231921Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2331921Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2431921Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2531921Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2636285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2731272Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2831272Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2936285Sbrian * SUCH DAMAGE. 3031272Sbrian * 3131272Sbrian * @(#)resourcevar.h 8.4 (Berkeley) 1/9/95 3236285Sbrian */ 3336285Sbrian 3431272Sbrian#ifndef _SYS_RESOURCEVAR_H_ 3531272Sbrian#define _SYS_RESOURCEVAR_H_ 3631343Sbrian 3731272Sbrian#if !defined(_KERNEL) && !defined(_KMEMUSER) 3831272Sbrian#error "not supposed to be exposed to userland" 3936285Sbrian#endif 4036285Sbrian 4131272Sbrian#include <sys/mutex.h> 4231272Sbrian 4331272Sbrian/* 4431272Sbrian * Kernel per-process accounting / statistics 4531272Sbrian */ 4631272Sbrianstruct pstats { 4731272Sbrian#define pstat_startzero p_ru 4831272Sbrian struct rusage p_ru; /* stats for this proc */ 4931272Sbrian struct rusage p_cru; /* sum of stats for reaped children */ 5031272Sbrian#define pstat_endzero pstat_startcopy 5136285Sbrian 5236285Sbrian#define pstat_startcopy p_timer 5336285Sbrian struct itimerspec p_timer[3]; /* virtual-time timers */ 5436285Sbrian 5531272Sbrian struct uprof { /* profile arguments */ 5631272Sbrian char * pr_base; /* buffer base */ 5731272Sbrian size_t pr_size; /* buffer size */ 5831272Sbrian u_long pr_off; /* pc offset */ 5936285Sbrian u_int pr_scale; /* pc scaling */ 6031272Sbrian u_long pr_addr; /* temp storage for addr until AST */ 6131272Sbrian u_long pr_ticks; /* temp storage for ticks until AST */ 6231272Sbrian } p_prof; 6331418Sbrian#define pstat_endcopy p_start 6436285Sbrian struct timeval p_start; /* starting time */ 6531272Sbrian}; 6631272Sbrian 6736285Sbrian#ifdef _KERNEL 6836285Sbrian 6936285Sbrian/* 7036285Sbrian * Process resource limits. Since this structure is moderately large, 7136285Sbrian * but changes infrequently, it is shared copy-on-write after forks. 7236285Sbrian * 7336285Sbrian * When a separate copy is created, then 'pl_writeable' is set to true, 7436285Sbrian * and 'pl_sv_limit' is pointed to the old proc_t::p_limit structure. 7531272Sbrian */ 7636285Sbrianstruct plimit { 7736285Sbrian struct rlimit pl_rlimit[RLIM_NLIMITS]; 7831272Sbrian char * pl_corename; 7931272Sbrian size_t pl_cnlen; 8031272Sbrian u_int pl_refcnt; 8131272Sbrian bool pl_writeable; 8231272Sbrian kmutex_t pl_lock; 8331272Sbrian struct plimit * pl_sv_limit; 8431272Sbrian}; 8531272Sbrian 8631272Sbrian/* add user profiling from AST XXXSMP */ 8731418Sbrian#define ADDUPROF(l) \ 8831272Sbrian do { \ 8936285Sbrian struct proc *_p = (l)->l_proc; \ 9031272Sbrian addupc_task((l), \ 9131272Sbrian _p->p_stats->p_prof.pr_addr, \ 9236285Sbrian _p->p_stats->p_prof.pr_ticks); \ 9331272Sbrian _p->p_stats->p_prof.pr_ticks = 0; \ 9431272Sbrian } while (/* CONSTCOND */ 0) 9531272Sbrian 9636285Sbrianextern char defcorename[]; 9736285Sbrian 9831272Sbrianextern int security_setidcore_dump; 9931272Sbrianextern char security_setidcore_path[]; 10036285Sbrianextern uid_t security_setidcore_owner; 10131272Sbrianextern gid_t security_setidcore_group; 10231272Sbrianextern mode_t security_setidcore_mode; 10331272Sbrian 10431272Sbrianvoid addupc_intr(struct lwp *, u_long); 10531272Sbrianvoid addupc_task(struct lwp *, u_long, u_int); 10631343Sbrianvoid calcru(struct proc *, struct timeval *, struct timeval *, 10731272Sbrian struct timeval *, struct timeval *); 10831343Sbrian 10931272Sbrianstruct plimit *lim_copy(struct plimit *); 11031272Sbrianvoid lim_addref(struct plimit *); 11136285Sbrianvoid lim_privatise(struct proc *); 11231272Sbrianvoid lim_setcorename(struct proc *, char *, size_t); 11331272Sbrianvoid lim_free(struct plimit *); 11431272Sbrian 11531272Sbrianvoid resource_init(void); 11631272Sbrianvoid ruadd(struct rusage *, struct rusage *); 11731272Sbrianvoid rulwps(proc_t *, struct rusage *); 11831272Sbrianstruct pstats *pstatscopy(struct pstats *); 11931272Sbrianvoid pstatsfree(struct pstats *); 12031272Sbrianextern rlim_t maxdmap; 12136285Sbrianextern rlim_t maxsmap; 12231272Sbrian 12331272Sbrian#endif 12431272Sbrian 12536285Sbrian#endif /* !_SYS_RESOURCEVAR_H_ */ 12631272Sbrian