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