1 /* $NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $");
45 #include "opt_compat.h"
47 #include <sys/param.h>
48 #include <sys/ucred.h>
49 #include <sys/mount.h>
50 #include <sys/signal.h>
51 #include <sys/stdint.h>
52 #include <sys/syscallsubr.h>
53 #include <sys/sysproto.h>
55 #include <sys/systm.h>
59 #include <machine/../linux32/linux.h>
60 #include <machine/../linux32/linux32_proto.h>
62 #include <machine/../linux/linux.h>
63 #include <machine/../linux/linux_proto.h>
66 static void native_to_linux_timespec(struct l_timespec *,
68 static int linux_to_native_timespec(struct timespec *,
70 static int linux_to_native_clockid(clockid_t *, clockid_t);
73 native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
75 ltp->tv_sec = ntp->tv_sec;
76 ltp->tv_nsec = ntp->tv_nsec;
80 linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
82 if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L)
84 ntp->tv_sec = ltp->tv_sec;
85 ntp->tv_nsec = ltp->tv_nsec;
91 linux_to_native_clockid(clockid_t *n, clockid_t l)
94 case LINUX_CLOCK_REALTIME:
97 case LINUX_CLOCK_MONOTONIC:
100 case LINUX_CLOCK_PROCESS_CPUTIME_ID:
101 case LINUX_CLOCK_THREAD_CPUTIME_ID:
102 case LINUX_CLOCK_REALTIME_HR:
103 case LINUX_CLOCK_MONOTONIC_HR:
113 linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
115 struct l_timespec lts;
117 clockid_t nwhich = 0; /* XXX: GCC */
120 error = linux_to_native_clockid(&nwhich, args->which);
123 error = kern_clock_gettime(td, nwhich, &tp);
126 native_to_linux_timespec(<s, &tp);
128 return (copyout(<s, args->tp, sizeof lts));
132 linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
135 struct l_timespec lts;
137 clockid_t nwhich = 0; /* XXX: GCC */
139 error = linux_to_native_clockid(&nwhich, args->which);
142 error = copyin(args->tp, <s, sizeof lts);
145 error = linux_to_native_timespec(&ts, <s);
149 return (kern_clock_settime(td, nwhich, &ts));
153 linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
156 struct l_timespec lts;
158 clockid_t nwhich = 0; /* XXX: GCC */
160 if (args->tp == NULL)
163 error = linux_to_native_clockid(&nwhich, args->which);
166 error = kern_clock_getres(td, nwhich, &ts);
169 native_to_linux_timespec(<s, &ts);
171 return (copyout(<s, args->tp, sizeof lts));
175 linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
177 struct timespec *rmtp;
178 struct l_timespec lrqts, lrmts;
179 struct timespec rqts, rmts;
182 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
186 if (args->rmtp != NULL)
191 error = linux_to_native_timespec(&rqts, &lrqts);
194 error = kern_nanosleep(td, &rqts, rmtp);
198 if (args->rmtp != NULL) {
199 native_to_linux_timespec(&lrmts, rmtp);
200 error = copyout(&lrmts, args->rmtp, sizeof(lrmts));
209 linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args)
211 struct timespec *rmtp;
212 struct l_timespec lrqts, lrmts;
213 struct timespec rqts, rmts;
216 if (args->flags != 0)
217 return (EINVAL); /* XXX deal with TIMER_ABSTIME */
219 if (args->which != LINUX_CLOCK_REALTIME)
222 error = copyin(args->rqtp, &lrqts, sizeof lrqts);
226 if (args->rmtp != NULL)
231 error = linux_to_native_timespec(&rqts, &lrqts);
234 error = kern_nanosleep(td, &rqts, rmtp);
238 if (args->rmtp != NULL) {
239 native_to_linux_timespec(&lrmts, rmtp);
240 error = copyout(&lrmts, args->rmtp, sizeof lrmts );