From patchwork Mon Jun 23 13:26:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32352 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4CEE520540 for ; Mon, 23 Jun 2014 13:29:51 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id rq2sf25854228pbb.2 for ; Mon, 23 Jun 2014 06:29:50 -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=mibipnBs+LoF3R8SEj7ZpXuxtswhXA0YvEFf9PpV95E=; b=MNYyB4cfUBScSIC71+kY4hZE3xKeQoOkPfU4qfSpAJLOT7NlpHxNAvDwMuejv+ecDq Upu4z83zaAedsbYNL2yaNdfY7EYjexIjULB3BCh9x2ye8ZaamBfEwPCv6wW1q5gsxTUY Qib7REfeFu3tIJVly/jQGsL89ylBgsgi7Alu/VMLQT9AOkBEn7QLZfV+py8CNyggGZA3 XkI75uTCKDfTVFIwmBm8ZsPa+v/ALKM0eDcWrMTs6q0GFR8APgi/3QlzjAck0CxV9zj2 9jsx1p4DtvnR9tjgfKyVjzEjA9+TRdP8YbLwEQThpwLIPF8z/oXvEPLBg8s/1R0rUeA1 0sKg== X-Gm-Message-State: ALoCoQlXCFSSDazz6VwGw1DJoea8e/clbBVl67hjQl20OEJfggMarPmNwzwJEMCK11qE1OhoMW05 X-Received: by 10.66.165.165 with SMTP id yz5mr10413829pab.37.1403530190522; Mon, 23 Jun 2014 06:29:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.11 with SMTP id n11ls1137540qge.11.gmail; Mon, 23 Jun 2014 06:29:50 -0700 (PDT) X-Received: by 10.221.29.137 with SMTP id ry9mr19283100vcb.6.1403530190414; Mon, 23 Jun 2014 06:29:50 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id fd4si8993152vec.17.2014.06.23.06.29.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 06:29:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so6064207veb.41 for ; Mon, 23 Jun 2014 06:29:50 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr19415218vcg.16.1403530190351; Mon, 23 Jun 2014 06:29:50 -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 tc5csp130754vcb; Mon, 23 Jun 2014 06:29:50 -0700 (PDT) X-Received: by 10.140.92.116 with SMTP id a107mr4640642qge.115.1403530189847; Mon, 23 Jun 2014 06:29:49 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b38si22658190qge.54.2014.06.23.06.29.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 23 Jun 2014 06:29:49 -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]:53510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Jh-0007iv-E5 for patch@linaro.org; Mon, 23 Jun 2014 09:29:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gk-0003iF-78 for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz4Gd-0001AJ-3n for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:46 -0400 Received: from afflict.kos.to ([92.243.29.197]:50448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gc-00019Z-LP for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:38 -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 0FFF02654D; Mon, 23 Jun 2014 15:26:36 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 23 Jun 2014 16:26:19 +0300 Message-Id: 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: 92.243.29.197 Cc: Paul Burton Subject: [Qemu-devel] [PULL 04/19] 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.128.182 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) {