[PATCH v5 2/4] tools/include/uapi: Add __kernel_old_time_t typedef to tools/include/uapi/linux/time_types.h
From: wang.yaxin
Date: Sat Aug 29 2026 - 05:15:07 EST
From: Wang Yaxin <wang.yaxin@xxxxxxxxxx>
Add time_types.h to tools/include/uapi/ to enable y2038-safe time
structures in tools. Unlike the kernel's uapi version, we define
the required types directly instead of including
<asm-generic/posix_types.h>.
Rationale:
- asm-generic/posix_types.h is NOT architecture-independent
- Different architectures override types (e.g., x86_32 overrides
__kernel_mode_t, __kernel_uid_t, __kernel_gid_t to unsigned short)
- int-ll64.h is special and cannot be used as a pattern here
Direct typedefs for the three types actually needed:
- __kernel_long_t: base type for time values
- __kernel_time64_t: 64-bit time for y2038-safe interfaces
- __kernel_old_time_t: legacy time type introduced in v5.5
This follows the reviewer's suggestion to add typedefs only where
needed, avoiding architecture-specific issues while maintaining
self-containment of tools/include/uapi/.
Signed-off-by: Wang Yaxin <wang.yaxin@xxxxxxxxxx>
---
tools/include/uapi/linux/time_types.h | 76 +++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 tools/include/uapi/linux/time_types.h
diff --git a/tools/include/uapi/linux/time_types.h b/tools/include/uapi/linux/time_types.h
new file mode 100644
index 000000000000..3aa25d824cac
--- /dev/null
+++ b/tools/include/uapi/linux/time_types.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Started by AICoder, pid:00350371 */
+#ifndef _UAPI_LINUX_TIME_TYPES_H
+#define _UAPI_LINUX_TIME_TYPES_H
+
+#include <linux/types.h>
+
+/*
+ * Define time-related types directly instead of including
+ * <asm-generic/posix_types.h>. The asm-generic header is not
+ * architecture-independent: different architectures override
+ * certain types (e.g., x86_32 overrides __kernel_mode_t, __kernel_uid_t,
+ * __kernel_gid_t to unsigned short).
+ *
+ * We only need a few specific types here, so define them directly
+ * to avoid architecture-specific issues while maintaining self-containment.
+ */
+
+#ifndef __kernel_long_t
+typedef long __kernel_long_t;
+#endif
+
+#ifndef __kernel_time64_t
+typedef long long __kernel_time64_t;
+#endif
+
+/*
+ * __kernel_old_time_t was introduced in v5.5 for y2038-safe migration.
+ * It is used by legacy time structures like __kernel_old_timespec.
+ * Defined here to avoid dependency on outdated system headers.
+ */
+#ifndef __kernel_old_time_t
+typedef __kernel_long_t __kernel_old_time_t;
+#endif
+/* Ended by AICoder, pid:00350371 */
+
+struct __kernel_timespec {
+ __kernel_time64_t tv_sec; /* seconds */
+ long long tv_nsec; /* nanoseconds */
+};
+
+struct __kernel_itimerspec {
+ struct __kernel_timespec it_interval; /* timer period */
+ struct __kernel_timespec it_value; /* timer expiration */
+};
+
+/*
+ * legacy timeval structure, only embedded in structures that
+ * traditionally used 'timeval' to pass time intervals (not absolute
+ * times). Do not add new users. If user space fails to compile
+ * here, this is probably because it is not y2038 safe and needs to
+ * be changed to use another interface.
+ */
+#ifndef __kernel_old_timeval
+struct __kernel_old_timeval {
+ __kernel_long_t tv_sec;
+ __kernel_long_t tv_usec;
+};
+#endif
+
+struct __kernel_old_timespec {
+ __kernel_old_time_t tv_sec; /* seconds */
+ __kernel_long_t tv_nsec; /* nanoseconds */
+};
+
+struct __kernel_old_itimerval {
+ struct __kernel_old_timeval it_interval;/* timer interval */
+ struct __kernel_old_timeval it_value; /* current value */
+};
+
+struct __kernel_sock_timeval {
+ __s64 tv_sec;
+ __s64 tv_usec;
+};
+
+#endif /* _UAPI_LINUX_TIME_TYPES_H */
--
2.25.1