linux-user changes for 2.1
From: Riku Voipio <[email protected]>
The following changes since commit de6793e8c2a4d34e28e5ea385276249fc98109ec:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20140627' into staging (2014-06-29 11:43:31 +0100)
are available in the git repository at:
git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream
for you to fetch changes up to f63eb01ac7a5b4437d5589ad4343527534bf9d0b:
linux-user: support the SIOCGIFINDEX ioctl (2014-06-29 14:19:59 +0300)
Changes since v1 - dropped those patches from Paul that add new syscalls from this round, since the won't compile with older libc's.
Christophe Lyon (1):
Add support for MAP_NORESERVE mmap flag.
Paul Burton (11):
linux-user: translate the result of getsockopt SO_TYPE
linux-user: support SO_ACCEPTCONN getsockopt option
linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options
linux-user: support SO_PASSSEC setsockopt option
linux-user: allow NULL arguments to mount
linux-user: support strace of epoll_create1
linux-user: fix struct target_epoll_event layout for MIPS
linux-user: respect timezone for settimeofday
linux-user: allow NULL tv argument for settimeofday
linux-user: support the KDSIGACCEPT ioctl
linux-user: support the SIOCGIFINDEX ioctl
Wim Vander Schelden (1):
linux-user: added fake open() for /proc/self/cmdline
linux-user/ioctls.h | 2 + linux-user/socket.h | 5 ++ linux-user/strace.list | 3 + linux-user/syscall.c | 215 ++++++++++++++++++++++++++++++++++++++++------ linux-user/syscall_defs.h | 9 +- 5 files changed, 207 insertions(+), 27 deletions(-)
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 03/13] linux-user: translate the result of getsockopt SO_TYPE
From: Paul Burton <[email protected]>
QEMU previously passed the result of the host syscall directly to the target program. This is a problem if the host & target have different representations of socket types, as is the case when running a MIPS target program on an x86 host. Introduce a host_to_target_sock_type helper function mirroring the existing target_to_host_sock_type, and call it to translate the value provided by getsockopt when called for the SO_TYPE option.
--- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
linux-user/syscall.c +34 -0
@@ -592,6 +592,37 @@ char *target_strerror(int err)return strerror (target_to_host_errno (err)); } +static inline int host_to_target_sock_type (int host_type) +{ +int target_type; + +switch (host_type &0xf /* SOCK_TYPE_MASK */ ) { +case SOCK_DGRAM : + target_type =TARGET_SOCK_DGRAM ; +break ; +case SOCK_STREAM : + target_type =TARGET_SOCK_STREAM ; +break ; +default : + target_type = host_type &0xf /* SOCK_TYPE_MASK */ ; +break ; + } + +#if defined(SOCK_CLOEXEC ) +if (host_type &SOCK_CLOEXEC ) { + target_type |=TARGET_SOCK_CLOEXEC ; + } +#endif + +#if defined(SOCK_NONBLOCK ) +if (host_type &SOCK_NONBLOCK ) { + target_type |=TARGET_SOCK_NONBLOCK ; + } +#endif + +return target_type; +} +static abi_ulong target_brk;static abi_ulong target_original_brk;static abi_ulong brk_page;
@@ -1636,6 +1667,9 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, ret =get_errno (getsockopt (sockfd, level, optname, &val, &lv));if (ret <0 )return ret; +if (optname ==SO_TYPE ) { + val =host_to_target_sock_type (val); + }if (len > lv) len = lv;if (len ==4 ) {
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 04/13] linux-user: support SO_ACCEPTCONN getsockopt option
In reply to [email protected]From: Paul Burton <[email protected]>
Translate the SO_ACCEPTCONN option to the host value & execute the syscall as expected.
--- linux-user/syscall.c | 3 +++ 1 file changed, 3 insertions(+)
linux-user/syscall.c +3 -0
@@ -1652,6 +1652,9 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,case TARGET_SO_RCVLOWAT : optname =SO_RCVLOWAT ; goto int_case; +case TARGET_SO_ACCEPTCONN : + optname =SO_ACCEPTCONN ; + goto int_case;default : goto int_case; }
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 01/13] Add support for MAP_NORESERVE mmap flag.
In reply to [email protected]From: Christophe Lyon <[email protected]>
mmap_flags_tbl contains a list of mmap flags, and how to map them to the target. This patch adds MAP_NORESERVE, which was missing to the list.
--- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+)
linux-user/syscall.c +2 -0
@@ -3908,6 +3908,8 @@ static bitmask_transtbl mmap_flags_tbl[] = { { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, + { TARGET_MAP_NORESERVE, TARGET_MAP_NORESERVE, MAP_NORESERVE, + MAP_NORESERVE }, { 0, 0, 0, 0 } };
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 08/13] linux-user: support strace of epoll_create1
In reply to [email protected]From: Paul Burton <[email protected]>
Add the epoll_create1 syscall to strace.list in order to display that syscall when it occurs, rather than a message about the syscall being unknown despite QEMU already implementing support for it.
--- linux-user/strace.list | 3 +++ 1 file changed, 3 insertions(+)
linux-user/strace.list +3 -0
@@ -114,6 +114,9 @@ #ifdef TARGET_NR_epoll_create { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL }, #endif +#ifdef TARGET_NR_epoll_create1 +{ TARGET_NR_epoll_create1, "epoll_create1" , NULL, NULL, NULL }, +#endif #ifdef TARGET_NR_epoll_ctl { TARGET_NR_epoll_ctl, "epoll_ctl" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 05/13] linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options
In reply to [email protected]From: Paul Burton <[email protected]>
Translate the SO_SNDBUFFORCE & SO_RCVBUFFORCE options to setsockopt to the host values & perform the syscall as expected, allowing use of those options by target programs.
--- linux-user/syscall.c | 6 ++++++ 1 file changed, 6 insertions(+)
linux-user/syscall.c +6 -0
@@ -1502,9 +1502,15 @@ set_timeout:case TARGET_SO_SNDBUF : optname =SO_SNDBUF ;break ; +case TARGET_SO_SNDBUFFORCE : + optname =SO_SNDBUFFORCE ; +break ;case TARGET_SO_RCVBUF : optname =SO_RCVBUF ;break ; +case TARGET_SO_RCVBUFFORCE : + optname =SO_RCVBUFFORCE ; +break ;case TARGET_SO_KEEPALIVE : optname =SO_KEEPALIVE ;break ;
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 07/13] linux-user: allow NULL arguments to mount
In reply to [email protected]From: Paul Burton <[email protected]>
Calls to the mount syscall can legitimately provide NULL as the value for the source of filesystemtype arguments, which QEMU would previously reject & return -EFAULT to the target program. An example of this is remounting an already mounted filesystem with different properties.
Instead of rejecting such syscalls with -EFAULT, pass NULL along to the kernel as the target program expects.
Additionally this patch fixes a potential memory leak when DEBUG_REMAP is enabled and lock_user_string fails on the target or filesystemtype arguments but a prior argument was non-NULL and already locked.
Since the patch already touched most lines of the TARGET_NR_mount case, it fixes the indentation & coding style for good measure.
--- linux-user/syscall.c | 75 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 22 deletions(-)
linux-user/syscall.c +53 -22
@@ -5614,29 +5614,60 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;#endif case TARGET_NR_mount: - { -/* need to look at the data field */ -void *p2, *p3; - p =lock_user_string (arg1); - p2 =lock_user_string (arg2); - p3 =lock_user_string (arg3); -if (!p || !p2 || !p3) - ret = -TARGET_EFAULT ; -else { -/* FIXME - arg5 should be locked, but it isn't clear how to -* do that since it's not guaranteed to be a NULL-terminated -* string. -*/ -if ( ! arg5 ) - ret =get_errno (mount (p, p2, p3, (unsigned long )arg4,NULL )); -else - ret =get_errno (mount (p, p2, p3, (unsigned long )arg4,g2h (arg5))); - } + { +/* need to look at the data field */ +void *p2, *p3; + +if (arg1) { + p =lock_user_string (arg1); +if (!p) { + goto efault; + } + }else { + p =NULL ; + } + + p2 =lock_user_string (arg2); +if (!p2) { +if (arg1) { +unlock_user (p, arg1,0 ); + } + goto efault; + } + +if (arg3) { + p3 =lock_user_string (arg3); +if (!p3) { +if (arg1) {unlock_user (p, arg1,0 ); -unlock_user (p2, arg2,0 ); -unlock_user (p3, arg3,0 ); -break ; - } + } +unlock_user (p2, arg2,0 ); + goto efault; + } + }else { + p3 =NULL ; + } + +/* FIXME - arg5 should be locked, but it isn't clear how to +* do that since it's not guaranteed to be a NULL-terminated +* string. +*/ +if (!arg5) { + ret =mount (p, p2, p3, (unsigned long )arg4,NULL ); + }else { + ret =mount (p, p2, p3, (unsigned long )arg4,g2h (arg5)); + } + ret =get_errno (ret); + +if (arg1) { +unlock_user (p, arg1,0 ); + } +unlock_user (p2, arg2,0 ); +if (arg3) { +unlock_user (p3, arg3,0 ); + } + } +break ;#ifdef TARGET_NR_umountcase TARGET_NR_umount:if (!(p =lock_user_string (arg1)))
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 06/13] linux-user: support SO_PASSSEC setsockopt option
In reply to [email protected]From: Paul Burton <[email protected]>
Translate the SO_PASSSEC option to setsockopt to the host value & perform the syscall as expected, allowing use of the option by target programs.
--- linux-user/socket.h | 5 +++++ linux-user/syscall.c | 3 +++ 2 files changed, 8 insertions(+)
linux-user/socket.h +5 -0
@@ -63,6 +63,7 @@#define TARGET_SO_PEERSEC 30#define TARGET_SO_SNDBUFFORCE 31#define TARGET_SO_RCVBUFFORCE 33 +#define TARGET_SO_PASSSEC 34/** sock_type - Socket types *
@@ -242,6 +243,10 @@#define TARGET_SOCK_MAX (TARGET_SOCK_PACKET + 1)#define TARGET_SOCK_TYPE_MASK 0xf/* Covers up to TARGET_SOCK_MAX-1. */ + +#define TARGET_SO_PASSSEC 31 +#else +#define TARGET_SO_PASSSEC 34#endif /* For setsockopt(2) */
linux-user/syscall.c +3 -0
@@ -1531,6 +1531,9 @@ set_timeout:case TARGET_SO_PASSCRED : optname =SO_PASSCRED ;break ; +case TARGET_SO_PASSSEC : + optname =SO_PASSSEC ; +break ;case TARGET_SO_TIMESTAMP : optname =SO_TIMESTAMP ;break ;
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 11/13] linux-user: allow NULL tv argument for settimeofday
In reply to [email protected]From: Paul Burton <[email protected]>
The tv argument to the settimeofday syscall is allowed to be NULL, if the program only wishes to provide the timezone. QEMU previously returned -EFAULT when tv was NULL. Instead, execute the syscall & provide NULL to the kernel as the target program expected.
--- linux-user/syscall.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
linux-user/syscall.c +8 -4
@@ -6401,11 +6401,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;case TARGET_NR_settimeofday: { -struct timeval tv; +struct timeval tv, *ptv =NULL ;struct timezone tz, *ptz =NULL ; -if (copy_from_user_timeval (&tv, arg1)) - goto efault; +if (arg1) { +if (copy_from_user_timeval (&tv, arg1)) { + goto efault; + } + ptv = &tv; + }if (arg2) {if (copy_from_user_timezone (&tz, arg2)) {
@@ -6414,7 +6418,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ptz = &tz; } - ret =get_errno (settimeofday (&tv, ptz)); + ret =get_errno (settimeofday (ptv, ptz)); }break ;#if defined(TARGET_NR_select)
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 12/13] linux-user: support the KDSIGACCEPT ioctl
In reply to [email protected]From: Paul Burton <[email protected]>
Add a definition of the KDSIGACCEPT ioctl & allow its use by target programs.
--- linux-user/ioctls.h | 1 + linux-user/syscall.c | 7 +++++++ linux-user/syscall_defs.h | 1 + 3 files changed, 9 insertions(+)
linux-user/ioctls.h +1 -0
@@ -64,6 +64,7 @@ IOCTL(KDSKBLED, 0, TYPE_INT) IOCTL(KDGETLED, 0, TYPE_INT) IOCTL(KDSETLED, 0, TYPE_INT) + IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT) IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))IOCTL (BLKROGET ,IOC_R ,MK_PTR (TYPE_INT ))
linux-user/syscall.c +7 -0
@@ -3689,6 +3689,13 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,return ret; } +static abi_long do_ioctl_kdsigaccept (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,abi_long cmd,abi_long arg) +{ +int sig =target_to_host_signal (arg); +return get_errno (ioctl (fd, ie->host_cmd, sig)); +} + static IOCTLEntry ioctl_entries[] = { #define IOCTL(cmd, access, ...) \ { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
linux-user/syscall_defs.h +1 -0
@@ -831,6 +831,7 @@ struct target_pollfd {#define TARGET_KDSKBLED 0x4B65/* set led flags (not lights) */ #define TARGET_KDGETLED 0x4B31/* return current led state */ #define TARGET_KDSETLED 0x4B32/* set led state [lights, not flags] */ +#define TARGET_KDSIGACCEPT 0x4B4E#define TARGET_SIOCATMARK 0x8905
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 10/13] linux-user: respect timezone for settimeofday
In reply to [email protected]From: Paul Burton <[email protected]>
The settimeofday syscall accepts a tz argument indicating the desired timezone to the kernel. QEMU previously ignored any argument provided by the target program & always passed NULL to the kernel. Instead, translate the argument & pass along the data userland provided.
Although this argument is described by the settimeofday man page as obsolete, it is used by systemd as of version 213.
--- linux-user/syscall.c | 29 ++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 5 +++++ 2 files changed, 33 insertions(+), 1 deletion(-)
linux-user/syscall.c +28 -1
@@ -935,6 +935,23 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,return 0 ; } +static inline abi_long copy_from_user_timezone (struct timezone *tz, +abi_ulong target_tz_addr) +{ +struct target_timezone *target_tz; + +if (!lock_user_struct (VERIFY_READ , target_tz, target_tz_addr,1 )) { +return -TARGET_EFAULT ; + } + +__get_user (tz->tz_minuteswest, &target_tz->tz_minuteswest); +__get_user (tz->tz_dsttime, &target_tz->tz_dsttime); + +unlock_user_struct (target_tz, target_tz_addr,0 ); + +return 0 ; +} +#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)#include <mqueue.h>
@@ -6385,9 +6402,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_settimeofday: {struct timeval tv; +struct timezone tz, *ptz =NULL ; +if (copy_from_user_timeval (&tv, arg1)) goto efault; - ret =get_errno (settimeofday (&tv,NULL )); + +if (arg2) { +if (copy_from_user_timezone (&tz, arg2)) { + goto efault; + } + ptz = &tz; + } + + ret =get_errno (settimeofday (&tv, ptz)); }break ;#if defined(TARGET_NR_select)
linux-user/syscall_defs.h +5 -0
@@ -165,6 +165,11 @@ struct target_timespec {abi_long tv_nsec; }; +struct target_timezone { +abi_int tz_minuteswest; +abi_int tz_dsttime; +}; +struct target_itimerval {struct target_timeval it_interval;struct target_timeval it_value;
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 09/13] linux-user: fix struct target_epoll_event layout for MIPS
In reply to [email protected]From: Paul Burton <[email protected]>
MIPS requires the pad field to 64b-align the data field just as ARM does.
--- linux-user/syscall_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall_defs.h +1 -1
@@ -2528,7 +2528,7 @@ typedef union target_epoll_data {struct target_epoll_event {uint32_t events; -#ifdef TARGET_ARM +#if defined(TARGET_ARM ) || defined(TARGET_MIPS ) || defined(TARGET_MIPS64 )uint32_t __pad;#endif target_epoll_data_t data;
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 02/13] linux-user: added fake open() for /proc/self/cmdline
In reply to [email protected]From: Wim Vander Schelden <[email protected]>
--- linux-user/syscall.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
linux-user/syscall.c +46 -0
@@ -4949,6 +4949,51 @@ int host_to_target_waitstatus(int status)return status; } +static int open_self_cmdline (void *cpu_env,int fd) +{ +int fd_orig =-1 ; +bool word_skipped = false; + + fd_orig =open ("/proc/self/cmdline" ,O_RDONLY ); +if (fd_orig <0 ) { +return fd_orig; + } + +while (true) { +ssize_t nb_read; +char buf[128 ]; +char *cp_buf = buf; + + nb_read =read (fd_orig, buf,sizeof (buf)); +if (nb_read <0 ) { + fd_orig =close (fd_orig); +return -1 ; + }else if (nb_read ==0 ) { +break ; + } + +if (!word_skipped) { +/* Skip the first string, which is the path to qemu-*-static +instead of the actual command. */ + cp_buf =memchr (buf,0 ,sizeof (buf)); +if (cp_buf) { +/* Null byte found, skip one string */ + cp_buf++; + nb_read -= cp_buf - buf; + word_skipped = true; + } + } + +if (word_skipped) { +if (write (fd, cp_buf, nb_read) != nb_read) { +return -1 ; + } + } + } + +return close (fd_orig); +} +static int open_self_maps (void *cpu_env,int fd) {#if defined(TARGET_ARM ) || defined(TARGET_M68K ) || defined(TARGET_UNICORE32 )
@@ -5150,6 +5195,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) { "maps", open_self_maps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, + { "cmdline", open_self_cmdline, is_proc_myself }, #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) { "/proc/net/route", open_net_route, is_proc }, #endif
Signature · 1 line
2.0.0.rc2
[Qemu-devel] [PULL v2 13/13] linux-user: support the SIOCGIFINDEX ioctl
In reply to [email protected]From: Paul Burton <[email protected]>
Add a definition of the SIOCGIFINDEX ioctl, allowing its use by target programs.
--- linux-user/ioctls.h | 1 + linux-user/syscall_defs.h | 1 + 2 files changed, 2 insertions(+)
linux-user/ioctls.h +1 -0
@@ -118,6 +118,7 @@ IOCTL(SIOCSIFMEM, IOC_W, MK_PTR(MK_STRUCT(STRUCT_ptr_ifreq))) IOCTL(SIOCADDMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) IOCTL(SIOCDELMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) + IOCTL(SIOCGIFINDEX, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) IOCTL(SIOCSIFLINK, 0, TYPE_NULL)IOCTL_SPECIAL (SIOCGIFCONF ,IOC_W |IOC_R , do_ioctl_ifconf,MK_PTR (MK_STRUCT (STRUCT_ifconf)))
linux-user/syscall_defs.h +1 -0
@@ -865,6 +865,7 @@ struct target_pollfd {#define TARGET_SIOCSIFSLAVE 0x8930#define TARGET_SIOCADDMULTI 0x8931/* Multicast address lists */ #define TARGET_SIOCDELMULTI 0x8932 +#define TARGET_SIOCGIFINDEX 0x8933/* Bridging control calls */ #define TARGET_SIOCGIFBR 0x8940/* Bridging support */
Signature · 1 line
2.0.0.rc2
Peter Maydell
AppliedQuoted 8 lines · On 29 June 2014 13:14, <[email protected]> wrote:
From: Riku Voipio <[email protected]>
The following changes since commit
de6793e8c2a4d34e28e5ea385276249fc98109ec:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20140627' into staging (2014-06-29 11:43:31 +0100)
are available in the git repository at:
Quoted 8 lines
git://git.linaro.org/people/riku.voipio/qemu.gitlinux-user-for-upstreamfor you to fetch changes up to
f63eb01ac7a5b4437d5589ad4343527534bf9d0b:linux-user: support the SIOCGIFINDEX ioctl (2014-06-29 14:19:59 +0300)
Changes since v1 - dropped those patches from Paul that add new syscalls from this round, since the won't compile with older libc's.
Applied, thanks.
-- PMM