From 536889d79703f69c4c9f3c4b7fb6c2bee6d0c10c Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Sun, 12 Jan 2025 22:23:16 +0000 Subject: [PATCH] Interpose clock_gettime64 Since debian generally added 64-bit time support on 32-bit arches, now glibc sometimes calls the clock_gettime64 syscall (and library wrapper). This function was missing, and is added here. Patch originally supplied here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1064555 --- src/libfaketime.c | 24 ++++++++++++++++++++++++ test/Makefile | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libfaketime.c b/src/libfaketime.c index c59c122..cb37bcf 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -164,6 +164,13 @@ struct utimbuf { #include #endif +/* __timespec64 is needed for clock_gettime64 on 32-bit architectures */ +struct __timespec64 +{ + uint64_t tv_sec; /* Seconds */ + uint64_t tv_nsec; /* Nanoseconds */ +}; + /* * Per thread variable, which we turn on inside real_* calls to avoid modifying * time multiple times of for the whole process to prevent faking time @@ -201,6 +208,7 @@ static time_t (*real_time) (time_t *); static int (*real_ftime) (struct timeb *); static int (*real_gettimeofday) (struct timeval *, void *); static int (*real_clock_gettime) (clockid_t clk_id, struct timespec *tp); +static int (*real_clock_gettime64) (clockid_t clk_id, struct __timespec64 *tp); #ifdef TIME_UTC static int (*real_timespec_get) (struct timespec *ts, int base); #endif @@ -2417,6 +2425,17 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) return result; } +/* this is used by 32-bit architectures only */ +int __clock_gettime64(clockid_t clk_id, struct __timespec64 *tp64) +{ + struct timespec tp; + int result; + + result = clock_gettime(clk_id, &tp); + tp64->tv_sec = tp.tv_sec; + tp64->tv_nsec = tp.tv_nsec; + return result; +} #ifdef TIME_UTC #ifdef MACOS_DYLD_INTERPOSE @@ -2760,6 +2779,11 @@ static void ftpl_really_init(void) { real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime"); } + real_clock_gettime64 = dlsym(RTLD_NEXT, "clock_gettime64"); + if (NULL == real_clock_gettime64) + { + real_clock_gettime64 = dlsym(RTLD_NEXT, "__clock_gettime64"); + } #ifdef FAKE_TIMERS #if defined(__sun) real_timer_gettime_233 = dlsym(RTLD_NEXT, "timer_gettime"); diff --git a/test/Makefile b/test/Makefile index 763ebc4..01cbd9f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,6 +1,6 @@ CC = gcc -CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS) +CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS) -U_FILE_OFFSET_BITS -U_TIME_BITS LDFLAGS += -lrt -lpthread SRC = timetest.c