@@ -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
@@ -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 */
@@ -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)
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(+)