aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2023-01-14 00:17:45 +0100
committerBen Hutchings <ben@decadent.org.uk>2023-02-12 22:10:18 +0100
commitdd8e32a4a6102db2d34ff8e5bfc39bd60f481337 (patch)
tree7b2246a5b1be68fb2624e56021568f2ffcc68594
parent0b35ac6c018c83be12a66db6b026b81b3321846a (diff)
downloadklibc-dd8e32a4a6102db2d34ff8e5bfc39bd60f481337.tar.gz
[klibc] time: Use 64-bit time types on all architectures
- Define time_t as __kernel_time64_t - In <sys/time.h>, replace <linux/time.h> with suitable definitions: - Define struct timespec and itimerspec to match the kernel's 64-bit structures. On 32-bit architectures, add padding around tv_nsec; the kernel uses a 64-bit tv_nsec but will mask out this padding. - Define struct timeval using __kernel_time64_t (although there are no new system calls using struct timeval) - Keep the old struct itimerval and struct timeval (as timeval_old) definitions. There aren't simple replacements available for the {get,set}itimer() and getrusage() system calls, and for these APIs struct timeval holds a relative time where the extra range is not needed. - Copy struct timezone and various important macro definitions - Change various system call wrappers to use the _time64 variants on 32-bit architectures Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/include/sys/resource.h4
-rw-r--r--usr/include/sys/time.h59
-rw-r--r--usr/include/sys/types.h2
-rw-r--r--usr/klibc/SYSCALLS.def18
4 files changed, 73 insertions, 10 deletions
diff --git a/usr/include/sys/resource.h b/usr/include/sys/resource.h
index 94ed28a596dc8..e43a69dd3f102 100644
--- a/usr/include/sys/resource.h
+++ b/usr/include/sys/resource.h
@@ -15,8 +15,8 @@
#define RUSAGE_THREAD 1
struct rusage {
- struct timeval ru_utime; /* user time used */
- struct timeval ru_stime; /* system time used */
+ struct timeval_old ru_utime; /* user time used */
+ struct timeval_old ru_stime; /* system time used */
__kernel_long_t ru_maxrss; /* maximum resident set size */
__kernel_long_t ru_ixrss; /* integral shared memory size */
__kernel_long_t ru_idrss; /* integral unshared data size */
diff --git a/usr/include/sys/time.h b/usr/include/sys/time.h
index e81633034fe8b..423d3d540fb68 100644
--- a/usr/include/sys/time.h
+++ b/usr/include/sys/time.h
@@ -6,9 +6,66 @@
#define _SYS_TIME_H
#include <klibc/extern.h>
+#include <klibc/endian.h>
#include <stddef.h>
#include <sys/types.h>
-#include <linux/time.h>
+
+/* struct timespec as used by current kernel UAPI (time64 on 32-bit) */
+struct timespec {
+ __kernel_time64_t tv_sec;
+#if __BYTE_ORDER == __BIG_ENDIAN && __BITS_PER_LONG == 32
+ int :32;
+#endif
+ long tv_nsec;
+#if __BYTE_ORDER == __LITTLE_ENDIAN && __BITS_PER_LONG == 32
+ int :32;
+#endif
+};
+
+/* struct timeval with 64-bit time, not used by kernel UAPI */
+struct timeval {
+ __kernel_time64_t tv_sec;
+ __kernel_suseconds_t tv_usec;
+};
+
+/* struct timeval as used by old kernel UAPI */
+struct timeval_old {
+ __kernel_time_t tv_sec;
+ __kernel_suseconds_t tv_usec;
+};
+
+struct itimerspec {
+ struct timespec it_interval;
+ struct timespec it_value;
+};
+
+struct itimerval {
+ struct timeval_old it_interval;
+ struct timeval_old it_value;
+};
+
+struct timezone {
+ int tz_minuteswest;
+ int tz_dsttime;
+};
+
+#define ITIMER_REAL 0
+#define ITIMER_VIRTUAL 1
+#define ITIMER_PROF 2
+
+#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
+#define CLOCK_TAI 11
+
+#define TIMER_ABSTIME 0x01
/* The 2.6.20 Linux headers always #define FD_ZERO __FD_ZERO, etc, in
<linux/time.h> but not all architectures define the
diff --git a/usr/include/sys/types.h b/usr/include/sys/types.h
index e17bc87f08f0e..d698ae5ba8b01 100644
--- a/usr/include/sys/types.h
+++ b/usr/include/sys/types.h
@@ -46,7 +46,7 @@ typedef __kernel_fsid_t fsid_t;
*/
#ifndef _TIME_T
#define _TIME_T
-typedef __kernel_time_t time_t;
+typedef __kernel_time64_t time_t;
#endif
#ifndef _CLOCK_T
diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def
index d46bb548484cf..660efc66d52f6 100644
--- a/usr/klibc/SYSCALLS.def
+++ b/usr/klibc/SYSCALLS.def
@@ -140,7 +140,8 @@ int fchown32,fchown::fchown(int, uid_t, gid_t);
<?> int fchownat(int, const char *, uid_t, gid_t, int);
<?> int lchown32,lchown::lchown(const char *, uid_t, gid_t);
int getcwd::__getcwd(char *, size_t);
-int utimensat(int, const char *, const struct timespec *, int);
+<32> int utimensat_time64::utimensat(int, const char *, const struct timespec *, int);
+<64> int utimensat(int, const char *, const struct timespec *, int);
<?> int inotify_init();
<?> int inotify_add_watch(int, const char *, __u32);
<?> int inotify_rm_watch(int, __u32);
@@ -165,9 +166,11 @@ int dup3(int, int, int);
<!i386,ppc64> int fcntl64,fcntl::fcntl(int, int, unsigned long);
int ioctl(int, int, void *);
int flock(int, int);
-int pselect6::__pselect6(int, fd_set *, fd_set *, fd_set *, struct timespec *, const struct __pselect6 *);
+<32> int pselect6_time64::__pselect6(int, fd_set *, fd_set *, fd_set *, struct timespec *, const struct __pselect6 *);
+<64> int pselect6::__pselect6(int, fd_set *, fd_set *, fd_set *, struct timespec *, const struct __pselect6 *);
<?> int poll(struct pollfd *, nfds_t, long);
-<?> int ppoll::__ppoll(struct pollfd *, nfds_t, struct timespec *, const sigset_t *, size_t);
+<32> int ppoll_time64::__ppoll(struct pollfd *, nfds_t, struct timespec *, const sigset_t *, size_t);
+<64> int ppoll::__ppoll(struct pollfd *, nfds_t, struct timespec *, const sigset_t *, size_t);
int fsync(int);
int fdatasync,fsync::fdatasync(int);
int readv(int, const struct iovec *, int);
@@ -204,9 +207,12 @@ int setitimer(int, const struct itimerval *, struct itimerval *);
clock_t times(struct tms *);
int gettimeofday::__gettimeofday(void *, struct timezone *);
int settimeofday::__settimeofday(const void *, const struct timezone *);
-int clock_gettime(clockid_t, struct timespec *);
-int clock_settime(clockid_t, const struct timespec *);
-int clock_nanosleep::__clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
+<32> int clock_gettime64::clock_gettime(clockid_t, struct timespec *);
+<64> int clock_gettime(clockid_t, struct timespec *);
+<32> int clock_settime64::clock_settime(clockid_t, const struct timespec *);
+<64> int clock_settime(clockid_t, const struct timespec *);
+<32> int clock_nanosleep_time64::__clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
+<64> int clock_nanosleep::__clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
<?> int pause();
/*