File: interpose-clock_gettime64.patch

package info (click to toggle)
faketime 0.9.10%2B2024-06-05%2Bgba9ed5b2-0.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,816 kB
  • sloc: ansic: 5,291; sh: 613; makefile: 178; pascal: 21
file content (86 lines) | stat: -rw-r--r-- 2,818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From: Helge Deller <deller@gmx.de>
Date: Sun, 12 Jan 2025 22:23:16 +0000
Subject: 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.

Closes: #1064555


This patch is part of an upstream MR:
  https://github.com/wolfcw/libfaketime/pull/487
---
 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 <sys/random.h>
 #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