|
From: | Aleksandar Markovic |
Subject: | Re: [PATCH v4 2/3] linux-user/syscall: Add support for clock_gettime64/clock_settime64 |
Date: | Wed, 4 Mar 2020 08:59:26 +0100 |
1:53 AM Sre, 04.03.2020. Alistair Francis <address@hidden> је написао/ла:
>
> Add support for the clock_gettime64/clock_settime64 syscalls. Currently
> we only support these syscalls when running on 64-bit hosts.
>
For clarity, "Currently we only support" should be replaced with "This patch supports only".
> Signed-off-by: Alistair Francis <address@hidden>
> ---
> linux-user/syscall.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index c000fb07c5..82468e018d 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1236,6 +1236,22 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,
> }
> #endif
>
> +#if defined(TARGET_NR_clock_settime64) && HOST_LONG_BITS == 64
> +static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
> + abi_ulong target_addr)
> +{
> + struct target_timespec *target_ts;
> +
> + if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) {
> + return -TARGET_EFAULT;
> + }
> + __get_user(host_ts->tv_sec, &target_ts->tv_sec);
> + __get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
> + unlock_user_struct(target_ts, target_addr, 0);
> + return 0;
> +}
> +#endif
> +
> static inline abi_long host_to_target_timespec(abi_ulong target_addr,
> struct timespec *host_ts)
> {
> @@ -11465,6 +11481,20 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
> return ret;
> }
> #endif
> +#ifdef TARGET_NR_clock_settime64
> +# if HOST_LONG_BITS == 64
> + case TARGET_NR_clock_settime64:
> + {
> + struct timespec ts;
> +
> + ret = target_to_host_timespec64(&ts, arg2);
> + if (!is_error(ret)) {
> + ret = get_errno(clock_settime(arg1, &ts));
> + }
> + return ret;
> + }
> +# endif
> +#endif
> #ifdef TARGET_NR_clock_gettime
> case TARGET_NR_clock_gettime:
> {
> @@ -11476,6 +11506,19 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
> return ret;
> }
> #endif
> +#ifdef TARGET_NR_clock_gettime64
> +# if HOST_LONG_BITS == 64
> + case TARGET_NR_clock_gettime64:
> + {
> + struct timespec ts;
> + ret = get_errno(clock_gettime(arg1, &ts));
> + if (!is_error(ret)) {
> + ret = host_to_target_timespec64(arg2, &ts);
> + }
> + return ret;
> + }
> +# endif
> +#endif
> #ifdef TARGET_NR_clock_getres
> case TARGET_NR_clock_getres:
> {
> --
Nice patch for the first version, still I think the patch could be much better.
Why not support 32-bit hosts? If a 32-bit host supports clock_<get|set>time64(), the mapping is obvious. If not, the implementation could be "best effort" based, using host's clock_<get|set>time().
Regards,
Aleksandar
> 2.25.1
>
>
[Prev in Thread] | Current Thread | [Next in Thread] |