GNU C Library master sources branch aaribaud/y2038 created. glibc-2.24-400-g83b43b0
aaribaud@sourceware.org
aaribaud@sourceware.org
Wed Feb 1 10:41:00 GMT 2017
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, aaribaud/y2038 has been created
at 83b43b0df15457905dcceba16fe8daf28084dd33 (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=83b43b0df15457905dcceba16fe8daf28084dd33
commit 83b43b0df15457905dcceba16fe8daf28084dd33
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Feb 1 08:43:29 2017 +0100
Add 64-bit versions for 'broken-up time' APIs
This consists in the following API additions:
([file] 32-bit function -> [file] 64-bit variant)
time/ctime.c ctime() -> ctime64()
time/gmtime.c gmtime() -> gmtime64()
time/gmtime.c gmtime_r() -> gmtime64_r()
time/localtime.c localtime() -> localtime64()
time/localtime.c localtime_r() -> localtime64_r()
which require the following internal additions
time/bits/types/time_t.h time_t -> time64_t
time/offtime.c __offtime() -> __offtime64()
time/tzset.c __tz_convert() -> __tz64_convert()
diff --git a/include/time.h b/include/time.h
index 2fa0764..53bafc8 100644
--- a/include/time.h
+++ b/include/time.h
@@ -15,6 +15,7 @@ libc_hidden_proto (asctime)
libc_hidden_proto (mktime)
libc_hidden_proto (timelocal)
libc_hidden_proto (localtime)
+libc_hidden_proto (localtime64)
libc_hidden_proto (strftime)
libc_hidden_proto (strptime)
@@ -48,13 +49,14 @@ extern int __use_tzfile attribute_hidden;
extern void __tzfile_read (const char *file, size_t extra,
char **extrap);
-extern void __tzfile_compute (time_t timer, int use_localtime,
+extern void __tzfile_compute (time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp);
extern void __tzfile_default (const char *std, const char *dst,
long int stdoff, long int dstoff);
extern void __tzset_parse_tz (const char *tz);
-extern void __tz_compute (time_t timer, struct tm *tm, int use_localtime)
+extern void __tzset64_parse_tz (const char *tz);
+extern void __tz_compute (time64_t timer, struct tm *tm, int use_localtime)
__THROW internal_function;
/* Subroutine of `mktime'. Return the `time_t' representation of TP and
@@ -71,6 +73,13 @@ extern struct tm *__gmtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp);
libc_hidden_proto (__gmtime_r)
+extern struct tm *__localtime64_r (const time64_t *__timer,
+ struct tm *__tp) attribute_hidden;
+
+extern struct tm *__gmtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp);
+libc_hidden_proto (__gmtime64_r)
+
/* Compute the `struct tm' representation of *T,
offset OFFSET seconds east of UTC,
and store year, yday, mon, mday, wday, hour, min, sec into *TP.
@@ -79,16 +88,36 @@ extern int __offtime (const time_t *__timer,
long int __offset,
struct tm *__tp);
+/* Compute the `struct tm' representation of 64-bit-time *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP.
+ Return nonzero if successful. */
+extern int __offtime64 (const time64_t *__timer,
+ long int __offset,
+ struct tm *__tp);
+
extern char *__asctime_r (const struct tm *__tp, char *__buf);
extern void __tzset (void);
+extern void __tzset64 (void);
/* Prototype for the internal function to get information based on TZ. */
extern struct tm *__tz_convert (const time_t *timer, int use_localtime, struct tm *tp);
+/* Prototype for the internal 64-bit-time function to get information based on TZ. */
+extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
+
+/* Prototype for the internal function to get information based on TZ,
+ 64-bit-time version. */
+extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
+
/* Return the maximum length of a timezone name.
This is what `sysconf (_SC_TZNAME_MAX)' does. */
extern long int __tzname_max (void);
+/* Return the maximum length of a timezone name (time/tzset64.c instance)
+ This is what `sysconf (_SC_TZNAME_MAX)' does. */
+extern long int __tzname64_max (void);
+
extern int __nanosleep (const struct timespec *__requested_time,
struct timespec *__remaining);
libc_hidden_proto (__nanosleep)
diff --git a/time/bits/types/time_t.h b/time/bits/types/time_t.h
index 16e5269..906dcf9 100644
--- a/time/bits/types/time_t.h
+++ b/time/bits/types/time_t.h
@@ -11,4 +11,11 @@ __END_NAMESPACE_STD
__USING_NAMESPACE_STD(time_t)
#endif
+/* Returned by `time64'. */
+typedef __time64_t time64_t;
+__END_NAMESPACE_STD
+#ifdef __USE_POSIX
+__USING_NAMESPACE_STD(time64_t)
+#endif
+
#endif
diff --git a/time/ctime.c b/time/ctime.c
index 451d7b9..450ad26 100644
--- a/time/ctime.c
+++ b/time/ctime.c
@@ -26,3 +26,13 @@ ctime (const time_t *t)
In particular, ctime and asctime must yield the same pointer. */
return asctime (localtime (t));
}
+
+/* Return a string as returned by asctime which
+ is the representation of *T in that form. */
+char *
+ctime64 (const time64_t *t)
+{
+ /* Apply the same rule as ctime:
+ make ctime64 (t) is equivalent to asctime (localtime64 (t)). */
+ return asctime (localtime64 (t));
+}
diff --git a/time/gmtime.c b/time/gmtime.c
index b3b5d0d..a895980 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -35,3 +35,21 @@ gmtime (const time_t *t)
{
return __tz_convert (t, 0, &_tmbuf);
}
+
+/* Return the `struct tm' representation of 64-bit-time *T
+ in UTC, using *TP to store the result. */
+struct tm *
+__gmtime64_r (const time64_t *t, struct tm *tp)
+{
+ return __tz64_convert (t, 0, tp);
+}
+libc_hidden_def (__gmtime64_r)
+weak_alias (__gmtime64_r, gmtime64_r)
+
+
+/* Return the `struct tm' representation of 64-bit-time *T in UTC. */
+struct tm *
+gmtime64 (const time64_t *t)
+{
+ return __tz64_convert (t, 0, &_tmbuf);
+}
diff --git a/time/localtime.c b/time/localtime.c
index 8ec40cf..7b147a1 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -39,3 +39,23 @@ localtime (const time_t *t)
return __tz_convert (t, 1, &_tmbuf);
}
libc_hidden_def (localtime)
+
+/* 64-bit-time versions */
+
+/* Return the `struct tm' representation of *T in local time,
+ using *TP to store the result. */
+struct tm *
+__localtime64_r (const time64_t *t, struct tm *tp)
+{
+ return __tz64_convert (t, 1, tp);
+}
+weak_alias (__localtime64_r, localtime64_r)
+
+
+/* Return the `struct tm' representation of *T in local time. */
+struct tm *
+localtime64 (const time64_t *t)
+{
+ return __tz64_convert (t, 1, &_tmbuf);
+}
+libc_hidden_def (localtime64)
diff --git a/time/offtime.c b/time/offtime.c
index b540b2f..1f83922 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -84,3 +84,67 @@ __offtime (const time_t *t, long int offset, struct tm *tp)
tp->tm_mday = days + 1;
return 1;
}
+
+/* Compute the `struct tm' representation of 64-bit-time *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP.
+ Return nonzero if successful. */
+int
+__offtime64 (const time64_t *t, long int offset, struct tm *tp)
+{
+ time64_t days, rem, y;
+ const unsigned short int *ip;
+
+ days = *t / SECS_PER_DAY;
+ rem = *t % SECS_PER_DAY;
+ rem += offset;
+ while (rem < 0)
+ {
+ rem += SECS_PER_DAY;
+ --days;
+ }
+ while (rem >= SECS_PER_DAY)
+ {
+ rem -= SECS_PER_DAY;
+ ++days;
+ }
+ tp->tm_hour = rem / SECS_PER_HOUR;
+ rem %= SECS_PER_HOUR;
+ tp->tm_min = rem / 60;
+ tp->tm_sec = rem % 60;
+ /* January 1, 1970 was a Thursday. */
+ tp->tm_wday = (4 + days) % 7;
+ if (tp->tm_wday < 0)
+ tp->tm_wday += 7;
+ y = 1970;
+
+#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
+#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
+
+ while (days < 0 || days >= (__isleap (y) ? 366 : 365))
+ {
+ /* Guess a corrected year, assuming 365 days per year. */
+ time64_t yg = y + days / 365 - (days % 365 < 0);
+
+ /* Adjust DAYS and Y to match the guessed year. */
+ days -= ((yg - y) * 365
+ + LEAPS_THRU_END_OF (yg - 1)
+ - LEAPS_THRU_END_OF (y - 1));
+ y = yg;
+ }
+ tp->tm_year = y - 1900;
+ if (tp->tm_year != y - 1900)
+ {
+ /* The year cannot be represented due to overflow. */
+ __set_errno (EOVERFLOW);
+ return 0;
+ }
+ tp->tm_yday = days;
+ ip = __mon_yday[__isleap(y)];
+ for (y = 11; days < (long int) ip[y]; --y)
+ continue;
+ days -= ip[y];
+ tp->tm_mon = y;
+ tp->tm_mday = days + 1;
+ return 1;
+}
diff --git a/time/time.h b/time/time.h
index 860aab7..894b72d 100644
--- a/time/time.h
+++ b/time/time.h
@@ -121,9 +121,17 @@ __BEGIN_NAMESPACE_STD
in Universal Coordinated Time (aka Greenwich Mean Time). */
extern struct tm *gmtime (const time_t *__timer) __THROW;
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+ in Universal Coordinated Time (aka Greenwich Mean Time). */
+extern struct tm *gmtime (const time_t *__timer) __THROW;
+
/* Return the `struct tm' representation
of *TIMER in the local timezone. */
extern struct tm *localtime (const time_t *__timer) __THROW;
+
+/* Return the `struct tm' representation
+ of the 64-bit-time *TIMER in the local timezone. */
+extern struct tm *localtime64 (const time64_t *__timer) __THROW;
__END_NAMESPACE_STD
#ifdef __USE_POSIX
@@ -132,10 +140,20 @@ __END_NAMESPACE_STD
extern struct tm *gmtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+ in UTC, using *TP to store the result. */
+extern struct tm *gmtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp) __THROW;
+
/* Return the `struct tm' representation of *TIMER in local time,
using *TP to store the result. */
extern struct tm *localtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
+
+/* Return the `struct tm' representation of the 64-bit-time *TIMER
+ in local time, using *TP to store the result. */
+extern struct tm *localtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp) __THROW;
#endif /* POSIX */
__BEGIN_NAMESPACE_STD
@@ -145,6 +163,9 @@ extern char *asctime (const struct tm *__tp) __THROW;
/* Equivalent to `asctime (localtime (timer))'. */
extern char *ctime (const time_t *__timer) __THROW;
+
+/* Equivalent to `asctime (localtime64 (timer))'. */
+extern char *ctime64 (const time64_t *__timer) __THROW;
__END_NAMESPACE_STD
#ifdef __USE_POSIX
diff --git a/time/tzfile.c b/time/tzfile.c
index 9049878..540b812 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -637,7 +637,7 @@ __tzfile_default (const char *std, const char *dst,
}
void
-__tzfile_compute (time_t timer, int use_localtime,
+__tzfile_compute (time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp)
{
@@ -692,7 +692,7 @@ __tzfile_compute (time_t timer, int use_localtime,
/* Convert to broken down structure. If this fails do not
use the string. */
- if (__glibc_unlikely (! __offtime (&timer, 0, tp)))
+ if (__glibc_unlikely (! __offtime64 (&timer, 0, tp)))
goto use_last;
/* Use the rules from the TZ string to compute the change. */
diff --git a/time/tzset.c b/time/tzset.c
index f65116c..cab57ae 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -61,7 +61,7 @@ typedef struct
/* We cache the computed time of change for a
given year so we don't have to recompute it. */
- time_t change; /* When to change to this zone. */
+ time64_t change; /* When to change to this zone. */
int computed_for; /* Year above is computed for. */
} tz_rule;
@@ -451,7 +451,7 @@ tzset_internal (int always, int explicit)
tz_rules[0].name = tz_rules[1].name = "UTC";
if (J0 != 0)
tz_rules[0].type = tz_rules[1].type = J0;
- tz_rules[0].change = tz_rules[1].change = (time_t) -1;
+ tz_rules[0].change = tz_rules[1].change = (time64_t) -1;
update_vars ();
return;
}
@@ -550,10 +550,11 @@ compute_change (tz_rule *rule, int year)
/* Figure out the correct timezone for TM and set `__tzname',
- `__timezone', and `__daylight' accordingly. */
+ `__timezone', and `__daylight' accordingly.
+ NOTE: this takes a time64_t value, so passing a time_t value is OK. */
void
internal_function
-__tz_compute (time_t timer, struct tm *tm, int use_localtime)
+__tz_compute (time64_t timer, struct tm *tm, int use_localtime)
{
compute_change (&tz_rules[0], 1900 + tm->tm_year);
compute_change (&tz_rules[1], 1900 + tm->tm_year);
@@ -654,6 +655,61 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
}
+/* Return the `struct tm' representation of *TIMER in the local timezone.
+ Use local time if USE_LOCALTIME is nonzero, UTC otherwise. */
+struct tm *
+__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp)
+{
+ long int leap_correction;
+ int leap_extra_secs;
+
+ if (timer == NULL)
+ {
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ __libc_lock_lock (tzset_lock);
+
+ /* Update internal database according to current TZ setting.
+ POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname.
+ This is a good idea since this allows at least a bit more parallelism. */
+ tzset_internal (tp == &_tmbuf && use_localtime, 1);
+
+ if (__use_tzfile)
+ __tzfile_compute (*timer, use_localtime, &leap_correction,
+ &leap_extra_secs, tp);
+ else
+ {
+ if (! __offtime64 (timer, 0, tp))
+ tp = NULL;
+ else
+ __tz_compute (*timer, tp, use_localtime);
+ leap_correction = 0L;
+ leap_extra_secs = 0;
+ }
+
+ __libc_lock_unlock (tzset_lock);
+
+ if (tp)
+ {
+ if (! use_localtime)
+ {
+ tp->tm_isdst = 0;
+ tp->tm_zone = "GMT";
+ tp->tm_gmtoff = 0L;
+ }
+
+ if (__offtime64 (timer, tp->tm_gmtoff - leap_correction, tp))
+ tp->tm_sec += leap_extra_secs;
+ else
+ tp = NULL;
+ }
+
+ return tp;
+}
+
+
libc_freeres_fn (free_mem)
{
while (tzstring_list != NULL)
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=248b20957b3fd2e6359fb310f482b575e42d8eab
commit 248b20957b3fd2e6359fb310f482b575e42d8eab
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 13 10:40:51 2016 +0100
Support 64-bit syscalls from 32-bit GLIBC clock_gettime and vice versa
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 19458ba..35a6f59 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -29,10 +29,23 @@
/* The REALTIME and MONOTONIC clock are definitely supported in the
kernel. */
#define SYSDEP_GETTIME \
- SYSDEP_GETTIME_CPUTIME; \
- case CLOCK_REALTIME: \
- case CLOCK_MONOTONIC: \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ SYSDEP_GETTIME_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec64 tp64; \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+ if (retval >= 0) \
+ { \
+ if (tp64.tv_sec < 0x80000000) \
+ { \
+ tp->tv_sec = (__time_t) tp64.tv_sec; \
+ tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec; \
+ } \
+ } \
+ } \
break
/* We handled the REALTIME clock here. */
@@ -40,7 +53,20 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETTIME_CPU(clock_id, tp) \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec64 tp64; \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+ if (retval >= 0) \
+ { \
+ if (tp64.tv_sec < 0x80000000) \
+ { \
+ tp->tv_sec = (__time_t) tp64.tv_sec; \
+ tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec; \
+ } \
+ } \
+ } \
break
#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
@@ -49,10 +75,21 @@
/* The REALTIME and MONOTONIC clock are definitely supported in the
kernel. */
#define SYSDEP_GETTIME64 \
- SYSDEP_GETTIME64_CPUTIME; \
- case CLOCK_REALTIME: \
- case CLOCK_MONOTONIC: \
- retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ SYSDEP_GETTIME64_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec tp32; \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+ if (retval >= 0) \
+ { \
+ tp->tv_sec = tp32.tv_sec; \
+ if (tp->tv_sec < 0) tp->tv_sec += 0x100000000; \
+ tp->tv_nsec = tp32.tv_nsec; \
+ } \
+ } \
break
/* We handled the REALTIME clock here. */
@@ -60,7 +97,18 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
- retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec tp32; \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+ if (retval >= 0) \
+ { \
+ tp->tv_sec = tp32.tv_sec; \
+ if (tp->tv_sec < 0) tp->tv_sec += 0x100000000; \
+ tp->tv_nsec = tp32.tv_nsec; \
+ } \
+ } \
break
#define SYSDEP_GETTIME64_CPUTIME /* Default catches them too. */
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=fb6d3288edc288884fead5a3c7dbcbf06fc30dfa
commit fb6d3288edc288884fead5a3c7dbcbf06fc30dfa
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 13 10:40:51 2016 +0100
Fix wrong ifdef SYSDEP_GETTIME in __clock_gettime64
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index f11f663..c7c9ef6 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -143,7 +143,7 @@ __clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
switch (clock_id)
{
-#ifdef SYSDEP_GETTIME
+#ifdef SYSDEP_GETTIME64
SYSDEP_GETTIME64;
#endif
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=ee7ed5c855ca8eb1e47c5bc94844cb314d5529ed
commit ee7ed5c855ca8eb1e47c5bc94844cb314d5529ed
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 6 18:36:51 2016 +0100
WIP: Y2038: support 64-bit clock_gettime and clock_settime
diff --git a/bits/types.h b/bits/types.h
index 01753bd..596f4e5 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -136,7 +136,8 @@ __STD_TYPE __CLOCK_T_TYPE __clock_t; /* Type of CPU usage counts. */
__STD_TYPE __RLIM_T_TYPE __rlim_t; /* Type for resource measurement. */
__STD_TYPE __RLIM64_T_TYPE __rlim64_t; /* Type for resource measurement (LFS). */
__STD_TYPE __ID_T_TYPE __id_t; /* General type for IDs. */
-__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */
+__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch, Y2038-unsafe. */
+__STD_TYPE __TIME64_T_TYPE __time64_t; /* Seconds since the Epoch, Y2038-safe. */
__STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds. */
__STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */
@@ -175,6 +176,8 @@ __STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
__STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t;
/* Unsigned long type used in system calls. */
__STD_TYPE __SYSCALL_ULONG_TYPE __syscall_ulong_t;
+/* Signed quad type used in system calls. */
+__STD_TYPE __SYSCALL_SQUAD_TYPE __syscall_squad_t;
/* These few don't really vary by system, they always correspond
to one of the other defined types. */
diff --git a/bits/typesizes.h b/bits/typesizes.h
index ff20601..2dc41b0 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -48,6 +48,7 @@
#define __ID_T_TYPE __U32_TYPE
#define __CLOCK_T_TYPE __SLONGWORD_TYPE
#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __TIME64_T_TYPE __SQUAD_TYPE
#define __USECONDS_T_TYPE __U32_TYPE
#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
#define __DADDR_T_TYPE __S32_TYPE
@@ -59,6 +60,7 @@
#define __SSIZE_T_TYPE __SWORD_TYPE
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+#define __SYSCALL_SQUAD_TYPE __SQUAD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
#ifdef __LP64__
diff --git a/include/features.h b/include/features.h
index 650d4c5..d35f7b0 100644
--- a/include/features.h
+++ b/include/features.h
@@ -339,6 +339,10 @@
# define __USE_FILE_OFFSET64 1
#endif
+#if defined _TIME_BITS && _TIME_BITS == 64
+# define __USE_TIME_BITS64 1
+#endif
+
#if defined _DEFAULT_SOURCE
# define __USE_MISC 1
#endif
diff --git a/include/time.h b/include/time.h
index 684ceb8..2fa0764 100644
--- a/include/time.h
+++ b/include/time.h
@@ -21,7 +21,10 @@ libc_hidden_proto (strptime)
extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
libc_hidden_proto (__clock_gettime)
+extern __typeof (clock_gettime64) __clock_gettime64;
+libc_hidden_proto (__clock_gettime64)
extern __typeof (clock_settime) __clock_settime;
+extern __typeof (clock_settime64) __clock_settime64;
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index ffd6426..f11f663 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,51 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
}
weak_alias (__clock_gettime, clock_gettime)
libc_hidden_def (__clock_gettime)
+
+/* Get current value of CLOCK and store it in TP, 64-bit version. */
+int
+__clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
+{
+ int retval = -1;
+
+ switch (clock_id)
+ {
+#ifdef SYSDEP_GETTIME
+ SYSDEP_GETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ {
+ struct timeval tv;
+ retval = gettimeofday (&tv, NULL);
+ if (retval == 0)
+ TIMEVAL_TO_TIMESPEC (&tv, tp);
+ }
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_GETTIME64_CPU
+ SYSDEP_GETTIME64_CPU (clock_id, tp);
+#endif
+#if HP_TIMING_AVAIL
+ if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+ == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_gettime (clock_id, tp);
+ else
+#endif
+ __set_errno (EINVAL);
+ break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+ case CLOCK_PROCESS_CPUTIME_ID:
+ retval = hp_timing_gettime (clock_id, tp);
+ break;
+#endif
+ }
+
+ return retval;
+}
+weak_alias (__clock_gettime64, clock_gettime64)
+libc_hidden_def (__clock_gettime64)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index a3fd267..22044e7 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -69,8 +69,77 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
}
#endif
+/*
+ * We define the 64- and 32-bit versions of clock_gettime. The client
+ * code determines which one is called:
+ *
+ * - if client code defines ___USE_TIME_BITS64, then GLIBC defines
+ * _TIME_BITS equal to 64, and the 64-bit version of clock_gettime
+ * gets declared and used.
+ *
+ * - if client code does not define ___USE_TIME_BITS64, then GLIBC does
+ * not define _TIME_BITS and the 32-bit version of clock_gettime gets
+ * declared and used.
+ */
+
+
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
+int
+__clock_settime64 (clockid_t clock_id, const struct timespec64 *tp)
+{
+ int retval;
+
+ /* Make sure the time cvalue is OK. */
+ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ switch (clock_id)
+ {
+#define HANDLE_REALTIME \
+ do { \
+ struct timeval tv; \
+ TIMESPEC_TO_TIMEVAL (&tv, tp); \
+ \
+ retval = settimeofday (&tv, NULL); \
+ } while (0)
+
+#ifdef SYSDEP_SETTIME64
+ SYSDEP_SETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ HANDLE_REALTIME;
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_SETTIME64_CPU
+ SYSDEP_SETTIME64_CPU;
+#endif
+#ifndef HANDLED_CPUTIME
+# if HP_TIMING_AVAIL
+ if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
+ || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_settime (clock_id, tp);
+ else
+# endif
+ {
+ __set_errno (EINVAL);
+ retval = -1;
+ }
+#endif
+ break;
+ }
+
+ return retval;
+}
+weak_alias (__clock_settime64, clock_settime64)
-/* Set CLOCK to value TP. */
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
int
__clock_settime (clockid_t clock_id, const struct timespec *tp)
{
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7e5ba53..7410904 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -9,11 +9,16 @@ libc {
}
GLIBC_2.24 {
recvmsg; sendmsg;
+ clock_gettime64; clock_settime64;
}
GLIBC_PRIVATE {
# A copy of sigaction lives in libpthread, and needs these.
__default_sa_restorer; __default_rt_sa_restorer;
# nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
__vdso_clock_gettime;
+ # (aaribaud) do we need this?
+ __clock_gettime64;
+ __clock_settime64;
+ __vdso_clock_gettime64;
}
}
diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index 6338200..b99c24b 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -23,6 +23,7 @@
int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
static inline void
_libc_vdso_platform_setup (void)
@@ -36,6 +37,11 @@ _libc_vdso_platform_setup (void)
p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
PTR_MANGLE (p);
VDSO_SYMBOL (clock_gettime) = p;
+
+ /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */
+ p = _dl_vdso_vsym ("__vdso_clock_gettime64", NULL);
+ PTR_MANGLE (p);
+ VDSO_SYMBOL (clock_gettime64) = p;
}
# define VDSO_SETUP _libc_vdso_platform_setup
diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
index bf5f012..1c86b90 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -27,6 +27,7 @@
extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
attribute_hidden;
extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
#endif
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 8bc979a..9445f8a 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -90,6 +90,8 @@ GLIBC_2.23 fts64_read F
GLIBC_2.23 fts64_set F
GLIBC_2.24 GLIBC_2.24 A
GLIBC_2.24 quick_exit F
+GLIBC_2.24 clock_gettime64 F
+GLIBC_2.24 clock_settime64 F
GLIBC_2.25 GLIBC_2.25 A
GLIBC_2.25 strfromd F
GLIBC_2.25 strfromf F
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index f6be61b..19458ba 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -44,4 +44,24 @@
break
#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
+/* 64-bit versions */
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+ kernel. */
+#define SYSDEP_GETTIME64 \
+ SYSDEP_GETTIME64_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ break
+
+/* We handled the REALTIME clock here. */
+#define HANDLED_REALTIME 1
+#define HANDLED_CPUTIME 1
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ break
+#define SYSDEP_GETTIME64_CPUTIME /* Default catches them too. */
+
#include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index bfd3064..01c5989 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -23,6 +23,11 @@
/* The REALTIME clock is definitely supported in the kernel. */
+#define SYSDEP_SETTIME64 \
+ case CLOCK_REALTIME: \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp); \
+ break
+
#define SYSDEP_SETTIME \
case CLOCK_REALTIME: \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
@@ -32,6 +37,9 @@
#define HANDLED_REALTIME 1
#define HANDLED_CPUTIME 1
+#define SYSDEP_SETTIME64_CPU \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp)
+
#define SYSDEP_SETTIME_CPU \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9f..dcb0ab5 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -11,4 +11,11 @@ struct timespec
__syscall_slong_t tv_nsec; /* Nanoseconds. */
};
+/* This one is for holding a Y2038-safe time value. */
+struct timespec64
+{
+ __time64_t tv_sec; /* Seconds. */
+ __syscall_squad_t tv_nsec; /* Nanoseconds. */
+};
+
#endif
diff --git a/time/time.h b/time/time.h
index c38fac7..860aab7 100644
--- a/time/time.h
+++ b/time/time.h
@@ -223,10 +223,19 @@ extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
/* Get current value of clock CLOCK_ID and store it in TP. */
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
+extern int clock_gettime64 (clockid_t __clock_id, struct timespec64 *__tp) __THROW;
/* Set clock CLOCK_ID to value TP. */
extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
__THROW;
+extern int clock_settime64 (clockid_t __clock_id, const struct timespec64 *__tp)
+ __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define timespec timespec64
+#define clock_gettime clock_gettime64
+#define clock_settime clock_settime64
+#endif
# ifdef __USE_XOPEN2K
/* High-resolution sleep with the specified clock.
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources
More information about the Glibc-cvs
mailing list