Skip to contentSkip to conversation

y2038: cobalt/posix/clock: Adding clock_gettime64

PATCH In review Song Chen 2 participants 4 messages Apr 21, 2021 – Apr 23, 2021

lore
Share & tools
lore

Song Chen

author
#0 lore raw

PATCH v5 1/5 y2038: cobalt/posix/clock: Adding clock_gettime64

From: chensong <[email protected]>

Add a syscall specific for clock_gettime with 64bit time_t.

---
v5:
1, new helper __cobalt_clock_gettime64

---
 include/cobalt/kernel/time.h    | 11 +++++++++++
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/clock.c     | 23 ++++++++++++++++++++++-
 kernel/cobalt/posix/clock.h     |  6 ++++++
 kernel/cobalt/posix/syscall32.c |  8 ++++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 kernel/cobalt/time.c            | 11 +++++++++++
 7 files changed, 63 insertions(+), 1 deletion(-)
include/cobalt/kernel/time.h +11 -0
index 19e8f2c..2890e25 100644
@@ -19,4 +19,15 @@
 int cobalt_get_timespec64(struct timespec64 *ts,
 			  const struct __kernel_timespec __user *uts);
 
+/**
+ * Covert struct timespec64 to struct __kernel_timespec
+ * and copy to userspace
+ *
+ * @param ts The source, provided by kernel
+ * @param uts The destination, will be filled
+ * @return 0 on success, -EFAULT otherwise
+ */
+int cobalt_put_timespec64(const struct timespec64 *ts,
+			   struct __kernel_timespec __user *uts);
+
 #endif //_COBALT_KERNEL_TIME_H
include/cobalt/uapi/syscall.h +1 -0
index 8895d2b..9859963 100644
@@ -123,6 +123,7 @@
 #define sc_cobalt_clock_adjtime			100
 #define sc_cobalt_thread_setschedprio		101
 #define sc_cobalt_sem_timedwait64		102
+#define sc_cobalt_clock_gettime64		103
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/clock.c +22 -1
index 6a47956..9127013 100644
@@ -23,6 +23,7 @@
 #include "thread.h"
 #include "clock.h"
 #include <trace/events/cobalt-posix.h>
+#include <cobalt/kernel/time.h>
 
 static struct xnclock *external_clocks[COBALT_MAX_EXTCLOCKS];
 
@@ -134,11 +135,31 @@ COBALT_SYSCALL(clock_gettime, current,
 	if (cobalt_put_u_timespec(u_ts, &ts))
 		return -EFAULT;
 
-	trace_cobalt_clock_gettime(clock_id, &ts);
+	return 0;
+}
+
+int __cobalt_clock_gettime64(clockid_t clock_id,
+			struct __kernel_timespec __user *u_ts)
+{
+	struct timespec64 ts;
+	int ret;
+
+	ret = __cobalt_clock_gettime(clock_id, &ts);
+	if (ret)
+		return ret;
+
+	if (cobalt_put_timespec64(&ts, u_ts))
+		return -EFAULT;
 
 	return 0;
 }
 
+COBALT_SYSCALL(clock_gettime64, current,
+	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	
+}
+
 int __cobalt_clock_settime(clockid_t clock_id, const struct timespec64 *ts)
 {
 	int _ret, ret = 0;
kernel/cobalt/posix/clock.h +6 -0
index e69e76e..639f030 100644
@@ -100,6 +100,9 @@ int __cobalt_clock_getres(clockid_t clock_id,
 int __cobalt_clock_gettime(clockid_t clock_id,
 			   struct timespec64 *ts);
 
+int __cobalt_clock_gettime64(clockid_t clock_id,
+			struct __kernel_timespec __user *u_ts);
+
 int __cobalt_clock_settime(clockid_t clock_id,
 			   const struct timespec64 *ts);
 
@@ -116,6 +119,9 @@ COBALT_SYSCALL_DECL(clock_getres,
 COBALT_SYSCALL_DECL(clock_gettime,
 		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
+COBALT_SYSCALL_DECL(clock_gettime64,
+		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL_DECL(clock_settime,
 		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
 
kernel/cobalt/posix/syscall32.c +8 -0
index a5dc6e4..5770ebc 100644
@@ -35,6 +35,7 @@
 #include "mqueue.h"
 #include "io.h"
 #include "../debug.h"
+#include <cobalt/kernel/time.h>
 
 COBALT_SYSCALL32emu(thread_create, init,
 		    (compat_ulong_t pth,
@@ -170,6 +171,13 @@ COBALT_SYSCALL32emu(clock_gettime, current,
 	return sys32_put_timespec(u_ts, &ts);
 }
 
+COBALT_SYSCALL32emu(clock_gettime64, current,
+		    (clockid_t clock_id,
+		     struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	
+}
+
 COBALT_SYSCALL32emu(clock_settime, current,
 		    (clockid_t clock_id,
 		     const struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index 0b5e26d..68067e6 100644
@@ -59,6 +59,10 @@ COBALT_SYSCALL32emu_DECL(clock_gettime,
 			 (clockid_t clock_id,
 			  struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(clock_gettime64,
+			 (clockid_t clock_id,
+			  struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL32emu_DECL(clock_settime,
 			 (clockid_t clock_id,
 			  const struct old_timespec32 __user *u_ts));
kernel/cobalt/time.c +11 -0
index a3fd8a7..4091def 100644
@@ -27,3 +27,14 @@ int cobalt_get_timespec64(struct timespec64 *ts,
 
 	return 0;
 }
+
+int cobalt_put_timespec64(const struct timespec64 *ts,
+		   struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts = {
+		.tv_sec = ts->tv_sec,
+		.tv_nsec = ts->tv_nsec
+	};
+
+	return cobalt_copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
+}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 20 lines · Song Chen

From: chensong <[email protected]>

Add a syscall specific for clock_gettime with 64bit time_t.

---
v5:
1, new helper __cobalt_clock_gettime64
---

 include/cobalt/kernel/time.h    | 11 +++++++++++
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/clock.c     | 23 ++++++++++++++++++++++-
 kernel/cobalt/posix/clock.h     |  6 ++++++
 kernel/cobalt/posix/syscall32.c |  8 ++++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 kernel/cobalt/time.c            | 11 +++++++++++
 7 files changed, 63 insertions(+), 1 deletion(-)

kernel/cobalt/posix/clock.c COBALT_SYSCALL(clock_gettime, current, · line 160

Quoted 4 lines
kernel/cobalt/posix/clock.c +4 -0
+COBALT_SYSCALL(clock_gettime64, current,
+	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	

Whitespace at end of line! Will fix it up in my tree.

kernel/cobalt/posix/syscall32.c COBALT_SYSCALL32emu(clock_gettime, current, · line 178

Quoted 6 lines
kernel/cobalt/posix/syscall32.c +5 -0
+COBALT_SYSCALL32emu(clock_gettime64, current,
+		    (clockid_t clock_id,
+		     struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	

WS at EOL again. Will fix it up in my tree.

Quoted 2 lines

+}

author
#2 lore raw
Quoted 21 lines · Florian
Quoted 20 lines · Song Chen

From: chensong <[email protected]>

Add a syscall specific for clock_gettime with 64bit time_t.

---
v5:
1, new helper __cobalt_clock_gettime64

---
  include/cobalt/kernel/time.h    | 11 +++++++++++
  include/cobalt/uapi/syscall.h   |  1 +
  kernel/cobalt/posix/clock.c     | 23 ++++++++++++++++++++++-
  kernel/cobalt/posix/clock.h     |  6 ++++++
  kernel/cobalt/posix/syscall32.c |  8 ++++++++
  kernel/cobalt/posix/syscall32.h |  4 ++++
  kernel/cobalt/time.c            | 11 +++++++++++
  7 files changed, 63 insertions(+), 1 deletion(-)
Quoted 6 lines

kernel/cobalt/posix/clock.c COBALT_SYSCALL(clock_gettime, current, · line 160

Quoted 4 lines
kernel/cobalt/posix/clock.c +4 -0
+COBALT_SYSCALL(clock_gettime64, current,
+	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	

Whitespace at end of line! Will fix it up in my tree.

sorry, i did checkpatch each time, probably missed it this time. thanks for fixing it up.

Song

Quoted 14 lines

kernel/cobalt/posix/syscall32.c COBALT_SYSCALL32emu(clock_gettime, current, · line 178

Quoted 7 lines
kernel/cobalt/posix/syscall32.c +5 -0
+COBALT_SYSCALL32emu(clock_gettime64, current,
+		    (clockid_t clock_id,
+		     struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_clock_gettime64(clock_id, u_ts);	

WS at EOL again. Will fix it up in my tree.

Quoted 2 lines

+}

#3 lore raw
In reply to Song Chen
Quoted 17 lines · Song Chen

From: chensong <[email protected]>

Add a syscall specific for clock_gettime with 64bit time_t.

include/cobalt/uapi/syscall.h +1 -0
index 8895d2b..9859963 100644
@@ -123,6 +123,7 @@
  #define sc_cobalt_clock_adjtime			100
  #define sc_cobalt_thread_setschedprio		101
  #define sc_cobalt_sem_timedwait64		102
+#define sc_cobalt_clock_gettime64		103
Quoted 1 line

My fault didn't notice that during review but now while preparing the wiki stuff for being available inside the Xenomai hacker space:

The next syscall would be clock_getres64 instead of clock_gettime64