Home | History | Annotate | Line # | Download | only in common
linux32_unistd.c revision 1.35
      1  1.35  christos /*	$NetBSD: linux32_unistd.c,v 1.35 2011/04/10 15:48:23 christos 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  christos __KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.35 2011/04/10 15:48:23 christos 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.1      manu 
     52   1.1      manu #include <machine/types.h>
     53   1.1      manu 
     54   1.1      manu #include <sys/syscallargs.h>
     55   1.1      manu 
     56   1.1      manu #include <compat/netbsd32/netbsd32.h>
     57   1.1      manu #include <compat/netbsd32/netbsd32_conv.h>
     58   1.1      manu 
     59   1.1      manu #include <compat/linux/common/linux_types.h>
     60   1.1      manu #include <compat/linux/common/linux_signal.h>
     61   1.1      manu #include <compat/linux/common/linux_machdep.h>
     62   1.1      manu #include <compat/linux/common/linux_misc.h>
     63   1.1      manu #include <compat/linux/common/linux_oldolduname.h>
     64  1.25        ad #include <compat/linux/common/linux_ipc.h>
     65  1.25        ad #include <compat/linux/common/linux_sem.h>
     66  1.35  christos #include <compat/linux/common/linux_fcntl.h>
     67   1.1      manu #include <compat/linux/linux_syscallargs.h>
     68   1.1      manu 
     69   1.1      manu #include <compat/linux32/common/linux32_types.h>
     70   1.1      manu #include <compat/linux32/common/linux32_signal.h>
     71   1.1      manu #include <compat/linux32/common/linux32_machdep.h>
     72   1.1      manu #include <compat/linux32/common/linux32_sysctl.h>
     73   1.1      manu #include <compat/linux32/common/linux32_socketcall.h>
     74   1.1      manu #include <compat/linux32/linux32_syscallargs.h>
     75   1.1      manu 
     76   1.1      manu static int linux32_select1(struct lwp *, register_t *,
     77   1.1      manu     int, fd_set *, fd_set *, fd_set *, struct timeval *);
     78   1.1      manu 
     79   1.1      manu int
     80  1.17       dsl linux32_sys_brk(struct lwp *l, const struct linux32_sys_brk_args *uap, register_t *retval)
     81   1.1      manu {
     82  1.17       dsl 	/* {
     83   1.1      manu 		syscallarg(netbsd32_charp) nsize;
     84  1.17       dsl 	} */
     85   1.1      manu 	struct linux_sys_brk_args ua;
     86   1.1      manu 
     87   1.1      manu 	NETBSD32TOP_UAP(nsize, char);
     88   1.1      manu 	return linux_sys_brk(l, &ua, retval);
     89   1.1      manu }
     90   1.1      manu 
     91   1.1      manu int
     92  1.17       dsl linux32_sys_llseek(struct lwp *l, const struct linux32_sys_llseek_args *uap, register_t *retval)
     93   1.1      manu {
     94  1.17       dsl 	/* {
     95  1.29     njoly 		syscallarg(int) fd;
     96   1.1      manu                 syscallarg(u_int32_t) ohigh;
     97   1.1      manu                 syscallarg(u_int32_t) olow;
     98  1.28     njoly 		syscallarg(netbsd32_voidp) res;
     99  1.29     njoly 		syscallarg(int) whence;
    100  1.17       dsl 	} */
    101   1.1      manu 	struct linux_sys_llseek_args ua;
    102   1.1      manu 
    103   1.1      manu 	NETBSD32TO64_UAP(fd);
    104   1.1      manu 	NETBSD32TO64_UAP(ohigh);
    105   1.1      manu 	NETBSD32TO64_UAP(olow);
    106  1.28     njoly 	NETBSD32TOP_UAP(res, void);
    107   1.1      manu 	NETBSD32TO64_UAP(whence);
    108   1.1      manu 
    109   1.1      manu 	return linux_sys_llseek(l, &ua, retval);
    110   1.1      manu }
    111   1.1      manu 
    112   1.1      manu int
    113  1.17       dsl linux32_sys_select(struct lwp *l, const struct linux32_sys_select_args *uap, register_t *retval)
    114   1.1      manu {
    115  1.17       dsl 	/* {
    116   1.1      manu 		syscallarg(int) nfds;
    117   1.1      manu 		syscallarg(netbsd32_fd_setp_t) readfds;
    118   1.1      manu 		syscallarg(netbsd32_fd_setp_t) writefds;
    119   1.1      manu 		syscallarg(netbsd32_fd_setp_t) exceptfds;
    120  1.30     njoly 		syscallarg(netbsd32_timeval50p_t) timeout;
    121  1.17       dsl 	} */
    122   1.1      manu 
    123   1.1      manu 	return linux32_select1(l, retval, SCARG(uap, nfds),
    124   1.7       dsl 	    SCARG_P32(uap, readfds),
    125   1.7       dsl 	    SCARG_P32(uap, writefds),
    126   1.7       dsl 	    SCARG_P32(uap, exceptfds),
    127   1.7       dsl 	    SCARG_P32(uap, timeout));
    128   1.1      manu }
    129   1.1      manu 
    130   1.1      manu int
    131  1.17       dsl linux32_sys_oldselect(struct lwp *l, const struct linux32_sys_oldselect_args *uap, register_t *retval)
    132   1.1      manu {
    133  1.17       dsl 	/* {
    134   1.1      manu 		syscallarg(linux32_oldselectp_t) lsp;
    135  1.17       dsl 	} */
    136   1.1      manu 	struct linux32_oldselect lsp32;
    137   1.1      manu 	int error;
    138   1.1      manu 
    139   1.7       dsl 	if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
    140   1.1      manu 		return error;
    141   1.1      manu 
    142   1.1      manu 	return linux32_select1(l, retval, lsp32.nfds,
    143   1.1      manu 	     NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
    144   1.1      manu 	     NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
    145   1.1      manu }
    146   1.1      manu 
    147   1.1      manu static int
    148  1.31    cegger linux32_select1(struct lwp *l, register_t *retval, int nfds,
    149  1.31    cegger 		fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    150  1.31    cegger 		struct timeval *timeout)
    151   1.1      manu {
    152  1.32  christos 	struct timespec ts0, ts1, uts, *ts = NULL;
    153  1.30     njoly 	struct netbsd32_timeval50 utv32;
    154   1.1      manu 	int error;
    155   1.1      manu 
    156   1.2       skd 
    157   1.1      manu 	/*
    158   1.1      manu 	 * Store current time for computation of the amount of
    159   1.1      manu 	 * time left.
    160   1.1      manu 	 */
    161   1.1      manu 	if (timeout) {
    162   1.1      manu 		if ((error = copyin(timeout, &utv32, sizeof(utv32))))
    163   1.1      manu 			return error;
    164   1.1      manu 
    165  1.32  christos 		uts.tv_sec = utv32.tv_sec;
    166  1.32  christos 		uts.tv_nsec = utv32.tv_usec * 1000;
    167   1.1      manu 
    168  1.32  christos 		if (itimespecfix(&uts)) {
    169   1.1      manu 			/*
    170   1.1      manu 			 * The timeval was invalid.  Convert it to something
    171   1.1      manu 			 * valid that will act as it does under Linux.
    172   1.1      manu 			 */
    173  1.32  christos 			uts.tv_sec += uts.tv_nsec / 1000000000;
    174  1.32  christos 			uts.tv_nsec %= 1000000000;
    175  1.32  christos 			if (uts.tv_nsec < 0) {
    176  1.32  christos 				uts.tv_sec -= 1;
    177  1.32  christos 				uts.tv_nsec += 1000000000;
    178   1.1      manu 			}
    179  1.32  christos 			if (uts.tv_sec < 0)
    180  1.32  christos 				timespecclear(&uts);
    181   1.1      manu 		}
    182  1.32  christos 		nanotime(&ts0);
    183  1.32  christos 		ts = &uts;
    184  1.32  christos 	} else
    185  1.32  christos 		timespecclear(&uts); /* XXX GCC4 */
    186   1.1      manu 
    187  1.34     rmind 	error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL);
    188   1.1      manu 
    189   1.1      manu 	if (error) {
    190   1.1      manu 		/*
    191   1.1      manu 		 * See fs/select.c in the Linux kernel.  Without this,
    192   1.1      manu 		 * Maelstrom doesn't work.
    193   1.1      manu 		 */
    194   1.1      manu 		if (error == ERESTART)
    195   1.1      manu 			error = EINTR;
    196   1.1      manu 		return error;
    197   1.1      manu 	}
    198   1.1      manu 
    199   1.1      manu 	if (timeout) {
    200   1.1      manu 		if (*retval) {
    201   1.1      manu 			/*
    202   1.1      manu 			 * Compute how much time was left of the timeout,
    203   1.1      manu 			 * by subtracting the current time and the time
    204   1.1      manu 			 * before we started the call, and subtracting
    205   1.1      manu 			 * that result from the user-supplied value.
    206   1.1      manu 			 */
    207  1.32  christos 			nanotime(&ts1);
    208  1.32  christos 			timespecsub(&ts1, &ts0, &ts1);
    209  1.32  christos 			timespecsub(&uts, &ts1, &uts);
    210  1.32  christos 			if (uts.tv_sec < 0)
    211  1.32  christos 				timespecclear(&uts);
    212   1.1      manu 		} else {
    213  1.32  christos 			timespecclear(&uts);
    214   1.1      manu 		}
    215   1.1      manu 
    216  1.32  christos 		utv32.tv_sec = uts.tv_sec;
    217  1.32  christos 		utv32.tv_usec = uts.tv_nsec / 1000;
    218   1.1      manu 
    219   1.1      manu 		if ((error = copyout(&utv32, timeout, sizeof(utv32))))
    220   1.1      manu 			return error;
    221   1.1      manu 	}
    222   1.1      manu 
    223   1.1      manu 	return 0;
    224   1.1      manu }
    225   1.1      manu 
    226  1.35  christos static int
    227  1.35  christos linux32_pipe(struct lwp *l, int *fd, register_t *retval, int flags)
    228   1.1      manu {
    229  1.17       dsl 	/* {
    230   1.1      manu 		syscallarg(netbsd32_intp) fd;
    231  1.17       dsl 	} */
    232   1.1      manu 	int error;
    233   1.1      manu 	int pfds[2];
    234   1.1      manu 
    235   1.1      manu 	pfds[0] = (int)retval[0];
    236   1.1      manu 	pfds[1] = (int)retval[1];
    237   1.1      manu 
    238  1.35  christos 	if ((error = copyout(pfds, fd, 2 * sizeof(*fd))) != 0)
    239   1.1      manu 		return error;
    240   1.1      manu 
    241  1.35  christos 	if (flags & LINUX_O_CLOEXEC) {
    242  1.35  christos 		fd_set_exclose(l, retval[0], true);
    243  1.35  christos 		fd_set_exclose(l, retval[1], true);
    244  1.35  christos 	}
    245   1.1      manu 	retval[0] = 0;
    246   1.1      manu 	retval[1] = 0;
    247   1.1      manu 
    248   1.1      manu 	return 0;
    249   1.1      manu }
    250   1.1      manu 
    251  1.35  christos int
    252  1.35  christos linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap,
    253  1.35  christos     register_t *retval)
    254  1.35  christos {
    255  1.35  christos 	int error;
    256  1.35  christos 	if ((error = pipe1(l, retval, 0)))
    257  1.35  christos 		return error;
    258  1.35  christos 	return linux32_pipe(l, SCARG_P32(uap, fd), retval, 0);
    259  1.35  christos }
    260  1.35  christos 
    261  1.35  christos int
    262  1.35  christos linux32_sys_pipe2(struct lwp *l, const struct linux32_sys_pipe2_args *uap,
    263  1.35  christos     register_t *retval)
    264  1.35  christos {
    265  1.35  christos 	int flag = 0;
    266  1.35  christos 	int error;
    267  1.35  christos 
    268  1.35  christos 	switch (SCARG(uap, flags)) {
    269  1.35  christos 	case LINUX_O_CLOEXEC:
    270  1.35  christos 		break;
    271  1.35  christos 	case LINUX_O_NONBLOCK:
    272  1.35  christos 	case LINUX_O_NONBLOCK|LINUX_O_CLOEXEC:
    273  1.35  christos 		flag = O_NONBLOCK;
    274  1.35  christos 		break;
    275  1.35  christos 	default:
    276  1.35  christos 		return EINVAL;
    277  1.35  christos 	}
    278  1.35  christos 
    279  1.35  christos 	if ((error = pipe1(l, retval, flag)))
    280  1.35  christos 		return error;
    281  1.35  christos 
    282  1.35  christos 	return linux32_pipe(l, SCARG_P32(uap, fd), retval, SCARG(uap, flags));
    283  1.35  christos }
    284  1.35  christos 
    285  1.35  christos int
    286  1.35  christos linux32_sys_dup3(struct lwp *l, const struct linux32_sys_dup3_args *uap,
    287  1.35  christos     register_t *retval)
    288  1.35  christos {
    289  1.35  christos 	/* {
    290  1.35  christos 		syscallarg(int) from;
    291  1.35  christos 		syscallarg(int) to;
    292  1.35  christos 		syscallarg(int) flags;
    293  1.35  christos 	} */
    294  1.35  christos 	struct sys_dup2_args ua;
    295  1.35  christos 	int error;
    296  1.35  christos 
    297  1.35  christos 	NETBSD32TO64_UAP(from);
    298  1.35  christos 	NETBSD32TO64_UAP(to);
    299  1.35  christos 
    300  1.35  christos 	if ((error = sys_dup2(l, &ua, retval)))
    301  1.35  christos 		return error;
    302  1.35  christos 
    303  1.35  christos 	if (SCARG(uap, flags) & LINUX_O_CLOEXEC)
    304  1.35  christos 		fd_set_exclose(l, SCARG(uap, to), true);
    305  1.35  christos 
    306  1.35  christos 	return 0;
    307  1.35  christos }
    308   1.1      manu 
    309   1.1      manu int
    310  1.17       dsl linux32_sys_unlink(struct lwp *l, const struct linux32_sys_unlink_args *uap, register_t *retval)
    311   1.1      manu {
    312  1.17       dsl 	/* {
    313   1.1      manu 		syscallarg(const netbsd32_charp) path;
    314  1.17       dsl 	} */
    315   1.1      manu 	struct linux_sys_unlink_args ua;
    316   1.1      manu 
    317   1.1      manu 	NETBSD32TOP_UAP(path, const char);
    318   1.1      manu 
    319   1.1      manu 	return linux_sys_unlink(l, &ua, retval);
    320   1.1      manu }
    321   1.1      manu 
    322   1.1      manu int
    323  1.17       dsl linux32_sys_creat(struct lwp *l, const struct linux32_sys_creat_args *uap, register_t *retval)
    324   1.1      manu {
    325  1.17       dsl 	/* {
    326   1.1      manu 		syscallarg(const netbsd32_charp) path;
    327   1.1      manu 		syscallarg(int) mode;
    328  1.17       dsl 	} */
    329   1.1      manu 	struct sys_open_args ua;
    330   1.1      manu 
    331   1.1      manu 	NETBSD32TOP_UAP(path, const char);
    332   1.1      manu 	SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    333   1.1      manu 	NETBSD32TO64_UAP(mode);
    334   1.1      manu 
    335   1.1      manu 	return sys_open(l, &ua, retval);
    336   1.1      manu }
    337   1.1      manu 
    338   1.1      manu int
    339  1.17       dsl linux32_sys_mknod(struct lwp *l, const struct linux32_sys_mknod_args *uap, register_t *retval)
    340   1.1      manu {
    341  1.17       dsl 	/* {
    342   1.1      manu 		syscallarg(const netbsd32_charp) path;
    343   1.1      manu 		syscallarg(int) mode;
    344   1.1      manu 		syscallarg(int) dev;
    345  1.17       dsl 	} */
    346   1.1      manu 	struct linux_sys_mknod_args ua;
    347   1.1      manu 
    348   1.1      manu 	NETBSD32TOP_UAP(path, const char);
    349   1.1      manu 	NETBSD32TO64_UAP(mode);
    350   1.1      manu 	NETBSD32TO64_UAP(dev);
    351   1.1      manu 
    352   1.1      manu 	return linux_sys_mknod(l, &ua, retval);
    353   1.1      manu }
    354   1.1      manu 
    355   1.1      manu int
    356  1.17       dsl linux32_sys_break(struct lwp *l, const struct linux32_sys_break_args *uap, register_t *retval)
    357   1.1      manu {
    358   1.1      manu #if 0
    359  1.17       dsl 	/* {
    360   1.1      manu 		syscallarg(const netbsd32_charp) nsize;
    361  1.17       dsl 	} */
    362   1.1      manu #endif
    363   1.1      manu 
    364   1.1      manu 	return ENOSYS;
    365   1.1      manu }
    366   1.1      manu 
    367   1.1      manu int
    368  1.17       dsl linux32_sys_swapon(struct lwp *l, const struct linux32_sys_swapon_args *uap, register_t *retval)
    369   1.1      manu {
    370  1.17       dsl 	/* {
    371   1.1      manu 		syscallarg(const netbsd32_charp) name;
    372  1.17       dsl 	} */
    373   1.1      manu 	struct sys_swapctl_args ua;
    374   1.1      manu 
    375   1.1      manu         SCARG(&ua, cmd) = SWAP_ON;
    376   1.7       dsl         SCARG(&ua, arg) = SCARG_P32(uap, name);
    377   1.1      manu         SCARG(&ua, misc) = 0;   /* priority */
    378   1.1      manu         return (sys_swapctl(l, &ua, retval));
    379   1.1      manu }
    380   1.1      manu 
    381   1.1      manu int
    382  1.17       dsl linux32_sys_swapoff(struct lwp *l, const struct linux32_sys_swapoff_args *uap, register_t *retval)
    383   1.1      manu {
    384  1.17       dsl 	/* {
    385   1.1      manu 		syscallarg(const netbsd32_charp) path;
    386  1.17       dsl 	} */
    387   1.1      manu 	struct sys_swapctl_args ua;
    388   1.1      manu 
    389   1.1      manu         SCARG(&ua, cmd) = SWAP_OFF;
    390   1.7       dsl         SCARG(&ua, arg) = SCARG_P32(uap, path);
    391   1.1      manu         SCARG(&ua, misc) = 0;   /* priority */
    392   1.1      manu         return (sys_swapctl(l, &ua, retval));
    393   1.1      manu }
    394   1.1      manu 
    395   1.1      manu 
    396   1.1      manu int
    397  1.17       dsl linux32_sys_reboot(struct lwp *l, const struct linux32_sys_reboot_args *uap, register_t *retval)
    398   1.1      manu {
    399  1.17       dsl 	/* {
    400   1.1      manu 		syscallarg(int) magic1;
    401   1.1      manu 		syscallarg(int) magic2;
    402   1.1      manu 		syscallarg(int) cmd;
    403   1.1      manu 		syscallarg(netbsd32_voidp) arg;
    404  1.17       dsl 	} */
    405   1.1      manu 	struct linux_sys_reboot_args ua;
    406   1.1      manu 
    407   1.1      manu 	NETBSD32TO64_UAP(magic1);
    408   1.1      manu 	NETBSD32TO64_UAP(magic2);
    409   1.1      manu 	NETBSD32TO64_UAP(cmd);
    410   1.1      manu 	NETBSD32TOP_UAP(arg, void);
    411   1.1      manu 
    412   1.1      manu 	return linux_sys_reboot(l, &ua, retval);
    413   1.1      manu }
    414   1.1      manu 
    415   1.1      manu int
    416  1.17       dsl linux32_sys_setresuid(struct lwp *l, const struct linux32_sys_setresuid_args *uap, register_t *retval)
    417   1.3      manu {
    418  1.17       dsl 	/* {
    419   1.3      manu 		syscallarg(uid_t) ruid;
    420   1.3      manu 		syscallarg(uid_t) euid;
    421   1.3      manu 		syscallarg(uid_t) suid;
    422  1.17       dsl 	} */
    423   1.3      manu 	struct linux_sys_setresuid_args ua;
    424   1.3      manu 
    425  1.27     njoly 	NETBSD32TO64_UAP(ruid);
    426  1.27     njoly 	NETBSD32TO64_UAP(euid);
    427  1.27     njoly 	NETBSD32TO64_UAP(suid);
    428   1.3      manu 
    429   1.3      manu 	return linux_sys_setresuid(l, &ua, retval);
    430   1.3      manu }
    431   1.3      manu 
    432   1.3      manu int
    433  1.26     njoly linux32_sys_getresuid(struct lwp *l, const struct linux32_sys_getresuid_args *uap, register_t *retval)
    434  1.26     njoly {
    435  1.26     njoly 	/* {
    436  1.26     njoly 		syscallarg(linux32_uidp_t) ruid;
    437  1.26     njoly 		syscallarg(linux32_uidp_t) euid;
    438  1.26     njoly 		syscallarg(linux32_uidp_t) suid;
    439  1.26     njoly 	} */
    440  1.26     njoly 	kauth_cred_t pc = l->l_cred;
    441  1.26     njoly 	int error;
    442  1.26     njoly 	uid_t uid;
    443  1.26     njoly 
    444  1.26     njoly 	uid = kauth_cred_getuid(pc);
    445  1.26     njoly 	if ((error = copyout(&uid, SCARG_P32(uap, ruid), sizeof(uid_t))) != 0)
    446  1.26     njoly 		return error;
    447  1.26     njoly 
    448  1.26     njoly 	uid = kauth_cred_geteuid(pc);
    449  1.26     njoly 	if ((error = copyout(&uid, SCARG_P32(uap, euid), sizeof(uid_t))) != 0)
    450  1.26     njoly 		return error;
    451  1.26     njoly 
    452  1.26     njoly 	uid = kauth_cred_getsvuid(pc);
    453  1.26     njoly 	return copyout(&uid, SCARG_P32(uap, suid), sizeof(uid_t));
    454  1.26     njoly }
    455  1.26     njoly 
    456  1.26     njoly int
    457  1.17       dsl linux32_sys_setresgid(struct lwp *l, const struct linux32_sys_setresgid_args *uap, register_t *retval)
    458   1.3      manu {
    459  1.17       dsl 	/* {
    460   1.3      manu 		syscallarg(gid_t) rgid;
    461   1.3      manu 		syscallarg(gid_t) egid;
    462   1.3      manu 		syscallarg(gid_t) sgid;
    463  1.17       dsl 	} */
    464   1.3      manu 	struct linux_sys_setresgid_args ua;
    465   1.3      manu 
    466  1.27     njoly 	NETBSD32TO64_UAP(rgid);
    467  1.27     njoly 	NETBSD32TO64_UAP(egid);
    468  1.27     njoly 	NETBSD32TO64_UAP(sgid);
    469   1.3      manu 
    470   1.3      manu 	return linux_sys_setresgid(l, &ua, retval);
    471   1.3      manu }
    472  1.13     njoly 
    473  1.13     njoly int
    474  1.26     njoly linux32_sys_getresgid(struct lwp *l, const struct linux32_sys_getresgid_args *uap, register_t *retval)
    475  1.26     njoly {
    476  1.26     njoly 	/* {
    477  1.26     njoly 		syscallarg(linux32_gidp_t) rgid;
    478  1.26     njoly 		syscallarg(linux32_gidp_t) egid;
    479  1.26     njoly 		syscallarg(linux32_gidp_t) sgid;
    480  1.26     njoly 	} */
    481  1.26     njoly 	kauth_cred_t pc = l->l_cred;
    482  1.26     njoly 	int error;
    483  1.26     njoly 	gid_t gid;
    484  1.26     njoly 
    485  1.26     njoly 	gid = kauth_cred_getgid(pc);
    486  1.26     njoly 	if ((error = copyout(&gid, SCARG_P32(uap, rgid), sizeof(gid_t))) != 0)
    487  1.26     njoly 		return error;
    488  1.26     njoly 
    489  1.26     njoly 	gid = kauth_cred_getegid(pc);
    490  1.26     njoly 	if ((error = copyout(&gid, SCARG_P32(uap, egid), sizeof(gid_t))) != 0)
    491  1.26     njoly 		return error;
    492  1.26     njoly 
    493  1.26     njoly 	gid = kauth_cred_getsvgid(pc);
    494  1.26     njoly 	return copyout(&gid, SCARG_P32(uap, sgid), sizeof(gid_t));
    495  1.26     njoly }
    496  1.26     njoly 
    497  1.26     njoly int
    498  1.17       dsl linux32_sys_nice(struct lwp *l, const struct linux32_sys_nice_args *uap, register_t *retval)
    499  1.13     njoly {
    500  1.17       dsl 	/* {
    501  1.13     njoly 		syscallarg(int) incr;
    502  1.17       dsl 	} */
    503  1.24     njoly 	struct proc *p = l->l_proc;
    504  1.22     njoly 	struct sys_setpriority_args bsa;
    505  1.33     njoly 	int error;
    506  1.13     njoly 
    507  1.13     njoly 	SCARG(&bsa, which) = PRIO_PROCESS;
    508  1.13     njoly 	SCARG(&bsa, who) = 0;
    509  1.24     njoly 	SCARG(&bsa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
    510  1.13     njoly 
    511  1.33     njoly 	error = sys_setpriority(l, &bsa, retval);
    512  1.33     njoly 	return (error) ? EPERM : 0;
    513  1.13     njoly }
    514  1.13     njoly 
    515  1.13     njoly int
    516  1.17       dsl linux32_sys_alarm(struct lwp *l, const struct linux32_sys_alarm_args *uap, register_t *retval)
    517  1.13     njoly {
    518  1.17       dsl 	/* {
    519  1.13     njoly 		syscallarg(unsigned int) secs;
    520  1.17       dsl 	} */
    521  1.13     njoly 	struct linux_sys_alarm_args ua;
    522  1.13     njoly 
    523  1.13     njoly 	NETBSD32TO64_UAP(secs);
    524  1.13     njoly 
    525  1.13     njoly 	return linux_sys_alarm(l, &ua, retval);
    526  1.13     njoly }
    527  1.13     njoly 
    528  1.13     njoly int
    529  1.17       dsl linux32_sys_fdatasync(struct lwp *l, const struct linux32_sys_fdatasync_args *uap, register_t *retval)
    530  1.13     njoly {
    531  1.17       dsl 	/* {
    532  1.13     njoly 		syscallarg(int) fd;
    533  1.17       dsl 	} */
    534  1.13     njoly 	struct linux_sys_fdatasync_args ua;
    535  1.13     njoly 
    536  1.13     njoly 	NETBSD32TO64_UAP(fd);
    537  1.13     njoly 
    538  1.13     njoly 	return linux_sys_fdatasync(l, &ua, retval);
    539  1.13     njoly }
    540  1.13     njoly 
    541  1.13     njoly int
    542  1.17       dsl linux32_sys_setfsuid(struct lwp *l, const struct linux32_sys_setfsuid_args *uap, register_t *retval)
    543  1.13     njoly {
    544  1.17       dsl 	/* {
    545  1.13     njoly 		syscallarg(uid_t) uid;
    546  1.17       dsl 	} */
    547  1.13     njoly 	struct linux_sys_setfsuid_args ua;
    548  1.13     njoly 
    549  1.13     njoly 	NETBSD32TO64_UAP(uid);
    550  1.13     njoly 
    551  1.13     njoly 	return linux_sys_setfsuid(l, &ua, retval);
    552  1.13     njoly }
    553  1.13     njoly 
    554  1.13     njoly int
    555  1.18     njoly linux32_sys_setfsgid(struct lwp *l, const struct linux32_sys_setfsgid_args *uap, register_t *retval)
    556  1.18     njoly {
    557  1.18     njoly 	/* {
    558  1.18     njoly 		syscallarg(gid_t) gid;
    559  1.18     njoly 	} */
    560  1.18     njoly 	struct linux_sys_setfsgid_args ua;
    561  1.18     njoly 
    562  1.18     njoly 	NETBSD32TO64_UAP(gid);
    563  1.18     njoly 
    564  1.18     njoly 	return linux_sys_setfsgid(l, &ua, retval);
    565  1.18     njoly }
    566  1.20       dsl 
    567  1.20       dsl /*
    568  1.20       dsl  * pread(2).
    569  1.20       dsl  */
    570  1.20       dsl int
    571  1.20       dsl linux32_sys_pread(struct lwp *l,
    572  1.20       dsl     const struct linux32_sys_pread_args *uap, register_t *retval)
    573  1.20       dsl {
    574  1.20       dsl 	/* {
    575  1.20       dsl 		syscallarg(int) fd;
    576  1.21     njoly 		syscallarg(netbsd32_voidp) buf;
    577  1.20       dsl 		syscallarg(netbsd32_size_t) nbyte;
    578  1.21     njoly 		syscallarg(linux32_off_t) offset;
    579  1.20       dsl 	} */
    580  1.20       dsl 	struct sys_pread_args pra;
    581  1.20       dsl 
    582  1.20       dsl 	SCARG(&pra, fd) = SCARG(uap, fd);
    583  1.21     njoly 	SCARG(&pra, buf) = SCARG_P32(uap, buf);
    584  1.20       dsl 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    585  1.20       dsl 	SCARG(&pra, offset) = SCARG(uap, offset);
    586  1.20       dsl 
    587  1.20       dsl 	return sys_pread(l, &pra, retval);
    588  1.20       dsl }
    589  1.20       dsl 
    590  1.20       dsl /*
    591  1.20       dsl  * pwrite(2).
    592  1.20       dsl  */
    593  1.20       dsl int
    594  1.20       dsl linux32_sys_pwrite(struct lwp *l,
    595  1.20       dsl     const struct linux32_sys_pwrite_args *uap, register_t *retval)
    596  1.20       dsl {
    597  1.20       dsl 	/* {
    598  1.20       dsl 		syscallarg(int) fd;
    599  1.21     njoly 		syscallarg(const netbsd32_voidp) buf;
    600  1.20       dsl 		syscallarg(netbsd32_size_t) nbyte;
    601  1.21     njoly 		syscallarg(linux32_off_t) offset;
    602  1.20       dsl 	} */
    603  1.20       dsl 	struct sys_pwrite_args pra;
    604  1.20       dsl 
    605  1.20       dsl 	SCARG(&pra, fd) = SCARG(uap, fd);
    606  1.21     njoly 	SCARG(&pra, buf) = SCARG_P32(uap, buf);
    607  1.20       dsl 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    608  1.20       dsl 	SCARG(&pra, offset) = SCARG(uap, offset);
    609  1.20       dsl 
    610  1.20       dsl 	return sys_pwrite(l, &pra, retval);
    611  1.20       dsl }
    612  1.20       dsl 
    613