lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZHyKoeSMaOHtSr58@1wt.eu>
Date:   Sun, 4 Jun 2023 14:59:13 +0200
From:   Willy Tarreau <w@....eu>
To:     Zhangjin Wu <falcon@...ylab.org>
Cc:     arnd@...db.de, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org, linux-riscv@...ts.infradead.org,
        thomas@...ch.de
Subject: Re: [PATCH 1/4] tools/nolibc: unistd.h: add __syscall() and
 __syscall_ret() helpers

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@...ylab.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ