From mboxrd@z Thu Jan 1 00:00:00 1970 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 Message-ID: <1213fd545e8fde1612c17e98533043f5.squirrel@alpha> Date: Tue, 1 Sep 2009 20:58:03 -0700 (PDT) From: "Gabriele Gorla" MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH] add target to host SO_* translation to getsocketopt List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@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);