linux-user: fix to handle variably sized SIOCGSTAMP with new kernels
PATCH v5 1/1 linux-user: fix to handle variably sized SIOCGSTAMP with new kernels
From: Daniel P. Berrangé <[email protected]>
The SIOCGSTAMP symbol was previously defined in the asm-generic/sockios.h header file. QEMU sees that header indirectly via sys/socket.h
In linux kernel commit 0768e17073dc527ccd18ed5f96ce85f9985e9115 the asm-generic/sockios.h header no longer defines SIOCGSTAMP. Instead it provides only SIOCGSTAMP_OLD, which only uses a 32-bit time_t on 32-bit architectures.
The linux/sockios.h header then defines SIOCGSTAMP using either SIOCGSTAMP_OLD or SIOCGSTAMP_NEW as appropriate. If SIOCGSTAMP_NEW is used, then the tv_sec field is 64-bit even on 32-bit architectures
To cope with this we must now convert the old and new type from the target to the host one.
---
Notes:
v5: [lv] define special _OLD values for sh
define special case for SPARC64
define ioctl helpers
define target__kernel_sock_timeval and target__kernel_timespec and converters to the host type
always use SIOCGSTAMP and SIOCGSTAMPNS on the host
v4: [lv] timeval64 and timespec64 are { long long , long }
v3: [lv] redefine TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMPNS_NEW,
timeval64 and timespec64 to use 0x89 type and abi_llong[2]
v2: [dpb] implement _NEW and _OLD variants
linux-user/ioctls.h | 11 ++- linux-user/syscall.c | 140 +++++++++++++++++++++++++++++-------- linux-user/syscall_defs.h | 30 +++++++- linux-user/syscall_types.h | 6 -- 4 files changed, 149 insertions(+), 38 deletions(-)
linux-user/ioctls.h +9 -2
@@ -222,8 +222,15 @@ IOCTL(SIOCGIWNAME, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_char_ifreq))) IOCTL(SIOCSPGRP, IOC_W, MK_PTR(TYPE_INT)) /* pid_t */ IOCTL(SIOCGPGRP, IOC_R, MK_PTR(TYPE_INT)) /* pid_t */ - IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval))) - IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec))) + + {TARGET_SIOCGSTAMP_OLD ,SIOCGSTAMP ,"IOCGSTAMP_OLD" ,IOC_R , \ + do_ioctl_SIOCGSTAMP }, + { TARGET_SIOCGSTAMPNS_OLD, SIOCGSTAMPNS, "IOCGSTAMPNS_OLD", IOC_R, \ + do_ioctl_SIOCGSTAMPNS }, + { TARGET_SIOCGSTAMP_NEW, SIOCGSTAMP, "IOCGSTAMP_NEW", IOC_R, \ + do_ioctl_SIOCGSTAMP }, + { TARGET_SIOCGSTAMPNS_NEW, SIOCGSTAMPNS, "IOCGSTAMPNS_NEW", IOC_R, \ + do_ioctl_SIOCGSTAMPNS }, IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT))IOCTL (RNDADDTOENTCNT ,IOC_W ,MK_PTR (TYPE_INT ))
linux-user/syscall.c +112 -28
178 lines not on this page · raw message
linux-user/syscall_defs.h +28 -2
@@ -209,16 +209,34 @@ struct target_linger {abi_int l_linger;/* How long to linger for */ }; +#if defined(TARGET_SPARC64 ) && !defined(TARGET_ABI32 ) +struct target_timeval { +abi_long tv_sec; +abi_int tv_usec; +}; +#define target__kernel_sock_timeval target_timeval +#else struct target_timeval {abi_long tv_sec;abi_long tv_usec; }; +struct target__kernel_sock_timeval { +abi_llong tv_sec; +abi_llong tv_usec; +}; +#endif +struct target_timespec {abi_long tv_sec;abi_long tv_nsec; }; +struct target__kernel_timespec { +abi_llong tv_sec; +abi_llong tv_nsec; +}; +struct target_timezone {abi_int tz_minuteswest;abi_int tz_dsttime;
@@ -749,8 +767,16 @@ struct target_pollfd {#define TARGET_SIOCGPGRP 0x8904#endif -#define TARGET_SIOCGSTAMP 0x8906/* Get stamp (timeval) */ -#define TARGET_SIOCGSTAMPNS 0x8907/* Get stamp (timespec) */ +#if defined(TARGET_SH4 ) +#define TARGET_SIOCGSTAMP_OLD TARGET_IOR('s', 100, struct target_timeval) +#define TARGET_SIOCGSTAMPNS_OLD TARGET_IOR('s', 101, struct target_timespec) +#else +#define TARGET_SIOCGSTAMP_OLD 0x8906 +#define TARGET_SIOCGSTAMPNS_OLD 0x8907 +#endif + +#define TARGET_SIOCGSTAMP_NEW TARGET_IOR(0x89, 0x06, abi_llong[2]) +#define TARGET_SIOCGSTAMPNS_NEW TARGET_IOR(0x89, 0x07, abi_llong[2])/* Networking ioctls */ #define TARGET_SIOCADDRT 0x890B/* add routing table entry */
linux-user/syscall_types.h +0 -6
@@ -14,12 +14,6 @@ STRUCT(serial_icounter_struct,STRUCT (sockaddr, TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14)) -STRUCT (timeval, - MK_ARRAY(TYPE_LONG, 2)) - -STRUCT (timespec, - MK_ARRAY(TYPE_LONG, 2)) - STRUCT(rtentry, TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, TYPE_PTRVOID,
Signature · 1 line
2.21.0
Quoted 17 lines · Laurent Vivier
From: Daniel P. Berrangé <[email protected]>
The SIOCGSTAMP symbol was previously defined in the
asm-generic/sockios.hheader file. QEMU sees that header indirectly viasys/socket.hIn linux kernel commit
0768e17073dc527ccd18ed5f96ce85f9985e9115theasm-generic/sockios.hheader no longer defines SIOCGSTAMP. Instead it provides onlySIOCGSTAMP_OLD, which only uses a 32-bittime_ton 32-bit architectures.The
linux/sockios.hheader then defines SIOCGSTAMP using eitherSIOCGSTAMP_OLDorSIOCGSTAMP_NEWas appropriate. IfSIOCGSTAMP_NEWis used, then thetv_secfield is 64-bit even on 32-bit architectures
Quoted 5 lines
To cope with this we must now convert the old and new type from the target to the host one.
Signed-off-by Daniel P. Berrangé <[email protected]>Signed-off-by Laurent Vivier <[email protected]>
Looks good to me now