diff mbox series

[v2,08/13] tools/nolibc: add pure 64bit time structs

Message ID c6bf754329eeb61a1ffe8f9e04ec70cb02e1a2ed.1685387484.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series nolibc: add part2 of support for rv32 | expand

Commit Message

Zhangjin Wu May 29, 2023, 7:56 p.m. UTC
It's time to provide 64bit time structs for all platforms, for y2038 is
near.

There are still old "struct timeval" and "struct itimerval" in
include/uapi/linux/time.h, remove "#include <linux/time.h>" and add our
own pure 64bit ones.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/linux-riscv/9e4064fc-f0c5-4dd3-941f-344d2150e1cd@app.fastmail.com/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/include/nolibc/sys.h   |  2 --
 tools/include/nolibc/types.h | 49 +++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index d0720af84b6d..1b3675d4c5fc 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -17,7 +17,6 @@ 
 #include <asm/mman.h>
 #include <linux/fs.h>
 #include <linux/loop.h>
-#include <linux/time.h>
 #include <linux/auxvec.h>
 #include <linux/fcntl.h> /* for O_* and AT_* */
 #include <linux/stat.h>  /* for statx() */
@@ -28,7 +27,6 @@ 
 #include "errno.h"
 #include "types.h"
 
-
 /* Functions in this file only describe syscalls. They're declared static so
  * that the compiler usually decides to inline them while still being allowed
  * to pass a pointer to one of their instances. Each syscall exists in two
diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h
index 698d859fc6e2..4ff35b7ea2bb 100644
--- a/tools/include/nolibc/types.h
+++ b/tools/include/nolibc/types.h
@@ -8,10 +8,57 @@ 
 #define _NOLIBC_TYPES_H
 
 #include "std.h"
-#include <linux/time.h>
+#include <linux/time_types.h>
 #include <linux/stat.h>
 #include <linux/wait.h>
 
+/* based on linux/time.h but with pure 64bit time structs */
+#define timespec __kernel_timespec
+#define itimerspec __kernel_itimerspec
+
+/* timeval is only provided for users, not compatible with syscalls */
+struct timeval {
+	__kernel_time64_t tv_sec;	/* seconds */
+	__s64 tv_usec;			/* microseconds */
+};
+
+struct timezone {
+	int tz_minuteswest;		/* minutes west of Greenwich */
+	int tz_dsttime;			/* type of dst correction */
+};
+
+/* itimerval is only provided for users, not compatible with syscalls */
+struct itimerval {
+	struct timeval it_interval;	/* timer interval */
+	struct timeval it_value;	/* current value */
+};
+
+/*
+ * Names of the interval timers, and structure
+ * defining a timer setting:
+ */
+#define ITIMER_REAL			0
+#define ITIMER_VIRTUAL			1
+#define ITIMER_PROF			2
+
+/*
+ * The IDs of the various system clocks (for POSIX.1b interval timers):
+ */
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+
+/*
+ * The various flags for setting POSIX.1b interval timers:
+ */
+#define TIMER_ABSTIME			0x01
 
 /* Only the generic macros and types may be defined here. The arch-specific
  * ones such as the O_RDONLY and related macros used by fcntl() and open(), or