1*1e72df6aStsutsui /* $NetBSD: kern_time_30.c,v 1.8 2019/12/15 16:48:26 tsutsui Exp $ */
2461a86f9Schristos
3461a86f9Schristos /*-
4461a86f9Schristos * Copyright (c) 2008 The NetBSD Foundation, Inc.
5461a86f9Schristos * All rights reserved.
6461a86f9Schristos *
7461a86f9Schristos * This code is derived from software contributed to The NetBSD Foundation
8461a86f9Schristos * by Christos Zoulas.
9461a86f9Schristos *
10461a86f9Schristos * Redistribution and use in source and binary forms, with or without
11461a86f9Schristos * modification, are permitted provided that the following conditions
12461a86f9Schristos * are met:
13461a86f9Schristos * 1. Redistributions of source code must retain the above copyright
14461a86f9Schristos * notice, this list of conditions and the following disclaimer.
15461a86f9Schristos * 2. Redistributions in binary form must reproduce the above copyright
16461a86f9Schristos * notice, this list of conditions and the following disclaimer in the
17461a86f9Schristos * documentation and/or other materials provided with the distribution.
18461a86f9Schristos *
19461a86f9Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20461a86f9Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21461a86f9Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22461a86f9Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23461a86f9Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24461a86f9Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25461a86f9Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26461a86f9Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27461a86f9Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28461a86f9Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29461a86f9Schristos * POSSIBILITY OF SUCH DAMAGE.
30461a86f9Schristos */
31461a86f9Schristos #include <sys/cdefs.h>
32*1e72df6aStsutsui __KERNEL_RCSID(0, "$NetBSD: kern_time_30.c,v 1.8 2019/12/15 16:48:26 tsutsui Exp $");
33461a86f9Schristos
3400d7b5f1Sriastradh #ifdef _KERNEL_OPT
35d91f98a8Spgoyette #include "opt_compat_netbsd.h"
36461a86f9Schristos #include "opt_ntp.h"
3700d7b5f1Sriastradh #endif
38461a86f9Schristos
39461a86f9Schristos #include <sys/param.h>
40461a86f9Schristos #include <sys/systm.h>
41461a86f9Schristos #include <sys/time.h>
42461a86f9Schristos #include <sys/timex.h>
43d91f98a8Spgoyette #include <sys/syscall.h>
44d91f98a8Spgoyette #include <sys/syscallvar.h>
45d91f98a8Spgoyette #include <sys/syscallargs.h>
46d91f98a8Spgoyette #include <sys/compat_stub.h>
47461a86f9Schristos
48d91f98a8Spgoyette #include <compat/common/compat_mod.h>
49461a86f9Schristos #include <compat/common/compat_util.h>
50461a86f9Schristos #include <compat/sys/time.h>
51461a86f9Schristos #include <compat/sys/timex.h>
52461a86f9Schristos
53d91f98a8Spgoyette static const struct syscall_package kern_time_30_syscalls[] = {
54d91f98a8Spgoyette { SYS_compat_30_ntp_gettime, 0,
55d91f98a8Spgoyette (sy_call_t *)compat_30_sys_ntp_gettime },
56d91f98a8Spgoyette { 0, 0, NULL }
57d91f98a8Spgoyette };
58461a86f9Schristos
59461a86f9Schristos int
compat_30_sys_ntp_gettime(struct lwp * l,const struct compat_30_sys_ntp_gettime_args * uap,register_t * retval)60461a86f9Schristos compat_30_sys_ntp_gettime(struct lwp *l,
61461a86f9Schristos const struct compat_30_sys_ntp_gettime_args *uap, register_t *retval)
62461a86f9Schristos {
63461a86f9Schristos /* {
64461a86f9Schristos syscallarg(struct ntptimeval30 *) ontvp;
65461a86f9Schristos } */
66461a86f9Schristos struct ntptimeval ntv;
67461a86f9Schristos struct ntptimeval30 ntv30;
68461a86f9Schristos struct timeval tv;
69461a86f9Schristos int error;
70461a86f9Schristos
71d91f98a8Spgoyette if (vec_ntp_gettime == NULL)
72d91f98a8Spgoyette return ENOSYS;
73d91f98a8Spgoyette
74461a86f9Schristos if (SCARG(uap, ntvp)) {
75d91f98a8Spgoyette (*vec_ntp_gettime)(&ntv);
761c1a7824Sriastradh memset(&ntv30, 0, sizeof(ntv30));
77461a86f9Schristos TIMESPEC_TO_TIMEVAL(&tv, &ntv.time);
78461a86f9Schristos timeval_to_timeval50(&tv, &ntv30.time);
79461a86f9Schristos ntv30.maxerror = ntv.maxerror;
80461a86f9Schristos ntv30.esterror = ntv.esterror;
81461a86f9Schristos
82461a86f9Schristos error = copyout(&ntv30, SCARG(uap, ntvp), sizeof(ntv30));
83461a86f9Schristos if (error)
84461a86f9Schristos return error;
85461a86f9Schristos }
86d91f98a8Spgoyette *retval = (*vec_ntp_timestatus)();
87461a86f9Schristos return 0;
88d91f98a8Spgoyette }
89d91f98a8Spgoyette
90d91f98a8Spgoyette int
kern_time_30_init(void)91d91f98a8Spgoyette kern_time_30_init(void)
92d91f98a8Spgoyette {
93d91f98a8Spgoyette
94d91f98a8Spgoyette return syscall_establish(NULL, kern_time_30_syscalls);
95d91f98a8Spgoyette }
96d91f98a8Spgoyette
97d91f98a8Spgoyette int
kern_time_30_fini(void)98d91f98a8Spgoyette kern_time_30_fini(void)
99d91f98a8Spgoyette {
100d91f98a8Spgoyette
101d91f98a8Spgoyette return syscall_disestablish(NULL, kern_time_30_syscalls);
102461a86f9Schristos }
103