From patchwork Fri Nov 13 16:58:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41050 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F37439450CF; Fri, 13 Nov 2020 16:58:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F37439450CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605286735; bh=kroHMMfqAyXY00dqd7j61NLTGqXg3gTRA4gVP4APF2k=; 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=VTFlbNmrUv5liYWYyuuMP1mcJ0ktS8pLlvntwWLfyF0UB/6Fvyf9aB8bh5Ya0i8xw NGoTgwxgEAR7jtDREyvCVHhD6RFJWD61PRVi4/dIGJNe0ub95m8HeC5A+WMY0Qj8CS UEqb510EKQQM84e3wKqBACbign2U8TEt0iSdfXwE= 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 3AAF23945047 for ; Fri, 13 Nov 2020 16:58:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3AAF23945047 Received: by mail-qt1-x844.google.com with SMTP id j31so7113608qtb.8 for ; Fri, 13 Nov 2020 08:58:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kroHMMfqAyXY00dqd7j61NLTGqXg3gTRA4gVP4APF2k=; b=qFT2stkZZ6Fb05LnCZQBMcIS9GNcHmlEBuJmQpq+rXZc6T8fKJI4fJyaKeiTzsmUyf snW3uFO5kkhSAfrpM0iFeBDz25j6TrO/adtsM6XnB+Wn0UOriFTi3+5AxQozVkca46yO NCN1atc8nsuMdVCop9lX5xPeDSQTLfoIwRmqRERdwlcs73I4ek/N9A6+rneB2XO5uJbe v3uww9mrpldJo5IumQ9yJuUnpRJHCdrZWHxvSOYTtT7MFpI0DmLAWelcuczkwwnCKu04 TrsTKFAP9ZctP16cvvvtzs+0+R6FTpSX6wonpw2gDZTXxfQaPqoWs6k8FNeQPbak+1fI 0aXg== X-Gm-Message-State: AOAM533PBBjpVodvbAHwkK70+ctcb/cO/ZQKylaDqcOPEMZtOK9sWzCb heUz1qmeJ6qQYtYWEwZbVukgVvxdK1YoNQ== X-Google-Smtp-Source: ABdhPJxMCyseg/oPyC23Lz//GmKSOyCfviaNUvv2Z8ZkYGfWp1oz1GCRDLJFSdePyStbtQ0T3R8iPg== X-Received: by 2002:ac8:5046:: with SMTP id h6mr2843101qtm.349.1605286726607; Fri, 13 Nov 2020 08:58:46 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id s16sm7363931qkg.5.2020.11.13.08.58.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 08:58:45 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 03/23] linux: Add syscall_ret and use it on INLINE_SYSCALL Date: Fri, 13 Nov 2020 13:58:17 -0300 Message-Id: <20201113165837.121629-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201113165837.121629-1-adhemerval.zanella@linaro.org> References: <20201113165837.121629-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It check the resulting value from INTERNAL_SYSCALL_CALL and sets the errno accordingly. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/fstatat.c | 2 +- sysdeps/unix/sysv/linux/fstatat64.c | 2 +- sysdeps/unix/sysv/linux/mq_unlink.c | 11 +++-------- sysdeps/unix/sysv/linux/sysdep-vdso.h | 26 +++++-------------------- sysdeps/unix/sysv/linux/sysdep.h | 28 +++++++++++++-------------- 5 files changed, 23 insertions(+), 46 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c index 87e5c0fc8f..5ba1b99372 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c +++ b/sysdeps/unix/sysv/linux/fstatat.c @@ -80,7 +80,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag) # endif /* __nr_fstatat64 */ # endif /* STAT_IS_KERNEL_STAT */ - return r == 0 ? 0 : INLINE_SYSCALL_ERROR_RETURN_VALUE (-r); + return syscall_ret (r); } weak_alias (__fstatat, fstatat) diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index 71216e43f5..a788940390 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -102,7 +102,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, # endif #endif - return r == 0 ? 0 : INLINE_SYSCALL_ERROR_RETURN_VALUE (-r); + return syscall_ret (r); } #if __TIMESIZE != 64 hidden_def (__fstatat64_time64) diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c index bfba6ccfec..701bc86438 100644 --- a/sysdeps/unix/sysv/linux/mq_unlink.c +++ b/sysdeps/unix/sysv/linux/mq_unlink.c @@ -30,12 +30,7 @@ mq_unlink (const char *name) /* While unlink can return either EPERM or EACCES, mq_unlink should return just EACCES. */ - if (ret < 0) - { - if (ret == -EPERM) - ret = -EACCES; - return INLINE_SYSCALL_ERROR_RETURN_VALUE (-ret); - } - - return ret; + if (ret == -EPERM) + ret = -EACCES; + return syscall_ret (ret); } diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h index 17ed99d495..9f59198444 100644 --- a/sysdeps/unix/sysv/linux/sysdep-vdso.h +++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h @@ -28,29 +28,13 @@ #define INLINE_VSYSCALL(name, nr, args...) \ ({ \ - __label__ out; \ - __label__ iserr; \ - long int sc_ret; \ - \ + long int sc_ret = -ENOSYS; \ __typeof (GLRO(dl_vdso_##name)) vdsop = GLRO(dl_vdso_##name); \ if (vdsop != NULL) \ - { \ - sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); \ - if (sc_ret == 0) \ - goto out; \ - if (sc_ret != -ENOSYS) \ - goto iserr; \ - } \ - \ - sc_ret = INTERNAL_SYSCALL_CALL (name, ##args); \ - if (sc_ret < 0) \ - { \ - iserr: \ - __set_errno (-sc_ret); \ - sc_ret = -1L; \ - } \ - out: \ - sc_ret; \ + sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); \ + if (sc_ret == -ENOSYS) \ + sc_ret = INTERNAL_SYSCALL_CALL (name, ##args); \ + syscall_ret (sc_ret); \ }) #endif /* SYSDEP_VDSO_LINUX_H */ diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h index d09e5ee532..e423b5e7b1 100644 --- a/sysdeps/unix/sysv/linux/sysdep.h +++ b/sysdeps/unix/sysv/linux/sysdep.h @@ -23,26 +23,24 @@ #include #include -#ifndef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL(sc_err) \ - ({ \ - __set_errno (sc_err); \ - -1L; \ - }) -#endif - #ifndef __ASSEMBLER__ +static inline long int +syscall_ret (unsigned long int val) +{ + if (val > -4096UL) + { + __set_errno (-val); + return -1; + } + return val; +} + /* Define a macro which expands into the inline wrapper code for a system call. It sets the errno and returns -1 on a failure, or the syscall return value otherwise. */ #undef INLINE_SYSCALL -#define INLINE_SYSCALL(name, nr, args...) \ - ({ \ - long int sc_ret = INTERNAL_SYSCALL (name, nr, args); \ - __glibc_unlikely (sc_ret > -4096UL) \ - ? SYSCALL_ERROR_LABEL (-sc_ret) \ - : sc_ret; \ - }) +#define INLINE_SYSCALL(...) \ + syscall_ret (INTERNAL_SYSCALL (__VA_ARGS__)) #endif /* Set error number and return -1. A target may choose to return the