From patchwork Wed Sep 2 03:58:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriele Gorla X-Patchwork-Id: 32867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 834D3B708C for ; Thu, 3 Sep 2009 15:06:42 +1000 (EST) Received: from localhost ([127.0.0.1]:43082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mj4Wr-00021m-5P for incoming@patchwork.ozlabs.org; Thu, 03 Sep 2009 01:06:37 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MihXk-0001dY-2h for qemu-devel@nongnu.org; Wed, 02 Sep 2009 00:34:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MihXe-0001dM-DY for qemu-devel@nongnu.org; Wed, 02 Sep 2009 00:33:58 -0400 Received: from [199.232.76.173] (port=44276 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MihXe-0001dJ-7t for qemu-devel@nongnu.org; Wed, 02 Sep 2009 00:33:54 -0400 Received: from [69.3.150.202] (port=51862 helo=alpha.penguintown.net) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MihXd-0007in-Hj for qemu-devel@nongnu.org; Wed, 02 Sep 2009 00:33:54 -0400 Received: from localhost ([127.0.0.1] helo=alpha ident=www-data) by alpha.penguintown.net with esmtp (Exim 4.69) (envelope-from ) id 1Migyx-00080J-O3 for qemu-devel@nongnu.org; Tue, 01 Sep 2009 20:58:03 -0700 Received: from 10.0.0.1 (SquirrelMail authenticated user gorlik) by alpha with HTTP; Tue, 1 Sep 2009 20:58:03 -0700 (PDT) Message-ID: <1213fd545e8fde1612c17e98533043f5.squirrel@alpha> Date: Tue, 1 Sep 2009 20:58:03 -0700 (PDT) From: "Gabriele Gorla" To: qemu-devel@nongnu.org User-Agent: SquirrelMail/1.4.15 MIME-Version: 1.0 X-Priority: 3 (Normal) Importance: Normal X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-Greylist: delayed 2137 seconds by postgrey-1.27 at monty-python; Wed, 02 Sep 2009 00:33:43 EDT X-Mailman-Approved-At: Thu, 03 Sep 2009 01:05:58 -0400 Subject: [Qemu-devel] [PATCH] add target to host SO_* translation to getsocketopt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org getsockopt will fail when the define for the socket options differ between target and host. This patch extracts the trnalsation code from setsockopt into a new function and uses the function in both setsockopt and getsockopt. Signed-off-by: Gabriele Gorla diff -r -U 5 qemu-0.10.6_orig/linux-user/syscall.c qemu-0.10.6/linux-user/syscall.c --- qemu-0.10.6_orig/linux-user/syscall.c 2009-07-16 17:56:24 -0700 +++ qemu-0.10.6/linux-user/syscall.c 2009-09-01 20:44:37 -0700 @@ -831,10 +831,77 @@ the_end: target_msgh->msg_controllen = tswapl(space); return 0; } +static int so_target_to_host(int optname) +{ + switch (optname) { + /* Options with 'int' argument. */ + case TARGET_SO_DEBUG: + optname = SO_DEBUG; + break; + case TARGET_SO_REUSEADDR: + optname = SO_REUSEADDR; + break; + case TARGET_SO_TYPE: + optname = SO_TYPE; + break; + case TARGET_SO_ERROR: + optname = SO_ERROR; + break; + case TARGET_SO_DONTROUTE: + optname = SO_DONTROUTE; + break; + case TARGET_SO_BROADCAST: + optname = SO_BROADCAST; + break; + case TARGET_SO_SNDBUF: + optname = SO_SNDBUF; + break; + case TARGET_SO_RCVBUF: + optname = SO_RCVBUF; + break; + case TARGET_SO_KEEPALIVE: + optname = SO_KEEPALIVE; + break; + case TARGET_SO_OOBINLINE: + optname = SO_OOBINLINE; + break; + case TARGET_SO_NO_CHECK: + optname = SO_NO_CHECK; + break; + case TARGET_SO_PRIORITY: + optname = SO_PRIORITY; + break; +#ifdef SO_BSDCOMPAT + case TARGET_SO_BSDCOMPAT: + optname = SO_BSDCOMPAT; + break; +#endif + case TARGET_SO_PASSCRED: + optname = SO_PASSCRED; + break; + case TARGET_SO_TIMESTAMP: + optname = SO_TIMESTAMP; + break; + case TARGET_SO_RCVLOWAT: + optname = SO_RCVLOWAT; + break; + case TARGET_SO_RCVTIMEO: + optname = SO_RCVTIMEO; + break; + case TARGET_SO_SNDTIMEO: + optname = SO_SNDTIMEO; + break; + break; + default: + optname=0; + } + return optname; +} + /* do_setsockopt() Must return target values and target errnos. */ static abi_long do_setsockopt(int sockfd, int level, int optname, abi_ulong optval_addr, socklen_t optlen) { abi_long ret; @@ -880,72 +947,12 @@ default: goto unimplemented; } break; case TARGET_SOL_SOCKET: - switch (optname) { - /* Options with 'int' argument. */ - case TARGET_SO_DEBUG: - optname = SO_DEBUG; - break; - case TARGET_SO_REUSEADDR: - optname = SO_REUSEADDR; - break; - case TARGET_SO_TYPE: - optname = SO_TYPE; - break; - case TARGET_SO_ERROR: - optname = SO_ERROR; - break; - case TARGET_SO_DONTROUTE: - optname = SO_DONTROUTE; - break; - case TARGET_SO_BROADCAST: - optname = SO_BROADCAST; - break; - case TARGET_SO_SNDBUF: - optname = SO_SNDBUF; - break; - case TARGET_SO_RCVBUF: - optname = SO_RCVBUF; - break; - case TARGET_SO_KEEPALIVE: - optname = SO_KEEPALIVE; - break; - case TARGET_SO_OOBINLINE: - optname = SO_OOBINLINE; - break; - case TARGET_SO_NO_CHECK: - optname = SO_NO_CHECK; - break; - case TARGET_SO_PRIORITY: - optname = SO_PRIORITY; - break; -#ifdef SO_BSDCOMPAT - case TARGET_SO_BSDCOMPAT: - optname = SO_BSDCOMPAT; - break; -#endif - case TARGET_SO_PASSCRED: - optname = SO_PASSCRED; - break; - case TARGET_SO_TIMESTAMP: - optname = SO_TIMESTAMP; - break; - case TARGET_SO_RCVLOWAT: - optname = SO_RCVLOWAT; - break; - case TARGET_SO_RCVTIMEO: - optname = SO_RCVTIMEO; - break; - case TARGET_SO_SNDTIMEO: - optname = SO_SNDTIMEO; - break; - break; - default: - goto unimplemented; - } + optname=so_target_to_host(optname); + if(optname==0) goto unimplemented; if (optlen < sizeof(uint32_t)) return -TARGET_EINVAL; if (get_user_u32(val, optval_addr)) return -TARGET_EFAULT; @@ -983,10 +990,12 @@ } break; case SOL_TCP: /* TCP options all take an 'int' value. */ int_case: + optname=so_target_to_host(optname); + if(optname==0) goto unimplemented; if (get_user_u32(len, optlen)) return -TARGET_EFAULT; if (len < 0) return -TARGET_EINVAL; lv = sizeof(int);