1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-01 10:06:57 +03:00

mach: Use the host_get_time64 to replace the deprecated host_get_time for CLOCK_REALTIME when it's available

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>
This commit is contained in:
Zhaoming Luo
2025-03-24 13:20:42 +08:00
committed by Samuel Thibault
parent b62692d3c7
commit 0544df4f4a
4 changed files with 55 additions and 0 deletions

View 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