Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4478868rwd; Sun, 4 Jun 2023 06:15:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4EUlHseXHpYNDKPwWJ/uoQC+oJOhuH/6qjp3i+jwzbtu9WCHRrGuHv0GlgaaUr30QLV/wM X-Received: by 2002:a05:6a00:13a9:b0:659:61ba:62df with SMTP id t41-20020a056a0013a900b0065961ba62dfmr1331920pfg.27.1685884546448; Sun, 04 Jun 2023 06:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685884546; cv=none; d=google.com; s=arc-20160816; b=0qSKZ+w51SMKFkAAMMiMSspwH7kBnTYasZ3g13lNrc7KHZNvI8UuXh3ZVOPev/rxD7 MB1q0MDmjdVWpIkFKe0WHDIeDr3yp1TDGjQliSwcw438FQ8FCB0hz0xcLgB9YBjnFi8Y 19QsMGcjRCnyxYDO/gSYNiiadhLNpdE12GiaXDIgsCoZ2lbefOAGlsLo4zKZfjPnYnj6 MFCsDNqj1TpIxZ8UgRMgGdBD31aLvOQsikEeZoxcFdy8W0A6bJ5ztuormjCFLl8blwJl ig50BN0EaAvfxpwmd5jTrQsdRTuBW137sCCgdN2kZ27rrJePItHcUeiRSREybu2OfJKW yNuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=SDvsCiElNlwXDcLzo2gyaS4chFSIMBi75CxE++EK+kU=; b=u8CE7347/qheNFc8/C23TYCy+FuKbEPISZY1EhyXS5mj+LksJDM0JCiKlFB8zfKpvx R7kV53g7xFWXG5aA8KTVNjlBw1muNxSRud+e/rZxJerESbr7lk/8QwEkv7MYpJGd/3jJ kQ/0hESehCD+2wlBxk28TFK6Bh0Ab1jQQpD0q/z5jRDPjDxPRGX3P52AnCWeY96yjvwy s4xxMZyHiPCpHWFg40trYtshFHmY5pccILGwgh9mbtHXBAUh6lSKfBb79iui2Kq571SU TVOxCKp3qlfYbdzOkmJNeV6phOFFr1Unc98941adlB/TCpBxO7f3wiAsuMuLbqdMKaDy 7fxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020a637255000000b0053fb85dd81asi4095333pgn.325.2023.06.04.06.15.33; Sun, 04 Jun 2023 06:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231757AbjFDM71 (ORCPT + 99 others); Sun, 4 Jun 2023 08:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjFDM7Z (ORCPT ); Sun, 4 Jun 2023 08:59:25 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62543AB; Sun, 4 Jun 2023 05:59:23 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 354CxDHH002392; Sun, 4 Jun 2023 14:59:13 +0200 Date: Sun, 4 Jun 2023 14:59:13 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: Re: [PATCH 1/4] tools/nolibc: unistd.h: add __syscall() and __syscall_ret() helpers Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zhangjin, On Sun, Jun 04, 2023 at 01:34:29PM +0800, Zhangjin Wu wrote: > most of the library routines share the same code model, let's add some > macros to simplify the coding and shrink the code lines too. > > One added for syscall return, one added for syscall call, both of them > can get the typeof 'return value' automatically. > > To get the return type of syscalls, __auto_type is better than typeof(), > but it is not supported by the old compilers (before 2013, see [1]), so, > use typeof() here. > > [1]: https://gcc.gnu.org/legacy-ml/gcc-patches/2013-11/msg01378.html > > Signed-off-by: Zhangjin Wu > --- > tools/include/nolibc/sys.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > index 1d6f33f58629..937a8578e3d4 100644 > --- a/tools/include/nolibc/sys.h > +++ b/tools/include/nolibc/sys.h > @@ -28,6 +28,21 @@ > #include "errno.h" > #include "types.h" > > +/* Syscall call and return helpers */ > +#define __syscall_ret(ret) \ > +({ \ > + if (ret < 0) { \ > + SET_ERRNO(-ret); \ > + ret = (typeof(ret))-1; \ > + } \ > + ret; \ > +}) > + > +#define __syscall(name, ...) \ > +({ \ > + typeof(sys_##name(__VA_ARGS__)) ret = sys_##name(__VA_ARGS__); \ > + __syscall_ret(ret); \ > +}) Well, I personally don't find that it increases legibility, on the opposite. At first when reading the series, I thought you had dropped errno setting on return. I think the reason is that when reading that last macro, it's not at all obvious that __syscall_ret() is actually modifying this ret value *and* returning it as the macro's result. If we'd want to go down that route, I suspect that something like this would at least hint about what is being returned: +#define __syscall(name, ...) \ +({ \ + typeof(sys_##name(__VA_ARGS__)) ret = sys_##name(__VA_ARGS__); \ + ret = __syscall_ret(ret); \ +}) But I'm interested in others' opinion on this, particularly Thomas and Arnd who review a significant number of patches. For now I prefer not to take it before we've settled on a choice. Thanks, Willy