Deleted Added
full compact
kern_resource.c (72200) kern_resource.c (72376)
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 72200 2001-02-09 06:11:45Z bmilekic $
39 * $FreeBSD: head/sys/kern/kern_resource.c 72376 2001-02-12 00:20:08Z jake $
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>

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

259 else
260 p = pfind(uap->pid);
261
262 if (p == 0)
263 return (ESRCH);
264
265 switch (uap->function) {
266 case RTP_LOOKUP:
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>

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

259 else
260 p = pfind(uap->pid);
261
262 if (p == 0)
263 return (ESRCH);
264
265 switch (uap->function) {
266 case RTP_LOOKUP:
267 return (copyout(&p->p_rtprio, uap->rtp, sizeof(struct rtprio)));
267 pri_to_rtp(&p->p_pri, &rtp);
268 return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
268 case RTP_SET:
269 if ((error = p_can(curp, p, P_CAN_SCHED, NULL)))
270 return (error);
271 /* disallow setting rtprio in most cases if not superuser */
272 if (suser(curp) != 0) {
273 /* can't set someone else's */
274 if (uap->pid)
275 return (EPERM);

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

282 * due to a CPU-bound normal process). Fix me! XXX
283 */
284#if 0
285 if (RTP_PRIO_IS_REALTIME(rtp.type))
286#endif
287 if (rtp.type != RTP_PRIO_NORMAL)
288 return (EPERM);
289 }
269 case RTP_SET:
270 if ((error = p_can(curp, p, P_CAN_SCHED, NULL)))
271 return (error);
272 /* disallow setting rtprio in most cases if not superuser */
273 if (suser(curp) != 0) {
274 /* can't set someone else's */
275 if (uap->pid)
276 return (EPERM);

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

283 * due to a CPU-bound normal process). Fix me! XXX
284 */
285#if 0
286 if (RTP_PRIO_IS_REALTIME(rtp.type))
287#endif
288 if (rtp.type != RTP_PRIO_NORMAL)
289 return (EPERM);
290 }
290 switch (rtp.type) {
291#ifdef RTP_PRIO_FIFO
292 case RTP_PRIO_FIFO:
293#endif
294 case RTP_PRIO_REALTIME:
295 case RTP_PRIO_NORMAL:
296 case RTP_PRIO_IDLE:
297 if (rtp.prio > RTP_PRIO_MAX)
298 return (EINVAL);
299 p->p_rtprio = rtp;
291 if (rtp_to_pri(&rtp, &p->p_pri) == 0)
300 return (0);
292 return (0);
301 default:
302 return (EINVAL);
303 }
304
293 return (EINVAL);
305 default:
306 return (EINVAL);
307 }
308}
309
294 default:
295 return (EINVAL);
296 }
297}
298
299int
300rtp_to_pri(struct rtprio *rtp, struct priority *pri)
301{
302
303 if (rtp->prio > RTP_PRIO_MAX)
304 return (-1);
305 switch (RTP_PRIO_BASE(rtp->type)) {
306 case RTP_PRIO_REALTIME:
307 pri->pri_level = PRI_MIN_REALTIME + rtp->prio;
308 break;
309 case RTP_PRIO_NORMAL:
310 pri->pri_level = PRI_MIN_TIMESHARE + rtp->prio;
311 break;
312 case RTP_PRIO_IDLE:
313 pri->pri_level = PRI_MIN_IDLE + rtp->prio;
314 break;
315 default:
316 return (-1);
317 }
318 pri->pri_class = rtp->type;
319 pri->pri_native = pri->pri_level;
320 pri->pri_user = pri->pri_level;
321 return (0);
322}
323
324void
325pri_to_rtp(struct priority *pri, struct rtprio *rtp)
326{
327
328 switch (PRI_BASE(pri->pri_class)) {
329 case PRI_REALTIME:
330 rtp->prio = pri->pri_level - PRI_MIN_REALTIME;
331 break;
332 case PRI_TIMESHARE:
333 rtp->prio = pri->pri_level - PRI_MIN_TIMESHARE;
334 break;
335 case PRI_IDLE:
336 rtp->prio = pri->pri_level - PRI_MIN_IDLE;
337 break;
338 default:
339 break;
340 }
341 rtp->type = pri->pri_class;
342}
343
310#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
311#ifndef _SYS_SYSPROTO_H_
312struct osetrlimit_args {
313 u_int which;
314 struct orlimit *rlp;
315};
316#endif
317/* ARGSUSED */

--- 544 unchanged lines hidden ---
344#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
345#ifndef _SYS_SYSPROTO_H_
346struct osetrlimit_args {
347 u_int which;
348 struct orlimit *rlp;
349};
350#endif
351/* ARGSUSED */

--- 544 unchanged lines hidden ---