Mon Dec 24 20:44:39 2018 UTC ()
move rlimit and quota code into their own modules.

(netbsd32_netbsd.c should have only simple shims.  anything more
than copying arguments from one args struct to the other should
not be placed in this file.  still a couple more to move out.)


(mrg)
diff -r1.39 -r1.40 src/sys/compat/netbsd32/files.netbsd32
diff -r1.220 -r1.221 src/sys/compat/netbsd32/netbsd32_netbsd.c
diff -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_quota.c
diff -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_rlimit.c

cvs diff -r1.39 -r1.40 src/sys/compat/netbsd32/files.netbsd32 (expand / switch to unified diff)

--- src/sys/compat/netbsd32/files.netbsd32 2016/10/19 09:44:01 1.39
+++ src/sys/compat/netbsd32/files.netbsd32 2018/12/24 20:44:39 1.40
@@ -1,37 +1,39 @@ @@ -1,37 +1,39 @@
1# $NetBSD: files.netbsd32,v 1.39 2016/10/19 09:44:01 skrll Exp $ 1# $NetBSD: files.netbsd32,v 1.40 2018/12/24 20:44:39 mrg Exp $
2# 2#
3# config file description for machine-independent netbsd32 compat code. 3# config file description for machine-independent netbsd32 compat code.
4# included by ports that need it. 4# included by ports that need it.
5 5
6# ports should define any machine-specific files they need in their 6# ports should define any machine-specific files they need in their
7# own file lists. 7# own file lists.
8 8
9define compat_netbsd32 9define compat_netbsd32
10file compat/netbsd32/netbsd32_core.c compat_netbsd32 & coredump 10file compat/netbsd32/netbsd32_core.c compat_netbsd32 & coredump
11file compat/netbsd32/netbsd32_exec_elf32.c compat_netbsd32 & exec_elf32 11file compat/netbsd32/netbsd32_exec_elf32.c compat_netbsd32 & exec_elf32
12file compat/netbsd32/netbsd32_exec_aout.c compat_netbsd32 & exec_aout 12file compat/netbsd32/netbsd32_exec_aout.c compat_netbsd32 & exec_aout
13file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32 13file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32
14file compat/netbsd32/netbsd32_event.c compat_netbsd32 14file compat/netbsd32/netbsd32_event.c compat_netbsd32
15file compat/netbsd32/netbsd32_execve.c compat_netbsd32 15file compat/netbsd32/netbsd32_execve.c compat_netbsd32
16file compat/netbsd32/netbsd32_fs.c compat_netbsd32 16file compat/netbsd32/netbsd32_fs.c compat_netbsd32
17file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32 17file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32
18file compat/netbsd32/netbsd32_ipc.c compat_netbsd32 18file compat/netbsd32/netbsd32_ipc.c compat_netbsd32
19file compat/netbsd32/netbsd32_lwp.c compat_netbsd32 19file compat/netbsd32/netbsd32_lwp.c compat_netbsd32
20file compat/netbsd32/netbsd32_module.c compat_netbsd32 20file compat/netbsd32/netbsd32_module.c compat_netbsd32
21file compat/netbsd32/netbsd32_mod.c compat_netbsd32 21file compat/netbsd32/netbsd32_mod.c compat_netbsd32
22file compat/netbsd32/netbsd32_mqueue.c compat_netbsd32 & mqueue 22file compat/netbsd32/netbsd32_mqueue.c compat_netbsd32 & mqueue
23file compat/netbsd32/netbsd32_nfssvc.c compat_netbsd32 & nfsserver 23file compat/netbsd32/netbsd32_nfssvc.c compat_netbsd32 & nfsserver
24file compat/netbsd32/netbsd32_ptrace.c compat_netbsd32 & ptrace 24file compat/netbsd32/netbsd32_ptrace.c compat_netbsd32 & ptrace
 25file compat/netbsd32/netbsd32_rlimit.c compat_netbsd32
 26file compat/netbsd32/netbsd32_quota.c compat_netbsd32 & quota
25file compat/netbsd32/netbsd32_select.c compat_netbsd32 27file compat/netbsd32/netbsd32_select.c compat_netbsd32
26file compat/netbsd32/netbsd32_sem.c compat_netbsd32 28file compat/netbsd32/netbsd32_sem.c compat_netbsd32
27file compat/netbsd32/netbsd32_signal.c compat_netbsd32 29file compat/netbsd32/netbsd32_signal.c compat_netbsd32
28file compat/netbsd32/netbsd32_socket.c compat_netbsd32 30file compat/netbsd32/netbsd32_socket.c compat_netbsd32
29file compat/netbsd32/netbsd32_sysctl.c compat_netbsd32 31file compat/netbsd32/netbsd32_sysctl.c compat_netbsd32
30file compat/netbsd32/netbsd32_time.c compat_netbsd32 32file compat/netbsd32/netbsd32_time.c compat_netbsd32
31file compat/netbsd32/netbsd32_wait.c compat_netbsd32 33file compat/netbsd32/netbsd32_wait.c compat_netbsd32
32file compat/netbsd32/netbsd32_sysent.c compat_netbsd32 34file compat/netbsd32/netbsd32_sysent.c compat_netbsd32
33file compat/netbsd32/netbsd32_syscalls.c compat_netbsd32 & syscall_debug 35file compat/netbsd32/netbsd32_syscalls.c compat_netbsd32 & syscall_debug
34 36
35file compat/netbsd32/netbsd32_compat_09.c compat_netbsd32 & (compat_09 | compat_sunos) 37file compat/netbsd32/netbsd32_compat_09.c compat_netbsd32 & (compat_09 | compat_sunos)
36file compat/netbsd32/netbsd32_compat_10.c compat_netbsd32 & (compat_10 | compat_sunos) 38file compat/netbsd32/netbsd32_compat_10.c compat_netbsd32 & (compat_10 | compat_sunos)
37file compat/netbsd32/netbsd32_compat_12.c compat_netbsd32 & (compat_12 | compat_sunos) 39file compat/netbsd32/netbsd32_compat_12.c compat_netbsd32 & (compat_12 | compat_sunos)

cvs diff -r1.220 -r1.221 src/sys/compat/netbsd32/netbsd32_netbsd.c (expand / switch to unified diff)

--- src/sys/compat/netbsd32/netbsd32_netbsd.c 2018/12/24 20:39:17 1.220
+++ src/sys/compat/netbsd32/netbsd32_netbsd.c 2018/12/24 20:44:39 1.221
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: netbsd32_netbsd.c,v 1.220 2018/12/24 20:39:17 mrg Exp $ */ 1/* $NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green 4 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,35 @@ @@ -17,27 +17,35 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.220 2018/12/24 20:39:17 mrg Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $");
 31
 32/*
 33 * below are all the standard NetBSD system calls, in the 32bit
 34 * environment, with the necessary conversions to 64bit before calling
 35 * the real syscall. anything that needs special attention is handled
 36 * elsewhere - this file should only contain structure assignment and
 37 * calls to the original function.
 38 */
31 39
32/* 40/*
33 * below are all the standard NetBSD system calls, in the 32bit 41 * below are all the standard NetBSD system calls, in the 32bit
34 * environment, with the necessary conversions to 64bit before calling 42 * environment, with the necessary conversions to 64bit before calling
35 * the real syscall. anything that needs special attention is handled 43 * the real syscall. anything that needs special attention is handled
36 * elsewhere - this file should only contain structure assignment and 44 * elsewhere - this file should only contain structure assignment and
37 * calls to the original function. 45 * calls to the original function.
38 */ 46 */
39 47
40#if defined(_KERNEL_OPT) 48#if defined(_KERNEL_OPT)
41#include "opt_ddb.h" 49#include "opt_ddb.h"
42#include "opt_ntp.h" 50#include "opt_ntp.h"
43#include "opt_ktrace.h" 51#include "opt_ktrace.h"
@@ -1196,120 +1204,27 @@ netbsd32_mkdir(struct lwp *l, const stru @@ -1196,120 +1204,27 @@ netbsd32_mkdir(struct lwp *l, const stru
1196int 1204int
1197netbsd32_rmdir(struct lwp *l, const struct netbsd32_rmdir_args *uap, register_t *retval) 1205netbsd32_rmdir(struct lwp *l, const struct netbsd32_rmdir_args *uap, register_t *retval)
1198{ 1206{
1199 /* { 1207 /* {
1200 syscallarg(const netbsd32_charp) path; 1208 syscallarg(const netbsd32_charp) path;
1201 } */ 1209 } */
1202 struct sys_rmdir_args ua; 1210 struct sys_rmdir_args ua;
1203 1211
1204 NETBSD32TOP_UAP(path, const char); 1212 NETBSD32TOP_UAP(path, const char);
1205 1213
1206 return sys_rmdir(l, &ua, retval); 1214 return sys_rmdir(l, &ua, retval);
1207} 1215}
1208 1216
1209int 1217// XXX new file
1210netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval) 
1211{ 
1212 /* { 
1213 syscallarg(const netbsd32_charp) path; 
1214 syscallarg(netbsd32_voidp) args; 
1215 } */ 
1216 struct netbsd32_quotactlargs args32; 
1217 struct quotactl_args args; 
1218 int error; 
1219 
1220 error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32)); 
1221 if (error) { 
1222 return error; 
1223 } 
1224 
1225 args.qc_op = args32.qc_op; 
1226 switch (args.qc_op) { 
1227 case QUOTACTL_STAT: 
1228 args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info); 
1229 break; 
1230 case QUOTACTL_IDTYPESTAT: 
1231 args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype; 
1232 args.u.idtypestat.qc_info = 
1233 NETBSD32PTR64(args32.u.idtypestat.qc_info); 
1234 break; 
1235 case QUOTACTL_OBJTYPESTAT: 
1236 args.u.objtypestat.qc_objtype = 
1237 args32.u.objtypestat.qc_objtype; 
1238 args.u.objtypestat.qc_info = 
1239 NETBSD32PTR64(args32.u.objtypestat.qc_info); 
1240 break; 
1241 case QUOTACTL_GET: 
1242 args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key); 
1243 args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val); 
1244 break; 
1245 case QUOTACTL_PUT: 
1246 args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key); 
1247 args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val); 
1248 break; 
1249 case QUOTACTL_DEL: 
1250 args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key); 
1251 break; 
1252 case QUOTACTL_CURSOROPEN: 
1253 args.u.cursoropen.qc_cursor = 
1254 NETBSD32PTR64(args32.u.cursoropen.qc_cursor); 
1255 break; 
1256 case QUOTACTL_CURSORCLOSE: 
1257 args.u.cursorclose.qc_cursor = 
1258 NETBSD32PTR64(args32.u.cursorclose.qc_cursor); 
1259 break; 
1260 case QUOTACTL_CURSORSKIPIDTYPE: 
1261 args.u.cursorskipidtype.qc_cursor = 
1262 NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor); 
1263 args.u.cursorskipidtype.qc_idtype = 
1264 args32.u.cursorskipidtype.qc_idtype; 
1265 break; 
1266 case QUOTACTL_CURSORGET: 
1267 args.u.cursorget.qc_cursor = 
1268 NETBSD32PTR64(args32.u.cursorget.qc_cursor); 
1269 args.u.cursorget.qc_keys = 
1270 NETBSD32PTR64(args32.u.cursorget.qc_keys); 
1271 args.u.cursorget.qc_vals = 
1272 NETBSD32PTR64(args32.u.cursorget.qc_vals); 
1273 args.u.cursorget.qc_maxnum = 
1274 args32.u.cursorget.qc_maxnum; 
1275 args.u.cursorget.qc_ret = 
1276 NETBSD32PTR64(args32.u.cursorget.qc_ret); 
1277 break; 
1278 case QUOTACTL_CURSORATEND: 
1279 args.u.cursoratend.qc_cursor = 
1280 NETBSD32PTR64(args32.u.cursoratend.qc_cursor); 
1281 args.u.cursoratend.qc_ret = 
1282 NETBSD32PTR64(args32.u.cursoratend.qc_ret); 
1283 break; 
1284 case QUOTACTL_CURSORREWIND: 
1285 args.u.cursorrewind.qc_cursor = 
1286 NETBSD32PTR64(args32.u.cursorrewind.qc_cursor); 
1287 break; 
1288 case QUOTACTL_QUOTAON: 
1289 args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype; 
1290 args.u.quotaon.qc_quotafile = 
1291 NETBSD32PTR64(args32.u.quotaon.qc_quotafile); 
1292 break; 
1293 case QUOTACTL_QUOTAOFF: 
1294 args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype; 
1295 break; 
1296 default: 
1297 return EINVAL; 
1298 } 
1299 
1300 return do_sys_quotactl(SCARG_P32(uap, path), &args); 
1301} 
1302 
1303int 1218int
1304netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval) 1219netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval)
1305{ 1220{
1306 /* { 1221 /* {
1307 syscallarg(const netbsd32_charp) fname; 1222 syscallarg(const netbsd32_charp) fname;
1308 syscallarg(netbsd32_fhandlep_t) fhp; 1223 syscallarg(netbsd32_fhandlep_t) fhp;
1309 syscallarg(netbsd32_size_tp) fh_size; 1224 syscallarg(netbsd32_size_tp) fh_size;
1310 } */ 1225 } */
1311 struct vnode *vp; 1226 struct vnode *vp;
1312 fhandle_t *fh; 1227 fhandle_t *fh;
1313 int error; 1228 int error;
1314 struct pathbuf *pb; 1229 struct pathbuf *pb;
1315 struct nameidata nd; 1230 struct nameidata nd;
@@ -1461,95 +1376,31 @@ netbsd32_pathconf(struct lwp *l, const s @@ -1461,95 +1376,31 @@ netbsd32_pathconf(struct lwp *l, const s
1461} 1376}
1462 1377
1463int 1378int
1464netbsd32_fpathconf(struct lwp *l, const struct netbsd32_fpathconf_args *uap, register_t *retval) 1379netbsd32_fpathconf(struct lwp *l, const struct netbsd32_fpathconf_args *uap, register_t *retval)
1465{ 1380{
1466 /* { 1381 /* {
1467 syscallarg(int) fd; 1382 syscallarg(int) fd;
1468 syscallarg(int) name; 1383 syscallarg(int) name;
1469 } */ 1384 } */
1470 struct sys_fpathconf_args ua; 1385 struct sys_fpathconf_args ua;
1471 1386
1472 NETBSD32TO64_UAP(fd); 1387 NETBSD32TO64_UAP(fd);
1473 NETBSD32TO64_UAP(name); 1388 NETBSD32TO64_UAP(name);
1474 return sys_fpathconf(l, &ua, retval); 
1475} 
1476 1389
1477static void 1390 return sys_fpathconf(l, &ua, retval);
1478fixlimit(int which, struct rlimit *alim) 
1479{ 
1480 switch (which) { 
1481 case RLIMIT_DATA: 
1482 if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32)) 
1483 alim->rlim_cur = MAXDSIZ32; 
1484 if (LIMITCHECK(alim->rlim_max, MAXDSIZ32)) 
1485 alim->rlim_max = MAXDSIZ32; 
1486 return; 
1487 case RLIMIT_STACK: 
1488 if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32)) 
1489 alim->rlim_cur = MAXSSIZ32; 
1490 if (LIMITCHECK(alim->rlim_max, MAXSSIZ32)) 
1491 alim->rlim_max = MAXSSIZ32; 
1492 return; 
1493 default: 
1494 return; 
1495 } 
1496} 
1497 
1498int 
1499netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap, 
1500 register_t *retval) 
1501{ 
1502 /* { 
1503 syscallarg(int) which; 
1504 syscallarg(netbsd32_rlimitp_t) rlp; 
1505 } */ 
1506 int which = SCARG(uap, which); 
1507 struct rlimit alim; 
1508 
1509 if ((u_int)which >= RLIM_NLIMITS) 
1510 return EINVAL; 
1511 
1512 alim = l->l_proc->p_rlimit[which]; 
1513 
1514 fixlimit(which, &alim); 
1515 
1516 return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim)); 
1517} 
1518 
1519int 
1520netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap, 
1521 register_t *retval) 
1522{ 
1523 /* { 
1524 syscallarg(int) which; 
1525 syscallarg(const netbsd32_rlimitp_t) rlp; 
1526 } */ 
1527 int which = SCARG(uap, which); 
1528 struct rlimit alim; 
1529 int error; 
1530 
1531 if ((u_int)which >= RLIM_NLIMITS) 
1532 return EINVAL; 
1533 
1534 error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit)); 
1535 if (error) 
1536 return error; 
1537 
1538 fixlimit(which, &alim); 
1539 
1540 return dosetrlimit(l, l->l_proc, which, &alim); 
1541} 1391}
1542 1392
 1393// XXX new file
1543int 1394int
1544netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval) 1395netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
1545{ 1396{
1546 /* { 1397 /* {
1547 syscallarg(netbsd32_voidp) addr; 1398 syscallarg(netbsd32_voidp) addr;
1548 syscallarg(netbsd32_size_t) len; 1399 syscallarg(netbsd32_size_t) len;
1549 syscallarg(int) prot; 1400 syscallarg(int) prot;
1550 syscallarg(int) flags; 1401 syscallarg(int) flags;
1551 syscallarg(int) fd; 1402 syscallarg(int) fd;
1552 syscallarg(netbsd32_long) PAD; 1403 syscallarg(netbsd32_long) PAD;
1553 syscallarg(netbsd32_off_t) pos; 1404 syscallarg(netbsd32_off_t) pos;
1554 } */ 1405 } */
1555 struct sys_mmap_args ua; 1406 struct sys_mmap_args ua;
@@ -2070,76 +1921,26 @@ netbsd32___fhopen40(struct lwp *l, const @@ -2070,76 +1921,26 @@ netbsd32___fhopen40(struct lwp *l, const
2070int 1921int
2071netbsd32_ovadvise(struct lwp *l, const struct netbsd32_ovadvise_args *uap, register_t *retval) 1922netbsd32_ovadvise(struct lwp *l, const struct netbsd32_ovadvise_args *uap, register_t *retval)
2072{ 1923{
2073 /* { 1924 /* {
2074 syscallarg(int) anom; 1925 syscallarg(int) anom;
2075 } */ 1926 } */
2076 struct sys_ovadvise_args ua; 1927 struct sys_ovadvise_args ua;
2077 1928
2078 NETBSD32TO64_UAP(anom); 1929 NETBSD32TO64_UAP(anom);
2079 1930
2080 return sys_ovadvise(l, &ua, retval); 1931 return sys_ovadvise(l, &ua, retval);
2081} 1932}
2082 1933
2083void 
2084netbsd32_adjust_limits(struct proc *p) 
2085{ 
2086 static const struct { 
2087 int id; 
2088 rlim_t lim; 
2089 } lm[] = { 
2090 { RLIMIT_DATA, MAXDSIZ32 }, 
2091 { RLIMIT_STACK, MAXSSIZ32 }, 
2092 }; 
2093 size_t i; 
2094 struct plimit *lim; 
2095 struct rlimit *rlim; 
2096 
2097 /* 
2098 * We can only reduce the current limits, we cannot stop external 
2099 * processes from changing them (eg via sysctl) later on. 
2100 * So there is no point trying to lock out such changes here. 
2101 * 
2102 * If we assume that rlim_cur/max are accessed using atomic 
2103 * operations, we don't need to lock against any other updates 
2104 * that might happen if the plimit structure is shared writable 
2105 * between multiple processes. 
2106 */ 
2107 
2108 /* Scan to determine is any limits are out of range */ 
2109 lim = p->p_limit; 
2110 for (i = 0; ; i++) { 
2111 if (i >= __arraycount(lm)) 
2112 /* All in range */ 
2113 return; 
2114 rlim = lim->pl_rlimit + lm[i].id; 
2115 if (LIMITCHECK(rlim->rlim_cur, lm[i].lim)) 
2116 break; 
2117 if (LIMITCHECK(rlim->rlim_max, lm[i].lim)) 
2118 break; 
2119 } 
2120 
2121 lim_privatise(p); 
2122 
2123 lim = p->p_limit; 
2124 for (i = 0; i < __arraycount(lm); i++) { 
2125 rlim = lim->pl_rlimit + lm[i].id; 
2126 if (LIMITCHECK(rlim->rlim_cur, lm[i].lim)) 
2127 rlim->rlim_cur = lm[i].lim; 
2128 if (LIMITCHECK(rlim->rlim_max, lm[i].lim)) 
2129 rlim->rlim_max = lm[i].lim; 
2130 } 
2131} 
2132 
2133int 1934int
2134netbsd32_uuidgen(struct lwp *l, const struct netbsd32_uuidgen_args *uap, register_t *retval) 1935netbsd32_uuidgen(struct lwp *l, const struct netbsd32_uuidgen_args *uap, register_t *retval)
2135{ 1936{
2136 /* { 1937 /* {
2137 syscallarg(netbsd32_uuidp_t) store; 1938 syscallarg(netbsd32_uuidp_t) store;
2138 syscallarg(int) count; 1939 syscallarg(int) count;
2139 } */ 1940 } */
2140 struct sys_uuidgen_args ua; 1941 struct sys_uuidgen_args ua;
2141 1942
2142 NETBSD32TOP_UAP(store, struct uuid); 1943 NETBSD32TOP_UAP(store, struct uuid);
2143 NETBSD32TO64_UAP(count); 1944 NETBSD32TO64_UAP(count);
2144 1945
2145 return sys_uuidgen(l, &ua, retval); 1946 return sys_uuidgen(l, &ua, retval);

File Added: src/sys/compat/netbsd32/netbsd32_quota.c
/*	$NetBSD: netbsd32_quota.c,v 1.1 2018/12/24 20:44:39 mrg Exp $	*/

/*
 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_quota.c,v 1.1 2018/12/24 20:44:39 mrg Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/quotactl.h>
#include <sys/filedesc.h>
#include <sys/vfs_syscalls.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>

int
netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
{
	/* {
		syscallarg(const netbsd32_charp) path;
		syscallarg(netbsd32_voidp) args;
	} */
	struct netbsd32_quotactlargs args32;
	struct quotactl_args args;
	int error;

	error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
	if (error) {
		return error;
	}

	args.qc_op = args32.qc_op;
	switch (args.qc_op) {
	    case QUOTACTL_STAT:
		args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
		break;
	    case QUOTACTL_IDTYPESTAT:
		args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
		args.u.idtypestat.qc_info =
			NETBSD32PTR64(args32.u.idtypestat.qc_info);
		break;
	    case QUOTACTL_OBJTYPESTAT:
		args.u.objtypestat.qc_objtype =
			args32.u.objtypestat.qc_objtype;
		args.u.objtypestat.qc_info =
			NETBSD32PTR64(args32.u.objtypestat.qc_info);
		break;
	    case QUOTACTL_GET:
		args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
		args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
		break;
	    case QUOTACTL_PUT:
		args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
		args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
		break;
	    case QUOTACTL_DEL:
		args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
		break;
	    case QUOTACTL_CURSOROPEN:
		args.u.cursoropen.qc_cursor =
			NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
		break;
	    case QUOTACTL_CURSORCLOSE:
		args.u.cursorclose.qc_cursor =
			NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
		break;
	    case QUOTACTL_CURSORSKIPIDTYPE:
		args.u.cursorskipidtype.qc_cursor =
			NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
		args.u.cursorskipidtype.qc_idtype =
			args32.u.cursorskipidtype.qc_idtype;
		break;
	    case QUOTACTL_CURSORGET:
		args.u.cursorget.qc_cursor =
			NETBSD32PTR64(args32.u.cursorget.qc_cursor);
		args.u.cursorget.qc_keys =
			NETBSD32PTR64(args32.u.cursorget.qc_keys);
		args.u.cursorget.qc_vals =
			NETBSD32PTR64(args32.u.cursorget.qc_vals);
		args.u.cursorget.qc_maxnum =
			args32.u.cursorget.qc_maxnum;
		args.u.cursorget.qc_ret =
			NETBSD32PTR64(args32.u.cursorget.qc_ret);
		break;
	    case QUOTACTL_CURSORATEND:
		args.u.cursoratend.qc_cursor =
			NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
		args.u.cursoratend.qc_ret =
			NETBSD32PTR64(args32.u.cursoratend.qc_ret);
		break;
	    case QUOTACTL_CURSORREWIND:
		args.u.cursorrewind.qc_cursor =
			NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
		break;
	    case QUOTACTL_QUOTAON:
		args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
		args.u.quotaon.qc_quotafile =
			NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
		break;
	    case QUOTACTL_QUOTAOFF:
		args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
		break;
	    default:
		return EINVAL;
	}

	return do_sys_quotactl(SCARG_P32(uap, path), &args);
}

File Added: src/sys/compat/netbsd32/netbsd32_rlimit.c
/*	$NetBSD: netbsd32_rlimit.c,v 1.1 2018/12/24 20:44:39 mrg Exp $	*/

/*
 * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * from: NetBSD: netbsd32_netbsd.c,v 1.218 2018/08/10 21:44:58 pgoyette Exp
 */

/* rlimit netbsd32 related code */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_rlimit.c,v 1.1 2018/12/24 20:44:39 mrg Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/resource.h>
#include <sys/exec.h>

#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>

#define LIMITCHECK(a, b) ((a) != RLIM_INFINITY && (a) > (b))

static void
fixlimit(int which, struct rlimit *alim)
{
	switch (which) {
	case RLIMIT_DATA:
		if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
			alim->rlim_cur = MAXDSIZ32;
		if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
			alim->rlim_max = MAXDSIZ32;
		return;
	case RLIMIT_STACK:
		if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
			alim->rlim_cur = MAXSSIZ32;
		if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
			alim->rlim_max = MAXSSIZ32;
		return;
	default:
		return;
	}
}

int
netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(int) which;
		syscallarg(netbsd32_rlimitp_t) rlp;
	} */
	int which = SCARG(uap, which);
	struct rlimit alim;

	if ((u_int)which >= RLIM_NLIMITS)
		return EINVAL;

	alim = l->l_proc->p_rlimit[which];

	fixlimit(which, &alim);

	return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
}

int
netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(int) which;
		syscallarg(const netbsd32_rlimitp_t) rlp;
	} */
		int which = SCARG(uap, which);
	struct rlimit alim;
	int error;

	if ((u_int)which >= RLIM_NLIMITS)
		return EINVAL;

	error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
	if (error)
		return (error);

	fixlimit(which, &alim);

	return dosetrlimit(l, l->l_proc, which, &alim);
}

void
netbsd32_adjust_limits(struct proc *p)
{
	static const struct {
		int id;
		rlim_t lim;
	} lm[] = {
		{ RLIMIT_DATA,	MAXDSIZ32 },
		{ RLIMIT_STACK, MAXSSIZ32 },
	};
	size_t i;
	struct plimit *lim;
	struct rlimit *rlim;

	/*
	 * We can only reduce the current limits, we cannot stop external
	 * processes from changing them (eg via sysctl) later on.
	 * So there is no point trying to lock out such changes here.
	 *
	 * If we assume that rlim_cur/max are accessed using atomic
	 * operations, we don't need to lock against any other updates
	 * that might happen if the plimit structure is shared writable
	 * between multiple processes.
	 */

	/* Scan to determine is any limits are out of range */
	lim = p->p_limit;
	for (i = 0; ; i++) {
		if (i >= __arraycount(lm))
			/* All in range */
			return;
		rlim = lim->pl_rlimit + lm[i].id;
		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
			break;
		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
			break;
	}

	lim_privatise(p);

	lim = p->p_limit;
	for (i = 0; i < __arraycount(lm); i++) {
		rlim = lim->pl_rlimit + lm[i].id;
		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
			rlim->rlim_cur = lm[i].lim;
		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
			rlim->rlim_max = lm[i].lim;
	}
}