Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_time.c revision 1.32.10.1
      1  1.32.10.1      yamt /*	$NetBSD: netbsd32_time.c,v 1.32.10.1 2009/05/04 08:12:26 yamt Exp $	*/
      2        1.1       mrg 
      3        1.1       mrg /*
      4        1.1       mrg  * Copyright (c) 1998, 2001 Matthew R. Green
      5        1.1       mrg  * All rights reserved.
      6        1.1       mrg  *
      7        1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8        1.1       mrg  * modification, are permitted provided that the following conditions
      9        1.1       mrg  * are met:
     10        1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11        1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12        1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15        1.1       mrg  *
     16        1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17        1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18        1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19        1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20        1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21        1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22        1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23        1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24        1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1       mrg  * SUCH DAMAGE.
     27        1.1       mrg  */
     28        1.3     lukem 
     29        1.3     lukem #include <sys/cdefs.h>
     30  1.32.10.1      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_time.c,v 1.32.10.1 2009/05/04 08:12:26 yamt Exp $");
     31        1.1       mrg 
     32        1.2       mrg #if defined(_KERNEL_OPT)
     33        1.1       mrg #include "opt_ntp.h"
     34       1.21  drochner #include "opt_compat_netbsd.h"
     35        1.1       mrg #endif
     36        1.1       mrg 
     37        1.1       mrg #include <sys/param.h>
     38        1.1       mrg #include <sys/systm.h>
     39        1.1       mrg #include <sys/mount.h>
     40        1.1       mrg #include <sys/time.h>
     41        1.1       mrg #include <sys/timex.h>
     42       1.13      cube #include <sys/timevar.h>
     43       1.22    kardel #include <sys/timetc.h>
     44        1.1       mrg #include <sys/proc.h>
     45        1.5   thorpej #include <sys/pool.h>
     46        1.1       mrg #include <sys/resourcevar.h>
     47       1.12  christos #include <sys/dirent.h>
     48       1.20      elad #include <sys/kauth.h>
     49        1.1       mrg 
     50        1.1       mrg #include <compat/netbsd32/netbsd32.h>
     51        1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     52        1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     53        1.1       mrg 
     54        1.1       mrg #ifdef NTP
     55       1.19        he 
     56        1.1       mrg int
     57  1.32.10.1      yamt netbsd32___ntp_gettime50(struct lwp *l,
     58  1.32.10.1      yamt     const struct netbsd32___ntp_gettime50_args *uap, register_t *retval)
     59        1.1       mrg {
     60       1.30       dsl 	/* {
     61        1.1       mrg 		syscallarg(netbsd32_ntptimevalp_t) ntvp;
     62       1.30       dsl 	} */
     63        1.1       mrg 	struct netbsd32_ntptimeval ntv32;
     64        1.1       mrg 	struct ntptimeval ntv;
     65        1.1       mrg 	int error = 0;
     66        1.1       mrg 
     67       1.27       dsl 	if (SCARG_P32(uap, ntvp)) {
     68       1.21  drochner 		ntp_gettime(&ntv);
     69        1.1       mrg 
     70       1.21  drochner 		ntv32.time.tv_sec = ntv.time.tv_sec;
     71       1.21  drochner 		ntv32.time.tv_nsec = ntv.time.tv_nsec;
     72        1.1       mrg 		ntv32.maxerror = (netbsd32_long)ntv.maxerror;
     73        1.1       mrg 		ntv32.esterror = (netbsd32_long)ntv.esterror;
     74       1.21  drochner 		ntv32.tai = (netbsd32_long)ntv.tai;
     75       1.21  drochner 		ntv32.time_state = ntv.time_state;
     76       1.27       dsl 		error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
     77        1.1       mrg 	}
     78        1.1       mrg 	if (!error) {
     79       1.21  drochner 		*retval = ntp_timestatus();
     80       1.21  drochner 	}
     81        1.1       mrg 
     82       1.21  drochner 	return (error);
     83       1.21  drochner }
     84        1.1       mrg 
     85  1.32.10.1      yamt #ifdef COMPAT_50
     86  1.32.10.1      yamt int
     87  1.32.10.1      yamt compat_50_netbsd32_ntp_gettime(struct lwp *l,
     88  1.32.10.1      yamt     const struct compat_50_netbsd32_ntp_gettime_args *uap, register_t *retval)
     89  1.32.10.1      yamt {
     90  1.32.10.1      yamt 	/* {
     91  1.32.10.1      yamt 		syscallarg(netbsd32_ntptimeval50p_t) ntvp;
     92  1.32.10.1      yamt 	} */
     93  1.32.10.1      yamt 	struct netbsd32_ntptimeval50 ntv32;
     94  1.32.10.1      yamt 	struct ntptimeval ntv;
     95  1.32.10.1      yamt 	int error = 0;
     96  1.32.10.1      yamt 
     97  1.32.10.1      yamt 	if (SCARG_P32(uap, ntvp)) {
     98  1.32.10.1      yamt 		ntp_gettime(&ntv);
     99  1.32.10.1      yamt 
    100  1.32.10.1      yamt 		ntv32.time.tv_sec = (int32_t)ntv.time.tv_sec;
    101  1.32.10.1      yamt 		ntv32.time.tv_nsec = ntv.time.tv_nsec;
    102  1.32.10.1      yamt 		ntv32.maxerror = (netbsd32_long)ntv.maxerror;
    103  1.32.10.1      yamt 		ntv32.esterror = (netbsd32_long)ntv.esterror;
    104  1.32.10.1      yamt 		ntv32.tai = (netbsd32_long)ntv.tai;
    105  1.32.10.1      yamt 		ntv32.time_state = ntv.time_state;
    106  1.32.10.1      yamt 		error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
    107  1.32.10.1      yamt 	}
    108  1.32.10.1      yamt 	if (!error) {
    109  1.32.10.1      yamt 		*retval = ntp_timestatus();
    110  1.32.10.1      yamt 	}
    111  1.32.10.1      yamt 
    112  1.32.10.1      yamt 	return (error);
    113  1.32.10.1      yamt }
    114  1.32.10.1      yamt #endif
    115  1.32.10.1      yamt 
    116       1.21  drochner #ifdef COMPAT_30
    117       1.21  drochner int
    118       1.30       dsl compat_30_netbsd32_ntp_gettime(struct lwp *l, const struct compat_30_netbsd32_ntp_gettime_args *uap, register_t *retval)
    119       1.21  drochner {
    120       1.30       dsl 	/* {
    121       1.21  drochner 		syscallarg(netbsd32_ntptimevalp_t) ntvp;
    122       1.30       dsl 	} */
    123       1.21  drochner 	struct netbsd32_ntptimeval30 ntv32;
    124       1.21  drochner 	struct ntptimeval ntv;
    125       1.21  drochner 	int error = 0;
    126        1.1       mrg 
    127       1.27       dsl 	if (SCARG_P32(uap, ntvp)) {
    128       1.21  drochner 		ntp_gettime(&ntv);
    129        1.1       mrg 
    130       1.21  drochner 		ntv32.time.tv_sec = ntv.time.tv_sec;
    131       1.21  drochner 		ntv32.time.tv_usec = ntv.time.tv_nsec / 1000;
    132       1.21  drochner 		ntv32.maxerror = (netbsd32_long)ntv.maxerror;
    133       1.21  drochner 		ntv32.esterror = (netbsd32_long)ntv.esterror;
    134       1.27       dsl 		error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
    135       1.21  drochner 	}
    136       1.21  drochner 	if (!error) {
    137       1.21  drochner 		*retval = ntp_timestatus();
    138        1.1       mrg 	}
    139       1.21  drochner 
    140        1.1       mrg 	return (error);
    141        1.1       mrg }
    142       1.21  drochner #endif
    143        1.1       mrg 
    144        1.1       mrg int
    145       1.30       dsl netbsd32_ntp_adjtime(struct lwp *l, const struct netbsd32_ntp_adjtime_args *uap, register_t *retval)
    146        1.1       mrg {
    147       1.30       dsl 	/* {
    148        1.1       mrg 		syscallarg(netbsd32_timexp_t) tp;
    149       1.30       dsl 	} */
    150        1.1       mrg 	struct netbsd32_timex ntv32;
    151        1.1       mrg 	struct timex ntv;
    152        1.1       mrg 	int error = 0;
    153        1.1       mrg 	int modes;
    154        1.1       mrg 
    155       1.27       dsl 	if ((error = copyin(SCARG_P32(uap, tp), &ntv32, sizeof(ntv32))))
    156        1.1       mrg 		return (error);
    157       1.22    kardel 
    158        1.1       mrg 	netbsd32_to_timex(&ntv32, &ntv);
    159        1.1       mrg 
    160        1.1       mrg 	/*
    161        1.1       mrg 	 * Update selected clock variables - only the superuser can
    162        1.1       mrg 	 * change anything. Note that there is no error checking here on
    163        1.1       mrg 	 * the assumption the superuser should know what it is doing.
    164        1.1       mrg 	 */
    165        1.1       mrg 	modes = ntv.modes;
    166       1.24      elad 	if (modes != 0 && (error = kauth_authorize_system(l->l_cred,
    167       1.24      elad 	    KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_NTPADJTIME, NULL, NULL,
    168       1.24      elad 	    NULL)))
    169        1.1       mrg 		return (error);
    170        1.1       mrg 
    171       1.22    kardel 	ntp_adjtime1(&ntv);
    172        1.1       mrg 
    173        1.1       mrg 	netbsd32_from_timex(&ntv, &ntv32);
    174       1.27       dsl 	error = copyout(&ntv32, SCARG_P32(uap, tp), sizeof(ntv32));
    175        1.1       mrg 	if (!error) {
    176       1.22    kardel 		*retval = ntp_timestatus();
    177        1.1       mrg 	}
    178        1.1       mrg 	return error;
    179        1.1       mrg }
    180       1.21  drochner #endif /* NTP */
    181        1.1       mrg 
    182        1.1       mrg int
    183  1.32.10.1      yamt netbsd32___setitimer50(struct lwp *l, const struct netbsd32___setitimer50_args *uap, register_t *retval)
    184        1.1       mrg {
    185       1.30       dsl 	/* {
    186        1.1       mrg 		syscallarg(int) which;
    187        1.1       mrg 		syscallarg(const netbsd32_itimervalp_t) itv;
    188        1.1       mrg 		syscallarg(netbsd32_itimervalp_t) oitv;
    189       1.30       dsl 	} */
    190        1.5   thorpej 	struct proc *p = l->l_proc;
    191       1.10      cube 	struct netbsd32_itimerval s32it, *itv32;
    192        1.1       mrg 	int which = SCARG(uap, which);
    193  1.32.10.1      yamt 	struct netbsd32___getitimer50_args getargs;
    194        1.1       mrg 	struct itimerval aitv;
    195       1.10      cube 	int error;
    196        1.1       mrg 
    197        1.1       mrg 	if ((u_int)which > ITIMER_PROF)
    198        1.1       mrg 		return (EINVAL);
    199       1.27       dsl 	itv32 = SCARG_P32(uap, itv);
    200       1.10      cube 	if (itv32) {
    201       1.10      cube 		if ((error = copyin(itv32, &s32it, sizeof(s32it))))
    202       1.10      cube 			return (error);
    203       1.10      cube 		netbsd32_to_itimerval(&s32it, &aitv);
    204       1.10      cube 	}
    205       1.26       dsl 	if (SCARG_P32(uap, oitv) != 0) {
    206        1.1       mrg 		SCARG(&getargs, which) = which;
    207        1.1       mrg 		SCARG(&getargs, itv) = SCARG(uap, oitv);
    208  1.32.10.1      yamt 		if ((error = netbsd32___getitimer50(l, &getargs, retval)) != 0)
    209        1.1       mrg 			return (error);
    210        1.1       mrg 	}
    211       1.10      cube 	if (itv32 == 0)
    212       1.10      cube 		return 0;
    213        1.5   thorpej 
    214       1.10      cube 	return dosetitimer(p, which, &aitv);
    215        1.1       mrg }
    216        1.1       mrg 
    217        1.1       mrg int
    218  1.32.10.1      yamt netbsd32___getitimer50(struct lwp *l, const struct netbsd32___getitimer50_args *uap, register_t *retval)
    219        1.1       mrg {
    220       1.30       dsl 	/* {
    221        1.1       mrg 		syscallarg(int) which;
    222        1.1       mrg 		syscallarg(netbsd32_itimervalp_t) itv;
    223       1.30       dsl 	} */
    224        1.5   thorpej 	struct proc *p = l->l_proc;
    225        1.1       mrg 	struct netbsd32_itimerval s32it;
    226        1.1       mrg 	struct itimerval aitv;
    227       1.10      cube 	int error;
    228        1.1       mrg 
    229       1.10      cube 	error = dogetitimer(p, SCARG(uap, which), &aitv);
    230       1.10      cube 	if (error)
    231       1.10      cube 		return error;
    232        1.5   thorpej 
    233        1.1       mrg 	netbsd32_from_itimerval(&aitv, &s32it);
    234       1.27       dsl 	return copyout(&s32it, SCARG_P32(uap, itv), sizeof(s32it));
    235        1.1       mrg }
    236        1.1       mrg 
    237        1.1       mrg int
    238  1.32.10.1      yamt netbsd32___gettimeofday50(struct lwp *l, const struct netbsd32___gettimeofday50_args *uap, register_t *retval)
    239        1.1       mrg {
    240       1.30       dsl 	/* {
    241        1.1       mrg 		syscallarg(netbsd32_timevalp_t) tp;
    242        1.1       mrg 		syscallarg(netbsd32_timezonep_t) tzp;
    243       1.30       dsl 	} */
    244        1.1       mrg 	struct timeval atv;
    245        1.1       mrg 	struct netbsd32_timeval tv32;
    246        1.1       mrg 	int error = 0;
    247        1.1       mrg 	struct netbsd32_timezone tzfake;
    248        1.1       mrg 
    249       1.26       dsl 	if (SCARG_P32(uap, tp)) {
    250        1.1       mrg 		microtime(&atv);
    251        1.1       mrg 		netbsd32_from_timeval(&atv, &tv32);
    252       1.27       dsl 		error = copyout(&tv32, SCARG_P32(uap, tp), sizeof(tv32));
    253        1.1       mrg 		if (error)
    254        1.1       mrg 			return (error);
    255        1.1       mrg 	}
    256       1.26       dsl 	if (SCARG_P32(uap, tzp)) {
    257        1.1       mrg 		/*
    258        1.1       mrg 		 * NetBSD has no kernel notion of time zone, so we just
    259        1.1       mrg 		 * fake up a timezone struct and return it if demanded.
    260        1.1       mrg 		 */
    261        1.1       mrg 		tzfake.tz_minuteswest = 0;
    262        1.1       mrg 		tzfake.tz_dsttime = 0;
    263       1.27       dsl 		error = copyout(&tzfake, SCARG_P32(uap, tzp), sizeof(tzfake));
    264        1.1       mrg 	}
    265        1.1       mrg 	return (error);
    266        1.1       mrg }
    267        1.1       mrg 
    268        1.1       mrg int
    269  1.32.10.1      yamt netbsd32___settimeofday50(struct lwp *l, const struct netbsd32___settimeofday50_args *uap, register_t *retval)
    270        1.1       mrg {
    271       1.30       dsl 	/* {
    272        1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tv;
    273        1.1       mrg 		syscallarg(const netbsd32_timezonep_t) tzp;
    274       1.30       dsl 	} */
    275        1.1       mrg 	struct netbsd32_timeval atv32;
    276        1.1       mrg 	struct timeval atv;
    277       1.16  christos 	struct timespec ats;
    278        1.1       mrg 	int error;
    279        1.5   thorpej 	struct proc *p = l->l_proc;
    280        1.1       mrg 
    281       1.16  christos 	/* Verify all parameters before changing time. */
    282       1.16  christos 
    283        1.1       mrg 	/*
    284        1.1       mrg 	 * NetBSD has no kernel notion of time zone, and only an
    285        1.1       mrg 	 * obsolete program would try to set it, so we log a warning.
    286        1.1       mrg 	 */
    287       1.26       dsl 	if (SCARG_P32(uap, tzp))
    288        1.1       mrg 		printf("pid %d attempted to set the "
    289        1.8     perry 		    "(obsolete) kernel time zone\n", p->p_pid);
    290       1.16  christos 
    291       1.26       dsl 	if (SCARG_P32(uap, tv) == 0)
    292       1.16  christos 		return 0;
    293       1.16  christos 
    294       1.27       dsl 	if ((error = copyin(SCARG_P32(uap, tv), &atv32, sizeof(atv32))) != 0)
    295       1.16  christos 		return error;
    296       1.16  christos 
    297       1.16  christos 	netbsd32_to_timeval(&atv32, &atv);
    298       1.16  christos 	TIMEVAL_TO_TIMESPEC(&atv, &ats);
    299       1.16  christos 	return settime(p, &ats);
    300        1.1       mrg }
    301        1.1       mrg 
    302        1.1       mrg int
    303  1.32.10.1      yamt netbsd32___adjtime50(struct lwp *l, const struct netbsd32___adjtime50_args *uap, register_t *retval)
    304        1.1       mrg {
    305       1.30       dsl 	/* {
    306        1.1       mrg 		syscallarg(const netbsd32_timevalp_t) delta;
    307        1.1       mrg 		syscallarg(netbsd32_timevalp_t) olddelta;
    308       1.30       dsl 	} */
    309        1.1       mrg 	struct netbsd32_timeval atv;
    310       1.22    kardel 	int error;
    311        1.1       mrg 
    312       1.32     joerg 	extern int time_adjusted;     /* in kern_ntptime.c */
    313       1.32     joerg 	extern int64_t time_adjtime;  /* in kern_ntptime.c */
    314       1.32     joerg 
    315       1.24      elad 	if ((error = kauth_authorize_system(l->l_cred,
    316       1.24      elad 	    KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL,
    317       1.24      elad 	    NULL)) != 0)
    318        1.1       mrg 		return (error);
    319       1.23        ad 
    320       1.32     joerg 	if (SCARG_P32(uap, olddelta)) {
    321       1.32     joerg 		atv.tv_sec = time_adjtime / 1000000;
    322       1.32     joerg 		atv.tv_usec = time_adjtime % 1000000;
    323       1.32     joerg 		if (atv.tv_usec < 0) {
    324       1.32     joerg 			atv.tv_usec += 1000000;
    325       1.32     joerg 			atv.tv_sec--;
    326       1.22    kardel 		}
    327       1.32     joerg 		(void) copyout(&atv,
    328       1.32     joerg 			       SCARG_P32(uap, olddelta),
    329       1.32     joerg 			       sizeof(atv));
    330       1.32     joerg 		if (error)
    331       1.32     joerg 			return (error);
    332       1.32     joerg 	}
    333       1.22    kardel 
    334       1.32     joerg 	if (SCARG_P32(uap, delta)) {
    335       1.27       dsl 		error = copyin(SCARG_P32(uap, delta), &atv,
    336       1.22    kardel 			       sizeof(struct timeval));
    337       1.22    kardel 		if (error)
    338       1.22    kardel 			return (error);
    339        1.1       mrg 
    340       1.32     joerg 		time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
    341       1.32     joerg 
    342       1.32     joerg 		if (time_adjtime)
    343       1.32     joerg 			/* We need to save the system time during shutdown */
    344       1.32     joerg 			time_adjusted |= 1;
    345        1.1       mrg 	}
    346       1.32     joerg 
    347        1.1       mrg 	return (0);
    348        1.1       mrg }
    349        1.1       mrg 
    350        1.1       mrg int
    351  1.32.10.1      yamt netbsd32___clock_gettime50(struct lwp *l, const struct netbsd32___clock_gettime50_args *uap, register_t *retval)
    352        1.1       mrg {
    353       1.30       dsl 	/* {
    354        1.1       mrg 		syscallarg(netbsd32_clockid_t) clock_id;
    355        1.1       mrg 		syscallarg(netbsd32_timespecp_t) tp;
    356       1.30       dsl 	} */
    357        1.1       mrg 	clockid_t clock_id;
    358        1.1       mrg 	struct timespec ats;
    359        1.1       mrg 	struct netbsd32_timespec ts32;
    360        1.1       mrg 
    361        1.1       mrg 	clock_id = SCARG(uap, clock_id);
    362        1.1       mrg 	if (clock_id != CLOCK_REALTIME)
    363        1.1       mrg 		return (EINVAL);
    364        1.1       mrg 
    365       1.14    simonb 	nanotime(&ats);
    366        1.1       mrg 	netbsd32_from_timespec(&ats, &ts32);
    367        1.1       mrg 
    368       1.27       dsl 	return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
    369        1.1       mrg }
    370        1.1       mrg 
    371        1.1       mrg int
    372  1.32.10.1      yamt netbsd32___clock_settime50(struct lwp *l, const struct netbsd32___clock_settime50_args *uap, register_t *retval)
    373        1.1       mrg {
    374       1.30       dsl 	/* {
    375        1.1       mrg 		syscallarg(netbsd32_clockid_t) clock_id;
    376        1.1       mrg 		syscallarg(const netbsd32_timespecp_t) tp;
    377       1.30       dsl 	} */
    378        1.1       mrg 	struct netbsd32_timespec ts32;
    379        1.1       mrg 	clockid_t clock_id;
    380        1.1       mrg 	struct timespec ats;
    381        1.1       mrg 	int error;
    382        1.1       mrg 
    383        1.1       mrg 	clock_id = SCARG(uap, clock_id);
    384        1.1       mrg 	if (clock_id != CLOCK_REALTIME)
    385        1.1       mrg 		return (EINVAL);
    386        1.1       mrg 
    387       1.27       dsl 	if ((error = copyin(SCARG_P32(uap, tp), &ts32, sizeof(ts32))) != 0)
    388        1.1       mrg 		return (error);
    389        1.1       mrg 
    390        1.1       mrg 	netbsd32_to_timespec(&ts32, &ats);
    391       1.23        ad 	return settime(l->l_proc, &ats);
    392        1.1       mrg }
    393        1.1       mrg 
    394        1.1       mrg int
    395  1.32.10.1      yamt netbsd32___clock_getres50(struct lwp *l, const struct netbsd32___clock_getres50_args *uap, register_t *retval)
    396        1.1       mrg {
    397       1.30       dsl 	/* {
    398        1.1       mrg 		syscallarg(netbsd32_clockid_t) clock_id;
    399        1.1       mrg 		syscallarg(netbsd32_timespecp_t) tp;
    400       1.30       dsl 	} */
    401        1.1       mrg 	struct netbsd32_timespec ts32;
    402        1.1       mrg 	clockid_t clock_id;
    403        1.1       mrg 	struct timespec ts;
    404        1.1       mrg 	int error = 0;
    405        1.1       mrg 
    406        1.1       mrg 	clock_id = SCARG(uap, clock_id);
    407        1.1       mrg 	if (clock_id != CLOCK_REALTIME)
    408        1.1       mrg 		return (EINVAL);
    409        1.1       mrg 
    410       1.26       dsl 	if (SCARG_P32(uap, tp)) {
    411        1.1       mrg 		ts.tv_sec = 0;
    412        1.1       mrg 		ts.tv_nsec = 1000000000 / hz;
    413        1.1       mrg 
    414        1.1       mrg 		netbsd32_from_timespec(&ts, &ts32);
    415       1.27       dsl 		error = copyout(&ts, SCARG_P32(uap, tp), sizeof(ts));
    416        1.1       mrg 	}
    417        1.1       mrg 
    418        1.1       mrg 	return error;
    419        1.1       mrg }
    420        1.1       mrg 
    421        1.1       mrg int
    422  1.32.10.1      yamt netbsd32___nanosleep50(struct lwp *l, const struct netbsd32___nanosleep50_args *uap, register_t *retval)
    423        1.1       mrg {
    424       1.30       dsl 	/* {
    425        1.1       mrg 		syscallarg(const netbsd32_timespecp_t) rqtp;
    426        1.1       mrg 		syscallarg(netbsd32_timespecp_t) rmtp;
    427       1.30       dsl 	} */
    428        1.1       mrg 	static int nanowait;
    429        1.1       mrg 	struct netbsd32_timespec ts32;
    430  1.32.10.1      yamt 	struct timespec rqt, ctime, rmt;
    431       1.22    kardel 	int error, timo;
    432        1.1       mrg 
    433       1.27       dsl 	error = copyin(SCARG_P32(uap, rqtp), &ts32, sizeof(ts32));
    434        1.1       mrg 	if (error)
    435        1.1       mrg 		return (error);
    436        1.1       mrg 
    437        1.1       mrg 	netbsd32_to_timespec(&ts32, &rqt);
    438  1.32.10.1      yamt 	if (itimespecfix(&rqt))
    439        1.1       mrg 		return (EINVAL);
    440        1.1       mrg 
    441  1.32.10.1      yamt 	getnanotime(&ctime);
    442  1.32.10.1      yamt 	timespecadd(&rqt, &ctime, &rqt);
    443  1.32.10.1      yamt 	timo = tshzto(&rqt);
    444        1.8     perry 	/*
    445        1.1       mrg 	 * Avoid inadvertantly sleeping forever
    446        1.1       mrg 	 */
    447        1.1       mrg 	if (timo == 0)
    448        1.1       mrg 		timo = 1;
    449        1.1       mrg 
    450        1.1       mrg 	error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
    451        1.1       mrg 	if (error == ERESTART)
    452        1.1       mrg 		error = EINTR;
    453        1.1       mrg 	if (error == EWOULDBLOCK)
    454        1.1       mrg 		error = 0;
    455        1.1       mrg 
    456       1.26       dsl 	if (SCARG_P32(uap, rmtp)) {
    457        1.9  christos 		int error1;
    458        1.1       mrg 
    459  1.32.10.1      yamt 		getnanotime(&rmt);
    460        1.1       mrg 
    461  1.32.10.1      yamt 		timespecsub(&rqt, &rmt, &rmt);
    462  1.32.10.1      yamt 		if (rmt.tv_sec < 0)
    463  1.32.10.1      yamt 			timespecclear(&rmt);
    464        1.1       mrg 
    465        1.1       mrg 		netbsd32_from_timespec(&rmt, &ts32);
    466       1.27       dsl 		error1 = copyout(&ts32, SCARG_P32(uap,rmtp), sizeof(ts32));
    467        1.9  christos 		if (error1)
    468        1.9  christos 			return (error1);
    469        1.1       mrg 	}
    470        1.1       mrg 
    471        1.1       mrg 	return error;
    472        1.1       mrg }
    473       1.11      cube 
    474       1.11      cube static int
    475       1.11      cube netbsd32_timer_create_fetch(const void *src, void *dst, size_t size)
    476       1.11      cube {
    477       1.11      cube 	struct sigevent *evp = dst;
    478       1.11      cube 	struct netbsd32_sigevent ev32;
    479       1.11      cube 	int error;
    480       1.11      cube 
    481       1.11      cube 	error = copyin(src, &ev32, sizeof(ev32));
    482       1.11      cube 	if (error)
    483       1.11      cube 		return error;
    484       1.11      cube 
    485       1.11      cube 	netbsd32_to_sigevent(&ev32, evp);
    486       1.11      cube 	return 0;
    487       1.11      cube }
    488       1.11      cube 
    489       1.11      cube int
    490       1.30       dsl netbsd32_timer_create(struct lwp *l, const struct netbsd32_timer_create_args *uap, register_t *retval)
    491       1.11      cube {
    492       1.30       dsl 	/* {
    493       1.11      cube 		syscallarg(netbsd32_clockid_t) clock_id;
    494       1.11      cube 		syscallarg(netbsd32_sigeventp_t) evp;
    495       1.11      cube 		syscallarg(netbsd32_timerp_t) timerid;
    496       1.30       dsl 	} */
    497       1.11      cube 
    498       1.27       dsl 	return timer_create1(SCARG_P32(uap, timerid),
    499       1.27       dsl 	    SCARG(uap, clock_id), SCARG_P32(uap, evp),
    500       1.23        ad 	    netbsd32_timer_create_fetch, l);
    501       1.11      cube }
    502       1.11      cube 
    503       1.11      cube int
    504       1.30       dsl netbsd32_timer_delete(struct lwp *l, const struct netbsd32_timer_delete_args *uap, register_t *retval)
    505       1.11      cube {
    506       1.30       dsl 	/* {
    507       1.11      cube 		syscallarg(netbsd32_timer_t) timerid;
    508       1.30       dsl 	} */
    509       1.11      cube 	struct sys_timer_delete_args ua;
    510       1.11      cube 
    511       1.11      cube 	NETBSD32TO64_UAP(timerid);
    512       1.11      cube 	return sys_timer_delete(l, (void *)&ua, retval);
    513       1.11      cube }
    514       1.11      cube 
    515       1.11      cube int
    516  1.32.10.1      yamt netbsd32___timer_settime50(struct lwp *l, const struct netbsd32___timer_settime50_args *uap, register_t *retval)
    517       1.11      cube {
    518       1.30       dsl 	/* {
    519       1.11      cube 		syscallarg(netbsd32_timer_t) timerid;
    520       1.11      cube 		syscallarg(int) flags;
    521       1.11      cube 		syscallarg(const netbsd32_itimerspecp_t) value;
    522       1.11      cube 		syscallarg(netbsd32_itimerspecp_t) ovalue;
    523       1.30       dsl 	} */
    524       1.11      cube 	int error;
    525       1.11      cube 	struct itimerspec value, ovalue, *ovp = NULL;
    526       1.11      cube 	struct netbsd32_itimerspec its32;
    527       1.11      cube 
    528       1.27       dsl 	if ((error = copyin(SCARG_P32(uap, value), &its32, sizeof(its32))) != 0)
    529       1.11      cube 		return (error);
    530       1.11      cube 	netbsd32_to_timespec(&its32.it_interval, &value.it_interval);
    531       1.11      cube 	netbsd32_to_timespec(&its32.it_value, &value.it_value);
    532       1.11      cube 
    533       1.26       dsl 	if (SCARG_P32(uap, ovalue))
    534       1.11      cube 		ovp = &ovalue;
    535       1.11      cube 
    536       1.11      cube 	if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
    537       1.11      cube 	    SCARG(uap, flags), l->l_proc)) != 0)
    538       1.11      cube 		return error;
    539       1.11      cube 
    540       1.11      cube 	if (ovp) {
    541       1.11      cube 		netbsd32_from_timespec(&ovp->it_interval, &its32.it_interval);
    542       1.11      cube 		netbsd32_from_timespec(&ovp->it_value, &its32.it_value);
    543       1.27       dsl 		return copyout(&its32, SCARG_P32(uap, ovalue), sizeof(its32));
    544       1.11      cube 	}
    545       1.11      cube 	return 0;
    546       1.11      cube }
    547       1.11      cube 
    548       1.11      cube int
    549  1.32.10.1      yamt netbsd32___timer_gettime50(struct lwp *l, const struct netbsd32___timer_gettime50_args *uap, register_t *retval)
    550       1.11      cube {
    551       1.30       dsl 	/* {
    552       1.11      cube 		syscallarg(netbsd32_timer_t) timerid;
    553       1.11      cube 		syscallarg(netbsd32_itimerspecp_t) value;
    554       1.30       dsl 	} */
    555       1.11      cube 	int error;
    556       1.11      cube 	struct itimerspec its;
    557       1.11      cube 	struct netbsd32_itimerspec its32;
    558       1.11      cube 
    559       1.11      cube 	if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
    560       1.11      cube 	    &its)) != 0)
    561       1.11      cube 		return error;
    562       1.11      cube 
    563       1.11      cube 	netbsd32_from_timespec(&its.it_interval, &its32.it_interval);
    564       1.11      cube 	netbsd32_from_timespec(&its.it_value, &its32.it_value);
    565       1.11      cube 
    566       1.27       dsl 	return copyout(&its32, SCARG_P32(uap, value), sizeof(its32));
    567       1.11      cube }
    568       1.11      cube 
    569       1.11      cube int
    570       1.30       dsl netbsd32_timer_getoverrun(struct lwp *l, const struct netbsd32_timer_getoverrun_args *uap, register_t *retval)
    571       1.11      cube {
    572       1.30       dsl 	/* {
    573       1.11      cube 		syscallarg(netbsd32_timer_t) timerid;
    574       1.30       dsl 	} */
    575       1.11      cube 	struct sys_timer_getoverrun_args ua;
    576       1.11      cube 
    577       1.11      cube 	NETBSD32TO64_UAP(timerid);
    578       1.11      cube 	return sys_timer_getoverrun(l, (void *)&ua, retval);
    579       1.11      cube }
    580