[libc] Make time_t 64 bits long on all platforms but arm32
This patch changes the size of time_t to be an int64_t. This still follows the POSIX standard which only requires time_t to be an integer. Making time_t a 64-bit integer also fixes two cases in 32 bits platforms that use SYS_clock_nanosleep_time64 and SYS_clock_gettime64, as the name of these calls implies, they require a 64-bit time_t. For instance, in rv32, the 32-bit version of these syscalls is not available. We also follow glibc here, where time_t is still a 32-bit integer in arm32. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D159125
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
#ifndef __LLVM_LIBC_TYPES_TIME_T_H__
|
||||
#define __LLVM_LIBC_TYPES_TIME_T_H__
|
||||
|
||||
#if (defined(__arm__) || defined(_M_ARM))
|
||||
typedef __INTPTR_TYPE__ time_t;
|
||||
#else
|
||||
typedef __INT64_TYPE__ time_t;
|
||||
#endif
|
||||
|
||||
#endif // __LLVM_LIBC_TYPES_TIME_T_H__
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "src/__support/error_or.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
|
||||
#include <stdint.h> // For int64_t.
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
#include <time.h>
|
||||
|
||||
@@ -27,12 +28,12 @@ LIBC_INLINE ErrorOr<int> clock_gettimeimpl(clockid_t clockid,
|
||||
static_cast<long>(clockid),
|
||||
reinterpret_cast<long>(ts));
|
||||
#elif defined(SYS_clock_gettime64)
|
||||
struct timespec64 ts64;
|
||||
static_assert(
|
||||
sizeof(time_t) == sizeof(int64_t),
|
||||
"SYS_clock_gettime64 requires struct timespec with 64-bit members.");
|
||||
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64,
|
||||
static_cast<long>(clockid),
|
||||
reinterpret_cast<long>(&ts64));
|
||||
ts->tv_sec = static_cast<time_t>(ts64.tv_sec);
|
||||
ts->tv_nsec = static_cast<long>(ts64.tv_nsec);
|
||||
reinterpret_cast<long>(ts));
|
||||
#else
|
||||
#error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available."
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
|
||||
#include <stdint.h> // For int64_t.
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace __llvm_libc {
|
||||
@@ -21,8 +22,11 @@ LLVM_LIBC_FUNCTION(int, nanosleep,
|
||||
#if SYS_nanosleep
|
||||
int ret = __llvm_libc::syscall_impl<int>(SYS_nanosleep, req, rem);
|
||||
#elif defined(SYS_clock_nanosleep_time64)
|
||||
int ret =
|
||||
__llvm_libc::syscall_impl<int>(SYS_clock_nanosleep_time64, req, rem);
|
||||
static_assert(
|
||||
sizeof(time_t) == sizeof(int64_t),
|
||||
"SYS_clock_gettime64 requires struct timespec with 64-bit members.");
|
||||
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_nanosleep_time64,
|
||||
CLOCK_REALTIME, 0, req, rem);
|
||||
#else
|
||||
#error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available."
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user