| @@ -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 |
1196 | int | | 1204 | int |
1197 | netbsd32_rmdir(struct lwp *l, const struct netbsd32_rmdir_args *uap, register_t *retval) | | 1205 | netbsd32_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 | |
1209 | int | | 1217 | // XXX new file |
1210 | netbsd32___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 | | | | |
1303 | int | | 1218 | int |
1304 | netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval) | | 1219 | netbsd32___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 | |
1463 | int | | 1378 | int |
1464 | netbsd32_fpathconf(struct lwp *l, const struct netbsd32_fpathconf_args *uap, register_t *retval) | | 1379 | netbsd32_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 | |
1477 | static void | | 1390 | return sys_fpathconf(l, &ua, retval); |
1478 | fixlimit(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 | | | | |
1498 | int | | | |
1499 | netbsd32_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 | | | | |
1519 | int | | | |
1520 | netbsd32_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 |
1543 | int | | 1394 | int |
1544 | netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval) | | 1395 | netbsd32_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 |
2070 | int | | 1921 | int |
2071 | netbsd32_ovadvise(struct lwp *l, const struct netbsd32_ovadvise_args *uap, register_t *retval) | | 1922 | netbsd32_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 | |
2083 | void | | | |
2084 | netbsd32_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 | | | | |
2133 | int | | 1934 | int |
2134 | netbsd32_uuidgen(struct lwp *l, const struct netbsd32_uuidgen_args *uap, register_t *retval) | | 1935 | netbsd32_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); |