Home | History | Annotate | Line # | Download | only in common
linux32_unistd.c revision 1.11
      1 /*	$NetBSD: linux32_unistd.c,v 1.11 2007/10/27 09:16:24 njoly 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.11 2007/10/27 09:16:24 njoly 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 
     50 #include <machine/types.h>
     51 
     52 #include <sys/syscallargs.h>
     53 
     54 #include <compat/netbsd32/netbsd32.h>
     55 #include <compat/netbsd32/netbsd32_conv.h>
     56 #include <compat/netbsd32/netbsd32_syscallargs.h>
     57 
     58 #include <compat/linux/common/linux_types.h>
     59 #include <compat/linux/common/linux_signal.h>
     60 #include <compat/linux/common/linux_machdep.h>
     61 #include <compat/linux/common/linux_misc.h>
     62 #include <compat/linux/common/linux_oldolduname.h>
     63 #include <compat/linux/linux_syscallargs.h>
     64 
     65 #include <compat/linux32/common/linux32_types.h>
     66 #include <compat/linux32/common/linux32_signal.h>
     67 #include <compat/linux32/common/linux32_machdep.h>
     68 #include <compat/linux32/common/linux32_sysctl.h>
     69 #include <compat/linux32/common/linux32_socketcall.h>
     70 #include <compat/linux32/linux32_syscallargs.h>
     71 
     72 static int linux32_select1(struct lwp *, register_t *,
     73     int, fd_set *, fd_set *, fd_set *, struct timeval *);
     74 
     75 int
     76 linux32_sys_brk(l, v, retval)
     77 	struct lwp *l;
     78 	void *v;
     79 	register_t *retval;
     80 {
     81 	struct linux32_sys_brk_args /* {
     82 		syscallarg(netbsd32_charp) nsize;
     83 	} */ *uap = v;
     84 	struct linux_sys_brk_args ua;
     85 
     86 	NETBSD32TOP_UAP(nsize, char);
     87 	return linux_sys_brk(l, &ua, retval);
     88 }
     89 
     90 int
     91 linux32_sys_access(l, v, retval)
     92 	struct lwp *l;
     93 	void *v;
     94 	register_t *retval;
     95 {
     96 	struct linux32_sys_access_args /* {
     97 		syscallarg(const netbsd32_charp) path;
     98 		syscallarg(int) flags;
     99 	} */ *uap = v;
    100 	struct sys_access_args ua;
    101 
    102 	NETBSD32TOP_UAP(path, const char);
    103 	NETBSD32TO64_UAP(flags);
    104 
    105 	return sys_access(l, &ua, retval);
    106 }
    107 
    108 int
    109 linux32_sys_llseek(l, v, retval)
    110 	struct lwp *l;
    111 	void *v;
    112 	register_t *retval;
    113 {
    114 	struct linux32_sys_llseek_args /* {
    115 		syscallcarg(int) fd;
    116                 syscallarg(u_int32_t) ohigh;
    117                 syscallarg(u_int32_t) olow;
    118 		syscallarg(netbsd32_void *) res;
    119 		syscallcarg(int) whence;
    120 	} */ *uap = v;
    121 	struct linux_sys_llseek_args ua;
    122 
    123 	NETBSD32TO64_UAP(fd);
    124 	NETBSD32TO64_UAP(ohigh);
    125 	NETBSD32TO64_UAP(olow);
    126 	NETBSD32TOP_UAP(res, char);
    127 	NETBSD32TO64_UAP(whence);
    128 
    129 	return linux_sys_llseek(l, &ua, retval);
    130 }
    131 
    132 int
    133 linux32_sys_readlink(l, v, retval)
    134 	struct lwp *l;
    135 	void *v;
    136 	register_t *retval;
    137 {
    138 	struct linux32_sys_readlink_args /* {
    139 		syscallarg(const netbsd32_charp) name;
    140 		syscallarg(netbsd32_charp) buf;
    141 		syscallarg(int) count;
    142 	} */ *uap = v;
    143 	struct linux_sys_readlink_args ua;
    144 
    145 	NETBSD32TOP_UAP(name, const char);
    146 	NETBSD32TOP_UAP(buf, char)
    147 	NETBSD32TO64_UAP(count);
    148 
    149 	return linux_sys_readlink(l, &ua, retval);
    150 }
    151 
    152 
    153 int
    154 linux32_sys_select(l, v, retval)
    155 	struct lwp *l;
    156 	void *v;
    157 	register_t *retval;
    158 {
    159 	struct linux32_sys_select_args /* {
    160 		syscallarg(int) nfds;
    161 		syscallarg(netbsd32_fd_setp_t) readfds;
    162 		syscallarg(netbsd32_fd_setp_t) writefds;
    163 		syscallarg(netbsd32_fd_setp_t) exceptfds;
    164 		syscallarg(netbsd32_timevalp_t) timeout;
    165 	} */ *uap = v;
    166 
    167 	return linux32_select1(l, retval, SCARG(uap, nfds),
    168 	    SCARG_P32(uap, readfds),
    169 	    SCARG_P32(uap, writefds),
    170 	    SCARG_P32(uap, exceptfds),
    171 	    SCARG_P32(uap, timeout));
    172 }
    173 
    174 int
    175 linux32_sys_oldselect(l, v, retval)
    176 	struct lwp *l;
    177 	void *v;
    178 	register_t *retval;
    179 {
    180 	struct linux32_sys_oldselect_args /* {
    181 		syscallarg(linux32_oldselectp_t) lsp;
    182 	} */ *uap = v;
    183 	struct linux32_oldselect lsp32;
    184 	int error;
    185 
    186 	if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
    187 		return error;
    188 
    189 	return linux32_select1(l, retval, lsp32.nfds,
    190 	     NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
    191 	     NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
    192 }
    193 
    194 static int
    195 linux32_select1(l, retval, nfds, readfds, writefds, exceptfds, timeout)
    196         struct lwp *l;
    197         register_t *retval;
    198         int nfds;
    199         fd_set *readfds, *writefds, *exceptfds;
    200         struct timeval *timeout;
    201 {
    202 	struct timeval tv0, tv1, utv, *tv = NULL;
    203 	struct netbsd32_timeval utv32;
    204 	int error;
    205 
    206 	timerclear(&utv); /* XXX GCC4 */
    207 
    208 	/*
    209 	 * Store current time for computation of the amount of
    210 	 * time left.
    211 	 */
    212 	if (timeout) {
    213 		if ((error = copyin(timeout, &utv32, sizeof(utv32))))
    214 			return error;
    215 
    216 		netbsd32_to_timeval(&utv32, &utv);
    217 
    218 		if (itimerfix(&utv)) {
    219 			/*
    220 			 * The timeval was invalid.  Convert it to something
    221 			 * valid that will act as it does under Linux.
    222 			 */
    223 			utv.tv_sec += utv.tv_usec / 1000000;
    224 			utv.tv_usec %= 1000000;
    225 			if (utv.tv_usec < 0) {
    226 				utv.tv_sec -= 1;
    227 				utv.tv_usec += 1000000;
    228 			}
    229 			if (utv.tv_sec < 0)
    230 				timerclear(&utv);
    231 		}
    232 		microtime(&tv0);
    233 		tv = &utv;
    234 	}
    235 
    236 	error = selcommon(l, retval, nfds,
    237 	    readfds, writefds, exceptfds, tv, NULL);
    238 
    239 	if (error) {
    240 		/*
    241 		 * See fs/select.c in the Linux kernel.  Without this,
    242 		 * Maelstrom doesn't work.
    243 		 */
    244 		if (error == ERESTART)
    245 			error = EINTR;
    246 		return error;
    247 	}
    248 
    249 	if (timeout) {
    250 		if (*retval) {
    251 			/*
    252 			 * Compute how much time was left of the timeout,
    253 			 * by subtracting the current time and the time
    254 			 * before we started the call, and subtracting
    255 			 * that result from the user-supplied value.
    256 			 */
    257 			microtime(&tv1);
    258 			timersub(&tv1, &tv0, &tv1);
    259 			timersub(&utv, &tv1, &utv);
    260 			if (utv.tv_sec < 0)
    261 				timerclear(&utv);
    262 		} else {
    263 			timerclear(&utv);
    264 		}
    265 
    266 		netbsd32_from_timeval(&utv, &utv32);
    267 
    268 		if ((error = copyout(&utv32, timeout, sizeof(utv32))))
    269 			return error;
    270 	}
    271 
    272 	return 0;
    273 }
    274 
    275 int
    276 linux32_sys_pipe(l, v, retval)
    277 	struct lwp *l;
    278 	void *v;
    279 	register_t *retval;
    280 {
    281 	struct linux32_sys_pipe_args /* {
    282 		syscallarg(netbsd32_intp) fd;
    283 	} */ *uap = v;
    284 	int error;
    285 	int pfds[2];
    286 
    287 	if ((error = sys_pipe(l, 0, retval)))
    288 		return error;
    289 
    290 	pfds[0] = (int)retval[0];
    291 	pfds[1] = (int)retval[1];
    292 
    293 	if ((error = copyout(pfds, SCARG_P32(uap, fd), 2 * sizeof (int))) != 0)
    294 		return error;
    295 
    296 	retval[0] = 0;
    297 	retval[1] = 0;
    298 
    299 	return 0;
    300 }
    301 
    302 
    303 int
    304 linux32_sys_unlink(l, v, retval)
    305 	struct lwp *l;
    306 	void *v;
    307 	register_t *retval;
    308 {
    309 	struct linux32_sys_unlink_args /* {
    310 		syscallarg(const netbsd32_charp) path;
    311 	} */ *uap = v;
    312 	struct linux_sys_unlink_args ua;
    313 
    314 	NETBSD32TOP_UAP(path, const char);
    315 
    316 	return linux_sys_unlink(l, &ua, retval);
    317 }
    318 
    319 int
    320 linux32_sys_chdir(l, v, retval)
    321 	struct lwp *l;
    322 	void *v;
    323 	register_t *retval;
    324 {
    325 	struct linux32_sys_chdir_args /* {
    326 		syscallarg(const netbsd32_charp) path;
    327 	} */ *uap = v;
    328 	struct sys_chdir_args ua;
    329 
    330 	NETBSD32TOP_UAP(path, const char);
    331 
    332 	return sys_chdir(l, &ua, retval);
    333 }
    334 
    335 int
    336 linux32_sys_link(l, v, retval)
    337 	struct lwp *l;
    338 	void *v;
    339 	register_t *retval;
    340 {
    341 	struct linux32_sys_link_args /* {
    342 		syscallarg(const netbsd32_charp) path;
    343 		syscallarg(const netbsd32_charp) link;
    344 	} */ *uap = v;
    345 	struct sys_link_args ua;
    346 
    347 	NETBSD32TOP_UAP(path, const char);
    348 	NETBSD32TOP_UAP(link, const char);
    349 
    350 	return sys_link(l, &ua, retval);
    351 }
    352 
    353 int
    354 linux32_sys_creat(l, v, retval)
    355 	struct lwp *l;
    356 	void *v;
    357 	register_t *retval;
    358 {
    359 	struct linux32_sys_creat_args /* {
    360 		syscallarg(const netbsd32_charp) path;
    361 		syscallarg(int) mode;
    362 	} */ *uap = v;
    363 	struct sys_open_args ua;
    364 
    365 	NETBSD32TOP_UAP(path, const char);
    366 	SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    367 	NETBSD32TO64_UAP(mode);
    368 
    369 	return sys_open(l, &ua, retval);
    370 }
    371 
    372 int
    373 linux32_sys_mknod(l, v, retval)
    374 	struct lwp *l;
    375 	void *v;
    376 	register_t *retval;
    377 {
    378 	struct linux32_sys_mknod_args /* {
    379 		syscallarg(const netbsd32_charp) path;
    380 		syscallarg(int) mode;
    381 		syscallarg(int) dev;
    382 	} */ *uap = v;
    383 	struct linux_sys_mknod_args ua;
    384 
    385 	NETBSD32TOP_UAP(path, const char);
    386 	NETBSD32TO64_UAP(mode);
    387 	NETBSD32TO64_UAP(dev);
    388 
    389 	return linux_sys_mknod(l, &ua, retval);
    390 }
    391 
    392 int
    393 linux32_sys_chmod(l, v, retval)
    394 	struct lwp *l;
    395 	void *v;
    396 	register_t *retval;
    397 {
    398 	struct linux32_sys_chmod_args /* {
    399 		syscallarg(const netbsd32_charp) path;
    400 		syscallarg(int) mode;
    401 	} */ *uap = v;
    402 	struct sys_chmod_args ua;
    403 
    404 	NETBSD32TOP_UAP(path, const char);
    405 	NETBSD32TO64_UAP(mode);
    406 
    407 	return sys_chmod(l, &ua, retval);
    408 }
    409 
    410 int
    411 linux32_sys_chown16(l, v, retval)
    412 	struct lwp *l;
    413 	void *v;
    414 	register_t *retval;
    415 {
    416 	struct linux32_sys_chown16_args /* {
    417 		syscallarg(const netbsd32_charp) path;
    418 		syscallarg(int) uid;
    419 		syscallarg(int) gid;
    420 	} */ *uap = v;
    421         struct sys___posix_chown_args ua;
    422 
    423 	NETBSD32TOP_UAP(path, const char);
    424 
    425         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
    426         	SCARG(&ua, uid) = (uid_t)-1;
    427 	else
    428         	SCARG(&ua, uid) = SCARG(uap, uid);
    429 
    430         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
    431         	SCARG(&ua, gid) = (gid_t)-1;
    432 	else
    433         	SCARG(&ua, gid) = SCARG(uap, gid);
    434 
    435         return sys___posix_chown(l, &ua, retval);
    436 }
    437 
    438 int
    439 linux32_sys_lchown16(l, v, retval)
    440 	struct lwp *l;
    441 	void *v;
    442 	register_t *retval;
    443 {
    444 	struct linux32_sys_lchown16_args /* {
    445 		syscallarg(const netbsd32_charp) path;
    446 		syscallarg(int) uid;
    447 		syscallarg(int) gid;
    448 	} */ *uap = v;
    449         struct sys___posix_lchown_args ua;
    450 
    451 	NETBSD32TOP_UAP(path, const char);
    452 
    453         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
    454         	SCARG(&ua, uid) = (uid_t)-1;
    455 	else
    456         	SCARG(&ua, uid) = SCARG(uap, uid);
    457 
    458         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
    459         	SCARG(&ua, gid) = (gid_t)-1;
    460 	else
    461         	SCARG(&ua, gid) = SCARG(uap, gid);
    462 
    463         return sys___posix_lchown(l, &ua, retval);
    464 }
    465 
    466 int
    467 linux32_sys_break(l, v, retval)
    468 	struct lwp *l;
    469 	void *v;
    470 	register_t *retval;
    471 {
    472 #if 0
    473 	struct linux32_sys_break_args /* {
    474 		syscallarg(const netbsd32_charp) nsize;
    475 	} */ *uap = v;
    476 #endif
    477 
    478 	return ENOSYS;
    479 }
    480 
    481 int
    482 linux32_sys_rename(l, v, retval)
    483 	struct lwp *l;
    484 	void *v;
    485 	register_t *retval;
    486 {
    487 	struct linux32_sys_rename_args /* {
    488 		syscallarg(const netbsd32_charp) from;
    489 		syscallarg(const netbsd32_charp) to;
    490 	} */ *uap = v;
    491 	struct sys_rename_args ua;
    492 
    493 	NETBSD32TOP_UAP(from, const char);
    494 	NETBSD32TOP_UAP(to, const char);
    495 
    496 	return sys___posix_rename(l, &ua, retval);
    497 }
    498 
    499 int
    500 linux32_sys_mkdir(l, v, retval)
    501 	struct lwp *l;
    502 	void *v;
    503 	register_t *retval;
    504 {
    505 	struct linux32_sys_mkdir_args /* {
    506 		syscallarg(const netbsd32_charp) path;
    507 		syscallarg(int) mode;
    508 	} */ *uap = v;
    509 	struct sys_mkdir_args ua;
    510 
    511 	NETBSD32TOP_UAP(path, const char);
    512 	NETBSD32TO64_UAP(mode);
    513 
    514 	return sys_mkdir(l, &ua, retval);
    515 }
    516 
    517 int
    518 linux32_sys_rmdir(l, v, retval)
    519 	struct lwp *l;
    520 	void *v;
    521 	register_t *retval;
    522 {
    523 	struct linux32_sys_rmdir_args /* {
    524 		syscallarg(const netbsd32_charp) path;
    525 	} */ *uap = v;
    526 	struct sys_rmdir_args ua;
    527 
    528 	NETBSD32TOP_UAP(path, const char);
    529 
    530 	return sys_rmdir(l, &ua, retval);
    531 }
    532 
    533 int
    534 linux32_sys_getgroups16(l, v, retval)
    535 	struct lwp *l;
    536 	void *v;
    537 	register_t *retval;
    538 {
    539 	struct linux32_sys_getgroups16_args /* {
    540 		syscallarg(int) gidsetsize;
    541 		syscallarg(linux32_gidp_t) gidset;
    542 	} */ *uap = v;
    543 	struct linux_sys_getgroups16_args ua;
    544 
    545 	NETBSD32TO64_UAP(gidsetsize);
    546 	NETBSD32TOP_UAP(gidset, linux_gid_t);
    547 
    548 	return linux_sys_getgroups16(l, &ua, retval);
    549 }
    550 
    551 int
    552 linux32_sys_setgroups16(l, v, retval)
    553 	struct lwp *l;
    554 	void *v;
    555 	register_t *retval;
    556 {
    557 	struct linux32_sys_setgroups16_args /* {
    558 		syscallarg(int) gidsetsize;
    559 		syscallarg(linux32_gidp_t) gidset;
    560 	} */ *uap = v;
    561 	struct linux_sys_setgroups16_args ua;
    562 
    563 	NETBSD32TO64_UAP(gidsetsize);
    564 	NETBSD32TOP_UAP(gidset, linux_gid_t);
    565 
    566 	return linux_sys_setgroups16(l, &ua, retval);
    567 }
    568 
    569 int
    570 linux32_sys_symlink(l, v, retval)
    571 	struct lwp *l;
    572 	void *v;
    573 	register_t *retval;
    574 {
    575 	struct linux32_sys_symlink_args /* {
    576 		syscallarg(const netbsd32_charp) path;
    577 		syscallarg(const netbsd32_charp) link;
    578 	} */ *uap = v;
    579 	struct sys_symlink_args ua;
    580 
    581 	NETBSD32TOP_UAP(path, const char);
    582 	NETBSD32TOP_UAP(link, const char);
    583 
    584 	return sys_symlink(l, &ua, retval);
    585 }
    586 
    587 
    588 int
    589 linux32_sys_swapon(l, v, retval)
    590 	struct lwp *l;
    591 	void *v;
    592 	register_t *retval;
    593 {
    594 	struct linux32_sys_swapon_args /* {
    595 		syscallarg(const netbsd32_charp) name;
    596 	} */ *uap = v;
    597 	struct sys_swapctl_args ua;
    598 
    599         SCARG(&ua, cmd) = SWAP_ON;
    600         SCARG(&ua, arg) = SCARG_P32(uap, name);
    601         SCARG(&ua, misc) = 0;   /* priority */
    602         return (sys_swapctl(l, &ua, retval));
    603 }
    604 
    605 int
    606 linux32_sys_swapoff(l, v, retval)
    607 	struct lwp *l;
    608 	void *v;
    609 	register_t *retval;
    610 {
    611 	struct linux32_sys_swapoff_args /* {
    612 		syscallarg(const netbsd32_charp) path;
    613 	} */ *uap = v;
    614 	struct sys_swapctl_args ua;
    615 
    616         SCARG(&ua, cmd) = SWAP_OFF;
    617         SCARG(&ua, arg) = SCARG_P32(uap, path);
    618         SCARG(&ua, misc) = 0;   /* priority */
    619         return (sys_swapctl(l, &ua, retval));
    620 }
    621 
    622 
    623 int
    624 linux32_sys_reboot(l, v, retval)
    625 	struct lwp *l;
    626 	void *v;
    627 	register_t *retval;
    628 {
    629 	struct linux32_sys_reboot_args /* {
    630 		syscallarg(int) magic1;
    631 		syscallarg(int) magic2;
    632 		syscallarg(int) cmd;
    633 		syscallarg(netbsd32_voidp) arg;
    634 	} */ *uap = v;
    635 	struct linux_sys_reboot_args ua;
    636 
    637 	NETBSD32TO64_UAP(magic1);
    638 	NETBSD32TO64_UAP(magic2);
    639 	NETBSD32TO64_UAP(cmd);
    640 	NETBSD32TOP_UAP(arg, void);
    641 
    642 	return linux_sys_reboot(l, &ua, retval);
    643 }
    644 
    645 int
    646 linux32_sys_truncate(l, v, retval)
    647 	struct lwp *l;
    648 	void *v;
    649 	register_t *retval;
    650 {
    651 	struct linux32_sys_truncate_args /* {
    652 		syscallarg(const netbsd32_charp) path;
    653 		syscallarg(netbsd32_charp) buf;
    654 		syscallarg(int) count;
    655 	} */ *uap = v;
    656 	struct compat_43_sys_truncate_args ua;
    657 
    658 	NETBSD32TOP_UAP(path, const char);
    659 	NETBSD32TO64_UAP(length);
    660 
    661 	return compat_43_sys_truncate(l, &ua, retval);
    662 }
    663 
    664 int
    665 linux32_sys_fchown16(l, v, retval)
    666 	struct lwp *l;
    667 	void *v;
    668 	register_t *retval;
    669 {
    670 	struct linux32_sys_fchown16_args /* {
    671 		syscallarg(int) fd;
    672 		syscallarg(int) uid;
    673 		syscallarg(int) gid;
    674 	} */ *uap = v;
    675         struct sys___posix_fchown_args ua;
    676 
    677 	SCARG(&ua, fd) = SCARG(uap, fd);
    678 
    679         if ((linux32_uid_t)SCARG(uap, uid) == (linux32_uid_t)-1)
    680         	SCARG(&ua, uid) = (uid_t)-1;
    681 	else
    682         	SCARG(&ua, uid) = SCARG(uap, uid);
    683 
    684         if ((linux32_gid_t)SCARG(uap, gid) == (linux32_gid_t)-1)
    685         	SCARG(&ua, gid) = (gid_t)-1;
    686 	else
    687         	SCARG(&ua, gid) = SCARG(uap, gid);
    688 
    689         return sys___posix_fchown(l, &ua, retval);
    690 }
    691 
    692 int
    693 linux32_sys_setresuid(l, v, retval)
    694 	struct lwp *l;
    695 	void *v;
    696 	register_t *retval;
    697 {
    698 	struct linux32_sys_setresuid_args /* {
    699 		syscallarg(uid_t) ruid;
    700 		syscallarg(uid_t) euid;
    701 		syscallarg(uid_t) suid;
    702 	} */ *uap = v;
    703 	struct linux_sys_setresuid_args ua;
    704 
    705 	SCARG(&ua, ruid) = (SCARG(uap, ruid) == -1) ? -1 : SCARG(uap, ruid);
    706 	SCARG(&ua, euid) = (SCARG(uap, euid) == -1) ? -1 : SCARG(uap, euid);
    707 	SCARG(&ua, suid) = (SCARG(uap, suid) == -1) ? -1 : SCARG(uap, suid);
    708 
    709 	return linux_sys_setresuid(l, &ua, retval);
    710 }
    711 
    712 int
    713 linux32_sys_setresgid(l, v, retval)
    714 	struct lwp *l;
    715 	void *v;
    716 	register_t *retval;
    717 {
    718 	struct linux32_sys_setresgid_args /* {
    719 		syscallarg(gid_t) rgid;
    720 		syscallarg(gid_t) egid;
    721 		syscallarg(gid_t) sgid;
    722 	} */ *uap = v;
    723 	struct linux_sys_setresgid_args ua;
    724 
    725 	SCARG(&ua, rgid) = (SCARG(uap, rgid) == -1) ? -1 : SCARG(uap, rgid);
    726 	SCARG(&ua, egid) = (SCARG(uap, egid) == -1) ? -1 : SCARG(uap, egid);
    727 	SCARG(&ua, sgid) = (SCARG(uap, sgid) == -1) ? -1 : SCARG(uap, sgid);
    728 
    729 	return linux_sys_setresgid(l, &ua, retval);
    730 }
    731