kern_resource.c (1542) | kern_resource.c (1549) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 39 */ 40 41#include <sys/param.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 39 */ 40 41#include <sys/param.h> |
42#include <sys/systm.h> |
|
42#include <sys/kernel.h> 43#include <sys/file.h> 44#include <sys/resourcevar.h> 45#include <sys/malloc.h> 46#include <sys/proc.h> 47 48#include <vm/vm.h> 49 50/* 51 * Resource controls and accounting. 52 */ 53 54struct getpriority_args { 55 int which; 56 int who; 57}; | 43#include <sys/kernel.h> 44#include <sys/file.h> 45#include <sys/resourcevar.h> 46#include <sys/malloc.h> 47#include <sys/proc.h> 48 49#include <vm/vm.h> 50 51/* 52 * Resource controls and accounting. 53 */ 54 55struct getpriority_args { 56 int which; 57 int who; 58}; |
59int |
|
58getpriority(curp, uap, retval) 59 struct proc *curp; 60 register struct getpriority_args *uap; 61 int *retval; 62{ 63 register struct proc *p; 64 register int low = PRIO_MAX + 1; 65 --- 43 unchanged lines hidden (view full) --- 109} 110 111struct setpriority_args { 112 int which; 113 int who; 114 int prio; 115}; 116/* ARGSUSED */ | 60getpriority(curp, uap, retval) 61 struct proc *curp; 62 register struct getpriority_args *uap; 63 int *retval; 64{ 65 register struct proc *p; 66 register int low = PRIO_MAX + 1; 67 --- 43 unchanged lines hidden (view full) --- 111} 112 113struct setpriority_args { 114 int which; 115 int who; 116 int prio; 117}; 118/* ARGSUSED */ |
119int |
|
117setpriority(curp, uap, retval) 118 struct proc *curp; 119 register struct setpriority_args *uap; 120 int *retval; 121{ 122 register struct proc *p; 123 int found = 0, error = 0; 124 --- 37 unchanged lines hidden (view full) --- 162 default: 163 return (EINVAL); 164 } 165 if (found == 0) 166 return (ESRCH); 167 return (error); 168} 169 | 120setpriority(curp, uap, retval) 121 struct proc *curp; 122 register struct setpriority_args *uap; 123 int *retval; 124{ 125 register struct proc *p; 126 int found = 0, error = 0; 127 --- 37 unchanged lines hidden (view full) --- 165 default: 166 return (EINVAL); 167 } 168 if (found == 0) 169 return (ESRCH); 170 return (error); 171} 172 |
173int |
|
170donice(curp, chgp, n) 171 register struct proc *curp, *chgp; 172 register int n; 173{ 174 register struct pcred *pcred = curp->p_cred; 175 176 if (pcred->pc_ucred->cr_uid && pcred->p_ruid && 177 pcred->pc_ucred->cr_uid != chgp->p_ucred->cr_uid && --- 11 unchanged lines hidden (view full) --- 189} 190 191#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 192struct setrlimit_args { 193 u_int which; 194 struct orlimit *lim; 195}; 196/* ARGSUSED */ | 174donice(curp, chgp, n) 175 register struct proc *curp, *chgp; 176 register int n; 177{ 178 register struct pcred *pcred = curp->p_cred; 179 180 if (pcred->pc_ucred->cr_uid && pcred->p_ruid && 181 pcred->pc_ucred->cr_uid != chgp->p_ucred->cr_uid && --- 11 unchanged lines hidden (view full) --- 193} 194 195#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 196struct setrlimit_args { 197 u_int which; 198 struct orlimit *lim; 199}; 200/* ARGSUSED */ |
201int |
|
197osetrlimit(p, uap, retval) 198 struct proc *p; 199 register struct setrlimit_args *uap; 200 int *retval; 201{ 202 struct orlimit olim; 203 struct rlimit lim; 204 int error; --- 6 unchanged lines hidden (view full) --- 211 return (dosetrlimit(p, uap->which, &lim)); 212} 213 214struct getrlimit_args { 215 u_int which; 216 struct orlimit *rlp; 217}; 218/* ARGSUSED */ | 202osetrlimit(p, uap, retval) 203 struct proc *p; 204 register struct setrlimit_args *uap; 205 int *retval; 206{ 207 struct orlimit olim; 208 struct rlimit lim; 209 int error; --- 6 unchanged lines hidden (view full) --- 216 return (dosetrlimit(p, uap->which, &lim)); 217} 218 219struct getrlimit_args { 220 u_int which; 221 struct orlimit *rlp; 222}; 223/* ARGSUSED */ |
224int |
|
219ogetrlimit(p, uap, retval) 220 struct proc *p; 221 register struct getrlimit_args *uap; 222 int *retval; 223{ 224 struct orlimit olim; 225 226 if (uap->which >= RLIM_NLIMITS) --- 8 unchanged lines hidden (view full) --- 235} 236#endif /* COMPAT_43 || COMPAT_SUNOS */ 237 238struct __setrlimit_args { 239 u_int which; 240 struct rlimit *lim; 241}; 242/* ARGSUSED */ | 225ogetrlimit(p, uap, retval) 226 struct proc *p; 227 register struct getrlimit_args *uap; 228 int *retval; 229{ 230 struct orlimit olim; 231 232 if (uap->which >= RLIM_NLIMITS) --- 8 unchanged lines hidden (view full) --- 241} 242#endif /* COMPAT_43 || COMPAT_SUNOS */ 243 244struct __setrlimit_args { 245 u_int which; 246 struct rlimit *lim; 247}; 248/* ARGSUSED */ |
249int |
|
243setrlimit(p, uap, retval) 244 struct proc *p; 245 register struct __setrlimit_args *uap; 246 int *retval; 247{ 248 struct rlimit alim; 249 int error; 250 251 if (error = 252 copyin((caddr_t)uap->lim, (caddr_t)&alim, sizeof (struct rlimit))) 253 return (error); 254 return (dosetrlimit(p, uap->which, &alim)); 255} 256 | 250setrlimit(p, uap, retval) 251 struct proc *p; 252 register struct __setrlimit_args *uap; 253 int *retval; 254{ 255 struct rlimit alim; 256 int error; 257 258 if (error = 259 copyin((caddr_t)uap->lim, (caddr_t)&alim, sizeof (struct rlimit))) 260 return (error); 261 return (dosetrlimit(p, uap->which, &alim)); 262} 263 |
264int |
|
257dosetrlimit(p, which, limp) 258 struct proc *p; 259 u_int which; 260 struct rlimit *limp; 261{ 262 register struct rlimit *alimp; | 265dosetrlimit(p, which, limp) 266 struct proc *p; 267 u_int which; 268 struct rlimit *limp; 269{ 270 register struct rlimit *alimp; |
263 extern unsigned maxdmap; | |
264 int error; 265 266 if (which >= RLIM_NLIMITS) 267 return (EINVAL); 268 alimp = &p->p_rlimit[which]; 269 if (limp->rlim_cur > alimp->rlim_max || 270 limp->rlim_max > alimp->rlim_max) 271 if (error = suser(p->p_ucred, &p->p_acflag)) --- 5 unchanged lines hidden (view full) --- 277 p->p_limit->p_refcnt--; 278 p->p_limit = limcopy(p->p_limit); 279 alimp = &p->p_rlimit[which]; 280 } 281 282 switch (which) { 283 284 case RLIMIT_DATA: | 271 int error; 272 273 if (which >= RLIM_NLIMITS) 274 return (EINVAL); 275 alimp = &p->p_rlimit[which]; 276 if (limp->rlim_cur > alimp->rlim_max || 277 limp->rlim_max > alimp->rlim_max) 278 if (error = suser(p->p_ucred, &p->p_acflag)) --- 5 unchanged lines hidden (view full) --- 284 p->p_limit->p_refcnt--; 285 p->p_limit = limcopy(p->p_limit); 286 alimp = &p->p_rlimit[which]; 287 } 288 289 switch (which) { 290 291 case RLIMIT_DATA: |
285 if (limp->rlim_cur > maxdmap) 286 limp->rlim_cur = maxdmap; 287 if (limp->rlim_max > maxdmap) 288 limp->rlim_max = maxdmap; | 292 if (limp->rlim_cur > MAXDSIZ) 293 limp->rlim_cur = MAXDSIZ; 294 if (limp->rlim_max > MAXDSIZ) 295 limp->rlim_max = MAXDSIZ; |
289 break; 290 291 case RLIMIT_STACK: | 296 break; 297 298 case RLIMIT_STACK: |
292 if (limp->rlim_cur > maxdmap) 293 limp->rlim_cur = maxdmap; 294 if (limp->rlim_max > maxdmap) 295 limp->rlim_max = maxdmap; | 299 if (limp->rlim_cur > MAXSSIZ) 300 limp->rlim_cur = MAXSSIZ; 301 if (limp->rlim_max > MAXSSIZ) 302 limp->rlim_max = MAXSSIZ; |
296 /* 297 * Stack is allocated to the max at exec time with only 298 * "rlim_cur" bytes accessible. If stack limit is going 299 * up make more accessible, if going down make inaccessible. 300 */ 301 if (limp->rlim_cur != alimp->rlim_cur) { 302 vm_offset_t addr; 303 vm_size_t size; --- 33 unchanged lines hidden (view full) --- 337 return (0); 338} 339 340struct __getrlimit_args { 341 u_int which; 342 struct rlimit *rlp; 343}; 344/* ARGSUSED */ | 303 /* 304 * Stack is allocated to the max at exec time with only 305 * "rlim_cur" bytes accessible. If stack limit is going 306 * up make more accessible, if going down make inaccessible. 307 */ 308 if (limp->rlim_cur != alimp->rlim_cur) { 309 vm_offset_t addr; 310 vm_size_t size; --- 33 unchanged lines hidden (view full) --- 344 return (0); 345} 346 347struct __getrlimit_args { 348 u_int which; 349 struct rlimit *rlp; 350}; 351/* ARGSUSED */ |
352int |
|
345getrlimit(p, uap, retval) 346 struct proc *p; 347 register struct __getrlimit_args *uap; 348 int *retval; 349{ 350 351 if (uap->which >= RLIM_NLIMITS) 352 return (EINVAL); 353 return (copyout((caddr_t)&p->p_rlimit[uap->which], (caddr_t)uap->rlp, 354 sizeof (struct rlimit))); 355} 356 357/* 358 * Transform the running time and tick information in proc p into user, 359 * system, and interrupt time usage. 360 */ | 353getrlimit(p, uap, retval) 354 struct proc *p; 355 register struct __getrlimit_args *uap; 356 int *retval; 357{ 358 359 if (uap->which >= RLIM_NLIMITS) 360 return (EINVAL); 361 return (copyout((caddr_t)&p->p_rlimit[uap->which], (caddr_t)uap->rlp, 362 sizeof (struct rlimit))); 363} 364 365/* 366 * Transform the running time and tick information in proc p into user, 367 * system, and interrupt time usage. 368 */ |
369void |
|
361calcru(p, up, sp, ip) 362 register struct proc *p; 363 register struct timeval *up; 364 register struct timeval *sp; 365 register struct timeval *ip; 366{ 367 register u_quad_t u, st, ut, it, tot; 368 register u_long sec, usec; --- 41 unchanged lines hidden (view full) --- 410 } 411} 412 413struct getrusage_args { 414 int who; 415 struct rusage *rusage; 416}; 417/* ARGSUSED */ | 370calcru(p, up, sp, ip) 371 register struct proc *p; 372 register struct timeval *up; 373 register struct timeval *sp; 374 register struct timeval *ip; 375{ 376 register u_quad_t u, st, ut, it, tot; 377 register u_long sec, usec; --- 41 unchanged lines hidden (view full) --- 419 } 420} 421 422struct getrusage_args { 423 int who; 424 struct rusage *rusage; 425}; 426/* ARGSUSED */ |
427int |
|
418getrusage(p, uap, retval) 419 register struct proc *p; 420 register struct getrusage_args *uap; 421 int *retval; 422{ 423 register struct rusage *rup; 424 425 switch (uap->who) { --- 9 unchanged lines hidden (view full) --- 435 436 default: 437 return (EINVAL); 438 } 439 return (copyout((caddr_t)rup, (caddr_t)uap->rusage, 440 sizeof (struct rusage))); 441} 442 | 428getrusage(p, uap, retval) 429 register struct proc *p; 430 register struct getrusage_args *uap; 431 int *retval; 432{ 433 register struct rusage *rup; 434 435 switch (uap->who) { --- 9 unchanged lines hidden (view full) --- 445 446 default: 447 return (EINVAL); 448 } 449 return (copyout((caddr_t)rup, (caddr_t)uap->rusage, 450 sizeof (struct rusage))); 451} 452 |
453void |
|
443ruadd(ru, ru2) 444 register struct rusage *ru, *ru2; 445{ 446 register long *ip, *ip2; 447 register int i; 448 449 timevaladd(&ru->ru_utime, &ru2->ru_utime); 450 timevaladd(&ru->ru_stime, &ru2->ru_stime); --- 26 unchanged lines hidden --- | 454ruadd(ru, ru2) 455 register struct rusage *ru, *ru2; 456{ 457 register long *ip, *ip2; 458 register int i; 459 460 timevaladd(&ru->ru_utime, &ru2->ru_utime); 461 timevaladd(&ru->ru_stime, &ru2->ru_stime); --- 26 unchanged lines hidden --- |