Message ID | 20200726235221.337529-3-Filip.Bozuta@syrmia.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | linux-user: Introducing functionality for two time64 syscalls | expand |
Le 27/07/2020 à 01:52, Filip Bozuta a écrit : > This patch implements functionality for following time64 syscalls: > > *mq_timedsend_time64() > > This is a year 2038 safe vairant of syscall: > > int mq_timedsend(mqd_t mqdes, const char *msg_ptr, > size_t msg_len, unsigned int msg_prio, > const struct timespec *abs_timeout) > --send a message to a message queue-- > man page: https://www.man7.org/linux/man-pages/man2/mq_timedsend.2.html > > *mq_timedreceive_time64() > > This is a year 2038 safe variant of syscall: > > ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, > size_t msg_len, unsigned int *msg_prio, > const struct timespec *abs_timeout) > --receive a message from a message queue-- > man page: https://man7.org/linux/man-pages/man3/mq_receive.3.html > > Implementation notes: > > These syscalls were implemented in similar ways like > 'mq_timedsend()' and 'mq_timedreceive' except that > functions 'target_to_host_timespec64()' and > 'host_to_target_timespec64()' were used to convert > values of 'struct timespec' between host and target. > > Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> > --- > linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 55 insertions(+), 3 deletions(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 1f8d04934a..d8cb3c0fd1 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -829,11 +829,13 @@ safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz, > safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, > unsigned, nsops, const struct timespec *, timeout) > #endif > -#ifdef TARGET_NR_mq_timedsend > +#if defined(TARGET_NR_mq_timedsend) || \ > + defined(TARGET_NR_mq_timedsend_time64) > safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, > size_t, len, unsigned, prio, const struct timespec *, timeout) > #endif > -#ifdef TARGET_NR_mq_timedreceive > +#if defined(TARGET_NR_mq_timedreceive) || \ > + defined(TARGET_NR_mq_timedreceive_time64) > safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, > size_t, len, unsigned *, prio, const struct timespec *, timeout) > #endif > @@ -1243,7 +1245,9 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts, > } > #endif > > -#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) > +#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ > + defined(TARGET_NR_mq_timedsend_time64) || \ > + defined(TARGET_NR_mq_timedreceive_time64) > static inline abi_long target_to_host_timespec64(struct timespec *host_ts, > abi_ulong target_addr) > { > @@ -11831,6 +11835,27 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, > } > return ret; > #endif > +#ifdef TARGET_NR_mq_timedsend_time64 > + case TARGET_NR_mq_timedsend_time64: > + { > + struct timespec ts; > + > + p = lock_user(VERIFY_READ, arg2, arg3, 1); > + if (arg5 != 0) { > + if (target_to_host_timespec64(&ts, arg5)) { > + return -TARGET_EFAULT; > + } > + ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, &ts)); > + if (host_to_target_timespec64(arg5, &ts)) { > + return -TARGET_EFAULT; > + } > + } else { > + ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, NULL)); > + } > + unlock_user(p, arg2, arg3); > + } > + return ret; > +#endif > > #ifdef TARGET_NR_mq_timedreceive > case TARGET_NR_mq_timedreceive: > @@ -11858,6 +11883,33 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, > } > return ret; > #endif > +#ifdef TARGET_NR_mq_timedreceive_time64 > + case TARGET_NR_mq_timedreceive_time64: > + { > + struct timespec ts; > + unsigned int prio; > + > + p = lock_user(VERIFY_READ, arg2, arg3, 1); > + if (arg5 != 0) { > + if (target_to_host_timespec64(&ts, arg5)) { > + return -TARGET_EFAULT; > + } > + ret = get_errno(safe_mq_timedreceive(arg1, p, arg3, > + &prio, &ts)); > + if (host_to_target_timespec64(arg5, &ts)) { > + return -TARGET_EFAULT; > + } > + } else { > + ret = get_errno(safe_mq_timedreceive(arg1, p, arg3, > + &prio, NULL)); > + } > + unlock_user(p, arg2, arg3); > + if (arg4 != 0) { > + put_user_u32(prio, arg4); > + } > + } > + return ret; > +#endif > > /* Not implemented for now... */ > /* case TARGET_NR_mq_notify: */ > Same comment as for PATCH 1. Except that: Reviewed-by: Laurent Vivier <laurent@vivier.eu>
diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1f8d04934a..d8cb3c0fd1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -829,11 +829,13 @@ safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz, safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, unsigned, nsops, const struct timespec *, timeout) #endif -#ifdef TARGET_NR_mq_timedsend +#if defined(TARGET_NR_mq_timedsend) || \ + defined(TARGET_NR_mq_timedsend_time64) safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, size_t, len, unsigned, prio, const struct timespec *, timeout) #endif -#ifdef TARGET_NR_mq_timedreceive +#if defined(TARGET_NR_mq_timedreceive) || \ + defined(TARGET_NR_mq_timedreceive_time64) safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, size_t, len, unsigned *, prio, const struct timespec *, timeout) #endif @@ -1243,7 +1245,9 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts, } #endif -#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) +#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ + defined(TARGET_NR_mq_timedsend_time64) || \ + defined(TARGET_NR_mq_timedreceive_time64) static inline abi_long target_to_host_timespec64(struct timespec *host_ts, abi_ulong target_addr) { @@ -11831,6 +11835,27 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } return ret; #endif +#ifdef TARGET_NR_mq_timedsend_time64 + case TARGET_NR_mq_timedsend_time64: + { + struct timespec ts; + + p = lock_user(VERIFY_READ, arg2, arg3, 1); + if (arg5 != 0) { + if (target_to_host_timespec64(&ts, arg5)) { + return -TARGET_EFAULT; + } + ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, &ts)); + if (host_to_target_timespec64(arg5, &ts)) { + return -TARGET_EFAULT; + } + } else { + ret = get_errno(safe_mq_timedsend(arg1, p, arg3, arg4, NULL)); + } + unlock_user(p, arg2, arg3); + } + return ret; +#endif #ifdef TARGET_NR_mq_timedreceive case TARGET_NR_mq_timedreceive: @@ -11858,6 +11883,33 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } return ret; #endif +#ifdef TARGET_NR_mq_timedreceive_time64 + case TARGET_NR_mq_timedreceive_time64: + { + struct timespec ts; + unsigned int prio; + + p = lock_user(VERIFY_READ, arg2, arg3, 1); + if (arg5 != 0) { + if (target_to_host_timespec64(&ts, arg5)) { + return -TARGET_EFAULT; + } + ret = get_errno(safe_mq_timedreceive(arg1, p, arg3, + &prio, &ts)); + if (host_to_target_timespec64(arg5, &ts)) { + return -TARGET_EFAULT; + } + } else { + ret = get_errno(safe_mq_timedreceive(arg1, p, arg3, + &prio, NULL)); + } + unlock_user(p, arg2, arg3); + if (arg4 != 0) { + put_user_u32(prio, arg4); + } + } + return ret; +#endif /* Not implemented for now... */ /* case TARGET_NR_mq_notify: */
This patch implements functionality for following time64 syscalls: *mq_timedsend_time64() This is a year 2038 safe vairant of syscall: int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout) --send a message to a message queue-- man page: https://www.man7.org/linux/man-pages/man2/mq_timedsend.2.html *mq_timedreceive_time64() This is a year 2038 safe variant of syscall: ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio, const struct timespec *abs_timeout) --receive a message from a message queue-- man page: https://man7.org/linux/man-pages/man3/mq_receive.3.html Implementation notes: These syscalls were implemented in similar ways like 'mq_timedsend()' and 'mq_timedreceive' except that functions 'target_to_host_timespec64()' and 'host_to_target_timespec64()' were used to convert values of 'struct timespec' between host and target. Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> --- linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-)