From patchwork Tue Sep 8 14:57:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AU1gcM5x; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7YT29w6z9sTS for ; Wed, 9 Sep 2020 00:57:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C26E395184B; Tue, 8 Sep 2020 14:57:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C26E395184B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577066; bh=kLx7TJqsatko9nnFeILPzHs+9ztpadEfqfDu4Em9o/w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AU1gcM5xrAZq4+1Sl2Efsf+TC6/uUzN10hxzLMgnzmWvHxlFXpX2ecpgxfuLQiEqi ca21cTQ3tgdUpn6U2fH6Sb+5+qWiEtNVH664W+IUW4ZnKjRdFzPHx5izTxuHYXDiFV MDFeKevGd/QcOQHWY7b91ak5B7d6m/6isoal9ka4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id 81EB1386103E for ; Tue, 8 Sep 2020 14:57:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 81EB1386103E Received: by mail-qk1-x741.google.com with SMTP id w12so15537053qki.6 for ; Tue, 08 Sep 2020 07:57:43 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=kLx7TJqsatko9nnFeILPzHs+9ztpadEfqfDu4Em9o/w=; b=MIA6vTk2HSO00uoC1+xowGuMcaJiLNCAfOEwJqvVaWnidpczSzbkJqWcVR345Fq3hi CJe8Kz+S/OHNNbjeH68BU9AamoEqTCnMPDK3DcnWWy7zAkQTq3N7tEeYo05eZ3Xv2P+f AtUduLqgXwml/cRQ/vnCzBTtbmxU1ip2Tcn6u48kz9Vep6bwNmb85jw8yxuTUl9jezQb r6zLefH8pVG/N81p5b/9rKjmxHN5X51zvh81WRFhK7qdDEXFisge6kG1/LJ5zIJkmY7n Ag6Nx1jdfqH/WeiH3Sd/FYUsyJbTfWjCpbYUwHyJgAuni7Bwwcv3fUNYl1q4LCjQDWZI yAdw== X-Gm-Message-State: AOAM533NhM/YUPOnrMwIAlB/yqlGUgqrXjP+TSAzB8kYFxU0LeB/ooFY jzqsiMCM6nreYAc54CIKVkq/Jn2oRcQhqw== X-Google-Smtp-Source: ABdhPJyfofDOH60Oz/H7CjIvHJs4r2pH+LVItz4h/KQCgUm21Cv2Q1gRM9BTClXS3pq2Q3QQW6rb5A== X-Received: by 2002:a05:620a:148:: with SMTP id e8mr486174qkn.186.1599577062712; Tue, 08 Sep 2020 07:57:42 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 01/14] linux: Simplify clock_getres Date: Tue, 8 Sep 2020 11:57:25 -0300 Message-Id: <20200908145738.640039-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" With arch-syscall.h it can now assumes the existance of either __NR_clock_getres or __NR_clock_getres_time64. The 32-bit time_t support is now only build for !__ASSUME_TIME64_SYSCALLS. It also uses the time64-support functions to simplify it further. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- sysdeps/unix/sysv/linux/clock_getres.c | 38 ++++++++++---------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c index 5f6955ab10..6be73c94de 100644 --- a/sysdeps/unix/sysv/linux/clock_getres.c +++ b/sysdeps/unix/sysv/linux/clock_getres.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -28,36 +29,26 @@ int __clock_getres64 (clockid_t clock_id, struct __timespec64 *res) { -#ifdef __ASSUME_TIME64_SYSCALLS - /* 64 bit ABIs or Newer 32-bit ABIs that only support 64-bit time_t. */ -# ifndef __NR_clock_getres_time64 -# define __NR_clock_getres_time64 __NR_clock_getres -# endif -# ifdef HAVE_CLOCK_GETRES64_VSYSCALL - return INLINE_VSYSCALL (clock_getres_time64, 2, clock_id, res); -# else - return INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); -# endif -#else int r; - /* Old 32-bit ABI with possible 64-bit time_t support. */ -# ifdef __NR_clock_getres_time64 - /* Avoid issue a __NR_clock_getres_time64 syscall on kernels that do not - support 64-bit time_t. */ - static int time64_support = 1; - if (atomic_load_relaxed (&time64_support) != 0) + +#ifndef __NR_clock_getres_time64 +# define __NR_clock_getres_time64 __NR_clock_getres +#endif + if (supports_time64 ()) { -# ifdef HAVE_CLOCK_GETRES64_VSYSCALL +#ifdef HAVE_CLOCK_GETRES64_VSYSCALL r = INLINE_VSYSCALL (clock_getres_time64, 2, clock_id, res); -# else +#else r = INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); -# endif +#endif + if (r == 0 || errno != ENOSYS) return r; - atomic_store_relaxed (&time64_support, 0); + mark_time64_unsupported (); } -# endif + +#ifndef __ASSUME_TIME64_SYSCALLS /* Fallback code that uses 32-bit support. */ struct timespec ts32; # ifdef HAVE_CLOCK_GETRES_VSYSCALL @@ -67,8 +58,9 @@ __clock_getres64 (clockid_t clock_id, struct __timespec64 *res) # endif if (r == 0) *res = valid_timespec_to_timespec64 (ts32); - return r; #endif + + return r; } #if __TIMESIZE != 64 From patchwork Tue Sep 8 14:57:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AT3og8lT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7YZ1qp2z9sTS for ; Wed, 9 Sep 2020 00:57:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51F7239518BE; Tue, 8 Sep 2020 14:57:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51F7239518BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577068; bh=Z9+yILVLjNRuvVqNB5E3jo1V1OOc1M6pX9M03oeEQxE=; 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=AT3og8lTN3LD0rnO0IkK5S+hDW/oxb1gg/4063uAVurGtjg0Gqq3HAN67sxKQ/fvz lcHjIR8yBlbJEkSb5ejEcQPZubN7/90DHi79xTnjiez5ckYXJRDjv7Pbavg62CD3K7 f3ucSnGj3K7EoeDxP5HCXGPCnL9Sh6kpoOGJNMwM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id D016E3861830 for ; Tue, 8 Sep 2020 14:57:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D016E3861830 Received: by mail-qt1-x843.google.com with SMTP id n10so12120247qtv.3 for ; Tue, 08 Sep 2020 07:57:44 -0700 (PDT) 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=Z9+yILVLjNRuvVqNB5E3jo1V1OOc1M6pX9M03oeEQxE=; b=AZ1OJVL5MYST6uUVERoikwnf0s8rgCJnXno9gabEWgthb64Vfv/yUuhRWnwqHS+/z8 7yfa/xhovctsQKXHS+hGf0QStzqVtWGCKcnRj1vU/mvKM3hI6MlvU6rtZ//SQpKNh/A6 pJe9nqXFW5KPfc7gG9rbb4A4EuK6KfG8nJN/tSmp6ZveCwCmqkqpzyRkpdh/kerpJ8GZ 6/6c8fzCpJXkUJbj9ThSyidGOu3tHMlu29Cu3KsSS6uXrezPARdZPMbiZKxtJ1VMeHrX Et83GFfZ9Y/TbLoe9L/HcgPqCpqZqGVX0JyWeZzwiDoWEkHroymJUfKO7dUR7Rsa6jiH RRAA== X-Gm-Message-State: AOAM533Vy7n8TXlYa+l00cOSpqPWh1o2gzZSFcuOhPDHf7CMrl3Tp36R A3VgkN8ggf9V6ZOdEf5MXoNBaeeJBzNzZg== X-Google-Smtp-Source: ABdhPJyJL8IqoCCj0KPcrIjPlSu3Lu17Ni2JGU8FhcPSYaUeUsozZ5TqOTUeHKpqOoyItAlP3uMs5A== X-Received: by 2002:aed:2907:: with SMTP id s7mr384295qtd.321.1599577064087; Tue, 08 Sep 2020 07:57:44 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:43 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 02/14] linux: Add ppoll time64 optimization Date: Tue, 8 Sep 2020 11:57:26 -0300 Message-Id: <20200908145738.640039-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It avoid continuing issue the __NR_ppoll_time64 syscall once the kernel advertise it does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- sysdeps/unix/sysv/linux/ppoll.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sysdeps/unix/sysv/linux/ppoll.c b/sysdeps/unix/sysv/linux/ppoll.c index dd2167fc55..e68a153427 100644 --- a/sysdeps/unix/sysv/linux/ppoll.c +++ b/sysdeps/unix/sysv/linux/ppoll.c @@ -22,6 +22,7 @@ #include #include #include +#include int @@ -37,16 +38,23 @@ __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, timeout = &tval; } + int ret; + + if (supports_time64 ()) + { #ifndef __NR_ppoll_time64 # define __NR_ppoll_time64 __NR_ppoll #endif - int ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, - __NSIG_BYTES); + ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, + __NSIG_BYTES); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret >= 0 || errno != ENOSYS) - return ret; + if (ret == 0 || errno != ENOSYS) + return ret; + mark_time64_unsupported (); + } + +#ifndef __ASSUME_TIME64_SYSCALLS struct timespec ts32; if (timeout) { From patchwork Tue Sep 8 14:57:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qlZYOaDf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Yg4cpYz9sSP for ; Wed, 9 Sep 2020 00:57:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D415B3951C0E; Tue, 8 Sep 2020 14:57:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D415B3951C0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577068; bh=0J2PEazsbWPkQKTwsovYY3jTNPc5otr208Tdl1h6Ka8=; 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=qlZYOaDfW3NzmgwhnXjdL03iPF1QTz+1bQwrZgiulGT1gZ1ZbTpJfsTBXPdH8v8iH W38M5FbDA9UOlN2jwEgR67f5Zf2FHs6GgJZMh28+0q6gITREGt85rSfW5LDexHA48t YCTnAVcKHJXH0gkF7deTtwPYdFiY9BG5MSlP1p90= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id 6AE0E39518AC for ; Tue, 8 Sep 2020 14:57:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6AE0E39518AC Received: by mail-qk1-x743.google.com with SMTP id w186so15578934qkd.1 for ; Tue, 08 Sep 2020 07:57:46 -0700 (PDT) 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=0J2PEazsbWPkQKTwsovYY3jTNPc5otr208Tdl1h6Ka8=; b=GzsqOIn78IQMRB975crh2kwlM7bouhNRMK6jr65mPuQ+hIz5/pNb8oJdBObDZMz3iH r7FEZkW21dkVI0hBMkfgP4zx2KnROT/Mcw9ZV8RTPPJ6lJEUpIXdzpbZZiG1N4KgtKCY 3oc3So/x+YVZYLC84soAQStMHE1UOqMqwiTHi47nZH62+XkzAtUhssy4qcDJhRoRWkYS 5R6lYFxOT4I1+rMgBE+Z2qiQJ9vM4DMEGtOnhxUEs9a5U+cOXwqx1MeY8UmJYzvYK2yS sa8te0j4V8u7I0d2hCDf+6FnNEzvD9BuzPhQa4ZuoFpuG5XTe02zoasDFyH56+vuMszo DKUg== X-Gm-Message-State: AOAM531ZSKOUaISLo1V8BPMrKjTIdGbN5YnzdRN6JTHsapf+AW8r9+xY miTAMTTgC0d9MYZfreO2KxycgBhqPjob0A== X-Google-Smtp-Source: ABdhPJzg2OGGgzJJXobUHLFNaxdtfhD0hihwljK8InDSLQKeecrx5FEuNC2hI2aOyYanDoaJGdR6mg== X-Received: by 2002:a37:92c7:: with SMTP id u190mr473582qkd.110.1599577065779; Tue, 08 Sep 2020 07:57:45 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:45 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 03/14] linux: Add time64 semtimedop support Date: Tue, 8 Sep 2020 11:57:27 -0300 Message-Id: <20200908145738.640039-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Either the __NR_semtimedop_time64 (for 32-bit) or the __NR_semtimedop (for 64-bit) syscall is used as default. The 32-bit fallback is used iff __ASSUME_TIME64_SYSCALLS is not defined, which assumes the kernel ABI provides either __NR_ipc or __NR_semtimeop (for 32-bit time_t). Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- sysdeps/unix/sysv/linux/include/sys/sem.h | 6 +++ sysdeps/unix/sysv/linux/semtimedop.c | 57 +++++++++++++++++++---- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/sysdeps/unix/sysv/linux/include/sys/sem.h b/sysdeps/unix/sysv/linux/include/sys/sem.h index a9151e057d..f369c6b6d3 100644 --- a/sysdeps/unix/sysv/linux/include/sys/sem.h +++ b/sysdeps/unix/sysv/linux/include/sys/sem.h @@ -7,9 +7,15 @@ __typeof__ (semtimedop) __semtimedop attribute_hidden; #if __TIMESIZE == 64 # define __semctl64 __semctl +# define __semtimedop64 __semtimedop #else +# include + extern int __semctl64 (int semid, int semnum, int cmd, ...); libc_hidden_proto (__semctl64); +extern int __semtimedop64 (int semid, struct sembuf *sops, size_t nsops, + const struct __timespec64 *tmo); +libc_hidden_proto (__semtimedop64); #endif # endif diff --git a/sysdeps/unix/sysv/linux/semtimedop.c b/sysdeps/unix/sysv/linux/semtimedop.c index 6fdde09bad..56121fb0bf 100644 --- a/sysdeps/unix/sysv/linux/semtimedop.c +++ b/sysdeps/unix/sysv/linux/semtimedop.c @@ -22,18 +22,59 @@ #include /* Perform user-defined atomical operation of array of semaphores. */ +int +__semtimedop64 (int semid, struct sembuf *sops, size_t nsops, + const struct __timespec64 *timeout) +{ +#if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS +# ifndef __NR_semtimedop_time64 +# define __NR_semtimedop_time64 __NR_semtimedop +# endif + int r = INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, + timeout); +#else + int r = INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, + SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); +#endif + +#ifndef __ASSUME_TIME64_SYSCALLS + if (r == 0 || errno != ENOSYS) + return r; + + struct timespec ts32, *pts32 = NULL; + if (timeout != NULL) + { + if (! in_time_t_range (timeout->tv_sec)) + { + __set_errno (EINVAL); + return -1; + } + ts32 = valid_timespec64_to_timespec (*timeout); + pts32 = &ts32; + } +# if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS + r = INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); +# else + r = INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, + SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); +# endif +#endif /* __ASSUME_TIME64_SYSCALLS */ + return r; +} +#if __TIMESIZE != 64 +libc_hidden_def (__semtimedop64) int __semtimedop (int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) { - /* semtimedop wire-up syscall is not exported for 32-bit ABIs (they have - semtimedop_time64 instead with uses a 64-bit time_t). */ -#if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined __NR_semtimedop - return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); -#else - return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, - SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); -#endif + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) + { + ts64 = valid_timespec_to_timespec64 (*timeout); + pts64 = &ts64; + } + return __semtimedop64 (semid, sops, nsops, pts64); } +#endif weak_alias (__semtimedop, semtimedop) From patchwork Tue Sep 8 14:57:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=B0FtC6IK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Yl5sLtz9sRK for ; Wed, 9 Sep 2020 00:58:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F2463951C1D; Tue, 8 Sep 2020 14:57:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F2463951C1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577070; bh=m5n8AAQhO4Z0BQ/AaFSDVP9cZXFYGLFOqkFeCQ4vaLk=; 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=B0FtC6IKCsypOHid/2weZGLQPxV1pGwNIInkIuYgPgcJbyE6tms3PuOnzCIoty/Qr cHQy2+0+N2Jt/S+o+uRvAexx69qK6KZ6txUklzkt03eZG2TAjLcoiIqmqxri6TFGfk hRp/Ag///NqBb0fBtdlcYd66WuOqtysdra3iiih8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by sourceware.org (Postfix) with ESMTPS id 32ADD3861830 for ; Tue, 8 Sep 2020 14:57:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 32ADD3861830 Received: by mail-qt1-x844.google.com with SMTP id n10so12120431qtv.3 for ; Tue, 08 Sep 2020 07:57:48 -0700 (PDT) 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=m5n8AAQhO4Z0BQ/AaFSDVP9cZXFYGLFOqkFeCQ4vaLk=; b=FL//SX0xFWe8XEGK9GOSb3dA/qRjqqkYSP1xW70juO1zOxl5Ye5z21Q4rZPiHzXwYm g6V93E+gjOOmJxOLJm669ewsB2RCNewVtiWAzA3ILfhDacmGFJshIpopK3oS3yd1Ns1n jG98YYSsUKcQTGjv2AR4dfD3EzCM/AN/PI196hf/nWBFgA+M2NshCnAXscaTlizab+zr aswmJcMl1BDjTKkwoPbOVBvApc1UNqnGtdFBkQ3CJgeoA/2dDUC9RphoN0NKyulsX4eC pIsDqXGjHCNf3uzLEyWC7WgPUHVEyeiQXFipUljtT1bHeW9/9hSswYkIT/wTBStNngDc 4gSA== X-Gm-Message-State: AOAM531IcQKIytjus3TO6HwgsRFi+4WOxuYLINNOfTKKEbcm6nEDpRu+ Sg/qUHuE7/F7mYkvHWId4mpCx5P1KhHj2w== X-Google-Smtp-Source: ABdhPJz6cuKvIzuoEdk9DTJJaZAmV9/Nemrh4GhhT5ExWD1To1nqsLhnFPrChCjY8qesCcVJOhPqoQ== X-Received: by 2002:ac8:1415:: with SMTP id k21mr465855qtj.374.1599577067383; Tue, 08 Sep 2020 07:57:47 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:46 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 04/14] linux: Add time64 pselect support Date: Tue, 8 Sep 2020 11:57:28 -0300 Message-Id: <20200908145738.640039-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: * Move the 32-bit fallback implementation to pselect32.c. It simplifies the required microblaze override. Reviewed-by: Alistair Francis --- The syscall __NR_pselect6_time64 (32-bit) or __NR_pselect6 (64-bit) is used as default. For architectures with __ASSUME_TIME64_SYSCALLS the 32-bit fallback uses __NR_pselec6. To accomodate microblaze missing pselect6 support on kernel older than 3.15 the fallback is moved to its own function to the microblaze specific implementation can override it. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- include/sys/select.h | 16 ++++++ sysdeps/unix/sysv/linux/Makefile | 2 +- .../microblaze/{pselect.c => pselect32.c} | 34 ++++-------- sysdeps/unix/sysv/linux/pselect.c | 53 ++++++++++++++----- sysdeps/unix/sysv/linux/pselect32.c | 47 ++++++++++++++++ 5 files changed, 116 insertions(+), 36 deletions(-) rename sysdeps/unix/sysv/linux/microblaze/{pselect.c => pselect32.c} (66%) create mode 100644 sysdeps/unix/sysv/linux/pselect32.c diff --git a/include/sys/select.h b/include/sys/select.h index 07bb49b994..b5ae9af861 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -3,6 +3,22 @@ #ifndef _ISOMAC /* Now define the internal interfaces. */ +# if __TIMESIZE == 64 +# define __pselect64 __pselect +#else +# include +extern int __pselect64 (int __nfds, fd_set *__readfds, + fd_set *__writefds, fd_set *__exceptfds, + const struct __timespec64 *__timeout, + const __sigset_t *__sigmask); +libc_hidden_proto (__pselect64) + +extern int __pselect32 (int __nfds, fd_set *__readfds, + fd_set *__writefds, fd_set *__exceptfds, + const struct __timespec64 *__timeout, + const __sigset_t *__sigmask) + attribute_hidden; +#endif extern int __pselect (int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, const struct timespec *__timeout, diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 5079f33655..03cb6e790d 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -61,7 +61,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \ open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \ timerfd_gettime timerfd_settime prctl \ process_vm_readv process_vm_writev clock_adjtime \ - time64-support + time64-support pselect32 CFLAGS-gethostid.c = -fexceptions CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables diff --git a/sysdeps/unix/sysv/linux/microblaze/pselect.c b/sysdeps/unix/sysv/linux/microblaze/pselect32.c similarity index 66% rename from sysdeps/unix/sysv/linux/microblaze/pselect.c rename to sysdeps/unix/sysv/linux/microblaze/pselect32.c index 1dfc3b8fc9..d7cfeaa0e9 100644 --- a/sysdeps/unix/sysv/linux/microblaze/pselect.c +++ b/sysdeps/unix/sysv/linux/microblaze/pselect32.c @@ -23,38 +23,27 @@ #include #ifndef __ASSUME_PSELECT -# define __pselect __pselect_syscall -#endif - -/* If pselect is supported, just use the Linux generic implementation. */ -#include - -#ifndef __ASSUME_PSELECT -# undef __pselect int -__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - const struct timespec *timeout, const sigset_t *sigmask) +__pselect32 (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, const struct __timespec64 *timeout, + const sigset_t *sigmask) { - int ret = __pselect_syscall (nfds, readfds, writefds, exceptfds, timeout, - sigmask); - if (ret >= 0 || errno != ENOSYS) - return ret; - /* The fallback uses 'select' which shows the race condition regarding signal mask set/restore, requires two additional syscalls, and has a worse timeout precision (microseconds instead of nanoseconds). */ - struct timeval tval, *ptval = NULL; + struct timeval tv32, *ptv32 = NULL; if (timeout != NULL) { - if (! valid_nanoseconds (timeout->tv_nsec)) + if (! in_time_t_range (timeout->tv_sec) + || ! valid_nanoseconds (timeout->tv_nsec)) { __set_errno (EINVAL); return -1; } - TIMESPEC_TO_TIMEVAL (&tval, timeout); - ptval = &tval; + tv32 = valid_timespec64_to_timeval (*timeout); + ptv32 = &tv32; } sigset_t savemask; @@ -62,12 +51,11 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, __sigprocmask (SIG_SETMASK, sigmask, &savemask); /* select itself is a cancellation entrypoint. */ - ret = __select (nfds, readfds, writefds, exceptfds, ptval); + int r = __select (nfds, readfds, writefds, exceptfds, ptv32); if (sigmask != NULL) __sigprocmask (SIG_SETMASK, &savemask, NULL); - return ret; + return r; } -weak_alias (__pselect, pselect) -#endif +#endif /* __ASSUME_PSELECT */ diff --git a/sysdeps/unix/sysv/linux/pselect.c b/sysdeps/unix/sysv/linux/pselect.c index 304db03338..ed36121023 100644 --- a/sysdeps/unix/sysv/linux/pselect.c +++ b/sysdeps/unix/sysv/linux/pselect.c @@ -18,14 +18,15 @@ #include #include +#include int -__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - const struct timespec *timeout, const sigset_t *sigmask) +__pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct __timespec64 *timeout, const sigset_t *sigmask) { /* The Linux kernel can in some situations update the timeout value. We do not want that so use a local variable. */ - struct timespec tval; + struct __timespec64 tval; if (timeout != NULL) { tval = *timeout; @@ -36,18 +37,46 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, we can only pass in 6 directly. If there is an architecture with support for more parameters a new version of this file needs to be created. */ - struct - { - __syscall_ulong_t ss; - __syscall_ulong_t ss_len; - } data; - data.ss = (__syscall_ulong_t) (uintptr_t) sigmask; - data.ss_len = __NSIG_BYTES; +#ifndef __NR_pselect6_time64 +# define __NR_pselect6_time64 __NR_pselect6 +#endif + int r; + if (supports_time64 ()) + { + r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, + timeout, + ((__syscall_ulong_t[]){ (uintptr_t) sigmask, + __NSIG_BYTES })); + if (r == 0 || errno != ENOSYS) + return r; + + mark_time64_unsupported (); + } - return SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, - timeout, &data); +#ifndef __ASSUME_TIME64_SYSCALLS + r = __pselect32 (nfds, readfds, writefds, exceptfds, timeout, sigmask); +#endif + return r; } + +#if __TIMESIZE != 64 +libc_hidden_def (__pselect64) + +int +__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask) +{ + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) + { + ts64 = valid_timespec_to_timespec64 (*timeout); + pts64 = &ts64; + } + return __pselect64 (nfds, readfds, writefds, exceptfds, pts64, sigmask); +} +#endif + #ifndef __pselect weak_alias (__pselect, pselect) #endif diff --git a/sysdeps/unix/sysv/linux/pselect32.c b/sysdeps/unix/sysv/linux/pselect32.c new file mode 100644 index 0000000000..0a2a7ac752 --- /dev/null +++ b/sysdeps/unix/sysv/linux/pselect32.c @@ -0,0 +1,47 @@ +/* Synchronous I/O multiplexing. Linux 32-bit time fallback. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +#ifndef __ASSUME_TIME64_SYSCALLS + +int +__pselect32 (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, const struct __timespec64 *timeout, + const sigset_t *sigmask) +{ + struct timespec ts32, *pts32 = NULL; + if (timeout != NULL) + { + if (! in_time_t_range (timeout->tv_sec)) + { + __set_errno (EINVAL); + return -1; + } + + ts32 = valid_timespec64_to_timespec (*timeout); + pts32 = &ts32; + } + + return SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, + pts32, + ((__syscall_ulong_t[]){ (uintptr_t) sigmask, + __NSIG_BYTES })); +} +#endif From patchwork Tue Sep 8 14:57:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=m325LQ8M; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Yr4Bkvz9sSP for ; Wed, 9 Sep 2020 00:58:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0724B3951C2B; Tue, 8 Sep 2020 14:57:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0724B3951C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577073; bh=GXfIdWCisx/P/S9weYcpCal1w6ZzXbI23/kTE4UmWNA=; 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=m325LQ8MCv81Ce83eWKYRUJcUSyuz4ubXOV6aIUL5cnNEYE5gsFIivY9u1fTtlg1g S51pn1DbMwJdz9ft6RmVvjZKZqZInn8bFNgBePKHyB1jzLZMafSrJqnm9YwMYsHVBb VKOX987xh8jNaq6LdK66zdOrLlyjIxwsUBlsw8jk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id 7DB1E39518B8 for ; Tue, 8 Sep 2020 14:57:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7DB1E39518B8 Received: by mail-qk1-x742.google.com with SMTP id d20so15563412qka.5 for ; Tue, 08 Sep 2020 07:57:49 -0700 (PDT) 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=GXfIdWCisx/P/S9weYcpCal1w6ZzXbI23/kTE4UmWNA=; b=PaVgXrSKkUPz8CQkpY0vfLD8+75bBMCwzvdxqeyXMKVPNsOdFzrrcz7kYXMxyy7cMM aidoRe75Dah5P6qYfDyEsQbV85zvk4AJJVqkxg7T/1d/gDxQu4VGqEPOoY0K9UvbHHsO ggNb1Knm+9AFhzJ98fghcOyj9b3A+kIZ/oeRTTk87V3dQuy4ZAoqX8WVypeO4UZry5LM zYQrsayYw6IzY50Bfr1327Bnl5UIorLjJwnWcLNhzavb0iY/uqlPytb7LymlGpKMgfVc HMExfZBHOH8GJRlXuSsJIeD61wLZZ2J38wQ2890g6udk5wLNT+MZqsqQ0OaSZYGXA3o4 sFCw== X-Gm-Message-State: AOAM533kCKnYcw9b9G7mQyaoihteact2wUqtGQcurPVfSwn5PTvhyUnp 1gCQQs+Vok9w7V4aphNAB8pBWpvsAy7QoA== X-Google-Smtp-Source: ABdhPJz+46dX+5BaF4EpOBMGwRyJNjZaXc/vqQuwdZaWj27QixjSjOT1p9yu36GKXTPPZHGp0M8aTQ== X-Received: by 2002:ae9:d882:: with SMTP id u124mr430059qkf.93.1599577068699; Tue, 08 Sep 2020 07:57:48 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:48 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 05/14] linux: Add time64 select support Date: Tue, 8 Sep 2020 11:57:29 -0300 Message-Id: <20200908145738.640039-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The syscall __NR_pselect6_time64 (32-bit) or __NR_pselect6 (64-bit) is used as default. For architectures with __ASSUME_TIME64_SYSCALLS the 32-bit fallback uses __NR_select/__NR__newselect or __NR_pselect6 (it should cover the microblaze case where older kernels do not provide __NR_pselect6). Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- include/sys/select.h | 8 +++ include/time.h | 6 +++ sysdeps/unix/sysv/linux/select.c | 92 ++++++++++++++++++++++++-------- 3 files changed, 83 insertions(+), 23 deletions(-) diff --git a/include/sys/select.h b/include/sys/select.h index b5ae9af861..ec073deeba 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -5,8 +5,11 @@ /* Now define the internal interfaces. */ # if __TIMESIZE == 64 # define __pselect64 __pselect +# define __select64 __select #else # include +# include + extern int __pselect64 (int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, const struct __timespec64 *__timeout, @@ -18,6 +21,11 @@ extern int __pselect32 (int __nfds, fd_set *__readfds, const struct __timespec64 *__timeout, const __sigset_t *__sigmask) attribute_hidden; + +extern int __select64 (int __nfds, fd_set *__readfds, + fd_set *__writefds, fd_set *__exceptfds, + struct __timeval64 *__timeout); +libc_hidden_proto (__select64) #endif extern int __pselect (int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, diff --git a/include/time.h b/include/time.h index fe4da9ca10..936486e206 100644 --- a/include/time.h +++ b/include/time.h @@ -464,6 +464,12 @@ valid_timespec_to_timeval32 (const struct timespec ts) return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; } +static inline struct __timeval64 +valid_timespec_to_timeval64 (const struct timespec ts) +{ + return (struct __timeval64) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; +} + /* Check if a value is in the valid nanoseconds range. Return true if it is, false otherwise. */ static inline bool diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c index 54c50edba2..bed52fbda2 100644 --- a/sysdeps/unix/sysv/linux/select.c +++ b/sysdeps/unix/sysv/linux/select.c @@ -21,6 +21,7 @@ #include #include #include +#include /* Check the first NFDS descriptors each in READFDS (if not NULL) for read readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS @@ -28,43 +29,88 @@ after waiting the interval specified therein. Returns the number of ready descriptors, or -1 for errors. */ -#ifdef __NR__newselect -# undef __NR_select -# define __NR_select __NR__newselect -#endif - int -__select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) +__select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct __timeval64 *timeout) { -#ifdef __NR_select - return SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds, - timeout); -#else - int result; - struct timespec ts, *tsp = NULL; - - if (timeout) + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) { - TIMEVAL_TO_TIMESPEC (timeout, &ts); - tsp = &ts; + ts64 = timeval64_to_timespec64 (*timeout); + pts64 = &ts64; } - result = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, tsp, - NULL); - - if (timeout) +#ifndef __NR_pselect6_time64 +# define __NR_pselect6_time64 __NR_pselect6 +#endif + int r; + if (supports_time64 ()) { + r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, + pts64, NULL); /* Linux by default will update the timeout after a pselect6 syscall (though the pselect() glibc call suppresses this behavior). Since select() on Linux has the same behavior as the pselect6 syscall, we update the timeout here. */ - TIMESPEC_TO_TIMEVAL (timeout, &ts); + if (r == 0 || errno != ENOSYS) + { + if (timeout != NULL) + TIMEVAL_TO_TIMESPEC (timeout, &ts64); + return r; + } + + mark_time64_unsupported (); } - return result; +#ifndef __ASSUME_TIME64_SYSCALLS + struct timespec ts32, *pts32 = NULL; + if (timeout != NULL) + { + if (! in_time_t_range (timeout->tv_sec)) + { + __set_errno (EINVAL); + return -1; + } + ts32 = valid_timespec64_to_timespec (ts64); + pts32 = &ts32; + } +# ifndef __ASSUME_PSELECT +# ifdef __NR__newselect +# undef __NR_select +# define __NR_select __NR__newselect +# endif + r = SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds, pts32); +# else + r = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, pts32, + NULL); +# endif + if (r >= 0 && timeout != NULL) + *timeout = valid_timespec_to_timeval64 (ts32); #endif + + return r; } + +#if __TIMESIZE != 64 +libc_hidden_def (__select64) + +int +__select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) +{ + struct __timeval64 tv64, *ptv64 = NULL; + if (timeout != NULL) + { + tv64 = valid_timeval_to_timeval64 (*timeout); + ptv64 = &tv64; + } + int r = __select64 (nfds, readfds, writefds, exceptfds, ptv64); + if (r >= 0 && timeout != NULL) + /* The remanining timeout will be always less the input TIMEOUT. */ + *timeout = valid_timeval64_to_timeval (tv64); + return r; +} +#endif libc_hidden_def (__select) weak_alias (__select, select) From patchwork Tue Sep 8 14:57:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=t5PuQ2z0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Yx3Lj4z9sRK for ; Wed, 9 Sep 2020 00:58:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B5723951C39; Tue, 8 Sep 2020 14:57:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B5723951C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577073; bh=QFLcOWO69A1E4S627h/imyAYzsuj7wHJvfusRrdgECg=; 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=t5PuQ2z0w1fPcCze6mSuZTkXCZY4Y8IfoEAQjPHY+p4E+PbyVYo62Om9v25X6/KAA f/rIIRNRBgoI4+ZfbjS/cdTAF05TWlpMS8wLqkusv9yQAu5qREGObFXJz8Lc0bsvkn Zb+EAMMnn+mRol8uSOokxg3qLqtX3skhOP/ImYtY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by sourceware.org (Postfix) with ESMTPS id 0F10639518B8 for ; Tue, 8 Sep 2020 14:57:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0F10639518B8 Received: by mail-qv1-xf43.google.com with SMTP id z18so4408966qvp.6 for ; Tue, 08 Sep 2020 07:57:51 -0700 (PDT) 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=QFLcOWO69A1E4S627h/imyAYzsuj7wHJvfusRrdgECg=; b=XLAhAnH4jr6XUI514ZEK6RjUGAQQ8b/2rWyGHhq+idQilumLNT+ephh3LrjabF5v+l PJkL/szMYodz0eVanDBgk7OKUClZ2tICGYXvO7yfV+pFGmy4l4aIu7Ff7q9JzBCc1XMM PTJ0anZjkQzJ9rQYBg3XWC7WgeZ07MmCziQuDdrKuxb5zxydb8BnEZsnl0rPJI1ycAw+ qZfKRW7/V2shOuAN17CDQJmSWCAVmQg/96L/jbrFu6Wy4Lo/Mz5ZvPVOI88g4r1J91dI fCrMrKdXhX17qGnrXXZUWNQnSI5QHFvlLCp2Wi5YvmHRTiO8PwSGhR/TlnlVdhrwpl9B 6lRg== X-Gm-Message-State: AOAM530T/XMUFoXTi21PsRd1brlGIWNy4Jw2w2JY1NF1ljF3MqZBknL+ Fqj0BNza4lx/PyDSjsFA0QE5K63qZyY/pA== X-Google-Smtp-Source: ABdhPJwaELg0hW7eUcuNUmxGyAId6pnHimwFSoYlMwWpKl3WLzOE2fUrl9Q5ZsAWjjDqlkGGyfEKWw== X-Received: by 2002:a0c:f946:: with SMTP id i6mr520589qvo.2.1599577070411; Tue, 08 Sep 2020 07:57:50 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:49 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 06/14] linux: Add time64 sigtimedwait support Date: Tue, 8 Sep 2020 11:57:30 -0300 Message-Id: <20200908145738.640039-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The syscall __NR_sigtimedwait_time64 (for 32-bit) or __NR_sigtimedwait (for 64-bit) is used as default. The 32-bit fallback is used iff __ASSUME_TIME64_SYSCALLS is not defined, which assumes the kernel ABI provides either __NR_rt_sigtimedwait (32-bit time_t). Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Alistair Francis --- include/signal.h | 8 +++++ sysdeps/unix/sysv/linux/sigtimedwait.c | 50 +++++++++++++++++++++----- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/signal.h b/include/signal.h index b4ee02d153..544d701bce 100644 --- a/include/signal.h +++ b/include/signal.h @@ -38,6 +38,14 @@ extern int __sigwait (const sigset_t *__set, int *__sig); libc_hidden_proto (__sigwait) extern int __sigwaitinfo (const sigset_t *__set, siginfo_t *__info); libc_hidden_proto (__sigwaitinfo) +#if __TIMESIZE == 64 +# define __sigtimedwait64 __sigtimedwait +#else +# include +extern int __sigtimedwait64 (const sigset_t *__set, siginfo_t *__info, + const struct __timespec64 *__timeout); +libc_hidden_proto (__sigtimedwait64) +#endif extern int __sigtimedwait (const sigset_t *__set, siginfo_t *__info, const struct timespec *__timeout); libc_hidden_proto (__sigtimedwait) diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c index f2ef3aad45..4405606571 100644 --- a/sysdeps/unix/sysv/linux/sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/sigtimedwait.c @@ -15,20 +15,38 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include -#include +#include int -__sigtimedwait (const sigset_t *set, siginfo_t *info, - const struct timespec *timeout) +__sigtimedwait64 (const sigset_t *set, siginfo_t *info, + const struct __timespec64 *timeout) { - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - int result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, timeout, +#ifndef __NR_rt_sigtimedwait_time64 +# define __NR_rt_sigtimedwait_time64 __NR_rt_sigtimedwait +#endif + int result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, __NSIG_BYTES); +#ifndef __ASSUME_TIME64_SYSCALLS + if (result != 0 && errno == ENOSYS) + { + struct timespec ts32, *pts32 = NULL; + if (timeout != NULL) + { + if (! in_time_t_range (timeout->tv_sec)) + { + __set_errno (EINVAL); + return -1; + } + ts32 = valid_timespec64_to_timespec (*timeout); + pts32 = &ts32; + } + result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, pts32, + __NSIG_BYTES); + } +#endif + /* The kernel generates a SI_TKILL code in si_code in case tkill is used. tkill is transparently used in raise(). Since having SI_TKILL as a code is useful in general we fold the results @@ -38,5 +56,21 @@ __sigtimedwait (const sigset_t *set, siginfo_t *info, return result; } +#if __TIMESIZE != 64 +libc_hidden_def (__sigtimedwait64) + +int +__sigtimedwait (const sigset_t *set, siginfo_t *info, + const struct timespec *timeout) +{ + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) + { + ts64 = valid_timespec_to_timespec64 (*timeout); + pts64 = &ts64; + } + return __sigtimedwait64 (set, info, pts64); +} +#endif libc_hidden_def (__sigtimedwait) weak_alias (__sigtimedwait, sigtimedwait) From patchwork Tue Sep 8 14:57:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=m8o1hzc+; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Z153Tbz9sRK for ; Wed, 9 Sep 2020 00:58:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B9453951C4C; Tue, 8 Sep 2020 14:57:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B9453951C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577074; bh=wza4BQ/EEblV6D7QwRl/SdKGwfU55zwOcAuK2bLh+cE=; 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=m8o1hzc+4yrAi/mQx94C9ptJ2btgFVItvhJWxP7/SpmUS9R6+VQoGzFhSm6rvV+iP HuLXGKbreU7GUdiOVY0EGaYQ1ZUsKlyv2MpkdwjDRZLVPxLPesLIDY5sDfvZzOeq/x aRFNe0+wf+Cqv+9p0MRwn+rrhu7nWBa8MgfRUgxs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by sourceware.org (Postfix) with ESMTPS id 43AEC3861830 for ; Tue, 8 Sep 2020 14:57:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 43AEC3861830 Received: by mail-qt1-x841.google.com with SMTP id n10so12120612qtv.3 for ; Tue, 08 Sep 2020 07:57:52 -0700 (PDT) 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=wza4BQ/EEblV6D7QwRl/SdKGwfU55zwOcAuK2bLh+cE=; b=LpTXjY1tavt4fAGDQLttiFysX1o+hlvfqRgeLnTpDJ/YthvIyvBfGPvtk3GnJGB+Ay 7Rf/KHSXkxV9NTB5NgJM/nxIDWipEmzitlIN6RyXQXi3eDDNdVql9/c4l646f0YSv5e2 gURLQAaLSA7VMUQTvye3sw1QGRmJagXGqAVwkJCYh/gmOhrU3CgBPKzYbScE6yEMuZAm CWMYI7OzXmQ4wAkaYjAnzm3lTtUMlD3BcE+B6Ly4ZMqi1fIJvkvLpOr4yO/+l4RU747+ J6KkrSmj0Xc+CIGdSy+0MPnWzUbNSqwqExTwTw05/ooC3SmC4P0M/2VIPvuRtUVTb6Ti p+Wg== X-Gm-Message-State: AOAM532n9aysU8ytdhnORSwJ9CdQxXtdU8TQg31/3A+R8N9jMXdqej7N RgkC6PECU5hjZ7mfviYTvWSZWogNBiXAxA== X-Google-Smtp-Source: ABdhPJxxTBKo1EZqSNcgQA98ukFXHjlvROZarU9pvcvfIJS1EojTZ8zPMN5O0E6vgPjMe4EYjjPqUQ== X-Received: by 2002:ac8:7388:: with SMTP id t8mr432801qtp.187.1599577071676; Tue, 08 Sep 2020 07:57:51 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:51 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 07/14] linux: Use 64-bit time_t syscall on clock_getcputclockid Date: Tue, 8 Sep 2020 11:57:31 -0300 Message-Id: <20200908145738.640039-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The syscall __NR_clock_getres_time64 (for 32-bit) or __NR_clock_getres (for 64-bit) is used as default. The 32-bit fallback is used iff __ASSUME_TIME64_SYSCALLS is not defined, which assumes the kernel ABI provides either __NR_rt_sigtimedwait (32-bit time_t). Since the symbol does not use any type which might be affected by the time_t, there is no need to add a 64-bit variant. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- sysdeps/unix/sysv/linux/clock_getcpuclockid.c | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sysdeps/unix/sysv/linux/clock_getcpuclockid.c b/sysdeps/unix/sysv/linux/clock_getcpuclockid.c index be1f477187..7d2e6d6bfe 100644 --- a/sysdeps/unix/sysv/linux/clock_getcpuclockid.c +++ b/sysdeps/unix/sysv/linux/clock_getcpuclockid.c @@ -30,20 +30,25 @@ __clock_getcpuclockid (pid_t pid, clockid_t *clock_id) const clockid_t pidclock = MAKE_PROCESS_CPUCLOCK (pid, CPUCLOCK_SCHED); - int r = INTERNAL_SYSCALL_CALL (clock_getres, pidclock, NULL); - if (!INTERNAL_SYSCALL_ERROR_P (r)) +#ifndef __NR_clock_getres_time64 +# define __NR_clock_getres_time64 __NR_clock_getres +#endif + int r = INTERNAL_SYSCALL_CALL (clock_getres_time64, pidclock, NULL); + +#ifndef __ASSUME_TIME64_SYSCALLS + if (r != 0 && r == -ENOSYS) + r = INTERNAL_SYSCALL_CALL (clock_getres, pidclock, NULL); +#endif + + if (r == 0) { *clock_id = pidclock; return 0; } - - if (INTERNAL_SYSCALL_ERRNO (r) == EINVAL) - { - /* The clock_getres system call checked the PID for us. */ - return ESRCH; - } - else - return INTERNAL_SYSCALL_ERRNO (r); + if (r == -EINVAL) + /* The clock_getres system call checked the PID for us. */ + return ESRCH; + return -r; } versioned_symbol (libc, __clock_getcpuclockid, clock_getcpuclockid, GLIBC_2_17); From patchwork Tue Sep 8 14:57:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=VwxVrNlD; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Z64NyZz9sRK for ; Wed, 9 Sep 2020 00:58:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23A4B39518B5; Tue, 8 Sep 2020 14:57:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23A4B39518B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577076; bh=yI9Kx99hWXRMFMbwgXj6t6i2itCIBDqgK5icHOs4VZg=; 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=VwxVrNlDhhkCXdWLAvMdsbRw4u8BKC8DJyDyet4JAQ+q1skKFuB79y6VYbFrLLkDf CPk160VfbN4Iz1+n5qXNtPGZKetTOy6Ks1/v0abM1VFDq8asLVbrohS7QNzJQzGdTa jVqQxnWh/mTw1Bw7qxzcVtyV5rJogmJ6inpr0iLk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 2D2F13951C4D for ; Tue, 8 Sep 2020 14:57:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2D2F13951C4D Received: by mail-qk1-x744.google.com with SMTP id f2so15566615qkh.3 for ; Tue, 08 Sep 2020 07:57:54 -0700 (PDT) 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=yI9Kx99hWXRMFMbwgXj6t6i2itCIBDqgK5icHOs4VZg=; b=Uz5hwFL0czKfi9Kzuq559IPJA3/tMpyg4kEHHNjyWKdmriH7JV66LWZyEJ75n2A3Uz 8QCyJySTExlBGCXpwfR3cOThFpo6DWOrDp6Bi9ObwZuTTm0QKRMZxcMscvOhsnE+Nhjx GFa+r8w7m6cVibbWMYNIuiSZ/jmQgfjMBlJWr/CBVc7r8LHQD3zDZCM6Cq85TmTHSVHd P4t91MKaxfaEz/G1LZSh6hNsfWOGDVZfWVpHzkW7sN2Py3SjKCu3AEhqYMhaYxyeUA7Y O75hYoaXqU9q/NCay7E63JFmG3DkzrlRDUARi/ySMaqbPT1K5nq94pw2oxuO+vQPssYG U0fQ== X-Gm-Message-State: AOAM5303ANcUYPfkCi8BG9J+dJh92gJxZKQjRTZi6cl4S7q3s0VrV93F WqWofVnLDTUU1969UT6afl2aIHcK76CkXw== X-Google-Smtp-Source: ABdhPJzQ3DQP9/1hn+R3+tFnFVy/4lVZbn7/6ScDbOfG2r6mgCiALju7JaifMfD16flE39lu9oaBXA== X-Received: by 2002:a37:9a0b:: with SMTP id c11mr464405qke.310.1599577072973; Tue, 08 Sep 2020 07:57:52 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:52 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 08/14] linux: Consolidate utimes Date: Tue, 8 Sep 2020 11:57:32 -0300 Message-Id: <20200908145738.640039-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The generic version does not have time64 support and Linux default uses utimensat. With hppa version gone, __ASSUME_UTIMES is not used anymore. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- sysdeps/unix/sysv/linux/generic/utimes.c | 46 ------------------- .../unix/sysv/linux/hppa/kernel-features.h | 5 -- sysdeps/unix/sysv/linux/hppa/utimes.c | 30 ------------ 3 files changed, 81 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/generic/utimes.c delete mode 100644 sysdeps/unix/sysv/linux/hppa/utimes.c diff --git a/sysdeps/unix/sysv/linux/generic/utimes.c b/sysdeps/unix/sysv/linux/generic/utimes.c deleted file mode 100644 index 0a8100e1b8..0000000000 --- a/sysdeps/unix/sysv/linux/generic/utimes.c +++ /dev/null @@ -1,46 +0,0 @@ -/* utimes -- Change access and modification times of file. Linux version. - Copyright (C) 2011-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Chris Metcalf , 2011. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include -#include -#include -#include -#include -#include - - -/* Change the access time of FILE to TVP[0] and - the modification time of FILE to TVP[1]. */ -int -__utimes (const char *file, const struct timeval tvp[2]) -{ - struct timespec ts[2]; - struct timespec *tsp = NULL; - - if (tvp) - { - TIMEVAL_TO_TIMESPEC (&tvp[0], &ts[0]); - TIMEVAL_TO_TIMESPEC (&tvp[1], &ts[1]); - tsp = &ts[0]; - } - - return INLINE_SYSCALL (utimensat, 4, AT_FDCWD, file, tsp, 0); -} - -weak_alias (__utimes, utimes) diff --git a/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/sysdeps/unix/sysv/linux/hppa/kernel-features.h index 8548b5c258..80eec02314 100644 --- a/sysdeps/unix/sysv/linux/hppa/kernel-features.h +++ b/sysdeps/unix/sysv/linux/hppa/kernel-features.h @@ -18,11 +18,6 @@ . */ -/* Support for the utimes syscall was added in 3.14. */ -#if __LINUX_KERNEL_VERSION >= 0x030e00 -# define __ASSUME_UTIMES 1 -#endif - #include_next #define __ASSUME_RECV_SYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/hppa/utimes.c b/sysdeps/unix/sysv/linux/hppa/utimes.c deleted file mode 100644 index a9c4a7ff45..0000000000 --- a/sysdeps/unix/sysv/linux/hppa/utimes.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Implement utimes for hppa. - Copyright (C) 2014-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* hppa has the utimensat syscall in all supported kernel versions but - gained the utimes syscall later, so use the linux-generic - implementation of utimes in terms of the utimensat syscall unless - the utimes syscall is known to be available. */ - -#include - -#ifdef __ASSUME_UTIMES -# include -#else -# include -#endif From patchwork Tue Sep 8 14:57:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ypYxIpHU; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7ZB6Vm8z9sRK for ; Wed, 9 Sep 2020 00:58:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB9483951C74; Tue, 8 Sep 2020 14:57:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB9483951C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577078; bh=LjOs+r7ahGq6YbOu7ikQSozkpBxBC7ntObxSYtFQ+EQ=; 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=ypYxIpHU5HCJ65oK7oHcEKgh/3bQIN58EezdRQG/PAEsF6RfrwlKom0GKBG143wWc Cblwtr6kQ1gVwPkzteYEDmVqW7rM6q0Po7MJrgk6yf9unEAL27UOV4kGcsuajCJfpH PlcZ93VsYZ9qqNtzCtJ6n8lf1HwxUXOgiPoVNY2M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id 23E0A3951C4D for ; Tue, 8 Sep 2020 14:57:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 23E0A3951C4D Received: by mail-qk1-x742.google.com with SMTP id w16so15538716qkj.7 for ; Tue, 08 Sep 2020 07:57:56 -0700 (PDT) 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=LjOs+r7ahGq6YbOu7ikQSozkpBxBC7ntObxSYtFQ+EQ=; b=cYufXgc0PhAVNRMlR1pQWX1adM3QIeaEnP3KCXVB7qSbB07PqeCrkZ7VD0P66btQjW dklDCrXfb63uaD3iXc7/C1VuxozuKqivtBph4qMztc2XK+CUHBTTO0GMhmXFzTcV9O0r dmR3uOXeQMKnnZSXUBi1sdLJaNzoam7eqLvyj1IT/460Fgj+J5wHlIrHxJ/HQKa17P/T RcnUy2WzVMp4tkbKbQRPXxvZUL+GHKnsZfL6ZJvPzkLIu2L8pKQGNinPUlNYEYyR4FcU c1oqi9BW/J+vY8i2pOjXEVcSP8Dpi+bWuQhHdpTeyuFkViTr2sCpPYMZkCw9EdLcZxX2 GqzQ== X-Gm-Message-State: AOAM531ZrUe3zO+Zjtt8F+3SXvqOgt/xc3GpK887zBsEzi5E/81Wila8 J8gu4m2HRHa+PWIcmMFw+9qe9jyYZTBKwQ== X-Google-Smtp-Source: ABdhPJxR48tXttbpkXo3v5Nu0Ly1dUvzjBxHLpmcIclIZNAcmz9opPyBZx/3gJSzrHo0eILqZwRVkQ== X-Received: by 2002:a37:ad08:: with SMTP id f8mr411493qkm.207.1599577075143; Tue, 08 Sep 2020 07:57:55 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:54 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 09/14] linux: Fix time64 support for futimesat Date: Tue, 8 Sep 2020 11:57:33 -0300 Message-Id: <20200908145738.640039-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The generic implementation does not support time64 and the default one return overflow for invalid tv_sec with UTIME_NOW / UTIME_OMIT (which is valid since tv_sec in such cases is ignored by the kernel). Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- sysdeps/unix/sysv/linux/generic/futimesat.c | 52 --------------------- sysdeps/unix/sysv/linux/utimensat.c | 8 +++- 2 files changed, 6 insertions(+), 54 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/generic/futimesat.c diff --git a/sysdeps/unix/sysv/linux/generic/futimesat.c b/sysdeps/unix/sysv/linux/generic/futimesat.c deleted file mode 100644 index 7be1fbc252..0000000000 --- a/sysdeps/unix/sysv/linux/generic/futimesat.c +++ /dev/null @@ -1,52 +0,0 @@ -/* futimesat -- Change access and modification times of file. Linux version. - Copyright (C) 2005-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Chris Metcalf , 2011. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Change the access time of FILE relative to FD to TVP[0] and - the modification time of FILE to TVP[1]. */ -int -futimesat (int fd, const char *file, const struct timeval tvp[2]) -{ - struct timespec tsp[2]; - int result; - - if (tvp) - { - if (tvp[0].tv_usec >= 1000000 || tvp[0].tv_usec < 0 - || tvp[1].tv_usec >= 1000000 || tvp[1].tv_usec < 0) - { - __set_errno (EINVAL); - return -1; - } - TIMEVAL_TO_TIMESPEC (&tvp[0], &tsp[0]); - TIMEVAL_TO_TIMESPEC (&tvp[1], &tsp[1]); - } - - result = INLINE_SYSCALL (utimensat, 4, fd, file, tvp ? tsp : NULL, 0); - return result; -} diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c index ea23c2f051..72784d824a 100644 --- a/sysdeps/unix/sysv/linux/utimensat.c +++ b/sysdeps/unix/sysv/linux/utimensat.c @@ -36,9 +36,13 @@ __utimensat64_helper (int fd, const char *file, if (ret == 0 || errno != ENOSYS) return ret; + /* For UTIME_NOW and UTIME_OMIT the value of tv_sec field is ignored. */ +# define NS_VALID(ns) \ + ((((ns).tv_nsec == UTIME_NOW || (ns).tv_nsec == UTIME_OMIT) \ + || in_time_t_range ((ns).tv_sec))) + if (tsp64 != NULL - && (! in_time_t_range (tsp64[0].tv_sec) - || ! in_time_t_range (tsp64[1].tv_sec))) + && (!NS_VALID (tsp64[0]) || !NS_VALID (tsp64[1]))) { __set_errno (EOVERFLOW); return -1; From patchwork Tue Sep 8 14:57:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=wAi2dRBZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7ZH1cqJz9sRK for ; Wed, 9 Sep 2020 00:58:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3AC4A3951C5D; Tue, 8 Sep 2020 14:58:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AC4A3951C5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577081; bh=lSaU4YbJLO/gsn7a8RhXZG2Iek3ApGUkderdDW7XZ3Q=; 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=wAi2dRBZcVUcNXXb9YG2GwY2sBqCz2iOyCpe5p3IJO6ACvHaSnP90xrwXCa8f1TrP JvaCMKQy/KbFIgTkFELeEYbMR8VVWJ1ec3TDYZsiKvSx86SMgwhSRQE/Fnl6OzOLtP /s2lmksc4oxOOOYX1RzzWyFyT3QVXFBCJt4HLDs0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id A51763951C67 for ; Tue, 8 Sep 2020 14:57:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A51763951C67 Received: by mail-qv1-xf41.google.com with SMTP id j10so7920440qvk.11 for ; Tue, 08 Sep 2020 07:57:58 -0700 (PDT) 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=lSaU4YbJLO/gsn7a8RhXZG2Iek3ApGUkderdDW7XZ3Q=; b=GUziPfkJxlcoYxUggBZPOkwEryoDjQP09Dw5BKyexK/zig2g8SgycbT/iVcx7oEbPZ 6XWw1RD8kHcty/73ZHn2xbJYfNMKk0Os7YZUCuasCikLVnBqa4epxlZZYPOg0fjI1rcj g9Piqs5k6wQtgnEA7vJThxPO45zrJ0g83zpJ0s2kNy02M/s8OcbUuFCBkFrr13a3tjUV o+A0oJg/bF+OvpGawkFszZUAbCCGzqmeJHCBRkpMgvKvg3/fFNzXCzMFEHiln2ESuvsK MBfFD0lBJsYzfkQIfK8FyDPY9vjqotlLJEryFhqqiVcBmbEFjHq5jQp0RswzVP5H1Ouj J/WA== X-Gm-Message-State: AOAM533W97r8G31HQIQBzLcpNshHxHoSixIvVYh27suXLTAfCETUzo+e GOXZBr+SypuJ+p7G2WihAhBlsZ1jaO2siA== X-Google-Smtp-Source: ABdhPJxDacQ9dDC9y4zIK3gj3ulk//BmYTlmaMgomvt1GH0PE2DfYd9LGKzELW8aNDoqntS61fyhQA== X-Received: by 2002:a0c:bf0a:: with SMTP id m10mr480412qvi.30.1599577077569; Tue, 08 Sep 2020 07:57:57 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:56 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 10/14] linux: Add time64 support for nanosleep Date: Tue, 8 Sep 2020 11:57:34 -0300 Message-Id: <20200908145738.640039-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It uses __clock_nanosleep64 and adds the __nanosleep64 symbol. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). Reviewed-by: Alistair Francis --- include/time.h | 9 ++++++ sysdeps/unix/sysv/linux/nanosleep.c | 50 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/nanosleep.c diff --git a/include/time.h b/include/time.h index 936486e206..edf6cdf829 100644 --- a/include/time.h +++ b/include/time.h @@ -271,6 +271,15 @@ extern struct tm *__tz_convert (__time64_t timer, int use_localtime, extern int __nanosleep (const struct timespec *__requested_time, struct timespec *__remaining); hidden_proto (__nanosleep) +#if __TIMESIZE == 64 +# define __nanosleep64 __nanosleep +#else +extern int __nanosleep64 (const struct __timespec64 *__requested_time, + struct __timespec64 *__remaining); +hidden_proto (__nanosleep64) +#endif + + extern int __getdate_r (const char *__string, struct tm *__resbufp) attribute_hidden; diff --git a/sysdeps/unix/sysv/linux/nanosleep.c b/sysdeps/unix/sysv/linux/nanosleep.c new file mode 100644 index 0000000000..8f4ee0f744 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nanosleep.c @@ -0,0 +1,50 @@ +/* High-resolution sleep. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +int +__nanosleep64 (const struct __timespec64 *req, struct __timespec64 *rem) +{ + int ret = __clock_nanosleep_time64 (CLOCK_REALTIME, 0, req, rem); + if (ret != 0) + { + __set_errno (ret); + return -1; + } + return 0; +} +#if __TIMESIZE != 64 +libc_hidden_def (__nanosleep64) + +int +__nanosleep (const struct timespec *req, struct timespec *rem) +{ + struct __timespec64 treq64, trem64; + + treq64 = valid_timespec_to_timespec64 (*req); + int ret = __nanosleep64 (&treq64, &trem64); + + if (ret != 0 && errno == EINTR && rem != NULL) + *rem = valid_timespec64_to_timespec (trem64); + return ret; +} +#endif +libc_hidden_def (__nanosleep) +weak_alias (__nanosleep, nanosleep) From patchwork Tue Sep 8 14:57:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=sGgLUau7; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7ZN0Hlcz9sRK for ; Wed, 9 Sep 2020 00:58:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57D4F3952517; Tue, 8 Sep 2020 14:58:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57D4F3952517 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577083; bh=EHsguGR8P9+0Y2TaO3iX2v/qiKUD7DL3dcMqx9FA9ww=; 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=sGgLUau7H6oIZLDqmT7VDDP+QFyRJQ3W7ZFoeadFgz35p4d+z/HOqMzMrPaSZ0Cdm w8UmCRWCQVE+Yj0/ZQ95GLEb2D6bpRRTNzcCe2DmB4FbKLrgB5tD5YY4m+T2YWXrl6 ir6T7yK4PURUIUBiDxTOnLlYjs/6BAIwIKQ0uTT8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 373673951C4D for ; Tue, 8 Sep 2020 14:58:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 373673951C4D Received: by mail-qt1-x843.google.com with SMTP id y11so6020503qtn.9 for ; Tue, 08 Sep 2020 07:58:01 -0700 (PDT) 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=EHsguGR8P9+0Y2TaO3iX2v/qiKUD7DL3dcMqx9FA9ww=; b=nNxoe3KiGP8sGYgQoWCVhvQVJwOrRq39zth72p2hgjSMQlfKfByP6VjXsmG+167S50 XcIPIe0+mogtN/s3sW4VAHvEWzrgyIw1n3ZnIaWgB6ZrFRpDPX2t71+BYaiRPVJEREiH TXLz1Vux0PhxznYLthF4MRlo6ye5AWrEmTrcUZhm8FANpg2wA55RB3SkdXa50CdrBY+4 n/7L6TPnu7c651oduE5Q6VMzB89jQF/QcLngriKtQqN8v8Mm/EQd+fsmg6PclOl8ZzBZ QylDo6PPOHpq6UrhhzoTLM8iyG508UfjfeEX+4nDJ1V6Pusk1bCWgegAWu2rL3ctPZy/ xDCA== X-Gm-Message-State: AOAM531BXlLdSdWp/udC+Izj/6AWkfWNi5Yp++pOsK3BIw/G4QbHscXd pK3X6WsBm5Mqecj/rfm3w04szc/jWoHCvw== X-Google-Smtp-Source: ABdhPJyHu9/LCm+kkmSFX3KBh3HYzpGxF+qqP1ZwuZRq8K9pEzmyXtl5NQGpVYyHxWH4YJ3Ywaudtw== X-Received: by 2002:aed:398a:: with SMTP id m10mr438468qte.143.1599577079282; Tue, 08 Sep 2020 07:57:59 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.57.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:57:58 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 11/14] linux: Add time64 recvmmsg support Date: Tue, 8 Sep 2020 11:57:35 -0300 Message-Id: <20200908145738.640039-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The wire-up syscall __NR_recvmmsg_time64 (for 32-bit) or __NR_recvmmsg (for 64-bit) is used as default. The 32-bit fallback is used iff __ASSUME_TIME64_SYSCALLS is not defined, which assumes the kernel ABI provides either __NR_socketcall or __NR_recvmmsg (32-bit time_t). It does not handle the timestamps on ancillary data (SCM_TIMESTAMPING records). Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Alistair Francis --- include/sys/socket.h | 8 ++++ sysdeps/unix/sysv/linux/recvmmsg.c | 63 ++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index 26db0e0d77..0e39dd2a3a 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -104,6 +104,14 @@ extern ssize_t __libc_recvmsg (int __fd, struct msghdr *__message, int __flags); extern ssize_t __recvmsg (int __fd, struct msghdr *__message, int __flags) attribute_hidden; +#if __TIMESIZE == 64 +# define __recvmmsg64 __recvmmsg +#else +extern int __recvmmsg64 (int __fd, struct mmsghdr *vmessages, + unsigned int vlen, int flags, + struct __timespec64 *timeout); +libc_hidden_proto (__recvmmsg64) +#endif /* Set socket FD's option OPTNAME at protocol level LEVEL to *OPTVAL (which is OPTLEN bytes long). diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c index 42c80c59c3..a29c91fb76 100644 --- a/sysdeps/unix/sysv/linux/recvmmsg.c +++ b/sysdeps/unix/sysv/linux/recvmmsg.c @@ -16,21 +16,62 @@ License along with the GNU C Library; if not, see . */ -#include #include - -#include -#include +#include #include -#include int -recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, - struct timespec *tmo) +__recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, + struct __timespec64 *timeout) { -#ifdef __ASSUME_RECVMMSG_SYSCALL - return SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, tmo); -#else - return SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, tmo); +#ifndef __NR_recvmmsg_time64 +# define __NR_recvmmsg_time64 __NR_recvmmsg #endif + int r = SYSCALL_CANCEL (recvmmsg_time64, fd, vmessages, vlen, flags, + timeout); +#ifndef __ASSUME_TIME64_SYSCALLS + if (r >= 0 || errno != ENOSYS) + return r; + + struct timespec ts32, *pts32 = NULL; + if (timeout != NULL) + { + if (! in_time_t_range (timeout->tv_sec)) + { + __set_errno (EINVAL); + return -1; + } + ts32 = valid_timespec64_to_timespec (*timeout); + pts32 = &ts32; + } +# 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); +#endif /* __ASSUME_TIME64_SYSCALLS */ + return r; } +#if __TIMESIZE != 64 +libc_hidden_def (__recvmmsg64) + +int +__recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, + struct timespec *timeout) +{ + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) + { + ts64 = valid_timespec_to_timespec64 (*timeout); + pts64 = &ts64; + } + int r = __recvmmsg64 (fd, vmessages, vlen, flags, pts64); + if (r >= 0) + /* The remanining timeout will be always less the input TIMEOUT. */ + *timeout = valid_timespec64_to_timespec (ts64); + return r; +} +#endif +weak_alias (__recvmmsg, recvmmsg) From patchwork Tue Sep 8 14:57:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=cwrlqM+q; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7ZS0j6mz9sRK for ; Wed, 9 Sep 2020 00:58:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFE1839518B4; Tue, 8 Sep 2020 14:58:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFE1839518B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577085; bh=hd4R9Ey7VEkEAY4U6BpjGA6Hz+uYun5WyCNFQZQQInY=; 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=cwrlqM+qWlL+ZzZWg5TfpgkAYOi0SGSfg7TR6tprgclH/TvvlobPQd6DvM526Sqei OBiy5RrQHaCG3Whqxu8c6ZmSQcM7MkAfxdXWRDtdVvxkIjloopqupOrwJ22QlyEU8M fvidOzJew87eI/KPEfcQJ7tbxqQt8I/sTRg7NtsU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 9D42B39518B8 for ; Tue, 8 Sep 2020 14:58:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D42B39518B8 Received: by mail-qt1-x843.google.com with SMTP id n18so12139500qtw.0 for ; Tue, 08 Sep 2020 07:58:02 -0700 (PDT) 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=hd4R9Ey7VEkEAY4U6BpjGA6Hz+uYun5WyCNFQZQQInY=; b=iJHFKrr1F/acRGSf9KFIbIbpHOYxBKDWNN6E5cu5p7S/gtbHcMksgPqB/OFxpvgFnO RgxbAW5qZzgc037+S166L70lk7zWsD4MqSFSSWNdZ8GoEYYoVwK8V3RjRqpB1uEALl1n LZbFaWEjVTpWoC6zveVofgk3Lr7R8krfZBAB7mTTuasxEBL9v99hE0n8Rzh5jfkv+dzn kpj28IEAJJDBQJyzxmf5JaZQbmWbu3NajCR7UVObrceHX8uC7j3p16f+W4KWxFvVamSx fcP+wRUrAKVwTLZjQm2COAaVJIp6e9KZ7f4ltoU6SQ45JRvf0UWd9IpVm3wR/JBU9ryq iStA== X-Gm-Message-State: AOAM533WUfDOHHEYI4s/ks9vlZzhorgXwHUhI6JZsOJJOj0Ja/x859jc 7nApKYAwPevpn5omsC9KjGBqhwHqjpBtOg== X-Google-Smtp-Source: ABdhPJwTGBlo+iVOZDmhI2jq2+nXo7JzUhoIl0tgnXxtdLRna8FQq715MZtBoAHluDWXKpC6hQ8M2A== X-Received: by 2002:ac8:f04:: with SMTP id e4mr441645qtk.342.1599577081002; Tue, 08 Sep 2020 07:58:01 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.58.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:58:00 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [RFC 12/14] linux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO Date: Tue, 8 Sep 2020 11:57:36 -0300 Message-Id: <20200908145738.640039-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The constant value will be changed for __TIMESIZE=64, so binaries built with 64-bit time support might fail to work properly on old kernels. Both {get,set}sockopt will retry the syscall with the old constant values and the timeout value adjusted when kernel returns ENOTPROTOPT. It also changes to SO_{RCV,SND}TIMEO to follow the uapi kernel values where SO_{RCV,SND}TIMEO_OLD indicates pre 64-bit time support and SO_{RCV,SND}TIMEO_NEW indicate time64 support. It allows to refer to constant independently of the time_t abi used (since kernel defines SO_{RCV,SND}TIMEO depending of the time_t size). The hppa, mips, powerpc, and sparc provides its own socket-constant.h, which are also updated the the SO_{RCV,SND}TIMEO constants (they are missed on 019d828669df966 patch). Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- .../unix/sysv/linux/bits/socket-constants.h | 19 ++--- sysdeps/unix/sysv/linux/getsockopt.c | 72 ++++++++++++++++-- .../sysv/linux/hppa/bits/socket-constants.h | 15 +++- .../sysv/linux/mips/bits/socket-constants.h | 17 ++++- .../linux/powerpc/bits/socket-constants.h | 19 ++++- sysdeps/unix/sysv/linux/setsockopt.c | 76 +++++++++++++++++-- .../sysv/linux/sparc/bits/socket-constants.h | 17 ++++- 7 files changed, 202 insertions(+), 33 deletions(-) diff --git a/sysdeps/unix/sysv/linux/bits/socket-constants.h b/sysdeps/unix/sysv/linux/bits/socket-constants.h index d02e1cbc7c..c7478651fb 100644 --- a/sysdeps/unix/sysv/linux/bits/socket-constants.h +++ b/sysdeps/unix/sysv/linux/bits/socket-constants.h @@ -32,19 +32,20 @@ #define SO_OOBINLINE 10 #define SO_RCVBUF 8 #define SO_RCVLOWAT 18 -#if (__TIMESIZE == 64 && __WORDSIZE == 32 \ - && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) -# define SO_RCVTIMEO 66 -#else -# define SO_RCVTIMEO 20 -#endif #define SO_REUSEADDR 2 #define SO_SNDBUF 7 #define SO_SNDLOWAT 19 +#define SO_TYPE 3 + +#define SO_RCVTIMEO_OLD 20 +#define SO_SNDTIMEO_OLD 21 +#define SO_RCVTIMEO_NEW 66 +#define SO_SNDTIMEO_NEW 67 #if (__TIMESIZE == 64 && __WORDSIZE == 32 \ && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) -# define SO_SNDTIMEO 67 +# define SO_RCVTIMEO SO_RCVTIMEO_NEW +# define SO_SNDTIMEO SO_SNDTIMEO_NEW #else -# define SO_SNDTIMEO 21 +# define SO_RCVTIMEO SO_RCVTIMEO_OLD +# define SO_SNDTIMEO SO_SNDTIMEO_OLD #endif -#define SO_TYPE 3 diff --git a/sysdeps/unix/sysv/linux/getsockopt.c b/sysdeps/unix/sysv/linux/getsockopt.c index 11939660c1..5dce0e29ee 100644 --- a/sysdeps/unix/sysv/linux/getsockopt.c +++ b/sysdeps/unix/sysv/linux/getsockopt.c @@ -15,16 +15,20 @@ License along with the GNU C Library; if not, see . */ -#include -#include #include - +/* The kernel header with SO_* constants is used as default for _GNU_SOURCE, + however the new constants that describe 64-bit time support were added + only on v5.1. */ +#if !defined(SO_RCVTIMEO_NEW) || !defined(SO_RCVTIMEO_OLD) +# include +#endif +#include +#include #include -#include -#include -int -__getsockopt (int fd, int level, int optname, void *optval, socklen_t *len) +static int +getsockopt_syscall (int fd, int level, int optname, void *optval, + socklen_t *len) { #ifdef __ASSUME_GETSOCKOPT_SYSCALL return INLINE_SYSCALL (getsockopt, 5, fd, level, optname, optval, len); @@ -32,4 +36,58 @@ __getsockopt (int fd, int level, int optname, void *optval, socklen_t *len) return SOCKETCALL (getsockopt, fd, level, optname, optval, len); #endif } + +#ifndef __ASSUME_TIME64_SYSCALLS +static int +getsockopt32 (int fd, int level, int optname, void *optval, + socklen_t *len) +{ + int r = -1; + + if (level != SOL_SOCKET) + return r; + + switch (optname) + { + case SO_RCVTIMEO_NEW: + case SO_SNDTIMEO_NEW: + { + if (*len < sizeof (struct __timeval64)) + { + __set_errno (EINVAL); + break; + } + + if (optname == SO_RCVTIMEO_NEW) + optname = SO_RCVTIMEO_OLD; + if (optname == SO_SNDTIMEO_NEW) + optname = SO_SNDTIMEO_OLD; + + struct __timeval32 tv32; + r = getsockopt_syscall (fd, level, optname, &tv32, + (socklen_t[]) { sizeof tv32 }); + if (r < 0) + break; + struct __timeval64 *tv64 = (struct __timeval64 *) optval; + *tv64 = valid_timeval32_to_timeval64 (tv32); + *len = sizeof (*tv64); + } + } + + return r; +} +#endif + +int +__getsockopt (int fd, int level, int optname, void *optval, socklen_t *len) +{ + int r = getsockopt_syscall (fd, level, optname, optval, len); + +#ifndef __ASSUME_TIME64_SYSCALLS + if (r == -1 && errno == ENOPROTOOPT) + r = getsockopt32 (fd, level, optname, optval, len); +#endif + + return r; +} weak_alias (__getsockopt, getsockopt) diff --git a/sysdeps/unix/sysv/linux/hppa/bits/socket-constants.h b/sysdeps/unix/sysv/linux/hppa/bits/socket-constants.h index fda7f95d44..eca5fe045c 100644 --- a/sysdeps/unix/sysv/linux/hppa/bits/socket-constants.h +++ b/sysdeps/unix/sysv/linux/hppa/bits/socket-constants.h @@ -30,9 +30,20 @@ #define SO_OOBINLINE 256 #define SO_RCVBUF 4098 #define SO_RCVLOWAT 4100 -#define SO_RCVTIMEO 4102 #define SO_REUSEADDR 4 #define SO_SNDBUF 4097 #define SO_SNDLOWAT 4099 -#define SO_SNDTIMEO 4101 #define SO_TYPE 4104 + +#define SO_RCVTIMEO_OLD 4102 +#define SO_SNDTIMEO_OLD 4101 +#define SO_RCVTIMEO_NEW 16448 +#define SO_SNDTIMEO_NEW 16449 +#if (__TIMESIZE == 64 && __WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define SO_RCVTIMEO SO_RCVTIMEO_NEW +# define SO_SNDTIMEO SO_SNDTIMEO_NEW +#else +# define SO_RCVTIMEO SO_RCVTIMEO_OLD +# define SO_SNDTIMEO SO_SNDTIMEO_OLD +#endif diff --git a/sysdeps/unix/sysv/linux/mips/bits/socket-constants.h b/sysdeps/unix/sysv/linux/mips/bits/socket-constants.h index daa47c6c7c..961fad21b8 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/socket-constants.h +++ b/sysdeps/unix/sysv/linux/mips/bits/socket-constants.h @@ -20,6 +20,8 @@ # error "Never include directly; use instead." #endif +#include + #define SOL_SOCKET 65535 #define SO_ACCEPTCONN 4105 #define SO_BROADCAST 32 @@ -30,9 +32,20 @@ #define SO_OOBINLINE 256 #define SO_RCVBUF 4098 #define SO_RCVLOWAT 4100 -#define SO_RCVTIMEO 4102 #define SO_REUSEADDR 4 #define SO_SNDBUF 4097 #define SO_SNDLOWAT 4099 -#define SO_SNDTIMEO 4101 #define SO_TYPE 4104 + +#define SO_RCVTIMEO_OLD 4100 +#define SO_SNDTIMEO_OLD 4101 +#define SO_RCVTIMEO_NEW 66 +#define SO_SNDTIMEO_NEW 67 +#if (__TIMESIZE == 64 && __WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define SO_RCVTIMEO SO_RCVTIMEO_NEW +# define SO_SNDTIMEO SO_SNDTIMEO_NEW +#else +# define SO_RCVTIMEO SO_RCVTIMEO_OLD +# define SO_SNDTIMEO SO_SNDTIMEO_OLD +#endif diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/socket-constants.h b/sysdeps/unix/sysv/linux/powerpc/bits/socket-constants.h index 77fc8b207e..d0ec3cb4fc 100644 --- a/sysdeps/unix/sysv/linux/powerpc/bits/socket-constants.h +++ b/sysdeps/unix/sysv/linux/powerpc/bits/socket-constants.h @@ -20,6 +20,8 @@ # error "Never include directly; use instead." #endif +#include + #define SOL_SOCKET 1 #define SO_ACCEPTCONN 30 #define SO_BROADCAST 6 @@ -30,9 +32,20 @@ #define SO_OOBINLINE 10 #define SO_RCVBUF 8 #define SO_RCVLOWAT 16 -#define SO_RCVTIMEO 18 #define SO_REUSEADDR 2 #define SO_SNDBUF 7 -#define SO_SNDLOWAT 17 -#define SO_SNDTIMEO 19 +#define SO_SNDTIMEO 67 #define SO_TYPE 3 + +#define SO_RCVTIMEO_OLD 18 +#define SO_SNDTIMEO_OLD 19 +#define SO_RCVTIMEO_NEW 66 +#define SO_SNDTIMEO_NEW 67 +#if (__TIMESIZE == 64 && __WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define SO_RCVTIMEO SO_RCVTIMEO_NEW +# define SO_SNDTIMEO SO_SNDTIMEO_NEW +#else +# define SO_RCVTIMEO SO_RCVTIMEO_OLD +# define SO_SNDTIMEO SO_SNDTIMEO_OLD +#endif diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c index 20c0868783..ebc32d788c 100644 --- a/sysdeps/unix/sysv/linux/setsockopt.c +++ b/sysdeps/unix/sysv/linux/setsockopt.c @@ -15,21 +15,81 @@ License along with the GNU C Library; if not, see . */ -#include -#include #include - +/* The kernel header with SO_* constants is used as default for _GNU_SOURCE, + however the new constants that describe 64-bit time support were added + only on v5.1. */ +#if !defined(SO_RCVTIMEO_NEW) || !defined(SO_RCVTIMEO_OLD) +# include +#endif +#include +#include #include -#include -#include -int -setsockopt (int fd, int level, int optname, const void *optval, socklen_t len) +static int +setsockopt_syscall (int fd, int level, int optname, const void *optval, + socklen_t len) { #ifdef __ASSUME_SETSOCKOPT_SYSCALL - return INLINE_SYSCALL (setsockopt, 5, fd, level, optname, optval, len); + return INLINE_SYSCALL_CALL (setsockopt, fd, level, optname, optval, len); #else return SOCKETCALL (setsockopt, fd, level, optname, optval, len); #endif } + +#ifndef __ASSUME_TIME64_SYSCALLS +static int +setsockopt32 (int fd, int level, int optname, const void *optval, + socklen_t len) +{ + int r = -1; + + if (level != SOL_SOCKET) + return r; + + switch (optname) + { + case SO_RCVTIMEO_NEW: + case SO_SNDTIMEO_NEW: + { + if (len < sizeof (struct __timeval64)) + { + __set_errno (EINVAL); + break; + } + + struct __timeval64 *tv64 = (struct __timeval64 *) optval; + if (! in_time_t_range (tv64->tv_sec)) + { + __set_errno (EOVERFLOW); + break; + } + + if (optname == SO_RCVTIMEO_NEW) + optname = SO_RCVTIMEO_OLD; + if (optname == SO_SNDTIMEO_NEW) + optname = SO_SNDTIMEO_OLD; + + struct __timeval32 tv32 = valid_timeval64_to_timeval32 (*tv64); + + r = setsockopt_syscall (fd, level, optname, &tv32, sizeof (tv32)); + } + } + + return r; +} +#endif + +int +setsockopt (int fd, int level, int optname, const void *optval, socklen_t len) +{ + int r = setsockopt_syscall (fd, level, optname, optval, len); + +#ifndef __ASSUME_TIME64_SYSCALLS + if (r == -1 && errno == ENOPROTOOPT) + r = setsockopt32 (fd, level, optname, optval, len); +#endif + + return r; +} weak_alias (setsockopt, __setsockopt) diff --git a/sysdeps/unix/sysv/linux/sparc/bits/socket-constants.h b/sysdeps/unix/sysv/linux/sparc/bits/socket-constants.h index 6ef575e521..d4bf8f79d6 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/socket-constants.h +++ b/sysdeps/unix/sysv/linux/sparc/bits/socket-constants.h @@ -20,6 +20,8 @@ # error "Never include directly; use instead." #endif +#include + #define SOL_SOCKET 65535 #define SO_ACCEPTCONN 32768 #define SO_BROADCAST 32 @@ -30,9 +32,20 @@ #define SO_OOBINLINE 256 #define SO_RCVBUF 4098 #define SO_RCVLOWAT 2048 -#define SO_RCVTIMEO 8192 #define SO_REUSEADDR 4 #define SO_SNDBUF 4097 #define SO_SNDLOWAT 4096 -#define SO_SNDTIMEO 16384 #define SO_TYPE 4104 + +#define SO_RCVTIMEO_OLD 8192 +#define SO_SNDTIMEO_OLD 16384 +#define SO_RCVTIMEO_NEW 68 +#define SO_SNDTIMEO_NEW 69 +#if (__TIMESIZE == 64 && __WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define SO_RCVTIMEO SO_RCVTIMEO_NEW +# define SO_SNDTIMEO SO_SNDTIMEO_NEW +#else +# define SO_RCVTIMEO SO_RCVTIMEO_OLD +# define SO_SNDTIMEO SO_SNDTIMEO_OLD +#endif From patchwork Tue Sep 8 14:57:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Lo0kGyyA; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7ZX4Mfsz9sRK for ; Wed, 9 Sep 2020 00:58:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FA7B3952DBB; Tue, 8 Sep 2020 14:58:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FA7B3952DBB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577086; bh=de6p5TdJYmEXV9hD8taCyUz4DnNGv6mCD1HLGTH3jfc=; 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=Lo0kGyyAwBeFPph4YI4QPJxQy/OFOXjSRERy4YDTBsa5FqjwS65yVL3sLtva+LncZ jecD9Y9aCjCxPDwKXs2e+hVrJz0lEd3nvpRsRknpy1hniVjiAxJUsGIbpD3uZQEDxA Nv8owrssD2eXdHuT85XnTE4Sq52AOaw+wrCrYJj8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id 50D3D39518B4 for ; Tue, 8 Sep 2020 14:58:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 50D3D39518B4 Received: by mail-qk1-x741.google.com with SMTP id w186so15579976qkd.1 for ; Tue, 08 Sep 2020 07:58:04 -0700 (PDT) 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=de6p5TdJYmEXV9hD8taCyUz4DnNGv6mCD1HLGTH3jfc=; b=MXTr9yjQRO3pIxcdS/nGdEYdalPdU/d4hFsl2tKkC5lN41k3t5YwvRdYSom6XAsL9h /Lc9PWkJP6Sf/8dfZP+iM2iikrb2v8Kx8YJYbZCI2saUnHiYfImJ1BFbHUaAV+wNKCQe ihUE9m7Ke9kYg7Ci2CUO72t/UR65bCF6+BLRrqRhw7bEXOaUP38Vl3lJpX97SPKKF3LS EiOmDicIbOLVJZRCYwPuTe9LnP/LTN42wCNXMoQnp5IF2wmOUkae64glC3CNAUtz7kOm k9hynmaIZQulEqEwQKplWjlg5IpLMbOsZVjg0GceKIovHDF84NbcIrwoOwcmN/VpcIyf xZtg== X-Gm-Message-State: AOAM533OifzuBV2XxQHOPpYT1FEzq1A9s3P2YDp6cuwOTYbJwthwG6zp xFu7+J9IFGSvCiqsX3SqRDTN/SenZY+oEg== X-Google-Smtp-Source: ABdhPJxjAgeYVexRE7LZyTdaJaapv+j0ktmVnXaoME1SqTcrGxd01UQIhXWcUQhp4/VZ1bhCNM/B4A== X-Received: by 2002:a37:7182:: with SMTP id m124mr417968qkc.37.1599577083246; Tue, 08 Sep 2020 07:58:03 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:58:02 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [RFC 13/14] linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS} Date: Tue, 8 Sep 2020 11:57:37 -0300 Message-Id: <20200908145738.640039-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The constant value will be changed for __TIMESIZE=64, so binaries built with 64-bit time support might fail to work properly on old kernels. Both {get,set}sockopt will retry the syscall with the old constant values and the timeout value adjusted when kernel returns ENOTPROTOPT. The recvmsg handling is more complicated because it requires check the returned kernel control message and make some convertions. 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. Calls with __TIMESIZE=32 will see the converted 64-bit time control messages as spurious control message of unknown type. Calls with __TIMESIZE=64 running on pre-time64 kernels will see the original message as a spurious control ones of unknown typ while running on kernel with native 64-bit time support will only see the time64 version of the control message. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- include/sys/socket.h | 9 +++ sysdeps/unix/sysv/linux/getsockopt.c | 12 ++++ sysdeps/unix/sysv/linux/recvmsg.c | 93 ++++++++++++++++++++++++++-- sysdeps/unix/sysv/linux/setsockopt.c | 12 ++++ 4 files changed, 121 insertions(+), 5 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index 0e39dd2a3a..c551c8fa87 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -162,6 +162,15 @@ libc_hidden_proto (__libc_sa_len) # define SA_LEN(_x) __libc_sa_len((_x)->sa_family) #endif +/* Used on y2038 emulation on 64-bit time_t binaries running on older + kernel without 64-bit time_t support. */ +#define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD +#define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD +#define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD +#define SCM_TIMESTAMP_NEW SO_TIMESTAMP_NEW +#define SCM_TIMESTAMPNS_NEW SO_TIMESTAMPNS_NEW +#define SCM_TIMESTAMPING_NEW SO_TIMESTAMPING_NEW + libc_hidden_proto (__cmsg_nxthdr) #endif diff --git a/sysdeps/unix/sysv/linux/getsockopt.c b/sysdeps/unix/sysv/linux/getsockopt.c index 5dce0e29ee..0089a177b6 100644 --- a/sysdeps/unix/sysv/linux/getsockopt.c +++ b/sysdeps/unix/sysv/linux/getsockopt.c @@ -72,6 +72,18 @@ getsockopt32 (int fd, int level, int optname, void *optval, *tv64 = valid_timeval32_to_timeval64 (tv32); *len = sizeof (*tv64); } + break; + + case SO_TIMESTAMP_NEW: + case SO_TIMESTAMPNS_NEW: + { + if (optname == SO_TIMESTAMP_NEW) + optname = SO_TIMESTAMP_OLD; + if (optname == SO_TIMESTAMPNS_NEW) + optname = SO_TIMESTAMPNS_OLD; + r = getsockopt_syscall (fd, level, optname, optval, len); + } + break; } return r; diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c index a86d502922..c6d1d10b05 100644 --- a/sysdeps/unix/sysv/linux/recvmsg.c +++ b/sysdeps/unix/sysv/linux/recvmsg.c @@ -21,14 +21,97 @@ #include #include +#ifndef __ASSUME_TIME64_SYSCALLS +/* It converts the first SO_TIMESTAMP or SO_TIMESTAMPNS with 32-bit time and + appends it to the control buffer. The 32-bit time field is kept as-is. + + Calls with __TIMESIZE=32 will see the converted 64-bit time control + messages as spurious control message of unknown type. + + Calls with __TIMESIZE=64 running on pre-time64 kernels will see the + original message as a spurious control ones of unknown typ while running + on kernel with native 64-bit time support will only see the time64 version + of the control message. */ +static void +convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) +{ + if (msg->msg_control == NULL || msg->msg_controllen == 0) + return; + + /* The returnted control message format for SO_TIMESTAMP_NEW is a + 'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a + 'struct __kernel_timespec'. In both case it is essentially two + uint64_t members. */ + uint64_t tvts[2]; + + struct cmsghdr *cmsg, *last = NULL; + int type = 0; + + for (cmsg = CMSG_FIRSTHDR (msg); + cmsg != NULL; + cmsg = CMSG_NXTHDR (msg, cmsg)) + { + if (cmsg->cmsg_level != SOL_SOCKET) + continue; + + switch (cmsg->cmsg_type) + { + case SCM_TIMESTAMP_OLD: + if (type != 0) + break; + type = SCM_TIMESTAMP_NEW; + goto common; + + case SCM_TIMESTAMPNS_OLD: + type = SCM_TIMESTAMPNS_NEW; + + /* fallthrough */ + common: + memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts)); + break; + } + + last = cmsg; + } + + if (last == NULL || type == 0) + return; + + if (CMSG_SPACE (sizeof tvts) > msgsize - msg->msg_controllen) + { + msg->msg_flags |= MSG_CTRUNC; + return; + } + + msg->msg_controllen += CMSG_SPACE (sizeof tvts); + cmsg = CMSG_NXTHDR(msg, last); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = type; + cmsg->cmsg_len = CMSG_LEN (sizeof tvts); + memcpy (CMSG_DATA (cmsg), tvts, sizeof tvts); +} +#endif + ssize_t __libc_recvmsg (int fd, struct msghdr *msg, int flags) { -# ifdef __ASSUME_RECVMSG_SYSCALL - return SYSCALL_CANCEL (recvmsg, fd, msg, flags); -# else - return SOCKETCALL_CANCEL (recvmsg, fd, msg, flags); -# endif + ssize_t r; +#ifndef __ASSUME_TIME64_SYSCALLS + socklen_t orig_controllen = msg->msg_controllen; +#endif + +#ifdef __ASSUME_RECVMSG_SYSCALL + r = SYSCALL_CANCEL (recvmsg, fd, msg, flags); +#else + r = SOCKETCALL_CANCEL (recvmsg, fd, msg, flags); +#endif + +#ifndef __ASSUME_TIME64_SYSCALLS + if (r >= 0) + convert_scm_timestamps (msg, orig_controllen); +#endif + + return r; } weak_alias (__libc_recvmsg, recvmsg) weak_alias (__libc_recvmsg, __recvmsg) diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c index ebc32d788c..6aabe8bbde 100644 --- a/sysdeps/unix/sysv/linux/setsockopt.c +++ b/sysdeps/unix/sysv/linux/setsockopt.c @@ -74,6 +74,18 @@ setsockopt32 (int fd, int level, int optname, const void *optval, r = setsockopt_syscall (fd, level, optname, &tv32, sizeof (tv32)); } + break; + + case SO_TIMESTAMP_NEW: + case SO_TIMESTAMPNS_NEW: + { + if (optname == SO_TIMESTAMP_NEW) + optname = SO_TIMESTAMP_OLD; + if (optname == SO_TIMESTAMPNS_NEW) + optname = SO_TIMESTAMPNS_OLD; + r = setsockopt_syscall (fd, level, optname, NULL, 0); + } + break; } return r; From patchwork Tue Sep 8 14:57:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1359778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=DQ793HMF; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm7Zd1c9Wz9sRK for ; Wed, 9 Sep 2020 00:58:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70B7739518B8; Tue, 8 Sep 2020 14:58:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70B7739518B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577087; bh=r2pGEFiLQAIX8Ms8hii/Q13lFfm//DnkGt0JbQUavzY=; 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=DQ793HMF0RsU/jUcnV8krZoZa4RwhHh9MU8W0/GyQUZ1vNxGWrcI+zOztdddcJ3UU 5a7eLbdNiMNTHe2kjz9Le/VG7d4eHxvx/AE3FQJuzwdTb0wG1NYBqcTCgMCwbzvNYN xmuhUIUtzTmn4K6XZ1XBgxICCz31jCOyiFQptVnE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id 70C173951C3A for ; Tue, 8 Sep 2020 14:58:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 70C173951C3A Received: by mail-qv1-xf41.google.com with SMTP id j3so7934745qvi.7 for ; Tue, 08 Sep 2020 07:58:05 -0700 (PDT) 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=r2pGEFiLQAIX8Ms8hii/Q13lFfm//DnkGt0JbQUavzY=; b=p70eShUZTdYt8SDc3swjnLcNzbkLHR/GyOfQecepLd9jIgRadPPass3V9LTrGLLmJa wGqUg6dsck5JOP0uif6vmX/b3EHqjPws2dV20wMY7eR5sd6eEa1hDg+/F9spA1yWsA7X hoOcGkAvBAiCza4qFVIPMY150Wa1QRcHzAYiGHRr0zLbEzazpInMuqx7a7WZRLmV9m8B 8qFj1psf966PS8nlt5WXVp8o+eGfUBI6uQf1NwYCsz7uKcY5RNv3/EDjXU8DXg8Tt+Wx bonkAwNuiQEAX0pnCaRNewEbOu3tJEBMTEGduziyV8i8RmP+K9SQKBAjlrCnXR7JrHK6 w45Q== X-Gm-Message-State: AOAM530aUBa1YeDLuFtyoB0fcGgqwXP0BHz9R7DMD6zAA704LJyFb0Uh GKszKHcmekOjR1xdJ6BO4am6H5wFNRbMKQ== X-Google-Smtp-Source: ABdhPJxIWcUZwK88AGSrLXiQ4bpsmZ34C815KFCkSZD71lF5uYmRxrgux+KRtWG9b0YD6ik4kTas7w== X-Received: by 2002:a0c:eeca:: with SMTP id h10mr464545qvs.13.1599577084789; Tue, 08 Sep 2020 07:58:04 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.58.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:58:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [RFC 14/14] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS} Date: Tue, 8 Sep 2020 11:57:38 -0300 Message-Id: <20200908145738.640039-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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 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). --- include/sys/socket.h | 3 +++ sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++-- sysdeps/unix/sysv/linux/recvmsg.c | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index c551c8fa87..171440ab14 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -171,6 +171,9 @@ libc_hidden_proto (__libc_sa_len) #define SCM_TIMESTAMPNS_NEW SO_TIMESTAMPNS_NEW #define SCM_TIMESTAMPING_NEW SO_TIMESTAMPING_NEW +extern void __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) + attribute_hidden; + libc_hidden_proto (__cmsg_nxthdr) #endif diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c index a29c91fb76..0f67e2dcac 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; } diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c index c6d1d10b05..510ed04ea5 100644 --- a/sysdeps/unix/sysv/linux/recvmsg.c +++ b/sysdeps/unix/sysv/linux/recvmsg.c @@ -32,8 +32,8 @@ original message as a spurious control ones of unknown typ while running on kernel with native 64-bit time support will only see the time64 version of the control message. */ -static void -convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) +void +__convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) { if (msg->msg_control == NULL || msg->msg_controllen == 0) return; @@ -108,7 +108,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags) #ifndef __ASSUME_TIME64_SYSCALLS if (r >= 0) - convert_scm_timestamps (msg, orig_controllen); + __convert_scm_timestamps (msg, orig_controllen); #endif return r;