]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mach: Use the host_get_time64 to replace the deprecated host_get_time for CLOCK_REALT...
authorZhaoming Luo <zhmingluo@163.com>
Mon, 24 Mar 2025 05:20:42 +0000 (13:20 +0800)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 25 Mar 2025 00:10:10 +0000 (01:10 +0100)
Check the availability of host_get_time64 and use it to replace
host_get_time for CLOCK_REALTIME when it's available. Fall back to
host_get_time if gnumach does not support host_get_time64 but the
gnumach headers do.

host_get_time is deprecated
See https://git.savannah.gnu.org/cgit/hurd/gnumach.git/commit/?id=569df850cd7badd1e36132ad3b44aa76a4d27c25
However, it's kept for backward compactbility.

* config.h.in: Add HAVE_HOST_GET_TIME64 config entry.
* sysdeps/mach/clock_gettime.c: Use host_get_time64 for CLOCK_REALTIME
  when it's possible, fall to host_get_time otherwise.
* sysdeps/mach/configure: Check the existence of host_get_time64 RPC.
* sysdeps/mach/configure.ac: Check the existence of host_get_time64 RPC.
Message-ID: <20250324052042.19803-1-zhmingluo@163.com>

config.h.in
sysdeps/mach/clock_gettime.c
sysdeps/mach/configure
sysdeps/mach/configure.ac

index cdbd555366b4f03853c1fa1676de3d78c23da45e..d3575c98458ad3e1c591a6dc47db2aac6809bc15 100644 (file)
 /* Mach specific: define if the `host_get_uptime64' RPC is available.  */
 #undef HAVE_HOST_GET_UPTIME64
 
+/* Mach specific: define if the `host_get_time64' RPC is available.  */
+#undef HAVE_HOST_GET_TIME64
+
 /* Mach specific: define if the `thread_set_name' RPC is available.  */
 #undef  HAVE_MACH_THREAD_SET_NAME
 
index 381ccb8451fa99f4da3900429893feb74ae9ffc2..8d0143cfb859c8da4ec9497a26038338c91dda2b 100644 (file)
@@ -57,6 +57,26 @@ __clock_gettime (clockid_t clock_id, struct timespec *ts)
 
     case CLOCK_REALTIME:
       {
+#ifdef HAVE_HOST_GET_TIME64
+       time_value64_t tv_64;
+       err = __host_get_time64 (__mach_host_self (), &tv_64);
+
+       /* If err is MIG_BAD_ID, it means an old gnumach which does not
+          support __host_get_time64 is running against the new gnumach
+          headers which has the signature of __host_get_time64. In that
+          case, we fall back to __host_get_time.  */
+       if (err != MIG_BAD_ID)
+         {
+           if (err)
+             {
+               __set_errno (err);
+               return -1;
+             }
+
+           TIME_VALUE64_TO_TIMESPEC (&tv_64, ts);
+           return 0;
+         }
+#endif
        /* __host_get_time can only fail if passed an invalid host_t.
           __mach_host_self could theoretically fail (producing an
           invalid host_t) due to resource exhaustion, but we assume
index 8aa6bbb18b8883c1bfb55164ebc58acf6af10ec6..311b2dd30bb80850c8348af39114a31b6e90c9f7 100644 (file)
@@ -491,6 +491,36 @@ if test $libc_cv_mach_rpc_host_get_uptime64 = yes; then
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for host_get_time64 in mach_host.defs" >&5
+printf %s "checking for host_get_time64 in mach_host.defs... " >&6; }
+if test ${libc_cv_mach_rpc_host_get_time64+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <mach/mach_host.defs>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP_TRADITIONAL "host_get_time64" >/dev/null 2>&1
+then :
+  libc_cv_mach_rpc_host_get_time64=yes
+else case e in #(
+  e) libc_cv_mach_rpc_host_get_time64=no ;;
+esac
+fi
+rm -rf conftest*
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_mach_rpc_host_get_time64" >&5
+printf "%s\n" "$libc_cv_mach_rpc_host_get_time64" >&6; }
+if test $libc_cv_mach_rpc_host_get_time64 = yes; then
+  printf "%s\n" "#define HAVE_HOST_GET_TIME64 1" >>confdefs.h
+
+fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for thread_set_name in gnumach.defs" >&5
 printf %s "checking for thread_set_name in gnumach.defs... " >&6; }
 if test ${libc_cv_mach_rpc_thread_set_name+y}
index 08e5fdefe9d3610550a06ed8c227bf42fb7fe499..3a6f2443e2c95de2ccbe3e2513550fb5b108caf1 100644 (file)
@@ -94,6 +94,8 @@ mach_RPC_CHECK(mach_host.defs, host_page_size,
               HAVE_HOST_PAGE_SIZE)
 mach_RPC_CHECK(mach_host.defs, host_get_uptime64,
               HAVE_HOST_GET_UPTIME64)
+mach_RPC_CHECK(mach_host.defs, host_get_time64,
+              HAVE_HOST_GET_TIME64)
 mach_RPC_CHECK(gnumach.defs, thread_set_name,
               HAVE_MACH_THREAD_SET_NAME)
 mach_RPC_CHECK(gnumach.defs, thread_get_name,