-
Notifications
You must be signed in to change notification settings - Fork 12
Description
As you are surely aware, there will be a problem with our current 32bit type time_t, since values after 19 Jan 2038 will become negative and thus cannot be represented. Although that will give us about 13 years before it really will become a problem, an increasing number of packages already may misbehave when working with 32bit time_t values. Eg. the some backends in gcc are starting to deprecate such a type in their runtime library, and as a result expect the underlying c-library to support a 64bit time_t type.
Actually, i think the situation is not that bad. For example, our struct stat already has members for the high values of time values:
Line 45 in fe785b5
| long __st_high_mtime; |
So using a 64bit time_t for those will not change the layout.
Introducing such a type (from the application point of view) should be implement following glibc. The application can define _TIME_BITS to be either 32 or 64, and will get a default value for it if that is undefined (much like is done for _FILE_OFFSET_BITS for file related functions). For a start, we could even set the default to 32 so existing applications don't break.
Using a 64bit time_t has (after a first look) direct consequences to the following structures
- struct timeval
- struct timespec
- struct itimerspec
- struct itimerval
- struct utimbuf
- struct timeb
- struct msqid_ds
- struct shmid_ds
- struct semid_ds
So we will need alternate names for all those. As a result, following functions in mintlib will be affected:
- gettimeofday()
Line 18 in fe785b5
__gettimeofday (struct timeval *tp, struct timezone *tzp) - settimeofday)
Line 17 in fe785b5
__settimeofday (const struct timeval *tp, const struct timezone *tzp) - time()
Line 17 in fe785b5
__time (time_t *buf) - mktime()
Line 2367 in fe785b5
time_t mktime(struct tm *tmp) - difftime()
Line 16 in fe785b5
double difftime(time_t time1, time_t time0) - gmtime()
Line 1762 in fe785b5
struct tm *gmtime(const time_t * timep) - gmtime_r()
Line 1756 in fe785b5
struct tm *gmtime_r(const time_t *__restrict timep, struct tm *__restrict tmp) - localtime()
Line 1711 in fe785b5
struct tm *localtime(const time_t *timep) - localtime_r()
Line 1722 in fe785b5
struct tm *localtime_r(const time_t *__restrict timep, struct tm *__restrict tmp) - ctime()
Line 9 in fe785b5
char *ctime(const time_t *timep) - ctime_r()
Line 18 in fe785b5
char *ctime_r(const time_t *timep, char *buf) - timegm()
Line 2393 in fe785b5
time_t timegm(struct tm *tmp) - timelocal()
Line 2386 in fe785b5
time_t timelocal(struct tm *tmp) - clock_gettime()
Line 22 in fe785b5
__clock_gettime(clockid_t clock_id, struct timespec *tp) - clock_settime() NYI
- utime()
Line 28 in fe785b5
__utime (const char *_filename, const struct utimbuf *_tset) - utimes()
Line 24 in fe785b5
__utimes (const char *filename, const struct timeval tvp[2]) - futimens() NYI
- semctl()
Line 38 in fe785b5
__semctl (int semid, int semnum, int cmd, ...) - semtimedop() NYI
- sendmsg()
Line 22 in fe785b5
__sendmsg (int fd, const struct msghdr *msg, int flags) - recvmsg()
Line 22 in fe785b5
__recvmsg (int fd, struct msghdr *msg, int flags) - adjtime
Line 16 in fe785b5
int __adjtime (__const struct timeval *__delta, - getitimer()
Line 19 in fe785b5
__getitimer (enum __itimer_which which, struct itimerval* old) - setitimer()
Line 19 in fe785b5
__setitimer (enum __itimer_which which, const struct itimerval* new, - ftime()
Line 23 in fe785b5
ftime (struct timeb *timebuf) - futimes()
Line 26 in fe785b5
int __futimes (int fd, const struct timeval tvp[2]) - stime()
Line 18 in fe785b5
__stime (const time_t *now)
Note that some of the IPC functions are not yet implement in mintlib and/or the kernel so are currently not that important.
There would also be some more posix functions that are affected, but which are not implemented in mintlib yet.
There are also a bunch of other functions that take a timeval/timespec as argument, but use it as a relative timeout value rather than an absolute value, so maybe don't need to be changed for now (you don't want to do a sleep() for more than 140 years). This also includes pthread_* functions, should they be implemented.
- select()
- pselect()
- poll()
- ppoll()
- fcntl()
- sem_timedwait()
- sem_clockwait()
- nanosleep()
- clock_getres()
- clock_nanosleep()
- getrusage()
- wait3()
- wait4()
As a result of the above, it seems we would need only 2 new functions in the mint kernel for now:
- Tgettimeofday64()
- Tsettimeofday64()
Tgetdate()/Tsetdate are not affected because
- they cannot be changed for TOS-compatibility
- they use a base year of 1980 and therefor will only overflow at 2108
Some other functions should be checked whether they behave correctly. Eg. all the functions that deal with struct stat should check the time values from filesystems to fit into 32bits if needed.
Obviously, we need a kernel first which implements the new functions, otherwise those new interfaces can't be used.
Any comments on these are welcome, especially should i have missed any types/functions that are affected.
PS.: Note that the timezone database is not affected by this. zic (the timezone info compiler) uses a 64bit type internally for quite some time, and produces tables that contain both 32bit and 64bit values.