Home | History | Annotate | Line # | Download | only in common
linux32_unistd.c revision 1.35.18.1
      1 /*	$NetBSD: linux32_unistd.c,v 1.35.18.1 2014/05/18 17:45:33 rmind Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Emmanuel Dreyfus
     17  * 4. The name of the author may not be used to endorse or promote
     18  *    products derived from this software without specific prior written
     19  *    permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 
     36 __KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.35.18.1 2014/05/18 17:45:33 rmind Exp $");
     37 
     38 #include <sys/types.h>
     39 #include <sys/param.h>
     40 #include <sys/fstypes.h>
     41 #include <sys/signal.h>
     42 #include <sys/dirent.h>
     43 #include <sys/kernel.h>
     44 #include <sys/fcntl.h>
     45 #include <sys/select.h>
     46 #include <sys/proc.h>
     47 #include <sys/ucred.h>
     48 #include <sys/swap.h>
     49 #include <sys/kauth.h>
     50 #include <sys/filedesc.h>
     51 #include <sys/vfs_syscalls.h>
     52 
     53 #include <machine/types.h>
     54 
     55 #include <sys/syscallargs.h>
     56 
     57 #include <compat/netbsd32/netbsd32.h>
     58 #include <compat/netbsd32/netbsd32_conv.h>
     59 
     60 #include <compat/linux/common/linux_types.h>
     61 #include <compat/linux/common/linux_signal.h>
     62 #include <compat/linux/common/linux_machdep.h>
     63 #include <compat/linux/common/linux_misc.h>
     64 #include <compat/linux/common/linux_oldolduname.h>
     65 #include <compat/linux/common/linux_ipc.h>
     66 #include <compat/linux/common/linux_sem.h>
     67 #include <compat/linux/common/linux_fcntl.h>
     68 #include <compat/linux/linux_syscallargs.h>
     69 
     70 #include <compat/linux32/common/linux32_types.h>
     71 #include <compat/linux32/common/linux32_signal.h>
     72 #include <compat/linux32/common/linux32_machdep.h>
     73 #include <compat/linux32/common/linux32_sched.h>
     74 #include <compat/linux32/common/linux32_sysctl.h>
     75 #include <compat/linux32/common/linux32_socketcall.h>
     76 #include <compat/linux32/linux32_syscallargs.h>
     77 
     78 static int linux32_select1(struct lwp *, register_t *,
     79     int, fd_set *, fd_set *, fd_set *, struct timeval *);
     80 
     81 int
     82 linux32_sys_brk(struct lwp *l, const struct linux32_sys_brk_args *uap, register_t *retval)
     83 {
     84 	/* {
     85 		syscallarg(netbsd32_charp) nsize;
     86 	} */
     87 	struct linux_sys_brk_args ua;
     88 
     89 	NETBSD32TOP_UAP(nsize, char);
     90 	return linux_sys_brk(l, &ua, retval);
     91 }
     92 
     93 int
     94 linux32_sys_llseek(struct lwp *l, const struct linux32_sys_llseek_args *uap, register_t *retval)
     95 {
     96 	/* {
     97 		syscallarg(int) fd;
     98                 syscallarg(u_int32_t) ohigh;
     99                 syscallarg(u_int32_t) olow;
    100 		syscallarg(netbsd32_voidp) res;
    101 		syscallarg(int) whence;
    102 	} */
    103 	struct linux_sys_llseek_args ua;
    104 
    105 	NETBSD32TO64_UAP(fd);
    106 	NETBSD32TO64_UAP(ohigh);
    107 	NETBSD32TO64_UAP(olow);
    108 	NETBSD32TOP_UAP(res, void);
    109 	NETBSD32TO64_UAP(whence);
    110 
    111 	return linux_sys_llseek(l, &ua, retval);
    112 }
    113 
    114 int
    115 linux32_sys_select(struct lwp *l, const struct linux32_sys_select_args *uap, register_t *retval)
    116 {
    117 	/* {
    118 		syscallarg(int) nfds;
    119 		syscallarg(netbsd32_fd_setp_t) readfds;
    120 		syscallarg(netbsd32_fd_setp_t) writefds;
    121 		syscallarg(netbsd32_fd_setp_t) exceptfds;
    122 		syscallarg(netbsd32_timeval50p_t) timeout;
    123 	} */
    124 
    125 	return linux32_select1(l, retval, SCARG(uap, nfds),
    126 	    SCARG_P32(uap, readfds),
    127 	    SCARG_P32(uap, writefds),
    128 	    SCARG_P32(uap, exceptfds),
    129 	    SCARG_P32(uap, timeout));
    130 }
    131 
    132 int
    133 linux32_sys_oldselect(struct lwp *l, const struct linux32_sys_oldselect_args *uap, register_t *retval)
    134 {
    135 	/* {
    136 		syscallarg(linux32_oldselectp_t) lsp;
    137 	} */
    138 	struct linux32_oldselect lsp32;
    139 	int error;
    140 
    141 	if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
    142 		return error;
    143 
    144 	return linux32_select1(l, retval, lsp32.nfds,
    145 	     NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
    146 	     NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
    147 }
    148 
    149 static int
    150 linux32_select1(struct lwp *l, register_t *retval, int nfds,
    151 		fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    152 		struct timeval *timeout)
    153 {
    154 	struct timespec ts0, ts1, uts, *ts = NULL;
    155 	struct netbsd32_timeval50 utv32;
    156 	int error;
    157 
    158 
    159 	/*
    160 	 * Store current time for computation of the amount of
    161 	 * time left.
    162 	 */
    163 	if (timeout) {
    164 		if ((error = copyin(timeout, &utv32, sizeof(utv32))))
    165 			return error;
    166 
    167 		uts.tv_sec = utv32.tv_sec;
    168 		uts.tv_nsec = utv32.tv_usec * 1000;
    169 
    170 		if (itimespecfix(&uts)) {
    171 			/*
    172 			 * The timeval was invalid.  Convert it to something
    173 			 * valid that will act as it does under Linux.
    174 			 */
    175 			uts.tv_sec += uts.tv_nsec / 1000000000;
    176 			uts.tv_nsec %= 1000000000;
    177 			if (uts.tv_nsec < 0) {
    178 				uts.tv_sec -= 1;
    179 				uts.tv_nsec += 1000000000;
    180 			}
    181 			if (uts.tv_sec < 0)
    182 				timespecclear(&uts);
    183 		}
    184 		nanotime(&ts0);
    185 		ts = &uts;
    186 	} else
    187 		timespecclear(&uts); /* XXX GCC4 */
    188 
    189 	error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL);
    190 
    191 	if (error) {
    192 		/*
    193 		 * See fs/select.c in the Linux kernel.  Without this,
    194 		 * Maelstrom doesn't work.
    195 		 */
    196 		if (error == ERESTART)
    197 			error = EINTR;
    198 		return error;
    199 	}
    200 
    201 	if (timeout) {
    202 		if (*retval) {
    203 			/*
    204 			 * Compute how much time was left of the timeout,
    205 			 * by subtracting the current time and the time
    206 			 * before we started the call, and subtracting
    207 			 * that result from the user-supplied value.
    208 			 */
    209 			nanotime(&ts1);
    210 			timespecsub(&ts1, &ts0, &ts1);
    211 			timespecsub(&uts, &ts1, &uts);
    212 			if (uts.tv_sec < 0)
    213 				timespecclear(&uts);
    214 		} else {
    215 			timespecclear(&uts);
    216 		}
    217 
    218 		utv32.tv_sec = uts.tv_sec;
    219 		utv32.tv_usec = uts.tv_nsec / 1000;
    220 
    221 		if ((error = copyout(&utv32, timeout, sizeof(utv32))))
    222 			return error;
    223 	}
    224 
    225 	return 0;
    226 }
    227 
    228 static int
    229 linux32_pipe(struct lwp *l, int *fd, register_t *retval, int flags)
    230 {
    231 	/* {
    232 		syscallarg(netbsd32_intp) fd;
    233 	} */
    234 	int error;
    235 	int pfds[2];
    236 
    237 	pfds[0] = (int)retval[0];
    238 	pfds[1] = (int)retval[1];
    239 
    240 	if ((error = copyout(pfds, fd, 2 * sizeof(*fd))) != 0)
    241 		return error;
    242 
    243 	if (flags & LINUX_O_CLOEXEC) {
    244 		fd_set_exclose(l, retval[0], true);
    245 		fd_set_exclose(l, retval[1], true);
    246 	}
    247 	retval[0] = 0;
    248 	retval[1] = 0;
    249 
    250 	return 0;
    251 }
    252 
    253 int
    254 linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap,
    255     register_t *retval)
    256 {
    257 	int error;
    258 	if ((error = pipe1(l, retval, 0)))
    259 		return error;
    260 	return linux32_pipe(l, SCARG_P32(uap, fd), retval, 0);
    261 }
    262 
    263 int
    264 linux32_sys_pipe2(struct lwp *l, const struct linux32_sys_pipe2_args *uap,
    265     register_t *retval)
    266 {
    267 	int flag = 0;
    268 	int error;
    269 
    270 	switch (SCARG(uap, flags)) {
    271 	case LINUX_O_CLOEXEC:
    272 		break;
    273 	case LINUX_O_NONBLOCK:
    274 	case LINUX_O_NONBLOCK|LINUX_O_CLOEXEC:
    275 		flag = O_NONBLOCK;
    276 		break;
    277 	default:
    278 		return EINVAL;
    279 	}
    280 
    281 	if ((error = pipe1(l, retval, flag)))
    282 		return error;
    283 
    284 	return linux32_pipe(l, SCARG_P32(uap, fd), retval, SCARG(uap, flags));
    285 }
    286 
    287 int
    288 linux32_sys_dup3(struct lwp *l, const struct linux32_sys_dup3_args *uap,
    289     register_t *retval)
    290 {
    291 	/* {
    292 		syscallarg(int) from;
    293 		syscallarg(int) to;
    294 		syscallarg(int) flags;
    295 	} */
    296 	struct linux_sys_dup3_args ua;
    297 
    298 	NETBSD32TO64_UAP(from);
    299 	NETBSD32TO64_UAP(to);
    300 	NETBSD32TO64_UAP(flags);
    301 
    302 	return linux_sys_dup3(l, &ua, retval);
    303 }
    304 
    305 
    306 int
    307 linux32_sys_openat(struct lwp *l, const struct linux32_sys_openat_args *uap, register_t *retval)
    308 {
    309 	/* {
    310 		syscallarg(int) fd;
    311 		syscallarg(const netbsd32_charp) path;
    312 		syscallarg(int) flags;
    313 		syscallarg(int) mode;
    314 	} */
    315 	struct linux_sys_openat_args ua;
    316 
    317 	NETBSD32TO64_UAP(fd);
    318 	NETBSD32TOP_UAP(path, const char);
    319 	NETBSD32TO64_UAP(flags);
    320 	NETBSD32TO64_UAP(mode);
    321 
    322 	return linux_sys_openat(l, &ua, retval);
    323 }
    324 
    325 int
    326 linux32_sys_mknodat(struct lwp *l, const struct linux32_sys_mknodat_args *uap, register_t *retval)
    327 {
    328 	/* {
    329 		syscallarg(int) fd;
    330 		syscallarg(const netbsd32_charp) path;
    331 		syscallarg(linux_umode_t) mode;
    332 		syscallarg(unsigned) dev;
    333 	} */
    334 	struct linux_sys_mknodat_args ua;
    335 
    336 	NETBSD32TO64_UAP(fd);
    337 	NETBSD32TOP_UAP(path, const char);
    338 	NETBSD32TO64_UAP(mode);
    339 	NETBSD32TO64_UAP(dev);
    340 
    341 	return linux_sys_mknodat(l, &ua, retval);
    342 }
    343 
    344 int
    345 linux32_sys_linkat(struct lwp *l, const struct linux32_sys_linkat_args *uap, register_t *retval)
    346 {
    347 	/* {
    348 		syscallarg(int) fd1;
    349 		syscallarg(netbsd32_charp) name1;
    350 		syscallarg(int) fd2;
    351 		syscallarg(netbsd32_charp) name2;
    352 		syscallarg(int) flags;
    353 	} */
    354 	int fd1 = SCARG(uap, fd1);
    355 	const char *name1 = SCARG_P32(uap, name1);
    356 	int fd2 = SCARG(uap, fd2);
    357 	const char *name2 = SCARG_P32(uap, name2);
    358 	int follow;
    359 
    360 	follow = SCARG(uap, flags) & LINUX_AT_SYMLINK_FOLLOW;
    361 
    362 	return do_sys_linkat(l, fd1, name1, fd2, name2, follow, retval);
    363 }
    364 
    365 int
    366 linux32_sys_unlink(struct lwp *l, const struct linux32_sys_unlink_args *uap, register_t *retval)
    367 {
    368 	/* {
    369 		syscallarg(const netbsd32_charp) path;
    370 	} */
    371 	struct linux_sys_unlink_args ua;
    372 
    373 	NETBSD32TOP_UAP(path, const char);
    374 
    375 	return linux_sys_unlink(l, &ua, retval);
    376 }
    377 
    378 int
    379 linux32_sys_unlinkat(struct lwp *l, const struct linux32_sys_unlinkat_args *uap, register_t *retval)
    380 {
    381 	/* {
    382 		syscallarg(int) fd;
    383 		syscallarg(const netbsd32_charp) path;
    384 		syscallarg(int) flag;
    385 	} */
    386 	struct linux_sys_unlinkat_args ua;
    387 
    388 	NETBSD32TO64_UAP(fd);
    389 	NETBSD32TOP_UAP(path, const char);
    390 	NETBSD32TO64_UAP(flag);
    391 
    392 	return linux_sys_unlinkat(l, &ua, retval);
    393 }
    394 
    395 int
    396 linux32_sys_fchmodat(struct lwp *l, const struct linux32_sys_fchmodat_args *uap, register_t *retval)
    397 {
    398 	/* {
    399 		syscallarg(int) fd;
    400 		syscallarg(netbsd_charp) path;
    401 		syscallarg(linux_umode_t) mode;
    402 	} */
    403 
    404 	return do_sys_chmodat(l, SCARG(uap, fd), SCARG_P32(uap, path),
    405 			      SCARG(uap, mode), AT_SYMLINK_FOLLOW);
    406 }
    407 
    408 int
    409 linux32_sys_fchownat(struct lwp *l, const struct linux32_sys_fchownat_args *uap, register_t *retval)
    410 {
    411 	/* {
    412 		syscallarg(int) fd;
    413 		syscallarg(netbsd_charp) path;
    414 		syscallarg(uid_t) owner;
    415 		syscallarg(gid_t) group;
    416 		syscallarg(int) flag;
    417 	} */
    418 	int flag;
    419 
    420 	flag = linux_to_bsd_atflags(SCARG(uap, flag));
    421 	return do_sys_chownat(l, SCARG(uap, fd), SCARG_P32(uap, path),
    422 			      SCARG(uap, owner), SCARG(uap, group), flag);
    423 }
    424 
    425 int
    426 linux32_sys_faccessat(struct lwp *l, const struct linux32_sys_faccessat_args *uap, register_t *retval)
    427 {
    428 	/* {
    429 		syscallarg(int) fd;
    430 		syscallarg(netbsd_charp) path;
    431 		syscallarg(int) amode;
    432 	} */
    433 
    434 	return do_sys_accessat(l, SCARG(uap, fd), SCARG_P32(uap, path),
    435 	     SCARG(uap, amode), AT_SYMLINK_FOLLOW);
    436 }
    437 
    438 int
    439 linux32_sys_utimensat(struct lwp *l, const struct linux32_sys_utimensat_args *uap, register_t *retval)
    440 {
    441 	/* {
    442 		syscallarg(int) fd;
    443 		syscallarg(const netbsd32_charp) path;
    444 		syscallarg(const linux32_timespecp_t) times;
    445 		syscallarg(int) flags;
    446 	} */
    447 	int error;
    448 	struct linux32_timespec lts[2];
    449 	struct timespec *tsp = NULL, ts[2];
    450 
    451 	if (SCARG_P32(uap, times)) {
    452 		error = copyin(SCARG_P32(uap, times), &lts, sizeof(lts));
    453 		if (error != 0)
    454 			return error;
    455 		linux32_to_native_timespec(&ts[0], &lts[0]);
    456 		linux32_to_native_timespec(&ts[1], &lts[1]);
    457 		tsp = ts;
    458 	}
    459 
    460 	return linux_do_sys_utimensat(l, SCARG(uap, fd), SCARG_P32(uap, path),
    461 	    tsp, SCARG(uap, flag), retval);
    462 }
    463 
    464 int
    465 linux32_sys_creat(struct lwp *l, const struct linux32_sys_creat_args *uap, register_t *retval)
    466 {
    467 	/* {
    468 		syscallarg(const netbsd32_charp) path;
    469 		syscallarg(int) mode;
    470 	} */
    471 	struct sys_open_args ua;
    472 
    473 	NETBSD32TOP_UAP(path, const char);
    474 	SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    475 	NETBSD32TO64_UAP(mode);
    476 
    477 	return sys_open(l, &ua, retval);
    478 }
    479 
    480 int
    481 linux32_sys_mknod(struct lwp *l, const struct linux32_sys_mknod_args *uap, register_t *retval)
    482 {
    483 	/* {
    484 		syscallarg(const netbsd32_charp) path;
    485 		syscallarg(int) mode;
    486 		syscallarg(int) dev;
    487 	} */
    488 	struct linux_sys_mknod_args ua;
    489 
    490 	NETBSD32TOP_UAP(path, const char);
    491 	NETBSD32TO64_UAP(mode);
    492 	NETBSD32TO64_UAP(dev);
    493 
    494 	return linux_sys_mknod(l, &ua, retval);
    495 }
    496 
    497 int
    498 linux32_sys_break(struct lwp *l, const struct linux32_sys_break_args *uap, register_t *retval)
    499 {
    500 #if 0
    501 	/* {
    502 		syscallarg(const netbsd32_charp) nsize;
    503 	} */
    504 #endif
    505 
    506 	return ENOSYS;
    507 }
    508 
    509 int
    510 linux32_sys_swapon(struct lwp *l, const struct linux32_sys_swapon_args *uap, register_t *retval)
    511 {
    512 	/* {
    513 		syscallarg(const netbsd32_charp) name;
    514 	} */
    515 	struct sys_swapctl_args ua;
    516 
    517         SCARG(&ua, cmd) = SWAP_ON;
    518         SCARG(&ua, arg) = SCARG_P32(uap, name);
    519         SCARG(&ua, misc) = 0;   /* priority */
    520         return (sys_swapctl(l, &ua, retval));
    521 }
    522 
    523 int
    524 linux32_sys_swapoff(struct lwp *l, const struct linux32_sys_swapoff_args *uap, register_t *retval)
    525 {
    526 	/* {
    527 		syscallarg(const netbsd32_charp) path;
    528 	} */
    529 	struct sys_swapctl_args ua;
    530 
    531         SCARG(&ua, cmd) = SWAP_OFF;
    532         SCARG(&ua, arg) = SCARG_P32(uap, path);
    533         SCARG(&ua, misc) = 0;   /* priority */
    534         return (sys_swapctl(l, &ua, retval));
    535 }
    536 
    537 
    538 int
    539 linux32_sys_reboot(struct lwp *l, const struct linux32_sys_reboot_args *uap, register_t *retval)
    540 {
    541 	/* {
    542 		syscallarg(int) magic1;
    543 		syscallarg(int) magic2;
    544 		syscallarg(int) cmd;
    545 		syscallarg(netbsd32_voidp) arg;
    546 	} */
    547 	struct linux_sys_reboot_args ua;
    548 
    549 	NETBSD32TO64_UAP(magic1);
    550 	NETBSD32TO64_UAP(magic2);
    551 	NETBSD32TO64_UAP(cmd);
    552 	NETBSD32TOP_UAP(arg, void);
    553 
    554 	return linux_sys_reboot(l, &ua, retval);
    555 }
    556 
    557 int
    558 linux32_sys_setresuid(struct lwp *l, const struct linux32_sys_setresuid_args *uap, register_t *retval)
    559 {
    560 	/* {
    561 		syscallarg(uid_t) ruid;
    562 		syscallarg(uid_t) euid;
    563 		syscallarg(uid_t) suid;
    564 	} */
    565 	struct linux_sys_setresuid_args ua;
    566 
    567 	NETBSD32TO64_UAP(ruid);
    568 	NETBSD32TO64_UAP(euid);
    569 	NETBSD32TO64_UAP(suid);
    570 
    571 	return linux_sys_setresuid(l, &ua, retval);
    572 }
    573 
    574 int
    575 linux32_sys_getresuid(struct lwp *l, const struct linux32_sys_getresuid_args *uap, register_t *retval)
    576 {
    577 	/* {
    578 		syscallarg(linux32_uidp_t) ruid;
    579 		syscallarg(linux32_uidp_t) euid;
    580 		syscallarg(linux32_uidp_t) suid;
    581 	} */
    582 	kauth_cred_t pc = l->l_cred;
    583 	int error;
    584 	uid_t uid;
    585 
    586 	uid = kauth_cred_getuid(pc);
    587 	if ((error = copyout(&uid, SCARG_P32(uap, ruid), sizeof(uid_t))) != 0)
    588 		return error;
    589 
    590 	uid = kauth_cred_geteuid(pc);
    591 	if ((error = copyout(&uid, SCARG_P32(uap, euid), sizeof(uid_t))) != 0)
    592 		return error;
    593 
    594 	uid = kauth_cred_getsvuid(pc);
    595 	return copyout(&uid, SCARG_P32(uap, suid), sizeof(uid_t));
    596 }
    597 
    598 int
    599 linux32_sys_setresgid(struct lwp *l, const struct linux32_sys_setresgid_args *uap, register_t *retval)
    600 {
    601 	/* {
    602 		syscallarg(gid_t) rgid;
    603 		syscallarg(gid_t) egid;
    604 		syscallarg(gid_t) sgid;
    605 	} */
    606 	struct linux_sys_setresgid_args ua;
    607 
    608 	NETBSD32TO64_UAP(rgid);
    609 	NETBSD32TO64_UAP(egid);
    610 	NETBSD32TO64_UAP(sgid);
    611 
    612 	return linux_sys_setresgid(l, &ua, retval);
    613 }
    614 
    615 int
    616 linux32_sys_getresgid(struct lwp *l, const struct linux32_sys_getresgid_args *uap, register_t *retval)
    617 {
    618 	/* {
    619 		syscallarg(linux32_gidp_t) rgid;
    620 		syscallarg(linux32_gidp_t) egid;
    621 		syscallarg(linux32_gidp_t) sgid;
    622 	} */
    623 	kauth_cred_t pc = l->l_cred;
    624 	int error;
    625 	gid_t gid;
    626 
    627 	gid = kauth_cred_getgid(pc);
    628 	if ((error = copyout(&gid, SCARG_P32(uap, rgid), sizeof(gid_t))) != 0)
    629 		return error;
    630 
    631 	gid = kauth_cred_getegid(pc);
    632 	if ((error = copyout(&gid, SCARG_P32(uap, egid), sizeof(gid_t))) != 0)
    633 		return error;
    634 
    635 	gid = kauth_cred_getsvgid(pc);
    636 	return copyout(&gid, SCARG_P32(uap, sgid), sizeof(gid_t));
    637 }
    638 
    639 int
    640 linux32_sys_nice(struct lwp *l, const struct linux32_sys_nice_args *uap, register_t *retval)
    641 {
    642 	/* {
    643 		syscallarg(int) incr;
    644 	} */
    645 	struct proc *p = l->l_proc;
    646 	struct sys_setpriority_args bsa;
    647 	int error;
    648 
    649 	SCARG(&bsa, which) = PRIO_PROCESS;
    650 	SCARG(&bsa, who) = 0;
    651 	SCARG(&bsa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
    652 
    653 	error = sys_setpriority(l, &bsa, retval);
    654 	return (error) ? EPERM : 0;
    655 }
    656 
    657 int
    658 linux32_sys_alarm(struct lwp *l, const struct linux32_sys_alarm_args *uap, register_t *retval)
    659 {
    660 	/* {
    661 		syscallarg(unsigned int) secs;
    662 	} */
    663 	struct linux_sys_alarm_args ua;
    664 
    665 	NETBSD32TO64_UAP(secs);
    666 
    667 	return linux_sys_alarm(l, &ua, retval);
    668 }
    669 
    670 int
    671 linux32_sys_fdatasync(struct lwp *l, const struct linux32_sys_fdatasync_args *uap, register_t *retval)
    672 {
    673 	/* {
    674 		syscallarg(int) fd;
    675 	} */
    676 	struct linux_sys_fdatasync_args ua;
    677 
    678 	NETBSD32TO64_UAP(fd);
    679 
    680 	return linux_sys_fdatasync(l, &ua, retval);
    681 }
    682 
    683 int
    684 linux32_sys_setfsuid(struct lwp *l, const struct linux32_sys_setfsuid_args *uap, register_t *retval)
    685 {
    686 	/* {
    687 		syscallarg(uid_t) uid;
    688 	} */
    689 	struct linux_sys_setfsuid_args ua;
    690 
    691 	NETBSD32TO64_UAP(uid);
    692 
    693 	return linux_sys_setfsuid(l, &ua, retval);
    694 }
    695 
    696 int
    697 linux32_sys_setfsgid(struct lwp *l, const struct linux32_sys_setfsgid_args *uap, register_t *retval)
    698 {
    699 	/* {
    700 		syscallarg(gid_t) gid;
    701 	} */
    702 	struct linux_sys_setfsgid_args ua;
    703 
    704 	NETBSD32TO64_UAP(gid);
    705 
    706 	return linux_sys_setfsgid(l, &ua, retval);
    707 }
    708 
    709 /*
    710  * pread(2).
    711  */
    712 int
    713 linux32_sys_pread(struct lwp *l,
    714     const struct linux32_sys_pread_args *uap, register_t *retval)
    715 {
    716 	/* {
    717 		syscallarg(int) fd;
    718 		syscallarg(netbsd32_voidp) buf;
    719 		syscallarg(netbsd32_size_t) nbyte;
    720 		syscallarg(netbsd32_off_t) offset;
    721 	} */
    722 	struct sys_pread_args pra;
    723 
    724 	SCARG(&pra, fd) = SCARG(uap, fd);
    725 	SCARG(&pra, buf) = SCARG_P32(uap, buf);
    726 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    727 	SCARG(&pra, PAD) = 0;
    728 	SCARG(&pra, offset) = SCARG(uap, offset);
    729 
    730 	return sys_pread(l, &pra, retval);
    731 }
    732 
    733 /*
    734  * pwrite(2).
    735  */
    736 int
    737 linux32_sys_pwrite(struct lwp *l,
    738     const struct linux32_sys_pwrite_args *uap, register_t *retval)
    739 {
    740 	/* {
    741 		syscallarg(int) fd;
    742 		syscallarg(const netbsd32_voidp) buf;
    743 		syscallarg(netbsd32_size_t) nbyte;
    744 		syscallarg(netbsd32_off_t) offset;
    745 	} */
    746 	struct sys_pwrite_args pra;
    747 
    748 	SCARG(&pra, fd) = SCARG(uap, fd);
    749 	SCARG(&pra, buf) = SCARG_P32(uap, buf);
    750 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    751 	SCARG(&pra, PAD) = 0;
    752 	SCARG(&pra, offset) = SCARG(uap, offset);
    753 
    754 	return sys_pwrite(l, &pra, retval);
    755 }
    756 
    757