From: chensong <[email protected]>

Adding a new syscall clock_settime64 which is y2038 safe

Signed-off-by: chensong <[email protected]>
[Florian: Reword commit msg]
Reviewed-by: Florian Bezdeka <[email protected]>
---
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/clock.c     | 17 +++++++++++++++++
 kernel/cobalt/posix/clock.h     |  7 +++++++
 kernel/cobalt/posix/syscall32.c |  7 +++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 5 files changed, 36 insertions(+)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 985996339..438af30ad 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -124,6 +124,7 @@
 #define sc_cobalt_thread_setschedprio          101
 #define sc_cobalt_sem_timedwait64              102
 #define sc_cobalt_clock_gettime64              103
+#define sc_cobalt_clock_settime64              104
 
 #define __NR_COBALT_SYSCALLS                   128 /* Power of 2 */
 
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index 34faf23bb..a30ed6c4b 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -219,6 +219,23 @@ COBALT_SYSCALL(clock_settime, current,
        return __cobalt_clock_settime(clock_id, &ts);
 }
 
+int __cobalt_clock_settime64(clockid_t clock_id,
+                       const struct __kernel_timespec __user *u_ts)
+{
+       struct timespec64 ts64;
+
+       if (cobalt_get_timespec64(&ts64, u_ts))
+               return -EFAULT;
+
+       return __cobalt_clock_settime(clock_id, &ts64);
+}
+
+COBALT_SYSCALL(clock_settime64, current,
+              (clockid_t clock_id, const struct __kernel_timespec __user 
*u_ts))
+{
+       return __cobalt_clock_settime64(clock_id, u_ts);
+}
+
 COBALT_SYSCALL(clock_adjtime, current,
               (clockid_t clock_id, struct __user_old_timex __user *u_tx))
 {
diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
index 639f03093..74c71c826 100644
--- a/kernel/cobalt/posix/clock.h
+++ b/kernel/cobalt/posix/clock.h
@@ -106,6 +106,9 @@ int __cobalt_clock_gettime64(clockid_t clock_id,
 int __cobalt_clock_settime(clockid_t clock_id,
                           const struct timespec64 *ts);
 
+int __cobalt_clock_settime64(clockid_t clock_id,
+                       const struct __kernel_timespec __user *u_ts);
+
 int __cobalt_clock_adjtime(clockid_t clock_id,
                           struct __kernel_timex *tx);
 
@@ -125,6 +128,10 @@ COBALT_SYSCALL_DECL(clock_gettime64,
 COBALT_SYSCALL_DECL(clock_settime,
                    (clockid_t clock_id, const struct __user_old_timespec 
__user *u_ts));
 
+COBALT_SYSCALL_DECL(clock_settime64,
+                   (clockid_t clock_id,
+                        const struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL_DECL(clock_adjtime,
                    (clockid_t clock_id, struct __user_old_timex __user *u_tx));
 
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index 138779011..464d7a8dd 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -191,6 +191,13 @@ COBALT_SYSCALL32emu(clock_settime, current,
        return __cobalt_clock_settime(clock_id, &ts);
 }
 
+COBALT_SYSCALL32emu(clock_settime64, current,
+                   (clockid_t clock_id,
+                    const struct __kernel_timespec __user *u_ts))
+{
+       return __cobalt_clock_settime64(clock_id, u_ts);
+}
+
 COBALT_SYSCALL32emu(clock_adjtime, current,
                    (clockid_t clock_id, struct old_timex32 __user *u_tx))
 {
diff --git a/kernel/cobalt/posix/syscall32.h b/kernel/cobalt/posix/syscall32.h
index a6e3aff65..4ec5ee599 100644
--- a/kernel/cobalt/posix/syscall32.h
+++ b/kernel/cobalt/posix/syscall32.h
@@ -67,6 +67,10 @@ COBALT_SYSCALL32emu_DECL(clock_settime,
                         (clockid_t clock_id,
                          const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(clock_settime64,
+                        (clockid_t clock_id,
+                         const struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL32emu_DECL(clock_adjtime,
                         (clockid_t clock_id,
                          struct old_timex32 __user *u_tx));
-- 
2.31.1


Reply via email to