From patchwork Fri Mar 5 20:14:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42307 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44B6C399F004; Fri, 5 Mar 2021 20:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44B6C399F004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975358; bh=K8NJKpi+ZxUhroSwephL/Qq3OM8305GHyBJXPiv9WEU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fiqPyN8pE1O1Z8+U0JF7kn6aKo3rq+wSQUSmb5FqtiLpFnG2WrvhmcFKGhui2pRnR hSOJjAlGxmfNVNk1Fp0tBH09zCGfG9TT94wXsVfekj2oOIFmC5yFvjz8+UCwn6XYOa jbb5+GWfaN0voY0or2zfC1ZQ9zcae3pv5YxBJUXU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id BBC76399C03A for ; Fri, 5 Mar 2021 20:15:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BBC76399C03A Received: by mail-qt1-x835.google.com with SMTP id t13so1388516qta.11 for ; Fri, 05 Mar 2021 12:15:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K8NJKpi+ZxUhroSwephL/Qq3OM8305GHyBJXPiv9WEU=; b=qgP35gR2B/qLDUu+zCND7RZ1p0N97CsCX44pJl5a8LYoQXZlB2htIHSu8UsYbGtkHh DiATiKnXvExsnIGyeLTw2kJ95g7pDYZmeGtqM4lq/g7lH2RZccixscbNv9Xg91ZlYUV2 ObC8ZWUPn/lUU0uGw5Ad2pfAhkFYpyPI0ZxyPuk2FVE1LoRyVLGsL3hgofdZc9Y7S3XS cZyhPz8kA+w3ztO539YbSFhWn0rxEUQhDxS0/gZJpFBcEA3LfzRJxhKPVaWdNaStWsLY k97JtDHzR9zoynxWxxIfimdIyvfwB9SOpAFCLjuTW5N3mMbPkS/E20P2OcgqXMrZT9Fd EPiw== X-Gm-Message-State: AOAM531U0Vo3MIqkl2tT2JcV76GhnApA51cmD3l/Hf312pZQQKLhlI46 EtMtDaUvN1CYOflhEmIt/PkqSrbVELb4uA== X-Google-Smtp-Source: ABdhPJxFZl0W3l738PNmrNtVN2HQvaZeX8Z7WbnfUK5UvUTxLilA3ZIFs03MriEo2WNR2Yl9+hne7Q== X-Received: by 2002:ac8:76c5:: with SMTP id q5mr10621104qtr.197.1614975354219; Fri, 05 Mar 2021 12:15:54 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:54 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 26/52] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS} Date: Fri, 5 Mar 2021 17:14:52 -0300 Message-Id: <20210305201518.798584-27-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210305201518.798584-1-adhemerval.zanella@linaro.org> References: <20210305201518.798584-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Handle the SO_TIMESTAMP{NS} similar to recvmsg: for !__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP or SO_TIMESTAMPNS and appends it to the control buffer if has extra space or returns MSG_CTRUNC otherwise. The 32-bit time field is kept as-is. Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of 'struct mmsghdr *' to IOV_MAX (and also increases the stack size requirement to IOV_MAX times sizeof (socklen_t)). The Linux imposes a similar limit to sendmmsg, so bound the array size on recvmmsg is not unreasonable. And this will be used only on older when building with 32-bit time support. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c index 672ba20332..5cd107ffa9 100644 --- a/sysdeps/unix/sysv/linux/recvmmsg.c +++ b/sysdeps/unix/sysv/linux/recvmmsg.c @@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } + + socklen_t csize[IOV_MAX]; + if (vlen > IOV_MAX) + vlen = IOV_MAX; + for (int i = 0; i < vlen; i++) + csize[i] = vmessages[i].msg_hdr.msg_controllen; + # ifdef __ASSUME_RECVMMSG_SYSCALL r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); # else r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); # endif - if (r >= 0 && timeout != NULL) - *timeout = valid_timespec_to_timespec64 (ts32); + if (r >= 0) + { + if (timeout != NULL) + *timeout = valid_timespec_to_timespec64 (ts32); + + for (int i=0; i < r; i++) + __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]); + } #endif /* __ASSUME_TIME64_SYSCALLS */ return r; }