From patchwork Sun Jun 29 12:14:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32664 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0E2A223577 for ; Sun, 29 Jun 2014 12:16:15 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id n16sf44591797oag.10 for ; Sun, 29 Jun 2014 05:16:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=onK0IP4MB5M6UkqeR3tjIA/cNeBIVulLrRgwBO9Lwto=; b=CkrNehvgYs78duPHFDUbkRScbqEal//zLVPwYJMAIiRBqL8JRlzdNNyC9KlPCG1SmO fjg+ZgL4GnB+AhWv781LwrGv71KudrrTEwsFBlO0Tjlsv+IrYnnYG6lKf8nuR6Hc59Ah f6RKdzMMDgK2GTiCEreDSEc5etfnkcqzuI7kKs0rtMX73a5mopoy+dw27Upv9QbQCUmE E9SR/kIc06SNRTN1QJjGKfda+UYhm//d7m0onLVHJCBzSbiXt4cqi6Ft87tRTGrzJJqq o0djIWCz8QmIrXkAQzaqPa0vmuQzhPZXa17VJytp46VPAxXRn4vf0VM5wx6J5mXbrVal 78/Q== X-Gm-Message-State: ALoCoQm2TAKYjSdbtveBK4x2o81yhTEOcG2Q13O0kR+rs0w2pb+AixYPV9I+0M7MHql6aSQ0grtF X-Received: by 10.50.73.35 with SMTP id i3mr12722413igv.2.1404044173832; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.225 with SMTP id o88ls1133472qge.88.gmail; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) X-Received: by 10.58.46.141 with SMTP id v13mr31922789vem.18.1404044173680; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id o5si8836521vez.30.2014.06.29.05.16.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so6447345vcb.5 for ; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) X-Received: by 10.58.150.100 with SMTP id uh4mr32782635veb.30.1404044173542; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp72363vcb; Sun, 29 Jun 2014 05:16:13 -0700 (PDT) X-Received: by 10.140.24.230 with SMTP id 93mr31064671qgr.11.1404044172841; Sun, 29 Jun 2014 05:16:12 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k6si20964633qct.2.2014.06.29.05.16.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:16:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:57492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E1k-0005MX-Bi for patch@linaro.org; Sun, 29 Jun 2014 08:16:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0c-00042g-Ii for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1E0X-0000bj-Ni for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:02 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=41865 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0X-0000ai-FF for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:14:57 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 9AA8C26547; Sun, 29 Jun 2014 14:14:55 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Sun, 29 Jun 2014 15:14:43 +0300 Message-Id: <8289d112811adfd609c1e3d855427a96418564b0.1404041926.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Peter Maydell , Anthony Liguori , Paul Burton Subject: [Qemu-devel] [PULL v2 03/13] linux-user: translate the result of getsockopt SO_TYPE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Paul Burton 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. Signed-off-by: Paul Burton Signed-off-by: Riku Voipio --- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5c175ba..8d13781 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -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) {