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