Message ID | f549b27981484b429b7c7f98e212bf3c5561724f.1685856497.git.falcon@tinylab.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1987139vqr; Sat, 3 Jun 2023 22:42:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NpYWUgQDfqKEXRB/gDSnJCpnT/gBrwF0k5r0B52PEPLlE7UUyWgdGbxnSTbfXyVLIQD1l X-Received: by 2002:a25:874a:0:b0:ba8:7122:2917 with SMTP id e10-20020a25874a000000b00ba871222917mr9323970ybn.0.1685857372065; Sat, 03 Jun 2023 22:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685857372; cv=none; d=google.com; s=arc-20160816; b=sIBdgaXZvYDhomNSg6l1KwLZLRTfMyoVc7fa86AbH7Ngf/riYaXHdEA2oHJAAMtdwu FFmfQa58mmPR39YsPEFyxjui/GI2LzhcVMNdkBRPKowB5PAT3ZzAq9JUNZ/zF6kI42Nz DrxtQgp2wYy2IkJfhN9/ESczkcY8IqNGAF5I7emIhbhr9XqPSlkccu8zwj9TMKoQx4z4 ebSbPIFIqTnPOuHcAwt/hK0xtPgY5Fu2JmNgaDvE/E5h0fFotvKweKOWnIycPGAKYs2k oZbHBFDcBKBB8LtCp/0P0KoGEVPZYReATzASYivpjy6wCudZI9YkQHfHZMhj9WFHLXGa FEvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=hhlAESCkobmzUn008FNagAcuFwvqA/T6Fg/nWzHPFa8=; b=BLVTmlNpZF4Lpmo7XPleIDkKOUqOMQJDBFSEvrtBt+p7U306r1n5bphaFSY5vTVTqk zlVG1WyFW5yELi1td2mRLb/waHQbfU2nHLWdXvXJU48He6KLLaIVOgoqPrjAwXlOBzte MrSow3KLQyDEUKN3k/MptpwW11Aaq7A2yMlBMtKjhMIQ7ifIE8R8e5JEkTtDu16bsaTr agr5jtYVUCKSeplb9E/MWnENAJw4Qe7MQuF9ZhxRzpuK25GfgqWiW2qN8cHqNTcDU16m bKW0hC8AwoXq6+koZdK7nOz/dRinSDQPARO9VpoVrvLZtE84InMh77dA/0WlqEETBWhO u2dQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a170902ec8f00b001a95babe3c0si3706977plg.371.2023.06.03.22.42.40; Sat, 03 Jun 2023 22:42:52 -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 S229799AbjFDFf3 (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Sun, 4 Jun 2023 01:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjFDFfZ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 4 Jun 2023 01:35:25 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B85FCE; Sat, 3 Jun 2023 22:35:23 -0700 (PDT) X-QQ-mid: bizesmtp83t1685856912tz2mpqb9 Received: from linux-lab-host.localdomain ( [61.141.77.49]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 04 Jun 2023 13:35:11 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: rZJGTgY0+YN6Hgm0UEoWeI0raRxwz+OClFuVPySOxGuRMnsmCqEXyxefSu3x0 2WU1GagREmkvIIMdLAcKZPPfzXOjtPC6QHE3ohpmFo0EwDu8CwIBqVcnio0loP9RgMSMEle vfF2rNJrqkaUHui8aQBWgK5qof0qpL61KoggBuPyvGXjWlRfC+JUz68VKJvriGEPu22kSbc RqLABcHytpqcY77XZL3DpY4doFeZYFXTqw9icVDCrprILlhn+oHUh/o89uCtTCHgHw1Z4/g qH5mWGlhL8RN+5kTi7TjkC8GBo1nfTwYXvNmegQ1933fDtiBVCTz03KNUfGCKHNsjcRg/aK RsT2h465n546UCWpcxgDIIFqF9rZUXUyBTxm19I3slRZRZGF2/hpk36ULoPt4VGRjQLLtme X-QQ-GoodBg: 0 X-BIZMAIL-ID: 350183426812210734 From: Zhangjin Wu <falcon@tinylab.org> To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: [PATCH 1/4] tools/nolibc: unistd.h: add __syscall() and __syscall_ret() helpers Date: Sun, 4 Jun 2023 13:34:29 +0800 Message-Id: <f549b27981484b429b7c7f98e212bf3c5561724f.1685856497.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1685856497.git.falcon@tinylab.org> References: <cover.1685856497.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767749579395308002?= X-GMAIL-MSGID: =?utf-8?q?1767749579395308002?= |
Series |
tools/nolibc: add two new syscall helpers
|
|
Commit Message
Zhangjin Wu
June 4, 2023, 5:34 a.m. UTC
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 <falcon@tinylab.org>
---
tools/include/nolibc/sys.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
Comments
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 <falcon@tinylab.org> > --- > 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
On 2023-06-04 14:59:13+0200, Willy Tarreau wrote: > 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 <falcon@tinylab.org> > > --- > > 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. While I see the value in factoring out this pattern I'm also not really happy with the implementation. Especially the magic delegation to "sys_##name". What about something like this: static inline long __ret_as_errno(long ret) /* or some other name */ { if (ret < 0) { SET_ERRNO(-ret); ret = -1; } return ret; } This avoids another macro by using a normal function. Syscall return values should always fit into long, at least extrapolating from syscall(2) and the fact that they are returned in registers. It would be a bit more verbose: int chdir(const char *path) { return __ret_as_errno(sys_chdir(path)); } But it's clear what's going on and also just one line. Thomas
> On 2023-06-04 14:59:13+0200, Willy Tarreau wrote: > > 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 <falcon@tinylab.org> > > > --- > > > 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, Hi, Willy, I did add something like this in my local copy to pass the errno and retval arguments too: #define __syscall_ret3(ret, errno, retval) \ ({ \ if (ret < 0) { \ SET_ERRNO(errno); \ ret = (typeof(ret)retval; \ } \ ret; \ }) #define __syscall_ret(ret) __syscall_ret3(ret, -ret, -1) But when really using them, I found we could be able to set the ret as errno at first (and the reval is always -1 currently), then used the only simpler __syscall_ret() at last. > > 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); \ > > +}) > > It is clearer. > > 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. > > While I see the value in factoring out this pattern I'm also not really > happy with the implementation. > Especially the magic delegation to "sys_##name". > > What about something like this: > > static inline long __ret_as_errno(long ret) /* or some other name */ > { > if (ret < 0) { > SET_ERRNO(-ret); > ret = -1; > } > return ret; > } > > This avoids another macro by using a normal function. > It is reasonable, like it very much. > Syscall return values should always fit into long, at least > extra polating from syscall(2) and the fact that they are returned in > registers. Yes, I did use 'long' instead of 'int' for unistd.h locally, but since tried to let it work with 'void *' before (e.g. sys_brk, an older version support pass the errno value), so, the typeof() is used and the same to unistd.h, but at last, none of (void *) return type is really used in current patchset, so, we are able to use this normal function version without the checking of the type. > > It would be a bit more verbose: > > int chdir(const char *path) > { > return __ret_as_errno(sys_chdir(path)); > } > > But it's clear what's going on and also just one line. Thanks Thomas, It looks good and I do like the 'embedded' calling of sys_chrdir(path), but __syscall() looks cleaner and shorter too, let's put them together: int chdir(const char *path) { return __ret_as_errno(sys_chdir(path)); } int chdir(const char *path) { return __syscall(chdir, path); } And even with: int chdir(const char *path) { return __sysret(sys_chdir(path)); } __syscall() works likes syscall(), and the definition is similar to syscall(), but uses the syscall name instead of syscall number, If reserve __syscall(), the inline function would be renamed back to __syscall_ret() or something like the shorter __sysret(), to align with our new __syscall(). for sys.h: /* Syscall return helper, set errno as ret when ret < 0 */ static inline long __sysret(long ret) { if (ret < 0) { SET_ERRNO(-ret); ret = -1; } return ret; } /* Syscall call helper, use syscall name instead of syscall number */ #define __syscall(name, ...) __sysret(sys_##name(__VA_ARGS__)) for unistd.h: #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__)) What about this version? The potential 'issue' may be mixing the use of __syscall(), _syscall() and syscall(), but the compilers may help to fix up this for us, I don't think it is a bottleneck. Best regards, Zhangjin > > Thomas
On Mon, Jun 05, 2023 at 01:58:57PM +0800, Zhangjin Wu wrote: > > What about something like this: > > > > static inline long __ret_as_errno(long ret) /* or some other name */ > > { > > if (ret < 0) { > > SET_ERRNO(-ret); > > ret = -1; > > } > > return ret; > > } > > > > This avoids another macro by using a normal function. > > > > It is reasonable, like it very much. > > > Syscall return values should always fit into long, at least > > extra polating from syscall(2) and the fact that they are returned in > > registers. > > Yes, I did use 'long' instead of 'int' for unistd.h locally, but since tried to > let it work with 'void *' before (e.g. sys_brk, an older version support pass > the errno value), so, the typeof() is used and the same to unistd.h, but at > last, none of (void *) return type is really used in current patchset, so, we > are able to use this normal function version without the checking of the type. > > > > > It would be a bit more verbose: > > > > int chdir(const char *path) > > { > > return __ret_as_errno(sys_chdir(path)); > > } > > > > But it's clear what's going on and also just one line. > > Thanks Thomas, It looks good and I do like the 'embedded' calling of > sys_chrdir(path), but __syscall() looks cleaner and shorter too, let's put them > together: > > int chdir(const char *path) > { > return __ret_as_errno(sys_chdir(path)); > } > > int chdir(const char *path) > { > return __syscall(chdir, path); > } > > And even with: > > int chdir(const char *path) > { > return __sysret(sys_chdir(path)); > } > > __syscall() works likes syscall(), and the definition is similar to syscall(), > but uses the syscall name instead of syscall number, If reserve __syscall(), > the inline function would be renamed back to __syscall_ret() or something like > the shorter __sysret(), to align with our new __syscall(). > > for sys.h: > > /* Syscall return helper, set errno as ret when ret < 0 */ > static inline long __sysret(long ret) > { > if (ret < 0) { > SET_ERRNO(-ret); > ret = -1; > } > return ret; > } > > /* Syscall call helper, use syscall name instead of syscall number */ > #define __syscall(name, ...) __sysret(sys_##name(__VA_ARGS__)) > > for unistd.h: > > #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__)) > > What about this version? > > The potential 'issue' may be mixing the use of __syscall(), _syscall() and > syscall(), but the compilers may help to fix up this for us, I don't think it > is a bottleneck. I think that could work. However, please place __attribute__((always_inline)) on these inline functions, as we don't want to turn them to function calls even at -O0. I'm traveling today, I'll let you and Thomas debate and decide how you'd like this to evolve. Also, please note that Paul is OK with merging for 6.5, but we should absolutely limit last-minute changes to the strict minimum we're able to test now. Thanks! Willy
> On Mon, Jun 05, 2023 at 01:58:57PM +0800, Zhangjin Wu wrote: > > > What about something like this: > > > > > > static inline long __ret_as_errno(long ret) /* or some other name */ > > > { > > > if (ret < 0) { > > > SET_ERRNO(-ret); > > > ret = -1; > > > } > > > return ret; > > > } > > > > > > This avoids another macro by using a normal function. > > > > > > > It is reasonable, like it very much. > > > > > Syscall return values should always fit into long, at least > > > extra polating from syscall(2) and the fact that they are returned in > > > registers. > > > > Yes, I did use 'long' instead of 'int' for unistd.h locally, but since tried to > > let it work with 'void *' before (e.g. sys_brk, an older version support pass > > the errno value), so, the typeof() is used and the same to unistd.h, but at > > last, none of (void *) return type is really used in current patchset, so, we > > are able to use this normal function version without the checking of the type. > > > > > > > > It would be a bit more verbose: > > > > > > int chdir(const char *path) > > > { > > > return __ret_as_errno(sys_chdir(path)); > > > } > > > > > > But it's clear what's going on and also just one line. > > > > Thanks Thomas, It looks good and I do like the 'embedded' calling of > > sys_chrdir(path), but __syscall() looks cleaner and shorter too, let's put them > > together: > > > > int chdir(const char *path) > > { > > return __ret_as_errno(sys_chdir(path)); > > } > > > > int chdir(const char *path) > > { > > return __syscall(chdir, path); > > } > > > > And even with: > > > > int chdir(const char *path) > > { > > return __sysret(sys_chdir(path)); > > } > > > > __syscall() works likes syscall(), and the definition is similar to syscall(), > > but uses the syscall name instead of syscall number, If reserve __syscall(), > > the inline function would be renamed back to __syscall_ret() or something like > > the shorter __sysret(), to align with our new __syscall(). > > > > for sys.h: > > > > /* Syscall return helper, set errno as ret when ret < 0 */ > > static inline long __sysret(long ret) > > { > > if (ret < 0) { > > SET_ERRNO(-ret); > > ret = -1; > > } > > return ret; > > } > > > > /* Syscall call helper, use syscall name instead of syscall number */ > > #define __syscall(name, ...) __sysret(sys_##name(__VA_ARGS__)) > > > > for unistd.h: > > > > #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__)) > > > > What about this version? > > > > The potential 'issue' may be mixing the use of __syscall(), _syscall() and > > syscall(), but the compilers may help to fix up this for us, I don't think it > > is a bottleneck. > > I think that could work. However, please place __attribute__((always_inline)) > on these inline functions, as we don't want to turn them to function calls > even at -O0. Thanks, done. > > I'm traveling today, I'll let you and Thomas debate and decide how you'd > like this to evolve. > Happy traveling. This revision is basically derived from the 'long' type information and __ret_as_errno() from Thomas, I will wait suggestion from Thomas and then send v2 later. > Also, please note that Paul is OK with merging for 6.5, but we should > absolutely limit last-minute changes to the strict minimum we're able > to test now. Strongly agree, we can delay this and the left time64 syscalls to 6.6, because they require more cleanup and discussion. Best regards, Zhangjin > > Thanks! > Willy
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); \ +}) /* Functions in this file only describe syscalls. They're declared static so * that the compiler usually decides to inline them while still being allowed