From 5d8add091b49510e2536a1ca93215bbec8c011f0 Mon Sep 17 00:00:00 2001 From: Nicolas Joly Date: Thu, 17 Apr 2008 17:47:23 +0000 Subject: [PATCH] Add compat linux32 sys_clock_{getres,gettime,settime} syscalls. --- sys/compat/linux/common/linux_sched.h | 4 +- sys/compat/linux/common/linux_time.c | 8 +- sys/compat/linux32/arch/amd64/syscalls.master | 11 ++- sys/compat/linux32/common/linux32_time.c | 105 +++++++++++++++++++++++++- sys/compat/linux32/common/linux32_types.h | 8 +- 5 files changed, 122 insertions(+), 14 deletions(-) diff --git a/sys/compat/linux/common/linux_sched.h b/sys/compat/linux/common/linux_sched.h index 7d5f317d440..1c600d4b865 100644 --- a/sys/compat/linux/common/linux_sched.h +++ b/sys/compat/linux/common/linux_sched.h @@ -1,4 +1,4 @@ -/* $NetBSD: linux_sched.h,v 1.2.36.3 2005/11/10 14:01:07 skrll Exp $ */ +/* $NetBSD: linux_sched.h,v 1.5 2005/12/11 12:20:19 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -88,4 +88,6 @@ struct linux_timespec { #define LINUX_CLOCK_REALTIME_HR 4 #define LINUX_CLOCK_MONOTONIC_HR 5 +int linux_to_native_clockid(clockid_t *, clockid_t); + #endif /* _LINUX_SCHED_H */ diff --git a/sys/compat/linux/common/linux_time.c b/sys/compat/linux/common/linux_time.c index 420ccde0280..f31298f4564 100644 --- a/sys/compat/linux/common/linux_time.c +++ b/sys/compat/linux/common/linux_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_time.c,v 1.21 2007/12/08 18:36:10 dsl Exp $ */ +/* $NetBSD: linux_time.c,v 1.22 2007/12/20 23:02:57 dsl Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.21 2007/12/08 18:36:10 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.22 2007/12/20 23:02:57 dsl Exp $"); #include #include @@ -67,8 +67,6 @@ static void native_to_linux_timespec(struct linux_timespec *, struct timespec *); static void linux_to_native_timespec(struct timespec *, struct linux_timespec *); -static int linux_to_native_clockid(clockid_t *, clockid_t); - /* * This is not implemented for alpha yet */ @@ -151,7 +149,7 @@ linux_to_native_timespec(struct timespec *ntp, struct linux_timespec *ltp) ntp->tv_nsec = ltp->tv_nsec; } -static int +int linux_to_native_clockid(clockid_t *n, clockid_t l) { switch (l) { diff --git a/sys/compat/linux32/arch/amd64/syscalls.master b/sys/compat/linux32/arch/amd64/syscalls.master index fa1afad683a..97e60800a79 100644 --- a/sys/compat/linux32/arch/amd64/syscalls.master +++ b/sys/compat/linux32/arch/amd64/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.31 2008/02/20 21:49:56 njoly Exp $ + $NetBSD: syscalls.master,v 1.32 2008/04/04 12:57:55 njoly Exp $ ; NetBSD i386 COMPAT_LINUX32 system call name/number "master" file. ; (See syscalls.conf to see what it is processed into.) @@ -418,9 +418,12 @@ 261 UNIMPL timer_gettime 262 UNIMPL timer_getoverrun 263 UNIMPL timer_delete -264 UNIMPL clock_settime -265 UNIMPL clock_gettime -266 UNIMPL clock_getres +264 STD { int linux32_sys_clock_settime(clockid_t which, \ + linux32_timespecp_t tp); } +265 STD { int linux32_sys_clock_gettime(clockid_t which, \ + linux32_timespecp_t tp); } +266 STD { int linux32_sys_clock_getres(clockid_t which, \ + linux32_timespecp_t tp); } 267 UNIMPL clock_nanosleep 268 UNIMPL statfs64 269 UNIMPL fstatfs64 diff --git a/sys/compat/linux32/common/linux32_time.c b/sys/compat/linux32/common/linux32_time.c index 6c3d62ec3a9..a068fae61bf 100644 --- a/sys/compat/linux32/common/linux32_time.c +++ b/sys/compat/linux32/common/linux32_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_time.c,v 1.16 2007/12/20 23:02:59 dsl Exp $ */ +/* $NetBSD: linux32_time.c,v 1.17 2008/03/27 19:06:51 ad Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -33,7 +33,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.16 2007/12/20 23:02:59 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.17 2008/03/27 19:06:51 ad Exp $"); #include #include @@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.16 2007/12/20 23:02:59 dsl Exp $" #include #include #include +#include #include @@ -64,6 +65,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.16 2007/12/20 23:02:59 dsl Exp $" #include #include #include +#include #include #include @@ -74,6 +76,12 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.16 2007/12/20 23:02:59 dsl Exp $" #include extern struct timezone linux_sys_tz; + +static __inline void +native_to_linux32_timespec(struct linux32_timespec *, struct timespec *); +static __inline void +linux32_to_native_timespec(struct timespec *, struct linux32_timespec *); + int linux32_sys_gettimeofday(struct lwp *l, const struct linux32_sys_gettimeofday_args *uap, register_t *retval) { @@ -224,4 +232,95 @@ linux32_sys_utime(struct lwp *l, const struct linux32_sys_utime_args *uap, regis return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW, tvp, UIO_SYSSPACE); -} +} + +static __inline void +native_to_linux32_timespec(struct linux32_timespec *ltp, struct timespec *ntp) +{ + ltp->tv_sec = ntp->tv_sec; + ltp->tv_nsec = ntp->tv_nsec; +} + +static __inline void +linux32_to_native_timespec(struct timespec *ntp, struct linux32_timespec *ltp) +{ + ntp->tv_sec = ltp->tv_sec; + ntp->tv_nsec = ltp->tv_nsec; +} + +int +linux32_sys_clock_settime(struct lwp *l, + const struct linux32_sys_clock_settime_args *uap, register_t *retval) +{ + /* { + syscallarg(clockid_t) which; + syscallarg(linux32_timespecp_t) tp; + } */ + int error; + struct timespec ts; + struct linux32_timespec lts; + + switch (SCARG(uap, which)) { + case LINUX_CLOCK_REALTIME: + break; + default: + return EINVAL; + } + + if ((error = copyin(SCARG_P32(uap, tp), <s, sizeof lts))) + return error; + + linux32_to_native_timespec(&ts, <s); + return settime(l->l_proc, &ts); +} + +int +linux32_sys_clock_gettime(struct lwp *l, + const struct linux32_sys_clock_gettime_args *uap, register_t *retval) +{ + /* { + syscallarg(clockid_t) which; + syscallarg(linux32_timespecp_t) tp; + } */ + struct timespec ts; + struct linux32_timespec lts; + + switch (SCARG(uap, which)) { + case LINUX_CLOCK_REALTIME: + nanotime(&ts); + break; + case LINUX_CLOCK_MONOTONIC: + nanouptime(&ts); + break; + default: + return EINVAL; + } + + native_to_linux32_timespec(<s, &ts); + return copyout(<s, SCARG_P32(uap, tp), sizeof lts); +} + +int +linux32_sys_clock_getres(struct lwp *l, + const struct linux32_sys_clock_getres_args *uap, register_t *retval) +{ + /* { + syscallarg(clockid_t) which; + syscallarg(linux32_timespecp_t) tp; + } */ + int error; + clockid_t id; + struct timespec ts; + struct linux32_timespec lts; + + error = linux_to_native_clockid(&id, SCARG(uap, which)); + if (error != 0 || SCARG_P32(uap, tp) == NULL) + return error; + + ts.tv_sec = 0; + ts.tv_nsec = 1000000000 / tc_getfrequency(); + native_to_linux32_timespec(<s, &ts); + return copyout(<s, SCARG_P32(uap, tp), sizeof lts); + + return 0; +} diff --git a/sys/compat/linux32/common/linux32_types.h b/sys/compat/linux32/common/linux32_types.h index 1bb5037b87c..ab1bf3be654 100644 --- a/sys/compat/linux32/common/linux32_types.h +++ b/sys/compat/linux32/common/linux32_types.h @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_types.h,v 1.5 2007/12/24 15:56:21 njoly Exp $ */ +/* $NetBSD: linux32_types.h,v 1.6 2008/01/15 22:38:35 njoly Exp $ */ /*- * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. @@ -61,6 +61,7 @@ typedef netbsd32_pointer_t linux32_gid16p_t; typedef netbsd32_pointer_t linux32_oldselectp_t; typedef netbsd32_pointer_t linux32_sysinfop_t; typedef netbsd32_pointer_t linux32_oldutsnamep_t; +typedef netbsd32_pointer_t linux32_timespecp_t; struct linux32_sysctl { netbsd32_intp name; @@ -103,4 +104,9 @@ struct linux32_sysinfo { char _f[20-2*sizeof(netbsd32_long)-sizeof(int)]; }; +struct linux32_timespec { + linux32_time_t tv_sec; + netbsd32_long tv_nsec; +}; + #endif /* !_LINUX32_TYPES_H */ -- 2.11.4.GIT