Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_50.c revision 1.42
      1  1.42  pgoyette /*	$NetBSD: netbsd32_compat_50.c,v 1.42 2019/12/12 02:15:42 pgoyette Exp $	*/
      2   1.2  christos 
      3   1.2  christos /*-
      4   1.2  christos  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5   1.2  christos  * All rights reserved.
      6   1.2  christos  *
      7   1.2  christos  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2  christos  * by Christos Zoulas.
      9   1.2  christos  *
     10   1.2  christos  * Redistribution and use in source and binary forms, with or without
     11   1.2  christos  * modification, are permitted provided that the following conditions
     12   1.2  christos  * are met:
     13   1.2  christos  * 1. Redistributions of source code must retain the above copyright
     14   1.2  christos  *    notice, this list of conditions and the following disclaimer.
     15   1.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2  christos  *    notice, this list of conditions and the following disclaimer in the
     17   1.2  christos  *    documentation and/or other materials provided with the distribution.
     18   1.2  christos  * 3. All advertising materials mentioning features or use of this software
     19   1.2  christos  *    must display the following acknowledgement:
     20   1.2  christos  *        This product includes software developed by the NetBSD
     21   1.2  christos  *        Foundation, Inc. and its contributors.
     22   1.2  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.2  christos  *    contributors may be used to endorse or promote products derived
     24   1.2  christos  *    from this software without specific prior written permission.
     25   1.2  christos  *
     26   1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.2  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.2  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.2  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.2  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.2  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.2  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.2  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.2  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.2  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.2  christos  * POSSIBILITY OF SUCH DAMAGE.
     37   1.2  christos  */
     38   1.2  christos #include <sys/cdefs.h>
     39  1.42  pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.42 2019/12/12 02:15:42 pgoyette Exp $");
     40   1.2  christos 
     41   1.2  christos #if defined(_KERNEL_OPT)
     42  1.32  pgoyette #include "opt_compat_netbsd.h"
     43  1.39  christos #include "opt_compat_netbsd32.h"
     44  1.37  christos #include "opt_ntp.h"
     45  1.37  christos #include "opt_quota.h"
     46   1.8     njoly #endif
     47   1.2  christos 
     48  1.34  pgoyette 
     49   1.2  christos #include <sys/param.h>
     50   1.2  christos #include <sys/systm.h>
     51  1.34  pgoyette #include <sys/module.h>
     52   1.2  christos #include <sys/mount.h>
     53   1.2  christos #include <sys/socket.h>
     54   1.2  christos #include <sys/socketvar.h>
     55   1.2  christos #include <sys/stat.h>
     56   1.2  christos #include <sys/time.h>
     57   1.2  christos #include <sys/ktrace.h>
     58   1.2  christos #include <sys/eventvar.h>
     59   1.2  christos #include <sys/resourcevar.h>
     60   1.2  christos #include <sys/vnode.h>
     61   1.2  christos #include <sys/file.h>
     62   1.2  christos #include <sys/filedesc.h>
     63   1.2  christos #include <sys/poll.h>
     64   1.2  christos #include <sys/namei.h>
     65   1.2  christos #include <sys/statvfs.h>
     66   1.2  christos #include <sys/syscallargs.h>
     67  1.34  pgoyette #include <sys/syscallvar.h>
     68   1.2  christos #include <sys/proc.h>
     69   1.2  christos #include <sys/dirent.h>
     70   1.2  christos #include <sys/kauth.h>
     71   1.2  christos #include <sys/vfs_syscalls.h>
     72  1.34  pgoyette #include <sys/rnd.h>
     73  1.34  pgoyette #include <sys/compat_stub.h>
     74  1.34  pgoyette #include <sys/module_hook.h>
     75   1.2  christos 
     76   1.2  christos #include <compat/netbsd32/netbsd32.h>
     77  1.34  pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
     78   1.2  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     79   1.2  christos #include <compat/netbsd32/netbsd32_conv.h>
     80   1.2  christos #include <compat/sys/mount.h>
     81   1.2  christos #include <compat/sys/time.h>
     82  1.34  pgoyette #include <compat/sys/rnd.h>
     83   1.2  christos 
     84  1.32  pgoyette #if defined(COMPAT_50)
     85   1.2  christos 
     86   1.2  christos /*
     87   1.2  christos  * Common routine to set access and modification times given a vnode.
     88   1.2  christos  */
     89   1.2  christos static int
     90   1.2  christos get_utimes32(const netbsd32_timeval50p_t *tptr, struct timeval *tv,
     91   1.2  christos     struct timeval **tvp)
     92   1.2  christos {
     93   1.2  christos 	int error;
     94   1.2  christos 	struct netbsd32_timeval50 tv32[2];
     95   1.2  christos 
     96   1.2  christos 	if (tptr == NULL) {
     97   1.2  christos 		*tvp = NULL;
     98   1.2  christos 		return 0;
     99   1.2  christos 	}
    100   1.2  christos 
    101   1.2  christos 	error = copyin(tptr, tv32, sizeof(tv32));
    102   1.2  christos 	if (error)
    103   1.2  christos 		return error;
    104   1.2  christos 	netbsd32_to_timeval50(&tv32[0], &tv[0]);
    105   1.2  christos 	netbsd32_to_timeval50(&tv32[1], &tv[1]);
    106   1.2  christos 
    107   1.2  christos 	*tvp = tv;
    108   1.2  christos 	return 0;
    109   1.2  christos }
    110   1.2  christos 
    111   1.2  christos int
    112   1.2  christos compat_50_netbsd32_mknod(struct lwp *l,
    113   1.2  christos     const struct compat_50_netbsd32_mknod_args *uap, register_t *retval)
    114   1.2  christos {
    115   1.2  christos 	/* {
    116   1.2  christos 		syscallarg(netbsd32_charp) path;
    117   1.2  christos 		syscallarg(mode_t) mode;
    118   1.2  christos 		syscallarg(uint32_t) dev;
    119   1.2  christos 	} */
    120   1.2  christos 	return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
    121  1.38     kamil 	    SCARG(uap, dev), UIO_USERSPACE);
    122   1.2  christos }
    123   1.2  christos 
    124   1.2  christos int
    125   1.2  christos compat_50_netbsd32_select(struct lwp *l,
    126   1.2  christos     const struct compat_50_netbsd32_select_args *uap, register_t *retval)
    127   1.2  christos {
    128   1.2  christos 	/* {
    129   1.2  christos 		syscallarg(int) nd;
    130   1.2  christos 		syscallarg(netbsd32_fd_setp_t) in;
    131   1.2  christos 		syscallarg(netbsd32_fd_setp_t) ou;
    132   1.2  christos 		syscallarg(netbsd32_fd_setp_t) ex;
    133   1.2  christos 		syscallarg(netbsd32_timeval50p_t) tv;
    134   1.2  christos 	} */
    135   1.2  christos 	int error;
    136   1.2  christos 	struct netbsd32_timeval50 tv32;
    137   1.4  christos 	struct timespec ats, *ts = NULL;
    138   1.2  christos 
    139   1.2  christos 	if (SCARG_P32(uap, tv)) {
    140   1.2  christos 		error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
    141   1.2  christos 		if (error != 0)
    142   1.2  christos 			return error;
    143  1.40     kamil 
    144  1.40     kamil 		if (tv32.tv_usec < 0 || tv32.tv_usec >= 1000000)
    145  1.40     kamil 			return EINVAL;
    146  1.40     kamil 
    147   1.4  christos 		ats.tv_sec = tv32.tv_sec;
    148   1.4  christos 		ats.tv_nsec = tv32.tv_usec * 1000;
    149   1.4  christos 		ts = &ats;
    150   1.2  christos 	}
    151   1.2  christos 
    152   1.7     rmind 	return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
    153   1.4  christos 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL);
    154   1.2  christos }
    155   1.2  christos 
    156   1.2  christos int
    157   1.2  christos compat_50_netbsd32_gettimeofday(struct lwp *l,
    158   1.2  christos     const struct compat_50_netbsd32_gettimeofday_args *uap, register_t *retval)
    159   1.2  christos {
    160   1.2  christos 	/* {
    161   1.2  christos 		syscallarg(netbsd32_timeval50p_t) tp;
    162   1.2  christos 		syscallarg(netbsd32_timezonep_t) tzp;
    163   1.2  christos 	} */
    164   1.2  christos 	struct timeval atv;
    165   1.2  christos 	struct netbsd32_timeval50 tv32;
    166   1.2  christos 	int error = 0;
    167   1.2  christos 	struct netbsd32_timezone tzfake;
    168   1.2  christos 
    169   1.2  christos 	if (SCARG_P32(uap, tp)) {
    170   1.2  christos 		microtime(&atv);
    171   1.2  christos 		netbsd32_from_timeval50(&atv, &tv32);
    172   1.2  christos 		error = copyout(&tv32, SCARG_P32(uap, tp), sizeof(tv32));
    173   1.2  christos 		if (error)
    174   1.2  christos 			return error;
    175   1.2  christos 	}
    176   1.2  christos 	if (SCARG_P32(uap, tzp)) {
    177   1.2  christos 		/*
    178   1.2  christos 		 * NetBSD has no kernel notion of time zone, so we just
    179   1.2  christos 		 * fake up a timezone struct and return it if demanded.
    180   1.2  christos 		 */
    181   1.2  christos 		tzfake.tz_minuteswest = 0;
    182   1.2  christos 		tzfake.tz_dsttime = 0;
    183   1.2  christos 		error = copyout(&tzfake, SCARG_P32(uap, tzp), sizeof(tzfake));
    184   1.2  christos 	}
    185   1.2  christos 	return error;
    186   1.2  christos }
    187   1.2  christos 
    188   1.2  christos int
    189   1.2  christos compat_50_netbsd32_settimeofday(struct lwp *l,
    190   1.2  christos     const struct compat_50_netbsd32_settimeofday_args *uap, register_t *retval)
    191   1.2  christos {
    192   1.2  christos 	/* {
    193   1.2  christos 		syscallarg(const netbsd32_timeval50p_t) tv;
    194   1.2  christos 		syscallarg(const netbsd32_timezonep_t) tzp;
    195   1.2  christos 	} */
    196   1.2  christos 	struct netbsd32_timeval50 atv32;
    197   1.2  christos 	struct timeval atv;
    198   1.2  christos 	struct timespec ats;
    199   1.2  christos 	int error;
    200   1.2  christos 	struct proc *p = l->l_proc;
    201   1.2  christos 
    202   1.2  christos 	/* Verify all parameters before changing time. */
    203   1.2  christos 
    204   1.2  christos 	/*
    205   1.2  christos 	 * NetBSD has no kernel notion of time zone, and only an
    206   1.2  christos 	 * obsolete program would try to set it, so we log a warning.
    207   1.2  christos 	 */
    208   1.2  christos 	if (SCARG_P32(uap, tzp))
    209   1.2  christos 		printf("pid %d attempted to set the "
    210   1.2  christos 		    "(obsolete) kernel time zone\n", p->p_pid);
    211   1.2  christos 
    212   1.2  christos 	if (SCARG_P32(uap, tv) == 0)
    213   1.2  christos 		return 0;
    214   1.2  christos 
    215   1.2  christos 	if ((error = copyin(SCARG_P32(uap, tv), &atv32, sizeof(atv32))) != 0)
    216   1.2  christos 		return error;
    217   1.2  christos 
    218   1.2  christos 	netbsd32_to_timeval50(&atv32, &atv);
    219  1.41     kamil 
    220  1.41     kamil 	if (atv.tv_usec < 0 || atv.tv_usec >= 1000000)
    221  1.41     kamil 		return EINVAL;
    222  1.41     kamil 
    223   1.2  christos 	TIMEVAL_TO_TIMESPEC(&atv, &ats);
    224   1.2  christos 	return settime(p, &ats);
    225   1.2  christos }
    226   1.2  christos 
    227   1.2  christos int
    228   1.2  christos compat_50_netbsd32_utimes(struct lwp *l,
    229   1.2  christos     const struct compat_50_netbsd32_utimes_args *uap, register_t *retval)
    230   1.2  christos {
    231   1.2  christos 	/* {
    232   1.2  christos 		syscallarg(const netbsd32_charp) path;
    233   1.2  christos 		syscallarg(const netbsd32_timeval50p_t) tptr;
    234   1.2  christos 	} */
    235   1.2  christos 	int error;
    236   1.2  christos 	struct timeval tv[2], *tvp;
    237   1.2  christos 
    238   1.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    239   1.2  christos 	if (error != 0)
    240   1.2  christos 		return error;
    241   1.2  christos 
    242   1.2  christos 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
    243   1.2  christos 	    tvp, UIO_SYSSPACE);
    244   1.2  christos }
    245   1.2  christos 
    246   1.2  christos int
    247   1.2  christos compat_50_netbsd32_adjtime(struct lwp *l,
    248   1.2  christos     const struct compat_50_netbsd32_adjtime_args *uap, register_t *retval)
    249   1.2  christos {
    250   1.2  christos 	/* {
    251   1.2  christos 		syscallarg(const netbsd32_timeval50p_t) delta;
    252   1.2  christos 		syscallarg(netbsd32_timeval50p_t) olddelta;
    253   1.2  christos 	} */
    254   1.2  christos 	struct netbsd32_timeval50 atv;
    255   1.2  christos 	int error;
    256   1.2  christos 
    257   1.2  christos 	extern int time_adjusted;     /* in kern_ntptime.c */
    258   1.2  christos 	extern int64_t time_adjtime;  /* in kern_ntptime.c */
    259   1.2  christos 
    260   1.2  christos 	if ((error = kauth_authorize_system(l->l_cred,
    261   1.2  christos 	    KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL,
    262   1.2  christos 	    NULL)) != 0)
    263   1.2  christos 		return (error);
    264   1.2  christos 
    265   1.2  christos 	if (SCARG_P32(uap, olddelta)) {
    266  1.28  christos 		mutex_spin_enter(&timecounter_lock);
    267   1.2  christos 		atv.tv_sec = time_adjtime / 1000000;
    268   1.2  christos 		atv.tv_usec = time_adjtime % 1000000;
    269   1.2  christos 		if (atv.tv_usec < 0) {
    270   1.2  christos 			atv.tv_usec += 1000000;
    271   1.2  christos 			atv.tv_sec--;
    272   1.2  christos 		}
    273  1.28  christos 		mutex_spin_exit(&timecounter_lock);
    274  1.28  christos 
    275  1.28  christos 		error = copyout(&atv, SCARG_P32(uap, olddelta), sizeof(atv));
    276   1.2  christos 		if (error)
    277   1.2  christos 			return (error);
    278   1.2  christos 	}
    279   1.2  christos 
    280   1.2  christos 	if (SCARG_P32(uap, delta)) {
    281  1.28  christos 		error = copyin(SCARG_P32(uap, delta), &atv, sizeof(atv));
    282   1.2  christos 		if (error)
    283   1.2  christos 			return (error);
    284   1.2  christos 
    285  1.28  christos 		mutex_spin_enter(&timecounter_lock);
    286   1.2  christos 		time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
    287   1.2  christos 		if (time_adjtime)
    288   1.2  christos 			/* We need to save the system time during shutdown */
    289   1.2  christos 			time_adjusted |= 1;
    290  1.28  christos 		mutex_spin_exit(&timecounter_lock);
    291   1.2  christos 	}
    292   1.2  christos 
    293   1.2  christos 	return 0;
    294   1.2  christos }
    295   1.2  christos 
    296   1.2  christos int
    297   1.2  christos compat_50_netbsd32_futimes(struct lwp *l,
    298   1.2  christos     const struct compat_50_netbsd32_futimes_args *uap, register_t *retval)
    299   1.2  christos {
    300   1.2  christos 	/* {
    301   1.2  christos 		syscallarg(int) fd;
    302   1.2  christos 		syscallarg(const netbsd32_timeval50p_t) tptr;
    303   1.2  christos 	} */
    304   1.2  christos 	int error;
    305   1.2  christos 	file_t *fp;
    306   1.2  christos 	struct timeval tv[2], *tvp;
    307   1.2  christos 
    308   1.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    309   1.2  christos 	if (error != 0)
    310   1.2  christos 		return error;
    311   1.2  christos 
    312   1.2  christos 	/* fd_getvnode() will use the descriptor for us */
    313   1.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    314   1.2  christos 		return error;
    315   1.2  christos 
    316  1.27      matt 	error = do_sys_utimes(l, fp->f_vnode, NULL, 0, tvp, UIO_SYSSPACE);
    317   1.2  christos 
    318   1.2  christos 	fd_putfile(SCARG(uap, fd));
    319   1.2  christos 	return error;
    320   1.2  christos }
    321   1.2  christos 
    322   1.2  christos int
    323   1.2  christos compat_50_netbsd32_clock_gettime(struct lwp *l,
    324   1.2  christos     const struct compat_50_netbsd32_clock_gettime_args *uap, register_t *retval)
    325   1.2  christos {
    326   1.2  christos 	/* {
    327   1.2  christos 		syscallarg(netbsd32_clockid_t) clock_id;
    328   1.2  christos 		syscallarg(netbsd32_timespec50p_t) tp;
    329   1.2  christos 	} */
    330  1.15     njoly 	int error;
    331   1.2  christos 	struct timespec ats;
    332   1.2  christos 	struct netbsd32_timespec50 ts32;
    333   1.2  christos 
    334  1.15     njoly 	error = clock_gettime1(SCARG(uap, clock_id), &ats);
    335  1.15     njoly 	if (error != 0)
    336  1.15     njoly 		return error;
    337   1.2  christos 
    338   1.2  christos 	netbsd32_from_timespec50(&ats, &ts32);
    339   1.2  christos 	return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
    340   1.2  christos }
    341   1.2  christos 
    342   1.2  christos int
    343   1.2  christos compat_50_netbsd32_clock_settime(struct lwp *l,
    344   1.2  christos     const struct compat_50_netbsd32_clock_settime_args *uap, register_t *retval)
    345   1.2  christos {
    346   1.2  christos 	/* {
    347   1.2  christos 		syscallarg(netbsd32_clockid_t) clock_id;
    348   1.2  christos 		syscallarg(const netbsd32_timespec50p_t) tp;
    349   1.2  christos 	} */
    350   1.2  christos 	struct netbsd32_timespec50 ts32;
    351   1.2  christos 	struct timespec ats;
    352   1.2  christos 	int error;
    353   1.2  christos 
    354   1.2  christos 	if ((error = copyin(SCARG_P32(uap, tp), &ts32, sizeof(ts32))) != 0)
    355   1.2  christos 		return (error);
    356   1.2  christos 
    357   1.2  christos 	netbsd32_to_timespec50(&ts32, &ats);
    358  1.13     njoly 	return clock_settime1(l->l_proc, SCARG(uap, clock_id), &ats, true);
    359   1.2  christos }
    360   1.2  christos 
    361   1.2  christos int
    362   1.2  christos compat_50_netbsd32_clock_getres(struct lwp *l,
    363   1.2  christos     const struct compat_50_netbsd32_clock_getres_args *uap, register_t *retval)
    364   1.2  christos {
    365   1.2  christos 	/* {
    366   1.2  christos 		syscallarg(netbsd32_clockid_t) clock_id;
    367   1.2  christos 		syscallarg(netbsd32_timespec50p_t) tp;
    368   1.2  christos 	} */
    369   1.2  christos 	struct netbsd32_timespec50 ts32;
    370   1.2  christos 	struct timespec ts;
    371  1.30      maxv 	int error;
    372   1.2  christos 
    373  1.14     njoly 	error = clock_getres1(SCARG(uap, clock_id), &ts);
    374  1.14     njoly 	if (error != 0)
    375  1.14     njoly 		return error;
    376   1.2  christos 
    377   1.2  christos 	if (SCARG_P32(uap, tp)) {
    378   1.2  christos 		netbsd32_from_timespec50(&ts, &ts32);
    379  1.12     njoly 		error = copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
    380   1.2  christos 	}
    381   1.2  christos 
    382   1.2  christos 	return error;
    383   1.2  christos }
    384   1.2  christos 
    385   1.2  christos int
    386   1.2  christos compat_50_netbsd32_timer_settime(struct lwp *l,
    387   1.2  christos     const struct compat_50_netbsd32_timer_settime_args *uap, register_t *retval)
    388   1.2  christos {
    389   1.2  christos 	/* {
    390   1.2  christos 		syscallarg(netbsd32_timer_t) timerid;
    391   1.2  christos 		syscallarg(int) flags;
    392   1.2  christos 		syscallarg(const netbsd32_itimerspec50p_t) value;
    393   1.2  christos 		syscallarg(netbsd32_itimerspec50p_t) ovalue;
    394   1.2  christos 	} */
    395   1.2  christos 	int error;
    396   1.2  christos 	struct itimerspec value, ovalue, *ovp = NULL;
    397   1.2  christos 	struct netbsd32_itimerspec50 its32;
    398   1.2  christos 
    399   1.2  christos 	if ((error = copyin(SCARG_P32(uap, value), &its32, sizeof(its32))) != 0)
    400   1.2  christos 		return (error);
    401   1.2  christos 	netbsd32_to_timespec50(&its32.it_interval, &value.it_interval);
    402   1.2  christos 	netbsd32_to_timespec50(&its32.it_value, &value.it_value);
    403   1.2  christos 
    404   1.2  christos 	if (SCARG_P32(uap, ovalue))
    405   1.2  christos 		ovp = &ovalue;
    406   1.2  christos 
    407   1.2  christos 	if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
    408   1.2  christos 	    SCARG(uap, flags), l->l_proc)) != 0)
    409   1.2  christos 		return error;
    410   1.2  christos 
    411   1.2  christos 	if (ovp) {
    412   1.2  christos 		netbsd32_from_timespec50(&ovp->it_interval, &its32.it_interval);
    413   1.2  christos 		netbsd32_from_timespec50(&ovp->it_value, &its32.it_value);
    414   1.2  christos 		return copyout(&its32, SCARG_P32(uap, ovalue), sizeof(its32));
    415   1.2  christos 	}
    416   1.2  christos 	return 0;
    417   1.2  christos }
    418   1.2  christos 
    419   1.2  christos int
    420   1.2  christos compat_50_netbsd32_timer_gettime(struct lwp *l, const struct compat_50_netbsd32_timer_gettime_args *uap, register_t *retval)
    421   1.2  christos {
    422   1.2  christos 	/* {
    423   1.2  christos 		syscallarg(netbsd32_timer_t) timerid;
    424   1.2  christos 		syscallarg(netbsd32_itimerspec50p_t) value;
    425   1.2  christos 	} */
    426   1.2  christos 	int error;
    427   1.2  christos 	struct itimerspec its;
    428   1.2  christos 	struct netbsd32_itimerspec50 its32;
    429   1.2  christos 
    430   1.2  christos 	if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
    431   1.2  christos 	    &its)) != 0)
    432   1.2  christos 		return error;
    433   1.2  christos 
    434   1.2  christos 	netbsd32_from_timespec50(&its.it_interval, &its32.it_interval);
    435   1.2  christos 	netbsd32_from_timespec50(&its.it_value, &its32.it_value);
    436   1.2  christos 
    437   1.2  christos 	return copyout(&its32, SCARG_P32(uap, value), sizeof(its32));
    438   1.2  christos }
    439   1.2  christos 
    440   1.2  christos int
    441   1.2  christos compat_50_netbsd32_nanosleep(struct lwp *l,
    442   1.2  christos     const struct compat_50_netbsd32_nanosleep_args *uap, register_t *retval)
    443   1.2  christos {
    444   1.2  christos 	/* {
    445   1.2  christos 		syscallarg(const netbsd32_timespec50p_t) rqtp;
    446   1.2  christos 		syscallarg(netbsd32_timespecp_t) rmtp;
    447   1.2  christos 	} */
    448   1.2  christos 	struct netbsd32_timespec50 ts32;
    449  1.11     njoly 	struct timespec rqt, rmt;
    450  1.11     njoly 	int error, error1;
    451   1.2  christos 
    452   1.2  christos 	error = copyin(SCARG_P32(uap, rqtp), &ts32, sizeof(ts32));
    453   1.2  christos 	if (error)
    454   1.2  christos 		return (error);
    455   1.2  christos 	netbsd32_to_timespec50(&ts32, &rqt);
    456   1.2  christos 
    457  1.21  christos 	error = nanosleep1(l, CLOCK_MONOTONIC, 0, &rqt,
    458  1.21  christos 	    SCARG_P32(uap, rmtp) ? &rmt : NULL);
    459  1.11     njoly 	if (SCARG_P32(uap, rmtp) == NULL || (error != 0 && error != EINTR))
    460  1.11     njoly 		return error;
    461   1.2  christos 
    462  1.11     njoly 	netbsd32_from_timespec50(&rmt, &ts32);
    463  1.11     njoly 	error1 = copyout(&ts32, SCARG_P32(uap,rmtp), sizeof(ts32));
    464  1.11     njoly 	return error1 ? error1 : error;
    465   1.2  christos }
    466   1.2  christos 
    467   1.2  christos static int
    468   1.2  christos compat_50_netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
    469   1.2  christos {
    470   1.2  christos 	const siginfo_t *info = src;
    471   1.2  christos 	siginfo32_t info32;
    472   1.2  christos 
    473   1.2  christos 	netbsd32_si_to_si32(&info32, info);
    474   1.2  christos 
    475   1.2  christos 	return copyout(&info32, dst, sizeof(info32));
    476   1.2  christos }
    477   1.2  christos 
    478   1.2  christos static int
    479   1.2  christos compat_50_netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
    480   1.2  christos {
    481   1.2  christos 	struct timespec *ts = dst;
    482   1.2  christos 	struct netbsd32_timespec50 ts32;
    483   1.2  christos 	int error;
    484   1.2  christos 
    485   1.2  christos 	error = copyin(src, &ts32, sizeof(ts32));
    486   1.2  christos 	if (error)
    487   1.2  christos 		return error;
    488   1.2  christos 
    489   1.2  christos 	netbsd32_to_timespec50(&ts32, ts);
    490   1.2  christos 	return 0;
    491   1.2  christos }
    492   1.2  christos 
    493   1.2  christos static int
    494   1.2  christos compat_50_netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
    495   1.2  christos {
    496   1.2  christos 	const struct timespec *ts = src;
    497   1.2  christos 	struct netbsd32_timespec50 ts32;
    498   1.2  christos 
    499   1.2  christos 	netbsd32_from_timespec50(ts, &ts32);
    500   1.2  christos 
    501   1.2  christos 	return copyout(&ts32, dst, sizeof(ts32));
    502   1.2  christos }
    503   1.2  christos 
    504   1.2  christos int
    505   1.2  christos compat_50_netbsd32___sigtimedwait(struct lwp *l,
    506   1.2  christos     const struct compat_50_netbsd32___sigtimedwait_args *uap, register_t *retval)
    507   1.2  christos {
    508   1.2  christos 	/* {
    509   1.2  christos 		syscallarg(netbsd32_sigsetp_t) set;
    510   1.2  christos 		syscallarg(netbsd32_siginfop_t) info;
    511   1.2  christos 		syscallarg(netbsd32_timespec50p_t) timeout;
    512   1.2  christos 	} */
    513   1.2  christos 	struct sys_____sigtimedwait50_args ua;
    514  1.17  drochner 	int res;
    515   1.2  christos 
    516   1.2  christos 	NETBSD32TOP_UAP(set, const sigset_t);
    517   1.2  christos 	NETBSD32TOP_UAP(info, siginfo_t);
    518   1.2  christos 	NETBSD32TOP_UAP(timeout, struct timespec);
    519   1.2  christos 
    520  1.17  drochner 	res = sigtimedwait1(l, &ua, retval,
    521  1.20  christos 	    copyin,
    522   1.2  christos 	    compat_50_netbsd32_sigtimedwait_put_info,
    523   1.2  christos 	    compat_50_netbsd32_sigtimedwait_fetch_timeout,
    524   1.2  christos 	    compat_50_netbsd32_sigtimedwait_put_timeout);
    525  1.17  drochner 	if (!res)
    526  1.33       mrg 		*retval = 0; /* NetBSD<=5 was not POSIX compliant */
    527  1.17  drochner 	return res;
    528   1.2  christos }
    529   1.2  christos 
    530   1.2  christos int
    531   1.2  christos compat_50_netbsd32_lutimes(struct lwp *l,
    532   1.2  christos     const struct compat_50_netbsd32_lutimes_args *uap, register_t *retval)
    533   1.2  christos {
    534   1.2  christos 	/* {
    535   1.2  christos 		syscallarg(const netbsd32_charp) path;
    536   1.2  christos 		syscallarg(const netbsd32_timeval50p_t) tptr;
    537   1.2  christos 	} */
    538   1.2  christos 	int error;
    539   1.2  christos 	struct timeval tv[2], *tvp;
    540   1.2  christos 
    541   1.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    542   1.2  christos 	if (error != 0)
    543   1.2  christos 		return error;
    544   1.2  christos 
    545   1.2  christos 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
    546   1.2  christos 	    tvp, UIO_SYSSPACE);
    547   1.2  christos }
    548   1.2  christos 
    549   1.2  christos int
    550   1.2  christos compat_50_netbsd32__lwp_park(struct lwp *l,
    551   1.2  christos     const struct compat_50_netbsd32__lwp_park_args *uap, register_t *retval)
    552   1.2  christos {
    553   1.2  christos 	/* {
    554   1.2  christos 		syscallarg(const netbsd32_timespec50p) ts;
    555   1.2  christos 		syscallarg(lwpid_t) unpark;
    556   1.2  christos 		syscallarg(netbsd32_voidp) hint;
    557   1.2  christos 		syscallarg(netbsd32_voidp) unparkhint;
    558   1.2  christos 	} */
    559   1.2  christos 	struct timespec ts, *tsp;
    560   1.2  christos 	struct netbsd32_timespec50 ts32;
    561   1.2  christos 	int error;
    562   1.2  christos 
    563   1.2  christos 	if (SCARG_P32(uap, ts) == NULL)
    564   1.2  christos 		tsp = NULL;
    565   1.2  christos 	else {
    566   1.2  christos 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
    567   1.2  christos 		if (error != 0)
    568   1.2  christos 			return error;
    569   1.2  christos 		netbsd32_to_timespec50(&ts32, &ts);
    570   1.2  christos 		tsp = &ts;
    571   1.2  christos 	}
    572   1.2  christos 
    573   1.2  christos 	if (SCARG(uap, unpark) != 0) {
    574   1.2  christos 		error = lwp_unpark(SCARG(uap, unpark),
    575   1.2  christos 		    SCARG_P32(uap, unparkhint));
    576   1.2  christos 		if (error != 0)
    577   1.2  christos 			return error;
    578   1.2  christos 	}
    579   1.2  christos 
    580  1.23  christos 	return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp,
    581  1.23  christos 	    SCARG_P32(uap, hint));
    582   1.2  christos }
    583   1.2  christos 
    584   1.2  christos static int
    585   1.2  christos netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
    586   1.2  christos {
    587   1.2  christos 	struct netbsd32_timespec50 ts32;
    588   1.2  christos 	int error;
    589   1.2  christos 
    590   1.2  christos 	KASSERT(length == sizeof(struct timespec50));
    591   1.2  christos 
    592   1.2  christos 	error = copyin(src, &ts32, sizeof(ts32));
    593   1.2  christos 	if (error)
    594   1.2  christos 		return error;
    595   1.2  christos 	netbsd32_to_timespec50(&ts32, (struct timespec *)dest);
    596   1.2  christos 	return 0;
    597   1.2  christos }
    598   1.2  christos 
    599   1.2  christos static int
    600  1.26      matt netbsd32_kevent_fetch_changes(void *ctx, const struct kevent *changelist,
    601   1.2  christos     struct kevent *changes, size_t index, int n)
    602   1.2  christos {
    603   1.2  christos 	const struct netbsd32_kevent *src =
    604   1.2  christos 	    (const struct netbsd32_kevent *)changelist;
    605  1.26      matt 	struct netbsd32_kevent *kev32, *changes32 = ctx;
    606   1.2  christos 	int error, i;
    607   1.2  christos 
    608   1.2  christos 	error = copyin(src + index, changes32, n * sizeof(*changes32));
    609   1.2  christos 	if (error)
    610   1.2  christos 		return error;
    611   1.2  christos 	for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
    612   1.2  christos 		netbsd32_to_kevent(kev32, changes);
    613   1.2  christos 	return 0;
    614   1.2  christos }
    615   1.2  christos 
    616   1.2  christos static int
    617  1.26      matt netbsd32_kevent_put_events(void *ctx, struct kevent *events,
    618   1.2  christos     struct kevent *eventlist, size_t index, int n)
    619   1.2  christos {
    620  1.26      matt 	struct netbsd32_kevent *kev32, *events32 = ctx;
    621   1.2  christos 	int i;
    622   1.2  christos 
    623   1.2  christos 	for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
    624   1.2  christos 		netbsd32_from_kevent(events, kev32);
    625   1.2  christos 	kev32 = (struct netbsd32_kevent *)eventlist;
    626   1.2  christos 	return  copyout(events32, kev32, n * sizeof(*events32));
    627   1.2  christos }
    628   1.2  christos 
    629   1.2  christos int
    630   1.2  christos compat_50_netbsd32_kevent(struct lwp *l,
    631   1.2  christos     const struct compat_50_netbsd32_kevent_args *uap, register_t *retval)
    632   1.2  christos {
    633   1.2  christos 	/* {
    634   1.2  christos 		syscallarg(int) fd;
    635   1.2  christos 		syscallarg(netbsd32_keventp_t) changelist;
    636   1.2  christos 		syscallarg(netbsd32_size_t) nchanges;
    637   1.2  christos 		syscallarg(netbsd32_keventp_t) eventlist;
    638   1.2  christos 		syscallarg(netbsd32_size_t) nevents;
    639   1.2  christos 		syscallarg(netbsd32_timespec50p_t) timeout;
    640   1.2  christos 	} */
    641   1.2  christos 	int error;
    642   1.2  christos 	size_t maxalloc, nchanges, nevents;
    643   1.2  christos 	struct kevent_ops netbsd32_kevent_ops = {
    644  1.19     joerg 		.keo_fetch_timeout = netbsd32_kevent_fetch_timeout,
    645  1.19     joerg 		.keo_fetch_changes = netbsd32_kevent_fetch_changes,
    646  1.19     joerg 		.keo_put_events = netbsd32_kevent_put_events,
    647   1.2  christos 	};
    648   1.2  christos 
    649   1.2  christos 	nchanges = SCARG(uap, nchanges);
    650   1.2  christos 	nevents = SCARG(uap, nevents);
    651  1.24      maxv 	maxalloc = KQ_NEVENTS;
    652  1.24      maxv 
    653   1.2  christos 	netbsd32_kevent_ops.keo_private =
    654  1.16     rmind 	    kmem_alloc(maxalloc * sizeof(struct netbsd32_kevent), KM_SLEEP);
    655   1.2  christos 
    656   1.2  christos 	error = kevent1(retval, SCARG(uap, fd),
    657   1.2  christos 	    NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
    658   1.2  christos 	    NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
    659   1.2  christos 	    NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
    660   1.2  christos 
    661  1.16     rmind 	kmem_free(netbsd32_kevent_ops.keo_private,
    662  1.16     rmind 	    maxalloc * sizeof(struct netbsd32_kevent));
    663   1.2  christos 	return error;
    664   1.2  christos }
    665   1.2  christos 
    666   1.2  christos int
    667   1.2  christos compat_50_netbsd32_pselect(struct lwp *l,
    668   1.2  christos     const struct compat_50_netbsd32_pselect_args *uap, register_t *retval)
    669   1.2  christos {
    670   1.2  christos 	/* {
    671   1.2  christos 		syscallarg(int) nd;
    672   1.2  christos 		syscallarg(netbsd32_fd_setp_t) in;
    673   1.2  christos 		syscallarg(netbsd32_fd_setp_t) ou;
    674   1.2  christos 		syscallarg(netbsd32_fd_setp_t) ex;
    675   1.2  christos 		syscallarg(const netbsd32_timespec50p_t) ts;
    676   1.2  christos 		syscallarg(const netbsd32_sigsetp_t) mask;
    677   1.2  christos 	} */
    678   1.2  christos 	int error;
    679   1.2  christos 	struct netbsd32_timespec50 ts32;
    680   1.4  christos 	struct timespec ats, *ts = NULL;
    681   1.2  christos 	sigset_t amask, *mask = NULL;
    682   1.2  christos 
    683   1.2  christos 	if (SCARG_P32(uap, ts)) {
    684   1.2  christos 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
    685   1.2  christos 		if (error != 0)
    686   1.2  christos 			return error;
    687   1.4  christos 		netbsd32_to_timespec50(&ts32, &ats);
    688   1.4  christos 		ts = &ats;
    689   1.2  christos 	}
    690   1.2  christos 	if (SCARG_P32(uap, mask)) {
    691   1.2  christos 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
    692   1.2  christos 		if (error != 0)
    693   1.2  christos 			return error;
    694   1.2  christos 		mask = &amask;
    695   1.2  christos 	}
    696   1.2  christos 
    697   1.7     rmind 	return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
    698   1.4  christos 	    SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask);
    699   1.2  christos }
    700   1.2  christos 
    701   1.2  christos int
    702   1.2  christos compat_50_netbsd32_pollts(struct lwp *l,
    703   1.2  christos     const struct compat_50_netbsd32_pollts_args *uap, register_t *retval)
    704   1.2  christos {
    705   1.2  christos 	/* {
    706   1.2  christos 		syscallarg(struct netbsd32_pollfdp_t) fds;
    707   1.2  christos 		syscallarg(u_int) nfds;
    708   1.2  christos 		syscallarg(const netbsd32_timespec50p_t) ts;
    709   1.2  christos 		syscallarg(const netbsd32_sigsetp_t) mask;
    710   1.2  christos 	} */
    711   1.2  christos 	int error;
    712   1.2  christos 	struct netbsd32_timespec50 ts32;
    713   1.4  christos 	struct timespec ats, *ts = NULL;
    714   1.2  christos 	sigset_t amask, *mask = NULL;
    715   1.2  christos 
    716   1.2  christos 	if (SCARG_P32(uap, ts)) {
    717   1.2  christos 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
    718   1.2  christos 		if (error != 0)
    719   1.2  christos 			return error;
    720   1.4  christos 		netbsd32_to_timespec50(&ts32, &ats);
    721   1.4  christos 		ts = &ats;
    722   1.2  christos 	}
    723   1.2  christos 	if (NETBSD32PTR64( SCARG(uap, mask))) {
    724   1.2  christos 		error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
    725   1.2  christos 		if (error != 0)
    726   1.2  christos 			return error;
    727   1.2  christos 		mask = &amask;
    728   1.2  christos 	}
    729   1.2  christos 
    730   1.7     rmind 	return pollcommon(retval, SCARG_P32(uap, fds),
    731   1.4  christos 	    SCARG(uap, nfds), ts, mask);
    732   1.2  christos }
    733   1.2  christos 
    734   1.2  christos int
    735   1.2  christos compat_50_netbsd32___stat30(struct lwp *l,
    736   1.2  christos     const struct compat_50_netbsd32___stat30_args *uap, register_t *retval)
    737   1.2  christos {
    738   1.2  christos 	/* {
    739   1.2  christos 		syscallarg(const netbsd32_charp) path;
    740   1.2  christos 		syscallarg(netbsd32_stat50p_t) ub;
    741   1.2  christos 	} */
    742   1.2  christos 	struct netbsd32_stat50 sb32;
    743   1.2  christos 	struct stat sb;
    744   1.2  christos 	int error;
    745   1.2  christos 	const char *path;
    746   1.2  christos 
    747   1.2  christos 	path = SCARG_P32(uap, path);
    748   1.2  christos 
    749   1.2  christos 	error = do_sys_stat(path, FOLLOW, &sb);
    750   1.2  christos 	if (error)
    751   1.2  christos 		return error;
    752   1.2  christos 	netbsd32_from___stat50(&sb, &sb32);
    753   1.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    754   1.2  christos 	return error;
    755   1.2  christos }
    756   1.2  christos 
    757   1.2  christos int
    758   1.2  christos compat_50_netbsd32___fstat30(struct lwp *l,
    759   1.2  christos     const struct compat_50_netbsd32___fstat30_args *uap, register_t *retval)
    760   1.2  christos {
    761   1.2  christos 	/* {
    762   1.2  christos 		syscallarg(int) fd;
    763   1.2  christos 		syscallarg(netbsd32_stat50p_t) sb;
    764   1.2  christos 	} */
    765   1.2  christos 	struct netbsd32_stat50 sb32;
    766   1.2  christos 	struct stat ub;
    767   1.3     njoly 	int error;
    768   1.2  christos 
    769   1.3     njoly 	error = do_sys_fstat(SCARG(uap, fd), &ub);
    770   1.2  christos 	if (error == 0) {
    771   1.2  christos 		netbsd32_from___stat50(&ub, &sb32);
    772   1.2  christos 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    773   1.2  christos 	}
    774   1.2  christos 	return error;
    775   1.2  christos }
    776   1.2  christos 
    777   1.2  christos int
    778   1.2  christos compat_50_netbsd32___lstat30(struct lwp *l,
    779   1.2  christos     const struct compat_50_netbsd32___lstat30_args *uap, register_t *retval)
    780   1.2  christos {
    781   1.2  christos 	/* {
    782   1.2  christos 		syscallarg(const netbsd32_charp) path;
    783   1.2  christos 		syscallarg(netbsd32_stat50p_t) ub;
    784   1.2  christos 	} */
    785   1.2  christos 	struct netbsd32_stat50 sb32;
    786   1.2  christos 	struct stat sb;
    787   1.2  christos 	int error;
    788   1.2  christos 	const char *path;
    789   1.2  christos 
    790   1.2  christos 	path = SCARG_P32(uap, path);
    791   1.2  christos 
    792   1.2  christos 	error = do_sys_stat(path, NOFOLLOW, &sb);
    793   1.2  christos 	if (error)
    794   1.2  christos 		return error;
    795   1.2  christos 	netbsd32_from___stat50(&sb, &sb32);
    796   1.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    797   1.2  christos 	return error;
    798   1.2  christos }
    799   1.2  christos 
    800   1.2  christos int
    801   1.2  christos compat_50_netbsd32___fhstat40(struct lwp *l, const struct compat_50_netbsd32___fhstat40_args *uap, register_t *retval)
    802   1.2  christos {
    803   1.2  christos 	/* {
    804   1.2  christos 		syscallarg(const netbsd32_pointer_t) fhp;
    805   1.2  christos 		syscallarg(netbsd32_size_t) fh_size;
    806   1.2  christos 		syscallarg(netbsd32_stat50p_t) sb;
    807   1.2  christos 	} */
    808   1.2  christos 	struct stat sb;
    809   1.2  christos 	struct netbsd32_stat50 sb32;
    810   1.2  christos 	int error;
    811   1.2  christos 
    812   1.2  christos 	error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
    813   1.2  christos 	if (error != 0) {
    814   1.2  christos 		netbsd32_from___stat50(&sb, &sb32);
    815   1.2  christos 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    816   1.2  christos 	}
    817   1.2  christos 	return error;
    818   1.2  christos }
    819   1.2  christos 
    820   1.2  christos int
    821   1.2  christos compat_50_netbsd32_wait4(struct lwp *l, const struct compat_50_netbsd32_wait4_args *uap, register_t *retval)
    822   1.2  christos {
    823   1.2  christos 	/* {
    824   1.2  christos 		syscallarg(int) pid;
    825   1.2  christos 		syscallarg(netbsd32_intp) status;
    826   1.2  christos 		syscallarg(int) options;
    827   1.2  christos 		syscallarg(netbsd32_rusage50p_t) rusage;
    828   1.2  christos 	} */
    829   1.6     rmind 	int error, status, pid = SCARG(uap, pid);
    830   1.6     rmind 	struct netbsd32_rusage50 ru32;
    831   1.6     rmind 	struct rusage ru;
    832   1.2  christos 
    833   1.6     rmind 	error = do_sys_wait(&pid, &status, SCARG(uap, options),
    834   1.6     rmind 	    SCARG_P32(uap, rusage) != NULL ? &ru : NULL);
    835   1.2  christos 
    836   1.2  christos 	retval[0] = pid;
    837   1.2  christos 	if (pid == 0)
    838   1.2  christos 		return error;
    839   1.2  christos 
    840   1.2  christos 	if (SCARG_P32(uap, rusage)) {
    841   1.2  christos 		netbsd32_from_rusage50(&ru, &ru32);
    842   1.2  christos 		error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
    843   1.2  christos 	}
    844   1.2  christos 
    845   1.2  christos 	if (error == 0 && SCARG_P32(uap, status))
    846   1.2  christos 		error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
    847   1.2  christos 
    848   1.2  christos 	return error;
    849   1.2  christos }
    850   1.2  christos 
    851   1.2  christos 
    852   1.2  christos int
    853   1.2  christos compat_50_netbsd32_getrusage(struct lwp *l, const struct compat_50_netbsd32_getrusage_args *uap, register_t *retval)
    854   1.2  christos {
    855   1.2  christos 	/* {
    856   1.2  christos 		syscallarg(int) who;
    857   1.2  christos 		syscallarg(netbsd32_rusage50p_t) rusage;
    858   1.2  christos 	} */
    859  1.22     njoly 	int error;
    860   1.2  christos 	struct proc *p = l->l_proc;
    861  1.22     njoly 	struct rusage ru;
    862  1.22     njoly 	struct netbsd32_rusage50 ru32;
    863   1.2  christos 
    864  1.22     njoly 	error = getrusage1(p, SCARG(uap, who), &ru);
    865  1.22     njoly 	if (error != 0)
    866  1.22     njoly 		return error;
    867   1.2  christos 
    868  1.22     njoly 	netbsd32_from_rusage50(&ru, &ru32);
    869  1.22     njoly 	return copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
    870   1.2  christos }
    871   1.2  christos 
    872   1.2  christos int
    873   1.2  christos compat_50_netbsd32_setitimer(struct lwp *l,
    874   1.2  christos     const struct compat_50_netbsd32_setitimer_args *uap, register_t *retval)
    875   1.2  christos {
    876   1.2  christos 	/* {
    877   1.2  christos 		syscallarg(int) which;
    878   1.2  christos 		syscallarg(const netbsd32_itimerval50p_t) itv;
    879   1.2  christos 		syscallarg(netbsd32_itimerval50p_t) oitv;
    880   1.2  christos 	} */
    881   1.2  christos 	struct proc *p = l->l_proc;
    882   1.2  christos 	struct netbsd32_itimerval50 s32it, *itv32;
    883   1.2  christos 	int which = SCARG(uap, which);
    884   1.2  christos 	struct compat_50_netbsd32_getitimer_args getargs;
    885   1.2  christos 	struct itimerval aitv;
    886   1.2  christos 	int error;
    887   1.2  christos 
    888   1.2  christos 	if ((u_int)which > ITIMER_PROF)
    889   1.2  christos 		return (EINVAL);
    890   1.2  christos 	itv32 = SCARG_P32(uap, itv);
    891   1.2  christos 	if (itv32) {
    892   1.2  christos 		if ((error = copyin(itv32, &s32it, sizeof(s32it))))
    893   1.2  christos 			return (error);
    894   1.2  christos 		netbsd32_to_itimerval50(&s32it, &aitv);
    895   1.2  christos 	}
    896   1.2  christos 	if (SCARG_P32(uap, oitv) != 0) {
    897   1.2  christos 		SCARG(&getargs, which) = which;
    898   1.2  christos 		SCARG(&getargs, itv) = SCARG(uap, oitv);
    899   1.2  christos 		if ((error = compat_50_netbsd32_getitimer(l, &getargs, retval)) != 0)
    900   1.2  christos 			return (error);
    901   1.2  christos 	}
    902   1.2  christos 	if (itv32 == 0)
    903   1.2  christos 		return 0;
    904   1.2  christos 
    905   1.2  christos 	return dosetitimer(p, which, &aitv);
    906   1.2  christos }
    907   1.2  christos 
    908   1.2  christos int
    909   1.2  christos compat_50_netbsd32_getitimer(struct lwp *l, const struct compat_50_netbsd32_getitimer_args *uap, register_t *retval)
    910   1.2  christos {
    911   1.2  christos 	/* {
    912   1.2  christos 		syscallarg(int) which;
    913   1.2  christos 		syscallarg(netbsd32_itimerval50p_t) itv;
    914   1.2  christos 	} */
    915   1.2  christos 	struct proc *p = l->l_proc;
    916   1.2  christos 	struct netbsd32_itimerval50 s32it;
    917   1.2  christos 	struct itimerval aitv;
    918   1.2  christos 	int error;
    919   1.2  christos 
    920   1.2  christos 	error = dogetitimer(p, SCARG(uap, which), &aitv);
    921   1.2  christos 	if (error)
    922   1.2  christos 		return error;
    923   1.2  christos 
    924   1.2  christos 	netbsd32_from_itimerval50(&aitv, &s32it);
    925   1.2  christos 	return copyout(&s32it, SCARG_P32(uap, itv), sizeof(s32it));
    926   1.2  christos }
    927   1.2  christos 
    928  1.37  christos #ifdef QUOTA
    929  1.18    bouyer int
    930  1.18    bouyer compat_50_netbsd32_quotactl(struct lwp *l, const struct compat_50_netbsd32_quotactl_args *uap, register_t *retval)
    931  1.18    bouyer {
    932  1.18    bouyer 	/* {
    933  1.18    bouyer 		syscallarg(const netbsd32_charp) path;
    934  1.18    bouyer 		syscallarg(int) cmd;
    935  1.18    bouyer 		syscallarg(int) uid;
    936  1.18    bouyer 		syscallarg(netbsd32_voidp) arg;
    937  1.18    bouyer 	} */
    938  1.18    bouyer 	struct compat_50_sys_quotactl_args ua;
    939  1.18    bouyer 
    940  1.18    bouyer 	NETBSD32TOP_UAP(path, const char);
    941  1.18    bouyer 	NETBSD32TO64_UAP(cmd);
    942  1.18    bouyer 	NETBSD32TO64_UAP(uid);
    943  1.18    bouyer 	NETBSD32TOP_UAP(arg, void *);
    944  1.18    bouyer 	return (compat_50_sys_quotactl(l, &ua, retval));
    945  1.18    bouyer }
    946  1.37  christos #endif
    947  1.29    martin 
    948  1.34  pgoyette #ifdef NTP
    949  1.34  pgoyette int
    950  1.34  pgoyette compat_50_netbsd32_ntp_gettime(struct lwp *l,
    951  1.34  pgoyette     const struct compat_50_netbsd32_ntp_gettime_args *uap, register_t *retval)
    952  1.34  pgoyette {
    953  1.34  pgoyette 	/* {
    954  1.34  pgoyette 		syscallarg(netbsd32_ntptimeval50p_t) ntvp;
    955  1.34  pgoyette 	} */
    956  1.34  pgoyette 	struct netbsd32_ntptimeval50 ntv32;
    957  1.34  pgoyette 	struct ntptimeval ntv;
    958  1.34  pgoyette 	int error = 0;
    959  1.34  pgoyette 
    960  1.34  pgoyette 	if (vec_ntp_gettime == NULL)
    961  1.34  pgoyette 		return EINVAL;
    962  1.34  pgoyette 
    963  1.34  pgoyette 	if (SCARG_P32(uap, ntvp)) {
    964  1.34  pgoyette 		(*vec_ntp_gettime)(&ntv);
    965  1.34  pgoyette 
    966  1.34  pgoyette 		memset(&ntv32, 0, sizeof(ntv32));
    967  1.34  pgoyette 		ntv32.time.tv_sec = (int32_t)ntv.time.tv_sec;
    968  1.34  pgoyette 		ntv32.time.tv_nsec = ntv.time.tv_nsec;
    969  1.34  pgoyette 		ntv32.maxerror = (netbsd32_long)ntv.maxerror;
    970  1.34  pgoyette 		ntv32.esterror = (netbsd32_long)ntv.esterror;
    971  1.34  pgoyette 		ntv32.tai = (netbsd32_long)ntv.tai;
    972  1.34  pgoyette 		ntv32.time_state = ntv.time_state;
    973  1.34  pgoyette 		error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
    974  1.34  pgoyette 	}
    975  1.34  pgoyette 	if (!error) {
    976  1.34  pgoyette 		*retval = (*vec_ntp_timestatus)();
    977  1.34  pgoyette 	}
    978  1.34  pgoyette 
    979  1.34  pgoyette 	return (error);
    980  1.34  pgoyette }
    981  1.34  pgoyette #endif
    982  1.34  pgoyette 
    983  1.34  pgoyette static struct syscall_package compat_netbsd32_50_syscalls[] = {
    984  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_mknod, 0,
    985  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_mknod },
    986  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_select, 0,
    987  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_select },
    988  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_gettimeofday, 0,
    989  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_gettimeofday },
    990  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_settimeofday, 0,
    991  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_settimeofday },
    992  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_utimes, 0,
    993  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_utimes },
    994  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_futimes, 0,
    995  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_futimes },
    996  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_adjtime, 0,
    997  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_adjtime },
    998  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_clock_gettime, 0,
    999  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_clock_gettime },
   1000  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_clock_settime, 0,
   1001  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_clock_settime },
   1002  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_clock_getres, 0,
   1003  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_clock_getres },
   1004  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_timer_settime, 0,
   1005  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_timer_settime },
   1006  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_timer_gettime, 0,
   1007  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_timer_gettime },
   1008  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_nanosleep, 0,
   1009  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_nanosleep },
   1010  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32___sigtimedwait, 0,
   1011  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32___sigtimedwait },
   1012  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_lutimes, 0,
   1013  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_lutimes },
   1014  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32__lwp_park, 0,
   1015  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32__lwp_park },
   1016  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_kevent, 0,
   1017  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_kevent },
   1018  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_pselect, 0,
   1019  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_pselect },
   1020  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_pollts, 0,
   1021  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_pollts },
   1022  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32___stat30, 0,
   1023  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32___stat30 },
   1024  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32___fstat30, 0,
   1025  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32___fstat30 },
   1026  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32___lstat30, 0,
   1027  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32___lstat30 },
   1028  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32___fhstat40, 0,
   1029  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32___fhstat40 },
   1030  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_wait4, 0,
   1031  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_wait4 },
   1032  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_getrusage, 0,
   1033  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_getrusage },
   1034  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_setitimer, 0,
   1035  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_setitimer },
   1036  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_getitimer, 0,
   1037  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_getitimer },
   1038  1.37  christos #ifdef QUOTA
   1039  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_quotactl, 0,
   1040  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_quotactl },
   1041  1.37  christos #endif
   1042  1.34  pgoyette #ifdef NTP
   1043  1.34  pgoyette 	{ NETBSD32_SYS_compat_50_netbsd32_ntp_gettime, 0,
   1044  1.34  pgoyette 	    (sy_call_t *)compat_50_netbsd32_ntp_gettime },
   1045  1.34  pgoyette #endif
   1046  1.34  pgoyette 	{ 0, 0, NULL }
   1047  1.34  pgoyette };
   1048  1.34  pgoyette 
   1049  1.34  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_50, "compat_netbsd32_60,compat_50");
   1050  1.34  pgoyette 
   1051  1.34  pgoyette static int
   1052  1.34  pgoyette compat_netbsd32_50_modcmd(modcmd_t cmd, void *arg)
   1053  1.34  pgoyette {
   1054  1.34  pgoyette 	int ret;
   1055  1.34  pgoyette 
   1056  1.34  pgoyette 	switch (cmd) {
   1057  1.34  pgoyette 	case MODULE_CMD_INIT:
   1058  1.34  pgoyette                 ret = syscall_establish(&emul_netbsd32,
   1059  1.34  pgoyette 		    compat_netbsd32_50_syscalls);
   1060  1.34  pgoyette 		if (ret == 0)
   1061  1.42  pgoyette 			MODULE_HOOK_SET(rnd_ioctl32_50_hook,
   1062  1.34  pgoyette 			    compat32_50_rnd_ioctl);
   1063  1.34  pgoyette 		return ret;
   1064  1.34  pgoyette 
   1065  1.34  pgoyette 	case MODULE_CMD_FINI:
   1066  1.34  pgoyette                 ret = syscall_disestablish(&emul_netbsd32,
   1067  1.34  pgoyette 		    compat_netbsd32_50_syscalls);
   1068  1.34  pgoyette 		if (ret == 0)
   1069  1.36  pgoyette 			MODULE_HOOK_UNSET(rnd_ioctl32_50_hook);
   1070  1.34  pgoyette 		return ret;
   1071  1.34  pgoyette 
   1072  1.34  pgoyette 	default:
   1073  1.34  pgoyette 		return ENOTTY;
   1074  1.34  pgoyette 	}
   1075  1.34  pgoyette }
   1076  1.32  pgoyette #endif /* COMPAT_50 */
   1077