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