2017-10-19 19:14:47 +08:00
|
|
|
#ifndef _LINUX_TIME32_H
|
|
|
|
#define _LINUX_TIME32_H
|
|
|
|
/*
|
|
|
|
* These are all interfaces based on the old time_t definition
|
|
|
|
* that overflows in 2038 on 32-bit architectures. New code
|
|
|
|
* should use the replacements based on time64_t and timespec64.
|
|
|
|
*
|
|
|
|
* Any interfaces in here that become unused as we migrate
|
|
|
|
* code to time64_t should get removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/time64.h>
|
2019-01-02 20:28:47 +08:00
|
|
|
#include <linux/timex.h>
|
2017-10-19 19:14:47 +08:00
|
|
|
|
|
|
|
#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
|
|
|
|
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
typedef s32 old_time32_t;
|
|
|
|
|
|
|
|
struct old_timespec32 {
|
|
|
|
old_time32_t tv_sec;
|
|
|
|
s32 tv_nsec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct old_timeval32 {
|
|
|
|
old_time32_t tv_sec;
|
|
|
|
s32 tv_usec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct old_itimerspec32 {
|
|
|
|
struct old_timespec32 it_interval;
|
|
|
|
struct old_timespec32 it_value;
|
|
|
|
};
|
|
|
|
|
2018-04-17 18:03:19 +08:00
|
|
|
struct old_utimbuf32 {
|
|
|
|
old_time32_t actime;
|
|
|
|
old_time32_t modtime;
|
|
|
|
};
|
|
|
|
|
2019-01-02 20:28:47 +08:00
|
|
|
struct old_timex32 {
|
|
|
|
u32 modes;
|
|
|
|
s32 offset;
|
|
|
|
s32 freq;
|
|
|
|
s32 maxerror;
|
|
|
|
s32 esterror;
|
|
|
|
s32 status;
|
|
|
|
s32 constant;
|
|
|
|
s32 precision;
|
|
|
|
s32 tolerance;
|
|
|
|
struct old_timeval32 time;
|
|
|
|
s32 tick;
|
|
|
|
s32 ppsfreq;
|
|
|
|
s32 jitter;
|
|
|
|
s32 shift;
|
|
|
|
s32 stabil;
|
|
|
|
s32 jitcnt;
|
|
|
|
s32 calcnt;
|
|
|
|
s32 errcnt;
|
|
|
|
s32 stbcnt;
|
|
|
|
s32 tai;
|
|
|
|
|
|
|
|
s32:32; s32:32; s32:32; s32:32;
|
|
|
|
s32:32; s32:32; s32:32; s32:32;
|
|
|
|
s32:32; s32:32; s32:32;
|
|
|
|
};
|
|
|
|
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
extern int get_old_timespec32(struct timespec64 *, const void __user *);
|
|
|
|
extern int put_old_timespec32(const struct timespec64 *, void __user *);
|
|
|
|
extern int get_old_itimerspec32(struct itimerspec64 *its,
|
|
|
|
const struct old_itimerspec32 __user *uits);
|
|
|
|
extern int put_old_itimerspec32(const struct itimerspec64 *its,
|
|
|
|
struct old_itimerspec32 __user *uits);
|
2018-07-03 13:44:21 +08:00
|
|
|
struct __kernel_timex;
|
|
|
|
int get_old_timex32(struct __kernel_timex *, const struct old_timex32 __user *);
|
|
|
|
int put_old_timex32(struct old_timex32 __user *, const struct __kernel_timex *);
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
|
2017-10-19 19:14:48 +08:00
|
|
|
#if __BITS_PER_LONG == 64
|
|
|
|
|
|
|
|
/* timespec64 is defined as timespec here */
|
|
|
|
static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
|
|
|
|
{
|
2018-04-27 21:40:12 +08:00
|
|
|
return *(const struct timespec *)&ts64;
|
2017-10-19 19:14:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
|
|
|
|
{
|
2018-04-27 21:40:12 +08:00
|
|
|
return *(const struct timespec64 *)&ts;
|
2017-10-19 19:14:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
|
|
|
|
{
|
|
|
|
struct timespec ret;
|
|
|
|
|
|
|
|
ret.tv_sec = (time_t)ts64.tv_sec;
|
|
|
|
ret.tv_nsec = ts64.tv_nsec;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
|
|
|
|
{
|
|
|
|
struct timespec64 ret;
|
|
|
|
|
|
|
|
ret.tv_sec = ts.tv_sec;
|
|
|
|
ret.tv_nsec = ts.tv_nsec;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-04-27 21:40:12 +08:00
|
|
|
#endif
|
2017-10-19 19:14:48 +08:00
|
|
|
|
2017-10-19 19:14:47 +08:00
|
|
|
static inline int timespec_equal(const struct timespec *a,
|
|
|
|
const struct timespec *b)
|
|
|
|
{
|
|
|
|
return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lhs < rhs: return <0
|
|
|
|
* lhs == rhs: return 0
|
|
|
|
* lhs > rhs: return >0
|
|
|
|
*/
|
|
|
|
static inline int timespec_compare(const struct timespec *lhs, const struct timespec *rhs)
|
|
|
|
{
|
|
|
|
if (lhs->tv_sec < rhs->tv_sec)
|
|
|
|
return -1;
|
|
|
|
if (lhs->tv_sec > rhs->tv_sec)
|
|
|
|
return 1;
|
|
|
|
return lhs->tv_nsec - rhs->tv_nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true if the timespec is norm, false if denorm:
|
|
|
|
*/
|
|
|
|
static inline bool timespec_valid(const struct timespec *ts)
|
|
|
|
{
|
|
|
|
/* Dates before 1970 are bogus */
|
|
|
|
if (ts->tv_sec < 0)
|
|
|
|
return false;
|
|
|
|
/* Can't have more nanoseconds then a second */
|
|
|
|
if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timespec_to_ns - Convert timespec to nanoseconds
|
|
|
|
* @ts: pointer to the timespec variable to be converted
|
|
|
|
*
|
|
|
|
* Returns the scalar nanosecond representation of the timespec
|
|
|
|
* parameter.
|
|
|
|
*/
|
|
|
|
static inline s64 timespec_to_ns(const struct timespec *ts)
|
|
|
|
{
|
|
|
|
return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ns_to_timespec - Convert nanoseconds to timespec
|
|
|
|
* @nsec: the nanoseconds value to be converted
|
|
|
|
*
|
|
|
|
* Returns the timespec representation of the nsec parameter.
|
|
|
|
*/
|
|
|
|
extern struct timespec ns_to_timespec(const s64 nsec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timespec_add_ns - Adds nanoseconds to a timespec
|
|
|
|
* @a: pointer to timespec to be incremented
|
|
|
|
* @ns: unsigned nanoseconds value to be added
|
|
|
|
*
|
|
|
|
* This must always be inlined because its used from the x86-64 vdso,
|
|
|
|
* which cannot call other kernel functions.
|
|
|
|
*/
|
|
|
|
static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
|
|
|
|
{
|
|
|
|
a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
|
|
|
|
a->tv_nsec = ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long mktime(const unsigned int year,
|
|
|
|
const unsigned int mon, const unsigned int day,
|
|
|
|
const unsigned int hour, const unsigned int min,
|
|
|
|
const unsigned int sec)
|
|
|
|
{
|
|
|
|
return mktime64(year, mon, day, hour, min, sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool timeval_valid(const struct timeval *tv)
|
|
|
|
{
|
|
|
|
/* Dates before 1970 are bogus */
|
|
|
|
if (tv->tv_sec < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Can't have more microseconds then a second */
|
|
|
|
if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timeval_to_ns - Convert timeval to nanoseconds
|
|
|
|
* @ts: pointer to the timeval variable to be converted
|
|
|
|
*
|
|
|
|
* Returns the scalar nanosecond representation of the timeval
|
|
|
|
* parameter.
|
|
|
|
*/
|
|
|
|
static inline s64 timeval_to_ns(const struct timeval *tv)
|
|
|
|
{
|
|
|
|
return ((s64) tv->tv_sec * NSEC_PER_SEC) +
|
|
|
|
tv->tv_usec * NSEC_PER_USEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ns_to_timeval - Convert nanoseconds to timeval
|
|
|
|
* @nsec: the nanoseconds value to be converted
|
|
|
|
*
|
|
|
|
* Returns the timeval representation of the nsec parameter.
|
|
|
|
*/
|
|
|
|
extern struct timeval ns_to_timeval(const s64 nsec);
|
y2038: Introduce struct __kernel_old_timeval
Dealing with 'struct timeval' users in the y2038 series is a bit tricky:
We have two definitions of timeval that are visible to user space,
one comes from glibc (or some other C library), the other comes from
linux/time.h. The kernel copy is what we want to be used for a number of
structures defined by the kernel itself, e.g. elf_prstatus (used it core
dumps), sysinfo and rusage (used in system calls). These generally tend
to be used for passing time intervals rather than absolute (epoch-based)
times, so they do not suffer from the y2038 overflow. Some of them
could be changed to use 64-bit timestamps by creating new system calls,
others like the core files cannot easily be changed.
An application using these interfaces likely also uses gettimeofday()
or other interfaces that use absolute times, and pass 'struct timeval'
pointers directly into kernel interfaces, so glibc must redefine their
timeval based on a 64-bit time_t when they introduce their y2038-safe
interfaces.
The only reasonable way forward I see is to remove the 'timeval'
definion from the kernel's uapi headers, and change the interfaces that
we do not want to (or cannot) duplicate for 64-bit times to use a new
__kernel_old_timeval definition instead. This type should be avoided
for all new interfaces (those can use 64-bit nanoseconds, or the 64-bit
version of timespec instead), and should be used with great care when
converting existing interfaces from timeval, to be sure they don't suffer
from the y2038 overflow, and only with consensus for the particular user
that using __kernel_old_timeval is better than moving to a 64-bit based
interface. The structure name is intentionally chosen to not conflict
with user space types, and to be ugly enough to discourage its use.
Note that ioctl based interfaces that pass a bare 'timeval' pointer
cannot change to '__kernel_old_timeval' because the user space source
code refers to 'timeval' instead, and we don't want to modify the user
space sources if possible. However, any application that relies on a
structure to contain an embedded 'timeval' (e.g. by passing a pointer
to the member into a function call that expects a timeval pointer) is
broken when that structure gets converted to __kernel_old_timeval. I
don't see any way around that, and we have to rely on the compiler to
produce a warning or compile failure that will alert users when they
recompile their sources against a new libc.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lkml.kernel.org/r/20180315161739.576085-1-arnd@arndb.de
2018-03-16 00:12:40 +08:00
|
|
|
extern struct __kernel_old_timeval ns_to_kernel_old_timeval(s64 nsec);
|
2017-10-19 19:14:47 +08:00
|
|
|
|
2018-08-22 04:33:00 +08:00
|
|
|
/*
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
* Old names for the 32-bit time_t interfaces, these will be removed
|
|
|
|
* when everything uses the new names.
|
2018-08-22 04:33:00 +08:00
|
|
|
*/
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
#define compat_time_t old_time32_t
|
|
|
|
#define compat_timeval old_timeval32
|
|
|
|
#define compat_timespec old_timespec32
|
|
|
|
#define compat_itimerspec old_itimerspec32
|
|
|
|
#define ns_to_compat_timeval ns_to_old_timeval32
|
|
|
|
#define get_compat_itimerspec64 get_old_itimerspec32
|
|
|
|
#define put_compat_itimerspec64 put_old_itimerspec32
|
|
|
|
#define compat_get_timespec64 get_old_timespec32
|
|
|
|
#define compat_put_timespec64 put_old_timespec32
|
2018-08-22 04:33:00 +08:00
|
|
|
|
2017-10-19 19:14:47 +08:00
|
|
|
#endif
|