linux-user: Add support for 'clock_nanosleep_time64()' and 'clock_adjtime64()'

This patch implements functionality for following time64 syscall:

*clock_nanosleep_time64()

    This is a year 2038 safe vairant of syscall:
    int clock_nanosleep(clockid_t clockid, int flags,
                        const struct timespec *request,
                        struct timespec *remain)
    --high-resolution sleep with specifiable clock--
    man page: https://man7.org/linux/man-pages/man2/clock_nanosleep.2.html

*clock_adjtime64()

    This is a year 2038 safe variant of syscall:
    int clock_adjtime(clockid_t clk_id, struct timex *buf)
    --tune kernel clock--
    man page: https://man7.org/linux/man-pages/man2/clock_adjtime.2.html

Implementation notes:

    Syscall 'clock_nanosleep_time64()' was implemented similarly
    to syscall 'clock_nanosleep()' except that 'host_to_target_timespec64()'
    and 'target_to_host_timespec64()' were used instead of the regular
    'host_to_target_timespec()' and 'target_to_host_timespec()'.

    For 'clock_adjtime64()' a 64-bit target kernel version of 'struct timex'
    was defined in 'syscall_defs.h': 'struct target__kernel_timex'.
    This type was used to convert the values of 64-bit timex type between
    host and target. For this purpose a 64-bit timex converting functions
    'target_to_host_timex64()' and 'host_to_target_timex64()'. An existing
    function 'copy_to_user_timeval64()' was used to convert the field
    'time' which if of type 'struct timeval' from host to target.
    Function 'copy_from_user_timveal64()' was added in this patch and
    used to convert the 'time' field from target to host.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824192116.65562-2-Filip.Bozuta@syrmia.com>
[lv: add missing ifdef's]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Filip Bozuta 2020-08-24 21:21:15 +02:00 committed by Laurent Vivier
parent d107e37573
commit 6ac03b2cac
2 changed files with 170 additions and 3 deletions

View file

@ -294,6 +294,37 @@ struct target_timex {
abi_int:32; abi_int:32; abi_int:32;
};
struct target__kernel_timex {
abi_uint modes; /* Mode selector */
abi_int: 32; /* pad */
abi_llong offset; /* Time offset */
abi_llong freq; /* Frequency offset */
abi_llong maxerror; /* Maximum error (microseconds) */
abi_llong esterror; /* Estimated error (microseconds) */
abi_int status; /* Clock command/status */
abi_int: 32; /* pad */
abi_llong constant; /* PLL (phase-locked loop) time constant */
abi_llong precision; /* Clock precision (microseconds, ro) */
abi_llong tolerance; /* Clock freq. tolerance (ppm, ro) */
struct target__kernel_sock_timeval time; /* Current time */
abi_llong tick; /* Microseconds between clock ticks */
abi_llong ppsfreq; /* PPS (pulse per second) frequency */
abi_llong jitter; /* PPS jitter (ro); nanoseconds */
abi_int shift; /* PPS interval duration (seconds) */
abi_int: 32; /* pad */
abi_llong stabil; /* PPS stability */
abi_llong jitcnt; /* PPS jitter limit exceeded (ro) */
abi_llong calcnt; /* PPS calibration intervals */
abi_llong errcnt; /* PPS calibration errors */
abi_llong stbcnt; /* PPS stability limit exceeded */
abi_int tai; /* TAI offset */
/* Further padding bytes to allow for future expansion */
abi_int:32; abi_int:32; abi_int:32; abi_int:32;
abi_int:32; abi_int:32; abi_int:32; abi_int:32;
abi_int:32; abi_int:32; abi_int:32;
};
typedef abi_long target_clock_t;
#define TARGET_HZ 100