Messages in this thread Patch in this message | | | From | Bamvor Zhang Jian <> | Subject | [RFC PATCH v2 2/4] time64: add timeval64 helper for compat syscalls | Date | Mon, 29 Jun 2015 22:23:25 +0800 |
| |
Add __kernel_compat_timeval in uapi in order to use it in ioctl command because compat_timeval is invisible in uapi. Meanwhile We could avoid to define it by using the __s32 array in ioctl command definition. I am sure which one is the better way. Any suggestion or input is welcome.
This patch also define compat_get_timeval64, compat_put_timeval64 for converting between compat_timeval and timeval64.
Signed-off-by: Bamvor Zhang Jian <bamvor.zhangjian@linaro.org> --- include/linux/compat.h | 3 +++ include/uapi/linux/time.h | 6 ++++++ kernel/compat.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+)
diff --git a/include/linux/compat.h b/include/linux/compat.h index ab25814..14569a7 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -154,6 +154,9 @@ extern int compat_get_timespec(struct timespec *, const void __user *); extern int compat_put_timespec(const struct timespec *, void __user *); extern int compat_get_timeval(struct timeval *, const void __user *); extern int compat_put_timeval(const struct timeval *, void __user *); +struct timeval64; +extern int compat_get_timeval64(struct timeval64 *tv, const struct compat_timeval __user *ctv); +extern int compat_put_timeval64(const struct timeval64 *tv, struct compat_timeval __user *ctv); /* * This function convert a timespec if necessary and returns a *user diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 2ca6a31..9f6093e 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -76,4 +76,10 @@ struct __kernel_timeval { }; #endif +typedef __s32 __kernel_time32_t; +struct __kernel_compat_timeval { + __kernel_time32_t tv_sec; + __s32 tv_usec; +}; + #endif /* _UAPI_LINUX_TIME_H */ diff --git a/kernel/compat.c b/kernel/compat.c index 333d364..ebe45b4 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -172,6 +172,23 @@ int compat_put_timeval(const struct timeval *tv, void __user *utv) } EXPORT_SYMBOL_GPL(compat_put_timeval); +int compat_get_timeval64(struct timeval64 *tv, const struct compat_timeval __user *ctv) +{ + return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) || + __get_user(tv->tv_sec, &ctv->tv_sec) || + __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; +} +EXPORT_SYMBOL_GPL(compat_get_timeval64); + +/* TODO: is it ok that just put to user without implicit cast? */ +int compat_put_timeval64(const struct timeval64 *tv, struct compat_timeval *ctv) +{ + return (!access_ok(VERIFY_WRITE, ctv, sizeof(*ctv)) || + __put_user(tv->tv_sec, &ctv->tv_sec) || + __put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; +} +EXPORT_SYMBOL_GPL(compat_put_timeval64); + int compat_get_timespec(struct timespec *ts, const void __user *uts) { if (COMPAT_USE_64BIT_TIME) -- 2.1.4
| |