klibc-bot for Ben Hutchings
2023-Jan-14 22:03 UTC
[klibc] [klibc:time64] time: Use 64-bit time types on all architectures
Commit-ID: df7b02bd5c9af14c6efbe39ee4c313e368dfe967 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=df7b02bd5c9af14c6efbe39ee4c313e368dfe967 Author: Ben Hutchings <ben at decadent.org.uk> AuthorDate: Sat, 14 Jan 2023 00:17:45 +0100 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 14 Jan 2023 18:10:12 +0100 [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 - Define struct timeval using __kernel_time64_t (although there are no new system calls using struct timeval) - Keep the old struct itimerval definition, because there aren't simple replacements available for the {get,set}itimer() system calls and it holds relative times that don't need the extra range - Similarly, keep the old struct timeval definition as timeval_old and use it in struct rusage - 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 at decadent.org.uk> --- usr/include/sys/resource.h | 4 ++-- usr/include/sys/time.h | 56 +++++++++++++++++++++++++++++++++++++++++++++- usr/include/sys/types.h | 2 +- usr/klibc/SYSCALLS.def | 18 ++++++++++----- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/usr/include/sys/resource.h b/usr/include/sys/resource.h index 94ed28a5..e43a69dd 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 e8163303..0ad639fa 100644 --- a/usr/include/sys/time.h +++ b/usr/include/sys/time.h @@ -6,9 +6,63 @@ #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 { + __kernel_time64_t tv_sec; +#if __BYTE_ORDER == __BIG_ENDIAN && __BITS_PER_LONG == 32 + long __tv_pad; +#endif + long tv_nsec; +#if __BYTE_ORDER == __LITTLE_ENDIAN && __BITS_PER_LONG == 32 + long __tv_pad; +#endif +}; + +struct timeval { + __kernel_time64_t tv_sec; + __kernel_suseconds_t tv_usec; +}; + +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 TIMER_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 e17bc87f..d698ae5b 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 d46bb548..660efc66 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(); /*
Arnd Bergmann
2023-Jan-14 22:36 UTC
[klibc] [klibc:time64] time: Use 64-bit time types on all architectures
On Sat, Jan 14, 2023, at 23:03, klibc-bot for Ben Hutchings wrote:> > #include <klibc/extern.h> > +#include <klibc/endian.h> > #include <stddef.h> > #include <sys/types.h> > -#include <linux/time.h> > + > +struct timespec { > + __kernel_time64_t tv_sec; > +#if __BYTE_ORDER == __BIG_ENDIAN && __BITS_PER_LONG == 32 > + long __tv_pad; > +#endif > + long tv_nsec; > +#if __BYTE_ORDER == __LITTLE_ENDIAN && __BITS_PER_LONG == 32 > + long __tv_pad; > +#endif > +};The problem with this definition is applications doing things like struct timespec ts = { 0, 5000 }; /* 5 ?s */ which on big-endian architectures ends up leaving tv_nsec set to zero and the padding set to an invalid number. This could either use the definition from glibc with an unnamed bitfield, or the __kernel_timespec definition using a 64-bit tv_nsec that is not C99 compliant but should just work. Arnd
Possibly Parallel Threads
- [klibc:time64] time: Use clock_* system calls for time-of-day and sleep
- [klibc:time64] select: Make all select calls wrappers for pselect6()
- [klibc:time64] time: Use 64-bit time types on all architectures
- [klibc:time64] resource: Avoid using <linux/resource.h>
- [klibc:time64] select: Fix handling of NULL timeout when wrapping pselect()