1*41aa5859Sriastradh /* $NetBSD: kern_resource_43.c,v 1.23 2021/09/07 11:43:02 riastradh Exp $ */
2dcb2a50bSchristos
3dcb2a50bSchristos /*-
4dcb2a50bSchristos * Copyright (c) 1982, 1986, 1991, 1993
5dcb2a50bSchristos * The Regents of the University of California. All rights reserved.
6dcb2a50bSchristos * (c) UNIX System Laboratories, Inc.
7dcb2a50bSchristos * All or some portions of this file are derived from material licensed
8dcb2a50bSchristos * to the University of California by American Telephone and Telegraph
9dcb2a50bSchristos * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10dcb2a50bSchristos * the permission of UNIX System Laboratories, Inc.
11dcb2a50bSchristos *
12dcb2a50bSchristos * Redistribution and use in source and binary forms, with or without
13dcb2a50bSchristos * modification, are permitted provided that the following conditions
14dcb2a50bSchristos * are met:
15dcb2a50bSchristos * 1. Redistributions of source code must retain the above copyright
16dcb2a50bSchristos * notice, this list of conditions and the following disclaimer.
17dcb2a50bSchristos * 2. Redistributions in binary form must reproduce the above copyright
18dcb2a50bSchristos * notice, this list of conditions and the following disclaimer in the
19dcb2a50bSchristos * documentation and/or other materials provided with the distribution.
20aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
21dcb2a50bSchristos * may be used to endorse or promote products derived from this software
22dcb2a50bSchristos * without specific prior written permission.
23dcb2a50bSchristos *
24dcb2a50bSchristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25dcb2a50bSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26dcb2a50bSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27dcb2a50bSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28dcb2a50bSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29dcb2a50bSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30dcb2a50bSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31dcb2a50bSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32dcb2a50bSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33dcb2a50bSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34dcb2a50bSchristos * SUCH DAMAGE.
35dcb2a50bSchristos *
36dcb2a50bSchristos * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94
37dcb2a50bSchristos */
38dcb2a50bSchristos
39dab6ef8bSlukem #include <sys/cdefs.h>
40*41aa5859Sriastradh __KERNEL_RCSID(0, "$NetBSD: kern_resource_43.c,v 1.23 2021/09/07 11:43:02 riastradh Exp $");
41d91f98a8Spgoyette
42d91f98a8Spgoyette #if defined(_KERNEL_OPT)
43d91f98a8Spgoyette #include "opt_compat_netbsd.h"
44d91f98a8Spgoyette #endif
45dab6ef8bSlukem
46dcb2a50bSchristos #include <sys/param.h>
47dcb2a50bSchristos #include <sys/systm.h>
48dcb2a50bSchristos #include <sys/kernel.h>
49dcb2a50bSchristos #include <sys/file.h>
50dcb2a50bSchristos #include <sys/resourcevar.h>
51dcb2a50bSchristos #include <sys/proc.h>
52dcb2a50bSchristos
53dcb2a50bSchristos #include <sys/mount.h>
54d91f98a8Spgoyette #include <sys/syscall.h>
55d91f98a8Spgoyette #include <sys/syscallvar.h>
56dcb2a50bSchristos #include <sys/syscallargs.h>
57dcb2a50bSchristos
58d91f98a8Spgoyette #include <compat/common/compat_mod.h>
59d91f98a8Spgoyette
60d91f98a8Spgoyette static struct syscall_package kern_resource_43_syscalls[] = {
61d91f98a8Spgoyette { SYS_compat_43_ogetrlimit, 0, (sy_call_t *)compat_43_sys_getrlimit },
62d91f98a8Spgoyette { SYS_compat_43_osetrlimit, 0, (sy_call_t *)compat_43_sys_setrlimit },
63d91f98a8Spgoyette { 0, 0, NULL }
64d91f98a8Spgoyette };
65d91f98a8Spgoyette
66dcb2a50bSchristos /* ARGSUSED */
67dcb2a50bSchristos int
compat_43_sys_getrlimit(struct lwp * l,const struct compat_43_sys_getrlimit_args * uap,register_t * retval)687e2790cfSdsl compat_43_sys_getrlimit(struct lwp *l, const struct compat_43_sys_getrlimit_args *uap, register_t *retval)
697160dfc8Sthorpej {
707e2790cfSdsl /* {
712587de6aSmycroft syscallarg(int) which;
722587de6aSmycroft syscallarg(struct orlimit *) rlp;
737e2790cfSdsl } */
746762b37eSthorpej struct proc *p = l->l_proc;
752587de6aSmycroft int which = SCARG(uap, which);
76dcb2a50bSchristos struct orlimit olim;
77dcb2a50bSchristos
782587de6aSmycroft if ((u_int)which >= RLIM_NLIMITS)
79dcb2a50bSchristos return (EINVAL);
80*41aa5859Sriastradh memset(&olim, 0, sizeof(olim));
812587de6aSmycroft olim.rlim_cur = p->p_rlimit[which].rlim_cur;
82dcb2a50bSchristos if (olim.rlim_cur == -1)
83dcb2a50bSchristos olim.rlim_cur = 0x7fffffff;
842587de6aSmycroft olim.rlim_max = p->p_rlimit[which].rlim_max;
85dcb2a50bSchristos if (olim.rlim_max == -1)
86dcb2a50bSchristos olim.rlim_max = 0x7fffffff;
878beba9d0Sdsl return copyout(&olim, SCARG(uap, rlp), sizeof(olim));
88dcb2a50bSchristos }
89dcb2a50bSchristos
90dcb2a50bSchristos /* ARGSUSED */
91dcb2a50bSchristos int
compat_43_sys_setrlimit(struct lwp * l,const struct compat_43_sys_setrlimit_args * uap,register_t * retval)927e2790cfSdsl compat_43_sys_setrlimit(struct lwp *l, const struct compat_43_sys_setrlimit_args *uap, register_t *retval)
937160dfc8Sthorpej {
947e2790cfSdsl /* {
952587de6aSmycroft syscallarg(int) which;
962587de6aSmycroft syscallarg(const struct orlimit *) rlp;
977e2790cfSdsl } */
982587de6aSmycroft int which = SCARG(uap, which);
99dcb2a50bSchristos struct orlimit olim;
100dcb2a50bSchristos struct rlimit lim;
101dcb2a50bSchristos int error;
102dcb2a50bSchristos
103fb4b40b7Schristos error = copyin(SCARG(uap, rlp), &olim, sizeof(struct orlimit));
1046cbf515eSchristos if (error)
105dcb2a50bSchristos return (error);
106dcb2a50bSchristos lim.rlim_cur = olim.rlim_cur;
107dcb2a50bSchristos lim.rlim_max = olim.rlim_max;
108f474dcebSad return (dosetrlimit(l, l->l_proc, which, &lim));
109dcb2a50bSchristos }
110d91f98a8Spgoyette
111d91f98a8Spgoyette int
kern_resource_43_init(void)112d91f98a8Spgoyette kern_resource_43_init(void)
113d91f98a8Spgoyette {
114d91f98a8Spgoyette
115d91f98a8Spgoyette return syscall_establish(NULL, kern_resource_43_syscalls);
116d91f98a8Spgoyette }
117d91f98a8Spgoyette
118d91f98a8Spgoyette int
kern_resource_43_fini(void)119d91f98a8Spgoyette kern_resource_43_fini(void)
120d91f98a8Spgoyette {
121d91f98a8Spgoyette
122d91f98a8Spgoyette return syscall_disestablish(NULL, kern_resource_43_syscalls);
123d91f98a8Spgoyette }
124