Deleted Added
sdiff udiff text old ( 80116 ) new ( 82749 )
full compact
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 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
83/*
84 * MPSAFE
85 */
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;
94
95 mtx_lock(&Giant);
96
97 switch (uap->which) {
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:
138 error = EINVAL;
139 break;
140 }
141 if (low == PRIO_MAX + 1 && error == 0)
142 error = ESRCH;
143 curp->p_retval[0] = low;
144 mtx_unlock(&Giant);
145 return (error);
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 */
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
167 mtx_lock(&Giant);
168
169 switch (uap->which) {
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:
214 error = EINVAL;
215 break;
216 }
217 if (found == 0 && error == 0)
218 error = ESRCH;
219 mtx_unlock(&Giant);
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 */
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
271 if (uap->pid == 0) {
272 p = curp;
273 PROC_LOCK(p);
274 } else {
275 p = pfind(uap->pid);
276 }
277
278 if (p == NULL) {
279 error = ESRCH;
280 goto done2;
281 }
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);
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 */
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;
399 mtx_lock(&Giant);
400 error = dosetrlimit(p, uap->which, &lim);
401 mtx_unlock(&Giant);
402 return (error);
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 */
414/* ARGSUSED */
415int
416ogetrlimit(p, uap)
417 struct proc *p;
418 register struct ogetrlimit_args *uap;
419{
420 struct orlimit olim;
421 int error;
422
423 if (uap->which >= RLIM_NLIMITS)
424 return (EINVAL);
425 mtx_lock(&Giant);
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;
432 error = copyout((caddr_t)&olim, (caddr_t)uap->rlp, sizeof(olim));
433 mtx_unlock(&Giant);
434 return (error);
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 */
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);
459 mtx_lock(&Giant);
460 error = dosetrlimit(p, uap->which, &alim);
461 mtx_unlock(&Giant);
462 return (error);
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 */
579/* ARGSUSED */
580int
581getrlimit(p, uap)
582 struct proc *p;
583 register struct __getrlimit_args *uap;
584{
585 int error;
586
587 if (uap->which >= RLIM_NLIMITS)
588 return (EINVAL);
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);
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 */
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;
708
709 mtx_lock(&Giant);
710
711 switch (uap->who) {
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:
724 rup = NULL;
725 error = EINVAL;
726 break;
727 }
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);
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 ---