Skip to content

Support for a 64bit time_t type #84

@th-otto

Description

@th-otto

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:

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:

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

  1. they cannot be changed for TOS-compatibility
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions