summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhaoming Luo <zhmingluo@163.com>2025-05-03 21:28:08 +0800
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2025-05-03 15:32:31 +0200
commit685bacfc48e05fab8be172f5659f7df4874d9834 (patch)
tree1d440860668ef4a0f127f393eae8fedeacaf4566
parent88cfa0464dc86d088e0f8484bc15a279d83919e9 (diff)
libshouldbeinlibc: Use 64bit mapped time values in maptime_read when possible
Use 64bit mapped time values in maptime_read when the kernel and the mapped_time_value structure in header file time_value.h support it. Otherwise step back to use the 32bit time. Message-ID: <20250503132808.15359-1-zhmingluo@163.com>
-rw-r--r--configure.ac3
-rw-r--r--libshouldbeinlibc/maptime.h16
2 files changed, 19 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 1f814438..d7e33e56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -335,6 +335,9 @@ AC_SUBST([libdaemon_CFLAGS])
AC_CHECK_MEMBERS([struct thread_sched_info.last_processor],,,
[#include <mach/thread_info.h>])
+AC_CHECK_MEMBERS([struct mapped_time_value.time_value.seconds],,,
+ [#include <mach/time_value.h>])
+
PKG_CHECK_MODULES([libblkid], [blkid],
[AC_DEFINE([HAVE_BLKID], [1], [Use libblkid])],
[true])
diff --git a/libshouldbeinlibc/maptime.h b/libshouldbeinlibc/maptime.h
index 04ce0353..3a595ae5 100644
--- a/libshouldbeinlibc/maptime.h
+++ b/libshouldbeinlibc/maptime.h
@@ -48,6 +48,22 @@ extern void maptime_read (volatile struct mapped_time_value *mtime, struct timev
MAPTIME_EI void
maptime_read (volatile struct mapped_time_value *mtime, struct timeval *tv)
{
+#ifdef HAVE_STRUCT_MAPPED_TIME_VALUE_TIME_VALUE_SECONDS
+ /* Use the 64bit time if it is supported in the kernel. Otherwise step
+ back to the 32bit time. */
+ if (mtime->time_value.seconds != 0)
+ {
+ do
+ {
+ tv->tv_sec = mtime->time_value.seconds;
+ __sync_synchronize ();
+ tv->tv_usec = mtime->time_value.nanoseconds / 1000;
+ __sync_synchronize ();
+ }
+ while (tv->tv_sec != mtime->check_seconds64);
+ return;
+ }
+#endif
do
{
tv->tv_sec = mtime->seconds;