[PATCH v2 1/1] mach: Use the host_get_time64 to replace the deprecated host_get_time for CLOCK_REALTIME when it's available

Samuel Thibault samuel.thibault@gnu.org
Sun Mar 23 18:46:49 GMT 2025


Zhaoming Luo, le dim. 23 mars 2025 10:47:14 +0800, a ecrit:
> Check the availability of host_get_time64 and use it to replace
> host_get_time for CLOCK_REALTIME when it's available.

>      case CLOCK_REALTIME:
>        {
> -	/* __host_get_time can only fail if passed an invalid host_t.
> +	/* __host_get_time(64) 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
>  	   this will never happen.  */
> +#ifdef HAVE_HOST_GET_TIME64
> +	time_value64_t tv;
> +	__host_get_time64 (__mach_host_self (), &tv);
> +	TIME_VALUE64_TO_TIMESPEC (&tv, ts);
> +#else
>  	time_value_t tv;
>  	__host_get_time (__mach_host_self (), &tv);
>  	TIME_VALUE_TO_TIMESPEC (&tv, ts);
> +#endif

You do not want to disable the __host_get_time call entirely: you might
be compiling against newer gnumach headers, but running an older gnumach
kernel. So you need to keep the __host_get_time code, and fallback to it
if __host_get_time64 fails with MIG_BAD_ID, see the
HAVE_HOST_GET_UPTIME64 case for instance.

Samuel


More information about the Libc-alpha mailing list