From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488234963008203.09666279420787; Mon, 27 Feb 2017 14:36:03 -0800 (PST) Received: from localhost ([::1]:57298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTth-0002b3-Bo for importer@patchew.org; Mon, 27 Feb 2017 17:36:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTrd-0001Pp-UB for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTrZ-0003sJ-JA for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:53 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:60770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTrZ-0003nK-9k for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:49 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MgwGe-1cvlWW0gyW-00M6wh; Mon, 27 Feb 2017 23:33:40 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:32 +0100 Message-Id: <20170227223337.17434-2-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K0:lV9gJQbTCg+gApx6k+k7SlzVwUVOCiFDC2IjzCweRJc1riSKT2/ FoDWHGDzPLvvYNX3tbzBKKn6D+xiSgqUdijlKHL9Hq7Y/JzAm3L0ODaOTcyL+3bSpcrC9QU ijTpRGRF0SSOWXPKG+ECClogrgtSNtQwDJ7Oj9m2Kqflf4m8hD4UgXtycgC/IgrxypYGgv0 BeKs0hMZQMTKHUViVSczA== X-UI-Out-Filterresults: notjunk:1;V01:K0:7JSYnE1OjEc=:YOPCY0S0dTv/lLmrLa0trr 19UJMDh6hnNuDs5FrwDXcisSr/wRTsRKpFl8Cmjrz5mz0AqqfC/OP5/yYEbAK6SM/uu3KcjSH gfpuGDj9/BIDREMFqmHEe6CacZHViRWpagdPYvVXD3xdU7iAR1J2hlRVRSWmJnhgl/EVOzkt5 zAIcS04e89dwJqcN5UL4uaLxlv12e1a2d9UUQiyHRmq+8A7n6Ja5TX+iPu8mi9SytBB7772yj dyyMKtM+ORvxi3iZNl6m7tYaABPWWDP2PVvmGWrZqQ4yrvzfmBKo2sUraCCFSZG//+sGjXfWl AefBVLajgdgti1SA4OJgBKC5yyhGjMNDYFjTMiih0E/8jcocf22wAhrPmEL5ddnYk9oRpN98E t/cXUAuhn6jnzTmrrKIarPE+iesJd3FVo3EfdnNmKSRKcZICn+H+rTTWFmLs+fWjM7McCNS14 ayO5apfAX6sYXlPalntvp1MQfXOnSPC/j8SKR7XuU3EWyDVeAwy8B1CfqawgDiVye3Ln3oSQ8 uKGytzfEBulDTElkgxvaV1fupX9EhW2kSrchdzyoWz6thyFFgvZrkBvkwv+z1gaZtKa2pTnY7 tLC3P8pF2YGmyLdxEN7zGkm3q5qt9IL4Q1uumThRnoRTMFgOnphPqjWCh/Mkwk7etmq3pmIAz C6jef54a/VtCNCpZEZKWxXpeyKbfVFMGEZC/etSmM1ca6Pg3tfisAfx+k+gXYdRnzKb1q78Mk jQFr9KphFsK2p8n+ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PULL 1/6] linux-user: fix fork() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Since commit 5ea2fc8 ("linux-user: Sanity check clone flags"), trying to run fork() fails with old distro on some architectures. This is the case with HP-PA and Debian 5 (Lenny). It fails on: if ((flags & CSIGNAL) !=3D TARGET_SIGCHLD) { return -TARGET_EINVAL; } because flags is 17, whereas on HP-PA, SIGCHLD is 18. 17 is the SIGCHLD value of my host (x86_64). It appears that for TARGET_NR_fork and TARGET_NR_vfork, QEMU calls do_fork() with SIGCHLD instead of TARGET_SIGCHLD. Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20170216173707.16209-1-laurent@vivier.eu> --- linux-user/syscall.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f569f82..4d85355 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7680,7 +7680,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, break; #ifdef TARGET_NR_fork case TARGET_NR_fork: - ret =3D get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0)); + ret =3D get_errno(do_fork(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0)); break; #endif #ifdef TARGET_NR_waitpid @@ -10490,7 +10490,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, #endif #ifdef TARGET_NR_vfork case TARGET_NR_vfork: - ret =3D get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHL= D, + ret =3D get_errno(do_fork(cpu_env, + CLONE_VFORK | CLONE_VM | TARGET_SIGCHLD, 0, 0, 0, 0)); break; #endif --=20 2.9.3 From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488234965937407.41124979135077; Mon, 27 Feb 2017 14:36:05 -0800 (PST) Received: from localhost ([::1]:57299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTtk-0002db-Ik for importer@patchew.org; Mon, 27 Feb 2017 17:36:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTre-0001Pq-Ee for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTra-0003vr-Dp for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:54 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:59084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTra-0003qZ-2R for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:50 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MUVwx-1cs8lL3G0x-00RJsa; Mon, 27 Feb 2017 23:33:41 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:33 +0100 Message-Id: <20170227223337.17434-3-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K0:kGJSbiGuNDL8ydhPu+BnjV0L08g+34LH0YJlkgEGH7Ys50w9n9a 9UCUaM50qQZO59BV5X0Gg7u887lekGidRNSNbMRkQaBNIfH3PpORs02xxeuR4uHK4Zl/10c yORHI9b/z6/JWTkPT8WrX2b/zoPmhm+TVRJ08/viNVi66FHLIRJt2QUieRd+DKyQx7SsHds uO2BRFgnEk9p+RcN0udDA== X-UI-Out-Filterresults: notjunk:1;V01:K0:S0ybRUwgjRo=:DYfhE8k1shEtLUudWJ1ehE lK9pHjUFQRXkVQhBHbnXuQeB5vp5C2ZuY66IhkaT8BKwEBlyKU7k8d2sMz0vZIXPpbzfaVgT+ RNyRgU/YaPyhdQ5ovTmNL4MiR+/NEaLWGWDqtsVyKR71XdeMtc+dcSsqelmfVT29/idtY+Yg8 9qWvtmC28Zg3G42eJ7OdS4z5ux+QsumZkg3O1lYJRfhi2rBeMFKVsZw7A92c4iocCtwx74zXg MIKQMMSfpLHiDvXoLqNHP6t3pQ9ni/W+44xj2HA4vuZE15+MCXp1MP+V9SnV+WVcTcwueTIVQ qZy61C+Ol7Kyj6TI0GXh8A81qLY4y/O63xildXdNNvyf5wuLi5hcGQQOJM+6+TrslGIfmHcII 8RZm4M6Pe+JX6o3VCgvel5yTw7WcFACUt/fQEndAuiAjX5xzsDsS4Fw/wG9dtLpfgWNZdoYUV RuSmlUjZaRW+T/IkoWgbIB+5znBRcX3ZqLIt81OmLTHuNhP18oVfTLQDKtHHhhamZr6ZH/cs1 dc1pW/tOU672Lyw8A+oQpms22HiXxUPq+c0bjzFMUnbX8gATRrwWgWQqnsU/TtzY41Nk+Wv+l 21SXd+fmGcgSHvmNKf4ZfekND4nfH7db106bnReCqaxbjWZBrRZFj7Ld5dbkNw8GAr70lBctJ eGf2EETlUvY7BS/PuI11MuDS1BVmWds6M8VbeXPNnA2qp/KxzHYOSv/GYreO0UfqNdDi55sAU Wtsyh0WiWnZ2XWeJ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL 2/6] linux-user: Add sockopts for IPv6 ping and IPv6 traceroute X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Helge Deller , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Helge Deller Add the neccessary sockopts for ping and traceroute on IPv6. This fixes the following qemu warnings with IPv6: Unsupported ancillary data: 0/2 Unsupported ancillary data: 0/11 Unsupported ancillary data: 41/25 Unsupported setsockopt level=3D0 optname=3D12 Unsupported setsockopt level=3D41 optname=3D16 Unsupported setsockopt level=3D41 optname=3D25 Unsupported setsockopt level=3D41 optname=3D50 Unsupported setsockopt level=3D41 optname=3D51 Unsupported setsockopt level=3D41 optname=3D8 Unsupported setsockopt level=3D58 optname=3D1 Tested with hppa-linux-user (big-endian) on x86_64 (little-endian). Signed-off-by: Helge Deller Reviewed-by: Laurent Vivier Tested-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20170218223130.GA25278@ls3530.fritz.box> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 132 ++++++++++++++++++++++++++++++++++++++++++= +++- linux-user/syscall_defs.h | 8 +++ 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4d85355..2bba500 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -57,6 +57,8 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #include #include #include +#include +#include #include "qemu-common.h" #ifdef CONFIG_TIMERFD #include @@ -1634,6 +1636,11 @@ static inline abi_long host_to_target_sockaddr(abi_u= long target_addr, struct sockaddr_ll *target_ll =3D (struct sockaddr_ll *)target_sad= dr; target_ll->sll_ifindex =3D tswap32(target_ll->sll_ifindex); target_ll->sll_hatype =3D tswap16(target_ll->sll_hatype); + } else if (addr->sa_family =3D=3D AF_INET6 && + len >=3D sizeof(struct target_sockaddr_in6)) { + struct target_sockaddr_in6 *target_in6 =3D + (struct target_sockaddr_in6 *)target_saddr; + target_in6->sin6_scope_id =3D tswap16(target_in6->sin6_scope_id); } unlock_user(target_saddr, target_addr, len); =20 @@ -1839,6 +1846,78 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, } break; =20 + case SOL_IP: + switch (cmsg->cmsg_type) { + case IP_TTL: + { + uint32_t *v =3D (uint32_t *)data; + uint32_t *t_int =3D (uint32_t *)target_data; + + __put_user(*v, t_int); + break; + } + case IP_RECVERR: + { + struct errhdr_t { + struct sock_extended_err ee; + struct sockaddr_in offender; + }; + struct errhdr_t *errh =3D (struct errhdr_t *)data; + struct errhdr_t *target_errh =3D + (struct errhdr_t *)target_data; + + __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); + __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); + __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); + __put_user(errh->ee.ee_code, &target_errh->ee.ee_code); + __put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad); + __put_user(errh->ee.ee_info, &target_errh->ee.ee_info); + __put_user(errh->ee.ee_data, &target_errh->ee.ee_data); + host_to_target_sockaddr((unsigned long) &target_errh->offe= nder, + (void *) &errh->offender, sizeof(errh->offender)); + break; + } + default: + goto unimplemented; + } + break; + + case SOL_IPV6: + switch (cmsg->cmsg_type) { + case IPV6_HOPLIMIT: + { + uint32_t *v =3D (uint32_t *)data; + uint32_t *t_int =3D (uint32_t *)target_data; + + __put_user(*v, t_int); + break; + } + case IPV6_RECVERR: + { + struct errhdr6_t { + struct sock_extended_err ee; + struct sockaddr_in6 offender; + }; + struct errhdr6_t *errh =3D (struct errhdr6_t *)data; + struct errhdr6_t *target_errh =3D + (struct errhdr6_t *)target_data; + + __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); + __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); + __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); + __put_user(errh->ee.ee_code, &target_errh->ee.ee_code); + __put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad); + __put_user(errh->ee.ee_info, &target_errh->ee.ee_info); + __put_user(errh->ee.ee_data, &target_errh->ee.ee_data); + host_to_target_sockaddr((unsigned long) &target_errh->offe= nder, + (void *) &errh->offender, sizeof(errh->offender)); + break; + } + default: + goto unimplemented; + } + break; + default: unimplemented: gemu_log("Unsupported ancillary data: %d/%d\n", @@ -2768,6 +2847,7 @@ static abi_long do_setsockopt(int sockfd, int level, = int optname, case IP_PKTINFO: case IP_MTU_DISCOVER: case IP_RECVERR: + case IP_RECVTTL: case IP_RECVTOS: #ifdef IP_FREEBIND case IP_FREEBIND: @@ -2817,6 +2897,11 @@ static abi_long do_setsockopt(int sockfd, int level,= int optname, case IPV6_MTU: case IPV6_V6ONLY: case IPV6_RECVPKTINFO: + case IPV6_UNICAST_HOPS: + case IPV6_RECVERR: + case IPV6_RECVHOPLIMIT: + case IPV6_2292HOPLIMIT: + case IPV6_CHECKSUM: val =3D 0; if (optlen < sizeof(uint32_t)) { return -TARGET_EINVAL; @@ -2827,6 +2912,50 @@ static abi_long do_setsockopt(int sockfd, int level,= int optname, ret =3D get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); break; + case IPV6_PKTINFO: + { + struct in6_pktinfo pki; + + if (optlen < sizeof(pki)) { + return -TARGET_EINVAL; + } + + if (copy_from_user(&pki, optval_addr, sizeof(pki))) { + return -TARGET_EFAULT; + } + + pki.ipi6_ifindex =3D tswap32(pki.ipi6_ifindex); + + ret =3D get_errno(setsockopt(sockfd, level, optname, + &pki, sizeof(pki))); + break; + } + default: + goto unimplemented; + } + break; + case SOL_ICMPV6: + switch (optname) { + case ICMPV6_FILTER: + { + struct icmp6_filter icmp6f; + + if (optlen > sizeof(icmp6f)) { + optlen =3D sizeof(icmp6f); + } + + if (copy_from_user(&icmp6f, optval_addr, optlen)) { + return -TARGET_EFAULT; + } + + for (val =3D 0; val < 8; val++) { + icmp6f.data[val] =3D tswap32(icmp6f.data[val]); + } + + ret =3D get_errno(setsockopt(sockfd, level, optname, + &icmp6f, optlen)); + break; + } default: goto unimplemented; } @@ -2834,7 +2963,8 @@ static abi_long do_setsockopt(int sockfd, int level, = int optname, case SOL_RAW: switch (optname) { case ICMP_FILTER: - /* struct icmp_filter takes an u32 value */ + case IPV6_CHECKSUM: + /* those take an u32 value */ if (optlen < sizeof(uint32_t)) { return -TARGET_EINVAL; } diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 72ca5b1..40c5027 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -164,6 +164,14 @@ struct target_sockaddr_in { sizeof(struct target_in_addr)]; }; =20 +struct target_sockaddr_in6 { + uint16_t sin6_family; + uint16_t sin6_port; /* big endian */ + uint32_t sin6_flowinfo; /* big endian */ + struct in6_addr sin6_addr; /* IPv6 address, big endian */ + uint32_t sin6_scope_id; +}; + struct target_sock_filter { abi_ushort code; uint8_t jt; --=20 2.9.3 From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488235232095769.0968886490524; Mon, 27 Feb 2017 14:40:32 -0800 (PST) Received: from localhost ([::1]:57317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTy2-0006RK-Om for importer@patchew.org; Mon, 27 Feb 2017 17:40:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTri-0001Rf-2r for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTrf-0004P0-VP for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:58 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:58819) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTrf-0004J6-Ij for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:55 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LmuL6-1c5rKM0RTg-00h4df; Mon, 27 Feb 2017 23:33:42 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:34 +0100 Message-Id: <20170227223337.17434-4-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> X-Provags-ID: V03:K0:jq6h+Byu5nMkEbJaCQu9OlEuoRFeOme/MgNQNcf/bsMrUjkxoWY kEGOEwzlZpMQfk4+xf+K4Omgoz7Tu3qX44933T0wejTU/PFyQxGOoLy1ck4pCTE6cye08Hm Hjt0BI3spB8xXHUpLmsemoOBQ4lNDh/Cry+fwjb9rSOBHP+ilpg9B+3RED/ynAn3dJX1cec +xdeoxkmaLQdumqW8q4hw== X-UI-Out-Filterresults: notjunk:1;V01:K0:TINnpSQVDdw=:rNk1qmOfw62rpyJ4KlzVJg MQUPv5828CJvC0DY84BQdcB0uj46iCj4jhTJASpi76lMTKHv+24ogmC74dWz1vvUTTjfgVl3U L8tSwzyjHXptgaOnZPdnxg2vZssIot5P/tyobN5BIf5MAw+GRSY8zKoz92NJihlDrP61Fwrjj j/j/TvbyBUSBDCdhOFLZ9GrruCu6IyDfat3F21BoyP9w45xP5F+DFWk/JFbxBim00u01ScKxe ekdGhlS5nU7yQuVqmfq3DOc4Lh7HxK5xr0BjPLMA7AiLHLrSIwrYrPJ9//4EzrkJtuTIZwWf4 3zh/VNh9xDRpdPv6xUNQfcbsGrDsBE33eUZuFVBMCX7U/WaIgRrfWdOiIbzwu5NLUZelNZ6m8 QPHpIg/v8FgBLgd6BXZ/ZJv56GCB3MZtgrZ3IOoXpLk59JyfGhJHxc6fdbiN1kXxRHP+zhtzT CwwcOV+ZuEEgZG/HQF4X72R0JGQrf5/srnMpnBWNQeoBLg6Ta7BeAkvyFb5OPCdS9Gn8GMcEt ah7ABklpFNa1Gfv3LP98b0rjta7ItlFxb57r7/5CIqGst/YX5uVsPp6zR6MRjmNcwBydooCkT bQALs8vxDTlBDwzydiHK028WIGcxEw8GPPRHVv8qq2p7nyddKsgBi+n2KNSyJFsxGMj10lKLD 1UFCb8EFBi3jhKnKfb+4+KIfESLRce+79lrpsVCrfE7NvSlnBw2mu24VWxOSEJeO16tg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PULL 3/6] linux-user: Add signal handling support for x86_64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pranith Kumar , Riku Voipio , Allan Wirth , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pranith Kumar Note that x86_64 has only _rt signal handlers. This implementation attempts to share code with the x86_32 implementation. CC: Laurent Vivier Signed-off-by: Allan Wirth Reviewed-by: Peter Maydell Signed-off-by: Pranith Kumar Reviewed-by: Laurent Vivier Message-Id: <20170226165345.8757-1-bobby.prani@gmail.com> Signed-off-by: Laurent Vivier --- linux-user/signal.c | 278 ++++++++++++++++++++++++++++++++++++++-----= ---- target/i386/cpu.h | 2 + target/i386/fpu_helper.c | 12 ++ 3 files changed, 241 insertions(+), 51 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 8209539..5dae87e 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -254,7 +254,7 @@ int do_sigprocmask(int how, const sigset_t *set, sigset= _t *oldset) } =20 #if !defined(TARGET_OPENRISC) && !defined(TARGET_UNICORE32) && \ - !defined(TARGET_X86_64) && !defined(TARGET_NIOS2) + !defined(TARGET_NIOS2) /* Just set the guest's signal mask to the specified value; the * caller is assumed to have called block_signals() already. */ @@ -512,7 +512,7 @@ void signal_init(void) } } =20 -#if !(defined(TARGET_X86_64) || defined(TARGET_UNICORE32)) +#ifndef TARGET_UNICORE32 /* Force a synchronously taken signal. The kernel force_sig() function * also forces the signal to "not blocked, not ignored", but for QEMU * that work is done in process_pending_signals(). @@ -819,9 +819,8 @@ int do_sigaction(int sig, const struct target_sigaction= *act, return ret; } =20 -#if defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 - -/* from the Linux kernel */ +#if defined(TARGET_I386) +/* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */ =20 struct target_fpreg { uint16_t significand[4]; @@ -835,58 +834,120 @@ struct target_fpxreg { }; =20 struct target_xmmreg { - abi_ulong element[4]; + uint32_t element[4]; }; =20 -struct target_fpstate { +struct target_fpstate_32 { /* Regular FPU environment */ - abi_ulong cw; - abi_ulong sw; - abi_ulong tag; - abi_ulong ipoff; - abi_ulong cssel; - abi_ulong dataoff; - abi_ulong datasel; - struct target_fpreg _st[8]; + uint32_t cw; + uint32_t sw; + uint32_t tag; + uint32_t ipoff; + uint32_t cssel; + uint32_t dataoff; + uint32_t datasel; + struct target_fpreg st[8]; uint16_t status; uint16_t magic; /* 0xffff =3D regular FPU data only */ =20 /* FXSR FPU environment */ - abi_ulong _fxsr_env[6]; /* FXSR FPU env is ignored */ - abi_ulong mxcsr; - abi_ulong reserved; - struct target_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ - struct target_xmmreg _xmm[8]; - abi_ulong padding[56]; + uint32_t _fxsr_env[6]; /* FXSR FPU env is ignored */ + uint32_t mxcsr; + uint32_t reserved; + struct target_fpxreg fxsr_st[8]; /* FXSR FPU reg data is ignored */ + struct target_xmmreg xmm[8]; + uint32_t padding[56]; }; =20 -#define X86_FXSR_MAGIC 0x0000 +struct target_fpstate_64 { + /* FXSAVE format */ + uint16_t cw; + uint16_t sw; + uint16_t twd; + uint16_t fop; + uint64_t rip; + uint64_t rdp; + uint32_t mxcsr; + uint32_t mxcsr_mask; + uint32_t st_space[32]; + uint32_t xmm_space[64]; + uint32_t reserved[24]; +}; =20 -struct target_sigcontext { +#ifndef TARGET_X86_64 +# define target_fpstate target_fpstate_32 +#else +# define target_fpstate target_fpstate_64 +#endif + +struct target_sigcontext_32 { uint16_t gs, __gsh; uint16_t fs, __fsh; uint16_t es, __esh; uint16_t ds, __dsh; - abi_ulong edi; - abi_ulong esi; - abi_ulong ebp; - abi_ulong esp; - abi_ulong ebx; - abi_ulong edx; - abi_ulong ecx; - abi_ulong eax; - abi_ulong trapno; - abi_ulong err; - abi_ulong eip; + uint32_t edi; + uint32_t esi; + uint32_t ebp; + uint32_t esp; + uint32_t ebx; + uint32_t edx; + uint32_t ecx; + uint32_t eax; + uint32_t trapno; + uint32_t err; + uint32_t eip; uint16_t cs, __csh; - abi_ulong eflags; - abi_ulong esp_at_signal; + uint32_t eflags; + uint32_t esp_at_signal; uint16_t ss, __ssh; - abi_ulong fpstate; /* pointer */ - abi_ulong oldmask; - abi_ulong cr2; + uint32_t fpstate; /* pointer */ + uint32_t oldmask; + uint32_t cr2; }; =20 +struct target_sigcontext_64 { + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + + uint64_t rdi; + uint64_t rsi; + uint64_t rbp; + uint64_t rbx; + uint64_t rdx; + uint64_t rax; + uint64_t rcx; + uint64_t rsp; + uint64_t rip; + + uint64_t eflags; + + uint16_t cs; + uint16_t gs; + uint16_t fs; + uint16_t ss; + + uint64_t err; + uint64_t trapno; + uint64_t oldmask; + uint64_t cr2; + + uint64_t fpstate; /* pointer */ + uint64_t padding[8]; +}; + +#ifndef TARGET_X86_64 +# define target_sigcontext target_sigcontext_32 +#else +# define target_sigcontext target_sigcontext_64 +#endif + +/* see Linux/include/uapi/asm-generic/ucontext.h */ struct target_ucontext { abi_ulong tuc_flags; abi_ulong tuc_link; @@ -895,8 +956,8 @@ struct target_ucontext { target_sigset_t tuc_sigmask; /* mask last for extensibility */ }; =20 -struct sigframe -{ +#ifndef TARGET_X86_64 +struct sigframe { abi_ulong pretcode; int sig; struct target_sigcontext sc; @@ -905,8 +966,7 @@ struct sigframe char retcode[8]; }; =20 -struct rt_sigframe -{ +struct rt_sigframe { abi_ulong pretcode; int sig; abi_ulong pinfo; @@ -917,6 +977,17 @@ struct rt_sigframe char retcode[8]; }; =20 +#else + +struct rt_sigframe { + abi_ulong pretcode; + struct target_ucontext uc; + struct target_siginfo info; + struct target_fpstate fpstate; +}; + +#endif + /* * Set up a signal frame. */ @@ -927,6 +998,7 @@ static void setup_sigcontext(struct target_sigcontext *= sc, abi_ulong fpstate_addr) { CPUState *cs =3D CPU(x86_env_get_cpu(env)); +#ifndef TARGET_X86_64 uint16_t magic; =20 /* already locked in setup_frame() */ @@ -959,6 +1031,44 @@ static void setup_sigcontext(struct target_sigcontext= *sc, /* non-iBCS2 extensions.. */ __put_user(mask, &sc->oldmask); __put_user(env->cr[2], &sc->cr2); +#else + __put_user(env->regs[R_EDI], &sc->rdi); + __put_user(env->regs[R_ESI], &sc->rsi); + __put_user(env->regs[R_EBP], &sc->rbp); + __put_user(env->regs[R_ESP], &sc->rsp); + __put_user(env->regs[R_EBX], &sc->rbx); + __put_user(env->regs[R_EDX], &sc->rdx); + __put_user(env->regs[R_ECX], &sc->rcx); + __put_user(env->regs[R_EAX], &sc->rax); + + __put_user(env->regs[8], &sc->r8); + __put_user(env->regs[9], &sc->r9); + __put_user(env->regs[10], &sc->r10); + __put_user(env->regs[11], &sc->r11); + __put_user(env->regs[12], &sc->r12); + __put_user(env->regs[13], &sc->r13); + __put_user(env->regs[14], &sc->r14); + __put_user(env->regs[15], &sc->r15); + + __put_user(cs->exception_index, &sc->trapno); + __put_user(env->error_code, &sc->err); + __put_user(env->eip, &sc->rip); + + __put_user(env->eflags, &sc->eflags); + __put_user(env->segs[R_CS].selector, &sc->cs); + __put_user((uint16_t)0, &sc->gs); + __put_user((uint16_t)0, &sc->fs); + __put_user(env->segs[R_SS].selector, &sc->ss); + + __put_user(mask, &sc->oldmask); + __put_user(env->cr[2], &sc->cr2); + + /* fpstate_addr must be 16 byte aligned for fxsave */ + assert(!(fpstate_addr & 0xf)); + + cpu_x86_fxsave(env, fpstate_addr); + __put_user(fpstate_addr, &sc->fpstate); +#endif } =20 /* @@ -972,23 +1082,34 @@ get_sigframe(struct target_sigaction *ka, CPUX86Stat= e *env, size_t frame_size) =20 /* Default to using normal stack */ esp =3D env->regs[R_ESP]; +#ifdef TARGET_X86_64 + esp -=3D 128; /* this is the redzone */ +#endif + /* This is the X/Open sanctioned signal stack switching. */ if (ka->sa_flags & TARGET_SA_ONSTACK) { if (sas_ss_flags(esp) =3D=3D 0) { esp =3D target_sigaltstack_used.ss_sp + target_sigaltstack_use= d.ss_size; } } else { - +#ifndef TARGET_X86_64 /* This is the legacy signal stack switching. */ if ((env->segs[R_SS].selector & 0xffff) !=3D __USER_DS && !(ka->sa_flags & TARGET_SA_RESTORER) && ka->sa_restorer) { esp =3D (unsigned long) ka->sa_restorer; } +#endif } + +#ifndef TARGET_X86_64 return (esp - frame_size) & -8ul; +#else + return ((esp - frame_size) & (~15ul)) - 8; +#endif } =20 +#ifndef TARGET_X86_64 /* compare linux/arch/i386/kernel/signal.c:setup_frame() */ static void setup_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUX86State *env) @@ -1029,7 +1150,6 @@ static void setup_frame(int sig, struct target_sigact= ion *ka, __put_user(val16, (uint16_t *)(frame->retcode+6)); } =20 - /* Set up registers for signal handler */ env->regs[R_ESP] =3D frame_addr; env->eip =3D ka->_sa_handler; @@ -1047,13 +1167,17 @@ static void setup_frame(int sig, struct target_siga= ction *ka, give_sigsegv: force_sigsegv(sig); } +#endif =20 -/* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */ +/* compare linux/arch/x86/kernel/signal.c:setup_rt_frame() */ static void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUX86State *env) { - abi_ulong frame_addr, addr; + abi_ulong frame_addr; +#ifndef TARGET_X86_64 + abi_ulong addr; +#endif struct rt_sigframe *frame; int i; =20 @@ -1063,12 +1187,17 @@ static void setup_rt_frame(int sig, struct target_s= igaction *ka, if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) goto give_sigsegv; =20 + /* These fields are only in rt_sigframe on 32 bit */ +#ifndef TARGET_X86_64 __put_user(sig, &frame->sig); addr =3D frame_addr + offsetof(struct rt_sigframe, info); __put_user(addr, &frame->pinfo); addr =3D frame_addr + offsetof(struct rt_sigframe, uc); __put_user(addr, &frame->puc); - tswap_siginfo(&frame->info, info); +#endif + if (ka->sa_flags & TARGET_SA_SIGINFO) { + tswap_siginfo(&frame->info, info); + } =20 /* Create the ucontext. */ __put_user(0, &frame->uc.tuc_flags); @@ -1087,6 +1216,7 @@ static void setup_rt_frame(int sig, struct target_sig= action *ka, =20 /* Set up to return from userspace. If provided, use a stub already in userspace. */ +#ifndef TARGET_X86_64 if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { @@ -1099,15 +1229,31 @@ static void setup_rt_frame(int sig, struct target_s= igaction *ka, val16 =3D 0x80cd; __put_user(val16, (uint16_t *)(frame->retcode+5)); } +#else + /* XXX: Would be slightly better to return -EFAULT here if test fails + assert(ka->sa_flags & TARGET_SA_RESTORER); */ + __put_user(ka->sa_restorer, &frame->pretcode); +#endif =20 /* Set up registers for signal handler */ env->regs[R_ESP] =3D frame_addr; env->eip =3D ka->_sa_handler; =20 +#ifndef TARGET_X86_64 + env->regs[R_EAX] =3D sig; + env->regs[R_EDX] =3D (unsigned long)&frame->info; + env->regs[R_ECX] =3D (unsigned long)&frame->uc; +#else + env->regs[R_EAX] =3D 0; + env->regs[R_EDI] =3D sig; + env->regs[R_ESI] =3D (unsigned long)&frame->info; + env->regs[R_EDX] =3D (unsigned long)&frame->uc; +#endif + cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); - cpu_x86_load_seg(env, R_SS, __USER_DS); cpu_x86_load_seg(env, R_CS, __USER_CS); + cpu_x86_load_seg(env, R_SS, __USER_DS); env->eflags &=3D ~TF_MASK; =20 unlock_user_struct(frame, frame_addr, 1); @@ -1125,6 +1271,7 @@ restore_sigcontext(CPUX86State *env, struct target_si= gcontext *sc) abi_ulong fpstate_addr; unsigned int tmpflags; =20 +#ifndef TARGET_X86_64 cpu_x86_load_seg(env, R_GS, tswap16(sc->gs)); cpu_x86_load_seg(env, R_FS, tswap16(sc->fs)); cpu_x86_load_seg(env, R_ES, tswap16(sc->es)); @@ -1138,7 +1285,29 @@ restore_sigcontext(CPUX86State *env, struct target_s= igcontext *sc) env->regs[R_EDX] =3D tswapl(sc->edx); env->regs[R_ECX] =3D tswapl(sc->ecx); env->regs[R_EAX] =3D tswapl(sc->eax); + env->eip =3D tswapl(sc->eip); +#else + env->regs[8] =3D tswapl(sc->r8); + env->regs[9] =3D tswapl(sc->r9); + env->regs[10] =3D tswapl(sc->r10); + env->regs[11] =3D tswapl(sc->r11); + env->regs[12] =3D tswapl(sc->r12); + env->regs[13] =3D tswapl(sc->r13); + env->regs[14] =3D tswapl(sc->r14); + env->regs[15] =3D tswapl(sc->r15); + + env->regs[R_EDI] =3D tswapl(sc->rdi); + env->regs[R_ESI] =3D tswapl(sc->rsi); + env->regs[R_EBP] =3D tswapl(sc->rbp); + env->regs[R_EBX] =3D tswapl(sc->rbx); + env->regs[R_EDX] =3D tswapl(sc->rdx); + env->regs[R_EAX] =3D tswapl(sc->rax); + env->regs[R_ECX] =3D tswapl(sc->rcx); + env->regs[R_ESP] =3D tswapl(sc->rsp); + + env->eip =3D tswapl(sc->rip); +#endif =20 cpu_x86_load_seg(env, R_CS, lduw_p(&sc->cs) | 3); cpu_x86_load_seg(env, R_SS, lduw_p(&sc->ss) | 3); @@ -1152,7 +1321,11 @@ restore_sigcontext(CPUX86State *env, struct target_s= igcontext *sc) if (!access_ok(VERIFY_READ, fpstate_addr, sizeof(struct target_fpstate))) goto badframe; +#ifndef TARGET_X86_64 cpu_x86_frstor(env, fpstate_addr, 1); +#else + cpu_x86_fxrstor(env, fpstate_addr); +#endif } =20 return err; @@ -1160,6 +1333,8 @@ badframe: return 1; } =20 +/* Note: there is no sigreturn on x86_64, there is only rt_sigreturn */ +#ifndef TARGET_X86_64 long do_sigreturn(CPUX86State *env) { struct sigframe *frame; @@ -1191,6 +1366,7 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } +#endif =20 long do_rt_sigreturn(CPUX86State *env) { @@ -1198,7 +1374,7 @@ long do_rt_sigreturn(CPUX86State *env) struct rt_sigframe *frame; sigset_t set; =20 - frame_addr =3D env->regs[R_ESP] - 4; + frame_addr =3D env->regs[R_ESP] - sizeof(abi_ulong); trace_user_do_rt_sigreturn(env, frame_addr); if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; @@ -6418,7 +6594,7 @@ static void handle_pending_signal(CPUArchState *cpu_e= nv, int sig, #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64) \ || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX) \ || defined(TARGET_PPC64) || defined(TARGET_HPPA) \ - || defined(TARGET_NIOS2) + || defined(TARGET_NIOS2) || defined(TARGET_X86_64) /* These targets do not have traditional signals. */ setup_rt_frame(sig, sa, &k->info, &target_old_set, cpu_env); #else diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8df124f..573f2aa 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1417,6 +1417,8 @@ floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper); void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector); void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32); void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32); +void cpu_x86_fxsave(CPUX86State *s, target_ulong ptr); +void cpu_x86_fxrstor(CPUX86State *s, target_ulong ptr); =20 /* you can call this signal handler from your SIGBUS and SIGSEGV signal handlers to inform the virtual CPU of exceptions. non zero diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c index 66474ad..69ea33a 100644 --- a/target/i386/fpu_helper.c +++ b/target/i386/fpu_helper.c @@ -1377,6 +1377,18 @@ void helper_fxrstor(CPUX86State *env, target_ulong p= tr) } } =20 +#if defined(CONFIG_USER_ONLY) +void cpu_x86_fxsave(CPUX86State *env, target_ulong ptr) +{ + helper_fxsave(env, ptr); +} + +void cpu_x86_fxrstor(CPUX86State *env, target_ulong ptr) +{ + helper_fxrstor(env, ptr); +} +#endif + void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { uintptr_t ra =3D GETPC(); --=20 2.9.3 From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488234966476379.9215051142522; Mon, 27 Feb 2017 14:36:06 -0800 (PST) Received: from localhost ([::1]:57300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTtl-0002f6-4f for importer@patchew.org; Mon, 27 Feb 2017 17:36:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTrh-0001Qm-5b for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTrc-00046S-GQ for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:57 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:59488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTrc-00041A-7e for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:52 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MLgGJ-1cjJ4e0CO3-000t3s; Mon, 27 Feb 2017 23:33:43 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:35 +0100 Message-Id: <20170227223337.17434-5-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> X-Provags-ID: V03:K0:7+fDW61jTyM7noGxRh/nu5ddiIOZf00aoM5drz575gqVIgvLJkj EZObbWhJ4YFVwc+w1AoSpQQcNpT+6sEAPXYcfoJDWE+sbL1J9qxlo2gXChB5HQn/M03JoxB AHHDkHkRrESrkWcSFOVQYifmExubJCcgM8n3IuEmjzZxLc6nIrSHKlizu9YoK6kpLNtNQEo 4kpX402DgmKU42JEJHMfA== X-UI-Out-Filterresults: notjunk:1;V01:K0:S4koxu0J1GI=:10TQZQjLJYrv+INixmJq9/ Fk7GhbmvM6cdHxsH2LT/6abYTW7kbsLSu2oLpQFen+2b2nlRFfERijLqDmcXkVL77CIhg8y3W eK2Fvm/9lv9rAuLtvG8vO41P/jN8+7AmcfKsBKdQI4VdT4tMQQU/6EXocOHex/5bjLfaZJTM9 kvdd95TsrUdR/2tp+w/i84l3ZUA117ioaDMoySFZXGpp3eX1nqFcaoXTAM8FApJA1raAdQgzi 7cIlqJ6b9EVzzbjfmFRohbBnL9V5GNqsvH8mz/um2mK9K/CHpXy7+/JgL1Z9X97JdjQ8f+tAN ALsSRvkpyAGtLC+lvFpBvMAjDN7qoFNiyerit6sT0a5JdiFIiyyNPTcDLc9MRtu0C6CTN3S6J nsAS/xD3OvM3JMEXV/hTZHFvM6/1hCa81VtQnhaw6IpnuhJDMi+XWuds4fuS/CyXEfn4WJ3Qb N1Hv436sYHnYUiTJUBB0r4ervkHjRlhYYxnGnaOXI1x/h/I1Tq99U14ZHHtETQr+76MCGawhf lvioEi5ZZNLnfJ/sdUlj+KGeOJnp7CxsZyi0tVmxI7cclmo4fWV6LmsOUKA1lmJTerPvFaUYx XVVESIPPsZAELgQz7VShnZix7NCcAhichle0ITbYB0IlNTFnp5Ik+8Vxw0Qupav4M+vEo0TL5 QHfUfwx9OgZG5aP9uaYixvToWTGRxGdcBV52oln+SJO/WvQyg/M1ZydxetVSDR34cuv8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 4/6] linux-user: correctly manage SR in ucontext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use cpu_m68k_get_ccr()/cpu_m68k_set_ccr() to setup and restore correctly the value of SR in the ucontext structure Signed-off-by: Laurent Vivier Message-Id: <20170225110517.2832-2-laurent@vivier.eu> --- linux-user/signal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 5dae87e..99adfc2 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5676,6 +5676,7 @@ static inline int target_rt_setup_ucontext(struct tar= get_ucontext *uc, CPUM68KState *env) { target_greg_t *gregs =3D uc->tuc_mcontext.gregs; + uint32_t sr =3D cpu_m68k_get_ccr(env); =20 __put_user(TARGET_MCONTEXT_VERSION, &uc->tuc_mcontext.version); __put_user(env->dregs[0], &gregs[0]); @@ -5695,7 +5696,7 @@ static inline int target_rt_setup_ucontext(struct tar= get_ucontext *uc, __put_user(env->aregs[6], &gregs[14]); __put_user(env->aregs[7], &gregs[15]); __put_user(env->pc, &gregs[16]); - __put_user(env->sr, &gregs[17]); + __put_user(sr, &gregs[17]); =20 return 0; } @@ -5729,7 +5730,7 @@ static inline int target_rt_restore_ucontext(CPUM68KS= tate *env, __get_user(env->aregs[7], &gregs[15]); __get_user(env->pc, &gregs[16]); __get_user(temp, &gregs[17]); - env->sr =3D (env->sr & 0xff00) | (temp & 0xff); + cpu_m68k_set_ccr(env, temp); =20 return 0; =20 --=20 2.9.3 From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488235231662616.4665335259064; Mon, 27 Feb 2017 14:40:31 -0800 (PST) Received: from localhost ([::1]:57316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTy1-0006QY-F7 for importer@patchew.org; Mon, 27 Feb 2017 17:40:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTrn-0001WK-5W for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTrj-0004fo-1r for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:03 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:64160) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTri-0004Y8-NU for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:33:58 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MGiBd-1cVXRW3oAL-00DTzi; Mon, 27 Feb 2017 23:33:44 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:36 +0100 Message-Id: <20170227223337.17434-6-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> X-Provags-ID: V03:K0:M/up4JArpKtkrq7AQRwUUk7hkTYhx+aLkFHGF3jGFkrlGRHLyzU Gy8FzmweIz1IedJCCKqTyXCZI5oiMBwj82DQSGg3jihQkAl+PCQ6s3oT21hGG7xQDXWMALj 8VK8JAxaXV1l5nsc2iQMfXmGjq+HJpoMQbi0aj35OgCVuO4joxsqdqL0q6YluHnZivuTam1 43pf5+s295pVUrpNwWQPA== X-UI-Out-Filterresults: notjunk:1;V01:K0:EcLbwgxqEvU=:kxj2IcQKLG54ETB5PDfwgr Q714WPO1e2iSl0/MAeIsuBKui6jM+4X0rKqWMjmerwCnKYa4HFz40Bn1jGGxg01pzmmUr04Hu folTSewu912PXDf8KceBGNItmyVhNWZ7qo+pJw3cxh6g+9Bktdpj7FNU8si/s0RLXhzsVltbW Zqz12c5yvmvcsMDP9YRmZBgK2jlZ0iSyMJEkOW1kS7CcQDMWczTMAVb2ivKu8DJ9rQom0XZYG PKAwCcm7uyMQpJ44uQBctC7mZrTmusBEvElqNbgeBbo4leu+z4Qu8hQOovLb+y6jWyuN7ufCo cL9LoFhhVh2vrvsnbAtq5fY4b7yYaMpPRe9a4doSsdouZCQk7jlwAvSlz5Es3H1Liuvtz2RFH Wqpxjfh7bKvXDPFAnyuTnkKcvZtowy+d8uw6zqTpQKbLrIQSJzlqbCNDAuVfa4miMbxujysCl Ek4E+oAzTguP0nDnkXi51O8GftvSgyFGpW9RsoZfCXbq4pbC/P28dJM2VEjXpz6tS594Wzld1 8B6YxrKm+iFvoQeOteUedewyFukDuAswIPN6kJrZDGdw/hynUakoAN+gni9oKQEkl+C/unzw1 COQxaMgBdfiEfc9NaV7zIKVd/bQri9DoY+pka9P//zrQKZmmyAA5bLCNY5AxcDxe/h551FPCj nEk1cJ48PxzJQWQgbaGSJK91xpMcgsRihK9cA9/EMv2nfJy3v9boL5tfEhZfoycF5B1M= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL 5/6] linux-user: fix do_rt_sigreturn on m68k linux userspace emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Michael Karcher , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Karcher do_rt_sigreturn uses an uninitialised local variable instead of fetching the old signal mask directly from the signal frame when restoring the mask, so the signal mask is undefined after do_rt_sigreturn. As the signal frame data is in target-endian order, target_to_host_sigset instead of target_to_host_sigset_internal is required. do_sigreturn is correct in using target_to_host_sigset_internal, because get_user already did the endianness conversion. Signed-off-by: Michael Karcher Signed-off-by: Laurent Vivier Message-Id: <20170225110517.2832-3-laurent@vivier.eu> --- linux-user/signal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 99adfc2..a67db04 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5851,14 +5851,13 @@ long do_rt_sigreturn(CPUM68KState *env) { struct target_rt_sigframe *frame; abi_ulong frame_addr =3D env->aregs[7] - 4; - target_sigset_t target_set; sigset_t set; =20 trace_user_do_rt_sigreturn(env, frame_addr); if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; =20 - target_to_host_sigset_internal(&set, &target_set); + target_to_host_sigset(&set, &frame->uc.tuc_sigmask); set_sigmask(&set); =20 /* restore registers */ --=20 2.9.3 From nobody Mon Feb 9 16:07:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148823541629574.57789693361588; Mon, 27 Feb 2017 14:43:36 -0800 (PST) Received: from localhost ([::1]:57348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciU10-0000p8-VC for importer@patchew.org; Mon, 27 Feb 2017 17:43:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciTrw-0001cv-9Q for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciTrs-0005Jg-GD for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:12 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:58676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciTrs-0005Bp-5i for qemu-devel@nongnu.org; Mon, 27 Feb 2017 17:34:08 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MJl7U-1chNvw3LaG-001AJH; Mon, 27 Feb 2017 23:33:45 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 23:33:37 +0100 Message-Id: <20170227223337.17434-7-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170227223337.17434-1-laurent@vivier.eu> References: <20170227223337.17434-1-laurent@vivier.eu> X-Provags-ID: V03:K0:F2iPNuISKQYWXpq38uRwDkCXPRnJ9MNmjGpZSiwEEObHkRUIZ5U 95xW4KAtJdBEuzRSvjXCrjsleIrXn7DKVDB3jqSP2YTkQJipBs9IntCPk4k96RZOOijqCmA RP/yYBYIIsziBQVTyl/7674+S6NmNLDwVDG2vdq77Ob6kxR/XjXYKisxQLVd/SbOSWR2mLu SQtNk1ZJNohmlASVclxpg== X-UI-Out-Filterresults: notjunk:1;V01:K0:LKt540LXeqE=:W23KyTUTgL5nx3ZRe6X7mT pvPQ1k4V16gWVTpbpUMYxv2N2IxKy0x/e/dhw892NMEKIDPKYeoVgB/h/ZP2nEpM8z0RXRcuk 13MnloSWAJZgHqE6QhcmJJcISdqyGrKbTQYN12j/bvRsFwT0/aNp3KTVeNEQzt+JcxWlJXM0n Wd49hYxRcj5OzTdwM5iOJCg6IsaRh3RXGPLdYfUvjKxZ89jWATP2Yj1MOPbCRooDe+KLPAGYB FBfzWzjsYFAkANELZfa4wQ/6ccBwbcCZijRL+ir48/VICjpt1IBxfbKZiRnV79Rb8OZCb5v2Z Hmz1wFl0wQ9ukdfJZ/vmEZHp3qFeq3rp3Uq6pHIvrtHamMACeSP55jgnpyw/Ew+eBEOCs+wG9 akaa7VWRbtU+4o4T3qNyvyymtfgGH0/cwamjwyUz/oRQOLxPef3oRklYAqVxz3iEBTCvIvHY0 Q6xrGsKrTMgMmo4JBk2jfADhMjyOdEyfG3vfJwTTBd0SHfEg+8gGRY2er8f09cpwbbbZuQS3f wlh+kSy5neQDD7d9yn9diG7aHsgv0ELoy2J22lgtgp6j406kLyTZlmmG0o8wSOVGBzzNwuTv+ 9cQ38BKKhXFwi1XSsQJonimsW53TvscZWijpK/y9PLVnluF+Oyzp7tg6j5/5sgNhy9pH+eGfL lzhUNKFBmUAJXN6EX4sp4DPbAO8WnfO6E49w+IWhB2xg4e7AMI2+IeQk1Jie520wCx2M= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 6/6] syscall: fixed mincore(2) not failing with ENOMEM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Riku Voipio , "Franklin \\\"Snaipe\\\" Mathieu" , Laurent Vivier , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Franklin \\\"Snaipe\\\" Mathieu" The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid. This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory. Signed-off-by: Franklin "Snaipe" Mathieu Cc: Riku Voipio Cc: Aurelien Jarno Reviewed-by: Laurent Vivier Message-Id: <20170217085800.28873-2-snaipe@diacritic.io> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2bba500..cec8428 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11194,11 +11194,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_l= ong arg1, case TARGET_NR_mincore: { void *a; + ret =3D -TARGET_ENOMEM; + a =3D lock_user(VERIFY_READ, arg1, arg2, 0); + if (!a) { + goto fail; + } ret =3D -TARGET_EFAULT; - if (!(a =3D lock_user(VERIFY_READ, arg1,arg2, 0))) - goto efault; - if (!(p =3D lock_user_string(arg3))) + p =3D lock_user_string(arg3); + if (!p) { goto mincore_fail; + } ret =3D get_errno(mincore(a, arg2, p)); unlock_user(p, arg3, ret); mincore_fail: --=20 2.9.3