Deleted Added
full compact
kern_resource.c (80116) kern_resource.c (82749)
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.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
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.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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 * $FreeBSD: head/sys/kern/kern_resource.c 80116 2001-07-22 00:21:19Z assar $
39 * $FreeBSD: head/sys/kern/kern_resource.c 82749 2001-09-01 19:04:37Z dillon $
40 */
41
42#include "opt_compat.h"
43#include "opt_rlimit.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 27 unchanged lines hidden (view full) ---

75 */
76
77#ifndef _SYS_SYSPROTO_H_
78struct getpriority_args {
79 int which;
80 int who;
81};
82#endif
40 */
41
42#include "opt_compat.h"
43#include "opt_rlimit.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 27 unchanged lines hidden (view full) ---

75 */
76
77#ifndef _SYS_SYSPROTO_H_
78struct getpriority_args {
79 int which;
80 int who;
81};
82#endif
83/*
84 * MPSAFE
85 */
83int
84getpriority(curp, uap)
85 struct proc *curp;
86 register struct getpriority_args *uap;
87{
88 register struct proc *p;
89 register int low = PRIO_MAX + 1;
86int
87getpriority(curp, uap)
88 struct proc *curp;
89 register struct getpriority_args *uap;
90{
91 register struct proc *p;
92 register int low = PRIO_MAX + 1;
93 int error = 0;
90
94
91 switch (uap->which) {
95 mtx_lock(&Giant);
92
96
97 switch (uap->which) {
93 case PRIO_PROCESS:
94 if (uap->who == 0)
95 low = curp->p_nice;
96 else {
97 p = pfind(uap->who);
98 if (p == NULL)
99 break;
100 if (p_cansee(curp, p) == 0)

--- 24 unchanged lines hidden (view full) ---

125 if (!p_cansee(curp, p) &&
126 p->p_ucred->cr_uid == uap->who &&
127 p->p_nice < low)
128 low = p->p_nice;
129 sx_sunlock(&allproc_lock);
130 break;
131
132 default:
98 case PRIO_PROCESS:
99 if (uap->who == 0)
100 low = curp->p_nice;
101 else {
102 p = pfind(uap->who);
103 if (p == NULL)
104 break;
105 if (p_cansee(curp, p) == 0)

--- 24 unchanged lines hidden (view full) ---

130 if (!p_cansee(curp, p) &&
131 p->p_ucred->cr_uid == uap->who &&
132 p->p_nice < low)
133 low = p->p_nice;
134 sx_sunlock(&allproc_lock);
135 break;
136
137 default:
133 return (EINVAL);
138 error = EINVAL;
139 break;
134 }
140 }
135 if (low == PRIO_MAX + 1)
136 return (ESRCH);
141 if (low == PRIO_MAX + 1 && error == 0)
142 error = ESRCH;
137 curp->p_retval[0] = low;
143 curp->p_retval[0] = low;
138 return (0);
144 mtx_unlock(&Giant);
145 return (error);
139}
140
141#ifndef _SYS_SYSPROTO_H_
142struct setpriority_args {
143 int which;
144 int who;
145 int prio;
146};
147#endif
146}
147
148#ifndef _SYS_SYSPROTO_H_
149struct setpriority_args {
150 int which;
151 int who;
152 int prio;
153};
154#endif
155/*
156 * MPSAFE
157 */
148/* ARGSUSED */
149int
150setpriority(curp, uap)
151 struct proc *curp;
152 register struct setpriority_args *uap;
153{
154 register struct proc *p;
155 int found = 0, error = 0;
156
158/* ARGSUSED */
159int
160setpriority(curp, uap)
161 struct proc *curp;
162 register struct setpriority_args *uap;
163{
164 register struct proc *p;
165 int found = 0, error = 0;
166
157 switch (uap->which) {
167 mtx_lock(&Giant);
158
168
169 switch (uap->which) {
159 case PRIO_PROCESS:
160 if (uap->who == 0)
161 error = donice(curp, curp, uap->prio);
162 else {
163 p = pfind(uap->who);
164 if (p == 0)
165 break;
166 if (p_cansee(curp, p) == 0)

--- 28 unchanged lines hidden (view full) ---

195 !p_cansee(curp, p)) {
196 error = donice(curp, p, uap->prio);
197 found++;
198 }
199 sx_sunlock(&allproc_lock);
200 break;
201
202 default:
170 case PRIO_PROCESS:
171 if (uap->who == 0)
172 error = donice(curp, curp, uap->prio);
173 else {
174 p = pfind(uap->who);
175 if (p == 0)
176 break;
177 if (p_cansee(curp, p) == 0)

--- 28 unchanged lines hidden (view full) ---

206 !p_cansee(curp, p)) {
207 error = donice(curp, p, uap->prio);
208 found++;
209 }
210 sx_sunlock(&allproc_lock);
211 break;
212
213 default:
203 return (EINVAL);
214 error = EINVAL;
215 break;
204 }
216 }
205 if (found == 0)
206 return (ESRCH);
217 if (found == 0 && error == 0)
218 error = ESRCH;
219 mtx_unlock(&Giant);
207 return (error);
208}
209
210static int
211donice(curp, chgp, n)
212 register struct proc *curp, *chgp;
213 register int n;
214{

--- 20 unchanged lines hidden (view full) ---

235 struct rtprio *rtp;
236};
237#endif
238
239/*
240 * Set realtime priority
241 */
242
220 return (error);
221}
222
223static int
224donice(curp, chgp, n)
225 register struct proc *curp, *chgp;
226 register int n;
227{

--- 20 unchanged lines hidden (view full) ---

248 struct rtprio *rtp;
249};
250#endif
251
252/*
253 * Set realtime priority
254 */
255
256/*
257 * MPSAFE
258 */
243/* ARGSUSED */
244int
245rtprio(curp, uap)
246 struct proc *curp;
247 register struct rtprio_args *uap;
248{
249 register struct proc *p;
250 struct rtprio rtp;
251 int error;
252
259/* ARGSUSED */
260int
261rtprio(curp, uap)
262 struct proc *curp;
263 register struct rtprio_args *uap;
264{
265 register struct proc *p;
266 struct rtprio rtp;
267 int error;
268
269 mtx_lock(&Giant);
270
253 if (uap->pid == 0) {
254 p = curp;
255 PROC_LOCK(p);
271 if (uap->pid == 0) {
272 p = curp;
273 PROC_LOCK(p);
256 } else
274 } else {
257 p = pfind(uap->pid);
275 p = pfind(uap->pid);
276 }
258
277
259 if (p == NULL)
260 return (ESRCH);
278 if (p == NULL) {
279 error = ESRCH;
280 goto done2;
281 }
261
262 switch (uap->function) {
263 case RTP_LOOKUP:
264 if ((error = p_cansee(curp, p)))
265 break;
266 pri_to_rtp(&p->p_pri, &rtp);
267 error = copyout(&rtp, uap->rtp, sizeof(struct rtprio));
268 break;

--- 26 unchanged lines hidden (view full) ---

295 }
296 error = rtp_to_pri(&rtp, &p->p_pri);
297 break;
298 default:
299 error = EINVAL;
300 break;
301 }
302 PROC_UNLOCK(p);
282
283 switch (uap->function) {
284 case RTP_LOOKUP:
285 if ((error = p_cansee(curp, p)))
286 break;
287 pri_to_rtp(&p->p_pri, &rtp);
288 error = copyout(&rtp, uap->rtp, sizeof(struct rtprio));
289 break;

--- 26 unchanged lines hidden (view full) ---

316 }
317 error = rtp_to_pri(&rtp, &p->p_pri);
318 break;
319 default:
320 error = EINVAL;
321 break;
322 }
323 PROC_UNLOCK(p);
324done2:
325 mtx_unlock(&Giant);
303 return (error);
304}
305
306int
307rtp_to_pri(struct rtprio *rtp, struct priority *pri)
308{
309
310 if (rtp->prio > RTP_PRIO_MAX)

--- 39 unchanged lines hidden (view full) ---

350
351#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
352#ifndef _SYS_SYSPROTO_H_
353struct osetrlimit_args {
354 u_int which;
355 struct orlimit *rlp;
356};
357#endif
326 return (error);
327}
328
329int
330rtp_to_pri(struct rtprio *rtp, struct priority *pri)
331{
332
333 if (rtp->prio > RTP_PRIO_MAX)

--- 39 unchanged lines hidden (view full) ---

373
374#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
375#ifndef _SYS_SYSPROTO_H_
376struct osetrlimit_args {
377 u_int which;
378 struct orlimit *rlp;
379};
380#endif
381/*
382 * MPSAFE
383 */
358/* ARGSUSED */
359int
360osetrlimit(p, uap)
361 struct proc *p;
362 register struct osetrlimit_args *uap;
363{
364 struct orlimit olim;
365 struct rlimit lim;
366 int error;
367
368 if ((error =
369 copyin((caddr_t)uap->rlp, (caddr_t)&olim, sizeof(struct orlimit))))
370 return (error);
371 lim.rlim_cur = olim.rlim_cur;
372 lim.rlim_max = olim.rlim_max;
384/* ARGSUSED */
385int
386osetrlimit(p, uap)
387 struct proc *p;
388 register struct osetrlimit_args *uap;
389{
390 struct orlimit olim;
391 struct rlimit lim;
392 int error;
393
394 if ((error =
395 copyin((caddr_t)uap->rlp, (caddr_t)&olim, sizeof(struct orlimit))))
396 return (error);
397 lim.rlim_cur = olim.rlim_cur;
398 lim.rlim_max = olim.rlim_max;
373 return (dosetrlimit(p, uap->which, &lim));
399 mtx_lock(&Giant);
400 error = dosetrlimit(p, uap->which, &lim);
401 mtx_unlock(&Giant);
402 return (error);
374}
375
376#ifndef _SYS_SYSPROTO_H_
377struct ogetrlimit_args {
378 u_int which;
379 struct orlimit *rlp;
380};
381#endif
403}
404
405#ifndef _SYS_SYSPROTO_H_
406struct ogetrlimit_args {
407 u_int which;
408 struct orlimit *rlp;
409};
410#endif
411/*
412 * MPSAFE
413 */
382/* ARGSUSED */
383int
384ogetrlimit(p, uap)
385 struct proc *p;
386 register struct ogetrlimit_args *uap;
387{
388 struct orlimit olim;
414/* ARGSUSED */
415int
416ogetrlimit(p, uap)
417 struct proc *p;
418 register struct ogetrlimit_args *uap;
419{
420 struct orlimit olim;
421 int error;
389
390 if (uap->which >= RLIM_NLIMITS)
391 return (EINVAL);
422
423 if (uap->which >= RLIM_NLIMITS)
424 return (EINVAL);
425 mtx_lock(&Giant);
392 olim.rlim_cur = p->p_rlimit[uap->which].rlim_cur;
393 if (olim.rlim_cur == -1)
394 olim.rlim_cur = 0x7fffffff;
395 olim.rlim_max = p->p_rlimit[uap->which].rlim_max;
396 if (olim.rlim_max == -1)
397 olim.rlim_max = 0x7fffffff;
426 olim.rlim_cur = p->p_rlimit[uap->which].rlim_cur;
427 if (olim.rlim_cur == -1)
428 olim.rlim_cur = 0x7fffffff;
429 olim.rlim_max = p->p_rlimit[uap->which].rlim_max;
430 if (olim.rlim_max == -1)
431 olim.rlim_max = 0x7fffffff;
398 return (copyout((caddr_t)&olim, (caddr_t)uap->rlp, sizeof(olim)));
432 error = copyout((caddr_t)&olim, (caddr_t)uap->rlp, sizeof(olim));
433 mtx_unlock(&Giant);
434 return (error);
399}
400#endif /* COMPAT_43 || COMPAT_SUNOS */
401
402#ifndef _SYS_SYSPROTO_H_
403struct __setrlimit_args {
404 u_int which;
405 struct rlimit *rlp;
406};
407#endif
435}
436#endif /* COMPAT_43 || COMPAT_SUNOS */
437
438#ifndef _SYS_SYSPROTO_H_
439struct __setrlimit_args {
440 u_int which;
441 struct rlimit *rlp;
442};
443#endif
444/*
445 * MPSAFE
446 */
408/* ARGSUSED */
409int
410setrlimit(p, uap)
411 struct proc *p;
412 register struct __setrlimit_args *uap;
413{
414 struct rlimit alim;
415 int error;
416
417 if ((error =
418 copyin((caddr_t)uap->rlp, (caddr_t)&alim, sizeof (struct rlimit))))
419 return (error);
447/* ARGSUSED */
448int
449setrlimit(p, uap)
450 struct proc *p;
451 register struct __setrlimit_args *uap;
452{
453 struct rlimit alim;
454 int error;
455
456 if ((error =
457 copyin((caddr_t)uap->rlp, (caddr_t)&alim, sizeof (struct rlimit))))
458 return (error);
420 return (dosetrlimit(p, uap->which, &alim));
459 mtx_lock(&Giant);
460 error = dosetrlimit(p, uap->which, &alim);
461 mtx_unlock(&Giant);
462 return (error);
421}
422
423int
424dosetrlimit(p, which, limp)
425 struct proc *p;
426 u_int which;
427 struct rlimit *limp;
428{

--- 97 unchanged lines hidden (view full) ---

526}
527
528#ifndef _SYS_SYSPROTO_H_
529struct __getrlimit_args {
530 u_int which;
531 struct rlimit *rlp;
532};
533#endif
463}
464
465int
466dosetrlimit(p, which, limp)
467 struct proc *p;
468 u_int which;
469 struct rlimit *limp;
470{

--- 97 unchanged lines hidden (view full) ---

568}
569
570#ifndef _SYS_SYSPROTO_H_
571struct __getrlimit_args {
572 u_int which;
573 struct rlimit *rlp;
574};
575#endif
576/*
577 * MPSAFE
578 */
534/* ARGSUSED */
535int
536getrlimit(p, uap)
537 struct proc *p;
538 register struct __getrlimit_args *uap;
539{
579/* ARGSUSED */
580int
581getrlimit(p, uap)
582 struct proc *p;
583 register struct __getrlimit_args *uap;
584{
585 int error;
540
541 if (uap->which >= RLIM_NLIMITS)
542 return (EINVAL);
586
587 if (uap->which >= RLIM_NLIMITS)
588 return (EINVAL);
543 return (copyout((caddr_t)&p->p_rlimit[uap->which], (caddr_t)uap->rlp,
544 sizeof (struct rlimit)));
589 mtx_lock(&Giant);
590 error = copyout((caddr_t)&p->p_rlimit[uap->which], (caddr_t)uap->rlp,
591 sizeof (struct rlimit));
592 mtx_unlock(&Giant);
593 return(error);
545}
546
547/*
548 * Transform the running time and tick information in proc p into user,
549 * system, and interrupt time usage.
550 */
551void
552calcru(p, up, sp, ip)

--- 87 unchanged lines hidden (view full) ---

640}
641
642#ifndef _SYS_SYSPROTO_H_
643struct getrusage_args {
644 int who;
645 struct rusage *rusage;
646};
647#endif
594}
595
596/*
597 * Transform the running time and tick information in proc p into user,
598 * system, and interrupt time usage.
599 */
600void
601calcru(p, up, sp, ip)

--- 87 unchanged lines hidden (view full) ---

689}
690
691#ifndef _SYS_SYSPROTO_H_
692struct getrusage_args {
693 int who;
694 struct rusage *rusage;
695};
696#endif
697/*
698 * MPSAFE
699 */
648/* ARGSUSED */
649int
650getrusage(p, uap)
651 register struct proc *p;
652 register struct getrusage_args *uap;
653{
654 register struct rusage *rup;
700/* ARGSUSED */
701int
702getrusage(p, uap)
703 register struct proc *p;
704 register struct getrusage_args *uap;
705{
706 register struct rusage *rup;
707 int error = 0;
655
708
656 switch (uap->who) {
709 mtx_lock(&Giant);
657
710
711 switch (uap->who) {
658 case RUSAGE_SELF:
659 rup = &p->p_stats->p_ru;
660 mtx_lock_spin(&sched_lock);
661 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
662 mtx_unlock_spin(&sched_lock);
663 break;
664
665 case RUSAGE_CHILDREN:
666 rup = &p->p_stats->p_cru;
667 break;
668
669 default:
712 case RUSAGE_SELF:
713 rup = &p->p_stats->p_ru;
714 mtx_lock_spin(&sched_lock);
715 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
716 mtx_unlock_spin(&sched_lock);
717 break;
718
719 case RUSAGE_CHILDREN:
720 rup = &p->p_stats->p_cru;
721 break;
722
723 default:
670 return (EINVAL);
724 rup = NULL;
725 error = EINVAL;
726 break;
671 }
727 }
672 return (copyout((caddr_t)rup, (caddr_t)uap->rusage,
673 sizeof (struct rusage)));
728 mtx_unlock(&Giant);
729 if (error == 0) {
730 error = copyout((caddr_t)rup, (caddr_t)uap->rusage,
731 sizeof (struct rusage));
732 }
733 return(error);
674}
675
676void
677ruadd(ru, ru2)
678 register struct rusage *ru, *ru2;
679{
680 register long *ip, *ip2;
681 register int i;

--- 227 unchanged lines hidden ---
734}
735
736void
737ruadd(ru, ru2)
738 register struct rusage *ru, *ru2;
739{
740 register long *ip, *ip2;
741 register int i;

--- 227 unchanged lines hidden ---