From patchwork Mon Nov 9 20:18:07 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: 40983 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 582E8397280C; Mon, 9 Nov 2020 20:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 582E8397280C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604953125; bh=Ggx3bLadphqHIHAOga6PxAtohcmcEf0rnzHH6lfMbhA=; 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=fyQ8KZcTpd2nUwHYaHwPOyAKINRFBguyamod6EVG+jBPEPv8P72blAxIfQ/9JcBIu RoVFK+jxMGLOw1Lm4DFR5tbwg2rLrpW1PryVu0RqPR3dL5xxNcKL4PZDRLLzZOGaOh GuZDYrsTXxlT7dCroxEsHnCrB+Bt/3aDuoZkq7tI= 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 4F4A7397200C for ; Mon, 9 Nov 2020 20:18:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F4A7397200C Received: by mail-qt1-x844.google.com with SMTP id g15so3243028qtq.13 for ; Mon, 09 Nov 2020 12:18:41 -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=Ggx3bLadphqHIHAOga6PxAtohcmcEf0rnzHH6lfMbhA=; b=YWtWkxbIq7kXHkYnfYIH1R5jofqpUuVqlsj/m/z8m/BBqN2G8MrrFalVemxhg5NBR/ pagRNMSrILMWr0ttakegZQBpG3qZ41xg2iLbAsXTdxm+tOtimVfs0gPsKqUENE9n7l+i yuAazPCNNJ6Dh54I4jRCruN6bXYI25wzz4AdnglJoesTDOfiXXcEcDWn9vol45G0jzHP /uo4cjmHFsvuMOX+VY9HYXiN8IyYf8f/Z0sdZuIrwP/CJllSN6r3tTYdvTngKvuiPyrZ 2oYWrpr7OphFWI+tOehzmUzmQoEx2le5EZEWs0rWOVT5FDQFMPD91UxofZxJRtrJgZ5/ 9UhQ== X-Gm-Message-State: AOAM533dMPFCEDS32z/OrQy65bko9zwKl1IulykFJSFu3k6PBv5kRpi/ k1Pr9YnrYXOVw06qcaC44GTjeufgDKTSlA== X-Google-Smtp-Source: ABdhPJwAKcnjVYHBtJVKcwblDdTTNkyd9CVO7ckPqjili01ofv/lrWfJgGaN9MrDb4NjC6AnRO3lFg== X-Received: by 2002:ac8:4d99:: with SMTP id a25mr4511007qtw.122.1604953120653; Mon, 09 Nov 2020 12:18:40 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z2sm6843407qkl.22.2020.11.09.12.18.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 12:18:40 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL Date: Mon, 9 Nov 2020 17:18:07 -0300 Message-Id: <20201109201826.120534-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201109201826.120534-1-adhemerval.zanella@linaro.org> References: <20201109201826.120534-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 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 | 4 +--- sysdeps/unix/sysv/linux/fstatat64.c | 4 +--- 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, 22 insertions(+), 51 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c index a61fffa6e7..5ba1b99372 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c +++ b/sysdeps/unix/sysv/linux/fstatat.c @@ -80,9 +80,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag) # endif /* __nr_fstatat64 */ # endif /* STAT_IS_KERNEL_STAT */ - return syscall_error (r) - ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) - : 0; + 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 6e12cf2456..a788940390 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -102,9 +102,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, # endif #endif - return syscall_error (r) - ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) - : 0; + 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 4964eb9028..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 (__glibc_unlikely (syscall_error (ret))) - { - 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 7c578808c6..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 (!syscall_error (sc_ret)) \ - goto out; \ - if (sc_ret != -ENOSYS) \ - goto iserr; \ - } \ - \ - sc_ret = INTERNAL_SYSCALL_CALL (name, ##args); \ - if (syscall_error (sc_ret)) \ - { \ - 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 9750c0418e..66bac892a5 100644 --- a/sysdeps/unix/sysv/linux/sysdep.h +++ b/sysdeps/unix/sysv/linux/sysdep.h @@ -29,28 +29,24 @@ syscall_error (unsigned long int val) { return val > -4096UL; } -#endif -#ifndef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL(sc_err) \ - ({ \ - __set_errno (sc_err); \ - -1L; \ - }) -#endif +static inline long int +syscall_ret (unsigned long int val) +{ + if (syscall_error (val)) + { + __set_errno (-val); + return -1; + } + return val; +} -#ifndef __ASSEMBLER__ /* 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 (syscall_error (sc_ret)) \ - ? 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