From patchwork Tue Sep 25 20:51:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 974736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42KYDr3KGPz9s55 for ; Wed, 26 Sep 2018 06:52:59 +1000 (AEST) Received: from localhost ([::1]:55211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uKG-0008Fv-Ra for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2018 16:52:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uJU-0008EL-9H for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4uJP-0002Ee-SW for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:08 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:35843) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4uJP-0002E2-Jc for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:03 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MBltM-1fv1s420HU-00C8fU; Tue, 25 Sep 2018 22:51:52 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 22:51:26 +0200 Message-Id: <20180925205129.25261-3-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925205129.25261-1-laurent@vivier.eu> References: <20180925205129.25261-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:CXxiFAzWUFDcUqxCxaPKXiu4LZhuBQhdw+7Dwx+77C+EXKU3DJO hCPweevZnv+FY/PRi3UWApH33Z/b08vNpy4pFtCZMPdlcbWiSKJlhXib2JOBGKYMOhWeIqR klSyln2iGQws9dse56mrjFnjILEXaswW01JelJAMIw4p1LbqRavHNnzRO7V6ddRRQ5SBwLI y1i7bjaEyfNTuSYTRBR9Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:2e0I2yLOopA=:j5UXCNomKeDA+MxMRxxwNY IJ0LxXt21kkK5qnbG2KT7EiV41g2lD0nQue4AnOd6Grx3Tdnl1rMvI+nO5Ar1M9f5qtngcOAf dWXe8zIrdxnEm8wZrGmdWsLehB6GDPamohFDAsTZqngnCaZXBeGJrbKOHYO5cX7sGMN0kX2/I zs/1r+sgq+PJ5FKXGXFO62kyrjTw7QWfHEbsBZrKI+6xGBFOD77R7VgKdWuI8trUYdt/GT6PB 58lSnbSPXPSF5B7/B+aAKMMYYn7M4Bu2/PD2bmoOnyWAPWFYM17FXKgSJa31uFShVBFFpbX9p pMz4cj5dzYKYhkZE+kuWbavXmm8IBmHl10bVpwoFTVil1tj6sONyg+SU6R4s08ez3NS0vrDKB pxZWsV8+Iz7qb2oCWNz61ffe5WjFCB/B/MTQUBeQ4W6ePbsFaZum/mTVEePF5OCvMbScY7Iyv 5j/40ExAuP2RDukZle1Ogl5xVn7eIeyjPq2JvVXop22gZcE5/bwjzX1sXIWAtfiFcPexExV3O hC+Rw4yVbAwLQcenP/LL5Jf2B3vYSU6we67VywMMGm4nZY2TAnfPn7mb9d63xGGy41Y+hhvg1 FWLfPreU5fvzMBreWVtViMqI71fy0S6Kd77cWvPVJHYIkDVyZsoIhYUXnhaDsvTaEEny+tkgV ZhUdxD9MSyfKdN+GfTZRK11V8LpWVZbOky2j9iV9e9yhyW4SEuFnLnB/LTBhAFdgruuhJ53ub l4JfAmJvGJFYA1mm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 Subject: [Qemu-devel] [PULL v2 2/5] linux-user: add SO_LINGER to {g, s}etsockopt 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: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Carlo Marcelo Arenas Belón Original implementation for setsockopt by Chen Gang[1]; all bugs mine, including removing assignment for optname which hopefully makes the logic easier to follow and moving some variables to make the code more selfcontained. [1] http://patchwork.ozlabs.org/patch/565659/ Signed-off-by: Carlo Marcelo Arenas Belón Co-Authored-By: Chen Gang Reviewed-by: Laurent Vivier Message-Id: <20180824085601.6259-1-carenas@gmail.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 52 ++++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 5 ++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e252f8b555..58fb967499 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2032,6 +2032,24 @@ set_timeout: unlock_user (dev_ifname, optval_addr, 0); return ret; } + case TARGET_SO_LINGER: + { + struct linger lg; + struct target_linger *tlg; + + if (optlen != sizeof(struct target_linger)) { + return -TARGET_EINVAL; + } + if (!lock_user_struct(VERIFY_READ, tlg, optval_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(lg.l_onoff, &tlg->l_onoff); + __get_user(lg.l_linger, &tlg->l_linger); + ret = get_errno(setsockopt(sockfd, SOL_SOCKET, SO_LINGER, + &lg, sizeof(lg))); + unlock_user_struct(tlg, optval_addr, 0); + return ret; + } /* Options with 'int' argument. */ case TARGET_SO_DEBUG: optname = SO_DEBUG; @@ -2123,7 +2141,6 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, level = SOL_SOCKET; switch (optname) { /* These don't just return a single integer */ - case TARGET_SO_LINGER: case TARGET_SO_RCVTIMEO: case TARGET_SO_SNDTIMEO: case TARGET_SO_PEERNAME: @@ -2161,6 +2178,39 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, } break; } + case TARGET_SO_LINGER: + { + struct linger lg; + socklen_t lglen; + struct target_linger *tlg; + + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + + lglen = sizeof(lg); + ret = get_errno(getsockopt(sockfd, level, SO_LINGER, + &lg, &lglen)); + if (ret < 0) { + return ret; + } + if (len > lglen) { + len = lglen; + } + if (!lock_user_struct(VERIFY_WRITE, tlg, optval_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(lg.l_onoff, &tlg->l_onoff); + __put_user(lg.l_linger, &tlg->l_linger); + unlock_user_struct(tlg, optval_addr, 1); + if (put_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + break; + } /* Options with 'int' argument. */ case TARGET_SO_DEBUG: optname = SO_DEBUG; diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 40bb60ef4c..18d434d6dc 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -203,6 +203,11 @@ struct target_ip_mreq_source { uint32_t imr_sourceaddr; }; +struct target_linger { + abi_int l_onoff; /* Linger active */ + abi_int l_linger; /* How long to linger for */ +}; + struct target_timeval { abi_long tv_sec; abi_long tv_usec;